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