@conecli/cone-render 0.8.20-shop.21 → 0.8.20-shop.211

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.
Files changed (163) hide show
  1. package/README.md +7 -1
  2. package/dist/api/index.ts +1 -1
  3. package/dist/assets/icon_blue_info.svg +1 -0
  4. package/dist/common/const.ts +1 -1
  5. package/dist/common/environmentType.ts +1 -0
  6. package/dist/common/index.h5.ts +1 -1
  7. package/dist/common/index.jd.ts +1 -1
  8. package/dist/common/index.ts +1 -1
  9. package/dist/common/index.weapp.ts +1 -1
  10. package/dist/common/jdplayerSdk.ts +1 -0
  11. package/dist/common/jssdk.ts +1 -0
  12. package/dist/common/pageType.ts +1 -0
  13. package/dist/common/sgmCustomCode.ts +1 -0
  14. package/dist/common/token/index.h5.ts +1 -1
  15. package/dist/common/token/token.jd.ts +1 -1
  16. package/dist/common/token/token.ts +1 -1
  17. package/dist/common/wxappApi.jd.ts +1 -0
  18. package/dist/common/wxappApi.ts +1 -1
  19. package/dist/components/ErrorBoundary.tsx +1 -1
  20. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  21. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  22. package/dist/components/base/CountDown/index.module.scss +49 -44
  23. package/dist/components/base/CountDown/index.tsx +1 -1
  24. package/dist/components/base/CustomScrollView/index.jd.tsx +1 -0
  25. package/dist/components/base/CustomScrollView/index.module.scss +7 -0
  26. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  27. package/dist/components/base/CustomVideo/common.ts +1 -0
  28. package/dist/components/base/CustomVideo/index.module.scss +1 -1
  29. package/dist/components/base/CustomVideo/index.tsx +1 -1
  30. package/dist/components/base/Dialog/index.module.scss +16 -0
  31. package/dist/components/base/Dialog/index.tsx +1 -1
  32. package/dist/components/base/Exposure/index.h5.tsx +1 -1
  33. package/dist/components/base/ExposureSmart/const.ts +1 -0
  34. package/dist/components/base/ExposureSmart/index.h5.module.scss +30 -6
  35. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  36. package/dist/components/base/ExposureSmart/index.module.scss +20 -9
  37. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  38. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  39. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  40. package/dist/components/base/InViewRender/index.tsx +1 -1
  41. package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
  42. package/dist/components/base/ItemViewExposureSmart/index.module.scss +8 -0
  43. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -0
  44. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  45. package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
  46. package/dist/components/base/LazyLoadImage/const.ts +1 -1
  47. package/dist/components/base/LazyLoadImage/index.h5.module.scss +24 -20
  48. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  49. package/dist/components/base/MobileCommonHeader/index.module.scss +17 -0
  50. package/dist/components/base/MobileCommonHeader/index.tsx +1 -0
  51. package/dist/components/base/NetworkDataError/const.ts +1 -1
  52. package/dist/components/base/NetworkDataError/index.module.scss +125 -69
  53. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  54. package/dist/components/base/Price/Base/index.module.scss +12 -0
  55. package/dist/components/base/Price/Base/index.tsx +1 -1
  56. package/dist/components/base/Price/Double/index.module.scss +32 -0
  57. package/dist/components/base/Price/Double/index.tsx +1 -1
  58. package/dist/components/base/Price/index.tsx +1 -1
  59. package/dist/components/base/Skeleton/index.tsx +1 -1
  60. package/dist/components/debug/DebugLayout/index.module.scss +67 -0
  61. package/dist/components/debug/DebugLayout/index.tsx +1 -0
  62. package/dist/components/debug/DebugLayout/utils.ts +1 -0
  63. package/dist/components/decorate/DecorateFloorModule/index.module.scss +32 -2
  64. package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
  65. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  66. package/dist/components/decorate/PlaceHolder/index.tsx +1 -1
  67. package/dist/components/floorItem.jd.tsx +1 -1
  68. package/dist/components/floorItem.tsx +1 -1
  69. package/dist/components/floorItem.weapp.tsx +1 -1
  70. package/dist/components/isv/Floor/index.tsx +1 -1
  71. package/dist/components/remoteFloorItem.tsx +1 -0
  72. package/dist/interface/common.ts +1 -1
  73. package/dist/interface/component.ts +1 -1
  74. package/dist/interface/jumpEventReport.ts +1 -1
  75. package/dist/interface/service.ts +1 -1
  76. package/dist/interface/utils.ts +1 -1
  77. package/dist/jumpEventReport/base.ts +1 -1
  78. package/dist/jumpEventReport/const.ts +1 -1
  79. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  80. package/dist/jumpEventReport/index.h5.ts +1 -1
  81. package/dist/jumpEventReport/index.jd.ts +1 -1
  82. package/dist/jumpEventReport/index.ts +1 -1
  83. package/dist/jumpEventReport/index.weapp.ts +1 -1
  84. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  85. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  86. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  87. package/dist/jumpEventReport/web/report.ts +1 -1
  88. package/dist/jumpEventReport/web.base.ts +1 -1
  89. package/dist/jumpEventReport/web.jd.ts +1 -1
  90. package/dist/jumpEventReport/web.jdb.ts +1 -1
  91. package/dist/jumpEventReport/web.jdjch.ts +1 -0
  92. package/dist/jumpEventReport/web.jxwxapp.ts +1 -0
  93. package/dist/jumpEventReport/web.pc.ts +1 -0
  94. package/dist/jumpEventReport/web.tjapp.ts +1 -0
  95. package/dist/jumpEventReport/web.tjm.ts +1 -0
  96. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  97. package/dist/language/en_US.json +178 -0
  98. package/dist/language/zh_CN.json +178 -0
  99. package/dist/language/zh_HK.json +178 -0
  100. package/dist/libs/taroAppReport.js +2 -2
  101. package/dist/modules/ContainerFloorList/index.h5.module.scss +66 -27
  102. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  103. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  104. package/dist/open/api/device.ts +1 -1
  105. package/dist/open/api/environment.ts +1 -1
  106. package/dist/open/api/index.ts +1 -1
  107. package/dist/open/api/jump/business.ts +1 -0
  108. package/dist/open/api/jump/index.ts +1 -0
  109. package/dist/open/api/jump/minPath.ts +1 -0
  110. package/dist/open/api/jump/side.ts +1 -0
  111. package/dist/open/api/jump/webUrl.ts +1 -0
  112. package/dist/open/api/jump copy.ts +1 -0
  113. package/dist/open/api/request.ts +1 -1
  114. package/dist/open/api/shopMember.ts +1 -1
  115. package/dist/open/api/track.ts +1 -1
  116. package/dist/open/api/util.ts +1 -1
  117. package/dist/open/components/index.ts +1 -1
  118. package/dist/sass/app.h5.scss +289 -212
  119. package/dist/sass/base.scss +195 -137
  120. package/dist/service/bMallConst.ts +1 -1
  121. package/dist/service/fetchGateway.ts +1 -1
  122. package/dist/service/fetchGateway.weapp.ts +1 -0
  123. package/dist/service/http/colorSign.ts +1 -1
  124. package/dist/service/http/const.ts +1 -1
  125. package/dist/service/http/h5Http.ts +1 -0
  126. package/dist/service/http/index.h5.ts +1 -0
  127. package/dist/service/requestServer.h5.ts +1 -0
  128. package/dist/service/requestServer.ts +1 -1
  129. package/dist/service/requestServer.weapp.ts +1 -0
  130. package/dist/utils/connectNativeJsBridge.ts +1 -1
  131. package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
  132. package/dist/utils/draExceptionAndProfile.ts +1 -1
  133. package/dist/utils/h5Utils.ts +1 -1
  134. package/dist/utils/index.h5.ts +1 -1
  135. package/dist/utils/index.ts +1 -1
  136. package/dist/utils/index.weapp.ts +1 -1
  137. package/dist/utils/intersectionObserver.ts +1 -1
  138. package/dist/utils/jm-common.js +1 -1
  139. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  140. package/dist/utils/jumpExtMapUtil.ts +1 -0
  141. package/dist/utils/sColor.js +1 -0
  142. package/dist/utils/sgmCodeUtils.ts +1 -0
  143. package/dist/utils/taroRenderUtil.ts +1 -0
  144. package/dist/utils/utils.ts +1 -1
  145. package/dist/wxapp/api/helper.js +1 -0
  146. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  147. package/dist/wxapp/common/user_info.js +1 -1
  148. package/dist/wxapp/components/launch-app/index.js +1 -0
  149. package/dist/wxapp/components/launch-app/index.json +5 -0
  150. package/dist/wxapp/components/launch-app/index.wxml +0 -0
  151. package/dist/wxapp/components/launch-app/index.wxss +0 -0
  152. package/dist/wxapp/components/subscribe-guider/helper.js +1 -0
  153. package/dist/wxapp/components/subscribe-guider/index.js +1 -0
  154. package/dist/wxapp/components/subscribe-guider/index.json +5 -0
  155. package/dist/wxapp/components/subscribe-guider/index.wxml +0 -0
  156. package/dist/wxapp/components/subscribe-guider/index.wxss +0 -0
  157. package/package.json +148 -115
  158. package/dist/components/base/Skeleton/old.tsx +0 -1
  159. package/dist/customHooks/useDocumentVisibilitychange.ts +0 -1
  160. package/dist/open/api/jump.ts +0 -1
  161. package/dist/utils/memberFormatUtils.js +0 -1
  162. /package/dist/service/{bMallConst.wxapp.ts → bMallConst.weapp.ts} +0 -0
  163. /package/dist/service/http/{colorSign.wxapp.ts → colorSign.weapp.ts} +0 -0
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  urlCookie
3
2
  public config: {
4
3
  [key: string]: any
5
4
  }
6
5
  public lazyContainer: CommonInterFace.lazyContainer
7
6
  this.config = {}
