- 更新系统名称、登录页宣传文案为37du平台相关内容 - 移除聊天功能相关代码与配置 - 新增客户端版本上报字段与设备统计接口 - 新增通知中心功能(60s轮询、localStorage已读标记) - 新增权限授权工作台相关接口与页面 - 新增统一页头组件ArtPageHeader - 调整快速入口配置指向真实功能页面 - 修复控制面地址为内网生产库
202 lines
7.1 KiB
Vue
202 lines
7.1 KiB
Vue
<!-- 个人中心(37du:accounts 身份体系,自助改密 + 头像上传) -->
|
||
<template>
|
||
<div class="w-full h-full p-0 bg-transparent border-none shadow-none">
|
||
<div class="relative flex-b mt-2.5 max-md:block max-md:mt-1">
|
||
<!-- 左:身份卡 -->
|
||
<div class="w-112 mr-5 max-md:w-full max-md:mr-0">
|
||
<div class="art-card-sm relative p-9 pb-6 overflow-hidden text-center">
|
||
<img class="absolute top-0 left-0 w-full h-50 object-cover" src="@imgs/user/bg.webp" />
|
||
<img
|
||
class="relative z-10 w-20 h-20 mt-30 mx-auto object-cover border-2 border-white rounded-full"
|
||
:src="avatarUrl"
|
||
@error="avatarError = true"
|
||
/>
|
||
<h2 class="mt-5 text-xl font-normal">{{ me.nickname || me.account }}</h2>
|
||
<p v-if="mustChangePwd" class="mt-2 text-xs text-[var(--el-color-danger)]">
|
||
当前为初始密码,请尽快修改
|
||
</p>
|
||
|
||
<div class="w-75 mx-auto mt-6 text-left">
|
||
<div class="mt-2.5">
|
||
<ArtSvgIcon icon="ri:user-3-line" class="text-g-700" />
|
||
<span class="ml-2 text-sm">账号:{{ me.account }}</span>
|
||
</div>
|
||
<div class="mt-2.5">
|
||
<ArtSvgIcon icon="ri:building-line" class="text-g-700" />
|
||
<span class="ml-2 text-sm">部门:{{ me.dept || '—' }}</span>
|
||
</div>
|
||
<div class="mt-2.5">
|
||
<ArtSvgIcon icon="ri:shield-check-line" class="text-g-700" />
|
||
<span class="ml-2 text-sm">身份:{{ me.is_admin ? '管理员' : '普通用户' }}</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mt-8">
|
||
<el-upload
|
||
:show-file-list="false"
|
||
accept=".jpg,.jpeg,.png,.gif,.webp"
|
||
:before-upload="beforeAvatarUpload"
|
||
:http-request="handleAvatarUpload"
|
||
>
|
||
<el-button size="small" plain>更换头像</el-button>
|
||
</el-upload>
|
||
<div class="mt-2 text-[11px] text-gray-400">支持 jpg/png/gif/webp,≤2MB</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 右:修改密码 -->
|
||
<div class="flex-1 overflow-hidden max-md:w-full max-md:mt-3.5">
|
||
<div class="art-card-sm">
|
||
<h1 class="p-4 text-xl font-normal border-b border-g-300">修改密码</h1>
|
||
|
||
<el-form
|
||
ref="pwdFormRef"
|
||
:model="pwdForm"
|
||
:rules="pwdRules"
|
||
class="box-border p-5 max-w-140"
|
||
label-width="96px"
|
||
label-position="top"
|
||
>
|
||
<el-form-item label="当前密码" prop="old_password">
|
||
<el-input v-model="pwdForm.old_password" type="password" show-password placeholder="输入当前密码" />
|
||
</el-form-item>
|
||
|
||
<el-form-item label="新密码" prop="new_password">
|
||
<el-input
|
||
v-model="pwdForm.new_password"
|
||
type="password"
|
||
show-password
|
||
placeholder="至少 8 位"
|
||
/>
|
||
</el-form-item>
|
||
|
||
<el-form-item label="确认新密码" prop="confirm_password">
|
||
<el-input v-model="pwdForm.confirm_password" type="password" show-password placeholder="再次输入新密码" />
|
||
</el-form-item>
|
||
|
||
<div class="flex-c justify-end [&_.el-button]:!w-27.5">
|
||
<el-button type="primary" :loading="submitting" v-ripple @click="submitPwd">保存修改</el-button>
|
||
</div>
|
||
<div class="mt-2 text-xs text-gray-400">
|
||
修改成功后当前登录仍有效;执行机侧下次登录请使用新密码。
|
||
</div>
|
||
</el-form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, reactive, ref } from 'vue'
|
||
import { ElMessage, type FormInstance, type FormRules, type UploadRequestOptions } from 'element-plus'
|
||
import { fetchGetUserInfo } from '@/api/auth'
|
||
import { changePassword, uploadAvatar } from '@/api/business'
|
||
import { useUserStore } from '@/store/modules/user'
|
||
import defaultAvatar from '@imgs/user/avatar.webp'
|
||
|
||
defineOptions({ name: 'UserCenter' })
|
||
|
||
const userStore = useUserStore()
|
||
|
||
// ---- 当前身份(/api/admin/me 实时拉取) ----
|
||
const me = ref<any>({ account: '', nickname: '', dept: '', is_admin: false, must_change_pwd: false, avatar: '' })
|
||
const avatarError = ref(false)
|
||
const avatarVersion = ref(Date.now())
|
||
|
||
const avatarUrl = computed(() => {
|
||
if (!me.value.account) return defaultAvatar
|
||
if (avatarError.value || !me.value.avatar) return defaultAvatar
|
||
return `/api/avatar/${encodeURIComponent(me.value.account)}?v=${avatarVersion.value}`
|
||
})
|
||
|
||
const mustChangePwd = computed(() => !!me.value.must_change_pwd)
|
||
|
||
async function loadMe() {
|
||
const info = await fetchGetUserInfo()
|
||
me.value = { ...info }
|
||
avatarError.value = false
|
||
avatarVersion.value = Date.now()
|
||
// 同步全局用户信息(昵称/头像展示用)
|
||
userStore.setUserInfo({
|
||
...userStore.getUserInfo,
|
||
nickname: info.nickname,
|
||
account: info.account
|
||
} as any)
|
||
}
|
||
|
||
// ---- 头像上传 ----
|
||
function beforeAvatarUpload(file: File): boolean {
|
||
const okType = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].includes(file.type)
|
||
if (!okType) {
|
||
ElMessage.error('仅支持 jpg/png/gif/webp')
|
||
return false
|
||
}
|
||
if (file.size > 2 * 1024 * 1024) {
|
||
ElMessage.error('头像不能超过 2MB')
|
||
return false
|
||
}
|
||
return true
|
||
}
|
||
|
||
async function handleAvatarUpload(options: UploadRequestOptions) {
|
||
await uploadAvatar(options.file as File, me.value.account)
|
||
ElMessage.success('头像已更新')
|
||
await loadMe()
|
||
}
|
||
|
||
// ---- 修改密码 ----
|
||
const pwdFormRef = ref<FormInstance>()
|
||
const submitting = ref(false)
|
||
const pwdForm = reactive({
|
||
old_password: '',
|
||
new_password: '',
|
||
confirm_password: ''
|
||
})
|
||
|
||
const pwdRules: FormRules = {
|
||
old_password: [{ required: true, message: '请输入当前密码', trigger: 'blur' }],
|
||
new_password: [
|
||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||
{ min: 8, max: 64, message: '新密码至少 8 位', trigger: 'blur' }
|
||
],
|
||
confirm_password: [
|
||
{ required: true, message: '请再次输入新密码', trigger: 'blur' },
|
||
{
|
||
validator: (_rule, value, callback) => {
|
||
if (value !== pwdForm.new_password) {
|
||
callback(new Error('两次输入的新密码不一致'))
|
||
} else {
|
||
callback()
|
||
}
|
||
},
|
||
trigger: 'blur'
|
||
}
|
||
]
|
||
}
|
||
|
||
async function submitPwd() {
|
||
if (!pwdFormRef.value) return
|
||
await pwdFormRef.value.validate()
|
||
submitting.value = true
|
||
try {
|
||
await changePassword({
|
||
account: me.value.account,
|
||
old_password: pwdForm.old_password,
|
||
new_password: pwdForm.new_password
|
||
})
|
||
ElMessage.success('密码修改成功')
|
||
pwdForm.old_password = ''
|
||
pwdForm.new_password = ''
|
||
pwdForm.confirm_password = ''
|
||
pwdFormRef.value?.clearValidate()
|
||
await loadMe()
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
}
|
||
|
||
loadMe()
|
||
</script>
|