@conecli/cone-render 0.9.1-shop2.8 → 0.10.1-beta.0

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 (56) 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/sgmCustomCode.ts +1 -0
  11. package/dist/common/wxappApi.jd.ts +1 -0
  12. package/dist/components/ErrorBoundary.tsx +1 -1
  13. package/dist/components/base/CustomScrollView/index.jd.tsx +1 -0
  14. package/dist/components/base/CustomScrollView/index.module.scss +7 -0
  15. package/dist/components/base/CustomVideo/index.tsx +1 -1
  16. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  17. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  18. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  19. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  20. package/dist/components/debug/DebugLayout/index.module.scss +67 -0
  21. package/dist/components/debug/DebugLayout/index.tsx +1 -0
  22. package/dist/components/debug/DebugLayout/utils.ts +1 -0
  23. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  24. package/dist/components/floorItem.jd.tsx +1 -1
  25. package/dist/components/floorItem.weapp.tsx +1 -1
  26. package/dist/components/isv/Floor/index.tsx +1 -1
  27. package/dist/components/remoteFloorItem.tsx +1 -1
  28. package/dist/interface/common.ts +1 -1
  29. package/dist/interface/component.ts +1 -1
  30. package/dist/interface/jumpEventReport.ts +1 -1
  31. package/dist/interface/service.ts +1 -1
  32. package/dist/interface/utils.ts +1 -1
  33. package/dist/jumpEventReport/base.ts +1 -1
  34. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  35. package/dist/jumpEventReport/index.h5.ts +1 -1
  36. package/dist/jumpEventReport/index.jd.ts +1 -1
  37. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  38. package/dist/jumpEventReport/web.jxwxapp.ts +1 -0
  39. package/dist/jumpEventReport/web.tjapp.ts +1 -0
  40. package/dist/jumpEventReport/web.tjm.ts +1 -0
  41. package/dist/open/api/environment.ts +1 -1
  42. package/dist/open/api/index.ts +1 -1
  43. package/dist/open/api/track.ts +1 -1
  44. package/dist/sass/app.h5.scss +5 -0
  45. package/dist/service/requestServer.ts +1 -1
  46. package/dist/utils/connectNativeJsBridge.ts +1 -1
  47. package/dist/utils/draExceptionAndProfile.ts +1 -1
  48. package/dist/utils/h5Utils.ts +1 -1
  49. package/dist/utils/index.h5.ts +1 -1
  50. package/dist/utils/index.ts +1 -1
  51. package/dist/utils/index.weapp.ts +1 -1
  52. package/dist/utils/jm-common.js +1 -1
  53. package/dist/utils/sgmCodeUtils.ts +1 -0
  54. package/dist/utils/utils.ts +1 -1
  55. package/package.json +42 -39
  56. package/dist/customHooks/useDocumentVisibilitychange.ts +0 -1
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  isJdApp,
3
2
  isAndroidDevice,
4
3
  isJdAndAndroidDevice,
5
4
  jdAppVersion,
6
5
  jdAppVersionStr,
7
6
  isString,
8
7
  isObject,
9
8
  serialize,
10
9
  dealNativePixelToCssPixel
11
10
  BUSINESS_TYPE,
12
11
  JSSDK_APP_WEBVIEW_CODE,
13
12
  SECTION_HOME_TAB_NAME_TYPE,
14
13
  SECTION_HOME_TAB_TYPE,
15
14
  WX_BUSINESS_TYPE,
16
15
  WXAPP_BIZ_KEY,
17
16
  WXAPP_BIZ_SHOP_LIGHT_KEY
18
17
  loginState: false,
19
18
  cookiesStr: '',
20
19
  userInfo: userPinKey,
21
20
  isJingGouMiniViewState: false,
22
21
  pageInfo: {
23
22
  wxBusinessType: WX_BUSINESS_TYPE.NO,
24
23
  address: '',
25
24
  addressCommaStr: '',
26
25
  un_area: '',
27
26
  vapptype: '1',
28
27
  pageType: 'home',
29
28
  isExposureState: false,
30
29
  moduleId: '',
31
30
  entrance: '',
32
31
  dataType: BUSINESS_TYPE.ONLINE,
33
32
  floorExposureInfo: {},
34
33
  floorVideInfo: {},
35
34
  productVideInfo: {},
36
35
  tabsLoadAllDataInfo: {
37
36
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]:
38
37
  false,
39
38
  },
40
39
  updateShopInfosAllState: false,
41
40
  isVipShop: false,
42
41
  isJdShowNativeImmersivePlayer: false,
43
42
  ...shopConfig,
44
43
  pageScrollTop: 0,
45
44
  pageIdxHeightInfo: {
46
45
  list: []
47
46
  },
48
47
  shopNavBarHeight: 0,
49
48
  },
50
49
  defaultQueryLogInfo: {
51
50
  sourceType: 'JDshop',
52
51
  sourceValue: '',
53
52
  moduleId: 'none',
54
53
  entrance: 'none',
55
54
  },
56
55
  sysInfo: {
57
56
  windowWidth: isPc ? 375 : 0,
58
57
  containerWidth: isPc ? 375 : 0,
59
58
  windowHeight: 0,
60
59
  netWorkType: '4g',
61
60
  jdBottomBarHeight: 0,
62
61
  jdNativeHeaderHeight: 0,
63
62
  },
64
63
  queryInfo: {},
65
64
  shopInfo: {},
66
65
  openAppData: {}
67
66
  public info: CommonInterFace.BaseConfigInfo
68
67
  public config: {
69
68
  [key: string]: any
70
69
  }
71
70
  public lazyContainer: CommonInterFace.lazyContainer
72
71
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
73
72
  public rootEleNode: HTMLElement | null
74
73
  public checkStatusAndLoginPromise: object | null
75
74
  private jmfeRegisterStatePromise: object | null
76
75
  private jmfeRegisterState: boolean
77
76
  constructor(opt) {
78
77
  this.info = this._getConfig(opt)
79
78
  this.config = {}
80
79
  this.lazyContainer = {
81
80
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
82
81
  appLazyContainerList: [],
83
82
  appLazyFinishContainerList: [],
84
83
  },
85
84
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
86
85
  appLazyContainerList: [],
87
86
  appLazyFinishContainerList: [],
88
87
  },
89
88
  }
90
89
  this.renderedIsvComponents = {}
91
90
  this.rootEleNode = document.querySelector('body')
92
91
  this.checkStatusAndLoginPromise = null
93
92
  this.jmfeRegisterStatePromise = null
94
93
  isJdApp && this.jmfeReayPromise()
95
94
  }
96
95
  _getConfig(opt) {
97
96
  return Object.assign({}, DefaultConfig, opt)
98
97
  }
99
98
 
100
99
  jmfeReayPromise() {
101
100
  if(this.jmfeRegisterState){
102
101
  return Promise.resolve(true)
103
102
  }else {
104
103
  !this.jmfeRegisterStatePromise && (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
105
104
  ready('jmfe', 3000).then(() => {
106
105
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
107
106
  this.jmfeRegisterState = true
108
107
  resolve(true)
109
108
  console.log('松果app内初始化注册jmfe认证完成')
110
109
  }).catch(() => {
111
110
  reject(false)
112
111
  })
113
112
  }))
