@conecli/cone-render 0.10.1-shop3.48 → 0.10.1-shop3.49

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
  (window.JDJshopViewInfo = {
702
702
  androidTouchSlop: 5,
703
703
  getAndroidTouchSlopState: false,
704
704
  });
705
705
  (state) => {
706
706
  console.log('document trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:', state);
707
707
  Taro.eventCenter.trigger(TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE, state ? 0 : 1);
708
708
  },
709
709
  1500,
710
710
  { leading: false, trailing: true },
711
711
  (state) => {
712
712
  console.log('IOS Android trigger PAGE_DOCUMENT_VISIBILITY_CHANGE state:', state);
713
713
  Taro.eventCenter.trigger(TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE, state);
714
714
  },
715
715
  1500,
716
716
  { leading: true, trailing: false },
717
717
  if (!isJdApp) {
718
718
  if (isH5) {
719
719
 
720
720
  const documentHandleVisibilityChange = () => {
721
721
  const state = document.hidden;
722
722
  window.startDocumentVisibilityChange && documentThrottledTrigger(state);
723
723
  };
724
724
  document.removeEventListener('visibilitychange', documentHandleVisibilityChange);
725
725
  console.log('每次进入页面先清除浏览器visibilitychange监听事件');
726
726
  setTimeout(() => {
727
727
  document.addEventListener('visibilitychange', documentHandleVisibilityChange, false);
728
728
  window.startDocumentVisibilityChange = true;
729
729
  }, 3000);
730
730
  }
731
731
  } else {
732
732
 
733
733
  !window.webviewVisible &&
734
734
  (window.webviewVisible = (state) => {
735
735
  if (window.startDocumentVisibilityChange) {
736
736
  webviewThrottledTrigger(state);
737
737
  } else {
738
738
  Taro.eventCenter.trigger(
739
739
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE_INIT_NOW_TIME,
740
740
  state,
741
741
  );
742
742
  }
743
743
  state === 1 && taroEventSendPageScrollInfo();
744
744
  });
745
745
  setTimeout(() => {
746
746
  window.startDocumentVisibilityChange = true;
747
747
  }, 3000);
748
748
  !window.floatReceiveData && (window.floatReceiveData = () => {});
749
749
  }
750
750
  MESSAGE_HOME_INIT: 'messageHomeInitPageData',
751
751
  [Message_CallBack_Name.MESSAGE_HOME_INIT]: {},
752
752
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = {
753
753
  displayHeight: 1920,
754
754
  offSetY: 0,
755
755
  };
756
756
  if (options) {
757
757
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] = options;
758
758
  }
759
759
  const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {};
760
760
  Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL, options || latestRes);
761
761
  console.log('PageScrollEnd fire');
762
762
  Taro.eventCenter.trigger(TaroEventType.PAGE_SCROLL_END, options);
763
763
  const { businessType } = options;
764
764
  switch (businessType) {
765
765
  case H5_MSG_TO_H5_BUSINESSTYPE.JOIN_MEMBER_SUCCESS:
766
766
  Taro.eventCenter.trigger(TaroEventType.JOIN_MEMBER_SUCCESS, options);
767
767
  break;
768
768
  case H5_MSG_TO_H5_BUSINESSTYPE.h5BaseDataChange:
769
769
  Taro.eventCenter.trigger(TaroEventType.H5_BASE_DATA_CHANGE_REGISTER, options);
770
770
  break;
771
771
  default:
772
772
  break;
773
773
  }
774
774
  const { shopHomeExtendInfo } = options;
775
775
  if (shopHomeExtendInfo) {
776
776
  Taro.eventCenter.trigger(TaroEventType.UPDATE_SHOP_HOME_EXTEND_DATA, shopHomeExtendInfo);
777
777
  }
778
778
  window && window.scrollTo(0, 0);
779
779
  Taro.eventCenter.trigger(TaroEventType.PAGE_INIT_EXPOSURE, options);
780
780
  const { action, params } = options;
781
781
  console.log('taroEventShopStowSend', options);
782
782
  if (action) {
783
783
  Taro.eventCenter.trigger(action, params);
784
784
  }
785
785
  NATIVE_PAGE_READ: 'pageReady',
786
786
  NATIVE_PAGE_FINISH: 'pageFinish',
