context.js
1.83 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { createPolicies } from './policies.js'
/**
* 构建菜单管道上下文
* @param {Object} [options]
* @param {Object} [options.userInfo]
* @param {boolean} [options.isStaff]
* @param {boolean} [options.mentorFlag]
* @param {Object} [options.apiResults]
*/
export function createMenuContext({
userInfo,
isStaff = false,
mentorFlag = false,
apiResults = {}
} = {}) {
const app = typeof getApp === 'function' ? getApp() : null
const resolvedIsStaff = isStaff ?? !!app?.globalData?.isStaff
return {
userInfo: userInfo || {},
isStaff: resolvedIsStaff,
mentorFlag: !!mentorFlag,
apiResults,
get policies() {
return createPolicies(this)
}
}
}
/**
* 菜单重建指纹(含 mentorFlag / isStaff / includeCustomerClue,供 onShow 脏标记)
* @param {Object} [userInfo]
* @param {Object} [extra]
* @param {boolean} [extra.mentorFlag]
* @param {boolean} [extra.isStaff]
* @param {boolean} [extra.includeCustomerClue] - 园区员工客户线索 provider
*/
export function getMenuFingerprint(userInfo = {}, extra = {}) {
const app = typeof getApp === 'function' ? getApp() : null
const isStaff =
extra.isStaff !== undefined
? extra.isStaff
: !!app?.globalData?.isStaff
const mentorFlag = extra.mentorFlag ? '1' : '0'
const includeCustomerClue = extra.includeCustomerClue ? '1' : '0'
return [
userInfo.uuid,
userInfo.shopMerchantId,
userInfo.merchantId,
userInfo.default4SStoreInfo?.merchantId,
userInfo.loginRole,
userInfo.loginRoleOnSelectMerchant,
userInfo.subLoginUser?.loginRole,
userInfo.subLoginUser?.channelType,
userInfo.isSuper,
isStaff ? '1' : '0',
mentorFlag,
includeCustomerClue
].join('|')
}
/** @alias getMenuFingerprint — 页面 rebuild 成功后提交指纹 */
export function buildMenuFingerprintKey(userInfo, extra = {}) {
return getMenuFingerprint(userInfo, extra)
}