@conecli/cone-render 0.9.1-shop2.8 → 0.9.1-shop2.9

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 (39) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/common/environmentType.ts +1 -0
  3. package/dist/common/index.h5.ts +1 -1
  4. package/dist/common/index.jd.ts +1 -1
  5. package/dist/common/index.ts +1 -1
  6. package/dist/common/index.weapp.ts +1 -1
  7. package/dist/common/sgmCustomCode.ts +1 -0
  8. package/dist/common/wxappApi.jd.ts +1 -0
  9. package/dist/components/ErrorBoundary.tsx +1 -1
  10. package/dist/components/base/CustomScrollView/index.jd.tsx +1 -0
  11. package/dist/components/base/CustomScrollView/index.module.scss +7 -0
  12. package/dist/components/floorItem.jd.tsx +1 -1
  13. package/dist/components/floorItem.weapp.tsx +1 -1
  14. package/dist/components/remoteFloorItem.tsx +1 -1
  15. package/dist/interface/common.ts +1 -1
  16. package/dist/interface/component.ts +1 -1
  17. package/dist/interface/jumpEventReport.ts +1 -1
  18. package/dist/interface/service.ts +1 -1
  19. package/dist/interface/utils.ts +1 -1
  20. package/dist/jumpEventReport/base.ts +1 -1
  21. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  22. package/dist/jumpEventReport/index.h5.ts +1 -1
  23. package/dist/jumpEventReport/index.jd.ts +1 -1
  24. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  25. package/dist/jumpEventReport/web.jxwxapp.ts +1 -0
  26. package/dist/jumpEventReport/web.tjapp.ts +1 -0
  27. package/dist/jumpEventReport/web.tjm.ts +1 -0
  28. package/dist/open/api/environment.ts +1 -1
  29. package/dist/open/api/track.ts +1 -1
  30. package/dist/service/requestServer.ts +1 -1
  31. package/dist/utils/draExceptionAndProfile.ts +1 -1
  32. package/dist/utils/h5Utils.ts +1 -1
  33. package/dist/utils/index.h5.ts +1 -1
  34. package/dist/utils/index.ts +1 -1
  35. package/dist/utils/index.weapp.ts +1 -1
  36. package/dist/utils/jm-common.js +1 -1
  37. package/dist/utils/sgmCodeUtils.ts +1 -0
  38. package/dist/utils/utils.ts +1 -1
  39. package/package.json +1 -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
  dealNativePixelToCssPixel
649
649
  BUSINESS_TYPE,
650
650
  JSSDK_APP_WEBVIEW_CODE,
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
  WXAPP_BIZ_SHOP_LIGHT_KEY
656
656
  loginState: false,
657
657
  cookiesStr: '',
658
658
  userInfo: userPinKey,
659
659
  isJingGouMiniViewState: false,
660
660
  isJingxiMiniViewState: false,
661
661
  pageInfo: {
662
662
  wxBusinessType: WX_BUSINESS_TYPE.NO,
663
663
  address: '',
664
664
  addressCommaStr: '',
665
665
  un_area: '',
666
666
  vapptype: '1',
667
667
  pageType: 'home',
668
668
  isExposureState: false,
669
669
  moduleId: '',
670
670
  entrance: '',
671
671
  dataType: BUSINESS_TYPE.ONLINE,
672
672
  floorExposureInfo: {},
673
673
  floorVideInfo: {},
674
674
  productVideInfo: {},
675
675
  tabsLoadAllDataInfo: {
676
676
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]:
677
677
  false,
678
678
  },
679
679
  updateShopInfosAllState: false,
680
680
  isVipShop: false,
681
681
  isJdShowNativeImmersivePlayer: false,
682
682
  ...shopConfig,
683
683
  pageScrollTop: 0,
684
684
  pageIdxHeightInfo: {
685
685
  list: []
686
686
  },
687
687
  shopNavBarHeight: 0,
688
688
  },
689
689
  defaultQueryLogInfo: {
690
690
  sourceType: 'JDshop',
691
691
  sourceValue: '',
692
692
  moduleId: 'none',
693
693
  entrance: 'none',
694
694
  },
695
695
  sysInfo: {
696
696
  windowWidth: isPc ? 375 : 0,
697
697
  containerWidth: isPc ? 375 : 0,
698
698
  windowHeight: 0,
699
699
  netWorkType: '4g',
700
700
  jdBottomBarHeight: 0,
701
701
  jdNativeHeaderHeight: 0,
702
702
  },