8
7
  pin: cookie.get('pin') || ''
9
8
  })
10
9
  if(!this.checkStatusAndLoginPromise){
11
10
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
12
11
  try {
13
12
  const getLoginState = await this.doCheckLoginStateAndForApiCheck()
14
13
  if(getLoginState){
15
14
  resolve(true)
16
15
  }else {
17
16
  this.toLogin(options)
18
17
  reject(false)
19
18
  }
20
19
  }catch (e) {
21
20
  this.toLogin(options)
22
21
  reject(false)
23
22
  }
24
23
  })
25
24
  }
26
25
 
27
26
  doCheckLoginStateAndForApiCheck() {
28
27
  if(this.info.loginState){
29
28
  return Promise.resolve(true)
30
29
  }else {
31
30
  return new Promise((resolve, reject) => {
32
31
  Taro.request({
33
32
  url: api.isLogin,
34
33
  jsonp:true,
35
34
  timeout: 3000,
36
35
  success: (res) => {
37
36
  const {statusCode,data} = res
38
37
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
39
38
  this.info.loginState = true
40
39
  resolve(true);
41
40
  } else {
42
41
  reject(false)
43
42
  }
44
43
  },
45
44
  fail:(err) => {
46
45
  console.log("登录检查异常", err)
47
46
  reject(false)
48
47
  }
49
48
  })
50
49
  })
51
50
  }
52
51
  }
53
52
  try {
54
53
  const getLoginState = await this.doCheckLoginStateAndForApiCheck()
55
54
  if(getLoginState){
56
55
  const { pin } = await this.getLoginCookie();
57
56
  this.info.userInfo = {
58
57
  pin,
59
58
  encodePin: encodeURIComponent(pin),
60
59
  ptkey: '',
61
60
  }
62
61
  resolve(true)
63
62
  }else {
64
63
  reject(false)
65
64
  }
66
65
  }catch (e) {
67
66
  reject(false)
68
67
  }
69
68
  })
70
69
  if(un_area && un_area.length > 0){
71
70
  this.info.pageInfo.address = un_area
72
71
  this.info.pageInfo.un_area = un_area
73
72
  this.info.pageInfo.addressCommaStr = un_area.replace(/_/g, ',')
74
73
  }
74
+ import Taro from '@tarojs/taro';
75
75
  dealNativePixelToCssPixel,
76
76
  isAndroidDevice,
77
77
  isIosDevice,
78
78
  isJdAndAndroidDevice,
79
79
  isJdAndHarmonyDevice,
80
80
  isObject,
81
81
  isPc,
82
82
  isString,
83
83
  jdAppVersion,
84
84
  jdAppVersionStr,
85
85
  serialize,
86
86
  draBusinessCustomReport,
87
87
  isH5AndJingGouMini,
88
88
  languageNowType,
89
89
  urlCookie,
90
90
  BUSINESS_TYPE,
91
91
  LoadJsInitLoadEnvType,
92
92
  LoadJsInitLoadType,
93
93
  LoadJsInitTriggerType,
94
94
  MPAAS_CONFIG_APP_LOW_VERSION,
95
95
  MPAAS_CONFIG_APP_VERSION,
96
96
  SECTION_HOME_TAB_NAME_TYPE,
97
97
  SECTION_HOME_TAB_TYPE,
98
98
  TaroEventType,
99
99
  WX_BUSINESS_TYPE,
100
100
  WXAPP_BIZ_KEY,
101
101
  WXAPP_BIZ_SHOP_LIGHT_KEY,
102
102
  JSSDK_APP_WEBVIEW_CODE,
103
103
  cacheH5LbsAddressKey,
104
104
  languageTypeList,
105
105
  getSystemInfos,
106
106
  getTaroStorageKeyValue,
107
107
  ipLoc_djd,
108
108
  setTaroStorage,
109
109
  sgmCustomReport,
110
110
  getMPaasConfigByBussinessKey,
111
111
  callRouterAndroid,
112
112
  callRouterIOS,
113
113
  const designWidth = 750;
114
114
  return (
115
115
  Math.ceil((((parseInt(String(size), 10) / 40) * 750) / designWidth) * 10000) / 10000 + 'rem'
116
116
  );
117
117
  abTestLabels: {},
118
118
  nonSellableSkuids: {},
119
119
  loginState: false,
120
120
  cookiesStr: '',
121
121
  userInfo: userPinKey,
122
122
  isImmersive: false,
123
123
  isJingGouMiniViewState: false,
124
124
  isJingxiMiniViewState: false,
125
125
  pageInfo: {
126
126
  wxBusinessType: WX_BUSINESS_TYPE.NO,
127
127
  address: '',
128
128
  addressCommaStr: '',
129
129
  un_area: '',
130
130
  userLbsAddress: '',
131
131
  vapptype: '1',
132
132
  pageType: 'home',
133
133
  isExposureState: false,
134
134
  moduleId: '',
135
135
  entrance: '',
136
136
  dataType: BUSINESS_TYPE.ONLINE,
137
137
  floorExposureInfo: {},
138
138
  floorVideInfo: {},
139
139
  productVideInfo: {},
140
140
  tabsLoadAllDataInfo: {
141
141
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
142
142
  },
143
143
  updateShopInfosAllState: false,
144
144
  isVipShop: false,
145
145
  isJdShowNativeImmersivePlayer: false,
146
146
  ...shopConfig,
147
147
  pageScrollTop: 0,
148
148
  pageIdxHeightInfo: {
149
149
  list: [],
150
150
  },
151
151
  shopNavBarHeight: 0,
152
152
  },
153
153
  defaultQueryLogInfo: {
154
154
  sourceType: 'JDshop',
155
155
  sourceValue: '',
156
156
  moduleId: 'none',
157
157
  entrance: 'none',
158
158
  },
159
159
  sysInfo: {
160
160
  windowWidth: isPc ? 375 : 0,
161
161
  containerWidth: isPc ? 375 : 0,
162
162
  windowHeight: 0,
163
163
  netWorkType: '4g',
164
164
  jdBottomBarHeight: 0,
165
165
  jdNativeHeaderHeight: 0,
166
166
  isJdTabletDevice: false,
167
167
  isJdTabletLandscape: false,
168
168
  },
169
169
  queryInfo: {},
170
170
  shopInfo: {},
171
171
  openAppData: {},
172
172
  public info: CommonInterFace.BaseConfigInfo;
173
173
  public config: {
174
174
  [key: string]: any;
175
175
  };
176
176
  public lazyContainer: CommonInterFace.lazyContainer;
177
177
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
178
178
  public rootEleNode: HTMLElement | null;
179
179
  public checkStatusAndLoginPromise: object | null;
180
180
  private jmfeRegisterStatePromise: Promise<any> | null;
181
181
  private jdScreenSizeInfoPromise: Promise<any> | null;
182
182
  private rootEleWidthRegisterPromise: Promise<any> | null;
183
183
  private jmfeRegisterState: boolean;
184
184
  public loadJsSdkList: Array<any>;
185
185
  public loadJsSdkListCachePromise: any;
186
186
  public rootEleInitWidth: number;
187
187
  public lbsAddressCachePromise: Promise<any> | null;
188
188
  public languageCacheProimse: Promise<any> | null;
189
189
  public languageJsonData: any | null;
190
190
  constructor(opt) {
191
191
  this.info = this._getConfig(opt);
192
192
  this.config = {};
193
193
  this.loadJsSdkList = [];
194
194
  this.loadJsSdkListCachePromise = {};
195
195
  this.lazyContainer = {
196
196
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
197
197
  appLazyContainerList: [],
198
198
  appLazyFinishContainerList: [],
199
199
  },
200
200
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
201
201
  appLazyContainerList: [],
202
202
  appLazyFinishContainerList: [],
203
203
  },
204
204
  };
205
205
  this.renderedIsvComponents = {};
206
206
  this.rootEleNode = document.querySelector('body');
207
207
  this.checkStatusAndLoginPromise = null;
208
208
  this.jmfeRegisterStatePromise = null;
209
209
  this.jdScreenSizeInfoPromise = null;
210
210
  this.rootEleWidthRegisterPromise = null;
211
211
  this.lbsAddressCachePromise = null;
212
212
  this.languageCacheProimse = null;
213
213
  this.languageJsonData = langeJsonDataForCn;
214
214
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
215
215
  this.loadOtherSdk();
216
216
  if (isJdApp) {
217
217
  this.jmfeReayPromise();
218
218
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
219
219
  }
220
220
  }
221
221
  _getConfig(opt) {
222
222
  return Object.assign({}, DefaultConfig, opt);
223
223
  }
224
224
  _getJdPadMinWidthForListen() {
225
225
  return (
226
226
  isJdApp &&
227
227
  Math.min(window.screen.width, window.screen.height) >
228
228
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
229
229
  );
230
230
  }
231
231
 
232
232
  jmfeReayPromise(): Promise<any> {
233
233
  if (isJdApp) {
234
234
  if (this.jmfeRegisterState) {
235
235
  return Promise.resolve(true);
236
236
  } else {
237
237
  !this.jmfeRegisterStatePromise &&
238
238
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
239
239
  ready('jmfe', 3000)
240
240
  .then(() => {
241
241
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
242
242
  this.jmfeRegisterState = true;
243
243
  resolve(true);
244
244
  console.log(
245
245
  '松果app内初始化注册jmfe认证完成',
246
246
  window?.jmfe,
247
247
  '当前版本',
248
248
  window?.jmfe?.VERSION,
249
249
  );
250
250
  })
251
251
  .catch((err) => {
252
252
  console.error('jmfe ready error', err);
253
253
  reject(false);
254
254
  });
255
255
  }));
256
256
  return this.jmfeRegisterStatePromise;
257
257
  }
258
258
  } else {
259
259
  return Promise.reject(false);
260
260
  }
261
261
  }
262
262
 
