toViewModel.js
1.87 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
74
75
76
77
78
79
80
/**
* 将注册表条目转为权益 WXML 兼容的 view model
*
* - `label` 映射为 `menuText`(模板 `item.menuText`)
* - `action` 映射为 `path` / `navigateToUrl` / `params` 等过渡字段
* - `extras` 合并 provider 运行时字段(noRead、tipsNum 等)
*
* router 类型写 `path` 的方式:
* 1. `action.type` 为 `router` / `workReport` / `defeatOrder`
* 2. `action.target` 为 packageEquity.extract / salaryAppeal / missingReception 时硬编码写 path
* 3. `createOrderPrompt` 写空 `path`
*
* @param {Object} entry - registry 条目
* @param {Object} [extras] - provider 附加字段
* @returns {Object} 可直接 setData 的菜单项
*/
export function registryItemToViewModel(entry, extras = {}) {
const {
id,
label,
icon,
section,
sortVal,
action,
...rest
} = entry
const vm = {
id,
menuText: label,
icon,
section,
sortVal,
...rest,
...extras
}
if (action) {
vm.action = action
if (
action.type === 'router' ||
action.type === 'workReport' ||
action.type === 'defeatOrder'
) {
vm.path = action.target
}
if (action.type === 'createOrderPrompt') {
vm.path = ''
}
if (action.type === 'router' && action.params) {
vm.params = action.params
}
if (action.type === 'navigate') {
vm.navigateToUrl = action.target
if (action.trackEventCode) {
vm.trackEventCode = action.trackEventCode
}
}
if (action.type === 'residentTarget') {
vm.path = action.target
}
if (action.type === 'salaryPerformance') {
vm.path = action.target || ''
}
if (
action.type === 'router' &&
['packageEquity.extract', 'packageEquity.salaryAppeal', 'packageEquity.missingReception'].includes(
action.target
)
) {
vm.path = action.target
if (action.params) vm.params = action.params
}
if (action.type === 'router' && action.usePath) {
vm.path = action.target
}
}
return vm
}