@conecli/cone-render 0.10.1-shop3.54 → 0.10.1-shop3.55

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
  isJdAndHarmonyDevice,
11
10
  (window.JDJshopViewInfo = {
12
11
  androidTouchSlop: 5,
13
12
  getAndroidTouchSlopState: false,
14
13
  });
15
14
  (state) => {
16
15
  console.log('document trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:', state);
17
16
  Taro.eventCenter.trigger(TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE, state ? 0 : 1);
18
17
  },
19
18
  1500,
20
19
  { leading: false, trailing: true },
21
20
  (state) => {
22
21
  console.log('IOS Android trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:', state);
23
22
  Taro.eventCenter.trigger(TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE, state);
24
23
  },
25
24
  1500,
26
25
  { leading: true, trailing: false },
27
26
  if (!isJdApp) {
28
27
  if (isH5) {
29
28
 
30
29
  const documentHandleVisibilityChange = () => {
31
30
  const state = document.hidden;
32
31
  window.startDocumentVisibilityChange && documentThrottledTrigger(state);
33
32
  };
34
33
  document.removeEventListener('visibilitychange', documentHandleVisibilityChange);
35
34
  console.log('每次进入页面先清除浏览器visibilitychange监听事件');
36
35
  setTimeout(() => {
37
36
  document.addEventListener('visibilitychange', documentHandleVisibilityChange, false);
38
37
  window.startDocumentVisibilityChange = true;
39
38
  }, 3000);
40
39
  }
41
40
  } else {
42
41
 
43
42
  !window.webviewVisible &&
44
43
  (window.webviewVisible = (state) => {
45
44
  if (window.startDocumentVisibilityChange) {
46
45
  webviewThrottledTrigger(state);
47
46
  } else {
48
47
  Taro.eventCenter.trigger(
49
48
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE_INIT_NOW_TIME,
50
49
  state,
51
50
  );
52
51
  }
53
52
  state === 1 && taroEventSendPageScrollInfo();
54
53
  });
55
54
  setTimeout(() => {
56
55
  window.startDocumentVisibilityChange = true;
57
56
  }, 3000);
58
57
  !window.floatReceiveData && (window.floatReceiveData = () => {});
59
58
  }
60
59
  MESSAGE_HOME_INIT: 'messageHomeInitPageData',
61
60
  [Message_CallBack_Name.MESSAGE_HOME_INIT]: {},
62
61
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = {
63
62
  displayHeight: 1920,
64
63
  offSetY: 0,
65
64
  };
66
65
  if (options) {
67
66
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = options;
68
67
  }
69
68
  const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {};
70
69
  Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL, options || latestRes);
71
70
  console.log('PageScrollEnd fire');
72
71
  Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL_END, options);
73
72
  const { businessType } = options;
74
73
  switch (businessType) {
75
74
  case H5_MSG_TO_H5_BUSINESSTYPE.JOIN_MEMBER_SUCCESS:
76
75
  Taro.eventCenter.trigger(TaroEventType.JOIN_MEMBER_SUCCESS, options);
77
76
  break;
78
77
  case H5_MSG_TO_H5_BUSINESSTYPE.h5BaseDataChange:
79
78
  Taro.eventCenter.trigger(TaroEventType.H5_BASE_DATA_CHANGE_REGISTER, options);
80
79
  break;
81
80
  default:
82
81
  break;
83
82
  }
84
83
  const { shopHomeExtendInfo } = options;
85
84
  if (shopHomeExtendInfo) {
86
85
  Taro.eventCenter.trigger(TaroEventType.UPDATE_SHOP_HOME_EXTEND_DATA, shopHomeExtendInfo);
87
86
  }
88
87
  window && window.scrollTo(0, 0);
89
88
  Taro.eventCenter.trigger(TaroEventType.PAGE_INIT_EXPOSURE, options);
90
89
  const { action, params } = options;
91
90
  console.log('taroEventShopStowSend', options);
92
91
  if (action) {
93
92
  Taro.eventCenter.trigger(action, params);
94
93
  }
95
94
  NATIVE_PAGE_READ: 'pageReady',
96
95
  NATIVE_PAGE_FINISH: 'pageFinish',
97
96
  NATIVE_INFO_DATA: 'nativeInfoData',
98
97
  NATIVE_PAGE_SCROLL: 'pageScroll',
99
98
  NATIVE_PAGE_SCROLL_END: 'pageScrollEnd',
100
99
  NATIVE_GET_SCROLL_TOP: 'nativeGetScrollTop',
101
100
  NATIVE_TO_SCROLL_TOP: 'nativeToScrollTop',
102
101
  NATIVE_CLOSE_SCROLL_MESSAGE: 'nativeCloseScrollMessage',
103
102
  NATIVE_MOBILE_CONFIG: 'getMobileConfig',
104
103
  NATIVE_SHOW_TOAST: 'showToast',
105
104
  NATIVE_SHOW_DIALOG: 'showDialog',
106
105
  NATIVE_PAGE_LAYOUT_CHANGE: 'pageLayoutChange',
107
106
  NATIVE_HOME_PAGING_ENABLE: 'homePagingEnable',
108
107
  NATIVE_GET_SCALED_TOUCH_SLOP: 'getScaledTouchSlop',
109
108
  NATIVE_ADD_CART: 'addCart',
110
109
  NATIVE_JUMP_TAB_BAR: 'jumpTabBar',
111
110
  NATIVE_OPEN_FLOAT: 'openFloat',
112
111
  NATIVE_INJECT_JS_FILE: 'needIsvPackage',
113
112
  NAVTIVE_FLOAT_READY: 'floatReady',
114
113
  NATIVE_REFRESH_PAGE: 'refreshPage',
115
114
  PAGE_PV_PARAM: 'pagePvParam',
116
115
  NATIVE_SCORLL_VIEW: 'nativeScrollControl',
117
116
  NATIVE_POP_WEBVIEW: 'popWebview',
118
117
  NATIVE_H5_SEND_MSG_TO_H5: 'h5SendMsgToH5',
119
118
  NATIVE_PUSH_NATIVE_PAGE: 'pushNativePage',
120
119
  UPDATE_NATIVE_DATA: 'updateNativeData',
121
120
  H5_TO_SCROLL_TOP: 'h5ToScrollTop',
122
121
  LUXURY_INFORM_CHANGE_HEIGHT: 'sendImmersionStatus',
123
122
  NATIVE_SHOPSTOW_SEND: 'sendMsgToShopStow',
124
123
  NATIVE_UPDATE_PAGE_INFO: 'pageCountInfo',
125
124
  NATIVE_TO_BUYER_SHOW_DETAIL: 'jumpBuyerShowDetail',
126
125
  NATIVE_TO_HIDE_JD_SHOP_HEADER: 'hideNativeHeader',
127
126
  NATIVE_TO_SHOW_CART_BTN: 'showCartButton',
128
127
  NATIVE_IMMERSIVEHEADER_STATE_CHANGE: 'immersiveHeaderStateChange',
129
128
  SHOP_FOLLOW_STATE_REGISTER: 'shopFollowStateRegister',
130
129
  SHOP_FOLLOW_STATE_SYNC: 'shopFollowStateSync',
131
130
  NATIVE_GET_SHOP_FOLLOW_STATE: 'getShopFollowState',
132
131
  H5_TO_NATIVE_LIVE_RESERVE_STATE: 'shopLiveReserveStateSync',
133
132
  H5_TO_NATIVE_SCROLL_TO_TOP: 'expertShopScrollToTop',
134
133
  OPEN: 'open',
135
134
  CLOSE: 'close',
136
135
  JOIN_MEMBER_SUCCESS: 'joinMemberSuccess',
137
136
  h5BaseDataChange: 'h5BaseDataChange',
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
  serialize: '1',
177
176
  routerParam: JSON.stringify(getRouterParam),
178
177
  callBackName: getCallBackName,
179
178
  callBackId: `${callBackName}Ios`,
180
179
  },
181
180
  });
182
181
  }
