context.js
2.03 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
68
69
70
71
72
73
import { createPolicies } from './policies.js'
/**
* 构建权益首页菜单管道上下文
* @param {Object} [options]
* @param {Object} [options.userInfo]
* @param {boolean} [options.isStaff]
* @param {boolean} [options.mentorFlag]
* @param {number} [options.mode] - Component `properties.mode`,控制 defeat_order
* @param {Array} [options.merchantBrand] - 门店品牌列表,defeatOrder 跳转用
* @param {Object} [options.apiResults]
*/
export function createEquityMenuContext({
userInfo,
isStaff = false,
mentorFlag = false,
mode = 0,
merchantBrand = [],
apiResults = {}
} = {}) {
const app = typeof getApp === 'function' ? getApp() : null
const resolvedIsStaff = isStaff ?? !!app?.globalData?.isStaff
return {
userInfo: userInfo || {},
isStaff: resolvedIsStaff,
mentorFlag: !!mentorFlag,
mode: mode ?? 0,
merchantBrand: merchantBrand || [],
apiResults,
get policies() {
return createPolicies(this)
}
}
}
/**
* 菜单重建指纹(含 mode / mentorFlag / isStaff,供 onShow 脏标记扩展)
* @param {Object} [userInfo]
* @param {Object} [extra]
* @param {boolean} [extra.mentorFlag]
* @param {boolean} [extra.isStaff]
* @param {number} [extra.mode]
*/
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 mode = extra.mode !== undefined ? String(extra.mode) : '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,
mode
].join('|')
}
/** @alias getMenuFingerprint — 页面 rebuild 成功后提交指纹 */
export function buildMenuFingerprintKey(userInfo, extra = {}) {
return getMenuFingerprint(userInfo, extra)
}