重构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
@@ -110,8 +110,8 @@
<section v-else class="settings-section-panel">
<div class="pane-head">
<div>
<h2>当前账号</h2>
<p>查看后台账号、权限范围和当前门店,不与小程序账号设置混用。</p>
<h2>管理员账号</h2>
<p>查看后台登录账号与当前会话状态。</p>
</div>
<span class="account-status"><i />会话正常</span>
</div>
@@ -128,27 +128,10 @@
<div class="setting-value">{{ userInfo?.nickname || '未设置昵称' }}</div>
<span class="control-note">只读</span>
</div>
<div class="setting-row">
<div class="setting-copy"><strong>角色</strong><span>当前后台角色与平台管理范围。</span></div>
<div class="setting-value">{{ roleLabel }}</div>
<span v-if="isPlatformOverview" class="status-pill">平台总览</span>
<span v-else class="control-note">只读</span>
</div>
<div class="setting-row setting-row--last">
<div class="setting-copy"><strong>权限范围</strong><span>当前账号可访问的功能权限数量。</span></div>
<div class="setting-value">{{ permissionCount }} 项权限</div>
<span class="control-note">{{ shopScopeText }}</span>
</div>
</div>
<div class="setting-group">
<div class="setting-group__head"><strong>{{ isPlatformOverview ? '管理范围' : '当前门店' }}</strong><span>SHOP</span></div>
<div class="setting-row setting-row--last">
<div class="setting-copy"><strong>{{ isPlatformOverview ? '平台总览模式' : '门店上下文' }}</strong><span>{{ isPlatformOverview ? '平台管理员可查看全平台数据。' : '切换后会刷新权限和业务数据上下文。' }}</span></div>
<div v-if="isPlatformOverview" class="setting-value">平台总览模式</div>
<a-select v-else-if="shopOptions.length > 1" v-model:value="selectedShopId" class="account-shop-select" :options="shopSelectOptions" :loading="shopSwitchLoading" @change="handleShopChange" />
<div v-else class="setting-value">{{ currentShopName }}</div>
<span class="control-note">{{ shopOptions.length > 1 ? `${shopOptions.length} 家可用门店` : '当前会话' }}</span>
<div class="setting-copy"><strong>后台会话</strong><span>后台请求使用管理员身份校验,退出登录后当前会话立即失效。</span></div>
<div class="setting-value">{{ userInfo?.id ? '已登录' : '状态未知' }}</div>
<span class="status-pill" :class="{ 'is-muted': !userInfo?.id }">{{ userInfo?.id ? '正常' : '待验证' }}</span>
</div>
</div>
</section>
@@ -158,15 +141,12 @@
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { onMounted, reactive, ref } from 'vue'
import { useRoute } from 'vue-router'
import { message } from 'ant-design-vue'
import { ApiOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons-vue'
import { adminAuthApi, adminSystemParameterConfigApi, type SystemParameterConfigVO } from '@/api/admin'
import { usePermission } from '@/utils/permission'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { notifyShopThemeChanged } from '@/utils/shop-theme'
import { getAdminCurrentShopName, getAdminRoleLabel, getAdminShopOptions, isBootstrapAdminUser, loadCachedAdminUserInfo } from './admin-helpers'
import { adminSystemParameterConfigApi, type SystemParameterConfigVO } from '@/api/admin'
import { loadCachedAdminUserInfo } from '@/utils/admin-session'
type SettingsSection = 'runtime' | 'services' | 'account'
type MapKey = 'tencentWeb' | 'amapWeb' | 'amapMini'
@@ -178,7 +158,6 @@ const savingDefaultPassword = ref(false)
const savingReviewNotice = ref(false)
const savingMap = ref(false)
const savingSmsProvider = ref(false)
const shopSwitchLoading = ref(false)
const defaultPasswordEnabled = ref(true)
const reviewNoticeEnabled = ref(true)
const mapEnabled = ref(true)
@@ -221,27 +200,6 @@ const mapForms = reactive<Record<MapKey | 'provider', SystemParameterConfigVO>>(
})
const userInfo = ref(loadCachedAdminUserInfo())
const selectedShopId = ref(userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined)
const { userPermissions, loadUserPermissions } = usePermission()
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
const isPlatformOverview = computed(() => isBootstrapAdminUser(userInfo.value))
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
const shopOptions = computed(() => getAdminShopOptions(userInfo.value))
const shopSelectOptions = computed(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
const permissionCount = computed(() => userPermissions.value.length)
const shopScopeText = computed(() => shopOptions.value.length ? shopOptions.value.map(item => item.name).join(' / ') : (isPlatformOverview.value ? '平台总览模式' : '游客模式'))
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)
}
const refreshLocalUserInfo = () => {
userInfo.value = loadCachedAdminUserInfo()
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
}
const load = async () => {
loading.value = true
@@ -271,8 +229,7 @@ const load = async () => {
if (mapByKey.AMAP_MINI_KEY) Object.assign(mapForms.amapMini, mapByKey.AMAP_MINI_KEY)
mapForms.provider.configValue = mapForms.provider.configValue === 'AMAP' ? 'AMAP' : 'TENCENT'
mapEnabled.value = mapForms.provider.enabled === 1
refreshLocalUserInfo()
await loadUserPermissions()
userInfo.value = loadCachedAdminUserInfo()
} catch (error) {
message.error(error instanceof Error ? error.message : '系统设置加载失败')
} finally {
@@ -348,27 +305,6 @@ const saveSmsProvider = async () => {
}
}
const handleShopChange = async (shopId: unknown) => {
if ((typeof shopId !== 'string' && typeof shopId !== 'number') || !String(shopId) || String(shopId) === String(userInfo.value?.shopId || '')) return
shopSwitchLoading.value = true
try {
await runWithGlobalLoading(async () => {
const response = await adminAuthApi.switchShop(String(shopId))
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
}
}
onMounted(() => {
void load()
})
@@ -418,7 +354,6 @@ onMounted(() => {
.warning-note { display: inline-flex; align-items: center; gap: 5px; color: #a66d22; font-size: 11px; white-space: nowrap; }
.warning-note::before { content: '!'; display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 50%; background: #fff3d9; font-size: 10px; font-weight: 800; }
.section-footnote { margin: 12px 2px 0; color: var(--admin-mobile-muted); font-size: 11px; }
.account-shop-select { width: 100%; min-width: 0; }
@media (max-width: 760px) {
.settings-header { align-items: flex-start; }
.settings-health, .account-status { display: none; }