Files
JayuCloud/JC-Salon-Frontend/src/views/admin/admin-helpers.ts
T

46 lines
1.9 KiB
TypeScript

/**
* Purpose: AdminCachedUserInfo supports admin-helpers.ts by holding or executing the admin cached user info page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { loadCachedAdminUserInfo, isBootstrapAdminUser, type AdminCachedUserInfo } from '@/utils/admin-session'
export { loadCachedAdminUserInfo, isBootstrapAdminUser }
export type { AdminCachedUserInfo }
/**
* Purpose: getAdminRoleLabel supports admin-helpers.ts by holding or executing the get admin role label 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.
*/
export const getAdminRoleLabel = (type?: number) => {
switch (type) {
case 4:
return '平台管理员'
case 2:
return '店长'
case 3:
return '店员'
default:
return '后台账号'
}
}
/**
* Purpose: getAdminShopOptions supports admin-helpers.ts by holding or executing the get admin shop options 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.
*/
export const getAdminShopOptions = (userInfo?: AdminCachedUserInfo | null) => {
const ids = userInfo?.shopIds || []
const names = userInfo?.shopNames || []
return ids.map((id, index) => ({
id: String(id),
name: names[index] || `门店 ${id}`
}))
}
/**
* Purpose: getAdminCurrentShopName supports admin-helpers.ts by holding or executing the get admin current shop name 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.
*/
export const getAdminCurrentShopName = (userInfo?: AdminCachedUserInfo | null) =>
userInfo?.shopName || (isBootstrapAdminUser(userInfo) ? '平台总览模式' : '游客模式')