787
787
  NATIVE_INFO_DATA: 'nativeInfoData',
788
788
  NATIVE_PAGE_SCROLL: 'pageScroll',
789
789
  NATIVE_PAGE_SCROLL_END: 'pageScrollEnd',
790
790
  NATIVE_GET_SCROLL_TOP: 'nativeGetScrollTop',
791
791
  NATIVE_TO_SCROLL_TOP: 'nativeToScrollTop',
792
792
  NATIVE_CLOSE_SCROLL_MESSAGE: 'nativeCloseScrollMessage',
793
793
  NATIVE_MOBILE_CONFIG: 'getMobileConfig',
794
794
  NATIVE_SHOW_TOAST: 'showToast',
795
795
  NATIVE_SHOW_DIALOG: 'showDialog',
796
796
  NATIVE_PAGE_LAYOUT_CHANGE: 'pageLayoutChange',
797
797
  NATIVE_HOME_PAGING_ENABLE: 'homePagingEnable',
798
798
  NATIVE_GET_SCALED_TOUCH_SLOP: 'getScaledTouchSlop',
799
799
  NATIVE_ADD_CART: 'addCart',
800
800
  NATIVE_JUMP_TAB_BAR: 'jumpTabBar',
801
801
  NATIVE_OPEN_FLOAT: 'openFloat',
802
802
  NATIVE_INJECT_JS_FILE: 'needIsvPackage',
803
803
  NAVTIVE_FLOAT_READY: 'floatReady',
804
804
  NATIVE_REFRESH_PAGE: 'refreshPage',
805
805
  PAGE_PV_PARAM: 'pagePvParam',
806
806
  NATIVE_SCORLL_VIEW: 'nativeScrollControl',
807
807
  NATIVE_POP_WEBVIEW: 'popWebview',
808
808
  NATIVE_H5_SEND_MSG_TO_H5: 'h5SendMsgToH5',
809
809
  NATIVE_PUSH_NATIVE_PAGE: 'pushNativePage',
810
810
  UPDATE_NATIVE_DATA: 'updateNativeData',
811
811
  H5_TO_SCROLL_TOP: 'h5ToScrollTop',
812
812
  LUXURY_INFORM_CHANGE_HEIGHT: 'sendImmersionStatus',
813
813
  NATIVE_SHOPSTOW_SEND: 'sendMsgToShopStow',
814
814
  NATIVE_UPDATE_PAGE_INFO: 'pageCountInfo',
815
815
  NATIVE_TO_BUYER_SHOW_DETAIL: 'jumpBuyerShowDetail',
816
816
  NATIVE_TO_HIDE_JD_SHOP_HEADER: 'hideNativeHeader',
817
817
  NATIVE_TO_SHOW_CART_BTN: 'showCartButton',
818
818
  NATIVE_IMMERSIVEHEADER_STATE_CHANGE: 'immersiveHeaderStateChange',
819
819
  SHOP_FOLLOW_STATE_REGISTER: 'shopFollowStateRegister',
820
820
  SHOP_FOLLOW_STATE_SYNC: 'shopFollowStateSync',
821
821
  NATIVE_GET_SHOP_FOLLOW_STATE: 'getShopFollowState',
822
822
  H5_TO_NATIVE_LIVE_RESERVE_STATE: 'shopLiveReserveStateSync',
823
823
  H5_TO_NATIVE_SCROLL_TO_TOP: 'expertShopScrollToTop',
824
824
  OPEN: 'open',
825
825
  CLOSE: 'close',
826
826
  JOIN_MEMBER_SUCCESS: 'joinMemberSuccess',
827
827
  h5BaseDataChange: 'h5BaseDataChange',
828
828
  type = Message_Type.NATIVE_PAGE_READ,
829
829
  sendData: null | object = null,
830
830
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
831
831
  console.log(
832
832
  '初始化nativePageRegisterMessage-isAppStowShop-type-sendData-isJdApp-isH5AndJdShopView',
833
833
  isAppStowShop,
834
834
  type,
835
835
  sendData,
836
836
  isJdApp,
837
837
  isH5AndJdShopView,
838
838
  callBackName,
839
839
  );
