功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -200,6 +200,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* AdminLayout 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, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
@@ -245,11 +249,14 @@ const router = useRouter()
|
||||
const route = useRoute()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
/** collapsed is a reactive state variable used by the template and event handlers. */
|
||||
const collapsed = ref(false)
|
||||
/** mobileDrawerOpen is a reactive state variable used by the template and event handlers. */
|
||||
const mobileDrawerOpen = ref(false)
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const selectedKeys = ref<string[]>([route.path])
|
||||
const selectedShopId = ref<string>()
|
||||
/** shopSwitchLoading is a reactive state variable used by the template and event handlers. */
|
||||
const shopSwitchLoading = ref(false)
|
||||
const { loadUserPermissions, hasPermission, clearPermissions, userPermissions } = usePermission()
|
||||
|
||||
@@ -265,6 +272,12 @@ const menuItems: AdminMenuItem[] = [
|
||||
{ key: '/admin/tags', icon: TagOutlined, label: '标签管理', permissionCode: 'tag:view' },
|
||||
{ key: '/admin/orders', icon: ShoppingOutlined, label: '订单管理', permissionCode: 'order:view' },
|
||||
{ key: '/admin/nail-artists', icon: TeamOutlined, label: '美甲师管理', permissionCode: 'nail_artist:view' }
|
||||
,
|
||||
{ key: '/admin/messages', icon: MessageOutlined, label: '消息发布', permissionCode: 'message:view' },
|
||||
{ key: '/admin/announcements', icon: MessageOutlined, label: '公告管理', permissionCode: 'announcement:view' },
|
||||
{ key: '/admin/vip-recharge-plans', icon: GiftOutlined, label: 'VIP充值配置', permissionCode: 'user:vip:manage' },
|
||||
{ key: '/admin/messagehub-push-configs', icon: MessageOutlined, label: '参数管理', permissionCode: 'messagehub:config:manage' },
|
||||
{ key: '/admin/legal-agreements', icon: SafetyCertificateOutlined, label: '协议管理', permissionCode: 'legal_agreement:manage' }
|
||||
]
|
||||
|
||||
const mobileTabs = [
|
||||
@@ -274,11 +287,19 @@ const mobileTabs = [
|
||||
{ key: 'profile', label: '我的', path: '/admin/profile', icon: UserOutlined }
|
||||
]
|
||||
|
||||
/** isBootstrapAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
/** isShopAuthorizationExpired is a reactive state variable used by the template and event handlers. */
|
||||
const isShopAuthorizationExpired = computed(() => Boolean(userInfo.value?.shopAuthorizationExpired))
|
||||
/** 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(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
|
||||
/** currentShopName is a reactive state variable used by the template and event handlers. */
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
/** roleLabel is a reactive state variable used by the template and event handlers. */
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
/** shopScopeText is a reactive state variable used by the template and event handlers. */
|
||||
const shopScopeText = computed(() => {
|
||||
if (!shopOptions.value.length) {
|
||||
return '游客模式'
|
||||
@@ -286,6 +307,7 @@ const shopScopeText = computed(() => {
|
||||
return `可登录门店:${shopOptions.value.map(shop => shop.name).join(' / ')}`
|
||||
})
|
||||
|
||||
/** filteredMenuItems is a reactive state variable used by the template and event handlers. */
|
||||
const filteredMenuItems = computed(() => {
|
||||
userPermissions.value
|
||||
let visibleItems = menuItems.filter(item => {
|
||||
@@ -300,9 +322,13 @@ const filteredMenuItems = computed(() => {
|
||||
if (isBootstrapAdmin.value) {
|
||||
visibleItems = visibleItems.filter(item => item.key === '/admin' || item.key === '/admin/shops')
|
||||
}
|
||||
if (isShopAuthorizationExpired.value && userInfo.value?.type !== 4) {
|
||||
visibleItems = visibleItems.filter(item => item.key === '/admin')
|
||||
}
|
||||
return visibleItems
|
||||
})
|
||||
|
||||
/** activeMobileTab is a reactive state variable used by the template and event handlers. */
|
||||
const activeMobileTab = computed(() => {
|
||||
if (route.path === '/admin' || route.path === '/admin/dashboard') {
|
||||
return 'workbench'
|
||||
@@ -329,6 +355,7 @@ const activeMobileTab = computed(() => {
|
||||
return 'workbench'
|
||||
})
|
||||
|
||||
/** currentMobileSectionLabel is a reactive state variable used by the template and event handlers. */
|
||||
const currentMobileSectionLabel = computed(() => {
|
||||
switch (activeMobileTab.value) {
|
||||
case 'orders':
|
||||
@@ -342,6 +369,7 @@ const currentMobileSectionLabel = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
/** currentMobileTitle is a reactive state variable used by the template and event handlers. */
|
||||
const currentMobileTitle = computed(() => {
|
||||
const currentMenu = menuItems.find(item => item.key === route.path)
|
||||
if (currentMenu) {
|
||||
@@ -356,6 +384,7 @@ const currentMobileTitle = computed(() => {
|
||||
return '后台管理'
|
||||
})
|
||||
|
||||
/** persistAdminSession is a local helper used by this page script. */
|
||||
const persistAdminSession = (payload: any) => {
|
||||
localStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
localStorage.setItem('adminRefreshToken', payload.refreshToken)
|
||||
@@ -363,29 +392,47 @@ const persistAdminSession = (payload: any) => {
|
||||
sessionStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
}
|
||||
|
||||
/** toggleCollapsed is a local helper used by this page script. */
|
||||
const toggleCollapsed = () => {
|
||||
collapsed.value = !collapsed.value
|
||||
}
|
||||
|
||||
/** handleMenuClick is a local helper used by this page script. */
|
||||
const handleMenuClick = (info: any) => {
|
||||
if (isShopAuthorizationExpired.value && userInfo.value?.type !== 4 && info.key !== '/admin') {
|
||||
message.warning('授权已到期,请联系管理员')
|
||||
return
|
||||
}
|
||||
router.push(info.key)
|
||||
}
|
||||
|
||||
/** openPathFromDrawer is a local helper used by this page script. */
|
||||
const openPathFromDrawer = (path: string) => {
|
||||
if (isShopAuthorizationExpired.value && userInfo.value?.type !== 4 && path !== '/admin' && path !== '/admin/profile') {
|
||||
message.warning('授权已到期,请联系管理员')
|
||||
return
|
||||
}
|
||||
mobileDrawerOpen.value = false
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
/** openProfileFromDrawer is a local helper used by this page script. */
|
||||
const openProfileFromDrawer = () => {
|
||||
openPathFromDrawer('/admin/profile')
|
||||
}
|
||||
|
||||
/** handleMobileTabClick is a local helper used by this page script. */
|
||||
const handleMobileTabClick = (path: string) => {
|
||||
if (isShopAuthorizationExpired.value && userInfo.value?.type !== 4 && path !== '/admin' && path !== '/admin/profile') {
|
||||
message.warning('授权已到期,请联系管理员')
|
||||
return
|
||||
}
|
||||
if (route.path !== path) {
|
||||
router.push(path)
|
||||
}
|
||||
}
|
||||
|
||||
/** handleLogout is a local helper used by this page script. */
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出登录',
|
||||
@@ -416,6 +463,7 @@ const handleLogout = () => {
|
||||
})
|
||||
}
|
||||
|
||||
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const cache = localStorage.getItem('adminUserInfo')
|
||||
@@ -431,6 +479,7 @@ const fetchUserInfo = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** 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
|
||||
|
||||
Reference in New Issue
Block a user