|
|
@ -1,29 +1,34 @@ |
|
|
|
<script setup> |
|
|
|
<script lang="ts" setup> |
|
|
|
import { t } from '@/i18n'; |
|
|
|
import { ref, onMounted } from "vue"; |
|
|
|
import { ref, reactive, onMounted } from "vue"; |
|
|
|
import { useChatStore } from "@/stores/chat"; |
|
|
|
import { notifyError, notifySuccess } from "@/util/msg"; |
|
|
|
import { fetchGet, getSystemConfig, setSystemKey } from "@/system/config"; |
|
|
|
import { fetchGet, fetchPost, getSystemConfig, setSystemKey } from "@/system/config"; |
|
|
|
const store = useChatStore() |
|
|
|
const form = ref({ |
|
|
|
nickname: '', |
|
|
|
}) |
|
|
|
interface ImgItem { |
|
|
|
url: string; |
|
|
|
name: string; |
|
|
|
} |
|
|
|
const editType = ref(0) |
|
|
|
const userInfo = getSystemConfig().userInfo |
|
|
|
const dialogShow = ref(false) |
|
|
|
let imgList = reactive([]) |
|
|
|
let imgList = reactive<ImgItem[]>([]) |
|
|
|
let pos = ref(0) |
|
|
|
const showChange = (val) =>{ |
|
|
|
|
|
|
|
const showChange = (val: boolean) =>{ |
|
|
|
dialogShow.value = val |
|
|
|
} |
|
|
|
const toChangeHead = async ()=>{ |
|
|
|
let res = await fetchGet(`${userInfo.url}/files/saveavatar?id=${userInfo.id}&name=${imgList[pos.value].name}`) |
|
|
|
console.log('submit!:',res) |
|
|
|
let res = await fetchGet(`${userInfo.url}/files/saveavatar?id=${userInfo.id}&name=${imgList[pos.value]?.name}`) |
|
|
|
if (!res.ok) { |
|
|
|
notifyError("头像换取失败") |
|
|
|
} else { |
|
|
|
res = await res.json() |
|
|
|
notifySuccess(res.message) |
|
|
|
userInfo.avatar = imgList[pos.value].name |
|
|
|
const response = await res.json() |
|
|
|
notifySuccess(response?.message || '头像换取成功') |
|
|
|
userInfo.avatar = imgList[pos.value]?.name |
|
|
|
store.userInfo.avatar = userInfo.url + '/upload/avatar/' + userInfo.avatar |
|
|
|
setSystemKey('userInfo', userInfo) |
|
|
|
} |
|
|
@ -35,8 +40,8 @@ const getHeadList = async () => { |
|
|
|
// const apiUrl = getSystemConfig().apiUrl + '/upload/avatar/'; |
|
|
|
const apiUrl = userInfo.url + '/upload/avatar/'; |
|
|
|
if (res.ok) { |
|
|
|
res = await res.json() |
|
|
|
for (const item of res.data) { |
|
|
|
const response = await res.json() |
|
|
|
for (const item of response?.data) { |
|
|
|
imgList.push({ |
|
|
|
url: apiUrl + item, |
|
|
|
name: item |
|
|
@ -45,67 +50,143 @@ const getHeadList = async () => { |
|
|
|
} |
|
|
|
} |
|
|
|
// 换头像 |
|
|
|
const chooseImg = (index) => { |
|
|
|
const chooseImg = (index: number) => { |
|
|
|
pos.value = index |
|
|
|
} |
|
|
|
const onSubmit = async () => { |
|
|
|
console.log('提交'); |
|
|
|
} |
|
|
|
//修改密码 |
|
|
|
const passwordForm = reactive({ |
|
|
|
oldPassword: '', |
|
|
|
newPassword: '', |
|
|
|
confirmPassword: '' |
|
|
|
}) |
|
|
|
const passwordRef:any = ref(null) |
|
|
|
const rules = { |
|
|
|
oldPassword: [ |
|
|
|
{ required: true, message: '密码不能为空', trigger: 'blur' } |
|
|
|
], |
|
|
|
newPassword: [ |
|
|
|
{ required: true, message: '密码不能为空', trigger: 'blur' }, |
|
|
|
{ min: 6, message: '密码长度不能小于6位', trigger: 'blur' } |
|
|
|
], |
|
|
|
confirmPassword: [ |
|
|
|
{ required: true, message: '请再次输入密码', trigger: 'blur' }, |
|
|
|
{ validator: (value:any, callback:any) => { |
|
|
|
if (value === '') { |
|
|
|
callback(new Error('请再次输入密码')); |
|
|
|
} else if (value !== passwordForm.newPassword) { |
|
|
|
callback(new Error('两次输入的密码不一致')); |
|
|
|
} else { |
|
|
|
callback(); |
|
|
|
} |
|
|
|
}, trigger: 'blur' } |
|
|
|
], |
|
|
|
} |
|
|
|
const toChangePwd = async () => { |
|
|
|
try { |
|
|
|
await passwordRef.value.validate() |
|
|
|
const formData = new FormData() |
|
|
|
formData.append('oldpassword', passwordForm.oldPassword) |
|
|
|
formData.append('newpassword', passwordForm.newPassword) |
|
|
|
let res = await fetchPost(`${userInfo.url}/member/savepwd`, formData) |
|
|
|
const response = await res.json() |
|
|
|
if (response && response?.success) { |
|
|
|
notifySuccess(response?.message) |
|
|
|
} else { |
|
|
|
notifyError(response?.message) |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
console.log(e) |
|
|
|
} |
|
|
|
} |
|
|
|
onMounted(()=>{ |
|
|
|
getHeadList() |
|
|
|
store.userInfo.avatar = userInfo.url + '/upload/avatar/' + userInfo.avatar |
|
|
|
}) |
|
|
|
</script> |
|
|
|
<template> |
|
|
|
<div> |
|
|
|
<el-form :model="form" label-width="160px" style="padding: 30px;"> |
|
|
|
<el-form-item label="头像"> |
|
|
|
<el-avatar :size="90" :src="store.userInfo.avatar" @click="showChange(true)"/> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="昵称"> |
|
|
|
<el-input v-model="store.userInfo.nickname" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="手机号"> |
|
|
|
<el-input v-model="store.userInfo.phone" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="工号"> |
|
|
|
<el-input v-model="store.userInfo.job_number" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="自我介绍"> |
|
|
|
<el-input v-model="store.userInfo.desc" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item> |
|
|
|
<el-button type="primary" @click="onSubmit">保存</el-button> |
|
|
|
</el-form-item> |
|
|
|
</el-form> |
|
|
|
<el-dialog v-model="dialogShow" title="修改头像" width="500px" draggable> |
|
|
|
<div> |
|
|
|
<span |
|
|
|
v-for="(item, index) in imgList" |
|
|
|
:key="item.name" |
|
|
|
class="img-box" |
|
|
|
> |
|
|
|
<el-avatar |
|
|
|
:size="80" |
|
|
|
:src="item.url" |
|
|
|
@click="chooseImg(index)" |
|
|
|
:class="{'is-active': pos == index}" |
|
|
|
<el-container> |
|
|
|
<el-aside> |
|
|
|
<div @click="editType = 0" :class="{'is-active': editType == 0}">修改资料</div> |
|
|
|
<div @click="editType = 1" :class="{'is-active': editType == 1}">修改密码</div> |
|
|
|
</el-aside> |
|
|
|
<el-main> |
|
|
|
<el-form v-if="editType == 0" :model="form" label-width="150px" style="padding: 30px;"> |
|
|
|
<el-form-item label="头像"> |
|
|
|
<el-avatar :size="90" :src="store.userInfo.avatar" @click="showChange(true)"/> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="昵称"> |
|
|
|
<el-input v-model="store.userInfo.nickname" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="手机号"> |
|
|
|
<el-input v-model="store.userInfo.phone" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="工号"> |
|
|
|
<el-input v-model="store.userInfo.job_number" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="自我介绍"> |
|
|
|
<el-input v-model="store.userInfo.desc" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item> |
|
|
|
<el-button type="primary" @click="onSubmit">保存</el-button> |
|
|
|
</el-form-item> |
|
|
|
</el-form> |
|
|
|
<el-form v-else :model="passwordForm" :rules="rules" ref="passwordRef" label-width="120px" style="padding: 30px;"> |
|
|
|
<el-form-item label="旧密码" prop="oldPassword"> |
|
|
|
<el-input |
|
|
|
v-model="passwordForm.oldPassword" |
|
|
|
type="password" |
|
|
|
show-password |
|
|
|
/> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="新密码" prop="newPassword"> |
|
|
|
<el-input |
|
|
|
v-model="passwordForm.newPassword" |
|
|
|
type="password" |
|
|
|
show-password |
|
|
|
/> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="再次输入密码" prop="confirmPassword"> |
|
|
|
<el-input |
|
|
|
v-model="passwordForm.confirmPassword" |
|
|
|
type="password" |
|
|
|
show-password |
|
|
|
/> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item> |
|
|
|
<el-button type="primary" @click="toChangePwd">保存</el-button> |
|
|
|
</el-form-item> |
|
|
|
</el-form> |
|
|
|
</el-main> |
|
|
|
<el-dialog v-model="dialogShow" title="修改头像" width="400px" draggable> |
|
|
|
<div> |
|
|
|
<span |
|
|
|
v-for="(item, index) in imgList" |
|
|
|
:key="item.name" |
|
|
|
class="img-box" |
|
|
|
> |
|
|
|
</el-avatar> |
|
|
|
<el-icon v-show="pos == index"><Select /></el-icon> |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
<template #footer> |
|
|
|
<div class="dialog-footer"> |
|
|
|
<el-button @click="showChange(false)">{{ t("cancel") }}</el-button> |
|
|
|
<el-button type="primary" @click="toChangeHead"> |
|
|
|
{{ t("confirm") }} |
|
|
|
</el-button> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</el-dialog> |
|
|
|
|
|
|
|
</div> |
|
|
|
<el-avatar |
|
|
|
:size="80" |
|
|
|
:src="item.url" |
|
|
|
@click="chooseImg(index)" |
|
|
|
:class="{'is-active': pos == index}" |
|
|
|
> |
|
|
|
</el-avatar> |
|
|
|
<el-icon v-show="pos == index"><Select /></el-icon> |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
<template #footer> |
|
|
|
<div class="dialog-footer"> |
|
|
|
<el-button @click="showChange(false)">{{ t("cancel") }}</el-button> |
|
|
|
<el-button type="primary" @click="toChangeHead"> |
|
|
|
{{ t("confirm") }} |
|
|
|
</el-button> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</el-dialog> |
|
|
|
</el-container> |
|
|
|
</template> |
|
|
|
|
|
|
|
<style scoped lang="scss"> |
|
|
@ -132,5 +213,28 @@ onMounted(()=>{ |
|
|
|
transform: translate(-50%,0) |
|
|
|
} |
|
|
|
} |
|
|
|
.el-container { |
|
|
|
|
|
|
|
.el-aside { |
|
|
|
width: 20%; |
|
|
|
padding: 20px; |
|
|
|
background-color: #f9f9f9; |
|
|
|
box-sizing: border-box; |
|
|
|
|
|
|
|
div { |
|
|
|
width: 100%; |
|
|
|
min-width: 38px; |
|
|
|
height: 40px; |
|
|
|
font-size: 14px; |
|
|
|
} |
|
|
|
.is-active, |
|
|
|
div:hover { |
|
|
|
font-weight: bold; |
|
|
|
color: #16b777; |
|
|
|
} |
|
|
|
.el-input { |
|
|
|
width: 200px; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</style> |
|
|
|