840
840
  if (isJdApp) {
841
841
  const getCallBackName = `window.${callBackName}`;
842
842
  let getRouterParam = {
843
843
  type,
844
844
  callBackName: getCallBackName,
845
845
  };
846
846
  if (!isAppStowShop) {
847
847
  getRouterParam['newHomePage'] = true;
848
848
  }
849
849
  if (sendData) {
850
850
  getRouterParam = Object.assign({}, getRouterParam, sendData);
851
851
  }
852
852
  if (isIosDevice) {
853
853
  const routerURL = isAppStowShop
854
854
  ? 'router://JDBDecorationPlatformModule/wrtNative'
855
855
  : 'router://JDShopModule/wrtNative';
856
856
  if (versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) >= 0) {
857
857
  callRouterIOS({
858
858
  routerURL,
859
859
  routerParam: getRouterParam,
860
860
  });
861
861
  } else {
862
862
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
863
863
  method: 'callRouterModuleWithParams',
864
864
  params: {
865
865
  routerURL,
866
866
  serialize: '1',
867
867
  routerParam: JSON.stringify(getRouterParam),
868
868
  callBackName: getCallBackName,
869
869
  callBackId: `${callBackName}Ios`,
870
870
  },
871
871
  });
872
872
  }
873
873
  } else if (isAndroidDevice) {
874
874
  if (type === Message_Type.NATIVE_MOBILE_CONFIG && jdAppVersionCompare('13.2.8') >= 0) {
875
875
  callRouterAndroid({
876
876
  routerURL: 'router://JDJShopModule/wrtNative',
877
877
  routerParam: getRouterParam,
878
878
  });
879
879
  } else {
880
880
  window?.JDJshop?.wrtNative(
881
881
  JSON.stringify({
882
882
  routerParam: JSON.stringify(getRouterParam),
883
883
  serialize: '1',
884
884
  callBackName: getCallBackName,
885
885
  callBackId: `${callBackName}Android`,
886
886
  }),
887
887
  );
888
888
  }
889
889
  } else if (isJdAndHarmonyDevice) {
890
890
  const plugin = 'JdShopPlugin';
891
891
  const action = type;
892
892
  const params = {
893
893
  routerURL: '',
894
894
  routerParam: getRouterParam,
895
895
  };
896
896
  window.XWebView &&
897
897
  window.XWebView.callNative(
898
898
  plugin,
899
899
  action,
900
900
  JSON.stringify(params),
901
901
  getCallBackName,
902
902
  `${callBackName}HarmonyOS`,
903
903
  );
904
904
  }
905
905
  return true;
906
906
  }
907
907
  return false;
908
908
  if (isJdApp) {
909
909
  if (isIosDevice) {
910
910
  window?.webkit?.messageHandlers?.MobileNavi?.postMessage({
911
911
  method: 'close',
912
912
  });
913
913
  } else if (isAndroidDevice) {
914
914
  window?.XView && window?.XView.close();
915
915
  } else if (isJdAndHarmonyDevice) {
916
916
  !isInLiveroomChannel && nativeClosePopWebView();
917
917
  isInLiveroomChannel &&
918
918
  window?.JDLiveAppJS &&
919
919
  window?.JDLiveAppJS?.handleJs(
920
920
  JSON.stringify([
921
921
  {
922
922
  action: 'closeWeb',
923
923
  params: {},
924
924
  },
925
925
  ]),
926
926
  );
927
927
  }
928
928
  }
929
929
  console.log('showToastByRouter:', title, showType);
930
930
  if (isJdApp) {
931
931
  const routerParam = {
932
932
  message: title,
933
933
  iconType: showType,
934
934
  duration,
935
935
  };
936
936
  if (isIosDevice) {
937
937
  callRouterIOS({
938
938
  routerURL: 'router://JDShopModule/showToast',
939
939
  routerParam,
940
940
  });
941
941
  } else if (isAndroidDevice) {
942
942
  callRouterAndroid({
943
943
  routerURL: 'router://JDJShopModule/showToast',
944
944
  routerParam,
945
945
  });
946
946
  } else if (isJdAndHarmonyDevice) {
947
947
  const plugin = 'JdShopPlugin';
948
948
  const action = 'showToast';
949
949
  const params = {
950
950
  routerURL: 'router://JDJShopModule/showToast',
951
951
  routerParam: routerParam,
952
952
  };
953
953
  window.XWebView && window.XWebView.callNative(plugin, action, JSON.stringify(params));
954
954
  }
955
955
  }
