jumpHandlers.js
7.15 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/**
* 精品首页菜单跳转 Command Dispatcher(按 item.id / action.type,无 name 回退)
*
* 点击时 shutDownTaskApi 副作用(taskId 不在 registry,见下表):
*
* | 触发方式 | 菜单 id / handler | taskId |
* |----------|-------------------|--------|
* | `SHUTDOWN_TASK_BY_ID` | `training_materials` | 5 |
* | `marketingMaterials` handler | `marketing_materials` | 6(硬编码) |
*
* 详见 tabIndex/docs/MENU-ARCHITECTURE.md「跳转副作用」。
*/
import commonApi from '../../api/api.js'
import {
checkDailyReport,
checkStudyTask,
checkAbnormalOrder
} from '../../store/ModalToQueueControl.js'
import { trackDynamicFormMenuEntry } from '../../utils/dynamicFormMenus.js'
import { resolveActionType } from './resolveActionType.js'
import { openWorkReportTemp } from './workReportHandler.js'
import { openOrderPromptWithRestrictState } from '../services/newOrderAbnormalFlowRestrict.service.js'
export { resolveActionType }
/** 使用 path + params 跳转、跳过员工锁单校验的菜单 id */
const ROUTER_PATH_PARAM_IDS = new Set([
'script_extract',
'script_verify',
'missing_reception',
'salary_appeal'
])
/** 跳过员工锁单校验、直接 router.go 的菜单 id */
const ROUTER_DIRECT_IDS = new Set([
'pending_approval',
'abnormal_flow_approval'
])
/** 点击前需 shutDownTaskApi 的菜单 id → taskId */
const SHUTDOWN_TASK_BY_ID = {
training_materials: 5
}
function getAppSafe() {
return typeof getApp === 'function' ? getApp() : null
}
/**
* 创建页面绑定的菜单点击处理器
* @param {Object} page - tabIndex 首页 Page 实例
* @returns {Function}
*/
export function createMenuJumpHandler(page) {
const handlers = {
workReport: async (item, ctx) => {
const { userInfo, mentorFlag } = ctx
if (
wx.$hasPermission?.canViewMentorship?.(userInfo) ||
mentorFlag
) {
wx.$track.setTrackData(0, 'supervisor_daily_page', {}, '', 1)
}
openWorkReportTemp(page, item)
},
switchTab: async (item) => {
wx.$util.pointRecord(item.recordId)
if (item.isRepairOrderTabFromMenu) {
const app = getAppSafe()
if (app) app.globalData.repairOrderOpenFromHomeMenu = true
}
return wx.switchTab({ url: item.action?.target || item.url })
},
navigate: async (item, ctx) => {
const { userInfo } = ctx
const code = item.trackEventCode || item.action?.trackEventCode
if (code === 'scenario_marketplace') {
wx.$track.setTrackData(0, 'scenario_marketplace', {}, '', 1)
}
const url = item.navigateToUrl || item.action?.target
trackDynamicFormMenuEntry(
url,
userInfo?.sceneType ?? 1,
item.trackEventCode
)
return wx.navigateTo({ url })
},
salaryPerformance: async () => {
return wx.$router.go('packageEquity.collegeScene', {
reLaunchPath: 'packageEquity.equityPage',
tabIndex: 0
})
},
residentTarget: async (item, ctx) => {
return wx.$router.go(item.url || item.action?.target, {
id: ctx.taskId
})
},
marketingMaterials: async (item, ctx) => {
const { userInfo } = ctx
commonApi.shutDownTaskApi({
merchantId: userInfo?.default4SStoreInfo?.merchantId,
staffUuid: userInfo?.uuid,
scene: 1,
taskId: 6
})
return wx.navigateTo({ url: item.url || item.action?.target })
},
miniProgram: async (item) => {
const action = item.action || {}
return wx.navigateToMiniProgram({
appId: action.appId || 'wx2c28337db96364d2',
path: action.path || 'pages/tab/index/index',
envVersion: action.envVersion || 'trial',
success() {}
})
},
scanCode: async (item, ctx) => {
return handleStaffGatedAction(page, item, ctx, async () => {
if (await wx.$globalDataFunction.inspectionOfProhibitionBill()) return
wx.scanCode({
success(res) {
page.showSelectType({ scene: res.result })
}
})
})
},
router: async (item, ctx) => {
const { userInfo } = ctx
const target = item.path || item.action?.target || item.url
const routerParams = item.params || item.action?.params || {}
if (item.id === 'customer_clue' || target === 'packageEquity.clueList') {
wx.$track.setTrackData(0, 'leads_page', {}, '', 1)
}
if (
target === 'tabWorkOrder.mentorshipManage' &&
wx.$hasPermission?.canViewMentorship?.(userInfo)
) {
wx.$track.setTrackData(0, 'mentorship_page', {}, '', 1)
}
const shutdownTaskId = SHUTDOWN_TASK_BY_ID[item.id]
if (shutdownTaskId) {
commonApi.shutDownTaskApi({
merchantId: userInfo?.default4SStoreInfo?.merchantId,
staffUuid: userInfo?.uuid,
scene: userInfo?.sceneType ?? 1,
taskId: shutdownTaskId
})
}
if (ROUTER_DIRECT_IDS.has(item.id)) {
return wx.$router.go(target)
}
if (ROUTER_PATH_PARAM_IDS.has(item.id) || item.path) {
return wx.$router.go(target, { params: routerParams })
}
return handleStaffGatedAction(page, item, ctx, async () => {
if (
item.beforeClick &&
(await wx.$globalDataFunction[item.beforeClick]())
) {
return
}
if (target === 'tabWorkOrder.createOrder') {
await openOrderPromptWithRestrictState(page, { sceneObj: {} })
} else {
wx.$router.go(target, { params: routerParams })
}
})
}
}
return async function dispatchMenuJump(e) {
let { item, type } = e.currentTarget.dataset
let { userInfo, taskId, mentorFlag } = page.data
if (userInfo?.merchantAccountList?.length) {
try {
userInfo.merchantAccountList.map(acc => {
if (acc == 6 || acc == 8) throw true
})
} catch (error) {
userInfo.merchantType = error
}
}
const ctx = { userInfo, type, taskId, mentorFlag }
const actionType = resolveActionType(item)
const handler = handlers[actionType] || handlers.router
return handler(item, ctx)
}
}
async function handleStaffGatedAction(page, item, ctx, actionFn) {
const { userInfo, type } = ctx
const isStaffMerchant =
userInfo?.merchantType && !wx.$hasPermission?.isSuper?.(userInfo)
if (isStaffMerchant && type == 2) {
wx.$util.pointRecord(item.recordId)
if (item.type === 'scanCode' || item.action?.type === 'scanCode') {
let staffCheck = await checkDailyReport()
if (staffCheck) return false
let staffStudyTask = await checkStudyTask()
if (staffStudyTask) return false
let abnormalOrderCheck = await checkAbnormalOrder('pages.index')
if (abnormalOrderCheck) return false
} else if (item.type === 'mini' || item.action?.type === 'miniProgram') {
return wx.navigateToMiniProgram({
appId: 'wx2c28337db96364d2',
path: 'pages/tab/index/index',
envVersion: 'trial',
success() {}
})
} else {
if (!item.noCheckdailyReport) {
let staffCheck = await checkDailyReport()
if (staffCheck) return false
let staffStudyTask = await checkStudyTask()
if (staffStudyTask) return false
let abnormalOrderCheck = await checkAbnormalOrder('pages.index')
if (abnormalOrderCheck) return false
}
}
return actionFn()
}
const target = item.url || item.action?.target
if (
![
'tabWorkOrder.createOrder',
'tabWorkOrder.createArchives',
'tabWorkOrder.defeatOrder'
].includes(target)
) {
wx.$util.pointRecord(item.recordId)
return wx.$router.go(target, {
scene: 1,
params: item.params || item.action?.params || {}
})
}
wx.$util.showNoAccess()
}