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