956
956
  console.log('nativePageLoadReady called');
957
957
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
958
958
  Message_Type.NATIVE_INFO_DATA
959
959
  ] = async (data: any) => {
960
960
  console.log('nativePageLoadReady callBack:', callBack, ', data:', data);
961
961
  callBack && callBack(data);
962
962
  };
963
963
  nativePageGetMessageInitCallBack();
964
964
  nativePageRegisterMessage(
965
965
  Message_Type.NATIVE_PAGE_READ,
966
966
  sendData,
967
967
  Message_CallBack_Name.MESSAGE_HOME_INIT,
968
968
  );
969
969
  return nativePageRegisterMessage(
970
970
  Message_Type.NATIVE_PAGE_FINISH,
971
971
  null,
972
972
  Message_CallBack_Name.MESSAGE_HOME_INIT,
973
973
  );
974
974
  callBack &&
975
975
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
976
976
  Message_Type.NATIVE_GET_SCROLL_TOP
977
977
  ] = callBack);
978
978
  return nativePageRegisterMessage(
979
979
  Message_Type.NATIVE_GET_SCROLL_TOP,
980
980
  null,
981
981
  Message_CallBack_Name.MESSAGE_HOME_INIT,
982
982
  );
983
983
  callBack &&
984
984
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
985
985
  Message_Type.NATIVE_TO_SCROLL_TOP
986
986
  ] = callBack);
987
987
  nativePageRegisterMessage(
988
988
  Message_Type.NATIVE_TO_SCROLL_TOP,
989
989
  {
990
990
  data: {
991
991
  scrollTop,
992
992
  },
993
993
  },
994
994
  Message_CallBack_Name.MESSAGE_HOME_INIT,
995
995
  );
996
996
  Taro.eventCenter.trigger(TaroEventType.LUXURY_INFORM_CHANGE_HEIGHT, data);
997
997
  Taro.eventCenter.trigger(TaroEventType.SHOP_FOLLOW_STATE_REGISTER, data);
998
998
  Taro.eventCenter.trigger(TaroEventType.IMMERSIVEHEADER_STATE_CHANGE, data);
999
999
  configName: string,
1000
1000
  isBeforePageReady: boolean,
1001
1001
  return new Promise((resolve, reject) => {
1002
1002
  if (!isJdApp) {
1003
1003
  reject({
1004
1004
  code: -1,
1005
1005
  message: 'getMPaasConfigByNative 只在松果APP店铺内部调用有效。',
1006
1006
  });
1007
1007
  return;
1008
1008
  }
1009
1009
  if (
1010
1010
  isIosDevice &&
1011
1011
  isBeforePageReady &&
1012
1012
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0
1013
1013
  ) {
1014
1014
  reject({
1015
1015
  code: -2,
1016
1016
  message: `在nativePageLoadReady之前调用,低于v${MPAAS_CONFIG_APP_VERSION}不会有返回,兜底处理`,
1017
1017
  });
1018
1018
  return;
1019
1019
  }
1020
1020
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1021
1021
  Message_Type.NATIVE_MOBILE_CONFIG
1022
1022
  ] = (data: any) => {
1023
1023
  const configData = isAndroidDevice ? data : data?.data;
1024
1024
  const res = JSONParse(configData);
1025
1025
  resolve(res);
1026
1026
  };
1027
1027
  nativePageGetMessageInitCallBack();
1028
1028
  nativePageRegisterMessage(
1029
1029
  Message_Type.NATIVE_MOBILE_CONFIG,
1030
1030
  {
1031
1031
  data: {
1032
1032
  space: isIosDevice ? 'JDCDSHOP' : 'JDShop',
1033
1033
  configName,
1034
1034
  },
1035
1035
  },
1036
1036
  Message_CallBack_Name.MESSAGE_HOME_INIT,
1037
1037
  );
1038
1038
  });
1039
1039
  bussinessKey: string,
1040
1040
  isBeforePageReady: boolean,
1041
1041
  if (!bussinessKey) {
1042
1042
  return null;
1043
1043
  }
1044
1044
  if (!isJdApp) {
1045
1045
  return null;
1046
1046
  }
1047
1047
  const CACHED_MPAAS_KEY = `mpaas_${CONFIG_NAME}`;