183
182
  } else if (isAndroidDevice) {
184
183
  if (type === Message_Type.NATIVE_MOBILE_CONFIG && jdAppVersionCompare('13.2.8') >= 0) {
185
184
  callRouterAndroid({
186
185
  routerURL: 'router://JDJShopModule/wrtNative',
187
186
  routerParam: getRouterParam,
188
187
  });
189
188
  } else {
190
189
  window?.JDJshop?.wrtNative(
191
190
  JSON.stringify({
192
191
  routerParam: JSON.stringify(getRouterParam),
193
192
  serialize: '1',
194
193
  callBackName: getCallBackName,
195
194
  callBackId: `${callBackName}Android`,
196
195
  }),
197
196
  );
198
197
  }
199
198
  } else if (isJdAndHarmonyDevice) {
200
199
  const plugin = 'JdShopPlugin';
201
200
  const action = type;
202
201
  const params = {
203
202
  routerURL: '',
204
203
  routerParam: getRouterParam,
205
204
  };
206
205
  window.XWebView &&
207
206
  window.XWebView.callNative(
208
207
  plugin,
209
208
  action,
210
209
  JSON.stringify(params),
211
210
  getCallBackName,
212
211
  `${callBackName}HarmonyOS`,
213
212
  );
214
213
  }
215
214
  return true;
216
215
  }
217
216
  return false;
218
217
  if (isJdApp) {
219
218
  if (isIosDevice) {
220
219
  window?.webkit?.messageHandlers?.MobileNavi?.postMessage({
221
220
  method: 'close',
222
221
  });
223
222
  } else if (isAndroidDevice) {
224
223
  window?.XView && window?.XView.close();
225
224
  } else if (isJdAndHarmonyDevice) {
226
225
  !isInLiveroomChannel && nativeClosePopWebView();
227
226
  isInLiveroomChannel &&
228
227
  window?.JDLiveAppJS &&
229
228
  window?.JDLiveAppJS?.handleJs(
230
229
  JSON.stringify([
231
230
  {
232
231
  action: 'closeWeb',
233
232
  params: {},
234
233
  },
235
234
  ]),
236
235
  );
237
236
  }
238
237
  }
239
238
  console.log('showToastByRouter:', title, showType);
240
239
  if (isJdApp) {
241
240
  const routerParam = {
242
241
  message: title,
243
242
  iconType: showType,
244
243
  duration,
245
244
  };
246
245
  if (isIosDevice) {
247
246
  callRouterIOS({
248
247
  routerURL: 'router://JDShopModule/showToast',
249
248
  routerParam,
250
249
  });
251
250
  } else if (isAndroidDevice) {
252
251
  callRouterAndroid({
253
252
  routerURL: 'router://JDJShopModule/showToast',
254
253
  routerParam,
255
254
  });
256
255
  } else if (isJdAndHarmonyDevice) {
257
256
  const plugin = 'JdShopPlugin';
258
257
  const action = 'showToast';
259
258
  const params = {
260
259
  routerURL: 'router://JDJShopModule/showToast',
261
260
  routerParam: routerParam,
262
261
  };
263
262
  window.XWebView && window.XWebView.callNative(plugin, action, JSON.stringify(params));
264
263
  }
265
264
  }
266
265
  console.log('nativePageLoadReady called');
267
266
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
268
267
  Message_Type.NATIVE_INFO_DATA
269
268
  ] = async (data: any) => {
270
269
  console.log('nativePageLoadReady callBack:', callBack, ', data:', data);
271
270
  callBack && callBack(data);
272
271
  };
273
272
  nativePageGetMessageInitCallBack();
274
273
  nativePageRegisterMessage(
275
274
  Message_Type.NATIVE_PAGE_READ,
276
275
  sendData,
277
276
  Message_CallBack_Name.MESSAGE_HOME_INIT,
278
277
  );
279
278
  return nativePageRegisterMessage(
280
279
  Message_Type.NATIVE_PAGE_FINISH,
281
280
  null,
282
281
  Message_CallBack_Name.MESSAGE_HOME_INIT,
283
282
  );
284
283
  callBack &&
285
284
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
286
285
  Message_Type.NATIVE_GET_SCROLL_TOP
287
286
  ] = callBack);
288
287
  return nativePageRegisterMessage(
289
288
  Message_Type.NATIVE_GET_SCROLL_TOP,
290
289
  null,
291
290
  Message_CallBack_Name.MESSAGE_HOME_INIT,
292
291
  );
293
292
  callBack &&
294
293
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
295
294
  Message_Type.NATIVE_TO_SCROLL_TOP
296
295
  ] = callBack);
297
296
  nativePageRegisterMessage(
298
297
  Message_Type.NATIVE_TO_SCROLL_TOP,
299
298
  {
300
299
  data: {
301
300
  scrollTop,
302
301
  },
303
302
  },
304
303
  Message_CallBack_Name.MESSAGE_HOME_INIT,
305
304
  );
306
305
  Taro.eventCenter.trigger(TaroEventType.LUXURY_INFORM_CHANGE_HEIGHT, data);
307
306
  Taro.eventCenter.trigger(TaroEventType.SHOP_FOLLOW_STATE_REGISTER, data);
308
307
  Taro.eventCenter.trigger(TaroEventType.IMMERSIVEHEADER_STATE_CHANGE, data);
309
308
  configName: string,
310
309
  isBeforePageReady: boolean,
311
310
  return new Promise((resolve, reject) => {
312
311
  if (!isJdApp) {
313
312
  reject({
314
313
  code: -1,
315
314
  message: 'getMPaasConfigByNative 只在松果APP店铺内部调用有效。',
316
315
  });
317
316
  return;
318
317
  }
319
318
  if (
320
319
  isIosDevice &&
321
320
  isBeforePageReady &&
322
321
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0
323
322
  ) {
324
323
  reject({
325
324
  code: -2,
326
325
  message: `在nativePageLoadReady之前调用,低于v${MPAAS_CONFIG_APP_VERSION}不会有返回,兜底处理`,
327
326
  });
328
327
  return;
329
328
  }
330
329
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
331
330
  Message_Type.NATIVE_MOBILE_CONFIG
332
331
  ] = (data: any) => {
333
332
  const configData = isAndroidDevice ? data : data?.data;
334
333
  const res = JSONParse(configData);
335
334
  resolve(res);
336
335
  };
337
336
  nativePageGetMessageInitCallBack();
338
337
  nativePageRegisterMessage(
339
338
  Message_Type.NATIVE_MOBILE_CONFIG,
340
339
  {
341
340
  data: {
342
341
  space: isIosDevice ? 'JDCDSHOP' : 'JDShop',
343
342
  configName,
344
343
  },
345
344
  },
346
345
  Message_CallBack_Name.MESSAGE_HOME_INIT,
347
346
  );
348
347
  });
349
348
  bussinessKey: string,
350
349
  isBeforePageReady: boolean,
351
350
  if (!bussinessKey) {
352
351
  return null;
353
352
  }
354
353
  if (!isJdApp) {
355
354
  return null;
356
355
  }
357
356
  const CACHED_MPAAS_KEY = `mpaas_${CONFIG_NAME}`;
358
357
  const CACHED_MPAAS_KEY_HELPER = `${CACHED_MPAAS_KEY}_helper`;
359
358
  let configData = window[CACHED_MPAAS_KEY];
360
359
  if (configData == null) {
361
360
  configData = await getMPaasConfigByNative(CONFIG_NAME, isBeforePageReady).catch((e) => {
362
361
  console.log('getMPaasConfigByNative error:', e);
363
362
  return null;
364
363
  });
365
364
  window[CACHED_MPAAS_KEY_HELPER] = {};
366
365
  window[CACHED_MPAAS_KEY] = configData;
367
366
  }
368
367
  if (configData) {
369
368
  const originData = configData[bussinessKey];
370
369
  const hasParse = window[CACHED_MPAAS_KEY_HELPER][bussinessKey];
371
370
  try {
372
371
  if (hasParse || ['object', 'boolean', 'number'].includes(typeof originData)) {
373
372
  return originData;
374
373
  } else {
375
374
  window[CACHED_MPAAS_KEY_HELPER][bussinessKey] = true;
376
375
  const parseData = JSON.parse(configData[bussinessKey]);
377
376
  configData[bussinessKey] = parseData;
378
377
  return parseData;
379
378
  }
380
379
  } catch (e) {
381
380
  return originData;
382
381
  }
383
382
  }
