@conecli/cone-render 0.9.1-shop2.12 → 0.9.1-shop2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
2
1
|
isH5AndJdShopView,
|
|
3
2
|
isJdApp,
|
|
4
3
|
isIosDevice,
|
|
5
4
|
isAndroidDevice,
|
|
6
5
|
isJdAndIosDevice,
|
|
7
6
|
isJdAndAndroidDevice,
|
|
8
7
|
jdAppVersionCompare,
|
|
9
8
|
isAppStowShop,
|
|
10
9
|
androidTouchSlop: 5,
|
|
11
10
|
getAndroidTouchSlopState: false,
|
|
12
11
|
(state) => {
|
|
13
12
|
console.log(
|
|
14
13
|
'document trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:',
|
|
15
14
|
state,
|
|
16
15
|
)
|
|
17
16
|
Taro.eventCenter.trigger(
|
|
18
17
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
19
18
|
state ? 0 : 1,
|
|
20
19
|
)
|
|
21
20
|
},
|
|
22
21
|
1500,
|
|
23
22
|
{ leading: false, trailing: true },
|
|
24
23
|
(state) => {
|
|
25
24
|
console.log(
|
|
26
25
|
'IOS Android trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:',
|
|
27
26
|
state,
|
|
28
27
|
)
|
|
29
28
|
Taro.eventCenter.trigger(
|
|
30
29
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
31
30
|
state,
|
|
32
31
|
)
|
|
33
32
|
},
|
|
34
33
|
1500,
|
|
35
34
|
{ leading: true, trailing: false },
|
|
36
35
|
if (!isJdApp) {
|
|
37
36
|
if (isH5) {
|
|
38
37
|
|
|
39
38
|
const documentHandleVisibilityChange = () => {
|
|
40
39
|
const state = document.hidden
|
|
41
40
|
window.startDocumentVisibilityChange && documentThrottledTrigger(state)
|
|
42
41
|
}
|
|
43
42
|
document.removeEventListener(
|
|
44
43
|
'visibilitychange',
|
|
45
44
|
documentHandleVisibilityChange,
|
|
46
45
|
)
|
|
47
46
|
console.log('每次进入页面先清除浏览器visibilitychange监听事件')
|
|
48
47
|
setTimeout(() => {
|
|
49
48
|
document.addEventListener(
|
|
50
49
|
'visibilitychange',
|
|
51
50
|
documentHandleVisibilityChange,
|
|
52
51
|
false,
|
|
53
52
|
)
|
|
54
53
|
window.startDocumentVisibilityChange = true
|
|
55
54
|
}, 3000)
|
|
56
55
|
}
|
|
57
56
|
} else {
|
|
58
57
|
|
|
59
58
|
!window.webviewVisible &&
|
|
60
59
|
(window.webviewVisible = (state) => {
|
|
61
60
|
window.startDocumentVisibilityChange && webviewThrottledTrigger(state)
|
|
62
61
|
state === 1 && taroEventSendPageScrollInfo()
|
|
63
62
|
})
|
|
64
63
|
setTimeout(() => {
|
|
65
64
|
window.startDocumentVisibilityChange = true
|
|
66
65
|
}, 3000)
|
|
67
66
|
!window.floatReceiveData && (window.floatReceiveData = () => {})
|
|
68
67
|
}
|
|
69
68
|
MESSAGE_HOME_INIT: 'messageHomeInitPageData',
|
|
70
69
|
[Message_CallBack_Name.MESSAGE_HOME_INIT]: {},
|
|
71
70
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = {
|
|
72
71
|
displayHeight: 1920,
|
|
73
72
|
offSetY: 0,
|
|
74
73
|
}
|
|
75
74
|
if (options) {
|
|
76
75
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = options
|
|
77
76
|
}
|
|
78
77
|
const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
|
|
79
78
|
Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL, options || latestRes)
|
|
80
79
|
console.log('PageScrollEnd fire')
|
|
81
80
|
Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL_END, options)
|
|
82
81
|
const { businessType } = options
|
|
83
82
|
switch (businessType) {
|
|
84
83
|
case H5_MSG_TO_H5_BUSINESSTYPE.JOIN_MEMBER_SUCCESS:
|
|
85
84
|
Taro.eventCenter.trigger(TaroEventType.JOIN_MEMBER_SUCCESS, options)
|
|
86
85
|
break
|
|
87
86
|
default:
|
|
88
87
|
break
|
|
89
88
|
}
|
|
90
89
|
const { shopHomeExtendInfo } = options
|
|
91
90
|
if (shopHomeExtendInfo) {
|
|
92
91
|
Taro.eventCenter.trigger(
|
|
93
92
|
TaroEventType.UPDATE_SHOP_HOME_EXTEND_DATA,
|
|
94
93
|
shopHomeExtendInfo,
|
|
95
94
|
)
|
|
96
95
|
}
|
|
97
96
|
window && window.scrollTo(0, 0)
|
|
98
97
|
Taro.eventCenter.trigger(TaroEventType.PAGE_INIT_EXPOSURE, options)
|
|
99
98
|
const { action, params } = options
|
|
100
99
|
console.log('taroEventShopStowSend', options)
|
|
101
100
|
if (action) {
|
|
102
101
|
Taro.eventCenter.trigger(action, params)
|
|
103
102
|
}
|
|
104
103
|
NATIVE_PAGE_READ: 'pageReady',
|
|
105
104
|
NATIVE_PAGE_FINISH: 'pageFinish',
|
|
106
105
|
NATIVE_INFO_DATA: 'nativeInfoData',
|
|
107
106
|
NATIVE_PAGE_SCROLL: 'pageScroll',
|
|
108
107
|
NATIVE_PAGE_SCROLL_END: 'pageScrollEnd',
|
|
109
108
|
NATIVE_GET_SCROLL_TOP: 'nativeGetScrollTop',
|
|
110
109
|
NATIVE_TO_SCROLL_TOP: 'nativeToScrollTop',
|
|
111
110
|
NATIVE_CLOSE_SCROLL_MESSAGE: 'nativeCloseScrollMessage',
|
|
112
111
|
NATIVE_MOBILE_CONFIG: 'getMobileConfig',
|
|
113
112
|
NATIVE_SHOW_TOAST: 'showToast',
|
|
114
113
|
NATIVE_SHOW_DIALOG: 'showDialog',
|
|
115
114
|
NATIVE_PAGE_LAYOUT_CHANGE: 'pageLayoutChange',
|
|
116
115
|
NATIVE_HOME_PAGING_ENABLE: 'homePagingEnable',
|
|
117
116
|
NATIVE_GET_SCALED_TOUCH_SLOP: 'getScaledTouchSlop',
|
|
118
117
|
NATIVE_ADD_CART: 'addCart',
|
|
119
118
|
NATIVE_OPEN_FLOAT: 'openFloat',
|
|
120
119
|
NATIVE_INJECT_JS_FILE: 'needIsvPackage',
|
|
121
120
|
NAVTIVE_FLOAT_READY: 'floatReady',
|
|
122
121
|
NATIVE_REFRESH_PAGE: 'refreshPage',
|
|
123
122
|
PAGE_PV_PARAM: 'pagePvParam',
|
|
124
123
|
NATIVE_SCORLL_VIEW: 'nativeScrollControl',
|
|
125
124
|
NATIVE_POP_WEBVIEW: 'popWebview',
|
|
126
125
|
NATIVE_H5_SEND_MSG_TO_H5: 'h5SendMsgToH5',
|
|
127
126
|
NATIVE_PUSH_NATIVE_PAGE: 'pushNativePage',
|
|
128
127
|
UPDATE_NATIVE_DATA: 'updateNativeData',
|
|
129
128
|
H5_TO_SCROLL_TOP: 'h5ToScrollTop',
|
|
130
129
|
LUXURY_INFORM_CHANGE_HEIGHT: 'sendImmersionStatus',
|
|
131
130
|
NATIVE_SHOPSTOW_SEND: 'sendMsgToShopStow',
|
|
132
131
|
NATIVE_UPDATE_PAGE_INFO: 'pageCountInfo',
|
|
133
132
|
NATIVE_TO_BUYER_SHOW_DETAIL: 'jumpBuyerShowDetail',
|
|
134
133
|
NATIVE_TO_HIDE_JD_SHOP_HEADER: 'hideNativeHeader',
|
|
135
134
|
OPEN: 'open',
|
|
136
135
|
CLOSE: 'close',
|
|
137
136
|
JOIN_MEMBER_SUCCESS: 'joinMemberSuccess',
|
|
138
137
|
type = Message_Type.NATIVE_PAGE_READ,
|
|
139
138
|
sendData: null | object = null,
|
|
140
139
|
callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
141
140
|
console.log(
|
|
142
141
|
'初始化nativePageRegisterMessage-isAppStowShop-type-sendData-isJdApp-isH5AndJdShopView',
|
|
143
142
|
isAppStowShop,
|
|
144
143
|
type,
|
|
145
144
|
sendData,
|
|
146
145
|
isJdApp,
|
|
147
146
|
isH5AndJdShopView,
|
|
148
147
|
callBackName,
|
|
149
148
|
)
|
|
150
149
|
if (isJdApp) {
|
|
151
150
|
const getCallBackName = `window.${callBackName}`
|
|
152
151
|
let getRouterParam = {
|
|
153
152
|
type,
|
|
154
153
|
callBackName: getCallBackName,
|
|
155
154
|
}
|
|
156
155
|
if (!isAppStowShop) {
|
|
157
156
|
getRouterParam['newHomePage'] = true
|
|
158
157
|
}
|
|
159
158
|
if (sendData) {
|
|
160
159
|
getRouterParam = Object.assign({}, getRouterParam, sendData)
|
|
161
160
|
}
|
|
162
161
|
if (isIosDevice) {
|
|
163
162
|
const routerURL = isAppStowShop
|
|
164
163
|
? 'router://JDBDecorationPlatformModule/wrtNative'
|
|
165
164
|
: 'router://JDShopModule/wrtNative'
|
|
166
165
|
if (versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) >= 0) {
|
|
167
166
|
callRouterIOS({
|
|
168
167
|
routerURL,
|
|
169
168
|
routerParam: getRouterParam,
|
|
170
169
|
})
|
|
171
170
|
} else {
|
|
172
171
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
173
172
|
method: 'callRouterModuleWithParams',
|
|
174
173
|
params: {
|
|
175
174
|
routerURL,
|
|
176
175
|
routerParam: JSON.stringify(getRouterParam),
|
|
177
176
|
callBackName: getCallBackName,
|
|
178
177
|
callBackId: `${callBackName}Ios`,
|
|
179
178
|
},
|
|
180
179
|
})
|
|
181
180
|
}
|
|
182
181
|
} else if (isAndroidDevice) {
|
|
183
182
|
window?.JDJshop?.wrtNative(
|
|
184
183
|
JSON.stringify({
|
|
185
184
|
routerParam: JSON.stringify(getRouterParam),
|
|
186
185
|
callBackName: getCallBackName,
|
|
187
186
|
callBackId: `${callBackName}Android`,
|
|
188
187
|
}),
|
|
189
188
|
)
|
|
190
189
|
}
|
|
191
190
|
return true
|
|
192
191
|
}
|
|
193
192
|
return false
|
|
194
193
|
if (isJdApp) {
|
|
195
194
|
if (isIosDevice) {
|
|
196
195
|
window?.webkit?.messageHandlers?.MobileNavi?.postMessage({
|
|
197
196
|
method: 'close',
|
|
198
197
|
})
|
|
199
198
|
} else if (isAndroidDevice) {
|
|
200
199
|
window?.XView && window?.XView.close()
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
console.log('showToastByRouter:', title, showType)
|
|
204
203
|
if (isJdApp) {
|
|
205
204
|
const routerParam = {
|
|
206
205
|
message: title,
|
|
207
206
|
iconType: showType,
|
|
208
207
|
duration,
|
|
209
208
|
}
|
|
210
209
|
if (isIosDevice) {
|
|
211
210
|
callRouterIOS({
|
|
212
211
|
routerURL: 'router://JDShopModule/showToast',
|
|
213
212
|
routerParam,
|
|
214
213
|
})
|
|
215
214
|
} else if (isAndroidDevice) {
|
|
216
215
|
callRouterAndroid({
|
|
217
216
|
routerURL: 'router://JDJShopModule/showToast',
|
|
218
217
|
routerParam,
|
|
219
218
|
})
|
|
220
219
|
}
|
|
221
220
|
}
|
|
222
221
|
console.log('nativePageLoadReady called')
|
|
223
222
|
Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
224
223
|
Message_Type.NATIVE_INFO_DATA
|
|
225
224
|
] = async (data: any) => {
|
|
226
225
|
console.log('nativePageLoadReady callBack:', callBack, ', data:', data)
|
|
227
226
|
callBack && callBack(data)
|
|
228
227
|
}
|
|
229
228
|
nativePageGetMessageInitCallBack()
|
|
230
229
|
nativePageRegisterMessage(
|
|
231
230
|
Message_Type.NATIVE_PAGE_READ,
|
|
232
231
|
sendData,
|
|
233
232
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
234
233
|
)
|
|
235
234
|
return nativePageRegisterMessage(
|
|
236
235
|
Message_Type.NATIVE_PAGE_FINISH,
|
|
237
236
|
null,
|
|
238
237
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
239
238
|
)
|
|
240
239
|
callBack &&
|
|
241
240
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
242
241
|
Message_Type.NATIVE_GET_SCROLL_TOP
|
|
243
242
|
] = callBack)
|
|
244
243
|
return nativePageRegisterMessage(
|
|
245
244
|
Message_Type.NATIVE_GET_SCROLL_TOP,
|
|
246
245
|
null,
|
|
247
246
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
248
247
|
)
|
|
249
248
|
callBack &&
|
|
250
249
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
251
250
|
Message_Type.NATIVE_TO_SCROLL_TOP
|
|
252
251
|
] = callBack)
|
|
253
252
|
nativePageRegisterMessage(
|
|
254
253
|
Message_Type.NATIVE_TO_SCROLL_TOP,
|
|
255
254
|
{
|
|
256
255
|
data: {
|
|
257
256
|
scrollTop,
|
|
258
257
|
},
|
|
259
258
|
},
|
|
260
259
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
261
260
|
)
|
|
262
261
|
Taro.eventCenter.trigger(TaroEventType.LUXURY_INFORM_CHANGE_HEIGHT, data)
|
|
263
262
|
configName: string,
|
|
264
263
|
isBeforePageReady: boolean,
|
|
265
264
|
return new Promise((resolve, reject) => {
|
|
266
265
|
if (!isJdApp) {
|
|
267
266
|
reject({
|
|
268
267
|
code: -1,
|
|
269
268
|
message: 'getMPaasConfigByNative 只在松果APP店铺内部调用有效。',
|
|
270
269
|
})
|
|
271
270
|
return
|
|
272
271
|
}
|
|
273
272
|
if (
|
|
274
273
|
isIosDevice &&
|
|
275
274
|
isBeforePageReady &&
|
|
276
275
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0
|
|
277
276
|
) {
|
|
278
277
|
reject({
|
|
279
278
|
code: -2,
|
|
280
279
|
message: `在nativePageLoadReady之前调用,低于v${MPAAS_CONFIG_APP_VERSION}不会有返回,兜底处理`,
|
|
281
280
|
})
|
|
282
281
|
return
|
|
283
282
|
}
|
|
284
283
|
Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
285
284
|
Message_Type.NATIVE_MOBILE_CONFIG
|
|
286
285
|
] = (data: any) => {
|
|
287
286
|
const configData = isAndroidDevice ? data : data?.data
|
|
288
287
|
const res = JSONParse(configData)
|
|
289
288
|
resolve(res)
|
|
290
289
|
}
|
|
291
290
|
nativePageGetMessageInitCallBack()
|
|
292
291
|
nativePageRegisterMessage(
|
|
293
292
|
Message_Type.NATIVE_MOBILE_CONFIG,
|
|
294
293
|
{
|
|
295
294
|
data: {
|
|
296
295
|
space: isIosDevice ? 'JDCDSHOP' : 'JDShop',
|
|
297
296
|
configName,
|
|
298
297
|
},
|
|
299
298
|
},
|
|
300
299
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
301
300
|
)
|
|
302
301
|
})
|
|
303
302
|
bussinessKey: string,
|
|
304
303
|
isBeforePageReady: boolean,
|
|
305
304
|
if (!bussinessKey) {
|
|
306
305
|
return null
|
|
307
306
|
}
|
|
308
307
|
if (!isJdApp) {
|
|
309
308
|
return null
|
|
310
309
|
}
|
|
311
310
|
const CACHED_MPAAS_KEY = `mpaas_${CONFIG_NAME}`
|
|
312
311
|
const CACHED_MPAAS_KEY_HELPER = `${CACHED_MPAAS_KEY}_helper`
|
|
313
312
|
let configData = window[CACHED_MPAAS_KEY]
|
|
314
313
|
if (configData == null) {
|
|
315
314
|
configData = await getMPaasConfigByNative(
|
|
316
315
|
CONFIG_NAME,
|
|
317
316
|
isBeforePageReady,
|
|
318
317
|
).catch((e) => {
|
|
319
318
|
console.log('getMPaasConfigByNative error:', e)
|
|
320
319
|
return null
|
|
321
320
|
})
|
|
322
321
|
window[CACHED_MPAAS_KEY_HELPER] = {}
|
|
323
322
|
window[CACHED_MPAAS_KEY] = configData
|
|
324
323
|
}
|
|
325
324
|
if (configData) {
|
|
326
325
|
const originData = configData[bussinessKey]
|
|
327
326
|
const hasParse = window[CACHED_MPAAS_KEY_HELPER][bussinessKey]
|
|
328
327
|
try {
|
|
329
328
|
if (
|
|
330
329
|
hasParse ||
|
|
331
330
|
['object', 'boolean', 'number'].includes(typeof originData)
|
|
332
331
|
) {
|
|
333
332
|
return originData
|
|
334
333
|
} else {
|
|
335
334
|
window[CACHED_MPAAS_KEY_HELPER][bussinessKey] = true
|
|
336
335
|
const parseData = JSON.parse(configData[bussinessKey])
|
|
337
336
|
configData[bussinessKey] = parseData
|
|
338
337
|
return parseData
|
|
339
338
|
}
|
|
340
339
|
} catch (e) {
|
|
341
340
|
return originData
|
|
342
341
|
}
|
|
343
342
|
}
|
|
344
343
|
return null
|
|
345
344
|
nativePageRegisterMessage(Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE)
|
|
346
345
|
if (isJdAndAndroidDevice) {
|
|
347
346
|
callBack &&
|
|
348
347
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
349
348
|
Message_Type.NATIVE_HOME_PAGING_ENABLE
|
|
350
349
|
] = callBack)
|
|
351
350
|
nativePageRegisterMessage(Message_Type.NATIVE_HOME_PAGING_ENABLE, {
|
|
352
351
|
data: {
|
|
353
352
|
enable: enable,
|
|
354
353
|
},
|
|
355
354
|
})
|
|
356
355
|
}
|
|
357
356
|
if (isJdAndAndroidDevice) {
|
|
358
357
|
callBack &&
|
|
359
358
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
360
359
|
Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP
|
|
361
360
|
] = callBack)
|
|
362
361
|
nativePageRegisterMessage(Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP)
|
|
363
362
|
}
|
|
364
363
|
SUCCESS: 'success',
|
|
365
364
|
FAIL: 'fail',
|
|
366
365
|
NORMAL: 'normal',
|
|
367
366
|
SUCCESS: 2,
|
|
368
367
|
FAIL: 3,
|
|
369
368
|
NORMAL: 1,
|
|
370
369
|
SUCCESS: 2,
|
|
371
370
|
FAIL: 3,
|
|
372
371
|
NORMAL: 1,
|
|
373
372
|
[ToastIosType.NORMAL]: ToastType.NORMAL,
|
|
374
373
|
[ToastIosType.SUCCESS]: ToastType.SUCCESS,
|
|
375
374
|
[ToastIosType.FAIL]: ToastType.FAIL,
|
|
376
375
|
if (isShowNewRouterToast) {
|
|
377
376
|
const changeShowType = isJdAndIosDevice
|
|
378
377
|
? toastIosTypeToNewToastType[showType] || showType
|
|
379
378
|
: showType
|
|
380
379
|
showToastByRouter(title, changeShowType, duration * 1000)
|
|
381
380
|
} else {
|
|
382
381
|
nativePageRegisterMessage(Message_Type.NATIVE_SHOW_TOAST, {
|
|
383
382
|
data: {
|
|
384
383
|
message: title,
|
|
385
384
|
iconType: showType,
|
|
386
385
|
duration,
|
|
387
386
|
},
|
|
388
387
|
})
|
|
389
388
|
}
|
|
390
389
|
routerURL,
|
|
391
390
|
routerParam,
|
|
392
391
|
callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
393
392
|
}) => {
|
|
394
393
|
console.log(
|
|
395
394
|
'callRouterIOS routerURL:',
|
|
396
395
|
routerURL,
|
|
397
396
|
',routerParam:',
|
|
398
397
|
routerParam,
|
|
399
398
|
)
|
|
400
399
|
const getCallBackName = `window.${callBackName}`
|
|
401
400
|
const params = {
|
|
402
401
|
routerURL,
|
|
403
402
|
routerParam,
|
|
404
403
|
callBackName: getCallBackName,
|
|
405
404
|
callBackId: `${callBackName}Ios`,
|
|
406
405
|
}
|
|
407
406
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
408
407
|
method: 'callRouterModuleWithParams',
|
|
409
408
|
params: JSON.stringify(params),
|
|
410
409
|
})
|
|
411
410
|
routerURL,
|
|
412
411
|
routerParam,
|
|
413
412
|
callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
414
413
|
}) => {
|
|
415
414
|
console.log(
|
|
416
415
|
'callRouterAndroid routerURL:',
|
|
417
416
|
routerURL,
|
|
418
417
|
',routerParam:',
|
|
419
418
|
routerParam,
|
|
420
419
|
)
|
|
421
420
|
const getCallBackName = `window.${callBackName}`
|
|
422
421
|
var params = {
|
|
423
422
|
jdRouter: '1',
|
|
424
423
|
routerURL,
|
|
425
424
|
routerParam,
|
|
426
425
|
callBackName: getCallBackName,
|
|
427
426
|
callBackId: `${callBackName}Android`,
|
|
428
427
|
}
|
|
429
428
|
window?.JDAppUnite?.callRouterModuleWithParams(JSON.stringify(params))
|
|
430
429
|
callBack &&
|
|
431
430
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
432
431
|
Message_Type.NATIVE_SHOW_DIALOG
|
|
433
432
|
] = callBack)
|
|
434
433
|
return nativePageRegisterMessage(Message_Type.NATIVE_SHOW_DIALOG, {
|
|
435
434
|
data: params,
|
|
436
435
|
})
|
|
437
436
|
if (!isJdApp) {
|
|
438
437
|
return
|
|
439
438
|
}
|
|
440
439
|
if (!window[Message_CallBack_Name.MESSAGE_HOME_INIT]) {
|
|
441
440
|
window[Message_CallBack_Name.MESSAGE_HOME_INIT] = messageData => {
|
|
442
441
|
try {
|
|
443
442
|
const getMessageJsonData = JSONParse(messageData)
|
|
444
443
|
const { status } = getMessageJsonData
|
|
445
444
|
if (status == '0') {
|
|
446
445
|
const { type, data } = getMessageJsonData?.data
|
|
447
446
|
const getSendJsonData = JSONParse(data)
|
|
448
447
|
switch (type) {
|
|
449
448
|
case Message_Type.NATIVE_INFO_DATA:
|
|
450
449
|
case Message_Type.NATIVE_PAGE_FINISH:
|
|
451
450
|
case Message_Type.NATIVE_GET_SCROLL_TOP:
|
|
452
451
|
case Message_Type.NATIVE_TO_SCROLL_TOP:
|
|
453
452
|
case Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE:
|
|
454
453
|
case Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP:
|
|
455
454
|
case Message_Type.NATIVE_MOBILE_CONFIG:
|
|
456
455
|
const getTypeCallBack =
|
|
457
456
|
Message_Trigger_CallBackFuncObj[
|
|
458
457
|
Message_CallBack_Name.MESSAGE_HOME_INIT
|
|
459
458
|
][type]
|
|
460
459
|
if (getTypeCallBack) {
|
|
461
460
|
const isCallBackFunc = typeof getTypeCallBack === 'function'
|
|
462
461
|
console.log(
|
|
463
462
|
'接收到原生通知 NATIVE_SHOPSTOW_SEND getSendJsonData',
|
|
464
463
|
getSendJsonData,
|
|
465
464
|
)
|
|
466
465
|
isCallBackFunc && getTypeCallBack(getSendJsonData)
|
|
467
466
|
}
|
|
468
467
|
break
|
|
469
468
|
case Message_Type.NATIVE_SHOW_DIALOG:
|
|
470
469
|
const showDialogCallBack =
|
|
471
470
|
Message_Trigger_CallBackFuncObj[
|
|
472
471
|
Message_CallBack_Name.MESSAGE_HOME_INIT
|
|
473
472
|
][type]
|
|
474
473
|
if (showDialogCallBack) {
|
|
475
474
|
const isCallBackFunc = typeof showDialogCallBack === 'function'
|
|
476
475
|
console.log(
|
|
477
476
|
`获取${type}类型数据数据type isCallBackFunc getMessageJsonData `,
|
|
478
477
|
type,
|
|
479
478
|
isCallBackFunc,
|
|
480
479
|
getMessageJsonData,
|
|
481
480
|
)
|
|
482
481
|
isCallBackFunc && showDialogCallBack(getMessageJsonData?.data)
|
|
483
482
|
}
|
|
484
483
|
break
|
|
485
484
|
case Message_Type.NATIVE_PAGE_SCROLL:
|
|
486
485
|
taroEventSendPageScrollInfo(data)
|
|
487
486
|
break
|
|
488
487
|
case Message_Type.NATIVE_PAGE_SCROLL_END:
|
|
489
488
|
taroEventSendPageScrollEndInfo(data)
|
|
490
489
|
break
|
|
491
490
|
case Message_Type.NATIVE_H5_SEND_MSG_TO_H5:
|
|
492
491
|
console.log('接收到原生通知 NATIVE_H5_SEND_MSG_TO_H5', data)
|
|
493
492
|
taroEventH5SendMsgToH5(getSendJsonData)
|
|
494
493
|
break
|
|
495
494
|
case Message_Type.UPDATE_NATIVE_DATA:
|
|
496
495
|
taroEventUpdateNativeData(getSendJsonData)
|
|
497
496
|
break
|
|
498
497
|
case Message_Type.H5_TO_SCROLL_TOP:
|
|
499
498
|
taroEventH5ToScrollTop()
|
|
500
499
|
break
|
|
501
500
|
case Message_Type.LUXURY_INFORM_CHANGE_HEIGHT:
|
|
502
501
|
taroEventSendImmersionStatus(data)
|
|
503
502
|
break
|
|
504
503
|
default:
|
|
505
504
|
}
|
|
506
505
|
} else {
|
|
507
506
|
console.log('传递数据获取异常', getMessageJsonData)
|
|
508
507
|
}
|
|
509
508
|
} catch (e) {
|
|
510
509
|
console.log('获取转换异常结果', e)
|
|
511
510
|
}
|
|
512
511
|
}
|
|
513
512
|
}
|
|
514
513
|
nativePageRegisterMessage(Message_Type.NATIVE_OPEN_FLOAT, {
|
|
515
514
|
data: params,
|
|
516
515
|
})
|
|
517
516
|
nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
|
|
518
517
|
data: {
|
|
519
518
|
type: NATIVE_POP_WEBVIEW_TYPE.OPEN,
|
|
520
519
|
height: DEFAULT_POP_WEBVIEW_HEIGHT,
|
|
521
520
|
...params,
|
|
522
521
|
},
|
|
523
522
|
})
|
|
524
523
|
nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
|
|
525
524
|
data: {
|
|
526
525
|
type: NATIVE_POP_WEBVIEW_TYPE.CLOSE,
|
|
527
526
|
...params,
|
|
528
527
|
},
|
|
529
528
|
})
|
|
530
529
|
Taro.eventCenter.off(TaroEventType.JOIN_MEMBER_SUCCESS)
|
|
531
530
|
console.log('popWebview关闭')
|
|
532
531
|
nativePageRegisterMessage(Message_Type.NATIVE_H5_SEND_MSG_TO_H5, {
|
|
533
532
|
data: params,
|
|
534
533
|
})
|
|
535
534
|
nativePageRegisterMessage(Message_Type.NATIVE_PUSH_NATIVE_PAGE, {
|
|
536
535
|
data: params,
|
|
537
536
|
})
|
|
538
537
|
window &&
|
|
539
538
|
(window.location.href = `xview://search?request={"action":"${Message_Type.NAVTIVE_FLOAT_READY}"}`)
|
|
540
539
|
res: UtilsInterFace.nativePageScrollRes,
|
|
541
540
|
const { displayHeight, offSetY } = res
|
|
542
541
|
if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined')
|
|
543
542
|
return
|
|
544
543
|
if (isIosDevice) return res
|
|
545
544
|
if (isAndroidDevice) {
|
|
546
545
|
const deviceRatio = window.devicePixelRatio
|
|
547
546
|
const cssDisplayHeight = Math.ceil(displayHeight / deviceRatio)
|
|
548
547
|
const cssOffsetY = Math.ceil(offSetY / deviceRatio)
|
|
549
548
|
return {
|
|
550
549
|
displayHeight: cssDisplayHeight,
|
|
551
550
|
offSetY: cssOffsetY,
|
|
552
551
|
}
|
|
553
552
|
}
|
|
554
553
|
nativePageRegisterMessage(Message_Type.NATIVE_UPDATE_PAGE_INFO, {
|
|
555
554
|
data: params,
|
|
556
555
|
})
|
|
557
556
|
nativePageRegisterMessage(Message_Type.NATIVE_TO_BUYER_SHOW_DETAIL, {
|
|
558
557
|
data: params,
|
|
559
558
|
})
|
|
560
559
|
nativePageRegisterMessage(Message_Type.NATIVE_TO_HIDE_JD_SHOP_HEADER, {
|
|
561
560
|
data: params,
|
|
562
561
|
})
|
|
562
|
+
import Taro from '@tarojs/taro'
|
|
563
563
|
isH5AndJdShopView,
|
|
564
564
|
isJdApp,
|
|
565
565
|
isIosDevice,
|
|
566
566
|
isAndroidDevice,
|
|
567
567
|
isJdAndIosDevice,
|
|
568
568
|
isJdAndAndroidDevice,
|
|
569
569
|
jdAppVersionCompare,
|
|
570
570
|
isAppStowShop,
|
|
571
571
|
androidTouchSlop: 5,
|
|
572
572
|
getAndroidTouchSlopState: false,
|
|
573
573
|
(state) => {
|
|
574
574
|
console.log(
|
|
575
575
|
'document trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:',
|
|
576
576
|
state,
|
|
577
577
|
)
|
|
578
578
|
Taro.eventCenter.trigger(
|
|
579
579
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
580
580
|
state ? 0 : 1,
|
|
581
581
|
)
|
|
582
582
|
},
|
|
583
583
|
1500,
|
|
584
584
|
{ leading: false, trailing: true },
|
|
585
585
|
(state) => {
|
|
586
586
|
console.log(
|
|
587
587
|
'IOS Android trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:',
|
|
588
588
|
state,
|
|
589
589
|
)
|
|
590
590
|
Taro.eventCenter.trigger(
|
|
591
591
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
592
592
|
state,
|
|
593
593
|
)
|
|
594
594
|
},
|
|
595
595
|
1500,
|
|
596
596
|
{ leading: true, trailing: false },
|
|
597
597
|
if (!isJdApp) {
|
|
598
598
|
if (isH5) {
|
|
599
599
|
|
|
600
600
|
const documentHandleVisibilityChange = () => {
|
|
601
601
|
const state = document.hidden
|
|
602
602
|
window.startDocumentVisibilityChange && documentThrottledTrigger(state)
|
|
603
603
|
}
|
|
604
604
|
document.removeEventListener(
|
|
605
605
|
'visibilitychange',
|
|
606
606
|
documentHandleVisibilityChange,
|
|
607
607
|
)
|
|
608
608
|
console.log('每次进入页面先清除浏览器visibilitychange监听事件')
|
|
609
609
|
setTimeout(() => {
|
|
610
610
|
document.addEventListener(
|
|
611
611
|
'visibilitychange',
|
|
612
612
|
documentHandleVisibilityChange,
|
|
613
613
|
false,
|
|
614
614
|
)
|
|
615
615
|
window.startDocumentVisibilityChange = true
|
|
616
616
|
}, 3000)
|
|
617
617
|
}
|
|
618
618
|
} else {
|
|
619
619
|
|
|
620
620
|
!window.webviewVisible &&
|
|
621
621
|
(window.webviewVisible = (state) => {
|
|
622
622
|
window.startDocumentVisibilityChange && webviewThrottledTrigger(state)
|
|
623
623
|
state === 1 && taroEventSendPageScrollInfo()
|
|
624
624
|
})
|
|
625
625
|
setTimeout(() => {
|
|
626
626
|
window.startDocumentVisibilityChange = true
|
|
627
627
|
}, 3000)
|
|
628
628
|
!window.floatReceiveData && (window.floatReceiveData = () => {})
|
|
629
629
|
}
|
|
630
630
|
MESSAGE_HOME_INIT: 'messageHomeInitPageData',
|
|
631
631
|
[Message_CallBack_Name.MESSAGE_HOME_INIT]: {},
|
|
632
632
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = {
|
|
633
633
|
displayHeight: 1920,
|
|
634
634
|
offSetY: 0,
|
|
635
635
|
}
|
|
636
636
|
if (options) {
|
|
637
637
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = options
|
|
638
638
|
}
|
|
639
639
|
const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
|
|
640
640
|
Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL, options || latestRes)
|
|
641
641
|
console.log('PageScrollEnd fire')
|
|
642
642
|
Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL_END, options)
|
|
643
643
|
const { businessType } = options
|
|
644
644
|
switch (businessType) {
|
|
645
645
|
case H5_MSG_TO_H5_BUSINESSTYPE.JOIN_MEMBER_SUCCESS:
|
|
646
646
|
Taro.eventCenter.trigger(TaroEventType.JOIN_MEMBER_SUCCESS, options)
|
|
647
647
|
break
|
|
648
648
|
default:
|
|
649
649
|
break
|
|
650
650
|
}
|
|
651
651
|
const { shopHomeExtendInfo } = options
|
|
652
652
|
if (shopHomeExtendInfo) {
|
|
653
653
|
Taro.eventCenter.trigger(
|
|
654
654
|
TaroEventType.UPDATE_SHOP_HOME_EXTEND_DATA,
|
|
655
655
|
shopHomeExtendInfo,
|
|
656
656
|
)
|
|
657
657
|
}
|
|
658
658
|
window && window.scrollTo(0, 0)
|
|
659
659
|
Taro.eventCenter.trigger(TaroEventType.PAGE_INIT_EXPOSURE, options)
|
|
660
660
|
const { action, params } = options
|
|
661
661
|
console.log('taroEventShopStowSend', options)
|
|
662
662
|
if (action) {
|
|
663
663
|
Taro.eventCenter.trigger(action, params)
|
|
664
664
|
}
|
|
665
665
|
NATIVE_PAGE_READ: 'pageReady',
|
|
666
666
|
NATIVE_PAGE_FINISH: 'pageFinish',
|
|
667
667
|
NATIVE_INFO_DATA: 'nativeInfoData',
|
|
668
668
|
NATIVE_PAGE_SCROLL: 'pageScroll',
|
|
669
669
|
NATIVE_PAGE_SCROLL_END: 'pageScrollEnd',
|
|
670
670
|
NATIVE_GET_SCROLL_TOP: 'nativeGetScrollTop',
|
|
671
671
|
NATIVE_TO_SCROLL_TOP: 'nativeToScrollTop',
|
|
672
672
|
NATIVE_CLOSE_SCROLL_MESSAGE: 'nativeCloseScrollMessage',
|
|
673
673
|
NATIVE_MOBILE_CONFIG: 'getMobileConfig',
|
|
674
674
|
NATIVE_SHOW_TOAST: 'showToast',
|
|
675
675
|
NATIVE_SHOW_DIALOG: 'showDialog',
|
|
676
676
|
NATIVE_PAGE_LAYOUT_CHANGE: 'pageLayoutChange',
|
|
677
677
|
NATIVE_HOME_PAGING_ENABLE: 'homePagingEnable',
|
|
678
678
|
NATIVE_GET_SCALED_TOUCH_SLOP: 'getScaledTouchSlop',
|
|
679
679
|
NATIVE_ADD_CART: 'addCart',
|
|
680
680
|
NATIVE_OPEN_FLOAT: 'openFloat',
|
|
681
681
|
NATIVE_INJECT_JS_FILE: 'needIsvPackage',
|
|
682
682
|
NAVTIVE_FLOAT_READY: 'floatReady',
|
|
683
683
|
NATIVE_REFRESH_PAGE: 'refreshPage',
|
|
684
684
|
PAGE_PV_PARAM: 'pagePvParam',
|
|
685
685
|
NATIVE_SCORLL_VIEW: 'nativeScrollControl',
|
|
686
686
|
NATIVE_POP_WEBVIEW: 'popWebview',
|
|
687
687
|
NATIVE_H5_SEND_MSG_TO_H5: 'h5SendMsgToH5',
|
|
688
688
|
NATIVE_PUSH_NATIVE_PAGE: 'pushNativePage',
|
|
689
689
|
UPDATE_NATIVE_DATA: 'updateNativeData',
|
|
690
690
|
H5_TO_SCROLL_TOP: 'h5ToScrollTop',
|
|
691
691
|
LUXURY_INFORM_CHANGE_HEIGHT: 'sendImmersionStatus',
|
|
692
692
|
NATIVE_SHOPSTOW_SEND: 'sendMsgToShopStow',
|
|
693
693
|
NATIVE_UPDATE_PAGE_INFO: 'pageCountInfo',
|
|
694
694
|
NATIVE_TO_BUYER_SHOW_DETAIL: 'jumpBuyerShowDetail',
|
|
695
695
|
NATIVE_TO_HIDE_JD_SHOP_HEADER: 'hideNativeHeader',
|
|
696
696
|
OPEN: 'open',
|
|
697
697
|
CLOSE: 'close',
|
|
698
698
|
JOIN_MEMBER_SUCCESS: 'joinMemberSuccess',
|
|
699
699
|
type = Message_Type.NATIVE_PAGE_READ,
|
|
700
700
|
sendData: null | object = null,
|
|
701
701
|
callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
702
702
|
console.log(
|
|
703
703
|
'初始化nativePageRegisterMessage-isAppStowShop-type-sendData-isJdApp-isH5AndJdShopView',
|
|
704
704
|
isAppStowShop,
|
|
705
705
|
type,
|
|
706
706
|
sendData,
|
|
707
707
|
isJdApp,
|
|
708
708
|
isH5AndJdShopView,
|
|
709
709
|
callBackName,
|
|
710
710
|
)
|
|
711
711
|
if (isJdApp) {
|
|
712
712
|
const getCallBackName = `window.${callBackName}`
|
|
713
713
|
let getRouterParam = {
|
|
714
714
|
type,
|
|
715
715
|
callBackName: getCallBackName,
|
|
716
716
|
}
|
|
717
717
|
if (!isAppStowShop) {
|
|
718
718
|
getRouterParam['newHomePage'] = true
|
|
719
719
|
}
|
|
720
720
|
if (sendData) {
|
|
721
721
|
getRouterParam = Object.assign({}, getRouterParam, sendData)
|
|
722
722
|
}
|
|
723
723
|
if (isIosDevice) {
|
|
724
724
|
const routerURL = isAppStowShop
|
|
725
725
|
? 'router://JDBDecorationPlatformModule/wrtNative'
|
|
726
726
|
: 'router://JDShopModule/wrtNative'
|
|
727
727
|
if (versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) >= 0) {
|
|
728
728
|
callRouterIOS({
|
|
729
729
|
routerURL,
|
|
730
730
|
routerParam: getRouterParam,
|
|
731
731
|
})
|
|
732
732
|
} else {
|
|
733
733
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
734
734
|
method: 'callRouterModuleWithParams',
|
|
735
735
|
params: {
|
|
736
736
|
routerURL,
|
|
737
737
|
routerParam: JSON.stringify(getRouterParam),
|
|
738
738
|
callBackName: getCallBackName,
|
|
739
739
|
callBackId: `${callBackName}Ios`,
|
|
740
740
|
},
|
|
741
741
|
})
|
|
742
742
|
}
|
|
743
743
|
} else if (isAndroidDevice) {
|
|
744
744
|
window?.JDJshop?.wrtNative(
|
|
745
745
|
JSON.stringify({
|
|
746
746
|
routerParam: JSON.stringify(getRouterParam),
|
|
747
747
|
callBackName: getCallBackName,
|
|
748
748
|
callBackId: `${callBackName}Android`,
|
|
749
749
|
}),
|
|
750
750
|
)
|
|
751
751
|
}
|
|
752
752
|
return true
|
|
753
753
|
}
|
|
754
754
|
return false
|
|
755
755
|
if (isJdApp) {
|
|
756
756
|
if (isIosDevice) {
|
|
757
757
|
window?.webkit?.messageHandlers?.MobileNavi?.postMessage({
|
|
758
758
|
method: 'close',
|
|
759
759
|
})
|
|
760
760
|
} else if (isAndroidDevice) {
|
|
761
761
|
window?.XView && window?.XView.close()
|
|
762
762
|
}
|
|
763
763
|
}
|
|
764
764
|
console.log('showToastByRouter:', title, showType)
|
|
765
765
|
if (isJdApp) {
|
|
766
766
|
const routerParam = {
|
|
767
767
|
message: title,
|
|
768
768
|
iconType: showType,
|
|
769
769
|
duration,
|
|
770
770
|
}
|
|
771
771
|
if (isIosDevice) {
|
|
772
772
|
callRouterIOS({
|
|
773
773
|
routerURL: 'router://JDShopModule/showToast',
|
|
774
774
|
routerParam,
|
|
775
775
|
})
|
|
776
776
|
} else if (isAndroidDevice) {
|
|
777
777
|
callRouterAndroid({
|
|
778
778
|
routerURL: 'router://JDJShopModule/showToast',
|
|
779
779
|
routerParam,
|
|
780
780
|
})
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
783
|
console.log('nativePageLoadReady called')
|
|
784
784
|
Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
785
785
|
Message_Type.NATIVE_INFO_DATA
|
|
786
786
|
] = async (data: any) => {
|
|
787
787
|
console.log('nativePageLoadReady callBack:', callBack, ', data:', data)
|
|
788
788
|
callBack && callBack(data)
|
|
789
789
|
}
|
|
790
790
|
nativePageGetMessageInitCallBack()
|
|
791
791
|
nativePageRegisterMessage(
|
|
792
792
|
Message_Type.NATIVE_PAGE_READ,
|
|
793
793
|
sendData,
|
|
794
794
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
795
795
|
)
|
|
796
796
|
return nativePageRegisterMessage(
|
|
797
797
|
Message_Type.NATIVE_PAGE_FINISH,
|
|
798
798
|
null,
|
|
799
799
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
800
800
|
)
|
|
801
801
|
callBack &&
|
|
802
802
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
803
803
|
Message_Type.NATIVE_GET_SCROLL_TOP
|
|
804
804
|
] = callBack)
|
|
805
805
|
return nativePageRegisterMessage(
|
|
806
806
|
Message_Type.NATIVE_GET_SCROLL_TOP,
|
|
807
807
|
null,
|
|
808
808
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
809
809
|
)
|
|
810
810
|
callBack &&
|
|
811
811
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
812
812
|
Message_Type.NATIVE_TO_SCROLL_TOP
|
|
813
813
|
] = callBack)
|
|
814
814
|
nativePageRegisterMessage(
|
|
815
815
|
Message_Type.NATIVE_TO_SCROLL_TOP,
|
|
816
816
|
{
|
|
817
817
|
data: {
|
|
818
818
|
scrollTop,
|
|
819
819
|
},
|
|
820
820
|
},
|
|
821
821
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
822
822
|
)
|
|
823
823
|
Taro.eventCenter.trigger(TaroEventType.LUXURY_INFORM_CHANGE_HEIGHT, data)
|
|
824
824
|
configName: string,
|
|
825
825
|
isBeforePageReady: boolean,
|
|
826
826
|
return new Promise((resolve, reject) => {
|
|
827
827
|
if (!isJdApp) {
|
|
828
828
|
reject({
|
|
829
829
|
code: -1,
|
|
830
830
|
message: 'getMPaasConfigByNative 只在松果APP店铺内部调用有效。',
|
|
831
831
|
})
|
|
832
832
|
return
|
|
833
833
|
}
|
|
834
834
|
if (
|
|
835
835
|
isIosDevice &&
|
|
836
836
|
isBeforePageReady &&
|
|
837
837
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0
|
|
838
838
|
) {
|
|
839
839
|
reject({
|
|
840
840
|
code: -2,
|
|
841
841
|
message: `在nativePageLoadReady之前调用,低于v${MPAAS_CONFIG_APP_VERSION}不会有返回,兜底处理`,
|
|
842
842
|
})
|
|
843
843
|
return
|
|
844
844
|
}
|
|
845
845
|
Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
846
846
|
Message_Type.NATIVE_MOBILE_CONFIG
|
|
847
847
|
] = (data: any) => {
|
|
848
848
|
const configData = isAndroidDevice ? data : data?.data
|
|
849
849
|
const res = JSONParse(configData)
|
|
850
850
|
resolve(res)
|
|
851
851
|
}
|
|
852
852
|
nativePageGetMessageInitCallBack()
|
|
853
853
|
nativePageRegisterMessage(
|
|
854
854
|
Message_Type.NATIVE_MOBILE_CONFIG,
|
|
855
855
|
{
|
|
856
856
|
data: {
|
|
857
857
|
space: isIosDevice ? 'JDCDSHOP' : 'JDShop',
|
|
858
858
|
configName,
|
|
859
859
|
},
|
|
860
860
|
},
|
|
861
861
|
Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
862
862
|
)
|
|
863
863
|
})
|
|
864
864
|
bussinessKey: string,
|
|
865
865
|
isBeforePageReady: boolean,
|
|
866
866
|
if (!bussinessKey) {
|
|
867
867
|
return null
|
|
868
868
|
}
|
|
869
869
|
if (!isJdApp) {
|
|
870
870
|
return null
|
|
871
871
|
}
|
|
872
872
|
const CACHED_MPAAS_KEY = `mpaas_${CONFIG_NAME}`
|
|
873
873
|
const CACHED_MPAAS_KEY_HELPER = `${CACHED_MPAAS_KEY}_helper`
|
|
874
874
|
let configData = window[CACHED_MPAAS_KEY]
|
|
875
875
|
if (configData == null) {
|
|
876
876
|
configData = await getMPaasConfigByNative(
|
|
877
877
|
CONFIG_NAME,
|
|
878
878
|
isBeforePageReady,
|
|
879
879
|
).catch((e) => {
|
|
880
880
|
console.log('getMPaasConfigByNative error:', e)
|
|
881
881
|
return null
|
|
882
882
|
})
|
|
883
883
|
window[CACHED_MPAAS_KEY_HELPER] = {}
|
|
884
884
|
window[CACHED_MPAAS_KEY] = configData
|
|
885
885
|
}
|
|
886
886
|
if (configData) {
|
|
887
887
|
const originData = configData[bussinessKey]
|
|
888
888
|
const hasParse = window[CACHED_MPAAS_KEY_HELPER][bussinessKey]
|
|
889
889
|
try {
|
|
890
890
|
if (
|
|
891
891
|
hasParse ||
|
|
892
892
|
['object', 'boolean', 'number'].includes(typeof originData)
|
|
893
893
|
) {
|
|
894
894
|
return originData
|
|
895
895
|
} else {
|
|
896
896
|
window[CACHED_MPAAS_KEY_HELPER][bussinessKey] = true
|
|
897
897
|
const parseData = JSON.parse(configData[bussinessKey])
|
|
898
898
|
configData[bussinessKey] = parseData
|
|
899
899
|
return parseData
|
|
900
900
|
}
|
|
901
901
|
} catch (e) {
|
|
902
902
|
return originData
|
|
903
903
|
}
|
|
904
904
|
}
|
|
905
905
|
return null
|
|
906
906
|
nativePageRegisterMessage(Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE)
|
|
907
907
|
if (isJdAndAndroidDevice) {
|
|
908
908
|
callBack &&
|
|
909
909
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
910
910
|
Message_Type.NATIVE_HOME_PAGING_ENABLE
|
|
911
911
|
] = callBack)
|
|
912
912
|
nativePageRegisterMessage(Message_Type.NATIVE_HOME_PAGING_ENABLE, {
|
|
913
913
|
data: {
|
|
914
914
|
enable: enable,
|
|
915
915
|
},
|
|
916
916
|
})
|
|
917
917
|
}
|
|
918
918
|
if (isJdAndAndroidDevice) {
|
|
919
919
|
callBack &&
|
|
920
920
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
921
921
|
Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP
|
|
922
922
|
] = callBack)
|
|
923
923
|
nativePageRegisterMessage(Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP)
|
|
924
924
|
}
|
|
925
925
|
SUCCESS: 'success',
|
|
926
926
|
FAIL: 'fail',
|
|
927
927
|
NORMAL: 'normal',
|
|
928
928
|
SUCCESS: 2,
|
|
929
929
|
FAIL: 3,
|
|
930
930
|
NORMAL: 1,
|
|
931
931
|
SUCCESS: 2,
|
|
932
932
|
FAIL: 3,
|
|
933
933
|
NORMAL: 1,
|
|
934
934
|
[ToastIosType.NORMAL]: ToastType.NORMAL,
|
|
935
935
|
[ToastIosType.SUCCESS]: ToastType.SUCCESS,
|
|
936
936
|
[ToastIosType.FAIL]: ToastType.FAIL,
|
|
937
937
|
if (isShowNewRouterToast) {
|
|
938
938
|
const changeShowType = isJdAndIosDevice
|
|
939
939
|
? toastIosTypeToNewToastType[showType] || showType
|
|
940
940
|
: showType
|
|
941
941
|
showToastByRouter(title, changeShowType, duration * 1000)
|
|
942
942
|
} else {
|
|
943
943
|
nativePageRegisterMessage(Message_Type.NATIVE_SHOW_TOAST, {
|
|
944
944
|
data: {
|
|
945
945
|
message: title,
|
|
946
946
|
iconType: showType,
|
|
947
947
|
duration,
|
|
948
948
|
},
|
|
949
949
|
})
|
|
950
950
|
}
|
|
951
951
|
routerURL,
|
|
952
952
|
routerParam,
|
|
953
953
|
callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
954
954
|
}) => {
|
|
955
955
|
console.log(
|
|
956
956
|
'callRouterIOS routerURL:',
|
|
957
957
|
routerURL,
|
|
958
958
|
',routerParam:',
|
|
959
959
|
routerParam,
|
|
960
960
|
)
|
|
961
961
|
const getCallBackName = `window.${callBackName}`
|
|
962
962
|
const params = {
|
|
963
963
|
routerURL,
|
|
964
964
|
serialize: "1",
|
|
965
965
|
routerParam,
|
|
966
966
|
callBackName: getCallBackName,
|
|
967
967
|
callBackId: `${callBackName}Ios`,
|
|
968
968
|
}
|
|
969
969
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
970
970
|
method: 'callRouterModuleWithParams',
|
|
971
971
|
params: JSON.stringify(params),
|
|
972
972
|
})
|
|
973
973
|
routerURL,
|
|
974
974
|
routerParam,
|
|
975
975
|
callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
|
|
976
976
|
}) => {
|
|
977
977
|
console.log(
|
|
978
978
|
'callRouterAndroid routerURL:',
|
|
979
979
|
routerURL,
|
|
980
980
|
',routerParam:',
|
|
981
981
|
routerParam,
|
|
982
982
|
)
|
|
983
983
|
const getCallBackName = `window.${callBackName}`
|
|
984
984
|
var params = {
|
|
985
985
|
jdRouter: '1',
|
|
986
986
|
serialize: "1",
|
|
987
987
|
routerURL,
|
|
988
988
|
routerParam,
|
|
989
989
|
callBackName: getCallBackName,
|
|
990
990
|
callBackId: `${callBackName}Android`,
|
|
991
991
|
}
|
|
992
992
|
console.log("=======获取安卓router协议参数=======", params)
|
|
993
993
|
window?.JDAppUnite?.callRouterModuleWithParams(JSON.stringify(params))
|
|
994
994
|
callBack &&
|
|
995
995
|
(Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
|
|
996
996
|
Message_Type.NATIVE_SHOW_DIALOG
|
|
997
997
|
] = callBack)
|
|
998
998
|
return nativePageRegisterMessage(Message_Type.NATIVE_SHOW_DIALOG, {
|
|
999
999
|
data: params,
|
|
1000
1000
|
})
|
|
1001
1001
|
if (!isJdApp) {
|
|
1002
1002
|
return
|
|
1003
1003
|
}
|
|
1004
1004
|
if (!window[Message_CallBack_Name.MESSAGE_HOME_INIT]) {
|
|
1005
1005
|
window[Message_CallBack_Name.MESSAGE_HOME_INIT] = messageData => {
|
|
1006
1006
|
try {
|
|
1007
1007
|
const getMessageJsonData = JSONParse(messageData)
|
|
1008
1008
|
const { status } = getMessageJsonData
|
|
1009
1009
|
if (status == '0') {
|
|
1010
1010
|
const { type, data } = getMessageJsonData?.data
|
|
1011
1011
|
const getSendJsonData = JSONParse(data)
|
|
1012
1012
|
switch (type) {
|
|
1013
1013
|
case Message_Type.NATIVE_INFO_DATA:
|
|
1014
1014
|
case Message_Type.NATIVE_PAGE_FINISH:
|
|
1015
1015
|
case Message_Type.NATIVE_GET_SCROLL_TOP:
|
|
1016
1016
|
case Message_Type.NATIVE_TO_SCROLL_TOP:
|
|
1017
1017
|
case Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE:
|
|
1018
1018
|
case Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP:
|
|
1019
1019
|
case Message_Type.NATIVE_MOBILE_CONFIG:
|
|
1020
1020
|
const getTypeCallBack =
|
|
1021
1021
|
Message_Trigger_CallBackFuncObj[
|
|
1022
1022
|
Message_CallBack_Name.MESSAGE_HOME_INIT
|
|
1023
1023
|
][type]
|
|
1024
1024
|
if (getTypeCallBack) {
|
|
1025
1025
|
const isCallBackFunc = typeof getTypeCallBack === 'function'
|
|
1026
1026
|
console.log(
|
|
1027
1027
|
'接收到原生通知 NATIVE_SHOPSTOW_SEND getSendJsonData',
|
|
1028
1028
|
getSendJsonData,
|
|
1029
1029
|
)
|
|
1030
1030
|
isCallBackFunc && getTypeCallBack(getSendJsonData)
|
|
1031
1031
|
}
|
|
1032
1032
|
break
|
|
1033
1033
|
case Message_Type.NATIVE_SHOW_DIALOG:
|
|
1034
1034
|
const showDialogCallBack =
|
|
1035
1035
|
Message_Trigger_CallBackFuncObj[
|
|
1036
1036
|
Message_CallBack_Name.MESSAGE_HOME_INIT
|
|
1037
1037
|
][type]
|
|
1038
1038
|
if (showDialogCallBack) {
|
|
1039
1039
|
const isCallBackFunc = typeof showDialogCallBack === 'function'
|
|
1040
1040
|
console.log(
|
|
1041
1041
|
`获取${type}类型数据数据type isCallBackFunc getMessageJsonData `,
|
|
1042
1042
|
type,
|
|
1043
1043
|
isCallBackFunc,
|
|
1044
1044
|
getMessageJsonData,
|
|
1045
1045
|
)
|
|
1046
1046
|
isCallBackFunc && showDialogCallBack(getMessageJsonData?.data)
|
|
1047
1047
|
}
|
|
1048
1048
|
break
|
|
1049
1049
|
case Message_Type.NATIVE_PAGE_SCROLL:
|
|
1050
1050
|
taroEventSendPageScrollInfo(data)
|
|
1051
1051
|
break
|
|
1052
1052
|
case Message_Type.NATIVE_PAGE_SCROLL_END:
|
|
1053
1053
|
taroEventSendPageScrollEndInfo(data)
|
|
1054
1054
|
break
|
|
1055
1055
|
case Message_Type.NATIVE_H5_SEND_MSG_TO_H5:
|
|
1056
1056
|
console.log('接收到原生通知 NATIVE_H5_SEND_MSG_TO_H5', data)
|
|
1057
1057
|
taroEventH5SendMsgToH5(getSendJsonData)
|
|
1058
1058
|
break
|
|
1059
1059
|
case Message_Type.UPDATE_NATIVE_DATA:
|
|
1060
1060
|
taroEventUpdateNativeData(getSendJsonData)
|
|
1061
1061
|
break
|
|
1062
1062
|
case Message_Type.H5_TO_SCROLL_TOP:
|
|
1063
1063
|
taroEventH5ToScrollTop()
|
|
1064
1064
|
break
|
|
1065
1065
|
case Message_Type.LUXURY_INFORM_CHANGE_HEIGHT:
|
|
1066
1066
|
taroEventSendImmersionStatus(data)
|
|
1067
1067
|
break
|
|
1068
1068
|
default:
|
|
1069
1069
|
}
|
|
1070
1070
|
} else {
|
|
1071
1071
|
console.log('传递数据获取异常', getMessageJsonData)
|
|
1072
1072
|
}
|
|
1073
1073
|
} catch (e) {
|
|
1074
1074
|
console.log('获取转换异常结果', e)
|
|
1075
1075
|
}
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
1078
|
nativePageRegisterMessage(Message_Type.NATIVE_OPEN_FLOAT, {
|
|
1079
1079
|
data: params,
|
|
1080
1080
|
})
|
|
1081
1081
|
nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
|
|
1082
1082
|
data: {
|
|
1083
1083
|
type: NATIVE_POP_WEBVIEW_TYPE.OPEN,
|
|
1084
1084
|
height: DEFAULT_POP_WEBVIEW_HEIGHT,
|
|
1085
1085
|
...params,
|
|
1086
1086
|
},
|
|
1087
1087
|
})
|
|
1088
1088
|
nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
|
|
1089
1089
|
data: {
|
|
1090
1090
|
type: NATIVE_POP_WEBVIEW_TYPE.CLOSE,
|
|
1091
1091
|
...params,
|
|
1092
1092
|
},
|
|
1093
1093
|
})
|
|
1094
1094
|
Taro.eventCenter.off(TaroEventType.JOIN_MEMBER_SUCCESS)
|
|
1095
1095
|
console.log('popWebview关闭')
|
|
1096
1096
|
nativePageRegisterMessage(Message_Type.NATIVE_H5_SEND_MSG_TO_H5, {
|
|
1097
1097
|
data: params,
|
|
1098
1098
|
})
|
|
1099
1099
|
nativePageRegisterMessage(Message_Type.NATIVE_PUSH_NATIVE_PAGE, {
|
|
1100
1100
|
data: params,
|
|
1101
1101
|
})
|
|
1102
1102
|
window &&
|
|
1103
1103
|
(window.location.href = `xview://search?request={"action":"${Message_Type.NAVTIVE_FLOAT_READY}"}`)
|
|
1104
1104
|
res: UtilsInterFace.nativePageScrollRes,
|
|
1105
1105
|
const { displayHeight, offSetY } = res
|
|
1106
1106
|
if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined')
|
|
1107
1107
|
return
|
|
1108
1108
|
if (isIosDevice) return res
|
|
1109
1109
|
if (isAndroidDevice) {
|
|
1110
1110
|
const deviceRatio = window.devicePixelRatio
|
|
1111
1111
|
const cssDisplayHeight = Math.ceil(displayHeight / deviceRatio)
|
|
1112
1112
|
const cssOffsetY = Math.ceil(offSetY / deviceRatio)
|
|
1113
1113
|
return {
|
|
1114
1114
|
displayHeight: cssDisplayHeight,
|
|
1115
1115
|
offSetY: cssOffsetY,
|
|
1116
1116
|
}
|
|
1117
1117
|
}
|
|
1118
1118
|
nativePageRegisterMessage(Message_Type.NATIVE_UPDATE_PAGE_INFO, {
|
|
1119
1119
|
data: params,
|
|
1120
1120
|
})
|
|
1121
1121
|
nativePageRegisterMessage(Message_Type.NATIVE_TO_BUYER_SHOW_DETAIL, {
|
|
1122
1122
|
data: params,
|
|
1123
1123
|
})
|
|
1124
1124
|
nativePageRegisterMessage(Message_Type.NATIVE_TO_HIDE_JD_SHOP_HEADER, {
|
|
1125
1125
|
data: params,
|
|
1126
1126
|
})
|