263
263
  getJdScreenSizeInfoPromise() {
264
264
  !this.jdScreenSizeInfoPromise &&
265
265
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
266
266
  const getThisTime = Date.now();
267
267
  this.jmfeReayPromise().then(() => {
268
268
  return Promise.race([
269
269
  window.jmfe.getScreenSize(),
270
270
  this.taskTimeoutPromise(() => {
271
271
  return {
272
272
  status: '-10',
273
273
  msg: '获取大屏信息2s超时',
274
274
  };
275
275
  }),
276
276
  ])
277
277
  .then((res) => {
278
278
  console.warn('===获取app大屏信息====', res);
279
279
  const { status, data } = res;
280
280
  if (status === '0' && data) {
281
281
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
282
282
  const getPageInfo = dealNativePixelToCssPixel({
283
283
  pageWidth,
284
284
  pageHeight,
285
285
  });
286
286
  this.info.sysInfo.jdScreenSizeType = sizeType;
287
287
  const getUseTime = Date.now() - getThisTime;
288
288
  console.warn(
289
289
  '===计算是否是app大屏信息,需满足宽度最新720===',
290
290
  getPageInfo,
291
291
  '原始数据',
292
292
  data,
293
293
  '是否是横屏isLandscape为1=',
294
294
  isLandscape,
295
295
  '用时',
296
296
  getUseTime,
297
297
  );
298
298
  if (getPageInfo?.pageWidth > 0) {
299
299
  this.rootEleInitWidth = getPageInfo?.pageWidth;
300
300
  draBusinessCustomReport({
301
301
  type: 'rootEle_width_getJdScreenSizeInfo',
302
302
  errMsg: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
303
303
  originReqDataStr: JSON.stringify({
304
304
  isJdApp,
305
305
  getPageInfo,
306
306
  originData: res,
307
307
  }),
308
308
  });
309
309
  resolve(getPageInfo);
310
310
  } else {
311
311
  resolve({
312
312
  pageWidth: 0,
313
313
  pageHeight: 0,
314
314
  msg: '转换异常',
315
315
  });
316
316
  }
317
317
  } else {
318
318
  resolve({
319
319
  pageWidth: 0,
320
320
  pageHeight: 0,
321
321
  msg: '获取大屏信息异常或者超时',
322
322
  });
323
323
  }
324
324
  })
325
325
  .catch((err) => {
326
326
  console.log('获取大屏信息异常', err);
327
327
  resolve({
328
328
  pageWidth: 0,
329
329
  pageHeight: 0,
330
330
  msg: '获取大屏信息异常',
331
331
  });
332
332
  });
333
333
  });
334
334
  }));
335
335
  return this.jdScreenSizeInfoPromise;
336
336
  }
337
337
 
338
338
  listenJdTabletScreenChange() {
339
339
  this.jmfeReayPromise().then(() => {
340
340
  try {
341
341
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
342
342
  window.jmfe.listenDeviceScreenChange((event) => {
343
343
  console.log(
344
344
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
345
345
  event,
346
346
  '通过前端判断是不是横屏',
347
347
  window.matchMedia('(orientation: landscape)')?.matches,
348
348
  );
349
349
  const { orientation } = event?.data;
350
350
  if (orientation) {
351
351
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
352
352
  Taro.eventCenter.trigger(
353
353
  TaroEventType.TABLE_SCREEN_CHANGE,
354
354
  this.info.sysInfo.isJdTabletLandscape,
355
355
  orientation,
356
356
  );
357
357
  }
358
358
  });
359
359
  } catch (error) {
360
360
  console.log('listenScreenChange的打印error:', error);
361
361
  }
362
362
  });
363
363
  }
364
364
 
365
365
  updateBusinessDomainAndApi(domain, api) {
366
366
  }
367
367
 
368
368
  formatNativeScreenPageData(action) {
369
369
  let getChangePageInfo: any = null;
370
370
  try {
371
371
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
372
372
  JSON.stringify({
373
373
  plugin: 'JDHybridScreenPlugin',
374
374
  action,
375
375
  sync: '1',
376
376
  }),
377
377
  );
378
378
  const getChangePageInfoData =
379
379
  typeof getNativeScreenPageInfoStr === 'string'
380
380
  ? JSON.parse(getNativeScreenPageInfoStr)
381
381
  : null;
382
382
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
383
383
  const { code, data } = getChangePageInfoData;
384
384
  getChangePageInfo = code && code === '0' ? data : null;
385
385
  }
386
386
  } catch (e) {
387
387
  console.log('JDHybridScreenPlugin转换异常', e);
388
388
  }
389
389
  return getChangePageInfo;
390
390
  }
391
391
 
392
392
  isAndroidFoldScreen() {
393
393
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
394
394
  }
395
395
 
396
396
  getJdAndroidPageChangeScreenInfo() {
397
397
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
398
398
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
399
399
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
400
400
  pageWidth: getPageScreenInfo.pageWidth,
401
401
  pageHeight: getPageScreenInfo.pageHeight,
402
402
  });
403
403
  getPageScreenInfo.pageWidth = pageWidth;
404
404
  getPageScreenInfo.pageHeight = pageHeight;
405
405
  }
406
406
  return getPageScreenInfo;
407
407
  }
408
408
 
409
409
  getRootEleWindowWidthInfo() {
410
410
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
411
411
  const getWindowWidth = window.innerWidth;
412
412
  const getScreenWidth = window.screen.width;
413
413
  return {
414
414
  getRootEleWidth,
415
415
  getWindowWidth,
416
416
  getScreenWidth,
417
417
  };
418
418
  }
419
419
 
420
420
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
421
421
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
422
422
  console.log(
423
423
  '当前获取根元素的宽度',
424
424
  getRootEleWidth,
425
425
  'getWindowWidth',
426
426
  getWindowWidth,
427
427
  'getScreenWidth',
428
428
  getScreenWidth,
429
429
  );
430
430
  const getLastWidth =
431
431
  getRootEleWidth > 0
432
432
  ? Math.round(getRootEleWidth)
433
433
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
434
434
  console.warn(
435
435
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
436
436
  );
437
437
  timeout > 0 &&
438
438
  draBusinessCustomReport({
439
439
  type: 'rootEle_width_timeout_getJdScreenSizeInfo',
440
440
  errMsg: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
441
441
  originReqDataStr: JSON.stringify({
442
442
  isJdApp,
443
443
  getRootEleWidth,
444
444
  getWindowWidth,
445
445
  getScreenWidth,
446
446
  ...reportParam,
447
447
  }),
448
448
  });
449
449
  return getLastWidth;
450
450
  }
451
451
 
452
452
  getPadWindowRootEleWidthPromise() {
453
453
  if (this.rootEleInitWidth > 0) {
454
454
  return Promise.resolve(this.rootEleInitWidth);
455
455
  } else {
456
456
  !this.rootEleWidthRegisterPromise &&
457
457
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
458
458
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
459
459
  if (getRootEleInitWidth > 0) {
460
460
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
461
461
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
462
462
  resolve(this.rootEleInitWidth);
463
463
  } else {
464
464
  const timerPromise = () => {
465
465
  return new Promise((resolve2) => {
466
466
  window.setTimeout(() => {
467
467
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
468
468
  this.getRootEleWindowWidthInfo();
469
469
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
470
470
  console.warn(
471
471
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
472
472
  );
473
473
  draBusinessCustomReport({
474
474
  type: 'rootEle_width_200_timeout_info',
475
475
  errMsg: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
476
476
  originReqDataStr: JSON.stringify({
477
477
  isJdApp,
478
478
  getRootEleWidth,
479
479
  getWindowWidth,
480
480
  getScreenWidth,
481
481
  }),
482
482
  });
483
483
  const getRes =
484
484
  getRootEleWidth > 0 && getWindowWidth > 0
485
485
  ? Math.min(getRootEleWidth, getWindowWidth)
486
486
  : Math.max(getRootEleWidth, getWindowWidth);
487
487
  resolve2({
488
488
  pageWidth: Math.round(getRes),
489
489
  });
490
490
  }
491
491
  }, 200);
492
492
  });
493
493
  };
494
494
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
495
495
  const { pageWidth } = res;
496
496
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
497
497
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
498
498
  });
499
499
  }
500
500
  }));
501
501
  return this.rootEleWidthRegisterPromise;
502
502
  }
503
503
  }
504
504
 
505
505
  async getSystemInfo(params) {
506
506
  const getParams = Object.assign({}, params || {});
507
507
  if (this.rootEleInitWidth > 0) {
508
508
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
509
509
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
510
510
  } else {
511
511
  if (this._getJdPadMinWidthForListen()) {
512
512
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
513
513
  getParams['replaceSystemWidth'] = true;
514
514
  }
515
515
  }
516
516
  this.createLanguagePromise();
517
517
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
518
518
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
519
519
  let _isfoldScreen = false;
520
520
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
521
521
  console.info(
522
522
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
523
523
  getStorageData,
524
524
  '通过缓存值第一次判断是否是折叠屏',
525
525
  getStorageData === 'true',
526
526
  );
527
527
  if (!getStorageData) {
528
528
  _isfoldScreen = this.isAndroidFoldScreen();
529
529
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
530
530
  } else {
531
531
  _isfoldScreen = getStorageData === 'true';
532
532
  }
533
533
  if (_isfoldScreen) {
534
534
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
535
535
  if (getJdAndroidPageInfo) {
536
536
  info = getSystemInfos(getJdAndroidPageInfo);
537
537
  console.warn(
538
538
  '当前为松果安卓折叠屏app,获取折叠屏信息',
539
539
  getJdAndroidPageInfo,
540
540
  '获取转换后的系统信息',
541
541
  info,
542
542
  );
543
543
  sgmCustomReport({
544
544
  type: 2,
545
545
  code: 'android_jdapp_foldScreen_info',
546
546
  msg: {
547
547
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
548
548
  androidPageInfo: getJdAndroidPageInfo,
549
549
  jdAppVersionStr,
550
550
  taroSysInfo: info,
551
551
  },
552
552
  });
553
553
  }
554
554
  }
555
555
  }