114
113
  return this.jmfeRegisterStatePromise
115
114
  }
116
115
  }
117
116
 
118
117
  updateBusinessDomainAndApi(domain, api) {
119
118
  }
120
119
 
121
120
  formatNativeScreenPageData(action) {
122
121
  let getChangePageInfo: any = null
123
122
  try {
124
123
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(JSON.stringify({
125
124
  plugin: "JDHybridScreenPlugin",
126
125
  action,
127
126
  sync: "1"
128
127
  }));
129
128
  const getChangePageInfoData = typeof getNativeScreenPageInfoStr === 'string' ? JSON.parse(getNativeScreenPageInfoStr) : null
130
129
  if(getChangePageInfoData && typeof getChangePageInfoData === 'object'){
131
130
  const { code, data} = getChangePageInfoData
132
131
  getChangePageInfo = code && code === "0" ? data : null;
133
132
  }
134
133
  }catch (e) {
135
134
  console.log("JDHybridScreenPlugin转换异常", e)
136
135
  }
137
136
  return getChangePageInfo
138
137
  }
139
138
 
140
139
  isAndroidFoldScreen() {
141
140
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
142
141
  }
143
142
 
144
143
  getJdAndroidPageChangeScreenInfo() {
145
144
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
146
145
  if(getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight){
147
146
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
148
147
  pageWidth: getPageScreenInfo.pageWidth,
149
148
  pageHeight: getPageScreenInfo.pageHeight
150
149
  })
151
150
  getPageScreenInfo.pageWidth = pageWidth
152
151
  getPageScreenInfo.pageHeight = pageHeight
153
152
  }
154
153
  return getPageScreenInfo
155
154
  }
156
155
 
157
156
  getSystemInfo(params) {
158
157
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
159
158
  ? {}
160
159
  : getSystemInfos(params)
161
160
  if(isJdAndAndroidDevice && window.innerWidth <= 0){
162
161
  const isfoldScreen = this.isAndroidFoldScreen()
163
162
  if(isfoldScreen){
164
163
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
165
164
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
166
165
  console.info("安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取",getJdAndroidPageInfo)
167
166
  }
168
167
  }
169
168
  this.info.sysInfo = {
170
169
  actualNavBarHeight: 0,
171
170
  ...this.info.sysInfo,
172
171
  ...info,
173
172
  safeContentHeight: info?.screenHeight,
174
173
  headerHeight: 0,
175
174
  tabBarHeight: 0,
176
175
  }
177
176
  if (isJdApp) {
178
177
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
179
178
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
180
179
  this.getAddressCachePromise()
181
180
  this.getElderModePromise()
182
181
  this.getJDAppearanceStatePromise()
183
182
  this.createJdAndroidRquestEventForTouchStart()
184
183
  }
185
184
  this.getNetWorkType()
186
185
  }
187
186
 
188
187
  getElderModePromise(){
189
188
  if(this.info.sysInfo.hasOwnProperty('jdAppModeType')){
190
189
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
191
190
  }else {
192
191
  if(isJdAndAndroidDevice){
193
192
  this.info.sysInfo.jdAppModeType = "0"
194
193
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
195
194
  }else {
196
195
  return new Promise(resolve => {
197
196
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
198
197
  if(!window[getCallBackName]){
199
198
  window[getCallBackName] = function(res){
200
199
  try {
201
200
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
202
201
  const {status, data, msg} = getResJson
203
202
  status === '0' ? resolve(data) : resolve("0")
204
203
  }catch (e) {
205
204
  resolve("0")
206
205
  }
207
206
  window[getCallBackName] = null
208
207
  }
209
208
  }
210
209
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
211
210
  method: 'callSyncRouterModuleWithParams',
212
211
  params: JSON.stringify({
213
212
  routerURL: "router://JDBModeModule/getCurrentMode",
214
213
  routerParam: {},
215
214
  callBackName: `window.${getCallBackName}`,
216
215
  callBackId: `${getCallBackName}Ios`,
217
216
  }),
218
217
  })
219
218
  })
220
219
  }
221
220
  }
222
221
  }
223
222
 
224
223
  getJDAppearanceStatePromise() {
225
224
  if(this.info.sysInfo.hasOwnProperty('jdAppearanceState')){
226
225
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
227
226
  } else {
228
227
  return new Promise(resolve => {
229
228
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
230
229
  if(!window[getCallBackName]){
231
230
  window[getCallBackName] = function(res){
232
231
  try {
233
232
  console.log('getJDAppearanceStatePromise',res)
234
233
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
235
234
  const {status, data, msg} = getResJson
236
235
  status === '0' ? resolve(data) : resolve("0")
237
236
  }catch (e) {
238
237
  resolve("0")
239
238
  }
240
239
  window[getCallBackName] = null
241
240
  }
242
241
  }
243
242
  if(isAndroidDevice) {
244
243
  const jsonString = JSON.stringify({
245
244
  callBackName: `window.${getCallBackName}`,
246
245
  })
247
246
  console.log('window.JDAppearance',window.JDAppearance)
248
247
  window.JDAppearance && window.JDAppearance.getUiState(jsonString);
249
248
  } else {
250
249
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
251
250
  method: 'callSyncRouterModuleWithParams',
252
251
  params: JSON.stringify({
253
252
  routerURL: "router://JDWebViewBusinessModule/getJDAppearanceState",
254
253
  routerParam: {},
255
254
  callBackName: `window.${getCallBackName}`,
256
255
  callBackId: `${getCallBackName}Ios`,
257
256
  }),
258
257
  })
259
258
  }
260
259
  })
261
260
  }
262
261
  }
263
262
 
264
263
  createJdAndroidRquestEventForTouchStart(){
265
264
  if(isJdAndAndroidDevice && window.JdAndroid){
266
265
  const rootEleNode = document.querySelector('body')
267
266
  if(rootEleNode){
268
267
  rootEleNode.addEventListener(
269
268
  'touchstart',
270
269
  this.jdAndroidAddEventListenerTouchStart,
271
270
  false,
272
271
  )
273
272
  }
274
273
  }
275
274
  }
276
275
  jdAndroidAddEventListenerTouchStart(e){
277
276
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
278
277
  if(!isH5SwiperCustomEle){
279
278
  const hasCustomEle = e ? (e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')) : false
280
279
  if (!hasCustomEle) {
281
280
  window.JdAndroid.requestEvent(false)
282
281
  console.log("createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false")
283
282
  }
284
283
  }
285
284
  }
286
285
  removeJdAndroidRquestEventForTouchStart(){
287
286
  if(isJdAndAndroidDevice && window.JdAndroid){
288
287
  const rootEleNode = document.querySelector('body')
289
288
  if(rootEleNode){
290
289
  rootEleNode.removeEventListener(
291
290
  'touchstart',
292
291
  this.jdAndroidAddEventListenerTouchStart,
293
292
  false,
294
293
  )
295
294
  }
296
295
  }
297
296
  }
298
297
 
299
298
  getNetWorkType() {
300
299
  if (isJdApp) {
301
300
  this.jmfeReayPromise().then(() => {
302
301
  window.jmfe.getNetworkStatus().then(({ status, data }) => {
303
302
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data)
304
303
  if (status === '0') {
305
304
  this.info.sysInfo['netWorkType'] = data
306
305
  }else {
307
306
  this._taroGetNetworkType()
308
307
  }
309
308
  }).catch((err) => {
310
309
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
311
310
  this._taroGetNetworkType()
312
311
  })
313
312
  })
314
313
  } else {
315
314
  this._taroGetNetworkType()
316
315
  }
317
316
  }