384
383
  return null;
385
384
  nativePageRegisterMessage(Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE);
386
385
  if (isJdAndAndroidDevice) {
387
386
  callBack &&
388
387
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
389
388
  Message_Type.NATIVE_HOME_PAGING_ENABLE
390
389
  ] = callBack);
391
390
  nativePageRegisterMessage(Message_Type.NATIVE_HOME_PAGING_ENABLE, {
392
391
  data: {
393
392
  enable: enable,
394
393
  },
395
394
  });
396
395
  }
397
396
  if (isJdAndAndroidDevice) {
398
397
  callBack &&
399
398
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
400
399
  Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP
401
400
  ] = callBack);
402
401
  nativePageRegisterMessage(Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP);
403
402
  }
404
403
  SUCCESS: 'success',
405
404
  FAIL: 'fail',
406
405
  NORMAL: 'normal',
407
406
  SUCCESS: 2,
408
407
  FAIL: 3,
409
408
  NORMAL: 1,
410
409
  SUCCESS: 2,
411
410
  FAIL: 3,
412
411
  NORMAL: 1,
413
412
  [ToastIosType.NORMAL]: ToastType.NORMAL,
414
413
  [ToastIosType.SUCCESS]: ToastType.SUCCESS,
415
414
  [ToastIosType.FAIL]: ToastType.FAIL,
416
415
  if (isShowNewRouterToast) {
417
416
  const changeShowType = isJdAndIosDevice
418
417
  ? toastIosTypeToNewToastType[showType] || showType
419
418
  : showType;
420
419
  showToastByRouter(title, changeShowType, duration * 1000);
421
420
  } else {
422
421
  nativePageRegisterMessage(Message_Type.NATIVE_SHOW_TOAST, {
423
422
  data: {
424
423
  message: title,
425
424
  iconType: showType,
426
425
  duration,
427
426
  },
428
427
  });
429
428
  }
430
429
  routerURL,
431
430
  routerParam,
432
431
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
433
432
  isSync = false,
434
433
  const getCallBackName = `window.${callBackName}`;
435
434
  const params = {
436
435
  routerURL,
437
436
  serialize: '1',
438
437
  routerParam,
439
438
  callBackName: getCallBackName,
440
439
  callBackId: `${callBackName}Ios`,
441
440
  };
442
441
  console.log(
443
442
  'callRouterIOS routerURL:',
444
443
  routerURL,
445
444
  ',routerParam:',
446
445
  routerParam,
447
446
  'params',
448
447
  params,
449
448
  'isSync',
450
449
  isSync,
451
450
  );
452
451
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
453
452
  method: isSync ? 'callSyncRouterModuleWithParams' : 'callRouterModuleWithParams',
454
453
  params: JSON.stringify(params),
455
454
  });
456
455
  routerURL,
457
456
  routerParam,
458
457
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
459
458
  isSync = false,
460
459
  hasJdRouter = true,
461
460
  console.log(
462
461
  'callRouterAndroid routerURL:',
463
462
  routerURL,
464
463
  ',routerParam:',
465
464
  routerParam,
466
465
  'isSync',
467
466
  isSync,
468
467
  );
469
468
  const getCallBackName = `window.${callBackName}`;
470
469
  routerParam?.data &&
471
470
  typeof routerParam?.data === 'object' &&
472
471
  (routerParam.data = JSON.stringify(routerParam?.data));
473
472
  var params = {
474
473
  serialize: '1',
475
474
  routerURL,
476
475
  routerParam,
477
476
  callBackName: getCallBackName,
478
477
  callBackId: `${callBackName}Android`,
479
478
  };
480
479
  hasJdRouter && (params['jdRouter'] = '1');
481
480
  isSync
482
481
  ? window?.JDAppUnite?.callSyncRouterModuleWithParams(JSON.stringify(params))
483
482
  : window?.JDAppUnite?.callRouterModuleWithParams(JSON.stringify(params));
484
483
  pluginName,
485
484
  action,
486
485
  routerParam,
487
486
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
488
487
  isSync = false,
489
488
  const getCallBackName = `window.${callBackName}`;
490
489
  const params = {
491
490
  routerURL: '',
492
491
  routerParam: routerParam,
493
492
  };
494
493
  const outBridgeType = ['getLastAddress', 'getAddress'];
495
494
  console.log(
496
495
  'callRouterHarmony pluginName:',
497
496
  pluginName,
498
497
  'action',
499
498
  action,
500
499
  ',routerParam:',
501
500
  routerParam,
502
501
  'params',
503
502
  params,
504
503
  'isSync',
505
504
  isSync,
506
505
  );
507
506
  window?.XWebView?.callNative(
508
507
  pluginName,
509
508
  action,
510
509
  outBridgeType.includes(action) ? JSON.stringify(routerParam) : JSON.stringify(params),
511
510
  getCallBackName,
512
511
  `${callBackName}HarmonyOS`,
513
512
  );
514
513
  callRouterHarmony,
515
514
  callBack &&
516
515
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
517
516
  Message_Type.NATIVE_SHOW_DIALOG
518
517
  ] = callBack);
519
518
  return nativePageRegisterMessage(Message_Type.NATIVE_SHOW_DIALOG, {
520
519
  data: params,
521
520
  });
522
521
  if (!isJdApp) {
523
522
  return;
524
523
  }
525
524
  if (!window[Message_CallBack_Name.MESSAGE_HOME_INIT]) {
526
525
  window[Message_CallBack_Name.MESSAGE_HOME_INIT] = (messageData) => {
527
526
  try {
528
527
  console.log('接收到原生通知返回的原始数据nativePageGetMessageInitCallBack', messageData);
529
528
  const getMessageJsonData = JSONParse(messageData);
530
529
  const { status } = getMessageJsonData;
531
530
  if (status == '0') {
532
531
  const { type, data } = getMessageJsonData?.data;
533
532
  const getSendJsonData = JSONParse(data);
534
533
  switch (type) {
535
534
  case Message_Type.NATIVE_INFO_DATA:
536
535
  case Message_Type.NATIVE_PAGE_FINISH:
537
536
  case Message_Type.NATIVE_GET_SCROLL_TOP:
538
537
  case Message_Type.NATIVE_TO_SCROLL_TOP:
539
538
  case Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE:
540
539
  case Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP:
541
540
  case Message_Type.NATIVE_MOBILE_CONFIG:
542
541
  case Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE:
543
542
  const getTypeCallBack =
544
543
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][type];
545
544
  if (getTypeCallBack) {
546
545
  const isCallBackFunc = typeof getTypeCallBack === 'function';
547
546
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND getSendJsonData', getSendJsonData);
548
547
  isCallBackFunc && getTypeCallBack(getSendJsonData);
549
548
  }
550
549
  break;
551
550
  case Message_Type.NATIVE_SHOW_DIALOG:
552
551
  const showDialogCallBack =
553
552
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][type];
554
553
  if (showDialogCallBack) {
555
554
  const isCallBackFunc = typeof showDialogCallBack === 'function';
556
555
  console.log(
557
556
  `获取${type}类型数据数据type isCallBackFunc getMessageJsonData `,
558
557
  type,
559
558
  isCallBackFunc,
560
559
  getMessageJsonData,
561
560
  );
562
561
  isCallBackFunc && showDialogCallBack(getMessageJsonData?.data);
563
562
  }
564
563
  break;
565
564
  case Message_Type.NATIVE_PAGE_SCROLL:
566
565
  taroEventSendPageScrollInfo(data);
567
566
  break;
568
567
  case Message_Type.NATIVE_PAGE_SCROLL_END:
569
568
  taroEventSendPageScrollEndInfo(data);
570
569
  break;
571
570
  case Message_Type.NATIVE_H5_SEND_MSG_TO_H5:
572
571
  console.log('接收到原生通知 NATIVE_H5_SEND_MSG_TO_H5', data);
573
572
  taroEventH5SendMsgToH5(getSendJsonData);
574
573
  break;
575
574
  case Message_Type.UPDATE_NATIVE_DATA:
576
575
  taroEventUpdateNativeData(getSendJsonData);
577
576
  break;
578
577
  case Message_Type.H5_TO_SCROLL_TOP:
579
578
  taroEventH5ToScrollTop();
580
579
  break;
581
580
  case Message_Type.NATIVE_SHOPSTOW_SEND:
582
581
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND', messageData);
583
582
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND getSendJsonData', getSendJsonData);
584
583
  taroEventShopStowSend(getSendJsonData);
585
584
  break;
586
585
  case Message_Type.LUXURY_INFORM_CHANGE_HEIGHT:
587
586
  taroEventSendImmersionStatus(data);
588
587
  break;
589
588
  case Message_Type.NATIVE_IMMERSIVEHEADER_STATE_CHANGE:
590
589
  taroEventSendImmersiveHeaderChange(data);
591
590
  break;
592
591
  case Message_Type.SHOP_FOLLOW_STATE_REGISTER:
593
592
  taroEventSendShopFollowStateChange(data);
594
593
  break;
595
594
  default:
596
595
  }
597
596
  } else {
598
597
  console.log('传递数据获取异常', getMessageJsonData);
599
598
  }
600
599
  } catch (e) {
601
600
  console.log('获取转换异常结果', e);
602
601
  }