703
703
  queryInfo: {},
704
704
  shopInfo: {},
705
705
  openAppData: {}
706
706
  public info: CommonInterFace.BaseConfigInfo
707
707
  public config: {
708
708
  [key: string]: any
709
709
  }
710
710
  public lazyContainer: CommonInterFace.lazyContainer
711
711
  public renderedIsvComponents: CommonInterFace.renderedIsvComponents
712
712
  public rootEleNode: HTMLElement | null
713
713
  public checkStatusAndLoginPromise: object | null
714
714
  private jmfeRegisterStatePromise: Promise<any> | null
715
715
  private jmfeRegisterState: boolean
716
716
  constructor(opt) {
717
717
  this.info = this._getConfig(opt)
718
718
  this.config = {}
719
719
  this.lazyContainer = {
720
720
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
721
721
  appLazyContainerList: [],
722
722
  appLazyFinishContainerList: [],
723
723
  },
724
724
  [SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
725
725
  appLazyContainerList: [],
726
726
  appLazyFinishContainerList: [],
727
727
  },
728
728
  }
729
729
  this.renderedIsvComponents = {}
730
730
  this.rootEleNode = document.querySelector('body')
731
731
  this.checkStatusAndLoginPromise = null
732
732
  this.jmfeRegisterStatePromise = null
733
733
  isJdApp && this.jmfeReayPromise()
734
734
  }
735
735
  _getConfig(opt) {
736
736
  return Object.assign({}, DefaultConfig, opt)
737
737
  }
738
738
 
739
739
  jmfeReayPromise(): Promise<any> {
740
740
  if(isJdApp) {
741
741
  if(this.jmfeRegisterState){
742
742
  return Promise.resolve(true)
743
743
  }else {
744
744
  !this.jmfeRegisterStatePromise && (this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
745
745
  ready('jmfe', 3000).then(() => {
746
746
  window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE)
747
747
  this.jmfeRegisterState = true
748
748
  resolve(true)
749
749
  console.log('松果app内初始化注册jmfe认证完成')
750
750
  }).catch(() => {
751
751
  reject(false)
752
752
  })
753
753
  }))
754
754
  return this.jmfeRegisterStatePromise
755
755
  }
756
756
  }else {
757
757
  return Promise.reject(false)
758
758
  }
759
759
  }
760
760
 
761
761
  updateBusinessDomainAndApi(domain, api) {
762
762
  }
763
763
 
764
764
  formatNativeScreenPageData(action) {
765
765
  let getChangePageInfo: any = null
766
766
  try {
767
767
  const getNativeScreenPageInfoStr = window.XWebView?._callNative(JSON.stringify({
768
768
  plugin: "JDHybridScreenPlugin",
769
769
  action,
770
770
  sync: "1"
771
771
  }));
772
772
  const getChangePageInfoData = typeof getNativeScreenPageInfoStr === 'string' ? JSON.parse(getNativeScreenPageInfoStr) : null
773
773
  if(getChangePageInfoData && typeof getChangePageInfoData === 'object'){
774
774
  const { code, data} = getChangePageInfoData
775
775
  getChangePageInfo = code && code === "0" ? data : null;
776
776
  }
777
777
  }catch (e) {
778
778
  console.log("JDHybridScreenPlugin转换异常", e)
779
779
  }
780
780
  return getChangePageInfo
781
781
  }
782
782
 
783
783
  isAndroidFoldScreen() {
784
784
  return this.formatNativeScreenPageData('isFoldScreen') === '1'
785
785
  }
786
786
 
787
787
  getJdAndroidPageChangeScreenInfo() {
788
788
  const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize')
789
789
  if(getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight){
790
790
  const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
791
791
  pageWidth: getPageScreenInfo.pageWidth,
792
792
  pageHeight: getPageScreenInfo.pageHeight
793
793
  })
794
794
  getPageScreenInfo.pageWidth = pageWidth
795
795
  getPageScreenInfo.pageHeight = pageHeight
796
796
  }
797
797
  return getPageScreenInfo
798
798
  }
799
799
 
