policies.js
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { effectiveLoginRole } from '../../utils/rolePermission.js'
import { getSpecialAccountChecklist } from './constants.js'
const perm = () => wx?.$hasPermission || {}
/**
* 从 MenuContext 派生可组合权限谓词,供 registry `visible(ctx)` 使用
*
* @param {Object} ctx - createMenuContext 返回值
* @returns {Record<string, () => boolean>}
*/
export function createPolicies(ctx) {
const { userInfo, isStaff, mentorFlag } = ctx
const p = perm()
return {
/** 技师 loginRole=7 */
isTechnician: () => p.isTechnician?.(userInfo),
/** 超管 */
isSuper: () => p.isSuper?.(userInfo),
/** 非驻店(loginRole != 4) */
isNoStaff: () => userInfo?.loginRole != 4 && userInfo?.loginRole != null,
/** 非飞行督导 */
isNotMentor: () => p.isNotMentor?.(userInfo),
/** 可多选门店(督导/超管等) */
canSelectMultiStore: () => p.canSelectMultiStore?.(userInfo),
/** 驻店日报相关权限 */
canSelectMultiStoreForStaffDaily: () =>
p.canSelectMultiStoreForStaffDaily?.(userInfo),
canViewMentorship: () => p.canViewMentorship?.(userInfo),
canViewRecruit: () => p.canViewRecruit?.(userInfo),
canViewViolation: () => p.canViewViolation?.(userInfo),
/** 员工或具备驻店日报督导权限 */
staffOrMultiStoreDaily: () =>
isStaff || p.canSelectMultiStoreForStaffDaily?.(userInfo),
notTechnician: () => !p.isTechnician?.(userInfo),
/** 驻店负责人或员工 */
isResidentOrStaff: () => {
const role =
userInfo?.subLoginUser?.loginRole ?? userInfo?.loginRole
return role === 4 || isStaff
},
/** 不在特殊账号白名单 */
notSpecialAccount: () =>
!getSpecialAccountChecklist().includes(userInfo?.accountName),
/** 非冀联园区 channelType!=9 */
notJiLianChannel: () => userInfo?.subLoginUser?.channelType != 9,
/** 违规查看权限或导师 */
mentorOrViolation: () =>
p.canViewViolation?.(userInfo) || mentorFlag
}
}