1048
1048
  const CACHED_MPAAS_KEY_HELPER = `${CACHED_MPAAS_KEY}_helper`;
1049
1049
  let configData = window[CACHED_MPAAS_KEY];
1050
1050
  if (configData == null) {
1051
1051
  configData = await getMPaasConfigByNative(CONFIG_NAME, isBeforePageReady).catch((e) => {
1052
1052
  console.log('getMPaasConfigByNative error:', e);
1053
1053
  return null;
1054
1054
  });
1055
1055
  window[CACHED_MPAAS_KEY_HELPER] = {};
1056
1056
  window[CACHED_MPAAS_KEY] = configData;
1057
1057
  }
1058
1058
  if (configData) {
1059
1059
  const originData = configData[bussinessKey];
1060
1060
  const hasParse = window[CACHED_MPAAS_KEY_HELPER][bussinessKey];
1061
1061
  try {
1062
1062
  if (hasParse || ['object', 'boolean', 'number'].includes(typeof originData)) {
1063
1063
  return originData;
1064
1064
  } else {
1065
1065
  window[CACHED_MPAAS_KEY_HELPER][bussinessKey] = true;
1066
1066
  const parseData = JSON.parse(configData[bussinessKey]);
1067
1067
  configData[bussinessKey] = parseData;
1068
1068
  return parseData;
1069
1069
  }
1070
1070
  } catch (e) {
1071
1071
  return originData;
1072
1072
  }
1073
1073
  }
1074
1074
  return null;
1075
1075
  nativePageRegisterMessage(Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE);
1076
1076
  if (isJdAndAndroidDevice) {
1077
1077
  callBack &&
1078
1078
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1079
1079
  Message_Type.NATIVE_HOME_PAGING_ENABLE
1080
1080
  ] = callBack);
1081
1081
  nativePageRegisterMessage(Message_Type.NATIVE_HOME_PAGING_ENABLE, {
1082
1082
  data: {
1083
1083
  enable: enable,
1084
1084
  },
1085
1085
  });
1086
1086
  }
1087
1087
  if (isJdAndAndroidDevice) {
1088
1088
  callBack &&
1089
1089
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1090
1090
  Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP
1091
1091
  ] = callBack);
1092
1092
  nativePageRegisterMessage(Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP);
1093
1093
  }
1094
1094
  SUCCESS: 'success',
1095
1095
  FAIL: 'fail',
1096
1096
  NORMAL: 'normal',
1097
1097
  SUCCESS: 2,
1098
1098
  FAIL: 3,
1099
1099
  NORMAL: 1,
1100
1100
  SUCCESS: 2,
1101
1101
  FAIL: 3,
1102
1102
  NORMAL: 1,
1103
1103
  [ToastIosType.NORMAL]: ToastType.NORMAL,
1104
1104
  [ToastIosType.SUCCESS]: ToastType.SUCCESS,
1105
1105
  [ToastIosType.FAIL]: ToastType.FAIL,
1106
1106
  if (isShowNewRouterToast) {
1107
1107
  const changeShowType = isJdAndIosDevice
1108
1108
  ? toastIosTypeToNewToastType[showType] || showType
1109
1109
  : showType;
1110
1110
  showToastByRouter(title, changeShowType, duration * 1000);
1111
1111
  } else {
1112
1112
  nativePageRegisterMessage(Message_Type.NATIVE_SHOW_TOAST, {
1113
1113
  data: {
1114
1114
  message: title,
1115
1115
  iconType: showType,
1116
1116
  duration,
1117
1117
  },
1118
1118
  });
1119
1119
  }
1120
1120
  routerURL,
1121
1121
  routerParam,
1122
1122
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
1123
1123
  isSync = false,
1124
1124
  const getCallBackName = `window.${callBackName}`;
1125
1125
  const params = {
1126
1126
  routerURL,
1127
1127
  serialize: '1',
1128
1128
  routerParam,
1129
1129
  callBackName: getCallBackName,
1130
1130
  callBackId: `${callBackName}Ios`,
1131
1131
  };
1132
1132
  console.log(
1133
1133
  'callRouterIOS routerURL:',
1134
1134
  routerURL,
1135
1135
  ',routerParam:',
1136
1136
  routerParam,
1137
1137
  'params',
1138
1138
  params,
1139
1139
  'isSync',
1140
1140
  isSync,
1141
1141
  );
