重构Salon后台单管理员与经营驾驶舱

This commit is contained in:
2026-10-26 01:19:23 +08:00
parent 17cf16db36
commit b8327146cb
35 changed files with 1087 additions and 4158 deletions
+115 -69
View File
@@ -1,47 +1,52 @@
<template>
<div class="admin-profile">
<section class="profile-head">
<header class="profile-head">
<div>
<span class="profile-eyebrow">后台账号</span>
<h1>{{ userInfo?.nickname || '未设置昵称' }}</h1>
<p>{{ userInfo?.account || '当前登录账号' }} · {{ roleLabel }}</p>
<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>
</div>
<span class="profile-chip">{{ isPlatformOverview ? '平台总览' : currentShopName }}</span>
</section>
<section class="profile-section">
<div class="profile-section__head">
<div>
<h2>账号与门店</h2>
<p>账号资料、权限范围和门店切换已集中到系统设置。</p>
<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>
</div>
</div>
<button class="profile-link" type="button" @click="router.push({ path: '/admin/settings', query: { section: 'account' } })">
<span class="profile-link__icon">◎</span>
<span class="profile-link__body"><strong>打开当前账号设置</strong><small>查看后台账号、权限范围和可用门店</small></span>
<span class="profile-link__arrow">›</span>
</button>
</section>
<section class="profile-section">
<div class="profile-section__head">
<div>
<h2>常用入口</h2>
<p>继续处理日常经营工作。</p>
<div class="password-form__actions">
<span>保存后当前设备和其他设备的后台登录都会退出。</span>
<a-button type="primary" html-type="submit" :loading="changingPassword">保存新密码</a-button>
</div>
</div>
<div class="profile-actions">
<a-button type="default" size="large" @click="router.push('/admin/orders')">查看订单</a-button>
<a-button type="default" size="large" @click="router.push('/admin/manage')">进入经营模块</a-button>
</div>
</a-form>
</section>
<section class="profile-section profile-section--logout">
<div class="profile-section__head">
<div>
<h2>退出登录</h2>
<p>退出后需要重新登录后台。</p>
</div>
<div><h2>退出登录</h2><p>退出后需要重新登录后台。</p></div>
</div>
<a-button danger size="large" block @click="handleLogout">退出当前账号</a-button>
</section>
@@ -49,57 +54,98 @@
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { message, Modal } from 'ant-design-vue'
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'
import { completeAdminLogout } from '@/utils/admin-logout'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { getAdminCurrentShopName, getAdminRoleLabel, isBootstrapAdminUser, loadCachedAdminUserInfo } from './admin-helpers'
import { loadCachedAdminUserInfo } from '@/utils/admin-session'
const router = useRouter()
const userInfo = ref(loadCachedAdminUserInfo())
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
const isPlatformOverview = computed(() => isBootstrapAdminUser(userInfo.value))
const handleLogout = () => {
Modal.confirm({
title: '确认退出登录',
content: '退出后需要重新登录后台。',
okText: '确认',
cancelText: '取消',
onOk: async () => {
await runWithGlobalLoading(async () => {
await completeAdminLogout(router)
message.success('已退出登录')
})
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 类')
}
}
})
],
confirmPassword: [
{ required: true, message: '请再次输入新密码' },
{
validator: async (_rule, value) => {
if (value && value !== passwordForm.newPassword) throw new Error('两次输入的新密码不一致')
}
}
]
}
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('已退出登录')
})
}
})
</script>
<style scoped>
.admin-profile { display: grid; gap: 18px; color: var(--admin-mobile-ink); }
.profile-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--admin-mobile-border); }
.profile-eyebrow { color: var(--theme-primary-action); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.profile-head h1 { margin: 7px 0 4px; font-size: 27px; }
.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; }
.profile-head p, .profile-section__head p { margin: 0; color: var(--admin-mobile-muted); font-size: 13px; }
.profile-chip { padding: 7px 10px; border-radius: 999px; background: var(--admin-mobile-accent-soft); color: var(--theme-primary-action); font-size: 12px; font-weight: 700; white-space: nowrap; }
.profile-section { padding-top: 16px; border-top: 1px solid var(--admin-mobile-border); }
.profile-section__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.profile-section__head h2 { margin: 0 0 4px; font-size: 15px; }
.profile-link { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px 2px; border: 0; border-bottom: 1px solid var(--admin-mobile-border); background: transparent; color: inherit; text-align: left; cursor: pointer; }
.profile-link:hover { color: var(--theme-primary-action); }
.profile-link__icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 12px; background: var(--admin-mobile-accent-soft); color: var(--theme-primary-action); font-size: 20px; }
.profile-link__body { display: grid; flex: 1; gap: 3px; min-width: 0; }
.profile-link__body strong { font-size: 14px; }
.profile-link__body small { color: var(--admin-mobile-muted); font-size: 12px; }
.profile-link__arrow { color: var(--admin-mobile-muted); font-size: 24px; line-height: 1; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.profile-actions .ant-btn { flex: 1 1 180px; }
.profile-section--logout .ant-btn { max-width: 240px; }
@media (max-width: 560px) {
.profile-head { align-items: flex-start; flex-direction: column; }
.profile-section--logout .ant-btn { max-width: none; }
}
.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; } }
</style>