jumpHandlers.js
5.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
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
/**
* 权益首页菜单跳转 Command Dispatcher(按 item.id / action.type)
*
* 点击时 shutDownTaskApi 副作用:
*
* | 触发方式 | 菜单 id | taskId | scene |
* |----------|---------|--------|-------|
* | `SHUTDOWN_TASK_BY_ID` | `training_materials` | 5 | 0 |
*
* 详见 packageEquity/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 { SCENE_TYPE } from './constants.js'
import { resolveActionType } from './resolveActionType.js'
import { openWorkReportTemp } from './workReportHandler.js'
import { openOrderPromptWithRestrictState } from '../../tabIndex/services/newOrderAbnormalFlowRestrict.service.js'
import { AI_ROUTES } from '../../router/routeAliases.js'
export { resolveActionType }
const SHUTDOWN_TASK_BY_ID = {
training_materials: 5
}
async function runStaffOrderChecks() {
let staffCheck = await checkDailyReport(true)
if (staffCheck) return true
let staffStudyTask = await checkStudyTask()
if (staffStudyTask) return true
let abnormalOrderCheck = await checkAbnormalOrder('pages.index')
if (abnormalOrderCheck) return true
return false
}
/**
* 创建页面绑定的菜单点击处理器
* @param {Object} page - packageEquity/pages/index Component 实例(需含 taskId、mentorFlag、merchantBrand)
* @returns {Function} 供 `navGo` 委托的 async dispatch 函数
*/
export function createEquityMenuJumpHandler(page) {
const handlers = {
workReport: async (item, ctx) => {
const { userInfo, mentorFlag } = ctx
if (
wx.$hasPermission?.canViewMentorship?.(userInfo) ||
mentorFlag
) {
wx.$track.setTrackData(0, 'supervisor_daily_page', {}, '', 0)
}
openWorkReportTemp(page, item)
},
navigate: async (item, ctx) => {
const { userInfo } = ctx
const code = item.trackEventCode || item.action?.trackEventCode
if (code === 'scenario_marketplace') {
wx.$track.setTrackData(0, 'scenario_marketplace', {}, '', 0)
}
const url = item.navigateToUrl || item.action?.target
trackDynamicFormMenuEntry(
url,
userInfo?.sceneType ?? SCENE_TYPE,
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.path || item.action?.target, {
id: ctx.taskId
})
},
createOrderPrompt: async (item, ctx) => {
if (await runStaffOrderChecks()) return
if (
item.beforeClick &&
(await wx.$globalDataFunction[item.beforeClick]())
) {
return
}
await openOrderPromptWithRestrictState(page)
},
defeatOrder: async (item, ctx) => {
const { merchantBrand } = ctx
let target = item.path || item.action?.target
if (
merchantBrand?.findIndex(i => ['鸿蒙智行'].includes(i.name)) == -1
) {
target = 'packageEquity.createDeafeatOrder'
}
if (await runStaffOrderChecks()) return
wx.$router.go(target, {
scene: SCENE_TYPE,
params: item.params || item.action?.params || {}
})
},
router: async (item, ctx) => {
const { userInfo } = ctx
const target = item.path || item.action?.target
const routerParams = item.params || item.action?.params || {}
if (item.id === 'customer_clue' || target === 'packageEquity.clueList') {
wx.$track.setTrackData(0, 'leads_page', {}, '', 0)
}
if (target === AI_ROUTES.aiCheckStart || target === 'packageEquity.start') {
wx.$track.setTrackData(0, 'aiCheck_page', {}, '', 0)
}
if (target === 'tabWorkOrder.mentorshipManage' &&
wx.$hasPermission?.canViewMentorship?.(userInfo)) {
wx.$track.setTrackData(0, 'mentorship_page', {}, '', 0)
}
if (target === 'packageEquity.receptionRecords') {
wx.$track.setTrackData(0, 'reception_records', {}, '', 0)
}
const shutdownTaskId = SHUTDOWN_TASK_BY_ID[item.id]
if (shutdownTaskId) {
commonApi.shutDownTaskApi({
merchantId: userInfo?.default4SStoreInfo?.merchantId,
staffUuid: userInfo?.uuid,
scene: SCENE_TYPE,
taskId: shutdownTaskId
})
}
if (
item.id === 'pending_approval' ||
item.id === 'abnormal_flow_approval'
) {
return wx.$router.go(target)
}
if (
['packageEquity.extract', 'packageEquity.salaryAppeal', 'packageEquity.missingReception'].includes(
target
) ||
item.params
) {
return wx.$router.go(target, { params: routerParams })
}
return wx.$router.go(target, {
scene: SCENE_TYPE,
params: routerParams
})
}
}
return async function dispatchEquityMenuJump(e) {
const { item } = e.currentTarget.dataset
const { userInfo, taskId, mentorFlag, merchantBrand } = page.data
const ctx = { userInfo, taskId, mentorFlag, merchantBrand }
const actionType = resolveActionType(item)
const handler = handlers[actionType] || handlers.router
return handler(item, ctx)
}
}