重构Salon后台系统设置并整合个人账号信息

This commit is contained in:
2026-10-25 20:34:15 +08:00
parent c1b282d465
commit 76917d92ad
7 changed files with 443 additions and 529 deletions
+58 -202
View File
@@ -1,186 +1,67 @@
<template>
<div class="admin-profile">
<section class="admin-page-intro">
<span class="admin-page-intro__eyebrow">{{ userInfo?.account || '后台账号' }}</span>
<h1 class="admin-page-intro__title">{{ userInfo?.nickname || '未设置昵称' }}</h1>
<div class="admin-page-intro__meta">
<span class="admin-page-chip">权限 {{ permissionCount }}</span>
<span class="admin-page-chip">门店 {{ shopOptions.length || 0 }}</span>
<span class="admin-page-chip">{{ roleLabel }}</span>
<span v-if="isPlatformOverview" class="admin-page-chip">平台总览</span>
<section class="profile-head">
<div>
<span class="profile-eyebrow">后台账号</span>
<h1>{{ userInfo?.nickname || '未设置昵称' }}</h1>
<p>{{ userInfo?.account || '当前登录账号' }} · {{ roleLabel }}</p>
</div>
<span class="profile-chip">{{ isPlatformOverview ? '平台总览' : currentShopName }}</span>
</section>
<div class="admin-mobile-grid admin-mobile-grid--two">
<section class="admin-mobile-stat">
<div class="admin-mobile-stat__label">当前门店</div>
<div class="admin-mobile-stat__value">{{ currentShopName }}</div>
</section>
<section class="admin-mobile-stat">
<div class="admin-mobile-stat__label">角色</div>
<div class="admin-mobile-stat__value">{{ roleLabel }}</div>
</section>
</div>
<section class="admin-mobile-section-card">
<div class="admin-mobile-section-card__title">账号信息</div>
<div class="profile-meta-list">
<div class="profile-meta-list__row">
<span>账号</span>
<strong>{{ userInfo?.account || '--' }}</strong>
</div>
<div class="profile-meta-list__row">
<span>昵称</span>
<strong>{{ userInfo?.nickname || '--' }}</strong>
</div>
<div class="profile-meta-list__row">
<span>权限数量</span>
<strong>{{ permissionCount }}</strong>
</div>
<div class="profile-meta-list__row">
<span>可登录门店</span>
<strong>{{ shopScopeText }}</strong>
<section class="profile-section">
<div class="profile-section__head">
<div>
<h2>账号与门店</h2>
<p>账号资料、权限范围和门店切换已集中到系统设置。</p>
</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="admin-mobile-section-card">
<div class="admin-mobile-section-card__title">{{ isPlatformOverview ? '管理范围' : '门店切换' }}</div>
<div v-if="isPlatformOverview" class="profile-static-shop">
平台总览模式,店铺业务仅可查看
<section class="profile-section">
<div class="profile-section__head">
<div>
<h2>常用入口</h2>
<p>继续处理日常经营工作。</p>
</div>
</div>
<a-select
v-else-if="shopOptions.length > 1"
v-model:value="selectedShopId"
class="profile-shop-select"
:options="shopSelectOptions"
:loading="shopSwitchLoading"
@change="handleShopChange"
/>
<div v-else class="profile-static-shop">
{{ currentShopName }}
</div>
</section>
<section class="admin-mobile-section-card">
<div class="admin-mobile-section-card__title">常用入口</div>
<div class="profile-actions">
<a-button type="default" size="large" block @click="router.push('/admin/orders')">查看订单</a-button>
<a-button type="default" size="large" block @click="router.push('/admin/manage')">进入经营模块</a-button>
<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>
</section>
<section class="admin-mobile-section-card">
<div class="admin-mobile-section-card__title">退出登录</div>
<section class="profile-section profile-section--logout">
<div class="profile-section__head">
<div>
<h2>退出登录</h2>
<p>退出后需要重新登录后台。</p>
</div>
</div>
<a-button danger size="large" block @click="handleLogout">退出当前账号</a-button>
</section>
</div>
</template>
<script setup lang="ts">
/**
* ProfileView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, onMounted, ref } from 'vue'
import { computed, ref } from 'vue'
import { useRouter } from 'vue-router'
import { message, Modal } from 'ant-design-vue'
import { adminAuthApi } from '@/api/admin'
import { usePermission } from '@/utils/permission'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { notifyShopThemeChanged } from '@/utils/shop-theme'
import { completeAdminLogout } from '@/utils/admin-logout'
import {
getAdminCurrentShopName,
getAdminRoleLabel,
getAdminShopOptions,
isBootstrapAdminUser,
loadCachedAdminUserInfo
} from './admin-helpers'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { getAdminCurrentShopName, getAdminRoleLabel, isBootstrapAdminUser, loadCachedAdminUserInfo } from './admin-helpers'
/**
* Purpose: router supports ProfileView.vue by holding or executing the router page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const router = useRouter()
const { userPermissions, loadUserPermissions } = usePermission()
/** userInfo is a reactive state variable used by the template and event handlers. */
const userInfo = ref(loadCachedAdminUserInfo())
/** selectedShopId is a reactive state variable used by the template and event handlers. */
const selectedShopId = ref(userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined)
/** shopSwitchLoading is a reactive state variable used by the template and event handlers. */
const shopSwitchLoading = ref(false)
/** currentShopName is a reactive state variable used by the template and event handlers. */
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
/**
* Purpose: isPlatformOverview supports ProfileView.vue by holding or executing the is platform overview page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const isPlatformOverview = computed(() => isBootstrapAdminUser(userInfo.value))
/** roleLabel is a reactive state variable used by the template and event handlers. */
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
/** shopOptions is a reactive state variable used by the template and event handlers. */
const shopOptions = computed(() => getAdminShopOptions(userInfo.value))
/** shopSelectOptions is a reactive state variable used by the template and event handlers. */
const shopSelectOptions = computed(() => {
const options = shopOptions.value.map(shop => ({ label: shop.name, value: shop.id }))
return options
})
/** permissionCount is a reactive state variable used by the template and event handlers. */
const permissionCount = computed(() => userPermissions.value.length)
/** shopScopeText is a reactive state variable used by the template and event handlers. */
const shopScopeText = computed(() => {
if (!shopOptions.value.length) {
return isPlatformOverview.value ? '平台总览模式' : '游客模式'
}
return shopOptions.value.map(item => item.name).join(' / ')
})
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
const isPlatformOverview = computed(() => isBootstrapAdminUser(userInfo.value))
/** persistAdminSession is a local helper used by this page script. */
const persistAdminSession = (payload: any) => {
localStorage.setItem('adminAccessToken', payload.accessToken)
localStorage.setItem('adminRefreshToken', payload.refreshToken)
localStorage.setItem('adminUserInfo', JSON.stringify(payload.userInfo))
sessionStorage.setItem('adminAccessToken', payload.accessToken)
}
/** refreshLocalUserInfo is a local helper used by this page script. */
const refreshLocalUserInfo = () => {
userInfo.value = loadCachedAdminUserInfo()
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
}
/** handleShopChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleShopChange = async (shopId: unknown) => {
if (typeof shopId !== 'string' && typeof shopId !== 'number') {
return
}
const normalizedShopId = String(shopId)
if (!normalizedShopId || normalizedShopId === String(userInfo.value?.shopId || '')) {
return
}
shopSwitchLoading.value = true
try {
await runWithGlobalLoading(async () => {
const response = await adminAuthApi.switchShop(normalizedShopId)
persistAdminSession(response as any)
refreshLocalUserInfo()
await loadUserPermissions()
notifyShopThemeChanged()
})
message.success('门店切换成功')
window.location.reload()
} catch (error: any) {
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
message.error(error?.message || '切换门店失败')
} finally {
shopSwitchLoading.value = false
}
}
/** handleLogout is a local helper used by this page script. */
const handleLogout = () => {
Modal.confirm({
title: '确认退出登录',
@@ -195,55 +76,30 @@ const handleLogout = () => {
}
})
}
onMounted(async () => {
refreshLocalUserInfo()
await loadUserPermissions()
})
</script>
<style scoped>
.admin-profile {
display: grid;
gap: 18px;
}
.profile-meta-list {
display: grid;
gap: 10px;
margin-top: 14px;
}
.profile-meta-list__row {
display: flex;
justify-content: space-between;
gap: 12px;
color: var(--text-secondary);
}
.profile-meta-list__row strong {
color: var(--admin-mobile-ink);
}
.profile-shop-select {
width: 100%;
margin-top: 14px;
}
.profile-static-shop {
margin-top: 14px;
min-height: 46px;
display: flex;
align-items: center;
padding: 0 14px;
border-radius: 16px;
background: var(--admin-mobile-accent-soft);
color: var(--admin-mobile-ink);
}
.profile-actions {
display: grid;
gap: 10px;
margin-top: 14px;
.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 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; }
}
</style>