@conecli/cone-render 0.10.1-shop3.1 → 0.10.1-shop3.100

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 (129) hide show
  1. package/README.md +1 -1
  2. package/dist/api/index.ts +1 -1
  3. package/dist/common/accessibility.h5.ts +1 -0
  4. package/dist/common/accessibility.ts +1 -0
  5. package/dist/common/const.ts +1 -1
  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.weapp.tsx +1 -0
  11. package/dist/common/jssdk.ts +1 -1
  12. package/dist/common/jssdk.weapp.ts +1 -0
  13. package/dist/common/pageType.ts +1 -1
  14. package/dist/common/token/index.h5.ts +1 -1
  15. package/dist/common/token/token.jd.ts +1 -1
  16. package/dist/common/wxappApi.ascf.ts +1 -0
  17. package/dist/common/wxappApi.ts +1 -1
  18. package/dist/components/ErrorBoundary.tsx +1 -1
  19. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  20. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  21. package/dist/components/base/CountDown/index.module.scss +49 -44
  22. package/dist/components/base/CountDown/index.tsx +1 -1
  23. package/dist/components/base/CustomScrollView/index-back.tsx +1 -0
  24. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  25. package/dist/components/base/CustomVideo/index.tsx +1 -1
  26. package/dist/components/base/CustomVideo/index.weapp.tsx +1 -0
  27. package/dist/components/base/Dialog/index.module.scss +11 -0
  28. package/dist/components/base/ExposureSmart/index.h5.module.scss +12 -2
  29. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  30. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  31. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  32. package/dist/components/base/InOrOutViewObserver/index.weapp.tsx +1 -0
  33. package/dist/components/base/InViewRender/index.tsx +1 -1
  34. package/dist/components/base/ItemViewExposureSmart/index.module.scss +2 -2
  35. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  36. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  37. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  38. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  39. package/dist/components/base/MobileCommonHeader/index.weapp.tsx +1 -0
  40. package/dist/components/base/NetworkDataError/const.ts +1 -1
  41. package/dist/components/base/NetworkDataError/index.module.scss +118 -72
  42. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  43. package/dist/components/base/Price/Base/index.module.scss +12 -0
  44. package/dist/components/base/Price/Base/index.tsx +1 -1
  45. package/dist/components/base/Price/Double/index.module.scss +33 -1
  46. package/dist/components/base/Price/Double/index.tsx +1 -1
  47. package/dist/components/base/ShopLeGaoTag/index.h5.module.scss +35 -0
  48. package/dist/components/base/ShopLeGaoTag/index.h5.tsx +1 -0
  49. package/dist/components/base/ShopLeGaoTag/index.module.scss +33 -0
  50. package/dist/components/base/ShopLeGaoTag/index.tsx +1 -0
  51. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  52. package/dist/components/floorItem.tsx +1 -1
  53. package/dist/components/floorItem.weapp.tsx +1 -1
  54. package/dist/components/isv/Floor/index.tsx +1 -1
  55. package/dist/components/remoteFloorItem.tsx +1 -1
  56. package/dist/config/env.ts +1 -1
  57. package/dist/interface/common.ts +1 -1
  58. package/dist/interface/component.ts +1 -1
  59. package/dist/interface/jumpEventReport.ts +1 -1
  60. package/dist/interface/service.ts +1 -1
  61. package/dist/jumpEventReport/base.ts +1 -1
  62. package/dist/jumpEventReport/const.ts +1 -1
  63. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  64. package/dist/jumpEventReport/index.h5.ts +1 -1
  65. package/dist/jumpEventReport/index.jd.ts +1 -1
  66. package/dist/jumpEventReport/index.weapp.ts +1 -1
  67. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  68. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  69. package/dist/jumpEventReport/logEventConfig.h5.ts +1 -0
  70. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  71. package/dist/jumpEventReport/web/report.ts +1 -1
  72. package/dist/jumpEventReport/web.base.ts +1 -1
  73. package/dist/jumpEventReport/web.jd.ts +1 -1
  74. package/dist/jumpEventReport/web.jdb.ts +1 -1
  75. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  76. package/dist/jumpEventReport/web.jxwxapp.ts +1 -1
  77. package/dist/jumpEventReport/web.pc.ts +1 -1
  78. package/dist/jumpEventReport/web.tjapp.ts +1 -1
  79. package/dist/jumpEventReport/web.tjm.ts +1 -1
  80. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  81. package/dist/language/en_US.json +395 -0
  82. package/dist/language/zh_CN.json +395 -0
  83. package/dist/language/zh_HK.json +395 -0
  84. package/dist/libs/openShopBridge.js +161 -0
  85. package/dist/libs/openShopBridge.min.js +1 -0
  86. package/dist/libs/taroAppReport.js +2 -2
  87. package/dist/modules/ContainerFloorList/index.h5.module.scss +80 -53
  88. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  89. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  90. package/dist/modules/DecorateContainerFloorList/index.weapp.tsx +1 -0
  91. package/dist/open/api/environment.ts +1 -1
  92. package/dist/open/api/shopMember.ts +1 -1
  93. package/dist/open/api/shopMember.weapp.ts +1 -0
  94. package/dist/open/api/track.ts +1 -1
  95. package/dist/open/api/util.ts +1 -1
  96. package/dist/open/components/index.ts +1 -1
  97. package/dist/open/index.ts +1 -1
  98. package/dist/sass/app.h5.scss +278 -224
  99. package/dist/sass/base.scss +150 -145
  100. package/dist/service/fetchGateway.ts +1 -1
  101. package/dist/service/fetchGateway.weapp.ts +1 -0
  102. package/dist/service/fetchJsonp.weapp.ts +1 -0
  103. package/dist/service/http/colorSign.ts +1 -1
  104. package/dist/service/http/const.ts +1 -1
  105. package/dist/service/http/h5Http.ts +1 -1
  106. package/dist/service/http/httpInterceptors.weapp.ts +1 -0
  107. package/dist/service/requestServer.h5.ts +1 -1
  108. package/dist/service/requestServer.ts +1 -1
  109. package/dist/service/requestServer.weapp.ts +1 -0
  110. package/dist/utils/connectNativeJsBridge.ts +1 -1
  111. package/dist/utils/h5Utils.ts +1 -1
  112. package/dist/utils/harmonyCallRouter.h5.ts +1 -0
  113. package/dist/utils/harmonyCallRouter.ts +0 -0
  114. package/dist/utils/index.h5.ts +1 -1
  115. package/dist/utils/index.ts +1 -1
  116. package/dist/utils/index.weapp.ts +1 -1
  117. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  118. package/dist/utils/jumpExtMapUtil.ts +1 -0
  119. package/dist/utils/jumpExtMapUtil.weapp.ts +1 -0
  120. package/dist/utils/log.ts +1 -0
  121. package/dist/utils/sColor.ts +1 -0
  122. package/dist/utils/sColor.weapp.ts +1 -0
  123. package/dist/utils/utils.ts +1 -1
  124. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  125. package/dist/wxapp/common/user_info.js +1 -1
  126. package/package.json +162 -141
  127. package/dist/jumpEventReport/web/wqshop.report.ts +0 -1
  128. package/dist/utils/memberFormatUtils.js +0 -1
  129. package/dist/utils/priceUtils.js +0 -1
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  isIosDevice,
3
2
  isAndroidDevice,
4
3
  isJdAndHarmonyDevice,
5
4
  isJdAndAndroidDevice,
6
5
  jdAppVersion,
7
6
  jdAppVersionStr,
8
7
  isString,
9
8
  isObject,
10
9
  serialize,
11
10
  dealNativePixelToCssPixel,
12
11
  isPc,
13
12
  BUSINESS_TYPE,
14
13
  JSSDK_APP_WEBVIEW_CODE,
15
14
  SECTION_HOME_TAB_NAME_TYPE,
16
15
  SECTION_HOME_TAB_TYPE,
17
16
  WXAPP_BIZ_KEY,
18
17
  WX_BUSINESS_TYPE,
19
18
  MPAAS_CONFIG_APP_VERSION,
20
19
  MPAAS_CONFIG_APP_LOW_VERSION,
21
20
  WXAPP_BIZ_SHOP_LIGHT_KEY,
22
21
  LoadJsInitLoadEnvType,
23
22
  LoadJsInitLoadType,
24
23
  LoadJsInitTriggerType
25
24
  loginState: false,
26
25
  cookiesStr: '',
27
26
  userInfo: userPinKey,
28
27
  isJingGouMiniViewState: false,
29
28
  isJingxiMiniViewState: false,
30
29
  pageInfo: {
31
30
  wxBusinessType: WX_BUSINESS_TYPE.NO,
32
31
  address: '',
33
32
  addressCommaStr: '',
34
33
  un_area: '',
35
34
  vapptype: '1',
36
35
  pageType: 'home',
37
36
  isExposureState: false,
38
37
  moduleId: '',
39
38
  entrance: '',
40
39
  dataType: BUSINESS_TYPE.ONLINE,
41
40
  floorExposureInfo: {},
42
41
  floorVideInfo: {},
43
42
  productVideInfo: {},
44
43
  tabsLoadAllDataInfo: {
45
44
  [SECTION_HOME_TAB_NAME_TYPE[
46
45
  SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
47
46
  ]]: false,
48
47
  },
49
48
  updateShopInfosAllState: false,
50
49
  isVipShop: false,
51
50
  isJdShowNativeImmersivePlayer: false,
52
51
  ...shopConfig,
53
52
  pageScrollTop: 0,
54
53
  pageIdxHeightInfo: {
55
54
  list: [],
56
55
  },
57
56
  shopNavBarHeight: 0,
58
57
  },
59
58
  defaultQueryLogInfo: {
60
59
  sourceType: 'JDshop',
61
60
  sourceValue: '',
62
61
  moduleId: 'none',
63
62
  entrance: 'none',
64
63
  },
65
64
  sysInfo: {
66
65
  windowWidth: isPc ? 375 : 0,
67
66
  containerWidth: isPc ? 375 : 0,
68
67
  windowHeight: 0,
69
68
  netWorkType: '4g',
70
69
  jdBottomBarHeight: 0,
71
70
  jdNativeHeaderHeight: 0,
72
71
  },
73
72
  queryInfo: {},
74
73
  shopInfo: {},
75
74
  openAppData: {},
76
75
  public info: CommonInterFace.BaseConfigInfo
77
76
  public config: {
78
77
  [key: string]: any
79
78
  }
80
79
  public lazyContainer: CommonInterFace.lazyContainer
81
80
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
82
81
  public rootEleNode: HTMLElement | null
83
82
  public checkStatusAndLoginPromise: object | null
84
83
  private jmfeRegisterStatePromise: Promise<any> | null
85
84
  private jmfeRegisterState: boolean
86
85
  public loadJsSdkList: Array<any>
87
86
  public loadJsSdkListCachePromise: any
88
87
  constructor(opt) {
89
88
  this.info = this._getConfig(opt)
90
89
  this.config = {}
91
90
  this.loadJsSdkList = []
92
91
  this.loadJsSdkListCachePromise = {}
93
92
  this.lazyContainer = {
94
93
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
95
94
  appLazyContainerList: [],
96
95
  appLazyFinishContainerList: [],
97
96
  },
98
97
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
99
98
  appLazyContainerList: [],
100
99
  appLazyFinishContainerList: [],
101
100
  },
102
101
  }
103
102
  this.renderedIsvComponents = {}
104
103
  this.rootEleNode = document.querySelector('body')
105
104
  this.checkStatusAndLoginPromise = null
106
105
  this.jmfeRegisterStatePromise = null
107
106
  this.loadOtherSdk()
108
107
  isJdApp && this.jmfeReayPromise()
109
108
  }
110
109
  _getConfig(opt) {
111
110
  return Object.assign({}, DefaultConfig, opt)
112
111
  }
113
112
 
114
113
  jmfeReayPromise(): Promise<any> {
115
114
  if (isJdApp) {
116
115
  if (this.jmfeRegisterState) {
117
116
  return Promise.resolve(true)
118
117
  } else {
119
118
  !this.jmfeRegisterStatePromise &&
120
119
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
121
120
  ready('jmfe', 3000)
122
121
  .then(() => {
123
122
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
124
123
  this.jmfeRegisterState = true
125
124
  resolve(true)
126
125
  console.log('松果app内初始化注册jmfe认证完成')
127
126
  })
128
127
  .catch((err) => {
129
128
  console.error('jmfe ready error', err)
130
129
  reject(false)
131
130
  })
132
131
  }))
133
132
  return this.jmfeRegisterStatePromise
134
133
  }
135
134
  } else {
136
135
  return Promise.reject(false)
137
136
  }
138
137
  }
139
138
 
140
139
  updateBusinessDomainAndApi(domain, api) {
141
140
  }
142
141
 
143
142
  formatNativeScreenPageData(action) {
144
143
  let getChangePageInfo: any = null
145
144
  try {
146
145
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
147
146
  JSON.stringify({
148
147
  plugin: 'JDHybridScreenPlugin',
149
148
  action,
150
149
  sync: '1',
151
150
  }),
152
151
  )
153
152
  const getChangePageInfoData =
154
153
  typeof getNativeScreenPageInfoStr === 'string'
155
154
  ? JSON.parse(getNativeScreenPageInfoStr)
156
155
  : null
157
156
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
158
157
  const { code, data } = getChangePageInfoData
159
158
  getChangePageInfo = code && code === '0' ? data : null
160
159
  }
161
160
  } catch (e) {
162
161
  console.log('JDHybridScreenPlugin转换异常', e)
163
162
  }
164
163
  return getChangePageInfo
165
164
  }
166
165
 
167
166
  isAndroidFoldScreen() {
168
167
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
169
168
  }
170
169
 
171
170
  getJdAndroidPageChangeScreenInfo() {
172
171
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
173
172
  if (
174
173
  getPageScreenInfo &&
175
174
  getPageScreenInfo?.pageWidth &&
176
175
  getPageScreenInfo?.pageHeight
177
176
  ) {
178
177
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
179
178
  pageWidth: getPageScreenInfo.pageWidth,
180
179
  pageHeight: getPageScreenInfo.pageHeight,
181
180
  })
182
181
  getPageScreenInfo.pageWidth = pageWidth
183
182
  getPageScreenInfo.pageHeight = pageHeight
184
183
  }
185
184
  return getPageScreenInfo
186
185
  }
187
186
 
188
187
  getSystemInfo(params) {
189
188
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
190
189
  ? {}
191
190
  : getSystemInfos(params)
192
191
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
193
192
  let _isfoldScreen = false
194
193
  const getStorageData = getTaroStorageKeyValue("jd_shopx_androidIsFoldScreen")
195
194
  console.info("获取当前本地存储是否有jd_shopx_androidIsFoldScreen", getStorageData,"通过缓存值第一次判断是否是折叠屏", getStorageData === 'true')
196
195
  if(!getStorageData){
197
196
  _isfoldScreen = this.isAndroidFoldScreen()
198
197
  setTaroStorage("jd_shopx_androidIsFoldScreen", `${_isfoldScreen}`)
199
198
  }else {
200
199
  _isfoldScreen = getStorageData === 'true'
201
200
  }
202
201
  if (_isfoldScreen) {
203
202
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
204
203
  if(getJdAndroidPageInfo){
205
204
  info = getSystemInfos(getJdAndroidPageInfo)
206
205
  console.warn("当前为松果安卓折叠屏app,获取折叠屏信息",getJdAndroidPageInfo,"获取转换后的系统信息",info)
207
206
  sgmCustomReport({
208
207
  type: 2,
209
208
  code: 'android_jdapp_foldScreen_info',
210
209
  msg: {
211
210
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
212
211
  androidPageInfo: getJdAndroidPageInfo,
213
212
  jdAppVersionStr,
214
213
  taroSysInfo: info
215
214
  }
216
215
  })
217
216
  }
218
217
  }
219
218
  }
220
219
  this.info.sysInfo = {
221
220
  actualNavBarHeight: 0,
222
221
  ...this.info.sysInfo,
223
222
  ...info,
224
223
  safeContentHeight: info?.screenHeight,
225
224
  headerHeight: 0,
226
225
  tabBarHeight: 0,
227
226
  }
228
227
  if (isJdApp) {
229
228
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
230
229
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
231
230
  this.getAddressCachePromise()
232
231
  this.getElderModePromise()
233
232
  this.getJDAppearanceStatePromise()
234
233
  this.createJdAndroidRquestEventForTouchStart()
235
234
  }
236
235
  this.getWifiVideoAutoPlayAsync()
237
236
  this.getMPaasConfigAsync()
238
237
  this.getNetWorkType()
239
238
  }
240
239
 
241
240
  taskTimeoutPromise(callBack, timeout = 2000) {
242
241
  return new Promise(resolve => {
243
242
  setTimeout(() => {
244
243
  const getCallBackRes = typeof callBack === 'function' && callBack()
245
244
  return resolve(getCallBackRes || false)
246
245
  }, timeout)
247
246
  })
248
247
  }
249
248
 
250
249
  getElderModePromise() {
251
250
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
252
251
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
253
252
  } else {
254
253
  if (isJdAndAndroidDevice) {
255
254
  this.info.sysInfo.jdAppModeType = '0'
256
255
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
257
256
  } else {
258
257
  return Promise.race([
259
258
  this.taskTimeoutPromise(() => {
260
259
  this.info.sysInfo.jdAppModeType = '0'
261
260
  return this.info.sysInfo.jdAppModeType
262
261
  }),
263
262
  new Promise(resolve => {
264
263
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
265
264
  if (!window[getCallBackName]) {
266
265
  window[getCallBackName] = res => {
267
266
  try {
268
267
  const getResJson =
269
268
  typeof res === 'string' ? JSON.parse(res) : res
270
269
  const { status, data, msg } = getResJson
271
270
  console.log(`获取松果app展示模式成功,返回结果${data}`)
272
271
  if (status === '0') {
273
272
  this.info.sysInfo.jdAppModeType = data
274
273
  resolve(data)
275
274
  } else {
276
275
  resolve('0')
277
276
  }
278
277
  } catch (e) {
279
278
  resolve('0')
280
279
  }
281
280
  window[getCallBackName] = null
282
281
  }
283
282
  }
284
283
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
285
284
  method: 'callSyncRouterModuleWithParams',
286
285
  params: JSON.stringify({
287
286
  routerURL: 'router://JDBModeModule/getCurrentMode',
288
287
  routerParam: {},
289
288
  callBackName: `window.${getCallBackName}`,
290
289
  callBackId: `${getCallBackName}Ios`,
291
290
  }),
292
291
  })
293
292
  }),
294
293
  ])