556
556
  if (isJdApp) {
557
557
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
558
558
  }
559
559
  this.info.sysInfo = {
560
560
  actualNavBarHeight: 0,
561
561
  ...this.info.sysInfo,
562
562
  ...info,
563
563
  safeContentHeight: info?.screenHeight,
564
564
  headerHeight: 0,
565
565
  tabBarHeight: 0,
566
566
  languageType: languageNowType,
567
567
  };
568
568
  if (isJdApp || isH5AndJingGouMini) {
569
569
  this.getLbsAddressCachePromise();
570
570
  }
571
571
  if (isJdApp) {
572
572
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
573
573
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
574
574
  this.getAddressCachePromise();
575
575
  this.getElderModePromise();
576
576
  this.getJDAppearanceStatePromise();
577
577
  this.createJdAndroidRquestEventForTouchStart();
578
578
  }
579
579
  this.getWifiVideoAutoPlayAsync();
580
580
  this.getMPaasConfigAsync();
581
581
  this.getNetWorkType();
582
582
  }
583
583
 
584
584
  taskTimeoutPromise(callBack, timeout = 2000) {
585
585
  return new Promise((resolve) => {
586
586
  setTimeout(() => {
587
587
  const getCallBackRes = typeof callBack === 'function' && callBack();
588
588
  return resolve(getCallBackRes || false);
589
589
  }, timeout);
590
590
  });
591
591
  }
592
592
 
593
593
  getElderModePromise() {
594
594
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
595
595
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
596
596
  } else {
597
597
  if (isJdAndAndroidDevice) {
598
598
  this.info.sysInfo.jdAppModeType = '0';
599
599
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
600
600
  } else {
601
601
  return Promise.race([
602
602
  this.taskTimeoutPromise(() => {
603
603
  this.info.sysInfo.jdAppModeType = '0';
604
604
  return this.info.sysInfo.jdAppModeType;
605
605
  }),
606
606
  new Promise((resolve) => {
607
607
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
608
608
  if (!window[getCallBackName]) {
609
609
  window[getCallBackName] = (res) => {
610
610
  try {
611
611
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
612
612
  const { status, data, msg } = getResJson;
613
613
  console.log(`获取松果app展示模式成功,返回结果${data}`);
614
614
  if (status === '0') {
615
615
  this.info.sysInfo.jdAppModeType = data;
616
616
  resolve(data);
617
617
  } else {
618
618
  resolve('0');
619
619
  }
620
620
  } catch (e) {
621
621
  resolve('0');
622
622
  }
623
623
  window[getCallBackName] = null;
624
624
  };
625
625
  }
626
626
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
627
627
  method: 'callSyncRouterModuleWithParams',
628
628
  params: JSON.stringify({
629
629
  routerURL: 'router://JDBModeModule/getCurrentMode',
630
630
  routerParam: {},
631
631
  callBackName: `window.${getCallBackName}`,
632
632
  callBackId: `${getCallBackName}Ios`,
633
633
  }),
634
634
  });
635
635
  }),
636
636
  ]);
637
637
  }
638
638
  }
639
639
  }
640
640
  getAPPUseStraightCorner() {
641
641
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
642
642
  const params = {
643
643
  routerURL,
644
644
  routerParam: {},
645
645
  jdRouter: '1',
646
646
  };
647
647
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
648
648
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
649
649
  } else {
650
650
  return this.jmfeReayPromise()
651
651
  .then(() => {
652
652
  if (isJdAndHarmonyDevice || !isJdApp) {
653
653
  console.log('not APP or is Harmony');
654
654
  return Promise.resolve(false);
655
655
  }
656
656
  console.log('jmfe setShareInfo', params);
657
657
  return Promise.race([
658
658
  window.jmfe.callRouter(params),
659
659
  this.taskTimeoutPromise(() => {
660
660
  return false;
661
661
  }),
662
662
  ]).then(({ status, data }) => {
663
663
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
664
664
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
665
665
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
666
666
  return Promise.resolve(status === '0' && Number(data) === 1);
667
667
  });
668
668
  })
669
669
  .catch((e) => {
670
670
  console.log('jmfe error', e);
671
671
  return Promise.resolve(false);
672
672
  });
673
673
  }
674
674
  }
675
675
 
676
676
  getJDAppearanceStatePromise() {
677
677
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
678
678
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
679
679
  } else {
680
680
  return Promise.race([
681
681
  this.taskTimeoutPromise(() => {
682
682
  this.info.sysInfo.jdAppearanceState = '0';
683
683
  return this.info.sysInfo.jdAppearanceState;
684
684
  }),
685
685
  new Promise((resolve) => {
686
686
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
687
687
  if (!window[getCallBackName]) {
688
688
  window[getCallBackName] = (res) => {
689
689
  try {
690
690
  console.log('getJDAppearanceStatePromise', res);
691
691
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
692
692
  const { status, data, msg } = getResJson;
693
693
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
694
694
  if (status === '0') {
695
695
  this.info.sysInfo.jdAppearanceState = data;
696
696
  resolve(data);
697
697
  } else {
698
698
  resolve('0');
699
699
  }
700
700
  } catch (e) {
701
701
  resolve('0');
702
702
  }
703
703
  window[getCallBackName] = null;
704
704
  };
705
705
  }
706
706
  if (isAndroidDevice) {
707
707
  const jsonString = JSON.stringify({
708
708
  callBackName: `window.${getCallBackName}`,
709
709
  });
710
710
  console.log('window.JDAppearance', window?.JDAppearance);
711
711
  window?.JDAppearance &&
712
712
  window?.JDAppearance?.getUiState &&
713
713
  window.JDAppearance.getUiState(jsonString);
714
714
  } else {
715
715
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
716
716
  method: 'callSyncRouterModuleWithParams',
717
717
  params: JSON.stringify({
718
718
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
719
719
  routerParam: {},
720
720
  callBackName: `window.${getCallBackName}`,
721
721
  callBackId: `${getCallBackName}Ios`,
722
722
  }),
723
723
  });
724
724
  }
725
725
  }),
726
726
  ]);
727
727
  }
728
728
  }
729
729
 
730
730
  createJdAndroidRquestEventForTouchStart() {
731
731
  if (isJdAndAndroidDevice && window?.JdAndroid) {
732
732
  const rootEleNode = document.querySelector('body');
733
733
  if (rootEleNode) {
734
734
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
735
735
  }
736
736
  }
737
737
  }
738
738
  jdAndroidAddEventListenerTouchStart(e) {
739
739
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
740
740
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
741
741
  const hasCustomEle = e
742
742
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
743
743
  : false;
744
744
  if (!hasCustomEle) {
745
745
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
746
746
  console.log(
747
747
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
748
748
  );
749
749
  }
750
750
  }
751
751
  }
752
752
  removeJdAndroidRquestEventForTouchStart() {
753
753
  if (isJdAndAndroidDevice && window.JdAndroid) {
754
754
  const rootEleNode = document.querySelector('body');
755
755
  if (rootEleNode) {
756
756
  rootEleNode.removeEventListener(
757
757
  'touchstart',
758
758
  this.jdAndroidAddEventListenerTouchStart,
759
759
  false,
760
760
  );
761
761
  }
762
762
  }
763
763
  }
764
764
 
765
765
  getNetWorkType() {
766
766
  if (isJdApp) {
767
767
  this.jmfeReayPromise().then(() => {
768
768
  window.jmfe
769
769
  .getNetworkStatus()
770
770
  .then(({ status, data }) => {
771
771
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
772
772
  if (status === '0') {
773
773
  this.info.sysInfo['netWorkType'] = data;
774
774
  } else {
775
775
  this._taroGetNetworkType();
776
776
  }
777
777
  })
778
778
  .catch((err) => {
779
779
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
780
780
  this._taroGetNetworkType();
781
781
  });
782
782
  });
783
783
  } else {
784
784
  this._taroGetNetworkType();
785
785
  }
786
786
  }
787
787
  _taroGetNetworkType() {
788
788
  Taro.getNetworkType().then((getRes) => {
789
789
  if (getRes && getRes.networkType) {
790
790
  this.info.sysInfo['netWorkType'] = getRes.networkType;
791
791
  console.log(
792
792
  '在app内通过taro对象获取网络状态完成,当前网络状态',
793
793
  this.info.sysInfo['netWorkType'],
794
794
  );
795
795
  }
796
796
  });
797
797
  }
798
798
 
799
799
  getCacheAddressRouter() {
800
800
  if (isJdApp) {
801
801
  if (!isJdAndHarmonyDevice) {
802
802
  return Promise.race([
803
803
  new Promise((resolve) => {
804
804
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
805
805
  if (!window[getCallBackName]) {
806
806
  window[getCallBackName] = (res) => {
807
807
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
808
808
  try {
809
809
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
810
810
  resolve(getResJson);
811
811
  } catch (e) {
812
812
  resolve({
813
813
  status: '-1002',
814
814
  msg: '地址信息解析json异常',
815
815
  res,
816
816
  });
817
817
  }
818
818
  window[getCallBackName] = null;
819
819
  };
820
820
  }
821
821
  const getRouterParam = {
822
822
  sceneId: 'basicShoppingProcess',
823
823
  };
824
824
  if (isAndroidDevice) {
825
825
  return callRouterAndroid({
826
826
  routerURL: 'router://JDAddressModule/getCacheAddress',
827
827
  routerParam: getRouterParam,
828
828
  callBackName: getCallBackName,
829
829
  isSync: true,
830
830
  });
831
831
  } else {
832
832
  return callRouterIOS({
833
833
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
834
834
  routerParam: getRouterParam,
835
835
  callBackName: getCallBackName,
836
836
  });
837
837
  }
838
838
  }),
839
839
  this.taskTimeoutPromise(() => {
840
840
  return {
841
841
  status: '-1000',
842
842
  msg: '原生router协议获取地址信息超时',
843
843
  };
844
844
  }, 3000),
845
845
  ]);
846
846
  } else {
847
847
  return Promise.resolve({
848
848
  status: '-1001',
849
849
  msg: '鸿蒙系统调用jmfe异常,获取失败',
850
850
  });
851
851
  }
852
852
  } else if (isH5AndJingGouMini) {
853
853
  return Promise.resolve({
854
854
  status: '-1002',
855
855
  msg: '普通h5暂无业务需要,未实现,获取失败',
856
856
  });
857
857
  } else {
858
858
  return Promise.resolve({
859
859
  status: '-1002',
860
860
  msg: '普通h5暂无业务需要,未实现,获取失败',
861
861
  });
862
862
  }
863
863
  }