800
800
  getSystemInfo(params) {
801
801
  let info: UtilsInterFace.taroGetSystemInfoSyncRes | {} = isPc
802
802
  ? {}
803
803
  : getSystemInfos(params)
804
804
  if(isJdAndAndroidDevice && window.innerWidth <= 0){
805
805
  const isfoldScreen = this.isAndroidFoldScreen()
806
806
  if(isfoldScreen){
807
807
  const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo()
808
808
  getJdAndroidPageInfo && (info = getSystemInfos(getJdAndroidPageInfo))
809
809
  console.info("安卓松果app折叠屏获取webview宽度为0,那么通过内部方法重置获取",getJdAndroidPageInfo)
810
810
  }
811
811
  }
812
812
  this.info.sysInfo = {
813
813
  actualNavBarHeight: 0,
814
814
  ...this.info.sysInfo,
815
815
  ...info,
816
816
  safeContentHeight: info?.screenHeight,
817
817
  headerHeight: 0,
818
818
  tabBarHeight: 0,
819
819
  }
820
820
  if (isJdApp) {
821
821
  this.info.sysInfo['hostVersionName'] = jdAppVersionStr
822
822
  this.info.sysInfo['hostAppVersion'] = jdAppVersion
823
823
  this.getAddressCachePromise()
824
824
  this.getElderModePromise()
825
825
  this.getJDAppearanceStatePromise()
826
826
  this.createJdAndroidRquestEventForTouchStart()
827
827
  }
828
828
  this.getNetWorkType()
829
829
  }
830
830
 
831
831
  taskTimeoutPromise(callBack, timeout = 2000){
832
832
  return new Promise((resolve) => {
833
833
  setTimeout(() => {
834
834
  const getCallBackRes = typeof callBack === 'function' && callBack()
835
835
  return resolve(getCallBackRes || false)
836
836
  }, timeout)
837
837
  })
838
838
  }
839
839
 
840
840
  getElderModePromise(){
841
841
  if(this.info.sysInfo.hasOwnProperty('jdAppModeType')){
842
842
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
843
843
  }else {
844
844
  if(isJdAndAndroidDevice){
845
845
  this.info.sysInfo.jdAppModeType = "0"
846
846
  return Promise.resolve(this.info.sysInfo.jdAppModeType)
847
847
  }else {
848
848
  return Promise.race([this.taskTimeoutPromise(() => {
849
849
  this.info.sysInfo.jdAppModeType = "0"
850
850
  return this.info.sysInfo.jdAppModeType
851
851
  }),new Promise(resolve => {
852
852
  const getCallBackName = `getJdCurrentModeType${Date.now()}`
853
853
  if(!window[getCallBackName]){
854
854
  window[getCallBackName] = (res) => {
855
855
  try {
856
856
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
857
857
  const {status, data, msg} = getResJson
858
858
  console.log(`获取松果app展示模式成功,返回结果${data}`)
859
859
  if(status === '0'){
860
860
  this.info.sysInfo.jdAppModeType = data
861
861
  resolve(data)
862
862
  }else {
863
863
  resolve("0")
864
864
  }
865
865
  }catch (e) {
866
866
  resolve("0")
867
867
  }
868
868
  window[getCallBackName] = null
869
869
  }
870
870
  }
871
871
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
872
872
  method: 'callSyncRouterModuleWithParams',
873
873
  params: JSON.stringify({
874
874
  routerURL: "router://JDBModeModule/getCurrentMode",
875
875
  routerParam: {},
876
876
  callBackName: `window.${getCallBackName}`,
877
877
  callBackId: `${getCallBackName}Ios`,
878
878
  }),
879
879
  })
880
880
  })])
881
881
  }
882
882
  }
883
883
  }
884
884
 