295
294
  }
296
295
  }
297
296
  }
298
297
  getAPPUseStraightCorner() {
299
298
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable'
300
299
  const params = {
301
300
  routerURL,
302
301
  routerParam: {},
303
302
  jdRouter: '1',
304
303
  }
305
304
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
306
305
  return Promise.resolve(this.info.sysInfo.jdStraightCorner)
307
306
  } else {
308
307
  return this.jmfeReayPromise()
309
308
  .then(() => {
310
309
  if(isJdAndHarmonyDevice || !isJdApp) {
311
310
  console.log('not APP or is Harmony')
312
311
  return Promise.resolve(false)
313
312
  }
314
313
  console.log('jmfe setShareInfo', params)
315
314
  return Promise.race([window.jmfe.callRouter(params), this.taskTimeoutPromise(() => {return false})])
316
315
  .then(({ status, data }) => {
317
316
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data)
318
317
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status)
319
318
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1
320
319
  return Promise.resolve( status === '0' && Number(data) === 1)
321
320
  })
322
321
  })
323
322
  .catch(e => {
324
323
  console.log('jmfe error', e)
325
324
  return Promise.resolve(false)
326
325
  })
327
326
  }
328
327
  }
329
328
 
330
329
  getJDAppearanceStatePromise() {
331
330
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
332
331
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
333
332
  } else {
334
333
  return Promise.race([
335
334
  this.taskTimeoutPromise(() => {
336
335
  this.info.sysInfo.jdAppearanceState = '0'
337
336
  return this.info.sysInfo.jdAppearanceState
338
337
  }),
339
338
  new Promise(resolve => {
340
339
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
341
340
  if (!window[getCallBackName]) {
342
341
  window[getCallBackName] = res => {
343
342
  try {
344
343
  console.log('getJDAppearanceStatePromise', res)
345
344
  const getResJson =
346
345
  typeof res === 'string' ? JSON.parse(res) : res
347
346
  const { status, data, msg } = getResJson
348
347
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
349
348
  if (status === '0') {
350
349
  this.info.sysInfo.jdAppearanceState = data
351
350
  resolve(data)
352
351
  } else {
353
352
  resolve('0')
354
353
  }
355
354
  } catch (e) {
356
355
  resolve('0')
357
356
  }
358
357
  window[getCallBackName] = null
359
358
  }
360
359
  }
361
360
  if (isAndroidDevice) {
362
361
  const jsonString = JSON.stringify({
363
362
  callBackName: `window.${getCallBackName}`,
364
363
  })
365
364
  console.log('window.JDAppearance', window.JDAppearance)
366
365
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
367
366
  } else {
368
367
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
369
368
  method: 'callSyncRouterModuleWithParams',
370
369
  params: JSON.stringify({
371
370
  routerURL:
372
371
  'router://JDWebViewBusinessModule/getJDAppearanceState',
373
372
  routerParam: {},
374
373
  callBackName: `window.${getCallBackName}`,
375
374
  callBackId: `${getCallBackName}Ios`,
376
375
  }),
377
376
  })
378
377
  }
379
378
  }),
380
379
  ])
381
380
  }
382
381
  }
383
382
 
384
383
  createJdAndroidRquestEventForTouchStart() {
385
384
  if (isJdAndAndroidDevice && window.JdAndroid) {
386
385
  const rootEleNode = document.querySelector('body')
387
386
  if (rootEleNode) {
388
387
  rootEleNode.addEventListener(
389
388
  'touchstart',
390
389
  this.jdAndroidAddEventListenerTouchStart,
391
390
  false,
392
391
  )
393
392
  }
394
393
  }
395
394
  }
396
395
  jdAndroidAddEventListenerTouchStart(e) {
397
396
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
398
397
  if (!isH5SwiperCustomEle) {
399
398
  const hasCustomEle = e
400
399
  ? e?.target?.closest('.J_customScroll') ||
401
400
  e?.target?.closest('.J_customLayout')
402
401
  : false
403
402
  if (!hasCustomEle) {
404
403
  window.JdAndroid.requestEvent(false)
405
404
  console.log(
406
405
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
407
406
  )
408
407
  }
409
408
  }
410
409
  }
411
410
  removeJdAndroidRquestEventForTouchStart() {
412
411
  if (isJdAndAndroidDevice && window.JdAndroid) {
413
412
  const rootEleNode = document.querySelector('body')
414
413
  if (rootEleNode) {
415
414
  rootEleNode.removeEventListener(
416
415
  'touchstart',
417
416
  this.jdAndroidAddEventListenerTouchStart,
418
417
  false,
419
418
  )
420
419
  }
421
420
  }
422
421
  }
423
422
 
424
423
  getNetWorkType() {
425
424
  if (isJdApp) {
426
425
  this.jmfeReayPromise().then(() => {
427
426
  window.jmfe
428
427
  .getNetworkStatus()
429
428
  .then(({ status, data }) => {
430
429
  console.log(
431
430
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
432
431
  data,
433
432
  )
434
433
  if (status === '0') {
435
434
  this.info.sysInfo['netWorkType'] = data
436
435
  } else {
437
436
  this._taroGetNetworkType()
438
437
  }
439
438
  })
440
439
  .catch(err => {
441
440
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
442
441
  this._taroGetNetworkType()
443
442
  })
444
443
  })
445
444
  } else {
446
445
  this._taroGetNetworkType()
447
446
  }
448
447
  }
449
448
  _taroGetNetworkType() {
450
449
  Taro.getNetworkType().then(getRes => {
451
450
  if (getRes && getRes.networkType) {
452
451
  this.info.sysInfo['netWorkType'] = getRes.networkType
453
452
  console.log(
454
453
  '在app内通过taro对象获取网络状态完成,当前网络状态',
455
454
  this.info.sysInfo['netWorkType'],
456
455
  )
457
456
  }
458
457
  })
459
458
  }
460
459
  getCacheAddressRouter() {
461
460
  if (!window.jmfe) return
462
461
  if (isAndroidDevice) {
463
462
  return window.jmfe.callRouter({
464
463
  jdRouter: '1',
465
464
  routerURL: 'router://JDAddressModule/getCacheAddress',
466
465
  routerParam: { sceneId: 'basicShoppingProcess' },
467
466
  })
468
467
  } else if (isIosDevice) {
469
468
  return window.jmfe.callRouter({
470
469
  jdRouter: '1',
471
470
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
472
471
  routerParam: { sceneId: 'basicShoppingProcess' },
473
472
  })
474
473
  } else if (isJdAndHarmonyDevice) {
475
474
  return new Promise(resolve => {
476
475
  resolve({})
477
476
  })
478
477
  } else {
479
478
  throw Error(
480
479
  'Unknown device type cannot obtain the address information through the route!',
481
480
  )
482
481
  }
483
482
  }
484
483
 
485
484
  getAddressCachePromise() {
486
485
  return new Promise(resolve => {
487
486
  if (
488
487
  this?.info?.sysInfo?.lat &&
489
488
  this?.info?.sysInfo?.lng &&
490
489
  this?.info?.sysInfo?.area
491
490
  ) {
492
491
  resolve({
493
492
  lat: this.info.sysInfo.lat,
494
493
  lng: this.info.sysInfo.lng,
495
494
  area: this?.info?.sysInfo?.area,
496
495
  })
497
496
  } else {
498
497
  this.jmfeReayPromise().then(() => {
499
498
  this.getCacheAddressRouter()
500
499
  .then(({ status, data }) => {
501
500
  console.log("原生端获取经纬度原始数据结果",status,data)
502
501
  if (status === '0' && data) {
503
502
  const {
504
503
  lat,
505
504
  latitude,
506
505
  lng,
507
506
  longitude,
508
507
  provinceId,
509
508
  cityId,
510
509
  countyId,
511
510
  townId,
512
511
  } = data || {}
513
512
  let area = ''
514
513
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
515
514
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
516
515
  if (provinceId) {
517
516
  area = `${provinceId}_${cityId || 0}_${countyId ||
518
517
  0}_${townId || 0}`
519
518
  this.info.pageInfo['address'] = area
520
519
  this.info.pageInfo['addressCommaStr'] = area.replace(
521
520
  /_/g,
522
521
  ',',
523
522
  )
524
523
  }
525
524
  resolve({
526
525
  lat: this.info.sysInfo['lat'],
527
526
  lng: this.info.sysInfo['lng'],
528
527
  area: area,
529
528
  })
530
529
  } else {
531
530
  resolve({ lat: '', lng: '', area: '' })
532
531
  }
533
532
  })
534
533
  .catch(e => {
535
534
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
536
535
  resolve({ lat: '', lng: '', area: '' })
537
536
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e)
538
537
  })
539
538
  }).catch(e => {
540
539
  resolve({ lat: '', lng: '', area: '' })
541
540
  console.log('判断jmfe不存在,获取经纬度信息异常e', e)
542
541
  })
543
542
  }
544
543
  })
545
544
  }
546
545
 
547
546
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
548
547
  console.log("updateMPaasConfigAsync isBeforePageReady:", isBeforePageReady)
549
548
  if (!isJdApp) {
550
549
  return
551
550
  }
552
551
  const avifSwitch = await getMPaasConfigByBussinessKey(
553
552
  'avifSwitch',
554
553
  isBeforePageReady,
555
554
  )
556
555
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
557
556
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
558
557
  'hybridHttpSwitch',
559
558
  isBeforePageReady,
560
559
  )
561
560
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch
562
561
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
563
562
  'isFollowAppVideoPlayStatus',
564
563
  isBeforePageReady,
565
564
  )
566
565
  console.log(
567
566
  'isBeforePageReady:',
568
567
  isBeforePageReady,
569
568
  'isFollowAppVideoPlayStatus:',
570
569
  isFollowAppVideoPlayStatus,
571
570
  )
572
571
  if (
573
572
  isFollowAppVideoPlayStatus === true ||
574
573
  isFollowAppVideoPlayStatus === 'true'
575
574
  ) {
576
575
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
577
576
  }
578
577
  }
579
578
 
580
579
  async getWifiVideoAutoPlayAsync() {
581
580
  this.info.sysInfo['wifiVideoAutoPlay'] = false
582
581
  if (!isJdApp) {
583
582
  return
584
583
  }
585
584
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
586
585
  return 0
587
586
  })
588
587
  if (Number(videoPlayStatus) === 1) {
589
588
  this.info.sysInfo['wifiVideoAutoPlay'] = true
590
589
  }
591
590
  }
592
591
 
593
592
  async getMPaasConfigAsync() {
594
593
  this.info.sysInfo.dynamicConfig = {}
595
594
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
596
595
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {}
597
596
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
598
597
  return this.updateMPaasConfigAsync(true)
599
598
  }
600
599
 
601
600
  getDynamicConfig(key: string){
602
601
  return this.info.sysInfo.dynamicConfig[key]
603
602
  }
604
603
  async updateMPaasConfig() {
605
604
  console.log('updateMPaasConfig')
606
605
  if (
607
606
  isIosDevice &&
608
607
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
609
608
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
610
609
  ) {
611
610
  try {
612
611
  await this.updateMPaasConfigAsync(false)
613
612
  } catch (e) {
614
613
  console.log('updateMPaasConfigAsync:', e)
615
614
  }
616
615
  }
617
616
  }
618
617
 
619
618
  toLogin(options) {
620
619
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
621
620
  ? this.toWxAppLogin(options)
622
621
  : this.toWebLogin(options)
623
622
  }
624
623
 
625
624
  doLogin(options) {
626
625
  return this.toLogin(options)
627
626
  }
628
627
 
629
628
  doLoginForJdPin(options = {}) {
630
629
  return this.doLogin({
631
630
  loginColor: {
632
631
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
633
632
  dpin: 0,
634
633
  },
635
634
  ...options,
636
635
  })
637
636
  }
638
637
 
639
638
  toWebLogin(options) {
640
639
  let params: {
641
640
  returnurl: string
642
641
  } = {
643
642
  returnurl: '',
644
643
  }
645
644
  const loginUrl = isPc
646
645
  ? `//passport.jd.com/new/login.aspx`
647
646
  : `${domain.mobileLogin}/user/login.action`
648
647
  const defaultParams = {
649
648
  appid: '100',
650
649
  returnurl: window.location.href,
651
650
  }
652
651
  if (isString(options)) {
653
652
  params = Object.assign({}, defaultParams, {
654
653
  returnurl: options,
655
654
  })
656
655
  } else if (isObject(options)) {
657
656
  const { loginColor, ...otherOptions } = options
658
657
  params = Object.assign({}, defaultParams, otherOptions)
659
658
  } else {
660
659
  params = defaultParams
661
660
  }
662
661
  params.returnurl = encodeURIComponent(params.returnurl)
663
662
  let getFullUrl = loginUrl + '?' + serialize(params)
664
663
  if (isPc) {
665
664
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
666
665
  }
667
666
  return Promise.resolve({
668
667
  h5ToUrl: true,
669
668
  url: getFullUrl,
670
669
  }).then(() => {
671
670
  window.location.href = getFullUrl
672
671
  })
673
672
  }
674
673
 