603
602
  };
604
603
  }
605
604
  console.warn('🚀 ~~ JumpTabBarInCurrentShop() ~~ params:', params);
606
605
  nativePageRegisterMessage(Message_Type.NATIVE_JUMP_TAB_BAR, {
607
606
  data: params,
608
607
  });
609
608
  nativePageRegisterMessage(Message_Type.NATIVE_OPEN_FLOAT, {
610
609
  data: params,
611
610
  });
612
611
  const changeData = {
613
612
  type: NATIVE_POP_WEBVIEW_TYPE.OPEN,
614
613
  height: DEFAULT_POP_WEBVIEW_HEIGHT,
615
614
  };
616
615
  if (isChangeDefaultPopViewHeight && !params?.height) {
617
616
  changeData.height = Math.round(window.screen.height * 0.8);
618
617
  changeData.borderRadius = 12;
619
618
  }
620
619
  nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
621
620
  data: {
622
621
  ...changeData,
623
622
  ...params,
624
623
  },
625
624
  });
626
625
  nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
627
626
  data: {
628
627
  type: NATIVE_POP_WEBVIEW_TYPE.CLOSE,
629
628
  ...params,
630
629
  },
631
630
  });
632
631
  Taro.eventCenter.off(TaroEventType.JOIN_MEMBER_SUCCESS);
633
632
  console.log('popWebview关闭');
634
633
  nativePageRegisterMessage(Message_Type.NATIVE_H5_SEND_MSG_TO_H5, {
635
634
  data: params,
636
635
  });
637
636
  nativePageRegisterMessage(Message_Type.NATIVE_PUSH_NATIVE_PAGE, {
638
637
  data: params,
639
638
  });
640
639
  window &&
641
640
  (window.location.href = `xview://search?request={"action":"${Message_Type.NAVTIVE_FLOAT_READY}"}`);
642
641
  const { displayHeight, offSetY } = res;
643
642
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined') return;
644
643
  if (isIosDevice) return res;
645
644
  if (isAndroidDevice) {
646
645
  const deviceRatio = window.devicePixelRatio;
647
646
  const cssDisplayHeight = Math.ceil(displayHeight / deviceRatio);
648
647
  const cssOffsetY = Math.ceil(offSetY / deviceRatio);
649
648
  return {
650
649
  displayHeight: cssDisplayHeight,
651
650
  offSetY: cssOffsetY,
652
651
  };
653
652
  }
654
653
  nativePageRegisterMessage(Message_Type.NATIVE_UPDATE_PAGE_INFO, {
655
654
  data: params,
656
655
  });
657
656
  nativePageRegisterMessage(Message_Type.NATIVE_TO_BUYER_SHOW_DETAIL, {
658
657
  data: params,
659
658
  });
660
659
  nativePageRegisterMessage(Message_Type.NATIVE_TO_HIDE_JD_SHOP_HEADER, {
661
660
  data: params,
662
661
  });
663
662
  nativePageRegisterMessage(Message_Type.NATIVE_TO_SHOW_CART_BTN, {
664
663
  data: params,
665
664
  });
666
665
  nativePageRegisterMessage(Message_Type.SHOP_FOLLOW_STATE_REGISTER, {
667
666
  data: params,
668
667
  });
669
668
  callBack &&
670
669
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
671
670
  Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE
672
671
  ] = callBack);
673
672
  nativePageRegisterMessage(Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE, {
674
673
  data: {},
675
674
  });
676
675
  nativePageRegisterMessage(Message_Type.SHOP_FOLLOW_STATE_SYNC, {
677
676
  data: {
678
677
  followed: followState,
679
678
  },
680
679
  });
681
680
  nativePageRegisterMessage(Message_Type.H5_TO_NATIVE_LIVE_RESERVE_STATE, {
682
681
  data: params,
683
682
  });
684
683
  Taro.eventCenter.on('SEND_MSG_TO_NATIVE', (key, params) => {
685
684
  nativePageRegisterMessage(key, {
686
685
  data: params,
687
686
  });
688
687
  });
689
688
  nativePageRegisterMessage(Message_Type.H5_TO_NATIVE_SCROLL_TO_TOP, {
690
689
  data: params,
691
690
  });
691
+ import Taro from '@tarojs/taro';
692
692
  isH5AndJdShopView,
693
693
  isJdApp,
694
694
  isIosDevice,
695
695
  isAndroidDevice,
696
696
  isJdAndIosDevice,
697
697
  isJdAndAndroidDevice,
698
698
  jdAppVersionCompare,
699
699
  isAppStowShop,
700
700
  isJdAndHarmonyDevice,
701
701
  isInJdShopView,
702
702
  (window.JDJshopViewInfo = {
703
703
  androidTouchSlop: 5,
704
704
  getAndroidTouchSlopState: false,
705
705
  });
706
706
  (state) => {
707
707
  console.log('document trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:', state);
708
708
  Taro.eventCenter.trigger(TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE, state ? 0 : 1);
709
709
  },
710
710
  1500,
711
711
  { leading: false, trailing: true },
712
712
  (state) => {
713
713
  console.log('IOS Android trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:', state);
714
714
  Taro.eventCenter.trigger(TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE, state);
715
715
  },
716
716
  1500,
717
717
  { leading: true, trailing: false },
718
718
  if (!isJdApp) {
719
719
  if (isH5) {
720
720
 
721
721
  const documentHandleVisibilityChange = () => {
722
722
  const state = document.hidden;
723
723
  window.startDocumentVisibilityChange && documentThrottledTrigger(state);
724
724
  };
725
725
  document.removeEventListener('visibilitychange', documentHandleVisibilityChange);
726
726
  console.log('每次进入页面先清除浏览器visibilitychange监听事件');
727
727
  setTimeout(() => {
728
728
  document.addEventListener('visibilitychange', documentHandleVisibilityChange, false);
729
729
  window.startDocumentVisibilityChange = true;
730
730
  }, 3000);
731
731
  }
732
732
  } else {
733
733
 
734
734
  !window.webviewVisible &&
735
735
  (window.webviewVisible = (state) => {
736
736
  if (window.startDocumentVisibilityChange) {
737
737
  webviewThrottledTrigger(state);
738
738
  } else {
739
739
  Taro.eventCenter.trigger(
740
740
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE_INIT_NOW_TIME,
741
741
  state,
742
742
  );
743
743
  }
744
744
  state === 1 && taroEventSendPageScrollInfo();
745
745
  });
746
746
  setTimeout(() => {
747
747
  window.startDocumentVisibilityChange = true;
748
748
  }, 3000);
749
749
  !window.floatReceiveData && (window.floatReceiveData = () => {});
750
750
  }