318
317
  _taroGetNetworkType(){
319
318
  Taro.getNetworkType().then((getRes) => {
320
319
  if (getRes &&
321
320
  getRes.networkType) {
322
321
  (this.info.sysInfo['netWorkType'] = getRes.networkType)
323
322
  console.log('在app内通过taro对象获取网络状态完成,当前网络状态', this.info.sysInfo['netWorkType'])
324
323
  }
325
324
  })
326
325
  }
327
326
  getCacheAddressRouter() {
328
327
  if (!window.jmfe) return
329
328
  if (isAndroidDevice) {
330
329
  return window.jmfe.callRouter({
331
330
  jdRouter: '1',
332
331
  routerURL: 'router://JDAddressModule/getCacheAddress',
333
332
  routerParam: { sceneId: 'basicShoppingProcess' },
334
333
  })
335
334
  } else {
336
335
  return window.jmfe.callRouter({
337
336
  jdRouter: '1',
338
337
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
339
338
  routerParam: { sceneId: 'basicShoppingProcess' },
340
339
  })
341
340
  }
342
341
  }
343
342
 
344
343
  getAddressCachePromise() {
345
344
  return new Promise((resolve) => {
346
345
  if (
347
346
  this?.info?.sysInfo?.lat &&
348
347
  this?.info?.sysInfo?.lng &&
349
348
  this?.info?.sysInfo?.area
350
349
  ) {
351
350
  resolve({
352
351
  lat: this.info.sysInfo.lat,
353
352
  lng: this.info.sysInfo.lng,
354
353
  area: this?.info?.sysInfo?.area,
355
354
  })
356
355
  } else {
357
356
  this.jmfeReayPromise().then(() => {
358
357
  this.getCacheAddressRouter()
359
358
  .then(({ status, data }) => {
360
359
  if (status === '0' && data) {
361
360
  const { lat , latitude, lng, longitude, provinceId, cityId,
362
361
  countyId,townId} = data || {}
363
362
  let area = '';
364
363
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
365
364
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
366
365
  if (provinceId) {
367
366
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`
368
367
  this.info.pageInfo['address'] = area
369
368
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g,',')
370
369
  }
371
370
  resolve({
372
371
  lat: this.info.sysInfo['lat'],
373
372
  lng: this.info.sysInfo['lng'],
374
373
  area: area,
375
374
  })
376
375
  } else {
377
376
  resolve({ lat: '', lng: '', area: '' })
378
377
  }
379
378
  })
380
379
  .catch(() => {
381
380
  resolve({ lat: '', lng: '', area: '' })
382
381
  })
383
382
  }).catch(() => {
384
383
  resolve({ lat: '', lng: '', area: '' })
385
384
  console.log("判断jmfe不存在,获取经纬度信息异常")
386
385
  })
387
386
  }
388
387
  })
389
388
  }
390
389
 
391
390
  toLogin(options) {
392
391
  return this.info.isJingGouMiniViewState
393
392
  ? this.toWxAppLogin(options)
394
393
  : this.toWebLogin(options)
395
394
  }
396
395
 
397
396
  doLogin(options) {
398
397
  return this.toLogin(options)
399
398
  }
400
399
 
401
400
  doLoginForJdPin(options = {}) {
402
401
  return this.doLogin({
403
402
  loginColor: {
404
403
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
405
404
  dpin: 0,
406
405
  },
407
406
  ...options
408
407
  })
409
408
  }
410
409
 
411
410
  toWebLogin(options) {
412
411
  let params: {
413
412
  returnurl: string
414
413
  } = {
415
414
  returnurl: '',
416
415
  }
417
416
  const loginUrl = isPc
418
417
  ? `//passport.jd.com/new/login.aspx`
419
418
  : `${domain.mobileLogin}/user/login.action`
420
419
  const defaultParams = {
421
420
  appid: '100',
422
421
  returnurl: window.location.href,
423
422
  }
424
423
  if (isString(options)) {
425
424
  params = Object.assign({}, defaultParams, {
426
425
  returnurl: options,
427
426
  })
428
427
  } else if (isObject(options)) {
429
428
  const { loginColor, ...otherOptions} = options
430
429
  params = Object.assign({}, defaultParams, otherOptions)
431
430
  } else {
432
431
  params = defaultParams
433
432
  }
434
433
  params.returnurl = encodeURIComponent(params.returnurl)
435
434
  let getFullUrl = loginUrl + '?' + serialize(params)
436
435
  if (isPc) {
437
436
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
438
437
  }
439
438
  return Promise.resolve({
440
439
  h5ToUrl: true,
441
440
  url: getFullUrl,
442
441
  }).then(() => {
443
442
  window.location.href = getFullUrl
444
443
  })
445
444
  }
446
445
 
447
446
  toWxAppLogin(options = {}) {
448
447
  console.log('微信京购小程序中h5登录跳转', options)
449
448
  return Promise.resolve(true).then(() => {
450
449
  const { loginColor } = Object.assign({},{
451
450
  loginColor: {
452
451
  bzi:WXAPP_BIZ_KEY,
453
452
  dpin: 1,
454
453
  },
455
454
  }, options)
456
455
  window.location.href = `${
457
456
  domain.wq
458
457
  }/pinbind/pintokenredirect?biz=${loginColor.bzi}&url=${encodeURIComponent(
459
458
  window.location.href,
460
459
  )}`
461
460
  })
462
461
  }
463
462
 
464
463
  getLoginCookie() {
465
464
  return Promise.resolve({
466
465
  pin: cookie.get('pin') || '',
467
466
  })
468
467
  }
469
468
 
470
469
  clearLoginCookie() {
471
470
  cookie.remove('pin')
472
471
  }
473
472
 
474
473
  checkStatusAndLogin(options = {}) {
475
474
  if (!this.checkStatusAndLoginPromise) {
476
475
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
477
476
  try {
478
477
  const getLoginState = await this.doCheckLoginStateAndForApiCheck()
479
478
  if (getLoginState) {
480
479
  resolve(true)
481
480
  } else {
482
481
  this.toLogin(options)
483
482
  reject(false)
484
483
  }
485
484
  } catch (e) {
486
485
  this.toLogin(options)
487
486
  reject(false)
488
487
  }
489
488
  })
490
489
  return this.checkStatusAndLoginPromise
491
490
  } else {
492
491
  return this.checkStatusAndLoginPromise
493
492
  .then(() => {
494
493
  return Promise.resolve(true)
495
494
  })
496
495
  .catch(() => {
497
496
  this.toLogin(options)
498
497
  return Promise.reject(true)
499
498
  })
500
499
  }
501
500
  }
502
501
 
503
502
  doCheckLoginStateAndForApiCheck() {
504
503
  if (this.info.loginState) {
505
504
  return Promise.resolve(true)
506
505
  } else {
507
506
  return new Promise((resolve, reject) => {
508
507
  if (this.info.isJingGouMiniViewState) {
509
508
  const getWqSkey = cookie.get('wq_skey')
510
509
  const getWqUin = cookie.get('wq_uin')
511
510
  if (getWqSkey && getWqUin) {
512
511
  this.info.loginState = true
513
512
  resolve(true)
514
513
  } else {
515
514
  reject(false)
516
515
  }
517
516
  } else {
518
517
  Taro.request({
519
518
  url: api.isLogin,
520
519
  jsonp: true,
521
520
  timeout: 3000,
522
521
  success: (res) => {
523
522
  const { statusCode, data } = res
524
523
  if (
525
524
  statusCode === 200 &&
526
525
  data?.islogin &&
527
526
  Number(data.islogin) === 1
528
527
  ) {
529
528
  this.info.loginState = true
530
529
  resolve(true)
531
530
  } else {
532
531
  reject(false)
533
532
  }
534
533
  },
535
534
  fail: (err) => {
536
535
  console.log('登录检查异常', err)
537
536
  reject(false)
538
537
  },
539
538
  })
540
539
  }
541
540
  })
542
541
  }
543
542
  }
544
543
 
545
544
  checkLoginStatus() {
546
545
  return new Promise(async (resolve, reject) => {
547
546
  try {
548
547
  const getLoginState = await this.doCheckLoginStateAndForApiCheck()
549
548
  if (getLoginState) {
550
549
  const { pin } = await this.getLoginCookie()
551
550
  this.info.userInfo = {
552
551
  pin,
553
552
  encodePin: encodeURIComponent(pin),
554
553
  ptkey: '',
555
554
  }
556
555
  resolve(true)
557
556
  } else {
558
557
  reject(false)
559
558
  }
560
559
  } catch (e) {
561
560
  reject(false)
562
561
  }
563
562
  })
564
563
  }
565
564
 
566
565
  updatePageAndLogInfo(updateQuery = {}) {
567
566
  const createUpdateQueryInfo: {
568
567
  query: {
569
568
  shopId?: string | number
570
569
  venderId?: string | number
571
570
  }
572
571
  updateShopInfoState: boolean
573
572
  } = Object.assign(
574
573
  {},
575
574
  {
576
575
  query: {},
577
576
  updateShopInfoState: false,
578
577
  },
579
578
  updateQuery,
580
579
  )
581
580
  console.log(
582
581
  '获取当前下发的店铺查询参数',
583
582
  updateQuery,
584
583
  '获取之前保存的shopInfo店铺查询参数',
585
584
  this.info?.shopInfo,
586
585
  )
587
586
  const { query, updateShopInfoState } = createUpdateQueryInfo
588
587
  const { shopId, venderId, un_area } = query
589
588
  if (updateShopInfoState) {
590
589
  this.info.queryInfo = {
591
590
  ...this.info.queryInfo,
592
591
  ...query,
593
592
  }
594
593
  if (shopId && venderId) {
595
594
  this.info.shopInfo = {
596
595
  shopId: `${shopId}`,
597
596
  venderId: `${venderId}`,
598
597
  }
599
598
  }
600
599
  } else {
601
600
  this.info.queryInfo = {
602
601
  ...query,
603
602
  }
604
603
  if (
605
604
  this.info.shopInfo?.shopId &&
606
605
  this.info.shopInfo?.venderId &&
607
606
  (this.info.shopInfo.shopId == shopId ||
608
607
  this.info.shopInfo.venderId == venderId)
609
608
  ) {
610
609
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
611
610
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
612
611
  console.log(
613
612
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
614
613
  this.info.queryInfo,
615
614
  )
616
615
  }
617
616
  }
618
617
  this.info.queryInfo['shopId'] &&
619
618
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
620
619
  this.info.queryInfo['venderId'] &&
621
620
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
622
621
  console.log(
623
622
  'h5==获取店铺下发查询参数\n',
624
623
  query,
625
624
  '\n获取店铺最后查询参数\n',
626
625
  this.info.queryInfo,
627
626
  '\n是否为更新店铺状态\n',
628
627
  updateShopInfoState,
629
628
  )
630
629
  const changeArea =
631
630
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
632
631
  if (changeArea) {
633
632
  this.info.pageInfo.address = changeArea
634
633
  this.info.pageInfo.un_area = changeArea
635
634
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
636
635
  }
637
636
  }
637
+ import Taro from '@tarojs/taro'
638
638
  isJdApp,
639
639
  isIosDevice,
640
640
  isAndroidDevice,
641
641
  isJdAndHarmonyDevice,
642
642
  isJdAndAndroidDevice,
643
643
  jdAppVersion,
644
644
  jdAppVersionStr,
645
645
  isString,
646
646
  isObject,
647
647
  serialize,
648
648
  urlCookie,
649
649
  dealNativePixelToCssPixel,
650
650
  BUSINESS_TYPE,
651
651
  SECTION_HOME_TAB_NAME_TYPE,
652
652
  SECTION_HOME_TAB_TYPE,
653
653
  WX_BUSINESS_TYPE,
654
654
  WXAPP_BIZ_KEY,
655
655
  MPAAS_CONFIG_APP_VERSION,
656
656
  MPAAS_CONFIG_APP_LOW_VERSION,
657
657
  WXAPP_BIZ_SHOP_LIGHT_KEY,
658
658
  loginState: false,
659
659
  cookiesStr: '',
660
660
  userInfo: userPinKey,
661
661
  isJingGouMiniViewState: false,
662
662
  isJingxiMiniViewState: false,
663
663
  pageInfo: {
664
664
  wxBusinessType: WX_BUSINESS_TYPE.NO,
665
665
  address: '',
666
666
  addressCommaStr: '',
667
667
  un_area: '',
668
668
  vapptype: '1',
669
669
  pageType: 'home',
670
670
  isExposureState: false,
671
671
  moduleId: '',
672
672
  entrance: '',
673
673
  dataType: BUSINESS_TYPE.ONLINE,
674
674
  floorExposureInfo: {},
675
675
  floorVideInfo: {},
676
676
  productVideInfo: {},
677
677
  tabsLoadAllDataInfo: {
678
678
  [SECTION_HOME_TAB_NAME_TYPE[
679
679
  SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
680
680
  ]]: false,
681
681
  },
682
682
  updateShopInfosAllState: false,
683
683
  isVipShop: false,
684
684
  isJdShowNativeImmersivePlayer: false,
685
685
  ...shopConfig,
686
686
  pageScrollTop: 0,
687
687
  pageIdxHeightInfo: {
688
688
  list: [],
689
689
  },
690
690
  shopNavBarHeight: 0,
691
691
  },
692
692
  defaultQueryLogInfo: {
693
693
  sourceType: 'JDshop',
694
694
  sourceValue: '',
695
695
  moduleId: 'none',
696
696
  entrance: 'none',
697
697
  },
698
698
  sysInfo: {
699
699
  windowWidth: isPc ? 375 : 0,
700
700
  containerWidth: isPc ? 375 : 0,
701
701
  windowHeight: 0,
702
702
  netWorkType: '4g',
703
703
  jdBottomBarHeight: 0,
704
704
  jdNativeHeaderHeight: 0,
705
705
  },
706
706
  queryInfo: {},
707
707
  shopInfo: {},
708
708
  openAppData: {},
709
709
  public info: CommonInterFace.BaseConfigInfo
710
710
  public config: {
711
711
  [key: string]: any
712
712
  }
713
713
  public lazyContainer: CommonInterFace.lazyContainer
714
714
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
715
715
  public rootEleNode: HTMLElement | null
716
716
  public checkStatusAndLoginPromise: object | null
717
717
  private jmfeRegisterStatePromise: Promise<any> | null
718
718
  private jmfeRegisterState: boolean
719
719
  constructor(opt) {
720
720
  this.info = this._getConfig(opt)
721
721
  this.config = {}
722
722
  this.lazyContainer = {
723
723
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
724
724
  appLazyContainerList: [],
725
725
  appLazyFinishContainerList: [],
726
726
  },
727
727
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
728
728
  appLazyContainerList: [],
729
729
  appLazyFinishContainerList: [],
730
730
  },
731
731
  }
732
732
  this.renderedIsvComponents = {}
733
733
  this.rootEleNode = document.querySelector('body')
734
734
  this.checkStatusAndLoginPromise = null
735
735
  this.jmfeRegisterStatePromise = null
736
736
  isJdApp && this.jmfeReayPromise()
737
737
  }
738
738
  _getConfig(opt) {
739
739
  return Object.assign({}, DefaultConfig, opt)
740
740
  }
741
741
 
742
742
  jmfeReayPromise(): Promise<any> {
743
743
  if (isJdApp) {
744
744
  if (this.jmfeRegisterState) {
745
745
  return Promise.resolve(true)
746
746
  } else {
747
747
  !this.jmfeRegisterStatePromise &&
748
748
  (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
749
749
  ready('jmfe', 3000)
750
750
  .then(() => {
751
751
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
752
752
  this.jmfeRegisterState = true
753
753
  resolve(true)
754
754
  console.log('松果app内初始化注册jmfe认证完成')
755
755
  })
756
756
  .catch(() => {
757
757
  reject(false)
758
758
  })
759
759
  }))
760
760
  return this.jmfeRegisterStatePromise
761
761
  }
762
762
  } else {
763
763
  return Promise.reject(false)
764
764
  }
765
765
  }
766
766
 
767
767
  updateBusinessDomainAndApi(domain, api) {
768
768
  }
769
769
 
770
770
  formatNativeScreenPageData(action) {
771
771
  let getChangePageInfo: any = null
772
772
  try {
773
773
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(
774
774
  JSON.stringify({
775
775
  plugin: 'JDHybridScreenPlugin',
776
776
  action,
777
777
  sync: '1',
778
778
  }),
779
779
  )
780
780
  const getChangePageInfoData =
781
781
  typeof getNativeScreenPageInfoStr === 'string'
782
782
  ? JSON.parse(getNativeScreenPageInfoStr)
783
783
  : null
784
784
  if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
785
785
  const { code, data } = getChangePageInfoData
786
786
  getChangePageInfo = code && code === '0' ? data : null
787
787
  }
788
788
  } catch (e) {
789
789
  console.log('JDHybridScreenPlugin转换异常', e)
790
790
  }
791
791
  return getChangePageInfo
792
792
  }
793
793
 
794
794
  isAndroidFoldScreen() {
795
795
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
796
796
  }
797
797
 
798
798
  getJdAndroidPageChangeScreenInfo() {
799
799
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
800
800
  if (
801
801
  getPageScreenInfo &&
802
802
  getPageScreenInfo?.pageWidth &&
803
803
  getPageScreenInfo?.pageHeight
804
804
  ) {
805
805
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
806
806
  pageWidth: getPageScreenInfo.pageWidth,
807
807
  pageHeight: getPageScreenInfo.pageHeight,
808
808
  })
809
809
  getPageScreenInfo.pageWidth = pageWidth
810
810
  getPageScreenInfo.pageHeight = pageHeight
811
811
  }
812
812
  return getPageScreenInfo
813
813
  }