1142
1142
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1143
1143
  method: isSync ? 'callSyncRouterModuleWithParams' : 'callRouterModuleWithParams',
1144
1144
  params: JSON.stringify(params),
1145
1145
  });
1146
1146
  routerURL,
1147
1147
  routerParam,
1148
1148
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
1149
1149
  isSync = false,
1150
1150
  hasJdRouter = true,
1151
1151
  console.log(
1152
1152
  'callRouterAndroid routerURL:',
1153
1153
  routerURL,
1154
1154
  ',routerParam:',
1155
1155
  routerParam,
1156
1156
  'isSync',
1157
1157
  isSync,
1158
1158
  );
1159
1159
  const getCallBackName = `window.${callBackName}`;
1160
1160
  routerParam?.data &&
1161
1161
  typeof routerParam?.data === 'object' &&
1162
1162
  (routerParam.data = JSON.stringify(routerParam?.data));
1163
1163
  var params = {
1164
1164
  serialize: '1',
1165
1165
  routerURL,
1166
1166
  routerParam,
1167
1167
  callBackName: getCallBackName,
1168
1168
  callBackId: `${callBackName}Android`,
1169
1169
  };
1170
1170
  hasJdRouter && (params['jdRouter'] = '1');
1171
1171
  isSync
1172
1172
  ? window?.JDAppUnite?.callSyncRouterModuleWithParams(JSON.stringify(params))
1173
1173
  : window?.JDAppUnite?.callRouterModuleWithParams(JSON.stringify(params));
1174
1174
  pluginName,
1175
1175
  action,
1176
1176
  routerParam,
1177
1177
  callBackName = Message_CallBack_Name.MESSAGE_HOME_INIT,
1178
1178
  isSync = false,
1179
1179
  const getCallBackName = `window.${callBackName}`;
1180
1180
  const params = {
1181
1181
  routerURL: '',
1182
1182
  routerParam: routerParam,
1183
1183
  };
1184
1184
  const outBridgeType = ['getLastAddress', 'getAddress'];
1185
1185
  console.log(
1186
1186
  'callRouterHarmony pluginName:',
1187
1187
  pluginName,
1188
1188
  'action',
1189
1189
  action,
1190
1190
  ',routerParam:',
1191
1191
  routerParam,
1192
1192
  'params',
1193
1193
  params,
1194
1194
  'isSync',
1195
1195
  isSync,
1196
1196
  );
1197
1197
  window?.XWebView?.callNative(
1198
1198
  pluginName,
1199
1199
  action,
1200
1200
  outBridgeType.includes(action) ? JSON.stringify(routerParam) : JSON.stringify(params),
1201
1201
  getCallBackName,
1202
1202
  `${callBackName}HarmonyOS`,
1203
1203
  );
1204
1204
  callRouterHarmony,
1205
1205
  callBack &&
1206
1206
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1207
1207
  Message_Type.NATIVE_SHOW_DIALOG
1208
1208
  ] = callBack);
1209
1209
  return nativePageRegisterMessage(Message_Type.NATIVE_SHOW_DIALOG, {
1210
1210
  data: params,
1211
1211
  });
1212
1212
  if (!isJdApp) {
1213
1213
  return;
1214
1214
  }