885
885
  getJDAppearanceStatePromise() {
886
886
  if(this.info.sysInfo.hasOwnProperty('jdAppearanceState')){
887
887
  return Promise.resolve(this.info.sysInfo.jdAppearanceState)
888
888
  } else {
889
889
  return Promise.race([this.taskTimeoutPromise(() => {
890
890
  this.info.sysInfo.jdAppearanceState = "0"
891
891
  return this.info.sysInfo.jdAppearanceState
892
892
  }),new Promise(resolve => {
893
893
  const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`
894
894
  if(!window[getCallBackName]){
895
895
  window[getCallBackName] = (res) =>{
896
896
  try {
897
897
  console.log('getJDAppearanceStatePromise',res)
898
898
  const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
899
899
  const {status, data, msg} = getResJson
900
900
  console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`)
901
901
  if(status === '0'){
902
902
  this.info.sysInfo.jdAppearanceState = data
903
903
  resolve(data)
904
904
  }else {
905
905
  resolve("0")
906
906
  }
907
907
  }catch (e) {
908
908
  resolve("0")
909
909
  }
910
910
  window[getCallBackName] = null
911
911
  }
912
912
  }
913
913
  if(isAndroidDevice) {
914
914
  const jsonString = JSON.stringify({
915
915
  callBackName: `window.${getCallBackName}`,
916
916
  })
917
917
  console.log('window.JDAppearance',window.JDAppearance)
918
918
  window.JDAppearance && window.JDAppearance.getUiState(jsonString);
919
919
  } else {
920
920
  window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
921
921
  method: 'callSyncRouterModuleWithParams',
922
922
  params: JSON.stringify({
923
923
  routerURL: "router://JDWebViewBusinessModule/getJDAppearanceState",
924
924
  routerParam: {},
925
925
  callBackName: `window.${getCallBackName}`,
926
926
  callBackId: `${getCallBackName}Ios`,
927
927
  }),
928
928
  })
929
929
  }
930
930
  })])
931
931
  }
932
932
  }
933
933
 
934
934
  createJdAndroidRquestEventForTouchStart(){
935
935
  if(isJdAndAndroidDevice && window.JdAndroid){
936
936
  const rootEleNode = document.querySelector('body')
937
937
  if(rootEleNode){
938
938
  rootEleNode.addEventListener(
939
939
  'touchstart',
940
940
  this.jdAndroidAddEventListenerTouchStart,
941
941
  false,
942
942
  )
943
943
  }
944
944
  }
945
945
  }
946
946
  jdAndroidAddEventListenerTouchStart(e){
947
947
  const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom')
948
948
  if(!isH5SwiperCustomEle){
949
949
  const hasCustomEle = e ? (e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')) : false
950
950
  if (!hasCustomEle) {
951
951
  window.JdAndroid.requestEvent(false)
952
952
  console.log("createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false")
953
953
  }
954
954
  }
955
955
  }
956
956
  removeJdAndroidRquestEventForTouchStart(){
957
957
  if(isJdAndAndroidDevice && window.JdAndroid){
958
958
  const rootEleNode = document.querySelector('body')
959
959
  if(rootEleNode){
960
960
  rootEleNode.removeEventListener(
961
961
  'touchstart',
962
962
  this.jdAndroidAddEventListenerTouchStart,
963
963
  false,
964
964
  )
965
965
  }
966
966
  }
967
967
  }
968
968
 
969
969
  getNetWorkType() {
970
970
  if (isJdApp) {
971
971
  this.jmfeReayPromise().then(() => {
972
972
  window.jmfe.getNetworkStatus().then(({ status, data }) => {
973
973
  console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data)
974
974
  if (status === '0') {
975
975
  this.info.sysInfo['netWorkType'] = data
976
976
  }else {
977
977
  this._taroGetNetworkType()
978
978
  }
979
979
  }).catch((err) => {
980
980
  console.log('在app内初始化通过jmfe对象获取网络状态异常====', err)
981
981
  this._taroGetNetworkType()
982
982
  })
983
983
  })
984
984
  } else {
985
985
  this._taroGetNetworkType()
986
986
  }
987
987
  }
988
988
  _taroGetNetworkType(){
989
989
  Taro.getNetworkType().then((getRes) => {
990
990
  if (getRes &&
991
991
  getRes.networkType) {
992
992
  (this.info.sysInfo['netWorkType'] = getRes.networkType)
993
993
  console.log('在app内通过taro对象获取网络状态完成,当前网络状态', this.info.sysInfo['netWorkType'])
994
994
  }
995
995
  })
996
996
  }
997
997
  getCacheAddressRouter() {
998
998
  if (!window.jmfe) return
999
999
  if (isAndroidDevice) {
1000
1000
  return window.jmfe.callRouter({
1001
1001
  jdRouter: '1',
1002
1002
  routerURL: 'router://JDAddressModule/getCacheAddress',
1003
1003
  routerParam: { sceneId: 'basicShoppingProcess' },
1004
1004
  })
1005
1005
  } else if(isIosDevice) {
1006
1006
  return window.jmfe.callRouter({
1007
1007
  jdRouter: '1',
1008
1008
  routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
1009
1009
  routerParam: { sceneId: 'basicShoppingProcess' },
1010
1010
  })
1011
1011
  } else if(isJdAndHarmonyDevice){
1012
1012
  return new Promise((resolve)=>{
1013
1013
  resolve({})
1014
1014
  })
1015
1015
  } else{
1016
1016
  throw Error('Unknown device type cannot obtain the address information through the route!')
1017
1017
  }
1018
1018
  }