814
814
 
815
815
  getSystemInfo(params) {
816
816
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
817
817
  ? {}
818
818
  : getSystemInfos(params)
819
819
  if (isJdAndAndroidDevice && window.innerWidth <= 0) {
820
820
  const isfoldScreen = this.isAndroidFoldScreen()
821
821
  if (isfoldScreen) {
822
822
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
823
823
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
824
824
  console.info(
825
825
  '安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取',
826
826
  getJdAndroidPageInfo,
827
827
  )
828
828
  }
829
829
  }
830
830
  this.info.sysInfo = {
831
831
  actualNavBarHeight: 0,
832
832
  ...this.info.sysInfo,
833
833
  ...info,
834
834
  safeContentHeight: info?.screenHeight,
835
835
  headerHeight: 0,
836
836
  tabBarHeight: 0,
837
837
  }
838
838
  if (isJdApp) {
839
839
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
840
840
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
841
841
  this.getAddressCachePromise()
842
842
  this.getElderModePromise()
843
843
  this.getJDAppearanceStatePromise()
844
844
  this.createJdAndroidRquestEventForTouchStart()
845
845
  }
846
846
  this.getWifiVideoAutoPlayAsync()
847
847
  this.getMPaasConfigAsync()
848
848
  this.getNetWorkType()
849
849
  }