675
674
  toWxAppLogin(options = {}) {
676
675
  console.log('微信京购小程序中h5登录跳转', options)
677
676
  return Promise.resolve(true).then(() => {
678
677
  const { loginColor } = Object.assign(
679
678
  {},
680
679
  {
681
680
  loginColor: {
682
681
  biz: WXAPP_BIZ_KEY,
683
682
  dpin: 1,
684
683
  },
685
684
  },
686
685
  options,
687
686
  )
688
687
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
689
688
  loginColor.biz
690
689
  }&url=${encodeURIComponent(window.location.href)}`
691
690
  })
692
691
  }
693
692
 
694
693
  getLoginCookie() {
695
694
  return Promise.resolve({
696
695
  pin: cookie.get('pin') || '',
697
696
  })
698
697
  }
699
698
 
700
699
  clearLoginCookie() {
701
700
  cookie.remove('pin')
702
701
  }
703
702
 
704
703
  checkStatusAndLogin(options = {}) {
705
704
  if (!this.checkStatusAndLoginPromise) {
706
705
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
707
706
  try {
708
707
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
709
708
  options,
710
709
  )
711
710
  if (getLoginState) {
712
711
  resolve(true)
713
712
  } else {
714
713
  this.toLogin(options)
715
714
  reject(false)
716
715
  }
717
716
  } catch (e) {
718
717
  this.toLogin(options)
719
718
  reject(false)
720
719
  }
721
720
  })
722
721
  return this.checkStatusAndLoginPromise
723
722
  } else {
724
723
  return this.checkStatusAndLoginPromise
725
724
  .then(() => {
726
725
  return Promise.resolve(true)
727
726
  })
728
727
  .catch(() => {
729
728
  this.toLogin(options)
730
729
  return Promise.reject(true)
731
730
  })
732
731
  }
733
732
  }
734
733
 
735
734
  checkJdStatusAndLogin(
736
735
  options = {
737
736
  loginColor: {
738
737
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
739
738
  dpin: 0,
740
739
  },
741
740
  },
742
741
  ) {
743
742
  return this.checkStatusAndLogin(options)
744
743
  }
745
744
 
746
745
  doCheckLoginStateAndForApiCheck(options) {
747
746
  if (this.info.loginState) {
748
747
  return Promise.resolve(true)
749
748
  } else {
750
749
  return new Promise((resolve, reject) => {
751
750
  if (
752
751
  this.info.isJingGouMiniViewState ||
753
752
  this.info.isJingxiMiniViewState
754
753
  ) {
755
754
  const getWqAuthToken = cookie.get('wq_auth_token')
756
755
  const getWqSkey = cookie.get('wq_skey')
757
756
  const getWqUin = cookie.get('wq_uin')
758
757
  const isLoginState =
759
758
  options?.loginColor?.dpin === 0
760
759
  ? getWqAuthToken
761
760
  : getWqSkey && getWqUin
762
761
  if (isLoginState) {
763
762
  this.info.loginState = true
764
763
  resolve(true)
765
764
  } else {
766
765
  reject(false)
767
766
  }
768
767
  } else {
769
768
  Taro.request({
770
769
  url: api.isLogin,
771
770
  jsonp: true,
772
771
  timeout: 3000,
773
772
  success: res => {
774
773
  const { statusCode, data } = res
775
774
  if (
776
775
  statusCode === 200 &&
777
776
  data?.islogin &&
778
777
  Number(data.islogin) === 1
779
778
  ) {
780
779
  this.info.loginState = true
781
780
  resolve(true)
782
781
  } else {
783
782
  reject(false)
784
783
  }
785
784
  },
786
785
  fail: err => {
787
786
  console.log('登录检查异常', err)
788
787
  reject(false)
789
788
  },
790
789
  })
791
790
  }
792
791
  })
793
792
  }
794
793
  }
795
794
 
796
795
  checkLoginStatus(options) {
797
796
  return new Promise(async (resolve, reject) => {
798
797
  try {
799
798
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
800
799
  options,
801
800
  )
802
801
  if (getLoginState) {
803
802
  const { pin } = await this.getLoginCookie()
804
803
  this.info.userInfo = {
805
804
  pin,
806
805
  encodePin: encodeURIComponent(pin),
807
806
  ptkey: '',
808
807
  }
809
808
  resolve(true)
810
809
  } else {
811
810
  reject(false)
812
811
  }
813
812
  } catch (e) {
814
813
  reject(false)
815
814
  }
816
815
  })
817
816
  }
818
817
 
819
818
  updatePageAndLogInfo(updateQuery = {}) {
820
819
  const createUpdateQueryInfo: {
821
820
  query: {
822
821
  shopId?: string | number
823
822
  venderId?: string | number
824
823
  }
825
824
  updateShopInfoState: boolean
826
825
  } = Object.assign(
827
826
  {},
828
827
  {
829
828
  query: {},
830
829
  updateShopInfoState: false,
831
830
  },
832
831
  updateQuery,
833
832
  )
834
833
  console.log(
835
834
  '获取当前下发的店铺查询参数',
836
835
  updateQuery,
837
836
  '获取之前保存的shopInfo店铺查询参数',
838
837
  this.info?.shopInfo,
839
838
  )
840
839
  const { query, updateShopInfoState } = createUpdateQueryInfo
841
840
  const { shopId, venderId, un_area } = query
842
841
  if (updateShopInfoState) {
843
842
  this.info.queryInfo = {
844
843
  ...this.info.queryInfo,
845
844
  ...query,
846
845
  }
847
846
  if (shopId && venderId) {
848
847
  this.info.shopInfo = {
849
848
  shopId: `${shopId}`,
850
849
  venderId: `${venderId}`,
851
850
  }
852
851
  }
853
852
  } else {
854
853
  this.info.queryInfo = {
855
854
  ...query,
856
855
  }
857
856
  if (
858
857
  this.info.shopInfo?.shopId &&
859
858
  this.info.shopInfo?.venderId &&
860
859
  (this.info.shopInfo.shopId == shopId ||
861
860
  this.info.shopInfo.venderId == venderId)
862
861
  ) {
863
862
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
864
863
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
865
864
  console.log(
866
865
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
867
866
  this.info.queryInfo,
868
867
  )
869
868
  }
870
869
  }
871
870
  this.info.queryInfo['shopId'] &&
872
871
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
873
872
  this.info.queryInfo['venderId'] &&
874
873
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
875
874
  console.log(
876
875
  'h5==获取店铺下发查询参数\n',
877
876
  query,
878
877
  '\n获取店铺最后查询参数\n',
879
878
  this.info.queryInfo,
880
879
  '\n是否为更新店铺状态\n',
881
880
  updateShopInfoState,
882
881
  )
883
882
  const changeArea =
884
883
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
885
884
  if (changeArea) {
886
885
  this.info.pageInfo.address = changeArea
887
886
  this.info.pageInfo.un_area = changeArea
888
887
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
889
888
  }
890
889
  }
891
890
 
892
891
  dealLoadSdkList(){
893
892
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
894
893
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? []
895
894
  const concatLoadJsList = [].concat(globalLoadJsList,businessLoadJsList)
896
895
  let mergeLoadJsList = globalLoadJsList
897
896
  try {
898
897
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
899
898
  const getFindIndex = accArr.findIndex(item => item?.fileName === current?.fileName);
900
899
  getFindIndex !== -1 ? (accArr[getFindIndex] = {...accArr[getFindIndex],...current }) : accArr.push(current);
901
900
  return accArr;
902
901
  }, []);
903
902
  }catch (e) {
904
903
  console.log("LoadJsList合并错误", e)
905
904
  }
906
905
  console.log("globalLoadJsList",globalLoadJsList,"businessLoadJsList",businessLoadJsList,"两个加载jsList集合合并完成", mergeLoadJsList)
907
906
  this.loadJsSdkList = mergeLoadJsList
908
907
  return this.loadJsSdkList
909
908
  }
910
909
 
911
910
  renderNextTickLoadSdk(){
912
911
  Taro.nextTick(() => {
913
912
  console.log("页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======")
914
913
  setTimeout(() => {
915
914
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK,this.loadJsSdkList)
916
915
  },1000)
917
916
  })
918
917
  }
919
918
 
920
919
  loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW,loadJsList:any[] = [] ) {
921
920
  const getLoadJsList = Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList()
922
921
  const getLoadFilterList = getLoadJsList.filter(item => {
923
922
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL
924
923
  let getLoastLoadEventState = true
925
924
  if(getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP){
926
925
  getLoastLoadEventState = isJdApp
927
926
  }
928
927
  else if(getInitLoadEnvType === LoadJsInitLoadEnvType.M){
929
928
  getLoastLoadEventState = !isJdApp
930
929
  }
931
930
  const getInitTriggerType = isJdApp && item?.initJdAppTriggerType ? item?.initTriggerType : item?.initTriggerType || LoadJsInitTriggerType.NOW
932
931
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false
933
932
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay
934
933
  })
935
934
  console.log("获取当前触发方式",triggerType,"获取当前最后加载的js集合",getLoadFilterList,"过滤前的加载集合",getLoadJsList)
936
935
  getLoadFilterList.length > 0 && getLoadFilterList.forEach((item) => {
937
936
  const isLoadState = /sgm/.test(item?.fileName) ? window?.shopGlobalSwitch?.openSgm === "true" : true
938
937
  isLoadState && this.loadItemSdkPromise(item)
939
938
  .then((res) => {
940
939
  console.info('当前js地址' + item?.src, '加载状态', res)
941
940
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs'
942
941
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
943
942
  window.dra.run('init', { aid: res?.aid })
944
943
  window.dra.run('start')
945
944
  }
946
945
  })
947
946
  .catch((err) => {
948
947
  console.info('当前js地址加载异常', item?.src)
949
948
  window?.fetchErrorData &&
950
949
  window.fetchErrorData({
951
950
  title: '公共js加载异常',
952
951
  type: "jsLoad",
953
952
  data: err,
954
953
  })
955
954
  })
956
955
  })
957
956
  }
958
957
  loadScriptEle(jsInfo,resolve,reject){
959
958
  const getFileName = jsInfo?.fileName;
960
959
  if(getFileName){
961
960
  const getEleId = `J_loadJs_${getFileName}`
962
961
  const getEle = document.getElementById(getEleId)
963
962
  if (!getEle) {
964
963
  const jsLoadErrorSgmCode = `jsLoadError_${
965
964
  jsInfo?.fileName || 'customJs'
966
965
  }`
967
966
  const _sgmEle = document.createElement('script')
968
967
  _sgmEle.id = getEleId
969
968
  _sgmEle.onload = function () {
970
969
  resolve({
971
970
  ...jsInfo,
972
971
  jsTip: "js加载成功",
973
972
  })
974
973
  }
975
974
  _sgmEle.onerror = function () {
976
975
  reject({
977
976
  ...jsInfo,
978
977
  env: getSgmCustomCode(jsLoadErrorSgmCode),
979
978
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
980
979
  })
981
980
  }
982
981
  const dataAttrList = ['timeout','fileName',"env"]
983
982
  const getJsInfoKeyList = Object.keys(jsInfo)
984
983
  getJsInfoKeyList.forEach(key => {
985
984
  if(key === "async"){
986
985
  _sgmEle.async = jsInfo[key]
987
986
  }else if(key === "crossOrigin"){
988
987
  _sgmEle.crossOrigin = jsInfo[key]
989
988
  }else if(key === "src"){
990
989
  _sgmEle.src = `${jsInfo[key]}`
991
990
  }else if(dataAttrList.includes(key) || /init/.test(key)) {
992
991
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key])
993
992
  }else {
994
993
  _sgmEle.setAttribute(key, jsInfo[key])
995
994
  }
996
995
  })
997
996
  document.head.appendChild(_sgmEle)
998
997
  }else {
999
998
  console.log(`当前${jsInfo?.fileName || "js"}已经存在页面中,可以直接调用相关方法`,jsInfo)
1000
999
  resolve({
1001
1000
  ...jsInfo,
1002
1001
  jsTip: "js本身已存在页面中",
1003
1002
  })
1004
1003
  }
1005
1004
  }else {
1006
1005
  console.warn("当前js资源信息缺少必要的参数fileName,请关注",jsInfo)
1007
1006
  }
1008
1007
  }
1009
1008
 
1010
1009
  loadItemSdkPromise(jsInfo = {}){
1011
1010
  if(jsInfo?.src){
1012
1011
  const getInitLoadType = isJdApp && jsInfo?.initJdAppLoadType ? jsInfo?.initJdAppLoadType : jsInfo?.initLoadType || LoadJsInitLoadType.ALL
1013
1012
  if(getInitLoadType !== LoadJsInitLoadType.NONE){
1014
1013
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src
1015
1014
  if (!this.loadJsSdkListCachePromise[getFileKeyName]){
1016
1015
  if(getInitLoadType !== LoadJsInitLoadType.INSERT_ELE){
1017
1016
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
1018
1017
  const jsLoadErrorSgmCode = `jsLoadError_${
1019
1018
  jsInfo?.fileName || 'customJs'
1020
1019
  }`
1021
1020
  try {
1022
1021
  const jsXhrRequest = new XMLHttpRequest();
1023
1022
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000
1024
1023
  const jsUrl = `${jsInfo?.src}`
1025
1024
  jsXhrRequest.open('GET', jsUrl, true);
1026
1025
  jsXhrRequest.onreadystatechange = () => {
1027
1026
  if (jsXhrRequest.readyState === 4){
1028
1027
  const getReqStatus = jsXhrRequest.status
1029
1028
  if (getReqStatus >= 200 && getReqStatus < 300 || getReqStatus === 304){
1030
1029
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL
1031
1030
  if(getInsetHeadState){
1032
1031
  this.loadScriptEle(jsInfo,resolve,reject)
1033
1032
  }else {
1034
1033
  resolve({
1035
1034
  ...jsInfo,
1036
1035
  jsTip: "js请求成功,暂未插入head节点,业务自行单独插入",
1037
1036
  })
1038
1037
  }
1039
1038
  getReqStatus !== 200 && sgmCustomReport({
1040
1039
  type: 3,
1041
1040
  code: "js_load_special_code",
1042
1041
  msg: {
1043
1042
  msg: "当前js加载成功,状态非200,特殊上报观察",
1044
1043
  jsReqState: getReqStatus,
1045
1044
  env: getSgmCustomCode("js_load_special_code"),
1046
1045
  data: jsInfo
1047
1046
  }
1048
1047
  })
1049
1048
  }else {
1050
1049
  const getRes = {
1051
1050
  ...jsInfo,
1052
1051
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1053
1052
  jsReqError: `请求状态异常,状态码为${getReqStatus}`,
1054
1053
  jsReqState: getReqStatus,
1055
1054
  }
1056
1055
  console.log("当前js请求状态异常,具体信息见", getRes)
1057
1056
  reject(getRes)
1058
1057
  }
1059
1058
  }
1060
1059
  };
1061
1060
  jsXhrRequest.onerror = () => {
1062
1061
  const getRes = {
1063
1062
  ...jsInfo,
1064
1063
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1065
1064
  jsReqError: '请求错误',
1066
1065
  }
1067
1066
  console.log("当前js请求错误", getRes)
1068
1067
  jsXhrRequest.abort()
1069
1068
  reject(getRes)
1070
1069
  }
1071
1070
  jsXhrRequest.ontimeout = () => {
1072
1071
  const getRes = {
1073
1072
  ...jsInfo,
1074
1073
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1075
1074
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
1076
1075
  jsReqState: jsXhrRequest.status,
1077
1076
  }
1078
1077
  console.log("当前js请求超时异常", getRes)
1079
1078
  jsXhrRequest.abort()
1080
1079
  reject(getRes)
1081
1080
  }
1082
1081
  jsXhrRequest.send();
1083
1082
  }catch (e) {
1084
1083
  console.log("执行js请求异常",e)
1085
1084
  reject({
1086
1085
  ...jsInfo,
1087
1086
  env: getSgmCustomCode(jsLoadErrorSgmCode),
1088
1087
  jsReqError: '未知异常',
1089
1088
  error: e,
1090
1089
  })
1091
1090
  }
1092
1091
  })
1093
1092
  }else {
1094
1093
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve,reject) => {
1095
1094
  return this.loadScriptEle(jsInfo,resolve,reject)
1096
1095
  })
1097
1096
  }
1098
1097
  }
1099
1098
  return this.loadJsSdkListCachePromise[getFileKeyName]
1100
1099
  }else {
1101
1100
  return Promise.resolve({
1102
1101
  ...jsInfo,
1103
1102
  jsTip: "js加载方式设置为不加载,当前不做处理",
1104
1103
  })
1105
1104
  }
1106
1105
  }else {
1107
1106
  return Promise.reject(jsInfo)
1108
1107
  }
1109
1108
  }
1109
+ import Taro from '@tarojs/taro';
1110
1110
  BUSINESS_TYPE,
1111
1111
  cacheAppKey,
1112
1112
  cacheAppUuidKey,
1113
1113
  cacheH5LbsAddressKey,
1114
1114
  JSSDK_APP_WEBVIEW_CODE,
1115
1115
  LoadJsInitLoadEnvType,
1116
1116
  LoadJsInitLoadType,
1117
1117
  LoadJsInitTriggerType,
1118
1118
  MPAAS_CONFIG_APP_LOW_VERSION,
1119
1119
  MPAAS_CONFIG_APP_VERSION,
1120
1120
  SECTION_HOME_TAB_NAME_TYPE,
1121
1121
  SECTION_HOME_TAB_TYPE,
1122
1122
  TaroEventType,
1123
1123
  WX_BUSINESS_TYPE,
1124
1124
  WXAPP_BIZ_KEY,
1125
1125
  WXAPP_BIZ_SHOP_LIGHT_KEY,
1126
1126
  languageTypeList,
1127
1127
  getSystemInfos,
1128
1128
  getTaroStorageKeyValue,
1129
1129
  ipLoc_djd,
1130
1130
  setTaroStorage,
1131
1131
  isInJdAppH5DebugMode,
1132
1132
  callRouterAndroid,
1133
1133
  callRouterIOS,
1134
1134
  getMPaasConfigByBussinessKey,
1135
1135
  dealNativePixelToCssPixel,
1136
1136
  draBusinessCustomReport,
1137
1137
  isAndroidDevice,
1138
1138
  isH5AndJingGouMini,
1139
1139
  isIosDevice,
1140
1140
  isJdAndAndroidDevice,
1141
1141
  isObject,
1142
1142
  isPc,
1143
1143
  isString,
1144
1144
  jdAppVersion,
1145
1145
  jdAppVersionStr,
1146
1146
  serialize,
1147
1147
  languageNowType,
1148
1148
  urlCookie,
1149
1149
  isAscfApp,
1150
1150
  jdAppVersionCompare,
1151
1151
  parseQueryUrlObj,
1152
1152
  abTestLabels: {},
1153
1153
  nonSellableSkuids: {},
1154
1154
  loginState: false,
1155
1155
  cookiesStr: '',
1156
1156
  userInfo: userPinKey,
1157
1157
  isImmersive:
1158
1158
  !window?.shopGlobalSwitch?.disableImmersive &&
1159
1159
  isJdApp &&
1160
1160
  window.location?.search.includes('immersive=1'),
1161
1161
  isJingGouMiniViewState: false,
1162
1162
  isJingxiMiniViewState: false,
1163
1163
  baseAddCartSwitch: true,
1164
1164
  pageInfo: {
1165
1165
  wxBusinessType: WX_BUSINESS_TYPE.NO,
1166
1166
  address: '',
1167
1167
  addressCommaStr: '',
1168
1168
  fullAddress: '',
1169
1169
  un_area: '',
1170
1170
  userLbsAddress: '',
1171
1171
  vapptype: '1',
1172
1172
  pageType: 'home',
1173
1173
  isExposureState: false,
1174
1174
  moduleId: '',
1175
1175
  entrance: '',
1176
1176
  dataType: BUSINESS_TYPE.ONLINE,
1177
1177
  floorExposureInfo: {},
1178
1178
  floorVideInfo: {},
1179
1179
  productVideInfo: {},
1180
1180
  tabsLoadAllDataInfo: {
1181
1181
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
1182
1182
  },
1183
1183
  updateShopInfosAllState: false,
1184
1184
  isVipShop: false,
1185
1185
  isJdShowNativeImmersivePlayer: false,
1186
1186
  isSuperBrandShop: false,
1187
1187
  ...shopConfig,
1188
1188
  pageScrollTop: 0,
1189
1189
  pageIdxHeightInfo: {
1190
1190
  list: [],
1191
1191
  },
1192
1192
  shopNavBarHeight: 0,
1193
1193
  },
1194
1194
  defaultQueryLogInfo: {
1195
1195
  sourceType: 'JDshop',
1196
1196
  sourceValue: '',
1197
1197
  moduleId: 'none',
1198
1198
  entrance: 'none',
1199
1199
  },
1200
1200
  sysInfo: {
1201
1201
  windowWidth: isPc ? 375 : 0,
1202
1202
  containerWidth: isPc ? 375 : 0,
1203
1203
  windowHeight: 0,
1204
1204
  netWorkType: '4g',
1205
1205
  jdBottomBarHeight: 0,
1206
1206
  jdNativeHeaderHeight: 0,
1207
1207
  isJdTabletDevice: false,
1208
1208
  isJdTabletLandscape: false,
1209
1209
  },
1210
1210
  queryInfo: {},
1211
1211
  shopInfo: {},
1212
1212
  openAppData: {},
1213
1213
  public info: CommonInterFace.BaseConfigInfo;
1214
1214
  public config: {
1215
1215
  [key: string]: any;
1216
1216
  };
1217
1217
  public lazyContainer: CommonInterFace.lazyContainer;
1218
1218
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
1219
1219
  public rootEleNode: HTMLElement | null;
1220
1220
  public checkStatusAndLoginPromise: object | null;
1221
1221
  private jmfeRegisterStatePromise: Promise<any> | null;
1222
1222
  private jdScreenSizeInfoPromise: Promise<any> | null;
1223
1223
  private rootEleWidthRegisterPromise: Promise<any> | null;
1224
1224
  private loadJsH5tagStatePromise: Promise<any> | null;
1225
1225
  private loadJsApiRequestStatePromise: Promise<any> | null;
1226
1226
  private jmfeRegisterState: boolean;
1227
1227
  public loadJsSdkList: {
1228
1228
  src: string;
1229
1229
  timeout: number;
1230
1230
  fileName: string;
1231
1231
  initTriggerType: typeof LoadJsInitTriggerType;
1232
1232
  initLinkTriggerWay:
1233
1233
  | 'asyncLoadAppSdkJs'
1234
1234
  | 'asyncLoadHandlerJs'
1235
1235
  | 'asyncLoadReportJs'
1236
1236
  | 'asyncLoadMtkJs'
1237
1237
  | 'asyncLoadSecurityJs'
1238
1238
  | 'asyncLoadSgmJs'
1239
1239
  | 'asyncLoadCartJs'
1240
1240
  | 'asyncLoadNewDraSdkJs'
1241
1241
  | 'asyncLoadH5TagJs';
1242
1242
  initLoadEnvType: typeof LoadJsInitLoadEnvType;
1243
1243
  defer?: 'true';
1244
1244
  async?: 'true';
1245
1245
  crossOrigin: 'anonymous' | '';
1246
1246
  }[];
1247
1247
  public loadJsSdkListCachePromise: any;
1248
1248
  public rootEleInitWidth: number;
1249
1249
  public lbsAddressCachePromise: Promise<any> | null;
1250
1250
  public languageCacheProimse: Promise<any> | null;
1251
1251
  public languageJsonData: any | null;
1252
1252
  public businessWorkerReady: boolean;
1253
1253
  public businessWorkerReadyPromise: Promise<any> | null;
1254
1254
  public workerPreRequestData = new Map<string, any>();
1255
1255
  constructor(opt) {
1256
1256
  this.info = this._getConfig(opt);
1257
1257
  this.config = {};
1258
1258
  this.loadJsSdkList = [];
1259
1259
  this.loadJsSdkListCachePromise = {};
1260
1260
  this.lazyContainer = {
1261
1261
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
1262
1262
  appLazyContainerList: [],
1263
1263
  appLazyFinishContainerList: [],
1264
1264
  },
1265
1265
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
1266
1266
  appLazyContainerList: [],
1267
1267
  appLazyFinishContainerList: [],
1268
1268
  },
1269
1269
  };
1270
1270
  this.renderedIsvComponents = {};
1271
1271
  this.rootEleNode = document.querySelector('body');
1272
1272
  this.checkStatusAndLoginPromise = null;
1273
1273
  this.jmfeRegisterStatePromise = null;
1274
1274
  this.jdScreenSizeInfoPromise = null;
1275
1275
  this.rootEleWidthRegisterPromise = null;
1276
1276
  this.lbsAddressCachePromise = null;
1277
1277
  this.languageCacheProimse = null;
1278
1278
  this.businessWorkerReady = false;
1279
1279
  this.businessWorkerReadyPromise = null;
1280
1280
  this.loadJsH5tagStatePromise = null;
1281
1281
  this.loadJsApiRequestStatePromise = null;
1282
1282
  this.workerPreRequestData = new Map<string, any>();
1283
1283
  this.languageJsonData = langeJsonDataForCn;
1284
1284
  this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
1285
1285
  this._init();
1286
1286
  if (isJdApp) {
1287
1287
  this.jmfeReayPromise().then(() => {
1288
1288
  this.jdWorkerReadyPromise();
1289
1289
  initAccessibility();
1290
1290
  });
1291
1291
  this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
1292
1292
  }
1293
1293
  }
1294
1294
  _getConfig(opt) {
1295
1295
  return Object.assign({}, DefaultConfig, opt);
1296
1296
  }
1297
1297
  _init() {
1298
1298
  this.loadOtherSdk();
1299
1299
  this.checkJdAddCartState();
1300
1300
  this.checkPageDomHeightToReport();
1301
1301
  }
1302
1302
  checkPageDomHeightToReport() {
1303
1303
  Taro.nextTick(() => {
1304
1304
  setTimeout(() => {
1305
1305
  const getReportData = {
1306
1306
  containerFloorLisHeight: -1,
1307
1307
  appHeight: -1,
1308
1308
  };
1309
1309
  const getAppEle = document.getElementById('app');
1310
1310
  const getFloorContainerEle = document.getElementById('J_shopContainerFloorList');
1311
1311
  const getNetWorkEle = document.querySelector('.J_shopNetwork');
1312
1312
  getFloorContainerEle &&
1313
1313
  (getReportData.containerFloorLisHeight =
1314
1314
  getFloorContainerEle?.getBoundingClientRect()?.height ?? -1);
1315
1315
  getAppEle && (getReportData.appHeight = getAppEle?.getBoundingClientRect()?.height ?? -1);
1316
1316
  const getMaxHeight = Math.max(
1317
1317
  getReportData.appHeight,
1318
1318
  getReportData.containerFloorLisHeight,
1319
1319
  );
1320
1320
  if (!getNetWorkEle && getMaxHeight > -1 && getMaxHeight < 80) {
1321
1321
  draBusinessCustomReport({
1322
1322
  eventName: 'business',
1323
1323
  errorName: 'pageDomHeightErrorCheck',
1324
1324
  errorMessage:
1325
1325
  '当前页面总高度异常小于80px,没有兜底network组件,可能空窗,请检查核对详细信息',
1326
1326
  extraData: JSON.stringify({
1327
1327
  data: getReportData,
1328
1328
  isJdApp,
1329
1329
  }),
1330
1330
  });
1331
1331
  }
1332
1332
  }, window?.shopGlobalSwitch?.checkPageDomHeightTime || 4000);
1333
1333
  });
1334
1334
  }
1335
1335
 
1336
1336
  checkJdAddCartState() {
1337
1337
  const getJdAppForNotMainRemoveCartUaList = isJdApp
1338
1338
  ? window?.PAGE_DATA?.businessData?.jdAppForNotMainRemoveCartUaList
1339
1339
  : undefined;
1340
1340
  if (
1341
1341
  getJdAppForNotMainRemoveCartUaList &&
1342
1342
  Array.isArray(getJdAppForNotMainRemoveCartUaList) &&
1343
1343
  getJdAppForNotMainRemoveCartUaList.length > 0
1344
1344
  ) {
1345
1345
  const setFilterReg = new RegExp(getJdAppForNotMainRemoveCartUaList.join('|'), 'i');
1346
1346
  this.info.baseAddCartSwitch = !setFilterReg.test(window.navigator.userAgent);
1347
1347
  }
1348
1348
  }
1349
1349
 
1350
1350
  loadApiSafeSteadyReayPromise() {
1351
1351
  if (!this.loadJsApiRequestStatePromise) {
1352
1352
  this.loadJsApiRequestStatePromise = this.loadOtherSdk(LoadJsInitTriggerType.API_REQUEST);
1353
1353
  }
1354
1354
  return this.loadJsApiRequestStatePromise;
1355
1355
  }
1356
1356
 
1357
1357
  loadH5tagReayPromise() {
1358
1358
  if (!this.loadJsH5tagStatePromise) {
1359
1359
  const h5TagJs = this.loadJsSdkList.find((e) => e.fileName === 'h5TagJs');
1360
1360
  this.loadJsH5tagStatePromise = !h5TagJs
1361
1361
  ? Promise.resolve(true)
1362
1362
  : this.loadOtherSdk(LoadJsInitTriggerType.NOW, [
1363
1363
  Object.assign({}, h5TagJs, {
1364
1364
  initTriggerType: LoadJsInitTriggerType.NOW,
1365
1365
  }),
1366
1366
  ]);
1367
1367
  }
1368
1368
  return this.loadJsH5tagStatePromise;
1369
1369
  }
1370
1370
 
1371
1371
  jmfeReayPromise(): Promise<any> {
1372
1372
  if (isJdApp) {
1373
1373
  if (this.jmfeRegisterState) {
1374
1374
  return Promise.resolve(true);
1375
1375
  } else {
1376
1376
  !this.jmfeRegisterStatePromise &&
1377
1377
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
1378
1378
  ready('jmfe', 3000)
1379
1379
  .then(() => {
1380
1380
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
1381
1381
  this.jmfeRegisterState = true;
1382
1382
  resolve(true);
1383
1383
  console.log(
1384
1384
  '松果app内初始化注册jmfe认证完成',
1385
1385
  window?.jmfe,
1386
1386
  '当前版本',
1387
1387
  window?.jmfe?.VERSION,
1388
1388
  );
1389
1389
  })
1390
1390
  .catch((err) => {
1391
1391
  console.error('jmfe ready error', err);
1392
1392
  reject(false);
1393
1393
  });
1394
1394
  }));
1395
1395
  return this.jmfeRegisterStatePromise;
1396
1396
  }
1397
1397
  } else {
1398
1398
  return Promise.reject(false);
1399
1399
  }
1400
1400
  }
1401
1401
 
1402
1402
  jdWorkerReadyPromise(): Promise<any> {
1403
1403
  if (isJdApp) {
1404
1404
  if (this.businessWorkerReady) {
1405
1405
  return Promise.resolve(true);
1406
1406
  } else {
1407
1407
  const getOpenJdWorkerState =
1408
1408
  window?.PAGE_DATA?.businessData?.businessWorkerVersion &&
1409
1409
  versionCompare(
1410
1410
  jdAppVersionStr,
1411
1411
  window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10',
1412
1412
  ) >= 0;
1413
1413
  !this.businessWorkerReadyPromise &&
1414
1414
  (this.businessWorkerReadyPromise = getOpenJdWorkerState
1415
1415
  ? new Promise((resolve) => {
1416
1416
  this.jmfeReayPromise()
1417
1417
  .then(() => {
1418
1418
  window.jmfe
1419
1419
  .onMsgForWorker(
1420
1420
  { version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
1421
1421
  (workerData) => {
1422
1422
  console.log('收到业务jd worker消息结果:', workerData);
1423
1423
  if (workerData && workerData?.workerType) {
1424
1424
  const getWorkerType = workerData?.workerType;
1425
1425
  if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
1426
1426
  this.workerPreRequestData.set(workerData?.functionId, workerData);
1427
1427
  Taro.eventCenter.trigger(getWorkerType, workerData);
1428
1428
  } else if (getWorkerType === TaroEventType.jdWorkerRequest) {
1429
1429
  Taro.eventCenter.trigger(getWorkerType, workerData);
1430
1430
  }
1431
1431
  }
1432
1432
  },
1433
1433
  )
1434
1434
  .then(() => {
1435
1435
  console.log('jd worker注册成功');
1436
1436
  this.businessWorkerReady = true;
1437
1437
  resolve(true);
1438
1438
  })
1439
1439
  .catch((error) => {
1440
1440
  console.log(
1441
1441
  'jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑',
1442
1442
  error,
1443
1443
  );
1444
1444
  draBusinessCustomReport({
1445
1445
  eventName: 'business',
1446
1446
  errorName: 'jmfe_onMsgForWorker_error',
1447
1447
  errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
1448
1448
  extraData: JSON.stringify({
1449
1449
  businessWorkerVersion:
1450
1450
  window?.PAGE_DATA?.businessData?.businessWorkerVersion,
1451
1451
  error,
1452
1452
  }),
1453
1453
  });
1454
1454
  resolve(false);
1455
1455
  });
1456
1456
  })
1457
1457
  .catch((err) => {
1458
1458
  console.log('jmfe超时异常,worker注册失败', err);
1459
1459
  resolve(false);
1460
1460
  });
1461
1461
  })
1462
1462
  : Promise.resolve(false));
1463
1463
  }
1464
1464
  return this.businessWorkerReadyPromise;
1465
1465
  } else {
1466
1466
  return Promise.resolve(false);
1467
1467
  }
1468
1468
  }
1469
1469
 
1470
1470
  taskTimeoutPromise(callBack, timeout = 2000) {
1471
1471
  return new Promise((resolve) => {
1472
1472
  setTimeout(
1473
1473
  () => {
1474
1474
  const getCallBackRes = typeof callBack === 'function' && callBack();
1475
1475
  return resolve(getCallBackRes || false);
1476
1476
  },
1477
1477
  isInJdAppH5DebugMode ? 0 : timeout,
1478
1478
  );
1479
1479
  });
1480
1480
  }
1481
1481
  _getJdPadMinWidthForListen() {
1482
1482
  return (
1483
1483
  isJdApp &&
1484
1484
  Math.min(window.screen.width, window.screen.height) >
1485
1485
  (window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
1486
1486
  );
1487
1487
  }
1488
1488
 
1489
1489
  getJdScreenSizeInfoPromise() {
1490
1490
  !this.jdScreenSizeInfoPromise &&
1491
1491
  (this.jdScreenSizeInfoPromise = new Promise((resolve) => {
1492
1492
  const getThisTime = Date.now();
1493
1493
  this.jmfeReayPromise().then(() => {
1494
1494
  return Promise.race([
1495
1495
  window.jmfe.getScreenSize(),
1496
1496
  this.taskTimeoutPromise(() => {
1497
1497
  return {
1498
1498
  status: '-10',
1499
1499
  msg: '获取大屏信息2s超时',
1500
1500
  };
1501
1501
  }),
1502
1502
  ])
1503
1503
  .then((res) => {
1504
1504
  console.warn('===获取app大屏信息====', res);
1505
1505
  const { status, data } = res;
1506
1506
  if (status === '0' && data) {
1507
1507
  const { sizeType, isLandscape, pageHeight, pageWidth } = data;
1508
1508
  const getPageInfo = dealNativePixelToCssPixel({
1509
1509
  pageWidth,
1510
1510
  pageHeight,
1511
1511
  });
1512
1512
  this.info.sysInfo.jdScreenSizeType = sizeType;
1513
1513
  const getUseTime = Date.now() - getThisTime;
1514
1514
  console.warn(
1515
1515
  '===计算是否是app大屏信息,需满足宽度最新720===',
1516
1516
  getPageInfo,
1517
1517
  '原始数据',
1518
1518
  data,
1519
1519
  '是否是横屏isLandscape为1=',
1520
1520
  isLandscape,
1521
1521
  '用时',
1522
1522
  getUseTime,
1523
1523
  );
1524
1524
  if (getPageInfo?.pageWidth > 0) {
1525
1525
  this.rootEleInitWidth = getPageInfo?.pageWidth;
1526
1526
  draBusinessCustomReport({
1527
1527
  eventName: 'UIInteract',
1528
1528
  errorName: 'rootEle_width_getJdScreenSizeInfo',
1529
1529
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
1530
1530
  extraData: JSON.stringify({
1531
1531
  isJdApp,
1532
1532
  getPageInfo,
1533
1533
  originData: res,
1534
1534
  }),
1535
1535
  });
1536
1536
  resolve(getPageInfo);
1537
1537
  } else {
1538
1538
  resolve({
1539
1539
  pageWidth: 0,
1540
1540
  pageHeight: 0,
1541
1541
  msg: '转换异常',
1542
1542
  });
1543
1543
  }
1544
1544
  } else {
1545
1545
  resolve({
1546
1546
  pageWidth: 0,
1547
1547
  pageHeight: 0,
1548
1548
  msg: '获取大屏信息异常或者超时',
1549
1549
  });
1550
1550
  }
1551
1551
  })
1552
1552
  .catch((err) => {
1553
1553
  console.log('获取大屏信息异常', err);
1554
1554
  resolve({
1555
1555
  pageWidth: 0,
1556
1556
  pageHeight: 0,
1557
1557
  msg: '获取大屏信息异常',
1558
1558
  });
1559
1559
  });
1560
1560
  });
1561
1561
  }));
1562
1562
  return this.jdScreenSizeInfoPromise;
1563
1563
  }
1564
1564
 
1565
1565
  listenJdTabletScreenChange() {
1566
1566
  this.jmfeReayPromise().then(() => {
1567
1567
  try {
1568
1568
  console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
1569
1569
  window.jmfe.listenDeviceScreenChange((event) => {
1570
1570
  console.log(
1571
1571
  '监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
1572
1572
  event,
1573
1573
  '通过前端判断是不是横屏',
1574
1574
  window.matchMedia('(orientation: landscape)')?.matches,
1575
1575
  );
1576
1576
  const { orientation } = event?.data;
1577
1577
  if (orientation) {
1578
1578
  this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
1579
1579
  Taro.eventCenter.trigger(
1580
1580
  TaroEventType.TABLE_SCREEN_CHANGE,
1581
1581
  this.info.sysInfo.isJdTabletLandscape,
1582
1582
  orientation,
1583
1583
  );
1584
1584
  }
1585
1585
  });
1586
1586
  } catch (error) {
1587
1587
  console.log('listenScreenChange的打印error:', error);
1588
1588
  }
1589
1589
  });
1590
1590
  }
1591
1591
 
1592
1592
  updateBusinessDomainAndApi(domain, api) {
1593
1593
  }
1594
1594
 
1595
1595
  formatNativeScreenPageData(action) {
1596
1596
  let getChangePageInfo: any = null;
1597
1597
  try {
1598
1598
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
1599
1599
  JSON.stringify({
1600
1600
  plugin: 'JDHybridScreenPlugin',
1601
1601
  action,
1602
1602
  sync: '1',
1603
1603
  }),
1604
1604
  );
1605
1605
  const getChangePageInfoData =
1606
1606
  typeof getNativeScreenPageInfoStr === 'string'
1607
1607
  ? JSON.parse(getNativeScreenPageInfoStr)
1608
1608
  : null;
1609
1609
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
1610
1610
  const { code, data } = getChangePageInfoData;
1611
1611
  getChangePageInfo = code && code === '0' ? data : null;
1612
1612
  }
1613
1613
  } catch (e) {
1614
1614
  console.log('JDHybridScreenPlugin转换异常', e);
1615
1615
  }
1616
1616
  return getChangePageInfo;
1617
1617
  }
1618
1618
 
1619
1619
  isAndroidFoldScreen() {
1620
1620
  return this.formatNativeScreenPageData('isFoldScreen') === '1';
1621
1621
  }
1622
1622
 
1623
1623
  isHarmonyFoldScreenPromise(): Promise<{
1624
1624
  isFoldScreen: boolean;
1625
1625
  getFoldDisplayMode?: number;
1626
1626
  }> {
1627
1627
  return new Promise((resolve) => {
1628
1628
  this.jmfeReayPromise()
1629
1629
  .then(() => {
1630
1630
  if (window.jmfe?.callNative) {
1631
1631
  Promise.all([
1632
1632
  window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
1633
1633
  window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {}),
1634
1634
  ])
1635
1635
  .then((res) => {
1636
1636
  resolve({
1637
1637
  isFoldScreen: res?.[0]?.data === '1',
1638
1638
  getFoldDisplayMode: res?.[1]?.data,
1639
1639
  });
1640
1640
  })
1641
1641
  .catch(() => {
1642
1642
  resolve({
1643
1643
  isFoldScreen: false,
1644
1644
  getFoldDisplayMode: undefined,
1645
1645
  });
1646
1646
  });
1647
1647
  } else {
1648
1648
  resolve({
1649
1649
  isFoldScreen: false,
1650
1650
  getFoldDisplayMode: undefined,
1651
1651
  });
1652
1652
  }
1653
1653
  })
1654
1654
  .catch(() => {
1655
1655
  resolve({
1656
1656
  isFoldScreen: false,
1657
1657
  getFoldDisplayMode: undefined,
1658
1658
  });
1659
1659
  });
1660
1660
  });
1661
1661
  }
1662
1662
 
1663
1663
  getJdAndroidPageChangeScreenInfo() {
1664
1664
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
1665
1665
  if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
1666
1666
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
1667
1667
  pageWidth: getPageScreenInfo.pageWidth,
1668
1668
  pageHeight: getPageScreenInfo.pageHeight,
1669
1669
  });
1670
1670
  getPageScreenInfo.pageWidth = pageWidth;
1671
1671
  getPageScreenInfo.pageHeight = pageHeight;
1672
1672
  }
1673
1673
  return getPageScreenInfo;
1674
1674
  }
1675
1675
 
1676
1676
  getRootEleWindowWidthInfo() {
1677
1677
  const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
1678
1678
  const getWindowWidth = window.innerWidth;
1679
1679
  const getScreenWidth = window.screen.width;
1680
1680
  return {
1681
1681
  getRootEleWidth,
1682
1682
  getWindowWidth,
1683
1683
  getScreenWidth,
1684
1684
  };
1685
1685
  }
1686
1686
 
1687
1687
  dealRootEleWidthFn(reportParam = {}, timeout = 0) {
1688
1688
  const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
1689
1689
  console.log(
1690
1690
  '当前获取根元素的宽度',
1691
1691
  getRootEleWidth,
1692
1692
  'getWindowWidth',
1693
1693
  getWindowWidth,
1694
1694
  'getScreenWidth',
1695
1695
  getScreenWidth,
1696
1696
  );
1697
1697
  const getLastWidth =
1698
1698
  getRootEleWidth > 0
1699
1699
  ? Math.round(getRootEleWidth)
1700
1700
  : Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
1701
1701
  console.warn(
1702
1702
  `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
1703
1703
  );
1704
1704
  timeout > 0 &&
1705
1705
  draBusinessCustomReport({
1706
1706
  eventName: 'UIInteract',
1707
1707
  errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
1708
1708
  errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
1709
1709
  extraData: JSON.stringify({
1710
1710
  isJdApp,
1711
1711
  getRootEleWidth,
1712
1712
  getWindowWidth,
1713
1713
  getScreenWidth,
1714
1714
  ...reportParam,
1715
1715
  }),
1716
1716
  });
1717
1717
  return getLastWidth;
1718
1718
  }