864
864
 
865
865
  getAddressCachePromise() {
866
866
  return new Promise((resolve) => {
867
867
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
868
868
  resolve({
869
869
  lat: this.info.sysInfo.lat,
870
870
  lng: this.info.sysInfo.lng,
871
871
  area: this?.info?.sysInfo?.area,
872
872
  });
873
873
  } else {
874
874
  this.getCacheAddressRouter()
875
875
  .then((res) => {
876
876
  const { status, data } = res;
877
877
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
878
878
  if (status === '0' && data) {
879
879
  const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
880
880
  data || {};
881
881
  let area = '';
882
882
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
883
883
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
884
884
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
885
885
  if (getProvinceIdNum && getProvinceIdNum > 0) {
886
886
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
887
887
  this.info.pageInfo['address'] = area;
888
888
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
889
889
  this.info.sysInfo['area'] = area;
890
890
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
891
891
  area: this.info.pageInfo.address,
892
892
  });
893
893
  }
894
894
  resolve({
895
895
  lat: this.info.sysInfo['lat'],
896
896
  lng: this.info.sysInfo['lng'],
897
897
  area: area,
898
898
  });
899
899
  } else {
900
900
  if (typeof res === 'object') {
901
901
  draBusinessCustomReport({
902
902
  type: 'jdapp_getCacheAddress_info_err',
903
903
  errMsg: '松果app内通过router协议获取用户地址及经纬度信息异常',
904
904
  originReqDataStr: JSON.stringify({
905
905
  isJdApp,
906
906
  jdAppVersion: jdAppVersionStr,
907
907
  ...res,
908
908
  }),
909
909
  });
910
910
  }
911
911
  resolve({ lat: '', lng: '', area: '' });
912
912
  }
913
913
  })
914
914
  .catch((e) => {
915
915
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
916
916
  draBusinessCustomReport({
917
917
  type: 'jdapp_getCacheAddress_info_catch_err',
918
918
  errMsg: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
919
919
  originReqDataStr: JSON.stringify({
920
920
  isJdApp,
921
921
  jdAppVersion: jdAppVersionStr,
922
922
  }),
923
923
  });
924
924
  resolve({ lat: '', lng: '', area: '' });
925
925
  });
926
926
  }
927
927
  });
928
928
  }
929
929
 
930
930
  getLbsCacheAddressRouter() {
931
931
  if (isJdApp) {
932
932
  if (!isJdAndHarmonyDevice) {
933
933
  return Promise.race([
934
934
  new Promise((resolve) => {
935
935
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
936
936
  if (!window[getCallBackName]) {
937
937
  window[getCallBackName] = (res) => {
938
938
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
939
939
  try {
940
940
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
941
941
  resolve(getResJson);
942
942
  } catch (e) {
943
943
  resolve({
944
944
  status: '-1002',
945
945
  msg: '地址信息解析json异常',
946
946
  res,
947
947
  });
948
948
  }
949
949
  window[getCallBackName] = null;
950
950
  };
951
951
  }
952
952
  const getRouterParam = {
953
953
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
954
954
  sceneId: 'basicShoppingProcess',
955
955
  };
956
956
  if (isAndroidDevice) {
957
957
  return callRouterAndroid({
958
958
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
959
959
  routerParam: getRouterParam,
960
960
  callBackName: getCallBackName,
961
961
  isSync: true,
962
962
  hasJdRouter: false,
963
963
  });
964
964
  } else {
965
965
  return callRouterIOS({
966
966
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
967
967
  routerParam: getRouterParam,
968
968
  callBackName: getCallBackName,
969
969
  isSync: true,
970
970
  });
971
971
  }
972
972
  }),
973
973
  this.taskTimeoutPromise(() => {
974
974
  return {
975
975
  status: '-1000',
976
976
  msg: '原生router协议获取lbs地址信息3s超时',
977
977
  };
978
978
  }, 3000),
979
979
  ]);
980
980
  } else {
981
981
  return Promise.resolve({
982
982
  status: '-1001',
983
983
  msg: '鸿蒙系统调用未实现,获取失败',
984
984
  });
985
985
  }
986
986
  } else if (isH5AndJingGouMini) {
987
987
  return this.getLocationForGpsPromise();
988
988
  } else {
989
989
  return Promise.resolve({
990
990
  status: '-1002',
991
991
  msg: '普通h5暂无业务需要,未实现,获取失败',
992
992
  });
993
993
  }
994
994
  }
995
995
  getLocationForGpsPromise() {
996
996
  return new Promise((resolve) => {
997
997
  let hasGetLocationForGps = true;
998
998
  if (urlCookie && urlCookie['loc']) {
999
999
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
1000
1000
  urlCookie['loc'].split('_');
1001
1001
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
1002
1002
  if (getProvinceIdNum && getProvinceIdNum > 0) {
1003
1003
  hasGetLocationForGps = false;
1004
1004
  resolve({
1005
1005
  status: '0',
1006
1006
  data: {
1007
1007
  provinceid,
1008
1008
  cityid,
1009
1009
  districtid,
1010
1010
  townid,
1011
1011
  origin: 'wxapp',
1012
1012
  },
1013
1013
  });
1014
1014
  }
1015
1015
  }
1016
1016
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
1017
1017
  window.navigator.geolocation.getCurrentPosition(
1018
1018
  (position) => {
1019
1019
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
1020
1020
  if (position?.coords) {
1021
1021
  resolve({
1022
1022
  status: '0',
1023
1023
  data: {
1024
1024
  srclat: position.coords?.latitude,
1025
1025
  srclng: position.coords.longitude,
1026
1026
  origin: 'h5',
1027
1027
  },
1028
1028
  });
1029
1029
  } else {
1030
1030
  resolve({
1031
1031
  status: '-1001',
1032
1032
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
1033
1033
  position,
1034
1034
  });
1035
1035
  }
1036
1036
  },
1037
1037
  (error) => {
1038
1038
  resolve({
1039
1039
  status: '-1001',
1040
1040
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
1041
1041
  error,
1042
1042
  });
1043
1043
  },
1044
1044
  {
1045
1045
  enableHighAccuracy: false,
1046
1046
  timeout: 3 * 1000,
1047
1047
  maximumAge: 10 * 60 * 1000,
1048
1048
  },
1049
1049
  );
1050
1050
  } else {
1051
1051
  resolve({
1052
1052
  status: '-1001',
1053
1053
  msg: '您的浏览器不支持地理定位',
1054
1054
  });
1055
1055
  }
1056
1056
  });
1057
1057
  }
1058
1058
 
1059
1059
  createLbsCacheAddress(realTimeArea) {
1060
1060
  const getLbsAddressCacheMinuteTime = Number(
1061
1061
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
1062
1062
  );
1063
1063
  console.log(
1064
1064
  '获取lbs缓存到cookie的时间,分钟',
1065
1065
  getLbsAddressCacheMinuteTime,
1066
1066
  'lbsAddressCacheToCookieMinuteTime',
1067
1067
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
1068
1068
  );
1069
1069
  if (getLbsAddressCacheMinuteTime > 0) {
1070
1070
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
1071
1071
  realTimeArea &&
1072
1072
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
1073
1073
  path: '/',
1074
1074
  expires,
1075
1075
  });
1076
1076
  }
1077
1077
  }
1078
1078
 