850
850
 
851
851
  taskTimeoutPromise(callBack, timeout = 2000) {
852
852
  return new Promise(resolve => {
853
853
  setTimeout(() => {
854
854
  const getCallBackRes = typeof callBack === 'function' && callBack()
855
855
  return resolve(getCallBackRes || false)
856
856
  }, timeout)
857
857
  })
858
858
  }
859
859
 
860
860
  getElderModePromise() {
861
861
  if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
862
862
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
863
863
  } else {
864
864
  if (isJdAndAndroidDevice) {
865
865
  this.info.sysInfo.jdAppModeType = '0'
866
866
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
867
867
  } else {
868
868
  return Promise.race([
869
869
  this.taskTimeoutPromise(() => {
870
870
  this.info.sysInfo.jdAppModeType = '0'
871
871
  return this.info.sysInfo.jdAppModeType
872
872
  }),
873
873
  new Promise(resolve => {
874
874
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
875
875
  if (!window[getCallBackName]) {
876
876
  window[getCallBackName] = res => {
877
877
  try {
878
878
  const getResJson =
879
879
  typeof res === 'string' ? JSON.parse(res) : res
880
880
  const { status, data, msg } = getResJson
881
881
  console.log(`获取松果app展示模式成功,返回结果${data}`)
882
882
  if (status === '0') {
883
883
  this.info.sysInfo.jdAppModeType = data
884
884
  resolve(data)
885
885
  } else {
886
886
  resolve('0')
887
887
  }
888
888
  } catch (e) {
889
889
  resolve('0')
890
890
  }
891
891
  window[getCallBackName] = null
892
892
  }
893
893
  }
894
894
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
895
895
  method: 'callSyncRouterModuleWithParams',
896
896
  params: JSON.stringify({
897
897
  routerURL: 'router://JDBModeModule/getCurrentMode',
898
898
  routerParam: {},
899
899
  callBackName: `window.${getCallBackName}`,
900
900
  callBackId: `${getCallBackName}Ios`,
901
901
  }),
902
902
  })
903
903
  }),
904
904
  ])
905
905
  }