751
751
  MESSAGE_HOME_INIT: 'messageHomeInitPageData',
752
752
  [Message_CallBack_Name.MESSAGE_HOME_INIT]: {},
753
753
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = {
754
754
  displayHeight: 1920,
755
755
  offSetY: 0,
756
756
  };
757
757
  if (options) {
758
758
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = options;
759
759
  }
760
760
  const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {};
761
761
  Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL, options || latestRes);
762
762
  console.log('PageScrollEnd fire');
763
763
  Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL_END, options);
764
764
  const { businessType } = options;
765
765
  switch (businessType) {
766
766
  case H5_MSG_TO_H5_BUSINESSTYPE.JOIN_MEMBER_SUCCESS:
767
767
  Taro.eventCenter.trigger(TaroEventType.JOIN_MEMBER_SUCCESS, options);
768
768
  break;
769
769
  case H5_MSG_TO_H5_BUSINESSTYPE.h5BaseDataChange:
770
770
  Taro.eventCenter.trigger(TaroEventType.H5_BASE_DATA_CHANGE_REGISTER, options);
771
771
  break;
772
772
  default:
773
773
  break;
774
774
  }
775
775
  const { shopHomeExtendInfo } = options;
776
776
  if (shopHomeExtendInfo) {
777
777
  Taro.eventCenter.trigger(TaroEventType.UPDATE_SHOP_HOME_EXTEND_DATA, shopHomeExtendInfo);
778
778
  }
779
779
  window && window.scrollTo(0, 0);
780
780
  Taro.eventCenter.trigger(TaroEventType.PAGE_INIT_EXPOSURE, options);
781
781
  const { action, params } = options;
782
782
  console.log('taroEventShopStowSend', options);
783
783
  if (action) {
784
784
  Taro.eventCenter.trigger(action, params);
785
785
  }
786
786
  NATIVE_PAGE_READ: 'pageReady',
787
787
  NATIVE_PAGE_FINISH: 'pageFinish',
788
788
  NATIVE_INFO_DATA: 'nativeInfoData',
789
789
  NATIVE_PAGE_SCROLL: 'pageScroll',
790
790
  NATIVE_PAGE_SCROLL_END: 'pageScrollEnd',
791
791
  NATIVE_GET_SCROLL_TOP: 'nativeGetScrollTop',
792
792
  NATIVE_TO_SCROLL_TOP: 'nativeToScrollTop',
793
793
  NATIVE_CLOSE_SCROLL_MESSAGE: 'nativeCloseScrollMessage',
794
794
  NATIVE_MOBILE_CONFIG: 'getMobileConfig',
795
795
  NATIVE_SHOW_TOAST: 'showToast',
796
796
  NATIVE_SHOW_DIALOG: 'showDialog',
797
797
  NATIVE_PAGE_LAYOUT_CHANGE: 'pageLayoutChange',
798
798
  NATIVE_HOME_PAGING_ENABLE: 'homePagingEnable',
799
799
  NATIVE_GET_SCALED_TOUCH_SLOP: 'getScaledTouchSlop',
800
800
  NATIVE_ADD_CART: 'addCart',
801
801
  NATIVE_JUMP_TAB_BAR: 'jumpTabBar',
802
802
  NATIVE_OPEN_FLOAT: 'openFloat',
803
803
  NATIVE_INJECT_JS_FILE: 'needIsvPackage',
804
804
  NAVTIVE_FLOAT_READY: 'floatReady',
805
805
  NATIVE_REFRESH_PAGE: 'refreshPage',
806
806
  PAGE_PV_PARAM: 'pagePvParam',
807
807
  NATIVE_SCORLL_VIEW: 'nativeScrollControl',
808
808
  NATIVE_POP_WEBVIEW: 'popWebview',
809
809
  NATIVE_H5_SEND_MSG_TO_H5: 'h5SendMsgToH5',
810
810
  NATIVE_PUSH_NATIVE_PAGE: 'pushNativePage',
811
811
  UPDATE_NATIVE_DATA: 'updateNativeData',
812
812
  H5_TO_SCROLL_TOP: 'h5ToScrollTop',
813
813
  LUXURY_INFORM_CHANGE_HEIGHT: 'sendImmersionStatus',
814
814
  NATIVE_SHOPSTOW_SEND: 'sendMsgToShopStow',
815
815
  NATIVE_UPDATE_PAGE_INFO: 'pageCountInfo',
816
816
  NATIVE_TO_BUYER_SHOW_DETAIL: 'jumpBuyerShowDetail',
817
817
  NATIVE_TO_HIDE_JD_SHOP_HEADER: 'hideNativeHeader',
818
818
  NATIVE_TO_SHOW_CART_BTN: 'showCartButton',
819
819
  NATIVE_IMMERSIVEHEADER_STATE_CHANGE: 'immersiveHeaderStateChange',
820
820
  SHOP_FOLLOW_STATE_REGISTER: 'shopFollowStateRegister',
821
821
  SHOP_FOLLOW_STATE_SYNC: 'shopFollowStateSync',
822
822
  NATIVE_GET_SHOP_FOLLOW_STATE: 'getShopFollowState',
823
823
  H5_TO_NATIVE_LIVE_RESERVE_STATE: 'shopLiveReserveStateSync',
824
824
  H5_TO_NATIVE_SCROLL_TO_TOP: 'expertShopScrollToTop',
825
825
  OPEN: 'open',
826
826
  CLOSE: 'close',
827
827
  JOIN_MEMBER_SUCCESS: 'joinMemberSuccess',
828
828
  h5BaseDataChange: 'h5BaseDataChange',
829
829
  type = Message_Type.NATIVE_PAGE_READ,
830
830
  sendData: null | object = null,
831
831
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
832
832
  console.log(
833
833
  '初始化nativePageRegisterMessage-isAppStowShop-type-sendData-isJdApp-isH5AndJdShopView',
834
834
  isAppStowShop,
835
835
  type,
836
836
  sendData,
837
837
  isJdApp,
838
838
  isH5AndJdShopView,
839
839
  callBackName,
840
840
  );
841
841
  if (isJdApp) {
842
842
  const getCallBackName = `window.${callBackName}`;
843
843
  let getRouterParam = {
844
844
  type,
845
845
  callBackName: getCallBackName,
846
846
  };
847
847
  if (!isAppStowShop) {
848
848
  getRouterParam['newHomePage'] = true;
849
849
  }
850
850
  if (sendData) {
851
851
  getRouterParam = Object.assign({}, getRouterParam, sendData);
852
852
  }
853
853
  if (isIosDevice) {
854
854
  const routerURL = isAppStowShop
855
855
  ? 'router://JDBDecorationPlatformModule/wrtNative'
856
856
  : 'router://JDShopModule/wrtNative';
857
857
  if (versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) >= 0) {
858
858
  callRouterIOS({
859
859
  routerURL,
860
860
  routerParam: getRouterParam,
861
861
  });
862
862
  } else {
863
863
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
864
864
  method: 'callRouterModuleWithParams',
865
865
  params: {
866
866
  routerURL,
867
867
  serialize: '1',
868
868
  routerParam: JSON.stringify(getRouterParam),
869
869
  callBackName: getCallBackName,
870
870
  callBackId: `${callBackName}Ios`,
871
871
  },
872
872
  });
873
873
  }
874
874
  } else if (isAndroidDevice) {
875
875
  if (type === Message_Type.NATIVE_MOBILE_CONFIG && jdAppVersionCompare('13.2.8') >= 0) {
876
876
  callRouterAndroid({
877
877
  routerURL: 'router://JDJShopModule/wrtNative',
878
878
  routerParam: getRouterParam,
879
879
  });
880
880
  } else {
881
881
  window?.JDJshop?.wrtNative(
882
882
  JSON.stringify({
883
883
  routerParam: JSON.stringify(getRouterParam),
884
884
  serialize: '1',
885
885
  callBackName: getCallBackName,
886
886
  callBackId: `${callBackName}Android`,
887
887
  }),
888
888
  );
889
889
  }
890
890
  } else if (isJdAndHarmonyDevice) {
891
891
  const plugin = 'JdShopPlugin';
892
892
  const action = type;
893
893
  const params = {
894
894
  routerURL: '',
895
895
  routerParam: getRouterParam,
896
896
  };
897
897
  window.XWebView &&
898
898
  window.XWebView.callNative(
899
899
  plugin,
900
900
  action,
901
901
  JSON.stringify(params),
902
902
  getCallBackName,
903
903
  `${callBackName}HarmonyOS`,
904
904
  );
905
905
  }
