toViewModel.js
2.06 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
81
82
83
/**
* 将注册表条目转为 WXML 兼容的 view model
*
* - `label` 映射为 `name`(模板仍用 item.name)
* - `action` 映射为 url / path / navigateToUrl / type 等过渡字段
* - `extras` 合并 provider 运行时字段(noRead、tipsNum 等,见 registry MenuViewModelExtras)
*
* router 类型写 `path` 的两种方式:
* 1. `action.usePath === true`(如 pending_approval)
* 2. `action.target` 为下列路由时硬编码写 path(与 usePath 无关):
* packageEquity.extract | packageEquity.salaryAppeal | packageEquity.missingReception
*
* @param {Object} entry - registry 条目
* @param {Object} [extras] - provider 附加字段(如 noRead、tipsNum)
* @returns {Object} 可直接 setData 的菜单项
*/
export function registryItemToViewModel(entry, extras = {}) {
const {
id,
label,
icon,
section,
sortVal,
action,
...rest
} = entry
const vm = {
id,
name: label,
icon,
section,
sortVal,
...rest,
...extras
}
if (action) {
vm.action = action
if (action.type === 'router' || action.type === 'workReport') {
vm.url = action.target
if (action.usePath) {
vm.path = action.target
}
}
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 === 'scanCode') {
vm.url = action.target
vm.type = 'scanCode'
}
if (action.type === 'miniProgram') {
vm.type = 'mini'
}
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 === 'residentTarget') {
vm.url = action.target
}
if (action.type === 'marketingMaterials') {
vm.url = action.target
}
if (action.type === 'switchTab') {
vm.isRepairOrderTabFromMenu = rest.isRepairOrderTabFromMenu ?? true
}
}
return vm
}