@conecli/cone-render 0.9.1-shop2.4 → 0.9.1-shop2.40

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