2026-05-13 12:43:01 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="admin-profile">
|
2026-10-26 01:19:23 +08:00
|
|
|
|
<header class="profile-head">
|
2026-10-25 20:34:15 +08:00
|
|
|
|
<div>
|
2026-10-26 01:19:23 +08:00
|
|
|
|
<span class="profile-eyebrow">管理员账号</span>
|
|
|
|
|
|
<h1>{{ userInfo?.nickname || '平台管理员' }}</h1>
|
|
|
|
|
|
<p>{{ userInfo?.account || '当前登录账号' }}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<a-avatar :size="58" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
<section class="profile-section">
|
|
|
|
|
|
<div class="profile-section__head">
|
|
|
|
|
|
<div><h2>账号资料</h2><p>该后台只服务平台管理员,数据范围为 Salon 全平台。</p></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="profile-rows">
|
|
|
|
|
|
<div class="profile-row"><span>登录账号</span><strong>{{ userInfo?.account || '--' }}</strong></div>
|
|
|
|
|
|
<div class="profile-row"><span>显示昵称</span><strong>{{ userInfo?.nickname || '未设置昵称' }}</strong></div>
|
|
|
|
|
|
<div class="profile-row"><span>账号类型</span><strong>平台管理员</strong></div>
|
|
|
|
|
|
<div class="profile-row"><span>平台范围</span><strong>全平台门店与经营数据</strong></div>
|
2026-05-13 12:43:01 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
2026-10-25 20:34:15 +08:00
|
|
|
|
<section class="profile-section">
|
|
|
|
|
|
<div class="profile-section__head">
|
2026-10-26 01:19:23 +08:00
|
|
|
|
<div><h2>安全设置</h2><p>修改管理员密码后,所有后台会话都会失效,需要重新登录。</p></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<a-form class="password-form" :model="passwordForm" :rules="passwordRules" layout="vertical" @finish="handleChangePassword">
|
|
|
|
|
|
<div class="password-form__grid">
|
|
|
|
|
|
<a-form-item label="当前密码" name="currentPassword">
|
|
|
|
|
|
<a-input-password v-model:value="passwordForm.currentPassword" autocomplete="current-password" placeholder="请输入当前密码" />
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="新密码" name="newPassword">
|
|
|
|
|
|
<a-input-password v-model:value="passwordForm.newPassword" autocomplete="new-password" placeholder="8-32 位,至少包含 3 类字符" />
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="确认新密码" name="confirmPassword">
|
|
|
|
|
|
<a-input-password v-model:value="passwordForm.confirmPassword" autocomplete="new-password" placeholder="请再次输入新密码" />
|
|
|
|
|
|
</a-form-item>
|
2026-05-13 12:43:01 +08:00
|
|
|
|
</div>
|
2026-10-26 01:19:23 +08:00
|
|
|
|
<div class="password-form__actions">
|
|
|
|
|
|
<span>保存后当前设备和其他设备的后台登录都会退出。</span>
|
|
|
|
|
|
<a-button type="primary" html-type="submit" :loading="changingPassword">保存新密码</a-button>
|
2026-10-25 20:34:15 +08:00
|
|
|
|
</div>
|
2026-10-26 01:19:23 +08:00
|
|
|
|
</a-form>
|
2026-05-13 12:43:01 +08:00
|
|
|
|
</section>
|
|
|
|
|
|
|
2026-10-25 20:34:15 +08:00
|
|
|
|
<section class="profile-section profile-section--logout">
|
|
|
|
|
|
<div class="profile-section__head">
|
2026-10-26 01:19:23 +08:00
|
|
|
|
<div><h2>退出登录</h2><p>退出后需要重新登录后台。</p></div>
|
2026-10-25 20:34:15 +08:00
|
|
|
|
</div>
|
2026-05-13 12:43:01 +08:00
|
|
|
|
<a-button danger size="large" block @click="handleLogout">退出当前账号</a-button>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-10-26 01:19:23 +08:00
|
|
|
|
import { reactive, ref } from 'vue'
|
2026-05-13 12:43:01 +08:00
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
|
import { message, Modal } from 'ant-design-vue'
|
2026-10-26 01:19:23 +08:00
|
|
|
|
import type { Rule } from 'ant-design-vue/es/form'
|
|
|
|
|
|
import { DEFAULT_AVATAR } from '@/constants'
|
|
|
|
|
|
import { adminAuthApi } from '@/api/admin'
|
|
|
|
|
|
import { clearAdminBootstrapSession } from '@/utils/admin-auth-bootstrap'
|
2026-10-10 16:08:46 +08:00
|
|
|
|
import { completeAdminLogout } from '@/utils/admin-logout'
|
2026-10-25 20:34:15 +08:00
|
|
|
|
import { runWithGlobalLoading } from '@/utils/action-loading'
|
2026-10-26 01:19:23 +08:00
|
|
|
|
import { loadCachedAdminUserInfo } from '@/utils/admin-session'
|
2026-05-13 12:43:01 +08:00
|
|
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
const userInfo = ref(loadCachedAdminUserInfo())
|
2026-10-26 01:19:23 +08:00
|
|
|
|
const changingPassword = ref(false)
|
|
|
|
|
|
const passwordForm = reactive({ currentPassword: '', newPassword: '', confirmPassword: '' })
|
|
|
|
|
|
const passwordRules: Record<string, Rule[]> = {
|
|
|
|
|
|
currentPassword: [{ required: true, message: '请输入当前密码' }],
|
|
|
|
|
|
newPassword: [
|
|
|
|
|
|
{ required: true, message: '请输入新密码' },
|
|
|
|
|
|
{ min: 8, max: 32, message: '密码长度需为 8-32 位' },
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: async (_rule, value) => {
|
|
|
|
|
|
const password = String(value || '')
|
|
|
|
|
|
const categoryCount = [/[0-9]/, /[a-z]/, /[A-Z]/, /[^A-Za-z0-9]/].filter(pattern => pattern.test(password)).length
|
|
|
|
|
|
if (password && categoryCount < 3) throw new Error('密码需至少包含数字、小写字母、大写字母、特殊符号中的 3 类')
|
|
|
|
|
|
}
|
2026-05-13 12:43:01 +08:00
|
|
|
|
}
|
2026-10-26 01:19:23 +08:00
|
|
|
|
],
|
|
|
|
|
|
confirmPassword: [
|
|
|
|
|
|
{ required: true, message: '请再次输入新密码' },
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: async (_rule, value) => {
|
|
|
|
|
|
if (value && value !== passwordForm.newPassword) throw new Error('两次输入的新密码不一致')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
2026-05-13 12:43:01 +08:00
|
|
|
|
}
|
2026-10-26 01:19:23 +08:00
|
|
|
|
|
|
|
|
|
|
const handleChangePassword = async () => {
|
|
|
|
|
|
changingPassword.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
await adminAuthApi.changePassword({ currentPassword: passwordForm.currentPassword, newPassword: passwordForm.newPassword })
|
|
|
|
|
|
clearAdminBootstrapSession()
|
|
|
|
|
|
message.success('密码已更新,请使用新密码重新登录')
|
|
|
|
|
|
await router.replace('/admin/login')
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
message.error(error?.message || '密码修改失败,请重试')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
changingPassword.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleLogout = () => Modal.confirm({
|
|
|
|
|
|
title: '确认退出登录',
|
|
|
|
|
|
content: '退出后需要重新登录后台。',
|
|
|
|
|
|
okText: '确认',
|
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
|
await runWithGlobalLoading(async () => {
|
|
|
|
|
|
await completeAdminLogout(router)
|
|
|
|
|
|
message.success('已退出登录')
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2026-05-13 12:43:01 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-10-25 20:34:15 +08:00
|
|
|
|
.admin-profile { display: grid; gap: 18px; color: var(--admin-mobile-ink); }
|
2026-10-26 01:19:23 +08:00
|
|
|
|
.profile-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 8px 0 18px; border-bottom: 1px solid var(--admin-mobile-border); }
|
|
|
|
|
|
.profile-eyebrow { color: var(--theme-primary-action); font-size: 11px; font-weight: 800; letter-spacing: .14em; }
|
|
|
|
|
|
.profile-head h1 { margin: 7px 0 4px; font-size: 28px; }
|
2026-10-25 20:34:15 +08:00
|
|
|
|
.profile-head p, .profile-section__head p { margin: 0; color: var(--admin-mobile-muted); font-size: 13px; }
|
2026-10-26 01:19:23 +08:00
|
|
|
|
.profile-section { padding-top: 4px; border-top: 1px solid var(--admin-mobile-border); }
|
|
|
|
|
|
.profile-section__head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; }
|
|
|
|
|
|
.profile-section__head h2 { margin: 0 0 4px; font-size: 17px; }
|
|
|
|
|
|
.profile-rows { border-top: 1px solid var(--admin-mobile-border); }
|
|
|
|
|
|
.profile-row { display: grid; grid-template-columns: 160px 1fr; align-items: center; gap: 18px; min-height: 58px; padding: 10px 14px; border-bottom: 1px solid color-mix(in srgb, var(--admin-mobile-border) 70%, transparent); background: color-mix(in srgb, var(--theme-card-bg) 82%, transparent); }
|
|
|
|
|
|
.profile-row span { color: var(--admin-mobile-muted); font-size: 12px; }
|
|
|
|
|
|
.profile-row strong { color: var(--admin-mobile-ink); font-size: 13px; }
|
|
|
|
|
|
.profile-link { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--admin-mobile-border); background: var(--theme-card-bg); color: inherit; text-align: left; cursor: pointer; }
|
|
|
|
|
|
.profile-link:hover { border-color: var(--theme-primary); background: var(--admin-mobile-accent-soft); }
|
|
|
|
|
|
.profile-link__icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--admin-mobile-accent-soft); color: var(--theme-primary-action); font-weight: 800; }
|
|
|
|
|
|
.profile-link__body { display: grid; flex: 1; gap: 3px; }
|
|
|
|
|
|
.profile-link__body small { color: var(--admin-mobile-muted); font-size: 11px; }
|
|
|
|
|
|
.profile-link__arrow { color: var(--theme-primary-action); font-size: 24px; }
|
|
|
|
|
|
.profile-section--logout { padding-bottom: 12px; }
|
|
|
|
|
|
.password-form { padding: 15px 14px 14px; border: 1px solid var(--admin-mobile-border); background: color-mix(in srgb, var(--theme-card-bg) 82%, transparent); }
|
|
|
|
|
|
.password-form__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
|
|
|
|
|
|
.password-form :deep(.ant-form-item) { margin-bottom: 12px; }
|
|
|
|
|
|
.password-form :deep(.ant-form-item-label) { padding-bottom: 4px; }
|
|
|
|
|
|
.password-form__actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-top: 2px; color: var(--admin-mobile-muted); font-size: 11px; }
|
|
|
|
|
|
.password-form__actions .ant-btn { flex: 0 0 auto; }
|
|
|
|
|
|
@media (max-width: 760px) { .password-form__grid { grid-template-columns: 1fr; gap: 0; } .password-form__actions { align-items: flex-start; flex-direction: column; } .password-form__actions .ant-btn { width: 100%; } }
|
|
|
|
|
|
@media (max-width: 640px) { .profile-row { grid-template-columns: 1fr; gap: 4px; } }
|
2026-05-13 12:43:01 +08:00
|
|
|
|
</style>
|