906
906
  }
907
907
  }
908
908
 
909
909
  getJDAppearanceStatePromise() {
910
910
  if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
911
911
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
912
912
  } else {
913
913
  return Promise.race([
914
914
  this.taskTimeoutPromise(() => {
915
915
  this.info.sysInfo.jdAppearanceState = '0'
916
916
  return this.info.sysInfo.jdAppearanceState
917
917
  }),
918
918
  new Promise(resolve => {
919
919
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
920
920
  if (!window[getCallBackName]) {
921
921
  window[getCallBackName] = res => {
922
922
  try {
923
923
  console.log('getJDAppearanceStatePromise', res)
924
924
  const getResJson =
925
925
  typeof res === 'string' ? JSON.parse(res) : res
926
926
  const { status, data, msg } = getResJson
927
927
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
928
928
  if (status === '0') {
929
929
  this.info.sysInfo.jdAppearanceState = data
930
930
  resolve(data)
931
931
  } else {
932
932
  resolve('0')
933
933
  }
934
934
  } catch (e) {
935
935
  resolve('0')
936
936
  }
937
937
  window[getCallBackName] = null
938
938
  }
939
939
  }
940
940
  if (isAndroidDevice) {
941
941
  const jsonString = JSON.stringify({
942
942
  callBackName: `window.${getCallBackName}`,
943
943
  })
944
944
  console.log('window.JDAppearance', window.JDAppearance)
945
945
  window.JDAppearance && window.JDAppearance.getUiState(jsonString)
946
946
  } else {
947
947
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
948
948
  method: 'callSyncRouterModuleWithParams',
949
949
  params: JSON.stringify({
950
950
  routerURL:
951
951
  'router://JDWebViewBusinessModule/getJDAppearanceState',
952
952
  routerParam: {},
953
953
  callBackName: `window.${getCallBackName}`,
954
954
  callBackId: `${getCallBackName}Ios`,
955
955
  }),
956
956
  })
957
957
  }
958
958
  }),
959
959
  ])
960
960
  }
961
961
  }
962
962
 
963
963
  createJdAndroidRquestEventForTouchStart() {
964
964
  if (isJdAndAndroidDevice && window.JdAndroid) {
965
965
  const rootEleNode = document.querySelector('body')
966
966
  if (rootEleNode) {
967
967
  rootEleNode.addEventListener(
968
968
  'touchstart',
969
969
  this.jdAndroidAddEventListenerTouchStart,
970
970
  false,
971
971
  )
972
972
  }
973
973
  }
974
974
  }
975
975
  jdAndroidAddEventListenerTouchStart(e) {
976
976
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
977
977
  if (!isH5SwiperCustomEle) {
978
978
  const hasCustomEle = e
979
979
  ? e?.target?.closest('.J_customScroll') ||
980
980
  e?.target?.closest('.J_customLayout')
981
981
  : false
982
982
  if (!hasCustomEle) {
983
983
  window.JdAndroid.requestEvent(false)
984
984
  console.log(
985
985
  'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
986
986
  )
987
987
  }
988
988
  }
989
989
  }
990
990
  removeJdAndroidRquestEventForTouchStart() {
991
991
  if (isJdAndAndroidDevice && window.JdAndroid) {
992
992
  const rootEleNode = document.querySelector('body')
993
993
  if (rootEleNode) {
994
994
  rootEleNode.removeEventListener(
995
995
  'touchstart',
996
996
  this.jdAndroidAddEventListenerTouchStart,
997
997
  false,
998
998
  )
999
999
  }
1000
1000
  }
1001
1001
  }
1002
1002
 
1003
1003
  getNetWorkType() {
1004
1004
  if (isJdApp) {
1005
1005
  this.jmfeReayPromise().then(() => {
1006
1006
  window.jmfe
1007
1007
  .getNetworkStatus()
1008
1008
  .then(({ status, data }) => {
1009
1009
  console.log(
1010
1010
  '在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====',
1011
1011
  data,
1012
1012
  )
1013
1013
  if (status === '0') {
1014
1014
  this.info.sysInfo['netWorkType'] = data
1015
1015
  } else {
1016
1016
  this._taroGetNetworkType()
1017
1017
  }
1018
1018
  })
1019
1019
  .catch(err => {
1020
1020
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
1021
1021
  this._taroGetNetworkType()
1022
1022
  })
1023
1023
  })
1024
1024
  } else {
1025
1025
  this._taroGetNetworkType()
1026
1026
  }
1027
1027
  }
1028
1028
  _taroGetNetworkType() {
1029
1029
  Taro.getNetworkType().then(getRes => {
1030
1030
  if (getRes && getRes.networkType) {
1031
1031
  this.info.sysInfo['netWorkType'] = getRes.networkType
1032
1032
  console.log(
1033
1033
  '在app内通过taro对象获取网络状态完成,当前网络状态',
1034
1034
  this.info.sysInfo['netWorkType'],
1035
1035
  )
1036
1036
  }
1037
1037
  })
1038
1038
  }
1039
1039
 
1040
1040
  getCacheAddressRouter() {
1041
1041
  if (!window.jmfe) return
1042
1042
  if (isAndroidDevice) {
1043
1043
  return window.jmfe.callRouter({
1044
1044
  jdRouter: '1',
1045
1045
  routerURL: 'router://JDAddressModule/getCacheAddress',
1046
1046
  routerParam: { sceneId: 'basicShoppingProcess' },
1047
1047
  })
1048
1048
  } else if (isIosDevice) {
1049
1049
  return window.jmfe.callRouter({
1050
1050
  jdRouter: '1',
1051
1051
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
1052
1052
  routerParam: { sceneId: 'basicShoppingProcess' },
1053
1053
  })
1054
1054
  } else if (isJdAndHarmonyDevice) {
1055
1055
  return new Promise(resolve => {
1056
1056
  resolve({})
1057
1057
  })
1058
1058
  } else {
1059
1059
  throw Error(
1060
1060
  'Unknown device type cannot obtain the address information through the route!',
1061
1061
  )
1062
1062
  }
1063
1063
  }
1064
1064
 