1079
1079
  getLbsAddressCachePromise() {
1080
1080
  if (!this.lbsAddressCachePromise) {
1081
1081
  this.lbsAddressCachePromise = new Promise((resolve) => {
1082
1082
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
1083
1083
  ? cookie.get(cacheH5LbsAddressKey)
1084
1084
  : '';
1085
1085
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
1086
1086
  if (getUserLbsAddress && getUserLbsAddress !== '') {
1087
1087
  resolve({
1088
1088
  ok: true,
1089
1089
  realTimeArea: getUserLbsAddress,
1090
1090
  });
1091
1091
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
1092
1092
  console.info(
1093
1093
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
1094
1094
  getCookieForLbsAddress,
1095
1095
  );
1096
1096
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
1097
1097
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
1098
1098
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
1099
1099
  realTimeArea: getCookieForLbsAddress,
1100
1100
  });
1101
1101
  resolve({
1102
1102
  ok: true,
1103
1103
  realTimeArea: getCookieForLbsAddress,
1104
1104
  });
1105
1105
  } else {
1106
1106
  this.getLbsCacheAddressRouter()
1107
1107
  .then((res) => {
1108
1108
  const { status, data } = res;
1109
1109
  console.log(
1110
1110
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
1111
1111
  status,
1112
1112
  data,
1113
1113
  res,
1114
1114
  );
1115
1115
  if (status === '0' && data) {
1116
1116
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
1117
1117
  data || {};
1118
1118
  let realTimeArea = '';
1119
1119
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
1120
1120
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
1121
1121
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
1122
1122
  if (getProvinceIdNum && getProvinceIdNum > 0) {
1123
1123
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
1124
1124
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
1125
1125
  this.info.sysInfo['realTimeArea'] = realTimeArea;
1126
1126
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
1127
1127
  realTimeArea: this.info.pageInfo.userLbsAddress,
1128
1128
  });
1129
1129
  this.createLbsCacheAddress(realTimeArea);
1130
1130
  } else {
1131
1131
  !origin && (this.lbsAddressCachePromise = null);
1132
1132
  }
1133
1133
  const getValidRealTimeArea = realTimeArea !== '';
1134
1134
  resolve({
1135
1135
  lat: this.info.sysInfo['srclat'],
1136
1136
  lng: this.info.sysInfo['srclng'],
1137
1137
  realTimeArea: realTimeArea,
1138
1138
  ok: getValidRealTimeArea,
1139
1139
  msg: getValidRealTimeArea
1140
1140
  ? '成功'
1141
1141
  : origin
1142
1142
  ? origin
1143
1143
  : '根据router底层获取lbs地址信息异常,详情见data',
1144
1144
  data: getValidRealTimeArea ? null : res,
1145
1145
  });
1146
1146
  if (!getValidRealTimeArea && !origin) {
1147
1147
  draBusinessCustomReport({
1148
1148
  type: 'h5_getLbsCacheAddress_info_err',
1149
1149
  errMsg: '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
1150
1150
  originReqDataStr: JSON.stringify({
1151
1151
  isJdApp,
1152
1152
  jdAppVersion: jdAppVersionStr,
1153
1153
  }),
1154
1154
  });
1155
1155
  }
1156
1156
  } else {
1157
1157
  typeof res === 'object' &&
1158
1158
  draBusinessCustomReport({
1159
1159
  type: 'h5_getLbsCacheAddress_info_err',
1160
1160
  errMsg:
1161
1161
  'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
1162
1162
  originReqDataStr: JSON.stringify({
1163
1163
  isJdApp,
1164
1164
  jdAppVersion: jdAppVersionStr,
1165
1165
  ...res,
1166
1166
  }),
1167
1167
  });
1168
1168
  this.lbsAddressCachePromise = null;
1169
1169
  resolve({ realTimeArea: '', ok: false });
1170
1170
  }
1171
1171
  })
1172
1172
  .catch((e) => {
1173
1173
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
1174
1174
  this.lbsAddressCachePromise = null;
1175
1175
  draBusinessCustomReport({
1176
1176
  type: 'h5_getLbsCacheAddress_info_err',
1177
1177
  errMsg:
1178
1178
  'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
1179
1179
  originReqDataStr: JSON.stringify({
1180
1180
  isJdApp,
1181
1181
  jdAppVersion: jdAppVersionStr,
1182
1182
  }),
1183
1183
  });
1184
1184
  resolve({ realTimeArea: '', ok: false });
1185
1185
  });
1186
1186
  }
1187
1187
  });
1188
1188
  }
1189
1189
  return this.lbsAddressCachePromise;
1190
1190
  }
1191
1191
 
1192
1192
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1193
1193
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
1194
1194
  if (!isJdApp) {
1195
1195
  return;
1196
1196
  }
1197
1197
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
1198
1198
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
1199
1199
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
1200
1200
  'hybridHttpSwitch',
1201
1201
  isBeforePageReady,
1202
1202
  );
1203
1203
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
1204
1204
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1205
1205
  'isFollowAppVideoPlayStatus',
1206
1206
  isBeforePageReady,
1207
1207
  );
1208
1208
  console.log(
1209
1209
  'isBeforePageReady:',
1210
1210
  isBeforePageReady,
1211
1211
  'isFollowAppVideoPlayStatus:',
1212
1212
  isFollowAppVideoPlayStatus,
1213
1213
  );
1214
1214
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
1215
1215
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
1216
1216
  }
1217
1217
  }
1218
1218
 
1219
1219
  async getWifiVideoAutoPlayAsync() {
1220
1220
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
1221
1221
  if (!isJdApp) {
1222
1222
  return;
1223
1223
  }
1224
1224
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
1225
1225
  return 0;
1226
1226
  });
1227
1227
  if (Number(videoPlayStatus) === 1) {
1228
1228
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
1229
1229
  }
1230
1230
  }
1231
1231
 
1232
1232
  async getMPaasConfigAsync() {
1233
1233
  this.info.sysInfo.dynamicConfig = {};
1234
1234
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
1235
1235
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
1236
1236
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
1237
1237
  return this.updateMPaasConfigAsync(true);
1238
1238
  }
1239
1239
 
1240
1240
  getDynamicConfig(key: string) {
1241
1241
  return this.info.sysInfo?.dynamicConfig?.[key];
1242
1242
  }
1243
1243
  async updateMPaasConfig() {
1244
1244
  console.log('updateMPaasConfig');
1245
1245
  if (
1246
1246
  isIosDevice &&
1247
1247
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1248
1248
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1249
1249
  ) {
1250
1250
  try {
1251
1251
  await this.updateMPaasConfigAsync(false);
1252
1252
  } catch (e) {
1253
1253
  console.log('updateMPaasConfigAsync:', e);
1254
1254
  }
1255
1255
  }
1256
1256
  }
1257
1257
 
1258
1258
  toLogin(options) {
1259
1259
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1260
1260
  ? this.toWxAppLogin(options)
1261
1261
  : this.toWebLogin(options);
1262
1262
  }
1263
1263
 
1264
1264
  doLogin(options) {
1265
1265
  return this.toLogin(options);
1266
1266
  }
1267
1267
 
1268
1268
  doLoginForJdPin(options = {}) {
1269
1269
  return this.doLogin({
1270
1270
  loginColor: {
1271
1271
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1272
1272
  dpin: 0,
1273
1273
  },
1274
1274
  ...options,
1275
1275
  });
1276
1276
  }
1277
1277
 
1278
1278
  toWebLogin(options) {
1279
1279
  let params: {
1280
1280
  returnurl: string;
1281
1281
  } = {
1282
1282
  returnurl: '',
1283
1283
  };
1284
1284
  const checkToPcLogin = options ? options?.isPc : isPc;
1285
1285
  const loginUrl = checkToPcLogin
1286
1286
  ? `//passport.jd.com/new/login.aspx`
1287
1287
  : `${domain.mobileLogin}/user/login.action`;
1288
1288
  const defaultParams = {
1289
1289
  appid: '100',
1290
1290
  returnurl: window.location.href,
1291
1291
  };
1292
1292
  if (isString(options)) {
1293
1293
  params = Object.assign({}, defaultParams, {
1294
1294
  returnurl: options,
1295
1295
  });
1296
1296
  } else if (isObject(options)) {
1297
1297
  const { loginColor, ...otherOptions } = options;
1298
1298
  params = Object.assign({}, defaultParams, otherOptions);
1299
1299
  } else {
1300
1300
  params = defaultParams;
1301
1301
  }
1302
1302
  params.returnurl = encodeURIComponent(params.returnurl);
1303
1303
  let getFullUrl = loginUrl + '?' + serialize(params);
1304
1304
  if (checkToPcLogin) {
1305
1305
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
1306
1306
  }
1307
1307
  return Promise.resolve({
1308
1308
  h5ToUrl: true,
1309
1309
  url: getFullUrl,
1310
1310
  }).then(() => {
1311
1311
  window.location.href = getFullUrl;
1312
1312
  });
1313
1313
  }
1314
1314
 