1719
1719
 
1720
1720
  getPadWindowRootEleWidthPromise() {
1721
1721
  if (this.rootEleInitWidth > 0) {
1722
1722
  return Promise.resolve(this.rootEleInitWidth);
1723
1723
  } else {
1724
1724
  !this.rootEleWidthRegisterPromise &&
1725
1725
  (this.rootEleWidthRegisterPromise = new Promise((resolve) => {
1726
1726
  const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
1727
1727
  if (getRootEleInitWidth > 0) {
1728
1728
  console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
1729
1729
  this.rootEleInitWidth = Math.round(getRootEleInitWidth);
1730
1730
  resolve(this.rootEleInitWidth);
1731
1731
  } else {
1732
1732
  const timerPromise = () => {
1733
1733
  return new Promise((resolve2) => {
1734
1734
  window.setTimeout(() => {
1735
1735
  const { getRootEleWidth, getWindowWidth, getScreenWidth } =
1736
1736
  this.getRootEleWindowWidthInfo();
1737
1737
  if (getRootEleWidth > 0 || getWindowWidth > 0) {
1738
1738
  console.warn(
1739
1739
  `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
1740
1740
  );
1741
1741
  draBusinessCustomReport({
1742
1742
  eventName: 'UIInteract',
1743
1743
  errorName: 'rootEle_width_200_timeout_info',
1744
1744
  errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
1745
1745
  extraData: JSON.stringify({
1746
1746
  isJdApp,
1747
1747
  getRootEleWidth,
1748
1748
  getWindowWidth,
1749
1749
  getScreenWidth,
1750
1750
  }),
1751
1751
  });
1752
1752
  const getRes =
1753
1753
  getRootEleWidth > 0 && getWindowWidth > 0
1754
1754
  ? Math.min(getRootEleWidth, getWindowWidth)
1755
1755
  : Math.max(getRootEleWidth, getWindowWidth);
1756
1756
  resolve2({
1757
1757
  pageWidth: Math.round(getRes),
1758
1758
  });
1759
1759
  }
1760
1760
  }, 200);
1761
1761
  });
1762
1762
  };
1763
1763
  Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
1764
1764
  const { pageWidth } = res;
1765
1765
  console.log('获取结果Promise.race getJdScreenSizeInfo', res);
1766
1766
  pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
1767
1767
  });
1768
1768
  }
1769
1769
  }));
1770
1770
  return this.rootEleWidthRegisterPromise;
1771
1771
  }
1772
1772
  }
1773
1773
 
1774
1774
  async getSystemInfo(params) {
1775
1775
  const getParams = Object.assign({}, params || {});
1776
1776
  if (this.rootEleInitWidth > 0) {
1777
1777
  getParams['rootEleInitWidth'] = this.rootEleInitWidth;
1778
1778
  console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
1779
1779
  } else {
1780
1780
  if (this._getJdPadMinWidthForListen()) {
1781
1781
  getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
1782
1782
  getParams['replaceSystemWidth'] = true;
1783
1783
  }
1784
1784
  }
1785
1785
  isJdApp && this.createLanguagePromise();
1786
1786
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
1787
1787
  if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
1788
1788
  let _isfoldScreen = false;
1789
1789
  const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
1790
1790
  console.info(
1791
1791
  '获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
1792
1792
  getStorageData,
1793
1793
  '通过缓存值第一次判断是否是折叠屏',
1794
1794
  getStorageData === 'true',
1795
1795
  );
1796
1796
  if (!getStorageData) {
1797
1797
  _isfoldScreen = this.isAndroidFoldScreen();
1798
1798
  setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
1799
1799
  } else {
1800
1800
  _isfoldScreen = getStorageData === 'true';
1801
1801
  }
1802
1802
  if (_isfoldScreen) {
1803
1803
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
1804
1804
  if (getJdAndroidPageInfo) {
1805
1805
  info = getSystemInfos(getJdAndroidPageInfo);
1806
1806
  console.warn(
1807
1807
  '当前为松果安卓折叠屏app,获取折叠屏信息',
1808
1808
  getJdAndroidPageInfo,
1809
1809
  '获取转换后的系统信息',
1810
1810
  info,
1811
1811
  );
1812
1812
  draBusinessCustomReport({
1813
1813
  eventName: 'UIInteract',
1814
1814
  errorName: 'android_jdapp_foldScreen_info',
1815
1815
  errorMessage:
1816
1816
  '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
1817
1817
  extraData: JSON.stringify({
1818
1818
  title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
1819
1819
  androidPageInfo: getJdAndroidPageInfo,
1820
1820
  jdAppVersionStr,
1821
1821
  taroSysInfo: info,
1822
1822
  }),
1823
1823
  });
1824
1824
  }
1825
1825
  }
1826
1826
  }
1827
1827
  if (isJdApp) {
1828
1828
  info?.isJdTabletDevice && this.listenJdTabletScreenChange();
1829
1829
  }
1830
1830
  this.info.sysInfo = {
1831
1831
  actualNavBarHeight: 0,
1832
1832
  ...this.info.sysInfo,
1833
1833
  ...info,
1834
1834
  safeContentHeight: info?.screenHeight,
1835
1835
  headerHeight: 0,
1836
1836
  tabBarHeight: 0,
1837
1837
  languageType: languageNowType,
1838
1838
  };
1839
1839
  if (isJdApp || isH5AndJingGouMini) {
1840
1840
  this.getAddressCachePromise();
1841
1841
  this.getLbsAddressCachePromise();
1842
1842
  }
1843
1843
  if (isJdApp) {
1844
1844
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
1845
1845
  this.info.sysInfo['hostAppVersion'] = jdAppVersion;
1846
1846
  this.getJdAppBaseInfo();
1847
1847
  this.getElderModePromise();
1848
1848
  this.getJDAppearanceStatePromise();
1849
1849
  this.createJdAndroidRquestEventForTouchStart();
1850
1850
  }
1851
1851
  this.getWifiVideoAutoPlayAsync();
1852
1852
  this.getMPaasConfigAsync();
1853
1853
  this.getNetWorkType();
1854
1854
  }
1855
1855
 
1856
1856
  getElderModePromise() {
1857
1857
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
1858
1858
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1859
1859
  } else {
1860
1860
  if (isJdAndAndroidDevice) {
1861
1861
  this.info.sysInfo.jdAppModeType = '0';
1862
1862
  return Promise.resolve(this.info.sysInfo.jdAppModeType);
1863
1863
  } else {
1864
1864
  return Promise.race([
1865
1865
  this.taskTimeoutPromise(() => {
1866
1866
  this.info.sysInfo.jdAppModeType = '0';
1867
1867
  return this.info.sysInfo.jdAppModeType;
1868
1868
  }),
1869
1869
  new Promise((resolve) => {
1870
1870
  const getCallBackName = `getJdCurrentModeType${Date.now()}`;
1871
1871
  if (!window[getCallBackName]) {
1872
1872
  window[getCallBackName] = (res) => {
1873
1873
  try {
1874
1874
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1875
1875
  const { status, data, msg } = getResJson;
1876
1876
  console.log(`获取松果app展示模式成功,返回结果${data}`);
1877
1877
  if (status === '0') {
1878
1878
  this.info.sysInfo.jdAppModeType = data;
1879
1879
  resolve(data);
1880
1880
  } else {
1881
1881
  resolve('0');
1882
1882
  }
1883
1883
  } catch (e) {
1884
1884
  resolve('0');
1885
1885
  }
1886
1886
  window[getCallBackName] = null;
1887
1887
  };
1888
1888
  }
1889
1889
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1890
1890
  method: 'callSyncRouterModuleWithParams',
1891
1891
  params: JSON.stringify({
1892
1892
  routerURL: 'router://JDBModeModule/getCurrentMode',
1893
1893
  routerParam: {},
1894
1894
  callBackName: `window.${getCallBackName}`,
1895
1895
  callBackId: `${getCallBackName}Ios`,
1896
1896
  }),
1897
1897
  });
1898
1898
  }),
1899
1899
  ]);
1900
1900
  }
1901
1901
  }
1902
1902
  }
1903
1903
  getAPPUseStraightCorner() {
1904
1904
  const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
1905
1905
  const params = {
1906
1906
  routerURL,
1907
1907
  routerParam: {},
1908
1908
  jdRouter: '1',
1909
1909
  };
1910
1910
  if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
1911
1911
  return Promise.resolve(this.info.sysInfo.jdStraightCorner);
1912
1912
  } else {
1913
1913
  return this.jmfeReayPromise()
1914
1914
  .then(() => {
1915
1915
  if (isJdAndHarmonyDevice || !isJdApp) {
1916
1916
  console.log('not APP or is Harmony');
1917
1917
  return Promise.resolve(false);
1918
1918
  }
1919
1919
  console.log('jmfe setShareInfo', params);
1920
1920
  return Promise.race([
1921
1921
  window.jmfe.callRouter(params),
1922
1922
  this.taskTimeoutPromise(() => {
1923
1923
  return false;
1924
1924
  }),
1925
1925
  ]).then(({ status, data }) => {
1926
1926
  console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
1927
1927
  console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
1928
1928
  this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
1929
1929
  return Promise.resolve(status === '0' && Number(data) === 1);
1930
1930
  });
1931
1931
  })
1932
1932
  .catch((e) => {
1933
1933
  console.log('jmfe error', e);
1934
1934
  return Promise.resolve(false);
1935
1935
  });
1936
1936
  }
1937
1937
  }
1938
1938
 
1939
1939
  getJDAppearanceStatePromise() {
1940
1940
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
1941
1941
  return Promise.resolve(this.info.sysInfo.jdAppearanceState);
1942
1942
  } else {
1943
1943
  return Promise.race([
1944
1944
  this.taskTimeoutPromise(() => {
1945
1945
  this.info.sysInfo.jdAppearanceState = '0';
1946
1946
  return this.info.sysInfo.jdAppearanceState;
1947
1947
  }),
1948
1948
  new Promise((resolve) => {
1949
1949
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
1950
1950
  if (!window[getCallBackName]) {
1951
1951
  window[getCallBackName] = (res) => {
1952
1952
  try {
1953
1953
  console.log('getJDAppearanceStatePromise', res);
1954
1954
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
1955
1955
  const { status, data, msg } = getResJson;
1956
1956
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
1957
1957
  if (status === '0') {
1958
1958
  this.info.sysInfo.jdAppearanceState = data;
1959
1959
  resolve(data);
1960
1960
  } else {
1961
1961
  resolve('0');
1962
1962
  }
1963
1963
  } catch (e) {
1964
1964
  resolve('0');
1965
1965
  }
1966
1966
  window[getCallBackName] = null;
1967
1967
  };
1968
1968
  }
1969
1969
  if (isAndroidDevice) {
1970
1970
  const jsonString = JSON.stringify({
1971
1971
  callBackName: `window.${getCallBackName}`,
1972
1972
  });
1973
1973
  console.log('window.JDAppearance', window?.JDAppearance);
1974
1974
  window?.JDAppearance &&
1975
1975
  window?.JDAppearance?.getUiState &&
1976
1976
  window.JDAppearance.getUiState(jsonString);
1977
1977
  } else {
1978
1978
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
1979
1979
  method: 'callSyncRouterModuleWithParams',
1980
1980
  params: JSON.stringify({
1981
1981
  routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
1982
1982
  routerParam: {},
1983
1983
  callBackName: `window.${getCallBackName}`,
1984
1984
  callBackId: `${getCallBackName}Ios`,
1985
1985
  }),
1986
1986
  });
1987
1987
  }
1988
1988
  }),
1989
1989
  ]);
1990
1990
  }
1991
1991
  }
1992
1992
 
1993
1993
  createJdAndroidRquestEventForTouchStart() {
1994
1994
  if (isJdAndAndroidDevice && window?.JdAndroid) {
1995
1995
  const rootEleNode = document.querySelector('body');
1996
1996
  if (rootEleNode) {
1997
1997
  rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
1998
1998
  }
1999
1999
  }
2000
2000
  }
2001
2001
  jdAndroidAddEventListenerTouchStart(e) {
2002
2002
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
2003
2003
  if (!isH5SwiperCustomEle && window?.JdAndroid) {
2004
2004
  const hasCustomEle = e
2005
2005
  ? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
2006
2006
  : false;
2007
2007
  if (!hasCustomEle) {
2008
2008
  window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
2009
2009
  console.log(
2010
2010
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
2011
2011
  );
2012
2012
  }
2013
2013
  }
2014
2014
  }
2015
2015
  removeJdAndroidRquestEventForTouchStart() {
2016
2016
  if (isJdAndAndroidDevice && window.JdAndroid) {
2017
2017
  const rootEleNode = document.querySelector('body');
2018
2018
  if (rootEleNode) {
2019
2019
  rootEleNode.removeEventListener(
2020
2020
  'touchstart',
2021
2021
  this.jdAndroidAddEventListenerTouchStart,
2022
2022
  false,
2023
2023
  );
2024
2024
  }
2025
2025
  }
2026
2026
  }
2027
2027
 
2028
2028
  getNetWorkType() {
2029
2029
  if (isJdApp) {
2030
2030
  this.jmfeReayPromise().then(() => {
2031
2031
  window.jmfe
2032
2032
  .getNetworkStatus()
2033
2033
  .then(({ status, data }) => {
2034
2034
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
2035
2035
  if (status === '0') {
2036
2036
  this.info.sysInfo['netWorkType'] = data;
2037
2037
  } else {
2038
2038
  this._taroGetNetworkType();
2039
2039
  }
2040
2040
  })
2041
2041
  .catch((err) => {
2042
2042
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
2043
2043
  this._taroGetNetworkType();
2044
2044
  });
2045
2045
  });
2046
2046
  } else {
2047
2047
  this._taroGetNetworkType();
2048
2048
  }
2049
2049
  }
2050
2050
  _taroGetNetworkType() {
2051
2051
  Taro.getNetworkType().then((getRes) => {
2052
2052
  if (getRes && getRes.networkType) {
2053
2053
  this.info.sysInfo['netWorkType'] = getRes.networkType;
2054
2054
  console.log(
2055
2055
  '在app内通过taro对象获取网络状态完成,当前网络状态',
2056
2056
  this.info.sysInfo['netWorkType'],
2057
2057
  );
2058
2058
  }
2059
2059
  });
2060
2060
  }
2061
2061
 
2062
2062
  getJdAppBaseInfo() {
2063
2063
  const appKeyCacheToCookieMinuteTime =
2064
2064
  window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
2065
2065
  appUuidCacheToCookieMinuteTime =
2066
2066
  window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
2067
2067
  getAppKey = cookie.get(cacheAppKey),
2068
2068
  getAppUuidKey = cookie.get(cacheAppUuidKey);
2069
2069
  console.log(
2070
2070
  '在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam',
2071
2071
  cacheAppKey,
2072
2072
  getAppKey,
2073
2073
  cacheAppUuidKey,
2074
2074
  getAppUuidKey,
2075
2075
  );
2076
2076
  if (
2077
2077
  appKeyCacheToCookieMinuteTime &&
2078
2078
  appUuidCacheToCookieMinuteTime &&
2079
2079
  getAppKey &&
2080
2080
  getAppUuidKey
2081
2081
  ) {
2082
2082
  const [uuid, eufv] = getAppUuidKey.split('@');
2083
2083
  const baseApiKeyParam = {
2084
2084
  uuid,
2085
2085
  };
2086
2086
  getAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getAppKey);
2087
2087
  if (eufv === '1' && /-/.test(uuid)) {
2088
2088
  const [eu, fv] = uuid.split('-');
2089
2089
  baseApiKeyParam['eu'] = eu;
2090
2090
  baseApiKeyParam['fv'] = fv;
2091
2091
  }
2092
2092
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
2093
2093
  this.jmfeReayPromise().then(() => {
2094
2094
  console.log('在app内初始化通过cookie获取api请求参数集合baseApiKeyParam', baseApiKeyParam);
2095
2095
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
2096
2096
  });
2097
2097
  } else {
2098
2098
  const checkGetJdAppKeyState =
2099
2099
  window?.shopGlobalSwitch?.getJdAppKeyVersion &&
2100
2100
  jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0;
2101
2101
  this.jmfeReayPromise().then(() => {
2102
2102
  Promise.all([
2103
2103
  checkGetJdAppKeyState && window.jmfe?.callNative
2104
2104
  ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0')
2105
2105
  : Promise.resolve({
2106
2106
  status: '-1000',
2107
2107
  msg: '当前版本不支持获取松果app中的getAppKey',
2108
2108
  data: '-1000',
2109
2109
  }),
2110
2110
  window.jmfe.getDeviceInfo(),
2111
2111
  ]).then((resList) => {
2112
2112
  const [getAppKeyRes, deviceInfoRes] = resList;
2113
2113
  console.log(
2114
2114
  '在app内初始化通过jmfe获取getAppKey结果',
2115
2115
  getAppKeyRes,
2116
2116
  '通过jmfe获取getDeviceInfo获取结果',
2117
2117
  deviceInfoRes,
2118
2118
  );
2119
2119
  const baseApiKeyParam = {};
2120
2120
  if (['0', '-1000'].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
2121
2121
  const getJmfeAppKey = getAppKeyRes?.data;
2122
2122
  if (getJmfeAppKey && getJmfeAppKey !== '') {
2123
2123
  getJmfeAppKey !== '-1000' && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
2124
2124
  const getJdAppKeyCacheToCookieMinuteTime =
2125
2125
  (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
2126
2126
  if (getJdAppKeyCacheToCookieMinuteTime) {
2127
2127
  const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
2128
2128
  cookie.set(cacheAppKey, getJmfeAppKey, {
2129
2129
  path: '/',
2130
2130
  expires,
2131
2131
  });
2132
2132
  }
2133
2133
  }
2134
2134
  }
2135
2135
  if (deviceInfoRes?.status === '0' && deviceInfoRes?.data) {
2136
2136
  const { uuid, eufv = '0', networkType } = deviceInfoRes?.data;
2137
2137
  if (uuid && uuid !== '') {
2138
2138
  networkType && (this.info.sysInfo['netWorkType'] = networkType);
2139
2139
  baseApiKeyParam['uuid'] = uuid;
2140
2140
  if (eufv === '1' && /-/.test(uuid)) {
2141
2141
  const [eu, fv] = uuid.split('-');
2142
2142
  baseApiKeyParam['eu'] = eu;
2143
2143
  baseApiKeyParam['fv'] = fv;
2144
2144
  }
2145
2145
  const getAppUuidCacheToCookieMinuteTime =
2146
2146
  (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
2147
2147
  if (getAppUuidCacheToCookieMinuteTime) {
2148
2148
  const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
2149
2149
  cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
2150
2150
  path: '/',
2151
2151
  expires,
2152
2152
  });
2153
2153
  }
2154
2154
  }
2155
2155
  }
2156
2156
  console.log(
2157
2157
  '在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam',
2158
2158
  baseApiKeyParam,
2159
2159
  );
2160
2160
  if (Object.keys(baseApiKeyParam).length > 0) {
2161
2161
  this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam;
2162
2162
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
2163
2163
  }
2164
2164
  });
2165
2165
  });
2166
2166
  }
2167
2167
  }
2168
2168
 
2169
2169
  getCacheAddressRouter() {
2170
2170
  if (isJdApp) {
2171
2171
  if (!isJdAndHarmonyDevice) {
2172
2172
  return Promise.race([
2173
2173
  new Promise((resolve) => {
2174
2174
  const getCallBackName = `getJdCacheAddress${Date.now()}`;
2175
2175
  if (!window[getCallBackName]) {
2176
2176
  window[getCallBackName] = (res) => {
2177
2177
  console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
2178
2178
  try {
2179
2179
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2180
2180
  resolve(getResJson);
2181
2181
  } catch (e) {
2182
2182
  resolve({
2183
2183
  status: '-1002',
2184
2184
  msg: '地址信息解析json异常',
2185
2185
  res,
2186
2186
  });
2187
2187
  }
2188
2188
  window[getCallBackName] = null;
2189
2189
  };
2190
2190
  }
2191
2191
  const getRouterParam = {
2192
2192
  sceneId: 'basicShoppingProcess',
2193
2193
  };
2194
2194
  if (isAndroidDevice) {
2195
2195
  return callRouterAndroid({
2196
2196
  routerURL: 'router://JDAddressModule/getCacheAddress',
2197
2197
  routerParam: getRouterParam,
2198
2198
  callBackName: getCallBackName,
2199
2199
  isSync: true,
2200
2200
  });
2201
2201
  } else {
2202
2202
  return callRouterIOS({
2203
2203
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
2204
2204
  routerParam: getRouterParam,
2205
2205
  callBackName: getCallBackName,
2206
2206
  });
2207
2207
  }
2208
2208
  }),
2209
2209
  this.taskTimeoutPromise(() => {
2210
2210
  return {
2211
2211
  status: '-1000',
2212
2212
  msg: '原生router协议获取地址信息超时',
2213
2213
  };
2214
2214
  }, 3000),
2215
2215
  ]);
2216
2216
  } else {
2217
2217
  return Promise.race([
2218
2218
  new Promise((resolve) => {
2219
2219
  this.jmfeReayPromise()
2220
2220
  .then(() => {
2221
2221
  const plugin = 'JDHybridRouterPlugin';
2222
2222
  const action = 'callSyncRouterModuleWithParams';
2223
2223
  const params = {
2224
2224
  routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
2225
2225
  routerParam: '',
2226
2226
  };
2227
2227
  const sync = '1';
2228
2228
  try {
2229
2229
  window.jmfe.callNative(plugin, action, params, sync).then((res) => {
2230
2230
  resolve(res);
2231
2231
  });
2232
2232
  } catch (error) {
2233
2233
  resolve({
2234
2234
  status: '-1001',
2235
2235
  msg: '判断jmfe不存在,获取经纬度信息异常',
2236
2236
  });
2237
2237
  }
2238
2238
  })
2239
2239
  .catch(() => {
2240
2240
  resolve({
2241
2241
  status: '-1002',
2242
2242
  msg: '鸿蒙系统调用jmfe异常,获取失败',
2243
2243
  });
2244
2244
  });
2245
2245
  }),
2246
2246
  this.taskTimeoutPromise(() => {
2247
2247
  return {
2248
2248
  status: '-1000',
2249
2249
  msg: '原生router协议获取地址信息超时',
2250
2250
  };
2251
2251
  }, 3000),
2252
2252
  ]);
2253
2253
  }
2254
2254
  } else if (isH5AndJingGouMini) {
2255
2255
  const { areaId, addressName } = this.getJingGouMiniInh5Address();
2256
2256
  if (areaId && areaId !== '' && addressName && addressName !== '') {
2257
2257
  return Promise.resolve({
2258
2258
  status: '0',
2259
2259
  data: {
2260
2260
  areaId,
2261
2261
  fullAddress: addressName,
2262
2262
  },
2263
2263
  });
2264
2264
  } else {
2265
2265
  return Promise.resolve({
2266
2266
  status: '-1002',
2267
2267
  msg: '京购内嵌h5h5暂无业务需要,未实现,获取失败',
2268
2268
  });
2269
2269
  }
2270
2270
  } else {
2271
2271
  return Promise.resolve({
2272
2272
  status: '-1002',
2273
2273
  msg: '普通h5暂无业务需要,未实现,获取失败',
2274
2274
  });
2275
2275
  }
2276
2276
  }
2277
2277
 
2278
2278
  getJingGouMiniInh5Address() {
2279
2279
  let getRes: any = {
2280
2280
  areaId: '',
2281
2281
  addressName: '',
2282
2282
  };
2283
2283
  try {
2284
2284
  const getUrlHast = decodeURIComponent(window.location.hash || '');
2285
2285
  const sensMatch = getUrlHast ? getUrlHast.match(/sens=({.*?})/) : null;
2286
2286
  if (sensMatch && sensMatch[1]) {
2287
2287
  const sensData = JSON.parse(sensMatch[1]);
2288
2288
  const getWqAddr = sensData?.wq_addr || '';
2289
2289
  if (getWqAddr && /\|/.test(getWqAddr)) {
2290
2290
  const addressList = getWqAddr.split(/\|/);
2291
2291
  const [addressId, areaId, areaName, addressName, coordinate] = addressList;
2292
2292
  getRes = {
2293
2293
  addressId,
2294
2294
  areaId,
2295
2295
  areaName,
2296
2296
  addressName,
2297
2297
  coordinate,
2298
2298
  };
2299
2299
  }
2300
2300
  }
2301
2301
  } catch (e) {
2302
2302
  console.log('获取hash转换异常', e);
2303
2303
  }
2304
2304
  return getRes;
2305
2305
  }
2306
2306
 
2307
2307
  getAddressCachePromise() {
2308
2308
  return new Promise((resolve) => {
2309
2309
  if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
2310
2310
  resolve({
2311
2311
  lat: this.info.sysInfo.lat,
2312
2312
  lng: this.info.sysInfo.lng,
2313
2313
  area: this?.info?.sysInfo?.area,
2314
2314
  fullAddress: this?.info?.pageInfo?.fullAddress,
2315
2315
  });
2316
2316
  } else {
2317
2317
  this.getCacheAddressRouter()
2318
2318
  .then((res) => {
2319
2319
  const { status, data } = res;
2320
2320
  console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
2321
2321
  if (status === '0' && data) {
2322
2322
  const {
2323
2323
  lat,
2324
2324
  latitude,
2325
2325
  lng,
2326
2326
  longitude,
2327
2327
  provinceId,
2328
2328
  cityId,
2329
2329
  countyId,
2330
2330
  townId,
2331
2331
  fullAddress,
2332
2332
  areaId,
2333
2333
  } = data || {};
2334
2334
  const getAreaIdsEnable = areaId && areaId !== '';
2335
2335
  const getEncodeFullAddress = fullAddress ? encodeURIComponent(fullAddress) : '';
2336
2336
  let area = getAreaIdsEnable ? areaId : '';
2337
2337
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
2338
2338
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
2339
2339
  const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
2340
2340
  if ((getProvinceIdNum && getProvinceIdNum > 0) || getAreaIdsEnable) {
2341
2341
  area = getAreaIdsEnable
2342
2342
  ? areaId
2343
2343
  : `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
2344
2344
  this.info.pageInfo['address'] = area;
2345
2345
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
2346
2346
  this.info.sysInfo['area'] = area;
2347
2347
  const getUpdateData = {
2348
2348
  area: this.info.pageInfo.address,
2349
2349
  };
2350
2350
  if (fullAddress && fullAddress.length > 0) {
2351
2351
  getUpdateData['fullAddress'] = getEncodeFullAddress;
2352
2352
  this.info.pageInfo['fullAddress'] = getEncodeFullAddress;
2353
2353
  }
2354
2354
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, getUpdateData);
2355
2355
  }
2356
2356
  resolve({
2357
2357
  lat: this.info.sysInfo['lat'],
2358
2358
  lng: this.info.sysInfo['lng'],
2359
2359
  fullAddress: getEncodeFullAddress,
2360
2360
  area: area,
2361
2361
  });
2362
2362
  } else {
2363
2363
  if (typeof res === 'object') {
2364
2364
  draBusinessCustomReport({
2365
2365
  eventName: 'business',
2366
2366
  errorName: 'jdapp_getCacheAddress_info_err',
2367
2367
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
2368
2368
  extraData: JSON.stringify({
2369
2369
  isJdApp,
2370
2370
  jdAppVersion: jdAppVersionStr,
2371
2371
  ...res,
2372
2372
  }),
2373
2373
  });
2374
2374
  }
2375
2375
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
2376
2376
  }
2377
2377
  })
2378
2378
  .catch((e) => {
2379
2379
  console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
2380
2380
  draBusinessCustomReport({
2381
2381
  eventName: 'business',
2382
2382
  errorName: 'jdapp_getCacheAddress_info_catch_err',
2383
2383
  errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
2384
2384
  extraData: JSON.stringify({
2385
2385
  isJdApp,
2386
2386
  jdAppVersion: jdAppVersionStr,
2387
2387
  }),
2388
2388
  });
2389
2389
  resolve({ lat: '', lng: '', area: '', fullAddress: '' });
2390
2390
  });
2391
2391
  }
2392
2392
  });
2393
2393
  }
2394
2394
 
2395
2395
  getLbsCacheAddressRouter() {
2396
2396
  if (isJdApp) {
2397
2397
  if (!isJdAndHarmonyDevice) {
2398
2398
  return Promise.race([
2399
2399
  new Promise((resolve) => {
2400
2400
  const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
2401
2401
  if (!window[getCallBackName]) {
2402
2402
  window[getCallBackName] = (res) => {
2403
2403
  console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
2404
2404
  try {
2405
2405
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
2406
2406
  resolve(getResJson);
2407
2407
  } catch (e) {
2408
2408
  resolve({
2409
2409
  status: '-1002',
2410
2410
  msg: '地址信息解析json异常',
2411
2411
  res,
2412
2412
  });
2413
2413
  }
2414
2414
  window[getCallBackName] = null;
2415
2415
  };
2416
2416
  }
2417
2417
  const getRouterParam = {
2418
2418
  appid: '219f70bbbf7e4ede7968bedaa1beafb4',
2419
2419
  sceneId: 'basicShoppingProcess',
2420
2420
  };
2421
2421
  if (isAndroidDevice) {
2422
2422
  return callRouterAndroid({
2423
2423
  routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
2424
2424
  routerParam: getRouterParam,
2425
2425
  callBackName: getCallBackName,
2426
2426
  isSync: true,
2427
2427
  hasJdRouter: false,
2428
2428
  });
2429
2429
  } else {
2430
2430
  return callRouterIOS({
2431
2431
  routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
2432
2432
  routerParam: getRouterParam,
2433
2433
  callBackName: getCallBackName,
2434
2434
  isSync: true,
2435
2435
  });
2436
2436
  }
2437
2437
  }),
2438
2438
  this.taskTimeoutPromise(() => {
2439
2439
  return {
2440
2440
  status: '-1000',
2441
2441
  msg: '原生router协议获取lbs地址信息3s超时',
2442
2442
  };
2443
2443
  }, 3000),
2444
2444
  ]);
2445
2445
  } else {
2446
2446
  return Promise.resolve({
2447
2447
  status: '-1001',
2448
2448
  msg: '鸿蒙系统调用未实现,获取失败',
2449
2449
  });
2450
2450
  }
2451
2451
  } else if (isH5AndJingGouMini) {
2452
2452
  return this.getLocationForGpsPromise();
2453
2453
  } else {
2454
2454
  return Promise.resolve({
2455
2455
  status: '-1002',
2456
2456
  msg: '普通h5暂无业务需要,未实现,获取失败',
2457
2457
  });
2458
2458
  }
2459
2459
  }
2460
2460
  getLocationForGpsPromise() {
2461
2461
  return new Promise((resolve) => {
2462
2462
  let hasGetLocationForGps = true;
2463
2463
  if (urlCookie && urlCookie['loc']) {
2464
2464
  const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
2465
2465
  urlCookie['loc'].split('_');
2466
2466
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
2467
2467
  if (getProvinceIdNum && getProvinceIdNum > 0) {
2468
2468
  hasGetLocationForGps = false;
2469
2469
  resolve({
2470
2470
  status: '0',
2471
2471
  data: {
2472
2472
  provinceid,
2473
2473
  cityid,
2474
2474
  districtid,
2475
2475
  townid,
2476
2476
  origin: 'wxapp',
2477
2477
  },
2478
2478
  });
2479
2479
  }
2480
2480
  }
2481
2481
  if (hasGetLocationForGps && window?.navigator?.geolocation) {
2482
2482
  window.navigator.geolocation.getCurrentPosition(
2483
2483
  (position) => {
2484
2484
  console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
2485
2485
  if (position?.coords) {
2486
2486
  resolve({
2487
2487
  status: '0',
2488
2488
  data: {
2489
2489
  srclat: position.coords?.latitude,
2490
2490
  srclng: position.coords.longitude,
2491
2491
  origin: 'h5',
2492
2492
  },
2493
2493
  });
2494
2494
  } else {
2495
2495
  resolve({
2496
2496
  status: '-1001',
2497
2497
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
2498
2498
  position,
2499
2499
  });
2500
2500
  }
2501
2501
  },
2502
2502
  (error) => {
2503
2503
  resolve({
2504
2504
  status: '-1001',
2505
2505
  msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
2506
2506
  error,
2507
2507
  });
2508
2508
  },
2509
2509
  {
2510
2510
  enableHighAccuracy: false,
2511
2511
  timeout: 3 * 1000,
2512
2512
  maximumAge: 10 * 60 * 1000,
2513
2513
  },
2514
2514
  );
2515
2515
  } else {
2516
2516
  resolve({
2517
2517
  status: '-1001',
2518
2518
  msg: '您的浏览器不支持地理定位',
2519
2519
  });
2520
2520
  }
2521
2521
  });
2522
2522
  }
2523
2523
 
2524
2524
  createLbsCacheAddress(realTimeArea) {
2525
2525
  const getLbsAddressCacheMinuteTime = Number(
2526
2526
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
2527
2527
  );
2528
2528
  console.log(
2529
2529
  '获取lbs缓存到cookie的时间,分钟',
2530
2530
  getLbsAddressCacheMinuteTime,
2531
2531
  'lbsAddressCacheToCookieMinuteTime',
2532
2532
  window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
2533
2533
  );
2534
2534
  if (getLbsAddressCacheMinuteTime > 0) {
2535
2535
  const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
2536
2536
  realTimeArea &&
2537
2537
  cookie.set(cacheH5LbsAddressKey, realTimeArea, {
2538
2538
  path: '/',
2539
2539
  expires,
2540
2540
  });
2541
2541
  }
2542
2542
  }
2543
2543
 
2544
2544
  getLbsAddressCachePromise() {
2545
2545
  if (!this.lbsAddressCachePromise) {
2546
2546
  this.lbsAddressCachePromise = new Promise((resolve) => {
2547
2547
  const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
2548
2548
  ? cookie.get(cacheH5LbsAddressKey)
2549
2549
  : '';
2550
2550
  const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
2551
2551
  if (getUserLbsAddress && getUserLbsAddress !== '') {
2552
2552
  resolve({
2553
2553
  ok: true,
2554
2554
  realTimeArea: getUserLbsAddress,
2555
2555
  });
2556
2556
  } else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
2557
2557
  console.info(
2558
2558
  `通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
2559
2559
  getCookieForLbsAddress,
2560
2560
  );
2561
2561
  this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
2562
2562
  this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
2563
2563
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
2564
2564
  realTimeArea: getCookieForLbsAddress,
2565
2565
  });
2566
2566
  resolve({
2567
2567
  ok: true,
2568
2568
  realTimeArea: getCookieForLbsAddress,
2569
2569
  });
2570
2570
  } else {
2571
2571
  this.getLbsCacheAddressRouter()
2572
2572
  .then((res) => {
2573
2573
  const { status, data } = res;
2574
2574
  console.log(
2575
2575
  '原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
2576
2576
  status,
2577
2577
  data,
2578
2578
  res,
2579
2579
  );
2580
2580
  if (status === '0' && data) {
2581
2581
  const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
2582
2582
  data || {};
2583
2583
  let realTimeArea = '';
2584
2584
  this.info.sysInfo['srclat'] = `${srclat || ''}`;
2585
2585
  this.info.sysInfo['srclng'] = `${srclng || ''}`;
2586
2586
  const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
2587
2587
  if (getProvinceIdNum && getProvinceIdNum > 0) {
2588
2588
  realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
2589
2589
  this.info.pageInfo['userLbsAddress'] = realTimeArea;
2590
2590
  this.info.sysInfo['realTimeArea'] = realTimeArea;
2591
2591
  Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
2592
2592
  realTimeArea: this.info.pageInfo.userLbsAddress,
2593
2593
  });
2594
2594
  this.createLbsCacheAddress(realTimeArea);
2595
2595
  } else {
2596
2596
  !origin && (this.lbsAddressCachePromise = null);
2597
2597
  }
2598
2598
  const getValidRealTimeArea = realTimeArea !== '';
2599
2599
  resolve({
2600
2600
  lat: this.info.sysInfo['srclat'],
2601
2601
  lng: this.info.sysInfo['srclng'],
2602
2602
  realTimeArea: realTimeArea,
2603
2603
  ok: getValidRealTimeArea,
2604
2604
  msg: getValidRealTimeArea
2605
2605
  ? '成功'
2606
2606
  : origin
2607
2607
  ? origin
2608
2608
  : '根据router底层获取lbs地址信息异常,详情见data',
2609
2609
  data: getValidRealTimeArea ? null : res,
2610
2610
  });
2611
2611
  if (!getValidRealTimeArea && !origin) {
2612
2612
  draBusinessCustomReport({
2613
2613
  eventName: 'business',
2614
2614
  errorName: 'h5_getLbsCacheAddress_info_err',
2615
2615
  errorMessage:
2616
2616
  '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
2617
2617
  extraData: JSON.stringify({
2618
2618
  isJdApp,
2619
2619
  jdAppVersion: jdAppVersionStr,
2620
2620
  }),
2621
2621
  });
2622
2622
  }
2623
2623
  } else {
2624
2624
  typeof res === 'object' &&
2625
2625
  draBusinessCustomReport({
2626
2626
  eventName: 'business',
2627
2627
  errorName: 'h5_getLbsCacheAddress_info_err',
2628
2628
  errorMessage:
2629
2629
  'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
2630
2630
  extraData: JSON.stringify({
2631
2631
  isJdApp,
2632
2632
  jdAppVersion: jdAppVersionStr,
2633
2633
  ...res,
2634
2634
  }),
2635
2635
  });
2636
2636
  this.lbsAddressCachePromise = null;
2637
2637
  resolve({ realTimeArea: '', ok: false });
2638
2638
  }
2639
2639
  })
2640
2640
  .catch((e) => {
2641
2641
  console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
2642
2642
  this.lbsAddressCachePromise = null;
2643
2643
  draBusinessCustomReport({
2644
2644
  eventName: 'business',
2645
2645
  errorName: 'h5_getLbsCacheAddress_info_err',
2646
2646
  errorMessage:
2647
2647
  'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
2648
2648
  extraData: JSON.stringify({
2649
2649
  isJdApp,
2650
2650
  jdAppVersion: jdAppVersionStr,
2651
2651
  }),
2652
2652
  });
2653
2653
  resolve({ realTimeArea: '', ok: false });
2654
2654
  });
2655
2655
  }
2656
2656
  });
2657
2657
  }
2658
2658
  return this.lbsAddressCachePromise;
2659
2659
  }
2660
2660
 
2661
2661
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
2662
2662
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
2663
2663
  if (!isJdApp) {
2664
2664
  return;
2665
2665
  }
2666
2666
  const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
2667
2667
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
2668
2668
  const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
2669
2669
  'hybridHttpSwitch',
2670
2670
  isBeforePageReady,
2671
2671
  );
2672
2672
  const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
2673
2673
  'jshopIsVipShop',
2674
2674
  isBeforePageReady,
2675
2675
  );
2676
2676
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
2677
2677
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
2678
2678
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
2679
2679
  'isFollowAppVideoPlayStatus',
2680
2680
  isBeforePageReady,
2681
2681
  );
2682
2682
  console.log(
2683
2683
  'isBeforePageReady:',
2684
2684
  isBeforePageReady,
2685
2685
  'isFollowAppVideoPlayStatus:',
2686
2686
  isFollowAppVideoPlayStatus,
2687
2687
  );
2688
2688
  if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
2689
2689
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
2690
2690
  }
2691
2691
  }
2692
2692
 
2693
2693
  async getWifiVideoAutoPlayAsync() {
2694
2694
  this.info.sysInfo['wifiVideoAutoPlay'] = false;
2695
2695
  if (!isJdApp) {
2696
2696
  return;
2697
2697
  }
2698
2698
  const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
2699
2699
  return 0;
2700
2700
  });
2701
2701
  if (Number(videoPlayStatus) === 1) {
2702
2702
  this.info.sysInfo['wifiVideoAutoPlay'] = true;
2703
2703
  }
2704
2704
  }
2705
2705
 
2706
2706
  async getMPaasConfigAsync() {
2707
2707
  this.info.sysInfo.dynamicConfig = {};
2708
2708
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
2709
2709
  this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
2710
2710
  this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
2711
2711
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
2712
2712
  return this.updateMPaasConfigAsync(true);
2713
2713
  }
2714
2714
 
2715
2715
  getDynamicConfig(key: string) {
2716
2716
  return this.info.sysInfo?.dynamicConfig?.[key];
2717
2717
  }
2718
2718
  async updateMPaasConfig() {
2719
2719
  console.log('updateMPaasConfig');
2720
2720
  if (
2721
2721
  isIosDevice &&
2722
2722
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
2723
2723
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
2724
2724
  ) {
2725
2725
  try {
2726
2726
  await this.updateMPaasConfigAsync(false);
2727
2727
  } catch (e) {
2728
2728
  console.log('updateMPaasConfigAsync:', e);
2729
2729
  }
2730
2730
  }
2731
2731
  }
2732
2732
 
2733
2733
  toLogin(options) {
2734
2734
  if (isAscfApp) {
2735
2735
  return this.toAscfAppLogin(options);
2736
2736
  }
2737
2737
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
2738
2738
  ? this.toWxAppLogin(options)
2739
2739
  : this.toWebLogin(options);
2740
2740
  }
2741
2741
 
2742
2742
  doLogin(options) {
2743
2743
  return this.toLogin(options);
2744
2744
  }
2745
2745
 
2746
2746
  doLoginForJdPin(options = {}) {
2747
2747
  return this.doLogin({
2748
2748
  loginColor: {
2749
2749
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2750
2750
  dpin: 0,
2751
2751
  },
2752
2752
  ...options,
2753
2753
  });
2754
2754
  }
2755
2755
 
2756
2756
  toWebLogin(options) {
2757
2757
  let params: {
2758
2758
  returnurl: string;
2759
2759
  } = {
2760
2760
  returnurl: '',
2761
2761
  };
2762
2762
  const checkToPcLogin = options ? options?.isPc : isPc;
2763
2763
  const loginUrl = checkToPcLogin
2764
2764
  ? `//passport.jd.com/new/login.aspx`
2765
2765
  : `${domain.mobileLogin}/user/login.action`;
2766
2766
  const defaultParams = {
2767
2767
  appid: '100',
2768
2768
  returnurl: window.location.href,
2769
2769
  };
2770
2770
  if (isString(options)) {
2771
2771
  params = Object.assign({}, defaultParams, {
2772
2772
  returnurl: options,
2773
2773
  });
2774
2774
  } else if (isObject(options)) {
2775
2775
  const { loginColor, ...otherOptions } = options;
2776
2776
  params = Object.assign({}, defaultParams, otherOptions);
2777
2777
  } else {
2778
2778
  params = defaultParams;
2779
2779
  }
2780
2780
  params.returnurl = encodeURIComponent(params.returnurl);
2781
2781
  let getFullUrl = loginUrl + '?' + serialize(params);
2782
2782
  if (checkToPcLogin) {
2783
2783
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
2784
2784
  }
2785
2785
  return Promise.resolve({
2786
2786
  h5ToUrl: true,
2787
2787
  url: getFullUrl,
2788
2788
  }).then(() => {
2789
2789
  window.location.href = getFullUrl;
2790
2790
  });
2791
2791
  }
2792
2792
 
2793
2793
  toAscfAppLogin(options = {}) {
2794
2794
  console.log('华为元服务中h5登录跳转', options);
2795
2795
  return Promise.resolve(true).then(() => {
2796
2796
  const returnPage = encodeURIComponent(window.location.href);
2797
2797
  if (has && has.ascfweb) {
2798
2798
  has.ascfweb.redirectTo({
2799
2799
  url: `/pages/login/index/index?isH5=1&returnPage=${returnPage}&pageType=h5&source=shopx`,
2800
2800
  });
2801
2801
  }
2802
2802
  });
2803
2803
  }
2804
2804
 
2805
2805
  toWxAppLogin(options = {}) {
2806
2806
  console.log('微信京购小程序中h5登录跳转', options);
2807
2807
  return Promise.resolve(true).then(() => {
2808
2808
  const { loginColor } = Object.assign(
2809
2809
  {},
2810
2810
  {
2811
2811
  loginColor: {
2812
2812
  biz: WXAPP_BIZ_KEY,
2813
2813
  dpin: 1,
2814
2814
  },
2815
2815
  },
2816
2816
  options,
2817
2817
  );
2818
2818
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
2819
2819
  loginColor.biz
2820
2820
  }&url=${encodeURIComponent(window.location.href)}`;
2821
2821
  });
2822
2822
  }
2823
2823
 
2824
2824
  getLoginCookie() {
2825
2825
  return Promise.resolve({
2826
2826
  pin: cookie.get('pin') || '',
2827
2827
  });
2828
2828
  }
2829
2829
 
2830
2830
  clearLoginCookie() {
2831
2831
  cookie.remove('pin');
2832
2832
  }
2833
2833
 
2834
2834
  checkStatusAndLogin(options = {}) {
2835
2835
  if (!this.checkStatusAndLoginPromise) {
2836
2836
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
2837
2837
  try {
2838
2838
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2839
2839
  if (getLoginState) {
2840
2840
  resolve(true);
2841
2841
  } else {
2842
2842
  this.toLogin(options);
2843
2843
  reject(false);
2844
2844
  }
2845
2845
  } catch (e) {
2846
2846
  this.toLogin(options);
2847
2847
  reject(false);
2848
2848
  }
2849
2849
  });
2850
2850
  return this.checkStatusAndLoginPromise;
2851
2851
  } else {
2852
2852
  return this.checkStatusAndLoginPromise
2853
2853
  .then(() => {
2854
2854
  return Promise.resolve(true);
2855
2855
  })
2856
2856
  .catch(() => {
2857
2857
  this.toLogin(options);
2858
2858
  return Promise.reject(true);
2859
2859
  });
2860
2860
  }
2861
2861
  }
2862
2862
 
2863
2863
  checkJdStatusAndLogin(
2864
2864
  options = {
2865
2865
  loginColor: {
2866
2866
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
2867
2867
  dpin: 0,
2868
2868
  },
2869
2869
  },
2870
2870
  ) {
2871
2871
  return this.checkStatusAndLogin(options);
2872
2872
  }
2873
2873
 
2874
2874
  doCheckLoginStateAndForApiCheck(options) {
2875
2875
  if (this.info.loginState) {
2876
2876
  return Promise.resolve(true);
2877
2877
  } else {
2878
2878
  return new Promise((resolve, reject) => {
2879
2879
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
2880
2880
  const getWqAuthToken = cookie.get('wq_auth_token');
2881
2881
  const getWqSkey = cookie.get('wq_skey');
2882
2882
  const getWqUin = cookie.get('wq_uin');
2883
2883
  const isLoginState =
2884
2884
  options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
2885
2885
  if (isLoginState) {
2886
2886
  this.info.loginState = true;
2887
2887
  resolve(true);
2888
2888
  } else {
2889
2889
  reject(false);
2890
2890
  }
2891
2891
  } else {
2892
2892
  Taro.request({
2893
2893
  url: api.isLogin,
2894
2894
  jsonp: true,
2895
2895
  timeout: 3000,
2896
2896
  success: (res) => {
2897
2897
  const { statusCode, data } = res;
2898
2898
  if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
2899
2899
  this.info.loginState = true;
2900
2900
  resolve(true);
2901
2901
  } else {
2902
2902
  reject(false);
2903
2903
  }
2904
2904
  },
2905
2905
  fail: (err) => {
2906
2906
  console.log('登录检查异常', err);
2907
2907
  reject(false);
2908
2908
  },
2909
2909
  });
2910
2910
  }
2911
2911
  });
2912
2912
  }
2913
2913
  }
2914
2914
 
2915
2915
  checkLoginStatus(options) {
2916
2916
  return new Promise(async (resolve, reject) => {
2917
2917
  try {
2918
2918
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
2919
2919
  if (getLoginState) {
2920
2920
  const { pin } = await this.getLoginCookie();
2921
2921
  this.info.userInfo = {
2922
2922
  pin,
2923
2923
  encodePin: encodeURIComponent(pin),
2924
2924
  ptkey: '',
2925
2925
  };
2926
2926
  resolve(true);
2927
2927
  } else {
2928
2928
  reject(false);
2929
2929
  }
2930
2930
  } catch (e) {
2931
2931
  reject(false);
2932
2932
  }
2933
2933
  });
2934
2934
  }
2935
2935
 
2936
2936
  updatePageAndLogInfo(updateQuery = {}) {
2937
2937
  const createUpdateQueryInfo: {
2938
2938
  query: {
2939
2939
  shopId?: string | number;
2940
2940
  venderId?: string | number;
2941
2941
  };
2942
2942
  updateShopInfoState: boolean;
2943
2943
  } = Object.assign(
2944
2944
  {},
2945
2945
  {
2946
2946
  query: {},
2947
2947
  updateShopInfoState: false,
2948
2948
  },
2949
2949
  updateQuery,
2950
2950
  );
2951
2951
  console.log(
2952
2952
  '获取当前下发的店铺查询参数',
2953
2953
  updateQuery,
2954
2954
  '获取之前保存的shopInfo店铺查询参数',
2955
2955
  this.info?.shopInfo,
2956
2956
  );
2957
2957
  const { query, updateShopInfoState } = createUpdateQueryInfo;
2958
2958
  const { shopId, venderId, un_area } = query;
2959
2959
  if (updateShopInfoState) {
2960
2960
  this.info.queryInfo = {
2961
2961
  ...this.info.queryInfo,
2962
2962
  ...query,
2963
2963
  };
2964
2964
  if (shopId && venderId) {
2965
2965
  this.info.shopInfo = {
2966
2966
  shopId: `${shopId}`,
2967
2967
  venderId: `${venderId}`,
2968
2968
  };
2969
2969
  }
2970
2970
  } else {
2971
2971
  this.info.queryInfo = {
2972
2972
  ...query,
2973
2973
  };
2974
2974
  if (
2975
2975
  this.info.shopInfo?.shopId &&
2976
2976
  this.info.shopInfo?.venderId &&
2977
2977
  (this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
2978
2978
  ) {
2979
2979
  this.info.queryInfo.shopId = this.info.shopInfo.shopId;
2980
2980
  this.info.queryInfo.venderId = this.info.shopInfo.venderId;
2981
2981
  console.log(
2982
2982
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
2983
2983
  this.info.queryInfo,
2984
2984
  );
2985
2985
  }
2986
2986
  }
2987
2987
  this.info.queryInfo['shopId'] &&
2988
2988
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
2989
2989
  this.info.queryInfo['venderId'] &&
2990
2990
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
2991
2991
  console.log(
2992
2992
  'h5==获取店铺下发查询参数\n',
2993
2993
  query,
2994
2994
  '\n获取店铺最后查询参数\n',
2995
2995
  this.info.queryInfo,
2996
2996
  '\n是否为更新店铺状态\n',
2997
2997
  updateShopInfoState,
2998
2998
  );
2999
2999
  const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
3000
3000
  if (changeArea) {
3001
3001
  const getBottomAreaStr = changeArea.replace(/-/g, '_');
3002
3002
  this.info.pageInfo.address = getBottomAreaStr;
3003
3003
  this.info.pageInfo.un_area = getBottomAreaStr;
3004
3004
  this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
3005
3005
  }
3006
3006
  }
3007
3007
 
3008
3008
  dealLoadSdkList() {
3009
3009
  const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
3010
3010
  const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
3011
3011
  const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
3012
3012
  let mergeLoadJsList = globalLoadJsList;
3013
3013
  try {
3014
3014
  mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
3015
3015
  const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
3016
3016
  getFindIndex !== -1
3017
3017
  ? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
3018
3018
  : accArr.push(current);
3019
3019
  return accArr;
3020
3020
  }, []);
3021
3021
  } catch (e) {
3022
3022
  console.log('LoadJsList合并错误', e);
3023
3023
  }
3024
3024
  console.log(
3025
3025
  'globalLoadJsList',
3026
3026
  globalLoadJsList,
3027
3027
  'businessLoadJsList',
3028
3028
  businessLoadJsList,
3029
3029
  '两个加载jsList集合合并完成',
3030
3030
  mergeLoadJsList,
3031
3031
  );
3032
3032
  this.loadJsSdkList = mergeLoadJsList;
3033
3033
  return this.loadJsSdkList;
3034
3034
  }
3035
3035
 
3036
3036
  renderNextTickLoadSdk(delayTime = 1000) {
3037
3037
  Taro.nextTick(() => {
3038
3038
  console.log(
3039
3039
  '页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
3040
3040
  );
3041
3041
  setTimeout(() => {
3042
3042
  this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
3043
3043
  }, delayTime);
3044
3044
  });
3045
3045
  }
3046
3046
 
3047
3047
  async loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
3048
3048
  const getLoadJsList =
3049
3049
  Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
3050
3050
  const getLoadFilterList = getLoadJsList.filter((item) => {
3051
3051
  if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
3052
3052
  item.initLoadType = undefined;
3053
3053
  }
3054
3054
  const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
3055
3055
  let getLoastLoadEventState = true;
3056
3056
  if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
3057
3057
  getLoastLoadEventState = isJdApp;
3058
3058
  }
3059
3059
  else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
3060
3060
  getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
3061
3061
  }
3062
3062
  const getInitTriggerType =
3063
3063
  isJdApp && item?.initJdAppTriggerType
3064
3064
  ? item?.initTriggerType
3065
3065
  : item?.initTriggerType || LoadJsInitTriggerType.NOW;
3066
3066
  const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
3067
3067
  return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
3068
3068
  });
3069
3069
  console.log(
3070
3070
  '获取当前触发方式',
3071
3071
  triggerType,
3072
3072
  '获取当前最后加载的js集合',
3073
3073
  getLoadFilterList,
3074
3074
  '过滤前的加载集合',
3075
3075
  getLoadJsList,
3076
3076
  );
3077
3077
  const loadTasks =
3078
3078
  getLoadFilterList.length > 0
3079
3079
  ? getLoadFilterList.map((item) => {
3080
3080
  const isLoadState = /sgm/.test(item?.fileName)
3081
3081
  ? window?.shopGlobalSwitch?.openSgm === 'true'
3082
3082
  : true;
3083
3083
  if (!isLoadState) {
3084
3084
  return Promise.resolve(true);
3085
3085
  }
3086
3086
  return this.loadItemSdkPromise(item)
3087
3087
  .then((res) => {
3088
3088
  console.info('当前js地址' + item?.src, '加载状态', res);
3089
3089
  const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
3090
3090
  if (isFileNameNewDraSdkJs && window?.dra?.run) {
3091
3091
  const getNewdraEnableShopIdPercentObj =
3092
3092
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || null;
3093
3093
  const getNewdraEnableVenderIdPercentObj =
3094
3094
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || null;
3095
3095
  let canInitDraRun = true;
3096
3096
  if (getNewdraEnableShopIdPercentObj || getNewdraEnableVenderIdPercentObj) {
3097
3097
  canInitDraRun = this.shouldPercentExecuteNewDra(
3098
3098
  this.getNewDraEnablePercentNum(),
3099
3099
  );
3100
3100
  }
3101
3101
  if (canInitDraRun) {
3102
3102
  window.dra.run('init', { aid: res?.aid });
3103
3103
  window.dra.run('start');
3104
3104
  }
3105
3105
  }
3106
3106
  return true;
3107
3107
  })
3108
3108
  .catch((err) => {
3109
3109
  console.info('当前js地址加载异常', item?.src);
3110
3110
  window?.fetchErrorData &&
3111
3111
  window.fetchErrorData({
3112
3112
  title: '公共js加载异常',
3113
3113
  type: 'jsLoad',
3114
3114
  data: err,
3115
3115
  });
3116
3116
  return true;
3117
3117
  });
3118
3118
  })
3119
3119
  : [];
3120
3120
  return loadTasks.length ? Promise.allSettled(loadTasks) : Promise.resolve([]);
3121
3121
  }
3122
3122
 
3123
3123
  shouldPercentExecuteNewDra(percent) {
3124
3124
  if (percent <= 0) return false;
3125
3125
  if (percent >= 100) return true;
3126
3126
  const getRes = Math.random() < percent / 100;
3127
3127
  console.log('获取dra初始化执行的概率为', percent, '执行结果', getRes);
3128
3128
  return getRes;
3129
3129
  }
3130
3130
 
3131
3131
  getNewDraEnablePercentNum() {
3132
3132
  const getNewdraEnableShopIdPercent =
3133
3133
  window?.PAGE_DATA?.businessData?.newDraEnableShopIdPercent || {};
3134
3134
  const getNewdraEnableVenderIdPercent =
3135
3135
  window?.PAGE_DATA?.businessData?.newDraEnableVenderIdPercent || {};
3136
3136
  const getShopId = parseQueryUrlObj?.shopId || '';
3137
3137
  const getVenderId = parseQueryUrlObj?.venderId || '';
3138
3138
  const getShopIdDraEnablePercent = getNewdraEnableShopIdPercent[getShopId]
3139
3139
  ? getNewdraEnableShopIdPercent[getShopId]
3140
3140
  : getNewdraEnableShopIdPercent?.ids?.includes(getShopId)
3141
3141
  ? getNewdraEnableShopIdPercent?.idsNumber
3142
3142
  : -1;
3143
3143
  const getVenderIdDraEnablePercent = getNewdraEnableVenderIdPercent[getVenderId]
3144
3144
  ? getNewdraEnableVenderIdPercent[getVenderId]
3145
3145
  : getNewdraEnableVenderIdPercent?.ids?.includes(getVenderId)
3146
3146
  ? getNewdraEnableVenderIdPercent?.idsNumber
3147
3147
  : -1;
3148
3148
  if (getShopIdDraEnablePercent > -1 || getVenderIdDraEnablePercent > -1) {
3149
3149
  return getShopIdDraEnablePercent || getVenderIdDraEnablePercent;
3150
3150
  }
3151
3151
  return 100;
3152
3152
  }
3153
3153
  loadScriptEle(jsInfo, resolve, reject) {
3154
3154
  const getFileName = jsInfo?.fileName;
3155
3155
  if (getFileName) {
3156
3156
  const getEleId = `J_loadJs_${getFileName}`;
3157
3157
  const getEle = document.getElementById(getEleId);
3158
3158
  if (!getEle) {
3159
3159
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
3160
3160
  const _sgmEle = document.createElement('script');
3161
3161
  _sgmEle.id = getEleId;
3162
3162
  _sgmEle.onload = function () {
3163
3163
  resolve({
3164
3164
  ...jsInfo,
3165
3165
  jsTip: 'js加载成功',
3166
3166
  });
3167
3167
  };
3168
3168
  _sgmEle.onerror = function () {
3169
3169
  reject({
3170
3170
  ...jsInfo,
3171
3171
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3172
3172
  jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
3173
3173
  });
3174
3174
  };
3175
3175
  const dataAttrList = ['timeout', 'fileName', 'env'];
3176
3176
  const getJsInfoKeyList = Object.keys(jsInfo);
3177
3177
  getJsInfoKeyList.forEach((key) => {
3178
3178
  if (key === 'async') {
3179
3179
  _sgmEle.async = jsInfo[key];
3180
3180
  } else if (key === 'crossOrigin') {
3181
3181
  _sgmEle.crossOrigin = jsInfo[key];
3182
3182
  } else if (key === 'src') {
3183
3183
  _sgmEle.src = `${jsInfo[key]}`;
3184
3184
  } else if (dataAttrList.includes(key) || /init/.test(key)) {
3185
3185
  _sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
3186
3186
  } else {
3187
3187
  _sgmEle.setAttribute(key, jsInfo[key]);
3188
3188
  }
3189
3189
  });
3190
3190
  document.head.appendChild(_sgmEle);
3191
3191
  } else {
3192
3192
  console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
3193
3193
  resolve({
3194
3194
  ...jsInfo,
3195
3195
  jsTip: 'js本身已存在页面中',
3196
3196
  });
3197
3197
  }
3198
3198
  } else {
3199
3199
  console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
3200
3200
  }
3201
3201
  }
3202
3202
 
3203
3203
  loadItemSdkPromise(jsInfo: Record<string, any> = {}): Promise<any> {
3204
3204
  if (jsInfo?.src) {
3205
3205
  const getInitLoadType =
3206
3206
  isJdApp && jsInfo?.initJdAppLoadType
3207
3207
  ? jsInfo?.initJdAppLoadType
3208
3208
  : jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
3209
3209
  if (getInitLoadType !== LoadJsInitLoadType.NONE) {
3210
3210
  const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
3211
3211
  if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
3212
3212
  if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
3213
3213
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
3214
3214
  const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
3215
3215
  try {
3216
3216
  const jsXhrRequest = new XMLHttpRequest();
3217
3217
  jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
3218
3218
  const jsUrl = `${jsInfo?.src}`;
3219
3219
  jsXhrRequest.open('GET', jsUrl, true);
3220
3220
  jsXhrRequest.onreadystatechange = () => {
3221
3221
  if (jsXhrRequest.readyState === 4) {
3222
3222
  const getReqStatus = jsXhrRequest.status;
3223
3223
  const statusText = jsXhrRequest.statusText;
3224
3224
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
3225
3225
  const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
3226
3226
  if (getInsetHeadState) {
3227
3227
  this.loadScriptEle(jsInfo, resolve, reject);
3228
3228
  } else {
3229
3229
  resolve({
3230
3230
  ...jsInfo,
3231
3231
  jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
3232
3232
  });
3233
3233
  }
3234
3234
  getReqStatus !== 200 &&
3235
3235
  draBusinessCustomReport({
3236
3236
  eventName: 'business',
3237
3237
  errorName: 'js_load_special_code',
3238
3238
  errorMessage: '当前js加载成功,状态非200,特殊上报观察',
3239
3239
  extraData: JSON.stringify({
3240
3240
  msg: '当前js加载成功,状态非200,特殊上报观察',
3241
3241
  jsReqState: getReqStatus,
3242
3242
  env: getSgmCustomCode('js_load_special_code'),
3243
3243
  data: jsInfo,
3244
3244
  }),
3245
3245
  });
3246
3246
  } else {
3247
3247
  const getRes = {
3248
3248
  ...jsInfo,
3249
3249
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3250
3250
  jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
3251
3251
  jsReqState: getReqStatus,
3252
3252
  };
3253
3253
  console.log('当前js请求状态异常,具体信息见', getRes);
3254
3254
  reject(getRes);
3255
3255
  }
3256
3256
  }
3257
3257
  };
3258
3258
  jsXhrRequest.onerror = () => {
3259
3259
  const getRes = {
3260
3260
  ...jsInfo,
3261
3261
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3262
3262
  jsReqError: '请求错误',
3263
3263
  };
3264
3264
  console.log('当前js请求错误', getRes);
3265
3265
  jsXhrRequest.abort();
3266
3266
  reject(getRes);
3267
3267
  };
3268
3268
  jsXhrRequest.ontimeout = () => {
3269
3269
  const getRes = {
3270
3270
  ...jsInfo,
3271
3271
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3272
3272
  jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
3273
3273
  jsReqState: jsXhrRequest.status,
3274
3274
  };
3275
3275
  console.log('当前js请求超时异常', getRes);
3276
3276
  jsXhrRequest.abort();
3277
3277
  reject(getRes);
3278
3278
  };
3279
3279
  jsXhrRequest.send();
3280
3280
  } catch (e) {
3281
3281
  console.log('执行js请求异常', e);
3282
3282
  reject({
3283
3283
  ...jsInfo,
3284
3284
  env: getSgmCustomCode(jsLoadErrorSgmCode),
3285
3285
  jsReqError: '未知异常',
3286
3286
  error: e,
3287
3287
  });
3288
3288
  }
3289
3289
  });
3290
3290
  } else {
3291
3291
  this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
3292
3292
  return this.loadScriptEle(jsInfo, resolve, reject);
3293
3293
  });
3294
3294
  }
3295
3295
  }
3296
3296
  return this.loadJsSdkListCachePromise[getFileKeyName];
3297
3297
  } else {
3298
3298
  return Promise.resolve({
3299
3299
  ...jsInfo,
3300
3300
  jsTip: 'js加载方式设置为不加载,当前不做处理',
3301
3301
  });
3302
3302
  }
3303
3303
  } else {
3304
3304
  return Promise.reject(jsInfo);
3305
3305
  }
3306
3306
  }
3307
3307
 
3308
3308
  createLanguagePromise() {
3309
3309
  const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
3310
3310
  if (!this.languageCacheProimse) {
3311
3311
  this.languageCacheProimse = new Promise((resolve, reject) => {
3312
3312
  const { fileName, prefixUrl } = getLanguageConfig;
3313
3313
  console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
3314
3314
  const dealLanguageFile = () => {
3315
3315
  this.getLanguageFilePromise(getLanguageConfig, languageNowType)
3316
3316
  .then((res: any) => {
3317
3317
  if (res && res?.data) {
3318
3318
  this.languageJsonData = res.data;
3319
3319
 
3320
3320
  setTimeout(() => {
3321
3321
  const getOtherLanguageList = languageTypeList.filter(
3322
3322
  (item) => item !== languageNowType,
3323
3323
  );
3324
3324
  getOtherLanguageList.length > 0 &&
3325
3325
  getOtherLanguageList.map((languageTypeKey) => {
3326
3326
  this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
3327
3327
  });
3328
3328
  }, 3000);
3329
3329
  resolve(res);
3330
3330
  } else {
3331
3331
  reject(res);
3332
3332
  }
3333
3333
  })
3334
3334
  .catch((err) => {
3335
3335
  reject(err);
3336
3336
  });
3337
3337
  };
3338
3338
  if (fileName && prefixUrl) {
3339
3339
  const getLangStorageKey = `jshopx_lang_${languageNowType}`;
3340
3340
  const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
3341
3341
  if (getLocalLangRes) {
3342
3342
  try {
3343
3343
  const getLocalLangJsonData =
3344
3344
  typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
3345
3345
  if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
3346
3346
  if (getLocalLangJsonData?.fileName === fileName) {
3347
3347
  const geThisLangData = getLocalLangJsonData.data;
3348
3348
  this.languageJsonData = geThisLangData;
3349
3349
  return resolve({
3350
3350
  ...getLanguageConfig,
3351
3351
  languageNowType,
3352
3352
  data: geThisLangData,
3353
3353
  });
3354
3354
  } else {
3355
3355
  dealLanguageFile();
3356
3356
  }
3357
3357
  } else {
3358
3358
  dealLanguageFile();
3359
3359
  }
3360
3360
  } catch (e) {
3361
3361
  return reject({
3362
3362
  languageNowType,
3363
3363
  msg: '转换错误',
3364
3364
  ...getLanguageConfig,
3365
3365
  });
3366
3366
  }
3367
3367
  } else {
3368
3368
  dealLanguageFile();
3369
3369
  }
3370
3370
  } else {
3371
3371
  return reject({
3372
3372
  languageNowType,
3373
3373
  msg: '文件对象下发异常',
3374
3374
  ...getLanguageConfig,
3375
3375
  });
3376
3376
  }
3377
3377
  });
3378
3378
  }
3379
3379
  return this.languageCacheProimse;
3380
3380
  }
3381
3381
 
3382
3382
  getLanguageFilePromise(info, languageTypeKey) {
3383
3383
  const { fileName, prefixUrl, timeout } = info || {};
3384
3384
  const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
3385
3385
  return new Promise((resolve, reject) => {
3386
3386
  const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
3387
3387
  try {
3388
3388
  const langXhrRequest = new XMLHttpRequest();
3389
3389
  langXhrRequest.timeout = timeout || 2000;
3390
3390
  langXhrRequest.open('GET', getUrl, true);
3391
3391
  langXhrRequest.responseType = 'json';
3392
3392
  langXhrRequest.onreadystatechange = () => {
3393
3393
  if (langXhrRequest.readyState === 4) {
3394
3394
  const getReqStatus = langXhrRequest.status;
3395
3395
  const statusText = langXhrRequest.statusText;
3396
3396
  if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
3397
3397
  const getData = langXhrRequest?.response || false;
3398
3398
  if (getData) {
3399
3399
  setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
3400
3400
  fileName,
3401
3401
  data: getData,
3402
3402
  });
3403
3403
  resolve({
3404
3404
  ...info,
3405
3405
  languageTypeKey,
3406
3406
  data: getData,
3407
3407
  });
3408
3408
  } else {
3409
3409
  reject({
3410
3410
  ...info,
3411
3411
  languageTypeKey,
3412
3412
  msg: '数据获取异常',
3413
3413
  });
3414
3414
  }
3415
3415
  } else {
3416
3416
  const getRes = {
3417
3417
  ...info,
3418
3418
  languageTypeKey,
3419
3419
  env: getSgmCustomCode(langLoadErrorSgmCode),
3420
3420
  msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
3421
3421
  };
3422
3422
  console.log('当前lang请求状态异常,具体信息见', getRes);
3423
3423
  reject(getRes);
3424
3424
  }
3425
3425
  }
3426
3426
  };
3427
3427
  langXhrRequest.onerror = () => {
3428
3428
  const getRes = {
3429
3429
  ...info,
3430
3430
  env: getSgmCustomCode(langLoadErrorSgmCode),
3431
3431
  msg: '请求错误',
3432
3432
  };
3433
3433
  console.log('当前lang请求错误', getRes);
3434
3434
  langXhrRequest.abort();
3435
3435
  reject(getRes);
3436
3436
  };
3437
3437
  langXhrRequest.ontimeout = () => {
3438
3438
  const getRes = {
3439
3439
  ...info,
3440
3440
  msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
3441
3441
  };
3442
3442
  console.log('执行lang多语言请求超时异常', getRes);
3443
3443
  langXhrRequest.abort();
3444
3444
  reject(getRes);
3445
3445
  };
3446
3446
  langXhrRequest.send();
3447
3447
  } catch (e) {
3448
3448
  console.log('执行lang多语言请求异常', e);
3449
3449
  reject({
3450
3450
  ...info,
3451
3451
  env: getSgmCustomCode(langLoadErrorSgmCode),
3452
3452
  msg: '未知异常',
3453
3453
  error: e,
3454
3454
  });
3455
3455
  }
3456
3456
  });
3457
3457
  }