906
906
  return true;
907
907
  }
908
908
  return false;
909
909
  if (isJdApp) {
910
910
  if (isIosDevice) {
911
911
  window?.webkit?.messageHandlers?.MobileNavi?.postMessage({
912
912
  method: 'close',
913
913
  });
914
914
  } else if (isAndroidDevice) {
915
915
  window?.XView && window?.XView.close();
916
916
  } else if (isJdAndHarmonyDevice) {
917
917
  !isInLiveroomChannel && nativeClosePopWebView();
918
918
  if(isInLiveroomChannel){
919
919
  if( window?.JDLiveAppJS){
920
920
  window?.JDLiveAppJS?.handleJs(
921
921
  JSON.stringify([
922
922
  {
923
923
  action: 'closeWeb',
924
924
  params: {},
925
925
  },
926
926
  ]),
927
927
  );
928
928
  }else {
929
929
  window?.XWebView?.callNative && window.XWebView.callNative(
930
930
  'JDXViewPlugin',
931
931
  'closeLayer2',
932
932
  JSON.stringify({}),
933
933
  'shopxCloseXview',
934
934
  '1'
935
935
  );
936
936
  }
937
937
  }
938
938
  }
939
939
  }
940
940
  console.log('showToastByRouter:', title, showType);
941
941
  if (isJdApp) {
942
942
  const routerParam = {
943
943
  message: title,
944
944
  iconType: showType,
945
945
  duration,
946
946
  };
947
947
  if (isIosDevice) {
948
948
  callRouterIOS({
949
949
  routerURL: 'router://JDShopModule/showToast',
950
950
  routerParam,
951
951
  });
952
952
  } else if (isAndroidDevice) {
953
953
  callRouterAndroid({
954
954
  routerURL: 'router://JDJShopModule/showToast',
955
955
  routerParam,
956
956
  });
957
957
  } else if (isJdAndHarmonyDevice) {
958
958
  const getHarmonyVersion = window?.shopGlobalSwitch?.useNativeHarmonyToastVersion
959
959
  if(getHarmonyVersion && jdAppVersionCompare(getHarmonyVersion) >= 0 && !isInJdShopView && window?.jmfe?.callRouter) {
960
960
  const params = {
961
961
  routerURL: 'router://JDJShopxModule/showToast',
962
962
  routerParam: routerParam,
963
963
  sync: ''
964
964
  }
965
965
  window.jmfe.callRouter(params).then((res) => {
966
966
  console.log('鸿蒙调用toast成功',res)
967
967
  })
968
968
  }else {
969
969
  const plugin = 'JdShopPlugin';
970
970
  const action = 'showToast';
971
971
  const params = {
972
972
  routerURL: 'router://JDJShopModule/showToast',
973
973
  routerParam: routerParam,
974
974
  };
975
975
  window.XWebView && window.XWebView.callNative(plugin, action, JSON.stringify(params));
976
976
  }
977
977
  }
978
978
  }
979
979
  console.log('nativePageLoadReady called');
980
980
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
981
981
  Message_Type.NATIVE_INFO_DATA
982
982
  ] = async (data: any) => {
983
983
  console.log('nativePageLoadReady callBack:', callBack, ', data:', data);
984
984
  callBack && callBack(data);
985
985
  };
986
986
  nativePageGetMessageInitCallBack();
987
987
  nativePageRegisterMessage(
988
988
  Message_Type.NATIVE_PAGE_READ,
989
989
  sendData,
990
990
  Message_CallBack_Name.MESSAGE_HOME_INIT,
991
991
  );
992
992
  return nativePageRegisterMessage(
993
993
  Message_Type.NATIVE_PAGE_FINISH,
994
994
  null,
995
995
  Message_CallBack_Name.MESSAGE_HOME_INIT,
996
996
  );
997
997
  callBack &&
998
998
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
999
999
  Message_Type.NATIVE_GET_SCROLL_TOP
1000
1000
  ] = callBack);
1001
1001
  return nativePageRegisterMessage(
1002
1002
  Message_Type.NATIVE_GET_SCROLL_TOP,
1003
1003
  null,
1004
1004
  Message_CallBack_Name.MESSAGE_HOME_INIT,
1005
1005
  );
1006
1006
  callBack &&
1007
1007
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1008
1008
  Message_Type.NATIVE_TO_SCROLL_TOP
1009
1009
  ] = callBack);
1010
1010
  nativePageRegisterMessage(
1011
1011
  Message_Type.NATIVE_TO_SCROLL_TOP,
1012
1012
  {
1013
1013
  data: {
1014
1014
  scrollTop,
1015
1015
  },
1016
1016
  },
1017
1017
  Message_CallBack_Name.MESSAGE_HOME_INIT,
1018
1018
  );
1019
1019
  Taro.eventCenter.trigger(TaroEventType.LUXURY_INFORM_CHANGE_HEIGHT, data);
1020
1020
  Taro.eventCenter.trigger(TaroEventType.SHOP_FOLLOW_STATE_REGISTER, data);
1021
1021
  Taro.eventCenter.trigger(TaroEventType.IMMERSIVEHEADER_STATE_CHANGE, data);
1022
1022
  configName: string,
1023
1023
  isBeforePageReady: boolean,
1024
1024
  return new Promise((resolve, reject) => {
1025
1025
  if (!isJdApp) {
1026
1026
  reject({
1027
1027
  code: -1,
1028
1028
  message: 'getMPaasConfigByNative 只在松果APP店铺内部调用有效。',
1029
1029
  });
1030
1030
  return;
1031
1031
  }
1032
1032
  if (
1033
1033
  isIosDevice &&
1034
1034
  isBeforePageReady &&
1035
1035
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0
1036
1036
  ) {
1037
1037
  reject({
1038
1038
  code: -2,
1039
1039
  message: `在nativePageLoadReady之前调用,低于v${MPAAS_CONFIG_APP_VERSION}不会有返回,兜底处理`,
1040
1040
  });
1041
1041
  return;
1042
1042
  }
1043
1043
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1044
1044
  Message_Type.NATIVE_MOBILE_CONFIG
1045
1045
  ] = (data: any) => {
1046
1046
  const configData = isAndroidDevice ? data : data?.data;
1047
1047
  const res = JSONParse(configData);
1048
1048
  resolve(res);
1049
1049
  };
1050
1050
  nativePageGetMessageInitCallBack();
1051
1051
  nativePageRegisterMessage(
1052
1052
  Message_Type.NATIVE_MOBILE_CONFIG,
1053
1053
  {
1054
1054
  data: {
1055
1055
  space: isIosDevice ? 'JDCDSHOP' : 'JDShop',
1056
1056
  configName,
1057
1057
  },
1058
1058
  },
1059
1059
  Message_CallBack_Name.MESSAGE_HOME_INIT,
1060
1060
  );
1061
1061
  });
1062
1062
  bussinessKey: string,
1063
1063
  isBeforePageReady: boolean,
1064
1064
  if (!bussinessKey) {
1065
1065
  return null;
1066
1066
  }
1067
1067
  if (!isJdApp) {
1068
1068
  return null;
1069
1069
  }
1070
1070
  const CACHED_MPAAS_KEY = `mpaas_${CONFIG_NAME}`;
1071
1071
  const CACHED_MPAAS_KEY_HELPER = `${CACHED_MPAAS_KEY}_helper`;
1072
1072
  let configData = window[CACHED_MPAAS_KEY];