1215
1215
  if (!window[Message_CallBack_Name.MESSAGE_HOME_INIT]) {
1216
1216
  window[Message_CallBack_Name.MESSAGE_HOME_INIT] = (messageData) => {
1217
1217
  try {
1218
1218
  console.log('接收到原生通知返回的原始数据nativePageGetMessageInitCallBack', messageData);
1219
1219
  const getMessageJsonData = JSONParse(messageData);
1220
1220
  const { status } = getMessageJsonData;
1221
1221
  if (status == '0') {
1222
1222
  const { type, data } = getMessageJsonData?.data;
1223
1223
  const getSendJsonData = JSONParse(data);
1224
1224
  switch (type) {
1225
1225
  case Message_Type.NATIVE_INFO_DATA:
1226
1226
  case Message_Type.NATIVE_PAGE_FINISH:
1227
1227
  case Message_Type.NATIVE_GET_SCROLL_TOP:
1228
1228
  case Message_Type.NATIVE_TO_SCROLL_TOP:
1229
1229
  case Message_Type.NATIVE_CLOSE_SCROLL_MESSAGE:
1230
1230
  case Message_Type.NATIVE_GET_SCALED_TOUCH_SLOP:
1231
1231
  case Message_Type.NATIVE_MOBILE_CONFIG:
1232
1232
  case Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE:
1233
1233
  const getTypeCallBack =
1234
1234
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][type];
1235
1235
  if (getTypeCallBack) {
1236
1236
  const isCallBackFunc = typeof getTypeCallBack === 'function';
1237
1237
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND getSendJsonData', getSendJsonData);
1238
1238
  isCallBackFunc && getTypeCallBack(getSendJsonData);
1239
1239
  }
1240
1240
  break;
1241
1241
  case Message_Type.NATIVE_SHOW_DIALOG:
1242
1242
  const showDialogCallBack =
1243
1243
  Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][type];
1244
1244
  if (showDialogCallBack) {
1245
1245
  const isCallBackFunc = typeof showDialogCallBack === 'function';
1246
1246
  console.log(
1247
1247
  `获取${type}类型数据数据type isCallBackFunc getMessageJsonData `,
1248
1248
  type,
1249
1249
  isCallBackFunc,
1250
1250
  getMessageJsonData,
1251
1251
  );
1252
1252
  isCallBackFunc && showDialogCallBack(getMessageJsonData?.data);
1253
1253
  }
1254
1254
  break;
1255
1255
  case Message_Type.NATIVE_PAGE_SCROLL:
1256
1256
  taroEventSendPageScrollInfo(data);
1257
1257
  break;
1258
1258
  case Message_Type.NATIVE_PAGE_SCROLL_END:
1259
1259
  taroEventSendPageScrollEndInfo(data);
1260
1260
  break;
1261
1261
  case Message_Type.NATIVE_H5_SEND_MSG_TO_H5:
1262
1262
  console.log('接收到原生通知 NATIVE_H5_SEND_MSG_TO_H5', data);
1263
1263
  taroEventH5SendMsgToH5(getSendJsonData);
1264
1264
  break;
1265
1265
  case Message_Type.UPDATE_NATIVE_DATA:
1266
1266
  taroEventUpdateNativeData(getSendJsonData);
1267
1267
  break;
1268
1268
  case Message_Type.H5_TO_SCROLL_TOP:
1269
1269
  taroEventH5ToScrollTop();
1270
1270
  break;
1271
1271
  case Message_Type.NATIVE_SHOPSTOW_SEND:
1272
1272
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND', messageData);
1273
1273
  console.log('接收到原生通知 NATIVE_SHOPSTOW_SEND getSendJsonData', getSendJsonData);
1274
1274
  taroEventShopStowSend(getSendJsonData);
1275
1275
  break;
1276
1276
  case Message_Type.LUXURY_INFORM_CHANGE_HEIGHT:
1277
1277
  taroEventSendImmersionStatus(data);
1278
1278
  break;
1279
1279
  case Message_Type.NATIVE_IMMERSIVEHEADER_STATE_CHANGE:
1280
1280
  taroEventSendImmersiveHeaderChange(data);
1281
1281
  break;
1282
1282
  case Message_Type.SHOP_FOLLOW_STATE_REGISTER:
1283
1283
  taroEventSendShopFollowStateChange(data);
1284
1284
  break;
1285
1285
  default:
1286
1286
  }
1287
1287
  } else {
1288
1288
  console.log('传递数据获取异常', getMessageJsonData);
1289
1289
  }
1290
1290
  } catch (e) {
1291
1291
  console.log('获取转换异常结果', e);
1292
1292
  }
1293
1293
  };
1294
1294
  }
1295
1295
  console.warn('🚀 ~~ JumpTabBarInCurrentShop() ~~ params:', params);
1296
1296
  nativePageRegisterMessage(Message_Type.NATIVE_JUMP_TAB_BAR, {
1297
1297
  data: params,
1298
1298
  });
1299
1299
  nativePageRegisterMessage(Message_Type.NATIVE_OPEN_FLOAT, {
1300
1300
  data: params,
1301
1301
  });
1302
1302
  const changeData = {
1303
1303
  type: NATIVE_POP_WEBVIEW_TYPE.OPEN,
1304
1304
  height: DEFAULT_POP_WEBVIEW_HEIGHT,
1305
1305
  };