1065
1065
  getAddressCachePromise() {
1066
1066
  return new Promise(resolve => {
1067
1067
  if (
1068
1068
  this?.info?.sysInfo?.lat &&
1069
1069
  this?.info?.sysInfo?.lng &&
1070
1070
  this?.info?.sysInfo?.area
1071
1071
  ) {
1072
1072
  resolve({
1073
1073
  lat: this.info.sysInfo.lat,
1074
1074
  lng: this.info.sysInfo.lng,
1075
1075
  area: this?.info?.sysInfo?.area,
1076
1076
  })
1077
1077
  } else {
1078
1078
  this.jmfeReayPromise()
1079
1079
  .then(() => {
1080
1080
  this.getCacheAddressRouter()
1081
1081
  .then(({ status, data }) => {
1082
1082
  if (status === '0' && data) {
1083
1083
  const {
1084
1084
  lat,
1085
1085
  latitude,
1086
1086
  lng,
1087
1087
  longitude,
1088
1088
  provinceId,
1089
1089
  cityId,
1090
1090
  countyId,
1091
1091
  townId,
1092
1092
  } = data || {}
1093
1093
  let area = ''
1094
1094
  this.info.sysInfo['lat'] = lat || latitude || ''
1095
1095
  this.info.sysInfo['lng'] = lng || longitude || ''
1096
1096
  if (provinceId) {
1097
1097
  area = `${provinceId}_${cityId || 0}_${countyId ||
1098
1098
  0}_${townId || 0}`
1099
1099
  this.info.pageInfo['address'] = area
1100
1100
  this.info.pageInfo['addressCommaStr'] = area.replace(
1101
1101
  /_/g,
1102
1102
  ',',
1103
1103
  )
1104
1104
  }
1105
1105
  resolve({
1106
1106
  lat: lat,
1107
1107
  lng: lng,
1108
1108
  area: area,
1109
1109
  })
1110
1110
  } else {
1111
1111
  resolve({ lat: '', lng: '', area: '' })
1112
1112
  }
1113
1113
  })
1114
1114
  .catch(e => {
1115
1115
  console.log(' ~~ file: index.h5.ts:514 ~~ .catch ~~ e:', e)
1116
1116
  resolve({ lat: '', lng: '', area: '' })
1117
1117
  })
1118
1118
  })
1119
1119
  .catch(e => {
1120
1120
  console.log(' ~~ file: index.h5.ts:518 ~~ .catch ~~ e:', e)
1121
1121
  resolve({ lat: '', lng: '', area: '' })
1122
1122
  console.log('判断jmfe不存在,获取经纬度信息异常')
1123
1123
  })
1124
1124
  }
1125
1125
  })
1126
1126
  }
1127
1127
 
1128
1128
  async updateMPaasConfigAsync(isBeforePageReady: boolean) {
1129
1129
  console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady)
1130
1130
  if (!isJdApp) {
1131
1131
  return
1132
1132
  }
1133
1133
  const avifSwitch = await getMPaasConfigByBussinessKey(
1134
1134
  'avifSwitch',
1135
1135
  isBeforePageReady,
1136
1136
  )
1137
1137
  this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch
1138
1138
  const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
1139
1139
  'isFollowAppVideoPlayStatus',
1140
1140
  isBeforePageReady,
1141
1141
  )
1142
1142
  console.log(
1143
1143
  'isBeforePageReady:',
1144
1144
  isBeforePageReady,
1145
1145
  'isFollowAppVideoPlayStatus:',
1146
1146
  isFollowAppVideoPlayStatus,
1147
1147
  )
1148
1148
  if (
1149
1149
  isFollowAppVideoPlayStatus === true ||
1150
1150
  isFollowAppVideoPlayStatus === 'true'
1151
1151
  ) {
1152
1152
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true
1153
1153
  }
1154
1154
  }
1155
1155
 
1156
1156
  async getWifiVideoAutoPlayAsync() {
1157
1157
  this.info.sysInfo['wifiVideoAutoPlay'] = false
1158
1158
  if (!isJdApp) {
1159
1159
  return
1160
1160
  }
1161
1161
  const videoPlayStatus = await getWifiVideoAutoPlay().catch(e => {
1162
1162
  return 0
1163
1163
  })
1164
1164
  if (Number(videoPlayStatus) === 1) {
1165
1165
  this.info.sysInfo['wifiVideoAutoPlay'] = true
1166
1166
  }
1167
1167
  }
1168
1168
 
1169
1169
  async getMPaasConfigAsync() {
1170
1170
  this.info.sysInfo.dynamicConfig = {}
1171
1171
  this.info.sysInfo.dynamicConfig['avifSwitch'] = {}
1172
1172
  this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false
1173
1173
  return this.updateMPaasConfigAsync(true)
1174
1174
  }
1175
1175
 
1176
1176
  getDynamicConfig(key: string) {
1177
1177
  return this.info.sysInfo.dynamicConfig[key]
1178
1178
  }
1179
1179
  async updateMPaasConfig() {
1180
1180
  console.log('updateMPaasConfig')
1181
1181
  if (
1182
1182
  isIosDevice &&
1183
1183
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
1184
1184
  versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
1185
1185
  ) {
1186
1186
  try {
1187
1187
  await this.updateMPaasConfigAsync(false)
1188
1188
  } catch (e) {
1189
1189
  console.log('updateMPaasConfigAsync:', e)
1190
1190
  }
1191
1191
  }
1192
1192
  }
1193
1193
 
1194
1194
  toLogin(options) {
1195
1195
  return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
1196
1196
  ? this.toWxAppLogin(options)
1197
1197
  : this.toWebLogin(options)
1198
1198
  }
1199
1199
 
1200
1200
  doLogin(options) {
1201
1201
  return this.toLogin(options)
1202
1202
  }
1203
1203
 
1204
1204
  doLoginForJdPin(options = {}) {
1205
1205
  return this.doLogin({
1206
1206
  loginColor: {
1207
1207
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1208
1208
  dpin: 0,
1209
1209
  },
1210
1210
  ...options,
1211
1211
  })
1212
1212
  }
1213
1213
 
1214
1214
  toWebLogin(options) {
1215
1215
  let params: {
1216
1216
  returnurl: string
1217
1217
  } = {
1218
1218
  returnurl: '',
1219
1219
  }
1220
1220
  const loginUrl = isPc
1221
1221
  ? `//passport.jd.com/new/login.aspx`
1222
1222
  : `${domain.mobileLogin}/user/login.action`
1223
1223
  const defaultParams = {
1224
1224
  appid: '100',
1225
1225
  returnurl: window.location.href,
1226
1226
  }
1227
1227
  if (isString(options)) {
1228
1228
  params = Object.assign({}, defaultParams, {
1229
1229
  returnurl: options,
1230
1230
  })
1231
1231
  } else if (isObject(options)) {
1232
1232
  const { loginColor, ...otherOptions } = options
1233
1233
  params = Object.assign({}, defaultParams, otherOptions)
1234
1234
  } else {
1235
1235
  params = defaultParams
1236
1236
  }
1237
1237
  params.returnurl = encodeURIComponent(params.returnurl)
1238
1238
  let getFullUrl = loginUrl + '?' + serialize(params)
1239
1239
  if (isPc) {
1240
1240
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
1241
1241
  }
1242
1242
  return Promise.resolve({
1243
1243
  h5ToUrl: true,
1244
1244
  url: getFullUrl,
1245
1245
  }).then(() => {
1246
1246
  window.location.href = getFullUrl
1247
1247
  })
1248
1248
  }
1249
1249
 