1315
1315
  toWxAppLogin(options = {}) {
1316
1316
  console.log('微信京购小程序中h5登录跳转', options);
1317
1317
  return Promise.resolve(true).then(() => {
1318
1318
  const { loginColor } = Object.assign(
1319
1319
  {},
1320
1320
  {
1321
1321
  loginColor: {
1322
1322
  biz: WXAPP_BIZ_KEY,
1323
1323
  dpin: 1,
1324
1324
  },
1325
1325
  },
1326
1326
  options,
1327
1327
  );
1328
1328
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1329
1329
  loginColor.biz
1330
1330
  }&url=${encodeURIComponent(window.location.href)}`;
1331
1331
  });
1332
1332
  }
1333
1333
 
1334
1334
  getLoginCookie() {
1335
1335
  return Promise.resolve({
1336
1336
  pin: cookie.get('pin') || '',
1337
1337
  });
1338
1338
  }
1339
1339
 
1340
1340
  clearLoginCookie() {
1341
1341
  cookie.remove('pin');
1342
1342
  }
1343
1343
 
1344
1344
  checkStatusAndLogin(options = {}) {
1345
1345
  if (!this.checkStatusAndLoginPromise) {
1346
1346
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1347
1347
  try {
1348
1348
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
1349
1349
  if (getLoginState) {
1350
1350
  resolve(true);
1351
1351
  } else {
1352
1352
  this.toLogin(options);
1353
1353
  reject(false);
1354
1354
  }
1355
1355
  } catch (e) {
1356
1356
  this.toLogin(options);
1357
1357
  reject(false);
1358
1358
  }
1359
1359
  });
1360
1360
  return this.checkStatusAndLoginPromise;
1361
1361
  } else {
1362
1362
  return this.checkStatusAndLoginPromise
1363
1363
  .then(() => {
1364
1364
  return Promise.resolve(true);
1365
1365
  })
1366
1366
  .catch(() => {
1367
1367
  this.toLogin(options);
1368
1368
  return Promise.reject(true);
1369
1369
  });
1370
1370
  }
1371
1371
  }
1372
1372
 
1373
1373
  checkJdStatusAndLogin(
1374
1374
  options = {
1375
1375
  loginColor: {
1376
1376
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1377
1377
  dpin: 0,
1378
1378
  },
1379
1379
  },
1380
1380
  ) {
1381
1381
  return this.checkStatusAndLogin(options);
1382
1382
  }
1383
1383
 
1384
1384
  doCheckLoginStateAndForApiCheck(options) {
1385
1385
  if (this.info.loginState) {
1386
1386
  return Promise.resolve(true);
1387
1387
  } else {
1388
1388
  return new Promise((resolve, reject) => {
1389
1389
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
1390
1390
  const getWqAuthToken = cookie.get('wq_auth_token');
1391
1391
  const getWqSkey = cookie.get('wq_skey');
1392
1392
  const getWqUin = cookie.get('wq_uin');
1393
1393
  const isLoginState =
1394
1394
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
1395
1395
  if (isLoginState) {
1396
1396
  this.info.loginState = true;
1397
1397
  resolve(true);
1398
1398
  } else {
1399
1399
  reject(false);
1400
1400
  }
1401
1401
  } else {
1402
1402
  Taro.request({
1403
1403
  url: api.isLogin,
1404
1404
  jsonp: true,
1405
1405
  timeout: 3000,
1406
1406
  success: (res) => {
1407
1407
  const { statusCode, data } = res;
1408
1408
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
1409
1409
  this.info.loginState = true;
1410
1410
  resolve(true);
1411
1411
  } else {
1412
1412
  reject(false);
1413
1413
  }
1414
1414
  },
1415
1415
  fail: (err) => {
1416
1416
  console.log('登录检查异常', err);
1417
1417
  reject(false);
1418
1418
  },
1419
1419
  });
1420
1420
  }
1421
1421
  });
1422
1422
  }
1423
1423
  }
1424
1424
 
1425
1425
  checkLoginStatus(options) {
1426
1426
  return new Promise(async (resolve, reject) => {
1427
1427
  try {
1428
1428
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
1429
1429
  if (getLoginState) {
1430
1430
  const { pin } = await this.getLoginCookie();
1431
1431
  this.info.userInfo = {
1432
1432
  pin,
1433
1433
  encodePin: encodeURIComponent(pin),
1434
1434
  ptkey: '',
1435
1435
  };
1436
1436
  resolve(true);
1437
1437
  } else {
1438
1438
  reject(false);
1439
1439
  }
1440
1440
  } catch (e) {
1441
1441
  reject(false);
1442
1442
  }
1443
1443
  });
1444
1444
  }
1445
1445
 
1446
1446
  updatePageAndLogInfo(updateQuery = {}) {
1447
1447
  const createUpdateQueryInfo: {
1448
1448
  query: {
1449
1449
  shopId?: string | number;
1450
1450
  venderId?: string | number;
1451
1451
  };
1452
1452
  updateShopInfoState: boolean;
1453
1453
  } = Object.assign(
1454
1454
  {},
1455
1455
  {
1456
1456
  query: {},
1457
1457
  updateShopInfoState: false,
1458
1458
  },
1459
1459
  updateQuery,
1460
1460
  );
1461
1461
  console.log(
1462
1462
  '获取当前下发的店铺查询参数',
1463
1463
  updateQuery,
1464
1464
  '获取之前保存的shopInfo店铺查询参数',
1465
1465
  this.info?.shopInfo,
1466
1466
  );
1467
1467
  const { query, updateShopInfoState } = createUpdateQueryInfo;
1468
1468
  const { shopId, venderId, un_area } = query;
1469
1469
  if (updateShopInfoState) {
1470
1470
  this.info.queryInfo = {
1471
1471
  ...this.info.queryInfo,
1472
1472
  ...query,
1473
1473
  };
1474
1474
  if (shopId && venderId) {
1475
1475
  this.info.shopInfo = {
1476
1476
  shopId: `${shopId}`,
1477
1477
  venderId: `${venderId}`,
1478
1478
  };
1479
1479
  }
1480
1480
  } else {
1481
1481
  this.info.queryInfo = {
1482
1482
  ...query,
1483
1483
  };
1484
1484
  if (
1485
1485
  this.info.shopInfo?.shopId &&
1486
1486
  this.info.shopInfo?.venderId &&
1487
1487
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
1488
1488
  ) {
1489
1489
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
1490
1490
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
1491
1491
  console.log(
1492
1492
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1493
1493
  this.info.queryInfo,
1494
1494
  );
1495
1495
  }
1496
1496
  }
1497
1497
  this.info.queryInfo['shopId'] &&
1498
1498
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
1499
1499
  this.info.queryInfo['venderId'] &&
1500
1500
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
1501
1501
  console.log(
1502
1502
  'h5==获取店铺下发查询参数\n',
1503
1503
  query,
1504
1504
  '\n获取店铺最后查询参数\n',
1505
1505
  this.info.queryInfo,
1506
1506
  '\n是否为更新店铺状态\n',
1507
1507
  updateShopInfoState,
1508
1508
  );
1509
1509
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
1510
1510
  if (changeArea) {
1511
1511
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
1512
1512
  this.info.pageInfo.address = getBottomAreaStr;
1513
1513
  this.info.pageInfo.un_area = getBottomAreaStr;
1514
1514
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
1515
1515
  }
1516
1516
  }
1517
1517
 
1518
1518
  dealLoadSdkList() {
1519
1519
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
1520
1520
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
1521
1521
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
1522
1522
  let mergeLoadJsList = globalLoadJsList;
1523
1523
  try {
1524
1524
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
1525
1525
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
1526
1526
  getFindIndex !== -1
1527
1527
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
1528
1528
  : accArr.push(current);
1529
1529
  return accArr;
1530
1530
  }, []);
1531
1531
  } catch (e) {
1532
1532
  console.log('LoadJsList合并错误', e);
1533
1533
  }
1534
1534
  console.log(
1535
1535
  'globalLoadJsList',
1536
1536
  globalLoadJsList,
1537
1537
  'businessLoadJsList',
1538
1538
  businessLoadJsList,
1539
1539
  '两个加载jsList集合合并完成',
1540
1540
  mergeLoadJsList,
1541
1541
  );
1542
1542
  this.loadJsSdkList = mergeLoadJsList;
1543
1543
  return this.loadJsSdkList;
1544
1544
  }
1545
1545
 
1546
1546
  renderNextTickLoadSdk() {
1547
1547
  Taro.nextTick(() => {
1548
1548
  console.log(
1549
1549
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
1550
1550
  );
1551
1551
  setTimeout(() => {
1552
1552
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
1553
1553
  }, 1000);
1554
1554
  });
1555
1555
  }
1556
1556
 
1557
1557
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
1558
1558
  const getLoadJsList =
1559
1559
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
1560
1560
  const getLoadFilterList = getLoadJsList.filter((item) => {
1561
1561
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
1562
1562
  let getLoastLoadEventState = true;
1563
1563
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
1564
1564
  getLoastLoadEventState = isJdApp;
1565
1565
  }
1566
1566
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
1567
1567
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
1568
1568
  }
1569
1569
  const getInitTriggerType =
1570
1570
  isJdApp && item?.initJdAppTriggerType
1571
1571
  ? item?.initTriggerType
1572
1572
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
1573
1573
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
1574
1574
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
1575
1575
  });
1576
1576
  console.log(
1577
1577
  '获取当前触发方式',
1578
1578
  triggerType,
1579
1579
  '获取当前最后加载的js集合',
1580
1580
  getLoadFilterList,
1581
1581
  '过滤前的加载集合',
1582
1582
  getLoadJsList,
1583
1583
  );
1584
1584
  getLoadFilterList.length > 0 &&
1585
1585
  getLoadFilterList.forEach((item) => {
1586
1586
  const isLoadState = /sgm/.test(item?.fileName)
1587
1587
  ? window?.shopGlobalSwitch?.openSgm === 'true'
1588
1588
  : true;
1589
1589
  isLoadState &&
1590
1590
  this.loadItemSdkPromise(item)
1591
1591
  .then((res) => {
1592
1592
  console.info('当前js地址' + item?.src, '加载状态', res);
1593
1593
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
1594
1594
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
1595
1595
  window.dra.run('init', { aid: res?.aid });
1596
1596
  window.dra.run('start');
1597
1597
  }
1598
1598
  })
1599
1599
  .catch((err) => {
1600
1600
  console.info('当前js地址加载异常', item?.src);
1601
1601
  window?.fetchErrorData &&
1602
1602
  window.fetchErrorData({
1603
1603
  title: '公共js加载异常',
1604
1604
  type: 'jsLoad',
1605
1605
  data: err,
1606
1606
  });
1607
1607
  });
1608
1608
  });
1609
1609
  }
1610
1610
  loadScriptEle(jsInfo, resolve, reject) {
1611
1611
  const getFileName = jsInfo?.fileName;
1612
1612
  if (getFileName) {
1613
1613
  const getEleId = `J_loadJs_${getFileName}`;
1614
1614
  const getEle = document.getElementById(getEleId);
1615
1615
  if (!getEle) {
1616
1616
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
1617
1617
  const _sgmEle = document.createElement('script');
1618
1618
  _sgmEle.id = getEleId;
1619
1619
  _sgmEle.onload = function () {
1620
1620
  resolve({
1621
1621
  ...jsInfo,
1622
1622
  jsTip: 'js加载成功',
1623
1623
  });
1624
1624
  };
1625
1625
  _sgmEle.onerror = function () {
1626
1626
  reject({
1627
1627
  ...jsInfo,
1628
1628
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1629
1629
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
1630
1630
  });
1631
1631
  };
1632
1632
  const dataAttrList = ['timeout', 'fileName', 'env'];
1633
1633
  const getJsInfoKeyList = Object.keys(jsInfo);
1634
1634
  getJsInfoKeyList.forEach((key) => {
1635
1635
  if (key === 'async') {
1636
1636
  _sgmEle.async = jsInfo[key];
1637
1637
  } else if (key === 'crossOrigin') {
1638
1638
  _sgmEle.crossOrigin = jsInfo[key];
1639
1639
  } else if (key === 'src') {
1640
1640
  _sgmEle.src = `${jsInfo[key]}`;
1641
1641
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
1642
1642
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
1643
1643
  } else {
1644
1644
  _sgmEle.setAttribute(key, jsInfo[key]);
1645
1645
  }
1646
1646
  });
1647
1647
  document.head.appendChild(_sgmEle);
1648
1648
  } else {
1649
1649
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
1650
1650
  resolve({
1651
1651
  ...jsInfo,
1652
1652
  jsTip: 'js本身已存在页面中',
1653
1653
  });
1654
1654
  }
1655
1655
  } else {
1656
1656
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
1657
1657
  }
1658
1658
  }
1659
1659
 
1660
1660
  loadItemSdkPromise(jsInfo = {}) {
1661
1661
  if (jsInfo?.src) {
1662
1662
  const getInitLoadType =
1663
1663
  isJdApp && jsInfo?.initJdAppLoadType
1664
1664
  ? jsInfo?.initJdAppLoadType
1665
1665
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
1666
1666
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
1667
1667
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
1668
1668
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
1669
1669
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
1670
1670
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
1671
1671
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
1672
1672
  try {
1673
1673
  const jsXhrRequest = new XMLHttpRequest();
1674
1674
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
1675
1675
  const jsUrl = `${jsInfo?.src}`;
1676
1676
  jsXhrRequest.open('GET', jsUrl, true);
1677
1677
  jsXhrRequest.onreadystatechange = () => {
1678
1678
  if (jsXhrRequest.readyState === 4) {
1679
1679
  const getReqStatus = jsXhrRequest.status;
1680
1680
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
1681
1681
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
1682
1682
  if (getInsetHeadState) {
1683
1683
  this.loadScriptEle(jsInfo, resolve, reject);
1684
1684
  } else {
1685
1685
  resolve({
1686
1686
  ...jsInfo,
1687
1687
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
1688
1688
  });
1689
1689
  }
1690
1690
  getReqStatus !== 200 &&
1691
1691
  sgmCustomReport({
1692
1692
  type: 3,
1693
1693
  code: 'js_load_special_code',
1694
1694
  msg: {
1695
1695
  msg: '当前js加载成功,状态非200,特殊上报观察',
1696
1696
  jsReqState: getReqStatus,
1697
1697
  env: getSgmCustomCode('js_load_special_code'),
1698
1698
  data: jsInfo,
1699
1699
  },
1700
1700
  });
1701
1701
  } else {
1702
1702
  const getRes = {
1703
1703
  ...jsInfo,
1704
1704
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1705
1705
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
1706
1706
  jsReqState: getReqStatus,
1707
1707
  };
1708
1708
  console.log('当前js请求状态异常,具体信息见', getRes);
1709
1709
  reject(getRes);
1710
1710
  }
1711
1711
  }
1712
1712
  };
1713
1713
  jsXhrRequest.onerror = () => {
1714
1714
  const getRes = {
1715
1715
  ...jsInfo,
1716
1716
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1717
1717
  jsReqError: '请求错误',
1718
1718
  };
1719
1719
  console.log('当前js请求错误', getRes);
1720
1720
  jsXhrRequest.abort();
1721
1721
  reject(getRes);
1722
1722
  };
1723
1723
  jsXhrRequest.ontimeout = () => {
1724
1724
  const getRes = {
1725
1725
  ...jsInfo,
1726
1726
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1727
1727
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
1728
1728
  jsReqState: jsXhrRequest.status,
1729
1729
  };
1730
1730
  console.log('当前js请求超时异常', getRes);
1731
1731
  jsXhrRequest.abort();
1732
1732
  reject(getRes);
1733
1733
  };
1734
1734
  jsXhrRequest.send();
1735
1735
  } catch (e) {
1736
1736
  console.log('执行js请求异常', e);
1737
1737
  reject({
1738
1738
  ...jsInfo,
1739
1739
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1740
1740
  jsReqError: '未知异常',
1741
1741
  error: e,
1742
1742
  });
1743
1743
  }
1744
1744
  });
1745
1745
  } else {
1746
1746
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
1747
1747
  return this.loadScriptEle(jsInfo, resolve, reject);
1748
1748
  });
1749
1749
  }
1750
1750
  }
1751
1751
  return this.loadJsSdkListCachePromise[getFileKeyName];
1752
1752
  } else {
1753
1753
  return Promise.resolve({
1754
1754
  ...jsInfo,
1755
1755
  jsTip: 'js加载方式设置为不加载,当前不做处理',
1756
1756
  });
1757
1757
  }
1758
1758
  } else {
1759
1759
  return Promise.reject(jsInfo);
1760
1760
  }
1761
1761
  }
1762
1762
 
1763
1763
  createLanguagePromise() {
1764
1764
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
1765
1765
  if (!this.languageCacheProimse) {
1766
1766
  this.languageCacheProimse = new Promise((resolve, reject) => {
1767
1767
  const { fileName, prefixUrl } = getLanguageConfig;
1768
1768
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
1769
1769
  const dealLanguageFile = () => {
1770
1770
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
1771
1771
  .then((res) => {
1772
1772
  if (res && res?.data) {
1773
1773
  this.languageJsonData = res.data;
1774
1774
 
1775
1775
  setTimeout(() => {
1776
1776
  const getOtherLanguageList = languageTypeList.filter(
1777
1777
  (item) => item !== languageNowType,
1778
1778
  );
1779
1779
  getOtherLanguageList.length > 0 &&
1780
1780
  getOtherLanguageList.map((languageTypeKey) => {
1781
1781
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
1782
1782
  });
1783
1783
  }, 3000);
1784
1784
  resolve(res);
1785
1785
  } else {
1786
1786
  reject(res);
1787
1787
  }
1788
1788
  })
1789
1789
  .catch((err) => {
1790
1790
  reject(err);
1791
1791
  });
1792
1792
  };
1793
1793
  if (fileName && prefixUrl) {
1794
1794
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
1795
1795
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
1796
1796
  if (getLocalLangRes) {
1797
1797
  try {
1798
1798
  const getLocalLangJsonData =
1799
1799
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
1800
1800
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
1801
1801
  if (getLocalLangJsonData?.fileName === fileName) {
1802
1802
  const geThisLangData = getLocalLangJsonData.data;
1803
1803
  this.languageJsonData = geThisLangData;
1804
1804
  return resolve({
1805
1805
  ...getLanguageConfig,
1806
1806
  languageNowType,
1807
1807
  data: geThisLangData,
1808
1808
  });
1809
1809
  } else {
1810
1810
  dealLanguageFile();
1811
1811
  }
1812
1812
  } else {
1813
1813
  dealLanguageFile();
1814
1814
  }
1815
1815
  } catch (e) {
1816
1816
  return reject({
1817
1817
  languageNowType,
1818
1818
  msg: '转换错误',
1819
1819
  ...getLanguageConfig,
1820
1820
  });
1821
1821
  }
1822
1822
  } else {
1823
1823
  dealLanguageFile();
1824
1824
  }
1825
1825
  } else {
1826
1826
  return reject({
1827
1827
  languageNowType,
1828
1828
  msg: '文件对象下发异常',
1829
1829
  ...getLanguageConfig,
1830
1830
  });
1831
1831
  }
1832
1832
  });
1833
1833
  }
1834
1834
  return this.languageCacheProimse;
1835
1835
  }
1836
1836
 
1837
1837
  getLanguageFilePromise(info, languageTypeKey) {
1838
1838
  const { fileName, prefixUrl, timeout } = info || {};
1839
1839
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
1840
1840
  return new Promise((resolve, reject) => {
1841
1841
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
1842
1842
  try {
1843
1843
  const langXhrRequest = new XMLHttpRequest();
1844
1844
  langXhrRequest.timeout = timeout || 2000;
1845
1845
  langXhrRequest.open('GET', getUrl, true);
1846
1846
  langXhrRequest.responseType = 'json';
1847
1847
  langXhrRequest.onreadystatechange = () => {
1848
1848
  if (langXhrRequest.readyState === 4) {
1849
1849
  const getReqStatus = langXhrRequest.status;
1850
1850
  const statusText = langXhrRequest.statusText;
1851
1851
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
1852
1852
  const getData = langXhrRequest?.response || false;
1853
1853
  if (getData) {
1854
1854
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
1855
1855
  fileName,
1856
1856
  data: getData,
1857
1857
  });
1858
1858
  resolve({
1859
1859
  ...info,
1860
1860
  languageTypeKey,
1861
1861
  data: getData,
1862
1862
  });
1863
1863
  } else {
1864
1864
  reject({
1865
1865
  ...info,
1866
1866
  languageTypeKey,
1867
1867
  msg: '数据获取异常',
1868
1868
  });
1869
1869
  }
1870
1870
  } else {
1871
1871
  const getRes = {
1872
1872
  ...info,
1873
1873
  languageTypeKey,
1874
1874
  env: getSgmCustomCode(langLoadErrorSgmCode),
1875
1875
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
1876
1876
  };
1877
1877
  console.log('当前lang请求状态异常,具体信息见', getRes);
1878
1878
  reject(getRes);
1879
1879
  }
1880
1880
  }
1881
1881
  };
1882
1882
  langXhrRequest.onerror = () => {
1883
1883
  const getRes = {
1884
1884
  ...info,
1885
1885
  env: getSgmCustomCode(langLoadErrorSgmCode),
1886
1886
  msg: '请求错误',
1887
1887
  };
1888
1888
  console.log('当前lang请求错误', getRes);
1889
1889
  langXhrRequest.abort();
1890
1890
  reject(getRes);
1891
1891
  };
1892
1892
  langXhrRequest.ontimeout = () => {
1893
1893
  const getRes = {
1894
1894
  ...info,
1895
1895
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
1896
1896
  };
1897
1897
  console.log('执行lang多语言请求超时异常', getRes);
1898
1898
  langXhrRequest.abort();
1899
1899
  reject(getRes);
1900
1900
  };
1901
1901
  langXhrRequest.send();
1902
1902
  } catch (e) {
1903
1903
  console.log('执行lang多语言请求异常', e);
1904
1904
  reject({
1905
1905
  ...info,
1906
1906
  env: getSgmCustomCode(langLoadErrorSgmCode),
1907
1907
  msg: '未知异常',
1908
1908
  error: e,
1909
1909
  });
1910
1910
  }
1911
1911
  });
1912
1912
  }