1073
1073
  if (configData == null) {
1074
1074
  configData = await getMPaasConfigByNative(CONFIG_NAME, isBeforePageReady).catch((e) => {
1075
1075
  console.log('getMPaasConfigByNative error:', e);
1076
1076
  return null;
1077
1077
  });
1078
1078
  window[CACHED_MPAAS_KEY_HELPER] = {};
1079
1079
  window[CACHED_MPAAS_KEY] = configData;
1080
1080
  }
1081
1081
  if (configData) {
1082
1082
  const originData = configData[bussinessKey];
1083
1083
  const hasParse = window[CACHED_MPAAS_KEY_HELPER][bussinessKey];
1084
1084
  try {
1085
1085
  if (hasParse || ['object', 'boolean', 'number'].includes(typeof originData)) {
1086
1086
  return originData;
1087
1087
  } else {
1088
1088
  window[CACHED_MPAAS_KEY_HELPER][bussinessKey] = true;
1089
1089
  const parseData = JSON.parse(configData[bussinessKey]);
1090
1090
  configData[bussinessKey] = parseData;
1091
1091
  return parseData;
1092
1092
  }
1093
1093
  } catch (e) {
1094
1094
  return originData;
1095
1095
  }
1096
1096
  }
1097
1097
  return null;
1098
1098
  nativePageRegisterMessage(Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE);
1099
1099
  if (isJdAndAndroidDevice) {
1100
1100
  callBack &&
1101
1101
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1102
1102
  Message_Type.NATIVE_HOME_PAGING_ENABLE
1103
1103
  ] = callBack);
1104
1104
  nativePageRegisterMessage(Message_Type.NATIVE_HOME_PAGING_ENABLE, {
1105
1105
  data: {
1106
1106
  enable: enable,
1107
1107
  },
1108
1108
  });
1109
1109
  }
1110
1110
  if (isJdAndAndroidDevice) {
1111
1111
  callBack &&
1112
1112
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1113
1113
  Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP
1114
1114
  ] = callBack);
1115
1115
  nativePageRegisterMessage(Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP);
1116
1116
  }
1117
1117
  SUCCESS: 'success',
1118
1118
  FAIL: 'fail',
1119
1119
  NORMAL: 'normal',
1120
1120
  SUCCESS: 2,
1121
1121
  FAIL: 3,
1122
1122
  NORMAL: 1,
1123
1123
  SUCCESS: 2,
1124
1124
  FAIL: 3,
1125
1125
  NORMAL: 1,
1126
1126
  [ToastIosType.NORMAL]: ToastType.NORMAL,
1127
1127
  [ToastIosType.SUCCESS]: ToastType.SUCCESS,
1128
1128
  [ToastIosType.FAIL]: ToastType.FAIL,
1129
1129
  if (isShowNewRouterToast) {
1130
1130
  const changeShowType = isJdAndIosDevice
1131
1131
  ? toastIosTypeToNewToastType[showType] || showType
1132
1132
  : showType;
1133
1133
  showToastByRouter(title, changeShowType, duration * 1000);
1134
1134
  } else {
1135
1135
  nativePageRegisterMessage(Message_Type.NATIVE_SHOW_TOAST, {
1136
1136
  data: {
1137
1137
  message: title,
1138
1138
  iconType: showType,
1139
1139
  duration,
1140
1140
  },
1141
1141
  });
1142
1142
  }
1143
1143
  routerURL,
1144
1144
  routerParam,
1145
1145
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
1146
1146
  isSync = false,
1147
1147
  const getCallBackName = `window.${callBackName}`;
1148
1148
  const params = {
1149
1149
  routerURL,
1150
1150
  serialize: '1',
1151
1151
  routerParam,
1152
1152
  callBackName: getCallBackName,
1153
1153
  callBackId: `${callBackName}Ios`,
1154
1154
  };
1155
1155
  console.log(
1156
1156
  'callRouterIOS routerURL:',
1157
1157
  routerURL,
1158
1158
  ',routerParam:',
1159
1159
  routerParam,
1160
1160
  'params',
1161
1161
  params,
1162
1162
  'isSync',
1163
1163
  isSync,
1164
1164
  );
1165
1165
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1166
1166
  method: isSync ? 'callSyncRouterModuleWithParams' : 'callRouterModuleWithParams',
1167
1167
  params: JSON.stringify(params),
1168
1168
  });
1169
1169
  routerURL,
1170
1170
  routerParam,
1171
1171
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
1172
1172
  isSync = false,
1173
1173
  hasJdRouter = true,
1174
1174
  console.log(
1175
1175
  'callRouterAndroid routerURL:',
1176
1176
  routerURL,
1177
1177
  ',routerParam:',
1178
1178
  routerParam,
1179
1179
  'isSync',
1180
1180
  isSync,
1181
1181
  );
1182
1182
  const getCallBackName = `window.${callBackName}`;
1183
1183
  routerParam?.data &&
1184
1184
  typeof routerParam?.data === 'object' &&
1185
1185
  (routerParam.data = JSON.stringify(routerParam?.data));
1186
1186
  var params = {
1187
1187
  serialize: '1',
1188
1188
  routerURL,
1189
1189
  routerParam,
1190
1190
  callBackName: getCallBackName,
1191
1191
  callBackId: `${callBackName}Android`,
1192
1192
  };
1193
1193
  hasJdRouter && (params['jdRouter'] = '1');
1194
1194
  isSync
1195
1195
  ? window?.JDAppUnite?.callSyncRouterModuleWithParams(JSON.stringify(params))
1196
1196
  : window?.JDAppUnite?.callRouterModuleWithParams(JSON.stringify(params));
1197
1197
  pluginName,
1198
1198
  action,
1199
1199
  routerParam,
1200
1200
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
1201
1201
  isSync = false,
1202
1202
  const getCallBackName = `window.${callBackName}`;
1203
1203
  const params = {
1204
1204
  routerURL: '',
1205
1205
  routerParam: routerParam,
1206
1206
  };
1207
1207
  const outBridgeType = ['getLastAddress', 'getAddress'];
1208
1208
  console.log(
1209
1209
  'callRouterHarmony pluginName:',
1210
1210
  pluginName,
1211
1211
  'action',
1212
1212
  action,
1213
1213
  ',routerParam:',
1214
1214
  routerParam,
1215
1215
  'params',
1216
1216
  params,
1217
1217
  'isSync',
1218
1218
  isSync,
1219
1219
  );
1220
1220
  window?.XWebView?.callNative(
1221
1221
  pluginName,
1222
1222
  action,
1223
1223
  outBridgeType.includes(action) ? JSON.stringify(routerParam) : JSON.stringify(params),
1224
1224
  getCallBackName,
1225
1225
  `${callBackName}HarmonyOS`,
1226
1226
  );
1227
1227
  callRouterHarmony,
1228
1228
  callBack &&
1229
1229
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1230
1230
  Message_Type.NATIVE_SHOW_DIALOG
1231
1231
  ] = callBack);
1232
1232
  return nativePageRegisterMessage(Message_Type.NATIVE_SHOW_DIALOG, {
1233
1233
  data: params,
1234
1234
  });
1235
1235
  if (!isJdApp) {
1236
1236
  return;
1237
1237
  }