1250
1250
  toWxAppLogin(options = {}) {
1251
1251
  console.log('微信京购小程序中h5登录跳转', options)
1252
1252
  return Promise.resolve(true).then(() => {
1253
1253
  const { loginColor } = Object.assign(
1254
1254
  {},
1255
1255
  {
1256
1256
  loginColor: {
1257
1257
  bzi: WXAPP_BIZ_KEY,
1258
1258
  dpin: 1,
1259
1259
  },
1260
1260
  },
1261
1261
  options,
1262
1262
  )
1263
1263
  window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${
1264
1264
  loginColor.bzi
1265
1265
  }&url=${encodeURIComponent(window.location.href)}`
1266
1266
  })
1267
1267
  }
1268
1268
 
1269
1269
  getLoginCookie() {
1270
1270
  return Promise.resolve({
1271
1271
  pin: cookie.get('pin') || '',
1272
1272
  })
1273
1273
  }
1274
1274
 
1275
1275
  clearLoginCookie() {
1276
1276
  cookie.remove('pin')
1277
1277
  }
1278
1278
 
1279
1279
  checkStatusAndLogin(options = {}) {
1280
1280
  if (!this.checkStatusAndLoginPromise) {
1281
1281
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1282
1282
  try {
1283
1283
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1284
1284
  options,
1285
1285
  )
1286
1286
  if (getLoginState) {
1287
1287
  resolve(true)
1288
1288
  } else {
1289
1289
  this.toLogin(options)
1290
1290
  reject(false)
1291
1291
  }
1292
1292
  } catch (e) {
1293
1293
  this.toLogin(options)
1294
1294
  reject(false)
1295
1295
  }
1296
1296
  })
1297
1297
  return this.checkStatusAndLoginPromise
1298
1298
  } else {
1299
1299
  return this.checkStatusAndLoginPromise
1300
1300
  .then(() => {
1301
1301
  return Promise.resolve(true)
1302
1302
  })
1303
1303
  .catch(() => {
1304
1304
  this.toLogin(options)
1305
1305
  return Promise.reject(true)
1306
1306
  })
1307
1307
  }
1308
1308
  }
1309
1309
 
1310
1310
  checkJdStatusAndLogin(
1311
1311
  options = {
1312
1312
  loginColor: {
1313
1313
  bzi: WXAPP_BIZ_SHOP_LIGHT_KEY,
1314
1314
  dpin: 0,
1315
1315
  },
1316
1316
  },
1317
1317
  ) {
1318
1318
  return this.checkStatusAndLogin(options)
1319
1319
  }
1320
1320
 
1321
1321
  doCheckLoginStateAndForApiCheck(options) {
1322
1322
  if (this.info.loginState) {
1323
1323
  return Promise.resolve(true)
1324
1324
  } else {
1325
1325
  return new Promise((resolve, reject) => {
1326
1326
  if (
1327
1327
  this.info.isJingGouMiniViewState ||
1328
1328
  this.info.isJingxiMiniViewState
1329
1329
  ) {
1330
1330
  const getWqAuthToken = cookie.get('wq_auth_token')
1331
1331
  const getWqSkey = cookie.get('wq_skey')
1332
1332
  const getWqUin = cookie.get('wq_uin')
1333
1333
  const isLoginState =
1334
1334
  options?.loginColor?.dpin === 0
1335
1335
  ? getWqAuthToken
1336
1336
  : getWqSkey && getWqUin
1337
1337
  if (isLoginState) {
1338
1338
  this.info.loginState = true
1339
1339
  resolve(true)
1340
1340
  } else {
1341
1341
  reject(false)
1342
1342
  }
1343
1343
  } else {
1344
1344
  Taro.request({
1345
1345
  url: api.isLogin,
1346
1346
  jsonp: true,
1347
1347
  timeout: 3000,
1348
1348
  success: res => {
1349
1349
  const { statusCode, data } = res
1350
1350
  if (
1351
1351
  statusCode === 200 &&
1352
1352
  data?.islogin &&
1353
1353
  Number(data.islogin) === 1
1354
1354
  ) {
1355
1355
  this.info.loginState = true
1356
1356
  resolve(true)
1357
1357
  } else {
1358
1358
  reject(false)
1359
1359
  }
1360
1360
  },
1361
1361
  fail: err => {
1362
1362
  console.log('登录检查异常', err)
1363
1363
  reject(false)
1364
1364
  },
1365
1365
  })
1366
1366
  }
1367
1367
  })
1368
1368
  }
1369
1369
  }
1370
1370
 
1371
1371
  checkLoginStatus(options) {
1372
1372
  return new Promise(async (resolve, reject) => {
1373
1373
  try {
1374
1374
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(
1375
1375
  options,
1376
1376
  )
1377
1377
  if (getLoginState) {
1378
1378
  const { pin } = await this.getLoginCookie()
1379
1379
  this.info.userInfo = {
1380
1380
  pin,
1381
1381
  encodePin: encodeURIComponent(pin),
1382
1382
  ptkey: '',
1383
1383
  }
1384
1384
  resolve(true)
1385
1385
  } else {
1386
1386
  reject(false)
1387
1387
  }
1388
1388
  } catch (e) {
1389
1389
  reject(false)
1390
1390
  }
1391
1391
  })
1392
1392
  }
1393
1393
 
1394
1394
  updatePageAndLogInfo(updateQuery = {}) {
1395
1395
  const createUpdateQueryInfo: {
1396
1396
  query: {
1397
1397
  shopId?: string | number
1398
1398
  venderId?: string | number
1399
1399
  }
1400
1400
  updateShopInfoState: boolean
1401
1401
  } = Object.assign(
1402
1402
  {},
1403
1403
  {
1404
1404
  query: {},
1405
1405
  updateShopInfoState: false,
1406
1406
  },
1407
1407
  updateQuery,
1408
1408
  )
1409
1409
  console.log(
1410
1410
  '获取当前下发的店铺查询参数',
1411
1411
  updateQuery,
1412
1412
  '获取之前保存的shopInfo店铺查询参数',
1413
1413
  this.info?.shopInfo,
1414
1414
  )
1415
1415
  const { query, updateShopInfoState } = createUpdateQueryInfo
1416
1416
  const { shopId, venderId, un_area } = query
1417
1417
  if (updateShopInfoState) {
1418
1418
  this.info.queryInfo = {
1419
1419
  ...this.info.queryInfo,
1420
1420
  ...query,
1421
1421
  }
1422
1422
  if (shopId && venderId) {
1423
1423
  this.info.shopInfo = {
1424
1424
  shopId: `${shopId}`,
1425
1425
  venderId: `${venderId}`,
1426
1426
  }
1427
1427
  }
1428
1428
  } else {
1429
1429
  this.info.queryInfo = {
1430
1430
  ...query,
1431
1431
  }
1432
1432
  if (
1433
1433
  this.info.shopInfo?.shopId &&
1434
1434
  this.info.shopInfo?.venderId &&
1435
1435
  (this.info.shopInfo.shopId == shopId ||
1436
1436
  this.info.shopInfo.venderId == venderId)
1437
1437
  ) {
1438
1438
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
1439
1439
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
1440
1440
  console.log(
1441
1441
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1442
1442
  this.info.queryInfo,
1443
1443
  )
1444
1444
  }
1445
1445
  }
1446
1446
  this.info.queryInfo['shopId'] &&
1447
1447
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
1448
1448
  this.info.queryInfo['venderId'] &&
1449
1449
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
1450
1450
  console.log(
1451
1451
  'h5==获取店铺下发查询参数\n',
1452
1452
  query,
1453
1453
  '\n获取店铺最后查询参数\n',
1454
1454
  this.info.queryInfo,
1455
1455
  '\n是否为更新店铺状态\n',
1456
1456
  updateShopInfoState,
1457
1457
  )
1458
1458
  const changeArea =
1459
1459
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
1460
1460
  if (changeArea) {
1461
1461
  this.info.pageInfo.address = changeArea
1462
1462
  this.info.pageInfo.un_area = changeArea
1463
1463
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
1464
1464
  }
1465
1465
  }