1019
1019
 
1020
1020
  getAddressCachePromise() {
1021
1021
  return new Promise((resolve) => {
1022
1022
  if (
1023
1023
  this?.info?.sysInfo?.lat &&
1024
1024
  this?.info?.sysInfo?.lng &&
1025
1025
  this?.info?.sysInfo?.area
1026
1026
  ) {
1027
1027
  resolve({
1028
1028
  lat: this.info.sysInfo.lat,
1029
1029
  lng: this.info.sysInfo.lng,
1030
1030
  area: this?.info?.sysInfo?.area,
1031
1031
  })
1032
1032
  } else {
1033
1033
  this.jmfeReayPromise().then(() => {
1034
1034
  this.getCacheAddressRouter()
1035
1035
  .then(({ status, data }) => {
1036
1036
  if (status === '0' && data) {
1037
1037
  const { lat , latitude, lng, longitude, provinceId, cityId,
1038
1038
  countyId,townId} = data || {}
1039
1039
  let area = '';
1040
1040
  this.info.sysInfo['lat'] = `${lat || latitude || ''}`
1041
1041
  this.info.sysInfo['lng'] = `${lng || longitude || ''}`
1042
1042
  if (provinceId) {
1043
1043
  area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`
1044
1044
  this.info.pageInfo['address'] = area
1045
1045
  this.info.pageInfo['addressCommaStr'] = area.replace(/_/g,',')
1046
1046
  }
1047
1047
  resolve({
1048
1048
  lat: this.info.sysInfo['lat'],
1049
1049
  lng: this.info.sysInfo['lng'],
1050
1050
  area: area,
1051
1051
  })
1052
1052
  } else {
1053
1053
  resolve({ lat: '', lng: '', area: '' })
1054
1054
  }
1055
1055
  })
1056
1056
  .catch((e) => {
1057
1057
  console.log(" ~~ file: index.h5.ts:514 ~~ .catch ~~ e:", e)
1058
1058
  resolve({ lat: '', lng: '', area: '' })
1059
1059
  })
1060
1060
  }).catch((e) => {
1061
1061
  console.log(" ~~ file: index.h5.ts:518 ~~ .catch ~~ e:", e)
1062
1062
  resolve({ lat: '', lng: '', area: '' })
1063
1063
  console.log("判断jmfe不存在,获取经纬度信息异常")
1064
1064
  })
1065
1065
  }
1066
1066
  })
1067
1067
  }
1068
1068
 
1069
1069
  toLogin(options) {
1070
1070
  return (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState)
1071
1071
  ? this.toWxAppLogin(options)
1072
1072
  : this.toWebLogin(options)
1073
1073
  }
1074
1074
 
1075
1075
  doLogin(options) {
1076
1076
  return this.toLogin(options)
1077
1077
  }
1078
1078
 
1079
1079
  doLoginForJdPin(options = {}) {
1080
1080
  return this.doLogin({
1081
1081
  loginColor: {
1082
1082
  biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
1083
1083
  dpin: 0,
1084
1084
  },
1085
1085
  ...options
1086
1086
  })
1087
1087
  }
1088
1088
 
1089
1089
  toWebLogin(options) {
1090
1090
  let params: {
1091
1091
  returnurl: string
1092
1092
  } = {
1093
1093
  returnurl: '',
1094
1094
  }
1095
1095
  const loginUrl = isPc
1096
1096
  ? `//passport.jd.com/new/login.aspx`
1097
1097
  : `${domain.mobileLogin}/user/login.action`
1098
1098
  const defaultParams = {
1099
1099
  appid: '100',
1100
1100
  returnurl: window.location.href,
1101
1101
  }
1102
1102
  if (isString(options)) {
1103
1103
  params = Object.assign({}, defaultParams, {
1104
1104
  returnurl: options,
1105
1105
  })
1106
1106
  } else if (isObject(options)) {
1107
1107
  const { loginColor, ...otherOptions} = options
1108
1108
  params = Object.assign({}, defaultParams, otherOptions)
1109
1109
  } else {
1110
1110
  params = defaultParams
1111
1111
  }
1112
1112
  params.returnurl = encodeURIComponent(params.returnurl)
1113
1113
  let getFullUrl = loginUrl + '?' + serialize(params)
1114
1114
  if (isPc) {
1115
1115
  getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl')
1116
1116
  }
1117
1117
  return Promise.resolve({
1118
1118
  h5ToUrl: true,
1119
1119
  url: getFullUrl,
1120
1120
  }).then(() => {
1121
1121
  window.location.href = getFullUrl
1122
1122
  })
1123
1123
  }
1124
1124
 
1125
1125
  toWxAppLogin(options = {}) {
1126
1126
  console.log('微信京购小程序中h5登录跳转', options)
1127
1127
  return Promise.resolve(true).then(() => {
1128
1128
  const { loginColor } = Object.assign({},{
1129
1129
  loginColor: {
1130
1130
  bzi:WXAPP_BIZ_KEY,
1131
1131
  dpin: 1,
1132
1132
  },
1133
1133
  }, options)
1134
1134
  window.location.href = `${
1135
1135
  domain.wq
1136
1136
  }/pinbind/pintokenredirect?biz=${loginColor.bzi}&url=${encodeURIComponent(
1137
1137
  window.location.href,
1138
1138
  )}`
1139
1139
  })
1140
1140
  }
1141
1141
 
1142
1142
  getLoginCookie() {
1143
1143
  return Promise.resolve({
1144
1144
  pin: cookie.get('pin') || '',
1145
1145
  })
1146
1146
  }
1147
1147
 
1148
1148
  clearLoginCookie() {
1149
1149
  cookie.remove('pin')
1150
1150
  }
1151
1151
 
1152
1152
  checkStatusAndLogin(options = {}) {
1153
1153
  if (!this.checkStatusAndLoginPromise) {
1154
1154
  this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
1155
1155
  try {
1156
1156
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options)
1157
1157
  if (getLoginState) {
1158
1158
  resolve(true)
1159
1159
  } else {
1160
1160
  this.toLogin(options)
1161
1161
  reject(false)
1162
1162
  }
1163
1163
  } catch (e) {
1164
1164
  this.toLogin(options)
1165
1165
  reject(false)
1166
1166
  }
1167
1167
  })
1168
1168
  return this.checkStatusAndLoginPromise
1169
1169
  } else {
1170
1170
  return this.checkStatusAndLoginPromise
1171
1171
  .then(() => {
1172
1172
  return Promise.resolve(true)
1173
1173
  })
1174
1174
  .catch(() => {
1175
1175
  this.toLogin(options)
1176
1176
  return Promise.reject(true)
1177
1177
  })
1178
1178
  }
1179
1179
  }
1180
1180
 
1181
1181
  checkJdStatusAndLogin(options = {
1182
1182
  loginColor: {
1183
1183
  bzi: WXAPP_BIZ_SHOP_LIGHT_KEY,
1184
1184
  dpin: 0,
1185
1185
  },
1186
1186
  }){
1187
1187
  return this.checkStatusAndLogin(options)
1188
1188
  }
1189
1189
 
1190
1190
  doCheckLoginStateAndForApiCheck(options) {
1191
1191
  if (this.info.loginState) {
1192
1192
  return Promise.resolve(true)
1193
1193
  } else {
1194
1194
  return new Promise((resolve, reject) => {
1195
1195
  if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
1196
1196
  const getWqAuthToken = cookie.get('wq_auth_token')
1197
1197
  const getWqSkey = cookie.get('wq_skey')
1198
1198
  const getWqUin = cookie.get('wq_uin')
1199
1199
  const isLoginState = options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
1200
1200
  if(isLoginState){
1201
1201
  this.info.loginState = true
1202
1202
  resolve(true)
1203
1203
  }else {
1204
1204
  reject(false)
1205
1205
  }
1206
1206
  } else {
1207
1207
  Taro.request({
1208
1208
  url: api.isLogin,
1209
1209
  jsonp: true,
1210
1210
  timeout: 3000,
1211
1211
  success: (res) => {
1212
1212
  const { statusCode, data } = res
1213
1213
  if (
1214
1214
  statusCode === 200 &&
1215
1215
  data?.islogin &&
1216
1216
  Number(data.islogin) === 1
1217
1217
  ) {
1218
1218
  this.info.loginState = true
1219
1219
  resolve(true)
1220
1220
  } else {
1221
1221
  reject(false)
1222
1222
  }
1223
1223
  },
1224
1224
  fail: (err) => {
1225
1225
  console.log('登录检查异常', err)
1226
1226
  reject(false)
1227
1227
  },
1228
1228
  })
1229
1229
  }
1230
1230
  })
1231
1231
  }
1232
1232
  }
1233
1233
 
1234
1234
  checkLoginStatus(options) {
1235
1235
  return new Promise(async (resolve, reject) => {
1236
1236
  try {
1237
1237
  const getLoginState = await this.doCheckLoginStateAndForApiCheck(options)
1238
1238
  if (getLoginState) {
1239
1239
  const { pin } = await this.getLoginCookie()
1240
1240
  this.info.userInfo = {
1241
1241
  pin,
1242
1242
  encodePin: encodeURIComponent(pin),
1243
1243
  ptkey: '',
1244
1244
  }
1245
1245
  resolve(true)
1246
1246
  } else {
1247
1247
  reject(false)
1248
1248
  }
1249
1249
  } catch (e) {
1250
1250
  reject(false)
1251
1251
  }
1252
1252
  })
1253
1253
  }
1254
1254
 
1255
1255
  updatePageAndLogInfo(updateQuery = {}) {
1256
1256
  const createUpdateQueryInfo: {
1257
1257
  query: {
1258
1258
  shopId?: string | number
1259
1259
  venderId?: string | number
1260
1260
  }
1261
1261
  updateShopInfoState: boolean
1262
1262
  } = Object.assign(
1263
1263
  {},
1264
1264
  {
1265
1265
  query: {},
1266
1266
  updateShopInfoState: false,
1267
1267
  },
1268
1268
  updateQuery,
1269
1269
  )
1270
1270
  console.log(
1271
1271
  '获取当前下发的店铺查询参数',
1272
1272
  updateQuery,
1273
1273
  '获取之前保存的shopInfo店铺查询参数',
1274
1274
  this.info?.shopInfo,
1275
1275
  )
1276
1276
  const { query, updateShopInfoState } = createUpdateQueryInfo
1277
1277
  const { shopId, venderId, un_area } = query
1278
1278
  if (updateShopInfoState) {
1279
1279
  this.info.queryInfo = {
1280
1280
  ...this.info.queryInfo,
1281
1281
  ...query,
1282
1282
  }
1283
1283
  if (shopId && venderId) {
1284
1284
  this.info.shopInfo = {
1285
1285
  shopId: `${shopId}`,
1286
1286
  venderId: `${venderId}`,
1287
1287
  }
1288
1288
  }
1289
1289
  } else {
1290
1290
  this.info.queryInfo = {
1291
1291
  ...query,
1292
1292
  }
1293
1293
  if (
1294
1294
  this.info.shopInfo?.shopId &&
1295
1295
  this.info.shopInfo?.venderId &&
1296
1296
  (this.info.shopInfo.shopId == shopId ||
1297
1297
  this.info.shopInfo.venderId == venderId)
1298
1298
  ) {
1299
1299
  this.info.queryInfo.shopId = this.info.shopInfo.shopId
1300
1300
  this.info.queryInfo.venderId = this.info.shopInfo.venderId
1301
1301
  console.log(
1302
1302
  '当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
1303
1303
  this.info.queryInfo,
1304
1304
  )
1305
1305
  }
1306
1306
  }
1307
1307
  this.info.queryInfo['shopId'] &&
1308
1308
  (this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`)
1309
1309
  this.info.queryInfo['venderId'] &&
1310
1310
  (this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`)
1311
1311
  console.log(
1312
1312
  'h5==获取店铺下发查询参数\n',
1313
1313
  query,
1314
1314
  '\n获取店铺最后查询参数\n',
1315
1315
  this.info.queryInfo,
1316
1316
  '\n是否为更新店铺状态\n',
1317
1317
  updateShopInfoState,
1318
1318
  )
1319
1319
  const changeArea =
1320
1320
  un_area && un_area.length > 0 ? un_area : ipLoc_djd ? ipLoc_djd : ''
1321
1321
  if (changeArea) {
1322
1322
  this.info.pageInfo.address = changeArea
1323
1323
  this.info.pageInfo.un_area = changeArea
1324
1324
  this.info.pageInfo.addressCommaStr = changeArea.replace(/_/g, ',')
1325
1325
  }
1326
1326
  }