1238
1238
  if (!window[Message_CallBack_Name.MESSAGE_HOME_INIT]) {
1239
1239
  window[Message_CallBack_Name.MESSAGE_HOME_INIT] = (messageData) => {
1240
1240
  try {
1241
1241
  console.log('接收到原生通知返回的原始数据nativePageGetMessageInitCallBack', messageData);
1242
1242
  const getMessageJsonData = JSONParse(messageData);
1243
1243
  const { status } = getMessageJsonData;
1244
1244
  if (status == '0') {
1245
1245
  const { type, data } = getMessageJsonData?.data;
1246
1246
  const getSendJsonData = JSONParse(data);
1247
1247
  switch (type) {
1248
1248
  case Message_Type.NATIVE_INFO_DATA:
1249
1249
  case Message_Type.NATIVE_PAGE_FINISH:
1250
1250
  case Message_Type.NATIVE_GET_SCROLL_TOP:
1251
1251
  case Message_Type.NATIVE_TO_SCROLL_TOP:
1252
1252
  case Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE:
1253
1253
  case Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP:
1254
1254
  case Message_Type.NATIVE_MOBILE_CONFIG:
1255
1255
  case Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE:
1256
1256
  const getTypeCallBack =
1257
1257
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][type];
1258
1258
  if (getTypeCallBack) {
1259
1259
  const isCallBackFunc = typeof getTypeCallBack === 'function';
1260
1260
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND getSendJsonData', getSendJsonData);
1261
1261
  isCallBackFunc && getTypeCallBack(getSendJsonData);
1262
1262
  }
1263
1263
  break;
1264
1264
  case Message_Type.NATIVE_SHOW_DIALOG:
1265
1265
  const showDialogCallBack =
1266
1266
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][type];
1267
1267
  if (showDialogCallBack) {
1268
1268
  const isCallBackFunc = typeof showDialogCallBack === 'function';
1269
1269
  console.log(
1270
1270
  `获取${type}类型数据数据type isCallBackFunc getMessageJsonData `,
1271
1271
  type,
1272
1272
  isCallBackFunc,
1273
1273
  getMessageJsonData,
1274
1274
  );
1275
1275
  isCallBackFunc && showDialogCallBack(getMessageJsonData?.data);
1276
1276
  }
1277
1277
  break;
1278
1278
  case Message_Type.NATIVE_PAGE_SCROLL:
1279
1279
  taroEventSendPageScrollInfo(data);
1280
1280
  break;
1281
1281
  case Message_Type.NATIVE_PAGE_SCROLL_END:
1282
1282
  taroEventSendPageScrollEndInfo(data);
1283
1283
  break;
1284
1284
  case Message_Type.NATIVE_H5_SEND_MSG_TO_H5:
1285
1285
  console.log('接收到原生通知 NATIVE_H5_SEND_MSG_TO_H5', data);
1286
1286
  taroEventH5SendMsgToH5(getSendJsonData);
1287
1287
  break;
1288
1288
  case Message_Type.UPDATE_NATIVE_DATA:
1289
1289
  taroEventUpdateNativeData(getSendJsonData);
1290
1290
  break;
1291
1291
  case Message_Type.H5_TO_SCROLL_TOP:
1292
1292
  taroEventH5ToScrollTop();
1293
1293
  break;
1294
1294
  case Message_Type.NATIVE_SHOPSTOW_SEND:
1295
1295
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND', messageData);
1296
1296
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND getSendJsonData', getSendJsonData);
1297
1297
  taroEventShopStowSend(getSendJsonData);
1298
1298
  break;
1299
1299
  case Message_Type.LUXURY_INFORM_CHANGE_HEIGHT:
1300
1300
  taroEventSendImmersionStatus(data);
1301
1301
  break;
1302
1302
  case Message_Type.NATIVE_IMMERSIVEHEADER_STATE_CHANGE:
1303
1303
  taroEventSendImmersiveHeaderChange(data);
1304
1304
  break;
1305
1305
  case Message_Type.SHOP_FOLLOW_STATE_REGISTER:
1306
1306
  taroEventSendShopFollowStateChange(data);
1307
1307
  break;
1308
1308
  default:
1309
1309
  }
1310
1310
  } else {
1311
1311
  console.log('传递数据获取异常', getMessageJsonData);
1312
1312
  }
1313
1313
  } catch (e) {
1314
1314
  console.log('获取转换异常结果', e);
1315
1315
  }
1316
1316
  };
1317
1317
  }
1318
1318
  console.warn('🚀 ~~ JumpTabBarInCurrentShop() ~~ params:', params);
1319
1319
  nativePageRegisterMessage(Message_Type.NATIVE_JUMP_TAB_BAR, {
1320
1320
  data: params,
1321
1321
  });
1322
1322
  nativePageRegisterMessage(Message_Type.NATIVE_OPEN_FLOAT, {
1323
1323
  data: params,
1324
1324
  });
1325
1325
  const changeData = {
1326
1326
  type: NATIVE_POP_WEBVIEW_TYPE.OPEN,
1327
1327
  height: DEFAULT_POP_WEBVIEW_HEIGHT,
1328
1328
  };
1329
1329
  if (isChangeDefaultPopViewHeight && !params?.height) {
1330
1330
  changeData.height = Math.round(window.screen.height * 0.8);
1331
1331
  changeData.borderRadius = 12;
1332
1332
  }
1333
1333
  nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
1334
1334
  data: {
1335
1335
  ...changeData,
1336
1336
  ...params,
1337
1337
  },
1338
1338
  });
1339
1339
  nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
1340
1340
  data: {
1341
1341
  type: NATIVE_POP_WEBVIEW_TYPE.CLOSE,
1342
1342
  ...params,
1343
1343
  },
1344
1344
  });
1345
1345
  Taro.eventCenter.off(TaroEventType.JOIN_MEMBER_SUCCESS);
1346
1346
  console.log('popWebview关闭');
1347
1347
  nativePageRegisterMessage(Message_Type.NATIVE_H5_SEND_MSG_TO_H5, {
1348
1348
  data: params,
1349
1349
  });
1350
1350
  nativePageRegisterMessage(Message_Type.NATIVE_PUSH_NATIVE_PAGE, {
1351
1351
  data: params,
1352
1352
  });
1353
1353
  window &&
1354
1354
  (window.location.href = `xview://search?request={"action":"${Message_Type.NAVTIVE_FLOAT_READY}"}`);
1355
1355
  const { displayHeight, offSetY } = res;
1356
1356
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined') return;
1357
1357
  if (isIosDevice) return res;
1358
1358
  if (isAndroidDevice) {
1359
1359
  const deviceRatio = window.devicePixelRatio;
1360
1360
  const cssDisplayHeight = Math.ceil(displayHeight / deviceRatio);
1361
1361
  const cssOffsetY = Math.ceil(offSetY / deviceRatio);
1362
1362
  return {
1363
1363
  displayHeight: cssDisplayHeight,
1364
1364
  offSetY: cssOffsetY,
1365
1365
  };
1366
1366
  }
1367
1367
  nativePageRegisterMessage(Message_Type.NATIVE_UPDATE_PAGE_INFO, {
1368
1368
  data: params,
1369
1369
  });
1370
1370
  nativePageRegisterMessage(Message_Type.NATIVE_TO_BUYER_SHOW_DETAIL, {
1371
1371
  data: params,
1372
1372
  });
1373
1373
  nativePageRegisterMessage(Message_Type.NATIVE_TO_HIDE_JD_SHOP_HEADER, {
1374
1374
  data: params,
1375
1375
  });
1376
1376
  nativePageRegisterMessage(Message_Type.NATIVE_TO_SHOW_CART_BTN, {
1377
1377
  data: params,
1378
1378
  });
1379
1379
  nativePageRegisterMessage(Message_Type.SHOP_FOLLOW_STATE_REGISTER, {
1380
1380
  data: params,
1381
1381
  });
1382
1382
  callBack &&
1383
1383
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1384
1384
  Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE
1385
1385
  ] = callBack);
1386
1386
  nativePageRegisterMessage(Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE, {
1387
1387
  data: {},
1388
1388
  });
1389
1389
  nativePageRegisterMessage(Message_Type.SHOP_FOLLOW_STATE_SYNC, {
1390
1390
  data: {
1391
1391
  followed: followState,
1392
1392
  },
1393
1393
  });
1394
1394
  nativePageRegisterMessage(Message_Type.H5_TO_NATIVE_LIVE_RESERVE_STATE, {
1395
1395
  data: params,
1396
1396
  });
1397
1397
  Taro.eventCenter.on('SEND_MSG_TO_NATIVE', (key, params) => {
1398
1398
  nativePageRegisterMessage(key, {
1399
1399
  data: params,
1400
1400
  });
1401
1401
  });
1402
1402
  nativePageRegisterMessage(Message_Type.H5_TO_NATIVE_SCROLL_TO_TOP, {
1403
1403
  data: params,
1404
1404
  });