1306
1306
  if (isChangeDefaultPopViewHeight && !params?.height) {
1307
1307
  changeData.height = Math.round(window.screen.height * 0.8);
1308
1308
  changeData.borderRadius = 12;
1309
1309
  }
1310
1310
  nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
1311
1311
  data: {
1312
1312
  ...changeData,
1313
1313
  ...params,
1314
1314
  },
1315
1315
  });
1316
1316
  nativePageRegisterMessage(Message_Type.NATIVE_POP_WEBVIEW, {
1317
1317
  data: {
1318
1318
  type: NATIVE_POP_WEBVIEW_TYPE.CLOSE,
1319
1319
  ...params,
1320
1320
  },
1321
1321
  });
1322
1322
  Taro.eventCenter.off(TaroEventType.JOIN_MEMBER_SUCCESS);
1323
1323
  console.log('popWebview关闭');
1324
1324
  nativePageRegisterMessage(Message_Type.NATIVE_H5_SEND_MSG_TO_H5, {
1325
1325
  data: params,
1326
1326
  });
1327
1327
  nativePageRegisterMessage(Message_Type.NATIVE_PUSH_NATIVE_PAGE, {
1328
1328
  data: params,
1329
1329
  });
1330
1330
  window &&
1331
1331
  (window.location.href = `xview://search?request={"action":"${Message_Type.NAVTIVE_FLOAT_READY}"}`);
1332
1332
  const { displayHeight, offSetY } = res;
1333
1333
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined') return;
1334
1334
  if (isIosDevice) return res;
1335
1335
  if (isAndroidDevice) {
1336
1336
  const deviceRatio = window.devicePixelRatio;
1337
1337
  const cssDisplayHeight = Math.ceil(displayHeight / deviceRatio);
1338
1338
  const cssOffsetY = Math.ceil(offSetY / deviceRatio);
1339
1339
  return {
1340
1340
  displayHeight: cssDisplayHeight,
1341
1341
  offSetY: cssOffsetY,
1342
1342
  };
1343
1343
  }
1344
1344
  nativePageRegisterMessage(Message_Type.NATIVE_UPDATE_PAGE_INFO, {
1345
1345
  data: params,
1346
1346
  });
1347
1347
  nativePageRegisterMessage(Message_Type.NATIVE_TO_BUYER_SHOW_DETAIL, {
1348
1348
  data: params,
1349
1349
  });
1350
1350
  nativePageRegisterMessage(Message_Type.NATIVE_TO_HIDE_JD_SHOP_HEADER, {
1351
1351
  data: params,
1352
1352
  });
1353
1353
  nativePageRegisterMessage(Message_Type.NATIVE_TO_SHOW_CART_BTN, {
1354
1354
  data: params,
1355
1355
  });
1356
1356
  nativePageRegisterMessage(Message_Type.SHOP_FOLLOW_STATE_REGISTER, {
1357
1357
  data: params,
1358
1358
  });
1359
1359
  callBack &&
1360
1360
  (Message_Trigger_CallBackFuncObj[Message_CallBack_Name.MESSAGE_HOME_INIT][
1361
1361
  Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE
1362
1362
  ] = callBack);
1363
1363
  nativePageRegisterMessage(Message_Type.NATIVE_GET_SHOP_FOLLOW_STATE, {
1364
1364
  data: {},
1365
1365
  });
1366
1366
  nativePageRegisterMessage(Message_Type.SHOP_FOLLOW_STATE_SYNC, {
1367
1367
  data: {
1368
1368
  followed: followState,
1369
1369
  },
1370
1370
  });
1371
1371
  nativePageRegisterMessage(Message_Type.H5_TO_NATIVE_LIVE_RESERVE_STATE, {
1372
1372
  data: params,
1373
1373
  });
1374
1374
  Taro.eventCenter.on('SEND_MSG_TO_NATIVE', (key, params) => {
1375
1375
  nativePageRegisterMessage(key, {
1376
1376
  data: params,
1377
1377
  });
1378
1378
  });
1379
1379
  nativePageRegisterMessage(Message_Type.H5_TO_NATIVE_SCROLL_TO_TOP, {
1380
1380
  data: params,
1381
1381
  });