@conecli/cone-render 0.9.1-shop2.9 → 0.10.1-beta.1

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