@conecli/cone-render 0.10.1-shop3.74 → 0.10.1-shop3.76
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
|
BUSINESS_TYPE,
|
|
3
2
|
cacheAppKey,
|
|
4
3
|
cacheAppUuidKey,
|
|
5
4
|
cacheH5LbsAddressKey,
|
|
6
5
|
JSSDK_APP_WEBVIEW_CODE,
|
|
7
6
|
LoadJsInitLoadEnvType,
|
|
8
7
|
LoadJsInitLoadType,
|
|
9
8
|
LoadJsInitTriggerType,
|
|
10
9
|
MPAAS_CONFIG_APP_LOW_VERSION,
|
|
11
10
|
MPAAS_CONFIG_APP_VERSION,
|
|
12
11
|
SECTION_HOME_TAB_NAME_TYPE,
|
|
13
12
|
SECTION_HOME_TAB_TYPE,
|
|
14
13
|
TaroEventType,
|
|
15
14
|
WX_BUSINESS_TYPE,
|
|
16
15
|
WXAPP_BIZ_KEY,
|
|
17
16
|
WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
18
17
|
languageTypeList,
|
|
19
18
|
getSystemInfos,
|
|
20
19
|
getTaroStorageKeyValue,
|
|
21
20
|
ipLoc_djd,
|
|
22
21
|
setTaroStorage,
|
|
23
22
|
sgmCustomReport,
|
|
24
23
|
isInJdAppH5DebugMode
|
|
25
24
|
callRouterAndroid,
|
|
26
25
|
callRouterIOS,
|
|
27
26
|
getMPaasConfigByBussinessKey,
|
|
28
27
|
dealNativePixelToCssPixel,
|
|
29
28
|
draBusinessCustomReport,
|
|
30
29
|
isAndroidDevice,
|
|
31
30
|
isH5AndJingGouMini,
|
|
32
31
|
isIosDevice,
|
|
33
32
|
isJdAndAndroidDevice,
|
|
34
33
|
isObject,
|
|
35
34
|
isPc,
|
|
36
35
|
isString,
|
|
37
36
|
jdAppVersion,
|
|
38
37
|
jdAppVersionStr,
|
|
39
38
|
serialize,
|
|
40
39
|
languageNowType,
|
|
41
40
|
urlCookie,
|
|
42
41
|
jdAppVersionCompare
|
|
43
42
|
abTestLabels: {},
|
|
44
43
|
nonSellableSkuids: {},
|
|
45
44
|
loginState: false,
|
|
46
45
|
cookiesStr: '',
|
|
47
46
|
userInfo: userPinKey,
|
|
48
47
|
isImmersive: false,
|
|
49
48
|
isJingGouMiniViewState: false,
|
|
50
49
|
isJingxiMiniViewState: false,
|
|
51
50
|
pageInfo: {
|
|
52
51
|
wxBusinessType: WX_BUSINESS_TYPE.NO,
|
|
53
52
|
address: '',
|
|
54
53
|
addressCommaStr: '',
|
|
55
54
|
un_area: '',
|
|
56
55
|
userLbsAddress: '',
|
|
57
56
|
vapptype: '1',
|
|
58
57
|
pageType: 'home',
|
|
59
58
|
isExposureState: false,
|
|
60
59
|
moduleId: '',
|
|
61
60
|
entrance: '',
|
|
62
61
|
dataType: BUSINESS_TYPE.ONLINE,
|
|
63
62
|
floorExposureInfo: {},
|
|
64
63
|
floorVideInfo: {},
|
|
65
64
|
productVideInfo: {},
|
|
66
65
|
tabsLoadAllDataInfo: {
|
|
67
66
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
|
|
68
67
|
},
|
|
69
68
|
updateShopInfosAllState: false,
|
|
70
69
|
isVipShop: false,
|
|
71
70
|
isJdShowNativeImmersivePlayer: false,
|
|
72
71
|
...shopConfig,
|
|
73
72
|
pageScrollTop: 0,
|
|
74
73
|
pageIdxHeightInfo: {
|
|
75
74
|
list: [],
|
|
76
75
|
},
|
|
77
76
|
shopNavBarHeight: 0,
|
|
78
77
|
},
|
|
79
78
|
defaultQueryLogInfo: {
|
|
80
79
|
sourceType: 'JDshop',
|
|
81
80
|
sourceValue: '',
|
|
82
81
|
moduleId: 'none',
|
|
83
82
|
entrance: 'none',
|
|
84
83
|
},
|
|
85
84
|
sysInfo: {
|
|
86
85
|
windowWidth: isPc ? 375 : 0,
|
|
87
86
|
containerWidth: isPc ? 375 : 0,
|
|
88
87
|
windowHeight: 0,
|
|
89
88
|
netWorkType: '4g',
|
|
90
89
|
jdBottomBarHeight: 0,
|
|
91
90
|
jdNativeHeaderHeight: 0,
|
|
92
91
|
isJdTabletDevice: false,
|
|
93
92
|
isJdTabletLandscape: false,
|
|
94
93
|
},
|
|
95
94
|
queryInfo: {},
|
|
96
95
|
shopInfo: {},
|
|
97
96
|
openAppData: {},
|
|
98
97
|
public info: CommonInterFace.BaseConfigInfo;
|
|
99
98
|
public config: {
|
|
100
99
|
[key: string]: any;
|
|
101
100
|
};
|
|
102
101
|
public lazyContainer: CommonInterFace.lazyContainer;
|
|
103
102
|
public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
|
|
104
103
|
public rootEleNode: HTMLElement | null;
|
|
105
104
|
public checkStatusAndLoginPromise: object | null;
|
|
106
105
|
private jmfeRegisterStatePromise: Promise<any> | null;
|
|
107
106
|
private jdScreenSizeInfoPromise: Promise<any> | null;
|
|
108
107
|
private rootEleWidthRegisterPromise: Promise<any> | null;
|
|
109
108
|
private jmfeRegisterState: boolean;
|
|
110
109
|
public loadJsSdkList: Array<any>;
|
|
111
110
|
public loadJsSdkListCachePromise: any;
|
|
112
111
|
public rootEleInitWidth: number;
|
|
113
112
|
public lbsAddressCachePromise: Promise<any> | null;
|
|
114
113
|
public languageCacheProimse: Promise<any> | null;
|
|
115
114
|
public languageJsonData: any | null;
|
|
116
115
|
public businessWorkerReady: boolean;
|
|
117
116
|
public businessWorkerReadyPromise: Promise<any> | null;
|
|
118
117
|
public workerPreRequestData = new Map<string, any>();
|
|
119
118
|
constructor(opt) {
|
|
120
119
|
this.info = this._getConfig(opt);
|
|
121
120
|
this.config = {};
|
|
122
121
|
this.loadJsSdkList = [];
|
|
123
122
|
this.loadJsSdkListCachePromise = {};
|
|
124
123
|
this.lazyContainer = {
|
|
125
124
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
|
|
126
125
|
appLazyContainerList: [],
|
|
127
126
|
appLazyFinishContainerList: [],
|
|
128
127
|
},
|
|
129
128
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
|
|
130
129
|
appLazyContainerList: [],
|
|
131
130
|
appLazyFinishContainerList: [],
|
|
132
131
|
},
|
|
133
132
|
};
|
|
134
133
|
this.renderedIsvComponents = {};
|
|
135
134
|
this.rootEleNode = document.querySelector('body');
|
|
136
135
|
this.checkStatusAndLoginPromise = null;
|
|
137
136
|
this.jmfeRegisterStatePromise = null;
|
|
138
137
|
this.jdScreenSizeInfoPromise = null;
|
|
139
138
|
this.rootEleWidthRegisterPromise = null;
|
|
140
139
|
this.lbsAddressCachePromise = null;
|
|
141
140
|
this.languageCacheProimse = null;
|
|
142
141
|
this.businessWorkerReady = false;
|
|
143
142
|
this.businessWorkerReadyPromise = null;
|
|
144
143
|
this.workerPreRequestData = new Map<string, any>();
|
|
145
144
|
this.languageJsonData = langeJsonDataForCn;
|
|
146
145
|
this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
|
|
147
146
|
this.loadOtherSdk();
|
|
148
147
|
if (isJdApp) {
|
|
149
148
|
this.jmfeReayPromise().then(() => {
|
|
150
149
|
this.jdWorkerReadyPromise()
|
|
151
150
|
})
|
|
152
151
|
this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
|
|
153
152
|
if (isJdAndHarmonyDevice) {
|
|
154
153
|
this.renderNextTickLoadSdk(2000);
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
_getConfig(opt) {
|
|
159
158
|
return Object.assign({}, DefaultConfig, opt);
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
jmfeReayPromise(): Promise<any> {
|
|
163
162
|
if (isJdApp) {
|
|
164
163
|
if (this.jmfeRegisterState) {
|
|
165
164
|
return Promise.resolve(true);
|
|
166
165
|
} else {
|
|
167
166
|
!this.jmfeRegisterStatePromise &&
|
|
168
167
|
(this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
|
|
169
168
|
ready('jmfe', 3000)
|
|
170
169
|
.then(() => {
|
|
171
170
|
window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
|
|
172
171
|
this.jmfeRegisterState = true;
|
|
173
172
|
resolve(true);
|
|
174
173
|
console.log(
|
|
175
174
|
'松果app内初始化注册jmfe认证完成',
|
|
176
175
|
window?.jmfe,
|
|
177
176
|
'当前版本',
|
|
178
177
|
window?.jmfe?.VERSION,
|
|
179
178
|
);
|
|
180
179
|
})
|
|
181
180
|
.catch((err) => {
|
|
182
181
|
console.error('jmfe ready error', err);
|
|
183
182
|
reject(false);
|
|
184
183
|
});
|
|
185
184
|
}));
|
|
186
185
|
return this.jmfeRegisterStatePromise;
|
|
187
186
|
}
|
|
188
187
|
} else {
|
|
189
188
|
return Promise.reject(false);
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
|
|
193
192
|
jdWorkerReadyPromise(): Promise<any> {
|
|
194
193
|
if (isJdApp) {
|
|
195
194
|
if (this.businessWorkerReady) {
|
|
196
195
|
return Promise.resolve(true);
|
|
197
196
|
} else {
|
|
198
197
|
const getOpenJdWorkerState = window?.PAGE_DATA?.businessData?.businessWorkerVersion && versionCompare(jdAppVersionStr, window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10') >= 0;
|
|
199
198
|
!this.businessWorkerReadyPromise && (this.businessWorkerReadyPromise = getOpenJdWorkerState ?
|
|
200
199
|
new Promise((resolve) => {
|
|
201
200
|
this.jmfeReayPromise().then(() => {
|
|
202
201
|
window.jmfe
|
|
203
202
|
.onMsgForWorker(
|
|
204
203
|
{ version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
|
|
205
204
|
(workerData) => {
|
|
206
205
|
console.log(
|
|
207
206
|
'收到业务jd worker消息结果:',
|
|
208
207
|
workerData,
|
|
209
208
|
);
|
|
210
209
|
if (workerData && workerData?.workerType) {
|
|
211
210
|
const getWorkerType = workerData?.workerType
|
|
212
211
|
if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
|
|
213
212
|
this.workerPreRequestData.set(workerData?.functionId, workerData);
|
|
214
213
|
Taro.eventCenter.trigger(
|
|
215
214
|
getWorkerType,
|
|
216
215
|
workerData);
|
|
217
216
|
} else if (getWorkerType === TaroEventType.jdWorkerRequest) {
|
|
218
217
|
Taro.eventCenter.trigger(
|
|
219
218
|
getWorkerType,
|
|
220
219
|
workerData);
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
222
|
},
|
|
224
223
|
)
|
|
225
224
|
.then(() => {
|
|
226
225
|
console.log('jd worker注册成功');
|
|
227
226
|
this.businessWorkerReady = true;
|
|
228
227
|
resolve(true);
|
|
229
228
|
})
|
|
230
229
|
.catch((error) => {
|
|
231
230
|
console.log('jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑', error);
|
|
232
231
|
draBusinessCustomReport({
|
|
233
232
|
eventName:'business',
|
|
234
233
|
errorName: 'jmfe_onMsgForWorker_error',
|
|
235
234
|
errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
|
|
236
235
|
extraData: JSON.stringify({
|
|
237
236
|
businessWorkerVersion:window?.PAGE_DATA?.businessData?.businessWorkerVersion,
|
|
238
237
|
error,
|
|
239
238
|
}),
|
|
240
239
|
});
|
|
241
240
|
resolve(false);
|
|
242
241
|
});
|
|
243
242
|
}).catch((err) => {
|
|
244
243
|
console.log('jmfe超时异常,worker注册失败', err);
|
|
245
244
|
resolve(false);
|
|
246
245
|
})
|
|
247
246
|
}) : Promise.resolve(false))
|
|
248
247
|
}
|
|
249
248
|
return this.businessWorkerReadyPromise
|
|
250
249
|
} else {
|
|
251
250
|
return Promise.resolve(false);
|
|
252
251
|
}
|
|
253
252
|
}
|
|
254
253
|
|
|
255
254
|
taskTimeoutPromise(callBack, timeout = 2000) {
|
|
256
255
|
return new Promise((resolve) => {
|
|
257
256
|
setTimeout(() => {
|
|
258
257
|
const getCallBackRes = typeof callBack === 'function' && callBack();
|
|
259
258
|
return resolve(getCallBackRes || false);
|
|
260
259
|
}, isInJdAppH5DebugMode ? 0 : timeout);
|
|
261
260
|
});
|
|
262
261
|
}
|
|
263
262
|
_getJdPadMinWidthForListen() {
|
|
264
263
|
return (
|
|
265
264
|
isJdApp &&
|
|
266
265
|
Math.min(window.screen.width, window.screen.height) >
|
|
267
266
|
(window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
|
|
268
267
|
);
|
|
269
268
|
}
|
|
270
269
|
|
|
271
270
|
getJdScreenSizeInfoPromise() {
|
|
272
271
|
!this.jdScreenSizeInfoPromise &&
|
|
273
272
|
(this.jdScreenSizeInfoPromise = new Promise((resolve) => {
|
|
274
273
|
const getThisTime = Date.now();
|
|
275
274
|
this.jmfeReayPromise().then(() => {
|
|
276
275
|
return Promise.race([
|
|
277
276
|
window.jmfe.getScreenSize(),
|
|
278
277
|
this.taskTimeoutPromise(() => {
|
|
279
278
|
return {
|
|
280
279
|
status: '-10',
|
|
281
280
|
msg: '获取大屏信息2s超时',
|
|
282
281
|
};
|
|
283
282
|
}),
|
|
284
283
|
])
|
|
285
284
|
.then((res) => {
|
|
286
285
|
console.warn('===获取app大屏信息====', res);
|
|
287
286
|
const { status, data } = res;
|
|
288
287
|
if (status === '0' && data) {
|
|
289
288
|
const { sizeType, isLandscape, pageHeight, pageWidth } = data;
|
|
290
289
|
const getPageInfo = dealNativePixelToCssPixel({
|
|
291
290
|
pageWidth,
|
|
292
291
|
pageHeight,
|
|
293
292
|
});
|
|
294
293
|
this.info.sysInfo.jdScreenSizeType = sizeType;
|
|
295
294
|
const getUseTime = Date.now() - getThisTime;
|
|
296
295
|
console.warn(
|
|
297
296
|
'===计算是否是app大屏信息,需满足宽度最新720===',
|
|
298
297
|
getPageInfo,
|
|
299
298
|
'原始数据',
|
|
300
299
|
data,
|
|
301
300
|
'是否是横屏isLandscape为1=',
|
|
302
301
|
isLandscape,
|
|
303
302
|
'用时',
|
|
304
303
|
getUseTime,
|
|
305
304
|
);
|
|
306
305
|
if (getPageInfo?.pageWidth > 0) {
|
|
307
306
|
this.rootEleInitWidth = getPageInfo?.pageWidth;
|
|
308
307
|
draBusinessCustomReport({
|
|
309
308
|
eventName: 'UIInteract',
|
|
310
309
|
errorName: 'rootEle_width_getJdScreenSizeInfo',
|
|
311
310
|
errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
|
|
312
311
|
extraData: JSON.stringify({
|
|
313
312
|
isJdApp,
|
|
314
313
|
getPageInfo,
|
|
315
314
|
originData: res,
|
|
316
315
|
}),
|
|
317
316
|
});
|
|
318
317
|
resolve(getPageInfo);
|
|
319
318
|
} else {
|
|
320
319
|
resolve({
|
|
321
320
|
pageWidth: 0,
|
|
322
321
|
pageHeight: 0,
|
|
323
322
|
msg: '转换异常',
|
|
324
323
|
});
|
|
325
324
|
}
|
|
326
325
|
} else {
|
|
327
326
|
resolve({
|
|
328
327
|
pageWidth: 0,
|
|
329
328
|
pageHeight: 0,
|
|
330
329
|
msg: '获取大屏信息异常或者超时',
|
|
331
330
|
});
|
|
332
331
|
}
|
|
333
332
|
})
|
|
334
333
|
.catch((err) => {
|
|
335
334
|
console.log('获取大屏信息异常', err);
|
|
336
335
|
resolve({
|
|
337
336
|
pageWidth: 0,
|
|
338
337
|
pageHeight: 0,
|
|
339
338
|
msg: '获取大屏信息异常',
|
|
340
339
|
});
|
|
341
340
|
});
|
|
342
341
|
});
|
|
343
342
|
}));
|
|
344
343
|
return this.jdScreenSizeInfoPromise;
|
|
345
344
|
}
|
|
346
345
|
|
|
347
346
|
listenJdTabletScreenChange() {
|
|
348
347
|
this.jmfeReayPromise().then(() => {
|
|
349
348
|
try {
|
|
350
349
|
console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
|
|
351
350
|
window.jmfe.listenDeviceScreenChange((event) => {
|
|
352
351
|
console.log(
|
|
353
352
|
'监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
|
|
354
353
|
event,
|
|
355
354
|
'通过前端判断是不是横屏',
|
|
356
355
|
window.matchMedia('(orientation: landscape)')?.matches,
|
|
357
356
|
);
|
|
358
357
|
const { orientation } = event?.data;
|
|
359
358
|
if (orientation) {
|
|
360
359
|
this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
|
|
361
360
|
Taro.eventCenter.trigger(
|
|
362
361
|
TaroEventType.TABLE_SCREEN_CHANGE,
|
|
363
362
|
this.info.sysInfo.isJdTabletLandscape,
|
|
364
363
|
orientation,
|
|
365
364
|
);
|
|
366
365
|
}
|
|
367
366
|
});
|
|
368
367
|
} catch (error) {
|
|
369
368
|
console.log('listenScreenChange的打印error:', error);
|
|
370
369
|
}
|
|
371
370
|
});
|
|
372
371
|
}
|
|
373
372
|
|
|
374
373
|
updateBusinessDomainAndApi(domain, api) {
|
|
375
374
|
}
|
|
376
375
|
|
|
377
376
|
formatNativeScreenPageData(action) {
|
|
378
377
|
let getChangePageInfo: any = null;
|
|
379
378
|
try {
|
|
380
379
|
const getNativeScreenPageInfoStr = window.XWebView?._callNative(
|
|
381
380
|
JSON.stringify({
|
|
382
381
|
plugin: 'JDHybridScreenPlugin',
|
|
383
382
|
action,
|
|
384
383
|
sync: '1',
|
|
385
384
|
}),
|
|
386
385
|
);
|
|
387
386
|
const getChangePageInfoData =
|
|
388
387
|
typeof getNativeScreenPageInfoStr === 'string'
|
|
389
388
|
? JSON.parse(getNativeScreenPageInfoStr)
|
|
390
389
|
: null;
|
|
391
390
|
if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
|
|
392
391
|
const { code, data } = getChangePageInfoData;
|
|
393
392
|
getChangePageInfo = code && code === '0' ? data : null;
|
|
394
393
|
}
|
|
395
394
|
} catch (e) {
|
|
396
395
|
console.log('JDHybridScreenPlugin转换异常', e);
|
|
397
396
|
}
|
|
398
397
|
return getChangePageInfo;
|
|
399
398
|
}
|
|
400
399
|
|
|
401
400
|
isAndroidFoldScreen() {
|
|
402
401
|
return this.formatNativeScreenPageData('isFoldScreen') === '1';
|
|
403
402
|
}
|
|
404
403
|
|
|
405
404
|
isHarmonyFoldScreenPromise(): Promise<{
|
|
406
405
|
isFoldScreen: boolean,
|
|
407
406
|
getFoldDisplayMode?: number,
|
|
408
407
|
}> {
|
|
409
408
|
return new Promise(resolve => {
|
|
410
409
|
this.jmfeReayPromise().then(() => {
|
|
411
410
|
if (window.jmfe?.callNative) {
|
|
412
411
|
Promise.all([
|
|
413
412
|
window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
|
|
414
413
|
window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {})
|
|
415
414
|
]).then(res => {
|
|
416
415
|
resolve({
|
|
417
416
|
isFoldScreen: res?.[0]?.data === '1',
|
|
418
417
|
getFoldDisplayMode: res?.[1]?.data,
|
|
419
418
|
})
|
|
420
419
|
}).catch(() => {
|
|
421
420
|
resolve({
|
|
422
421
|
isFoldScreen: false,
|
|
423
422
|
getFoldDisplayMode: undefined,
|
|
424
423
|
});
|
|
425
424
|
});
|
|
426
425
|
} else {
|
|
427
426
|
resolve({
|
|
428
427
|
isFoldScreen: false,
|
|
429
428
|
getFoldDisplayMode: undefined,
|
|
430
429
|
});
|
|
431
430
|
}
|
|
432
431
|
}).catch(() => {
|
|
433
432
|
resolve({
|
|
434
433
|
isFoldScreen: false,
|
|
435
434
|
getFoldDisplayMode: undefined,
|
|
436
435
|
});
|
|
437
436
|
});
|
|
438
437
|
})
|
|
439
438
|
}
|
|
440
439
|
|
|
441
440
|
getJdAndroidPageChangeScreenInfo() {
|
|
442
441
|
const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
|
|
443
442
|
if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
|
|
444
443
|
const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
|
|
445
444
|
pageWidth: getPageScreenInfo.pageWidth,
|
|
446
445
|
pageHeight: getPageScreenInfo.pageHeight,
|
|
447
446
|
});
|
|
448
447
|
getPageScreenInfo.pageWidth = pageWidth;
|
|
449
448
|
getPageScreenInfo.pageHeight = pageHeight;
|
|
450
449
|
}
|
|
451
450
|
return getPageScreenInfo;
|
|
452
451
|
}
|
|
453
452
|
|
|
454
453
|
getRootEleWindowWidthInfo() {
|
|
455
454
|
const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
|
|
456
455
|
const getWindowWidth = window.innerWidth;
|
|
457
456
|
const getScreenWidth = window.screen.width;
|
|
458
457
|
return {
|
|
459
458
|
getRootEleWidth,
|
|
460
459
|
getWindowWidth,
|
|
461
460
|
getScreenWidth,
|
|
462
461
|
};
|
|
463
462
|
}
|
|
464
463
|
|
|
465
464
|
dealRootEleWidthFn(reportParam = {}, timeout = 0) {
|
|
466
465
|
const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
|
|
467
466
|
console.log(
|
|
468
467
|
'当前获取根元素的宽度',
|
|
469
468
|
getRootEleWidth,
|
|
470
469
|
'getWindowWidth',
|
|
471
470
|
getWindowWidth,
|
|
472
471
|
'getScreenWidth',
|
|
473
472
|
getScreenWidth,
|
|
474
473
|
);
|
|
475
474
|
const getLastWidth =
|
|
476
475
|
getRootEleWidth > 0
|
|
477
476
|
? Math.round(getRootEleWidth)
|
|
478
477
|
: Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
|
|
479
478
|
console.warn(
|
|
480
479
|
`根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
|
|
481
480
|
);
|
|
482
481
|
timeout > 0 &&
|
|
483
482
|
draBusinessCustomReport({
|
|
484
483
|
eventName: 'UIInteract',
|
|
485
484
|
errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
|
|
486
485
|
errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
|
|
487
486
|
extraData: JSON.stringify({
|
|
488
487
|
isJdApp,
|
|
489
488
|
getRootEleWidth,
|
|
490
489
|
getWindowWidth,
|
|
491
490
|
getScreenWidth,
|
|
492
491
|
...reportParam,
|
|
493
492
|
}),
|
|
494
493
|
});
|
|
495
494
|
return getLastWidth;
|
|
496
495
|
}
|
|
497
496
|
|
|
498
497
|
getPadWindowRootEleWidthPromise() {
|
|
499
498
|
if (this.rootEleInitWidth > 0) {
|
|
500
499
|
return Promise.resolve(this.rootEleInitWidth);
|
|
501
500
|
} else {
|
|
502
501
|
!this.rootEleWidthRegisterPromise &&
|
|
503
502
|
(this.rootEleWidthRegisterPromise = new Promise((resolve) => {
|
|
504
503
|
const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
|
|
505
504
|
if (getRootEleInitWidth > 0) {
|
|
506
505
|
console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
|
|
507
506
|
this.rootEleInitWidth = Math.round(getRootEleInitWidth);
|
|
508
507
|
resolve(this.rootEleInitWidth);
|
|
509
508
|
} else {
|
|
510
509
|
const timerPromise = () => {
|
|
511
510
|
return new Promise((resolve2) => {
|
|
512
511
|
window.setTimeout(() => {
|
|
513
512
|
const { getRootEleWidth, getWindowWidth, getScreenWidth } =
|
|
514
513
|
this.getRootEleWindowWidthInfo();
|
|
515
514
|
if (getRootEleWidth > 0 || getWindowWidth > 0) {
|
|
516
515
|
console.warn(
|
|
517
516
|
`根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
|
|
518
517
|
);
|
|
519
518
|
draBusinessCustomReport({
|
|
520
519
|
eventName: 'UIInteract',
|
|
521
520
|
errorName: 'rootEle_width_200_timeout_info',
|
|
522
521
|
errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
|
|
523
522
|
extraData: JSON.stringify({
|
|
524
523
|
isJdApp,
|
|
525
524
|
getRootEleWidth,
|
|
526
525
|
getWindowWidth,
|
|
527
526
|
getScreenWidth,
|
|
528
527
|
}),
|
|
529
528
|
});
|
|
530
529
|
const getRes =
|
|
531
530
|
getRootEleWidth > 0 && getWindowWidth > 0
|
|
532
531
|
? Math.min(getRootEleWidth, getWindowWidth)
|
|
533
532
|
: Math.max(getRootEleWidth, getWindowWidth);
|
|
534
533
|
resolve2({
|
|
535
534
|
pageWidth: Math.round(getRes),
|
|
536
535
|
});
|
|
537
536
|
}
|
|
538
537
|
}, 200);
|
|
539
538
|
});
|
|
540
539
|
};
|
|
541
540
|
Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
|
|
542
541
|
const { pageWidth } = res;
|
|
543
542
|
console.log('获取结果Promise.race getJdScreenSizeInfo', res);
|
|
544
543
|
pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
|
|
545
544
|
});
|
|
546
545
|
}
|
|
547
546
|
}));
|
|
548
547
|
return this.rootEleWidthRegisterPromise;
|
|
549
548
|
}
|
|
550
549
|
}
|
|
551
550
|
|
|
552
551
|
async getSystemInfo(params) {
|
|
553
552
|
const getParams = Object.assign({}, params || {});
|
|
554
553
|
if (this.rootEleInitWidth > 0) {
|
|
555
554
|
getParams['rootEleInitWidth'] = this.rootEleInitWidth;
|
|
556
555
|
console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
|
|
557
556
|
} else {
|
|
558
557
|
if (this._getJdPadMinWidthForListen()) {
|
|
559
558
|
getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
|
|
560
559
|
getParams['replaceSystemWidth'] = true;
|
|
561
560
|
}
|
|
562
561
|
}
|
|
563
562
|
isJdApp && this.createLanguagePromise();
|
|
564
563
|
let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
|
|
565
564
|
if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
|
|
566
565
|
let _isfoldScreen = false;
|
|
567
566
|
const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
|
|
568
567
|
console.info(
|
|
569
568
|
'获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
|
|
570
569
|
getStorageData,
|
|
571
570
|
'通过缓存值第一次判断是否是折叠屏',
|
|
572
571
|
getStorageData === 'true',
|
|
573
572
|
);
|
|
574
573
|
if (!getStorageData) {
|
|
575
574
|
_isfoldScreen = this.isAndroidFoldScreen();
|
|
576
575
|
setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
|
|
577
576
|
} else {
|
|
578
577
|
_isfoldScreen = getStorageData === 'true';
|
|
579
578
|
}
|
|
580
579
|
if (_isfoldScreen) {
|
|
581
580
|
const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
|
|
582
581
|
if (getJdAndroidPageInfo) {
|
|
583
582
|
info = getSystemInfos(getJdAndroidPageInfo);
|
|
584
583
|
console.warn(
|
|
585
584
|
'当前为松果安卓折叠屏app,获取折叠屏信息',
|
|
586
585
|
getJdAndroidPageInfo,
|
|
587
586
|
'获取转换后的系统信息',
|
|
588
587
|
info,
|
|
589
588
|
);
|
|
590
589
|
draBusinessCustomReport({
|
|
591
590
|
eventName: 'UIInteract',
|
|
592
591
|
errorName: 'android_jdapp_foldScreen_info',
|
|
593
592
|
errorMessage: '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
|
|
594
593
|
extraData: JSON.stringify({
|
|
595
594
|
title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
|
|
596
595
|
androidPageInfo: getJdAndroidPageInfo,
|
|
597
596
|
jdAppVersionStr,
|
|
598
597
|
taroSysInfo: info,
|
|
599
598
|
}),
|
|
600
599
|
});
|
|
601
600
|
}
|
|
602
601
|
}
|
|
603
602
|
}
|
|
604
603
|
if (isJdApp) {
|
|
605
604
|
info?.isJdTabletDevice && this.listenJdTabletScreenChange();
|
|
606
605
|
}
|
|
607
606
|
this.info.sysInfo = {
|
|
608
607
|
actualNavBarHeight: 0,
|
|
609
608
|
...this.info.sysInfo,
|
|
610
609
|
...info,
|
|
611
610
|
safeContentHeight: info?.screenHeight,
|
|
612
611
|
headerHeight: 0,
|
|
613
612
|
tabBarHeight: 0,
|
|
614
613
|
languageType: languageNowType,
|
|
615
614
|
};
|
|
616
615
|
if (isJdApp || isH5AndJingGouMini) {
|
|
617
616
|
this.getLbsAddressCachePromise();
|
|
618
617
|
}
|
|
619
618
|
if (isJdApp) {
|
|
620
619
|
this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
|
|
621
620
|
this.info.sysInfo['hostAppVersion'] = jdAppVersion;
|
|
622
621
|
this.getJdAppBaseInfo();
|
|
623
622
|
this.getAddressCachePromise();
|
|
624
623
|
this.getElderModePromise();
|
|
625
624
|
this.getJDAppearanceStatePromise();
|
|
626
625
|
this.createJdAndroidRquestEventForTouchStart();
|
|
627
626
|
}
|
|
628
627
|
this.getWifiVideoAutoPlayAsync();
|
|
629
628
|
this.getMPaasConfigAsync();
|
|
630
629
|
this.getNetWorkType();
|
|
631
630
|
}
|
|
632
631
|
|
|
633
632
|
getElderModePromise() {
|
|
634
633
|
if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
|
|
635
634
|
return Promise.resolve(this.info.sysInfo.jdAppModeType);
|
|
636
635
|
} else {
|
|
637
636
|
if (isJdAndAndroidDevice) {
|
|
638
637
|
this.info.sysInfo.jdAppModeType = '0';
|
|
639
638
|
return Promise.resolve(this.info.sysInfo.jdAppModeType);
|
|
640
639
|
} else {
|
|
641
640
|
return Promise.race([
|
|
642
641
|
this.taskTimeoutPromise(() => {
|
|
643
642
|
this.info.sysInfo.jdAppModeType = '0';
|
|
644
643
|
return this.info.sysInfo.jdAppModeType;
|
|
645
644
|
}),
|
|
646
645
|
new Promise((resolve) => {
|
|
647
646
|
const getCallBackName = `getJdCurrentModeType${Date.now()}`;
|
|
648
647
|
if (!window[getCallBackName]) {
|
|
649
648
|
window[getCallBackName] = (res) => {
|
|
650
649
|
try {
|
|
651
650
|
const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
|
|
652
651
|
const { status, data, msg } = getResJson;
|
|
653
652
|
console.log(`获取松果app展示模式成功,返回结果${data}`);
|
|
654
653
|
if (status === '0') {
|
|
655
654
|
this.info.sysInfo.jdAppModeType = data;
|
|
656
655
|
resolve(data);
|
|
657
656
|
} else {
|
|
658
657
|
resolve('0');
|
|
659
658
|
}
|
|
660
659
|
} catch (e) {
|
|
661
660
|
resolve('0');
|
|
662
661
|
}
|
|
663
662
|
window[getCallBackName] = null;
|
|
664
663
|
};
|
|
665
664
|
}
|
|
666
665
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
667
666
|
method: 'callSyncRouterModuleWithParams',
|
|
668
667
|
params: JSON.stringify({
|
|
669
668
|
routerURL: 'router://JDBModeModule/getCurrentMode',
|
|
670
669
|
routerParam: {},
|
|
671
670
|
callBackName: `window.${getCallBackName}`,
|
|
672
671
|
callBackId: `${getCallBackName}Ios`,
|
|
673
672
|
}),
|
|
674
673
|
});
|
|
675
674
|
}),
|
|
676
675
|
]);
|
|
677
676
|
}
|
|
678
677
|
}
|
|
679
678
|
}
|
|
680
679
|
getAPPUseStraightCorner() {
|
|
681
680
|
const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
|
|
682
681
|
const params = {
|
|
683
682
|
routerURL,
|
|
684
683
|
routerParam: {},
|
|
685
684
|
jdRouter: '1',
|
|
686
685
|
};
|
|
687
686
|
if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
|
|
688
687
|
return Promise.resolve(this.info.sysInfo.jdStraightCorner);
|
|
689
688
|
} else {
|
|
690
689
|
return this.jmfeReayPromise()
|
|
691
690
|
.then(() => {
|
|
692
691
|
if (isJdAndHarmonyDevice || !isJdApp) {
|
|
693
692
|
console.log('not APP or is Harmony');
|
|
694
693
|
return Promise.resolve(false);
|
|
695
694
|
}
|
|
696
695
|
console.log('jmfe setShareInfo', params);
|
|
697
696
|
return Promise.race([
|
|
698
697
|
window.jmfe.callRouter(params),
|
|
699
698
|
this.taskTimeoutPromise(() => {
|
|
700
699
|
return false;
|
|
701
700
|
}),
|
|
702
701
|
]).then(({ status, data }) => {
|
|
703
702
|
console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
|
|
704
703
|
console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
|
|
705
704
|
this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
|
|
706
705
|
return Promise.resolve(status === '0' && Number(data) === 1);
|
|
707
706
|
});
|
|
708
707
|
})
|
|
709
708
|
.catch((e) => {
|
|
710
709
|
console.log('jmfe error', e);
|
|
711
710
|
return Promise.resolve(false);
|
|
712
711
|
});
|
|
713
712
|
}
|
|
714
713
|
}
|
|
715
714
|
|
|
716
715
|
getJDAppearanceStatePromise() {
|
|
717
716
|
if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
|
|
718
717
|
return Promise.resolve(this.info.sysInfo.jdAppearanceState);
|
|
719
718
|
} else {
|
|
720
719
|
return Promise.race([
|
|
721
720
|
this.taskTimeoutPromise(() => {
|
|
722
721
|
this.info.sysInfo.jdAppearanceState = '0';
|
|
723
722
|
return this.info.sysInfo.jdAppearanceState;
|
|
724
723
|
}),
|
|
725
724
|
new Promise((resolve) => {
|
|
726
725
|
const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
|
|
727
726
|
if (!window[getCallBackName]) {
|
|
728
727
|
window[getCallBackName] = (res) => {
|
|
729
728
|
try {
|
|
730
729
|
console.log('getJDAppearanceStatePromise', res);
|
|
731
730
|
const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
|
|
732
731
|
const { status, data, msg } = getResJson;
|
|
733
732
|
console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
|
|
734
733
|
if (status === '0') {
|
|
735
734
|
this.info.sysInfo.jdAppearanceState = data;
|
|
736
735
|
resolve(data);
|
|
737
736
|
} else {
|
|
738
737
|
resolve('0');
|
|
739
738
|
}
|
|
740
739
|
} catch (e) {
|
|
741
740
|
resolve('0');
|
|
742
741
|
}
|
|
743
742
|
window[getCallBackName] = null;
|
|
744
743
|
};
|
|
745
744
|
}
|
|
746
745
|
if (isAndroidDevice) {
|
|
747
746
|
const jsonString = JSON.stringify({
|
|
748
747
|
callBackName: `window.${getCallBackName}`,
|
|
749
748
|
});
|
|
750
749
|
console.log('window.JDAppearance', window?.JDAppearance);
|
|
751
750
|
window?.JDAppearance &&
|
|
752
751
|
window?.JDAppearance?.getUiState &&
|
|
753
752
|
window.JDAppearance.getUiState(jsonString);
|
|
754
753
|
} else {
|
|
755
754
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
756
755
|
method: 'callSyncRouterModuleWithParams',
|
|
757
756
|
params: JSON.stringify({
|
|
758
757
|
routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
|
|
759
758
|
routerParam: {},
|
|
760
759
|
callBackName: `window.${getCallBackName}`,
|
|
761
760
|
callBackId: `${getCallBackName}Ios`,
|
|
762
761
|
}),
|
|
763
762
|
});
|
|
764
763
|
}
|
|
765
764
|
}),
|
|
766
765
|
]);
|
|
767
766
|
}
|
|
768
767
|
}
|
|
769
768
|
|
|
770
769
|
createJdAndroidRquestEventForTouchStart() {
|
|
771
770
|
if (isJdAndAndroidDevice && window?.JdAndroid) {
|
|
772
771
|
const rootEleNode = document.querySelector('body');
|
|
773
772
|
if (rootEleNode) {
|
|
774
773
|
rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
|
|
775
774
|
}
|
|
776
775
|
}
|
|
777
776
|
}
|
|
778
777
|
jdAndroidAddEventListenerTouchStart(e) {
|
|
779
778
|
const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
|
|
780
779
|
if (!isH5SwiperCustomEle && window?.JdAndroid) {
|
|
781
780
|
const hasCustomEle = e
|
|
782
781
|
? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
|
|
783
782
|
: false;
|
|
784
783
|
if (!hasCustomEle) {
|
|
785
784
|
window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
|
|
786
785
|
console.log(
|
|
787
786
|
'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
|
|
788
787
|
);
|
|
789
788
|
}
|
|
790
789
|
}
|
|
791
790
|
}
|
|
792
791
|
removeJdAndroidRquestEventForTouchStart() {
|
|
793
792
|
if (isJdAndAndroidDevice && window.JdAndroid) {
|
|
794
793
|
const rootEleNode = document.querySelector('body');
|
|
795
794
|
if (rootEleNode) {
|
|
796
795
|
rootEleNode.removeEventListener(
|
|
797
796
|
'touchstart',
|
|
798
797
|
this.jdAndroidAddEventListenerTouchStart,
|
|
799
798
|
false,
|
|
800
799
|
);
|
|
801
800
|
}
|
|
802
801
|
}
|
|
803
802
|
}
|
|
804
803
|
|
|
805
804
|
getNetWorkType() {
|
|
806
805
|
if (isJdApp) {
|
|
807
806
|
this.jmfeReayPromise().then(() => {
|
|
808
807
|
window.jmfe
|
|
809
808
|
.getNetworkStatus()
|
|
810
809
|
.then(({ status, data }) => {
|
|
811
810
|
console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
|
|
812
811
|
if (status === '0') {
|
|
813
812
|
this.info.sysInfo['netWorkType'] = data;
|
|
814
813
|
} else {
|
|
815
814
|
this._taroGetNetworkType();
|
|
816
815
|
}
|
|
817
816
|
})
|
|
818
817
|
.catch((err) => {
|
|
819
818
|
console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
|
|
820
819
|
this._taroGetNetworkType();
|
|
821
820
|
});
|
|
822
821
|
});
|
|
823
822
|
} else {
|
|
824
823
|
this._taroGetNetworkType();
|
|
825
824
|
}
|
|
826
825
|
}
|
|
827
826
|
_taroGetNetworkType() {
|
|
828
827
|
Taro.getNetworkType().then((getRes) => {
|
|
829
828
|
if (getRes && getRes.networkType) {
|
|
830
829
|
this.info.sysInfo['netWorkType'] = getRes.networkType;
|
|
831
830
|
console.log(
|
|
832
831
|
'在app内通过taro对象获取网络状态完成,当前网络状态',
|
|
833
832
|
this.info.sysInfo['netWorkType'],
|
|
834
833
|
);
|
|
835
834
|
}
|
|
836
835
|
});
|
|
837
836
|
}
|
|
838
837
|
|
|
839
838
|
getJdAppBaseInfo(){
|
|
840
839
|
const appKeyCacheToCookieMinuteTime = window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
|
|
841
840
|
appUuidCacheToCookieMinuteTime = window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
|
|
842
841
|
getAppKey = cookie.get(cacheAppKey),getAppUuidKey = cookie.get(cacheAppUuidKey);
|
|
843
842
|
console.log("在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam",cacheAppKey,getAppKey,cacheAppUuidKey,getAppUuidKey)
|
|
844
843
|
if(appKeyCacheToCookieMinuteTime && appUuidCacheToCookieMinuteTime && getAppKey && getAppUuidKey){
|
|
845
844
|
const [ uuid, eufv] = getAppUuidKey.split("@")
|
|
846
845
|
const baseApiKeyParam = {
|
|
847
846
|
uuid,
|
|
848
847
|
}
|
|
849
848
|
getAppKey !== "-1000" && (baseApiKeyParam['x_app_key'] = getAppKey)
|
|
850
849
|
if(eufv === "1" && /-/.test(uuid)){
|
|
851
850
|
const [eu, fv] = uuid.split('-');
|
|
852
851
|
baseApiKeyParam['eu'] = eu;
|
|
853
852
|
baseApiKeyParam['fv'] = fv;
|
|
854
853
|
}
|
|
855
854
|
this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam
|
|
856
855
|
this.jmfeReayPromise().then(() => {
|
|
857
856
|
console.log("在app内初始化通过cookie获取api请求参数集合baseApiKeyParam",baseApiKeyParam)
|
|
858
857
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam)
|
|
859
858
|
})
|
|
860
859
|
}else {
|
|
861
860
|
const checkGetJdAppKeyState = window?.shopGlobalSwitch?.getJdAppKeyVersion && jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0
|
|
862
861
|
this.jmfeReayPromise().then(() => {
|
|
863
862
|
Promise.all([
|
|
864
863
|
checkGetJdAppKeyState && window.jmfe?.callNative ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0') : Promise.resolve({
|
|
865
864
|
status: "-1000",
|
|
866
865
|
msg: "当前版本不支持获取松果app中的getAppKey",
|
|
867
866
|
data: "-1000"
|
|
868
867
|
}),
|
|
869
868
|
window.jmfe.getDeviceInfo()
|
|
870
869
|
]).then(resList => {
|
|
871
870
|
const [getAppKeyRes, deviceInfoRes] = resList;
|
|
872
871
|
console.log("在app内初始化通过jmfe获取getAppKey结果", getAppKeyRes, "通过jmfe获取getDeviceInfo获取结果", deviceInfoRes)
|
|
873
872
|
const baseApiKeyParam = {}
|
|
874
873
|
if (["0","-1000"].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
|
|
875
874
|
const getJmfeAppKey = getAppKeyRes?.data
|
|
876
875
|
if(getJmfeAppKey && getJmfeAppKey !== ""){
|
|
877
876
|
getJmfeAppKey !== "-1000" && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
|
|
878
877
|
const getJdAppKeyCacheToCookieMinuteTime = (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
|
|
879
878
|
if(getJdAppKeyCacheToCookieMinuteTime){
|
|
880
879
|
const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
|
|
881
880
|
cookie.set(cacheAppKey, getJmfeAppKey, {
|
|
882
881
|
path: '/',
|
|
883
882
|
expires,
|
|
884
883
|
})
|
|
885
884
|
}
|
|
886
885
|
}
|
|
887
886
|
}
|
|
888
887
|
if (deviceInfoRes?.status === "0" && deviceInfoRes?.data) {
|
|
889
888
|
const { uuid, eufv = "0", networkType } = deviceInfoRes?.data
|
|
890
889
|
if( uuid && uuid !== "" ){
|
|
891
890
|
networkType && (this.info.sysInfo['netWorkType'] = networkType);
|
|
892
891
|
baseApiKeyParam['uuid'] = uuid;
|
|
893
892
|
if (eufv === "1" && /-/.test(uuid)) {
|
|
894
893
|
const [eu, fv] = uuid.split('-');
|
|
895
894
|
baseApiKeyParam['eu'] = eu;
|
|
896
895
|
baseApiKeyParam['fv'] = fv;
|
|
897
896
|
}
|
|
898
897
|
const getAppUuidCacheToCookieMinuteTime = (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
|
|
899
898
|
if(getAppUuidCacheToCookieMinuteTime){
|
|
900
899
|
const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
|
|
901
900
|
cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
|
|
902
901
|
path: '/',
|
|
903
902
|
expires,
|
|
904
903
|
})
|
|
905
904
|
}
|
|
906
905
|
}
|
|
907
906
|
}
|
|
908
907
|
console.log("在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam", baseApiKeyParam)
|
|
909
908
|
if(Object.keys(baseApiKeyParam).length > 0){
|
|
910
909
|
this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam
|
|
911
910
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
|
|
912
911
|
}
|
|
913
912
|
})
|
|
914
913
|
})
|
|
915
914
|
}
|
|
916
915
|
}
|
|
917
916
|
|
|
918
917
|
getCacheAddressRouter() {
|
|
919
918
|
if (isJdApp) {
|
|
920
919
|
if (!isJdAndHarmonyDevice) {
|
|
921
920
|
return Promise.race([
|
|
922
921
|
new Promise((resolve) => {
|
|
923
922
|
const getCallBackName = `getJdCacheAddress${Date.now()}`;
|
|
924
923
|
if (!window[getCallBackName]) {
|
|
925
924
|
window[getCallBackName] = (res) => {
|
|
926
925
|
console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
|
|
927
926
|
try {
|
|
928
927
|
const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
|
|
929
928
|
resolve(getResJson);
|
|
930
929
|
} catch (e) {
|
|
931
930
|
resolve({
|
|
932
931
|
status: '-1002',
|
|
933
932
|
msg: '地址信息解析json异常',
|
|
934
933
|
res,
|
|
935
934
|
});
|
|
936
935
|
}
|
|
937
936
|
window[getCallBackName] = null;
|
|
938
937
|
};
|
|
939
938
|
}
|
|
940
939
|
const getRouterParam = {
|
|
941
940
|
sceneId: 'basicShoppingProcess',
|
|
942
941
|
};
|
|
943
942
|
if (isAndroidDevice) {
|
|
944
943
|
return callRouterAndroid({
|
|
945
944
|
routerURL: 'router://JDAddressModule/getCacheAddress',
|
|
946
945
|
routerParam: getRouterParam,
|
|
947
946
|
callBackName: getCallBackName,
|
|
948
947
|
isSync: true,
|
|
949
948
|
});
|
|
950
949
|
} else {
|
|
951
950
|
return callRouterIOS({
|
|
952
951
|
routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
|
|
953
952
|
routerParam: getRouterParam,
|
|
954
953
|
callBackName: getCallBackName,
|
|
955
954
|
});
|
|
956
955
|
}
|
|
957
956
|
}),
|
|
958
957
|
this.taskTimeoutPromise(() => {
|
|
959
958
|
return {
|
|
960
959
|
status: '-1000',
|
|
961
960
|
msg: '原生router协议获取地址信息超时',
|
|
962
961
|
};
|
|
963
962
|
}, 3000),
|
|
964
963
|
]);
|
|
965
964
|
} else {
|
|
966
965
|
return Promise.race([
|
|
967
966
|
new Promise((resolve) => {
|
|
968
967
|
this.jmfeReayPromise()
|
|
969
968
|
.then(() => {
|
|
970
969
|
const plugin = 'JDHybridRouterPlugin';
|
|
971
970
|
const action = 'callSyncRouterModuleWithParams';
|
|
972
971
|
const params = {
|
|
973
972
|
routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
|
|
974
973
|
routerParam: '',
|
|
975
974
|
};
|
|
976
975
|
const sync = '1';
|
|
977
976
|
try {
|
|
978
977
|
window.jmfe.callNative(plugin, action, params, sync).then((res) => {
|
|
979
978
|
resolve(res);
|
|
980
979
|
});
|
|
981
980
|
} catch (error) {
|
|
982
981
|
resolve({
|
|
983
982
|
status: '-1001',
|
|
984
983
|
msg: '判断jmfe不存在,获取经纬度信息异常',
|
|
985
984
|
});
|
|
986
985
|
}
|
|
987
986
|
})
|
|
988
987
|
.catch(() => {
|
|
989
988
|
resolve({
|
|
990
989
|
status: '-1002',
|
|
991
990
|
msg: '鸿蒙系统调用jmfe异常,获取失败',
|
|
992
991
|
});
|
|
993
992
|
});
|
|
994
993
|
}),
|
|
995
994
|
this.taskTimeoutPromise(() => {
|
|
996
995
|
return {
|
|
997
996
|
status: '-1000',
|
|
998
997
|
msg: '原生router协议获取地址信息超时',
|
|
999
998
|
};
|
|
1000
999
|
}, 3000),
|
|
1001
1000
|
]);
|
|
1002
1001
|
}
|
|
1003
1002
|
} else if (isH5AndJingGouMini) {
|
|
1004
1003
|
return Promise.resolve({
|
|
1005
1004
|
status: '-1002',
|
|
1006
1005
|
msg: '普通h5暂无业务需要,未实现,获取失败',
|
|
1007
1006
|
});
|
|
1008
1007
|
} else {
|
|
1009
1008
|
return Promise.resolve({
|
|
1010
1009
|
status: '-1002',
|
|
1011
1010
|
msg: '普通h5暂无业务需要,未实现,获取失败',
|
|
1012
1011
|
});
|
|
1013
1012
|
}
|
|
1014
1013
|
}
|
|
1015
1014
|
|
|
1016
1015
|
getAddressCachePromise() {
|
|
1017
1016
|
return new Promise((resolve) => {
|
|
1018
1017
|
if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
|
|
1019
1018
|
resolve({
|
|
1020
1019
|
lat: this.info.sysInfo.lat,
|
|
1021
1020
|
lng: this.info.sysInfo.lng,
|
|
1022
1021
|
area: this?.info?.sysInfo?.area,
|
|
1023
1022
|
});
|
|
1024
1023
|
} else {
|
|
1025
1024
|
this.getCacheAddressRouter()
|
|
1026
1025
|
.then((res) => {
|
|
1027
1026
|
const { status, data } = res;
|
|
1028
1027
|
console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
|
|
1029
1028
|
if (status === '0' && data) {
|
|
1030
1029
|
const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
|
|
1031
1030
|
data || {};
|
|
1032
1031
|
let area = '';
|
|
1033
1032
|
this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
|
|
1034
1033
|
this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
|
|
1035
1034
|
const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
|
|
1036
1035
|
if (getProvinceIdNum && getProvinceIdNum > 0) {
|
|
1037
1036
|
area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
|
|
1038
1037
|
this.info.pageInfo['address'] = area;
|
|
1039
1038
|
this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
|
|
1040
1039
|
this.info.sysInfo['area'] = area;
|
|
1041
1040
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
|
|
1042
1041
|
area: this.info.pageInfo.address,
|
|
1043
1042
|
});
|
|
1044
1043
|
}
|
|
1045
1044
|
resolve({
|
|
1046
1045
|
lat: this.info.sysInfo['lat'],
|
|
1047
1046
|
lng: this.info.sysInfo['lng'],
|
|
1048
1047
|
area: area,
|
|
1049
1048
|
});
|
|
1050
1049
|
} else {
|
|
1051
1050
|
if (typeof res === 'object') {
|
|
1052
1051
|
draBusinessCustomReport({
|
|
1053
1052
|
eventName: 'business',
|
|
1054
1053
|
errorName: 'jdapp_getCacheAddress_info_err',
|
|
1055
1054
|
errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
|
|
1056
1055
|
extraData: JSON.stringify({
|
|
1057
1056
|
isJdApp,
|
|
1058
1057
|
jdAppVersion: jdAppVersionStr,
|
|
1059
1058
|
...res,
|
|
1060
1059
|
}),
|
|
1061
1060
|
});
|
|
1062
1061
|
}
|
|
1063
1062
|
resolve({ lat: '', lng: '', area: '' });
|
|
1064
1063
|
}
|
|
1065
1064
|
})
|
|
1066
1065
|
.catch((e) => {
|
|
1067
1066
|
console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
|
|
1068
1067
|
draBusinessCustomReport({
|
|
1069
1068
|
eventName: 'business',
|
|
1070
1069
|
errorName: 'jdapp_getCacheAddress_info_catch_err',
|
|
1071
1070
|
errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
|
|
1072
1071
|
extraData: JSON.stringify({
|
|
1073
1072
|
isJdApp,
|
|
1074
1073
|
jdAppVersion: jdAppVersionStr,
|
|
1075
1074
|
}),
|
|
1076
1075
|
});
|
|
1077
1076
|
resolve({ lat: '', lng: '', area: '' });
|
|
1078
1077
|
});
|
|
1079
1078
|
}
|
|
1080
1079
|
});
|
|
1081
1080
|
}
|
|
1082
1081
|
|
|
1083
1082
|
getLbsCacheAddressRouter() {
|
|
1084
1083
|
if (isJdApp) {
|
|
1085
1084
|
if (!isJdAndHarmonyDevice) {
|
|
1086
1085
|
return Promise.race([
|
|
1087
1086
|
new Promise((resolve) => {
|
|
1088
1087
|
const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
|
|
1089
1088
|
if (!window[getCallBackName]) {
|
|
1090
1089
|
window[getCallBackName] = (res) => {
|
|
1091
1090
|
console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
|
|
1092
1091
|
try {
|
|
1093
1092
|
const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
|
|
1094
1093
|
resolve(getResJson);
|
|
1095
1094
|
} catch (e) {
|
|
1096
1095
|
resolve({
|
|
1097
1096
|
status: '-1002',
|
|
1098
1097
|
msg: '地址信息解析json异常',
|
|
1099
1098
|
res,
|
|
1100
1099
|
});
|
|
1101
1100
|
}
|
|
1102
1101
|
window[getCallBackName] = null;
|
|
1103
1102
|
};
|
|
1104
1103
|
}
|
|
1105
1104
|
const getRouterParam = {
|
|
1106
1105
|
appid: '219f70bbbf7e4ede7968bedaa1beafb4',
|
|
1107
1106
|
sceneId: 'basicShoppingProcess',
|
|
1108
1107
|
};
|
|
1109
1108
|
if (isAndroidDevice) {
|
|
1110
1109
|
return callRouterAndroid({
|
|
1111
1110
|
routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
|
|
1112
1111
|
routerParam: getRouterParam,
|
|
1113
1112
|
callBackName: getCallBackName,
|
|
1114
1113
|
isSync: true,
|
|
1115
1114
|
hasJdRouter: false,
|
|
1116
1115
|
});
|
|
1117
1116
|
} else {
|
|
1118
1117
|
return callRouterIOS({
|
|
1119
1118
|
routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
|
|
1120
1119
|
routerParam: getRouterParam,
|
|
1121
1120
|
callBackName: getCallBackName,
|
|
1122
1121
|
isSync: true,
|
|
1123
1122
|
});
|
|
1124
1123
|
}
|
|
1125
1124
|
}),
|
|
1126
1125
|
this.taskTimeoutPromise(() => {
|
|
1127
1126
|
return {
|
|
1128
1127
|
status: '-1000',
|
|
1129
1128
|
msg: '原生router协议获取lbs地址信息3s超时',
|
|
1130
1129
|
};
|
|
1131
1130
|
}, 3000),
|
|
1132
1131
|
]);
|
|
1133
1132
|
} else {
|
|
1134
1133
|
return Promise.resolve({
|
|
1135
1134
|
status: '-1001',
|
|
1136
1135
|
msg: '鸿蒙系统调用未实现,获取失败',
|
|
1137
1136
|
});
|
|
1138
1137
|
}
|
|
1139
1138
|
} else if (isH5AndJingGouMini) {
|
|
1140
1139
|
return this.getLocationForGpsPromise();
|
|
1141
1140
|
} else {
|
|
1142
1141
|
return Promise.resolve({
|
|
1143
1142
|
status: '-1002',
|
|
1144
1143
|
msg: '普通h5暂无业务需要,未实现,获取失败',
|
|
1145
1144
|
});
|
|
1146
1145
|
}
|
|
1147
1146
|
}
|
|
1148
1147
|
getLocationForGpsPromise() {
|
|
1149
1148
|
return new Promise((resolve) => {
|
|
1150
1149
|
let hasGetLocationForGps = true;
|
|
1151
1150
|
if (urlCookie && urlCookie['loc']) {
|
|
1152
1151
|
const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
|
|
1153
1152
|
urlCookie['loc'].split('_');
|
|
1154
1153
|
const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
|
|
1155
1154
|
if (getProvinceIdNum && getProvinceIdNum > 0) {
|
|
1156
1155
|
hasGetLocationForGps = false;
|
|
1157
1156
|
resolve({
|
|
1158
1157
|
status: '0',
|
|
1159
1158
|
data: {
|
|
1160
1159
|
provinceid,
|
|
1161
1160
|
cityid,
|
|
1162
1161
|
districtid,
|
|
1163
1162
|
townid,
|
|
1164
1163
|
origin: 'wxapp',
|
|
1165
1164
|
},
|
|
1166
1165
|
});
|
|
1167
1166
|
}
|
|
1168
1167
|
}
|
|
1169
1168
|
if (hasGetLocationForGps && window?.navigator?.geolocation) {
|
|
1170
1169
|
window.navigator.geolocation.getCurrentPosition(
|
|
1171
1170
|
(position) => {
|
|
1172
1171
|
console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
|
|
1173
1172
|
if (position?.coords) {
|
|
1174
1173
|
resolve({
|
|
1175
1174
|
status: '0',
|
|
1176
1175
|
data: {
|
|
1177
1176
|
srclat: position.coords?.latitude,
|
|
1178
1177
|
srclng: position.coords.longitude,
|
|
1179
1178
|
origin: 'h5',
|
|
1180
1179
|
},
|
|
1181
1180
|
});
|
|
1182
1181
|
} else {
|
|
1183
1182
|
resolve({
|
|
1184
1183
|
status: '-1001',
|
|
1185
1184
|
msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
|
|
1186
1185
|
position,
|
|
1187
1186
|
});
|
|
1188
1187
|
}
|
|
1189
1188
|
},
|
|
1190
1189
|
(error) => {
|
|
1191
1190
|
resolve({
|
|
1192
1191
|
status: '-1001',
|
|
1193
1192
|
msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
|
|
1194
1193
|
error,
|
|
1195
1194
|
});
|
|
1196
1195
|
},
|
|
1197
1196
|
{
|
|
1198
1197
|
enableHighAccuracy: false,
|
|
1199
1198
|
timeout: 3 * 1000,
|
|
1200
1199
|
maximumAge: 10 * 60 * 1000,
|
|
1201
1200
|
},
|
|
1202
1201
|
);
|
|
1203
1202
|
} else {
|
|
1204
1203
|
resolve({
|
|
1205
1204
|
status: '-1001',
|
|
1206
1205
|
msg: '您的浏览器不支持地理定位',
|
|
1207
1206
|
});
|
|
1208
1207
|
}
|
|
1209
1208
|
});
|
|
1210
1209
|
}
|
|
1211
1210
|
|
|
1212
1211
|
createLbsCacheAddress(realTimeArea) {
|
|
1213
1212
|
const getLbsAddressCacheMinuteTime = Number(
|
|
1214
1213
|
window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
|
|
1215
1214
|
);
|
|
1216
1215
|
console.log(
|
|
1217
1216
|
'获取lbs缓存到cookie的时间,分钟',
|
|
1218
1217
|
getLbsAddressCacheMinuteTime,
|
|
1219
1218
|
'lbsAddressCacheToCookieMinuteTime',
|
|
1220
1219
|
window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
|
|
1221
1220
|
);
|
|
1222
1221
|
if (getLbsAddressCacheMinuteTime > 0) {
|
|
1223
1222
|
const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
|
|
1224
1223
|
realTimeArea &&
|
|
1225
1224
|
cookie.set(cacheH5LbsAddressKey, realTimeArea, {
|
|
1226
1225
|
path: '/',
|
|
1227
1226
|
expires,
|
|
1228
1227
|
});
|
|
1229
1228
|
}
|
|
1230
1229
|
}
|
|
1231
1230
|
|
|
1232
1231
|
getLbsAddressCachePromise() {
|
|
1233
1232
|
if (!this.lbsAddressCachePromise) {
|
|
1234
1233
|
this.lbsAddressCachePromise = new Promise((resolve) => {
|
|
1235
1234
|
const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
|
|
1236
1235
|
? cookie.get(cacheH5LbsAddressKey)
|
|
1237
1236
|
: '';
|
|
1238
1237
|
const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
|
|
1239
1238
|
if (getUserLbsAddress && getUserLbsAddress !== '') {
|
|
1240
1239
|
resolve({
|
|
1241
1240
|
ok: true,
|
|
1242
1241
|
realTimeArea: getUserLbsAddress,
|
|
1243
1242
|
});
|
|
1244
1243
|
} else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
|
|
1245
1244
|
console.info(
|
|
1246
1245
|
`通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
|
|
1247
1246
|
getCookieForLbsAddress,
|
|
1248
1247
|
);
|
|
1249
1248
|
this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
|
|
1250
1249
|
this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
|
|
1251
1250
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
|
|
1252
1251
|
realTimeArea: getCookieForLbsAddress,
|
|
1253
1252
|
});
|
|
1254
1253
|
resolve({
|
|
1255
1254
|
ok: true,
|
|
1256
1255
|
realTimeArea: getCookieForLbsAddress,
|
|
1257
1256
|
});
|
|
1258
1257
|
} else {
|
|
1259
1258
|
this.getLbsCacheAddressRouter()
|
|
1260
1259
|
.then((res) => {
|
|
1261
1260
|
const { status, data } = res;
|
|
1262
1261
|
console.log(
|
|
1263
1262
|
'原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
|
|
1264
1263
|
status,
|
|
1265
1264
|
data,
|
|
1266
1265
|
res,
|
|
1267
1266
|
);
|
|
1268
1267
|
if (status === '0' && data) {
|
|
1269
1268
|
const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
|
|
1270
1269
|
data || {};
|
|
1271
1270
|
let realTimeArea = '';
|
|
1272
1271
|
this.info.sysInfo['srclat'] = `${srclat || ''}`;
|
|
1273
1272
|
this.info.sysInfo['srclng'] = `${srclng || ''}`;
|
|
1274
1273
|
const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
|
|
1275
1274
|
if (getProvinceIdNum && getProvinceIdNum > 0) {
|
|
1276
1275
|
realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
|
|
1277
1276
|
this.info.pageInfo['userLbsAddress'] = realTimeArea;
|
|
1278
1277
|
this.info.sysInfo['realTimeArea'] = realTimeArea;
|
|
1279
1278
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
|
|
1280
1279
|
realTimeArea: this.info.pageInfo.userLbsAddress,
|
|
1281
1280
|
});
|
|
1282
1281
|
this.createLbsCacheAddress(realTimeArea);
|
|
1283
1282
|
} else {
|
|
1284
1283
|
!origin && (this.lbsAddressCachePromise = null);
|
|
1285
1284
|
}
|
|
1286
1285
|
const getValidRealTimeArea = realTimeArea !== '';
|
|
1287
1286
|
resolve({
|
|
1288
1287
|
lat: this.info.sysInfo['srclat'],
|
|
1289
1288
|
lng: this.info.sysInfo['srclng'],
|
|
1290
1289
|
realTimeArea: realTimeArea,
|
|
1291
1290
|
ok: getValidRealTimeArea,
|
|
1292
1291
|
msg: getValidRealTimeArea
|
|
1293
1292
|
? '成功'
|
|
1294
1293
|
: origin
|
|
1295
1294
|
? origin
|
|
1296
1295
|
: '根据router底层获取lbs地址信息异常,详情见data',
|
|
1297
1296
|
data: getValidRealTimeArea ? null : res,
|
|
1298
1297
|
});
|
|
1299
1298
|
if (!getValidRealTimeArea && !origin) {
|
|
1300
1299
|
draBusinessCustomReport({
|
|
1301
1300
|
eventName: 'business',
|
|
1302
1301
|
errorName: 'h5_getLbsCacheAddress_info_err',
|
|
1303
1302
|
errorMessage: '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
|
|
1304
1303
|
extraData: JSON.stringify({
|
|
1305
1304
|
isJdApp,
|
|
1306
1305
|
jdAppVersion: jdAppVersionStr,
|
|
1307
1306
|
}),
|
|
1308
1307
|
});
|
|
1309
1308
|
}
|
|
1310
1309
|
} else {
|
|
1311
1310
|
typeof res === 'object' &&
|
|
1312
1311
|
draBusinessCustomReport({
|
|
1313
1312
|
eventName: 'business',
|
|
1314
1313
|
errorName: 'h5_getLbsCacheAddress_info_err',
|
|
1315
1314
|
errorMessage: 'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
|
|
1316
1315
|
extraData: JSON.stringify({
|
|
1317
1316
|
isJdApp,
|
|
1318
1317
|
jdAppVersion: jdAppVersionStr,
|
|
1319
1318
|
...res,
|
|
1320
1319
|
}),
|
|
1321
1320
|
});
|
|
1322
1321
|
this.lbsAddressCachePromise = null;
|
|
1323
1322
|
resolve({ realTimeArea: '', ok: false });
|
|
1324
1323
|
}
|
|
1325
1324
|
})
|
|
1326
1325
|
.catch((e) => {
|
|
1327
1326
|
console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
|
|
1328
1327
|
this.lbsAddressCachePromise = null;
|
|
1329
1328
|
draBusinessCustomReport({
|
|
1330
1329
|
eventName: 'business',
|
|
1331
1330
|
errorName: 'h5_getLbsCacheAddress_info_err',
|
|
1332
1331
|
errorMessage: 'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
|
|
1333
1332
|
extraData: JSON.stringify({
|
|
1334
1333
|
isJdApp,
|
|
1335
1334
|
jdAppVersion: jdAppVersionStr,
|
|
1336
1335
|
}),
|
|
1337
1336
|
});
|
|
1338
1337
|
resolve({ realTimeArea: '', ok: false });
|
|
1339
1338
|
});
|
|
1340
1339
|
}
|
|
1341
1340
|
});
|
|
1342
1341
|
}
|
|
1343
1342
|
return this.lbsAddressCachePromise;
|
|
1344
1343
|
}
|
|
1345
1344
|
|
|
1346
1345
|
async updateMPaasConfigAsync(isBeforePageReady: boolean) {
|
|
1347
1346
|
console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
|
|
1348
1347
|
if (!isJdApp) {
|
|
1349
1348
|
return;
|
|
1350
1349
|
}
|
|
1351
1350
|
const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
|
|
1352
1351
|
this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
|
|
1353
1352
|
const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
|
|
1354
1353
|
'hybridHttpSwitch',
|
|
1355
1354
|
isBeforePageReady,
|
|
1356
1355
|
);
|
|
1357
1356
|
const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
|
|
1358
1357
|
'jshopIsVipShop',
|
|
1359
1358
|
isBeforePageReady,
|
|
1360
1359
|
);
|
|
1361
1360
|
this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
|
|
1362
1361
|
this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
|
|
1363
1362
|
const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
|
|
1364
1363
|
'isFollowAppVideoPlayStatus',
|
|
1365
1364
|
isBeforePageReady,
|
|
1366
1365
|
);
|
|
1367
1366
|
console.log(
|
|
1368
1367
|
'isBeforePageReady:',
|
|
1369
1368
|
isBeforePageReady,
|
|
1370
1369
|
'isFollowAppVideoPlayStatus:',
|
|
1371
1370
|
isFollowAppVideoPlayStatus,
|
|
1372
1371
|
);
|
|
1373
1372
|
if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
|
|
1374
1373
|
this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
|
|
1375
1374
|
}
|
|
1376
1375
|
}
|
|
1377
1376
|
|
|
1378
1377
|
async getWifiVideoAutoPlayAsync() {
|
|
1379
1378
|
this.info.sysInfo['wifiVideoAutoPlay'] = false;
|
|
1380
1379
|
if (!isJdApp) {
|
|
1381
1380
|
return;
|
|
1382
1381
|
}
|
|
1383
1382
|
const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
|
|
1384
1383
|
return 0;
|
|
1385
1384
|
});
|
|
1386
1385
|
if (Number(videoPlayStatus) === 1) {
|
|
1387
1386
|
this.info.sysInfo['wifiVideoAutoPlay'] = true;
|
|
1388
1387
|
}
|
|
1389
1388
|
}
|
|
1390
1389
|
|
|
1391
1390
|
async getMPaasConfigAsync() {
|
|
1392
1391
|
this.info.sysInfo.dynamicConfig = {};
|
|
1393
1392
|
this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
|
|
1394
1393
|
this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
|
|
1395
1394
|
this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
|
|
1396
1395
|
this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
|
|
1397
1396
|
return this.updateMPaasConfigAsync(true);
|
|
1398
1397
|
}
|
|
1399
1398
|
|
|
1400
1399
|
getDynamicConfig(key: string) {
|
|
1401
1400
|
return this.info.sysInfo?.dynamicConfig?.[key];
|
|
1402
1401
|
}
|
|
1403
1402
|
async updateMPaasConfig() {
|
|
1404
1403
|
console.log('updateMPaasConfig');
|
|
1405
1404
|
if (
|
|
1406
1405
|
isIosDevice &&
|
|
1407
1406
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
|
|
1408
1407
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
|
|
1409
1408
|
) {
|
|
1410
1409
|
try {
|
|
1411
1410
|
await this.updateMPaasConfigAsync(false);
|
|
1412
1411
|
} catch (e) {
|
|
1413
1412
|
console.log('updateMPaasConfigAsync:', e);
|
|
1414
1413
|
}
|
|
1415
1414
|
}
|
|
1416
1415
|
}
|
|
1417
1416
|
|
|
1418
1417
|
toLogin(options) {
|
|
1419
1418
|
return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
|
|
1420
1419
|
? this.toWxAppLogin(options)
|
|
1421
1420
|
: this.toWebLogin(options);
|
|
1422
1421
|
}
|
|
1423
1422
|
|
|
1424
1423
|
doLogin(options) {
|
|
1425
1424
|
return this.toLogin(options);
|
|
1426
1425
|
}
|
|
1427
1426
|
|
|
1428
1427
|
doLoginForJdPin(options = {}) {
|
|
1429
1428
|
return this.doLogin({
|
|
1430
1429
|
loginColor: {
|
|
1431
1430
|
biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
1432
1431
|
dpin: 0,
|
|
1433
1432
|
},
|
|
1434
1433
|
...options,
|
|
1435
1434
|
});
|
|
1436
1435
|
}
|
|
1437
1436
|
|
|
1438
1437
|
toWebLogin(options) {
|
|
1439
1438
|
let params: {
|
|
1440
1439
|
returnurl: string;
|
|
1441
1440
|
} = {
|
|
1442
1441
|
returnurl: '',
|
|
1443
1442
|
};
|
|
1444
1443
|
const checkToPcLogin = options ? options?.isPc : isPc;
|
|
1445
1444
|
const loginUrl = checkToPcLogin
|
|
1446
1445
|
? `//passport.jd.com/new/login.aspx`
|
|
1447
1446
|
: `${domain.mobileLogin}/user/login.action`;
|
|
1448
1447
|
const defaultParams = {
|
|
1449
1448
|
appid: '100',
|
|
1450
1449
|
returnurl: window.location.href,
|
|
1451
1450
|
};
|
|
1452
1451
|
if (isString(options)) {
|
|
1453
1452
|
params = Object.assign({}, defaultParams, {
|
|
1454
1453
|
returnurl: options,
|
|
1455
1454
|
});
|
|
1456
1455
|
} else if (isObject(options)) {
|
|
1457
1456
|
const { loginColor, ...otherOptions } = options;
|
|
1458
1457
|
params = Object.assign({}, defaultParams, otherOptions);
|
|
1459
1458
|
} else {
|
|
1460
1459
|
params = defaultParams;
|
|
1461
1460
|
}
|
|
1462
1461
|
params.returnurl = encodeURIComponent(params.returnurl);
|
|
1463
1462
|
let getFullUrl = loginUrl + '?' + serialize(params);
|
|
1464
1463
|
if (checkToPcLogin) {
|
|
1465
1464
|
getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
|
|
1466
1465
|
}
|
|
1467
1466
|
return Promise.resolve({
|
|
1468
1467
|
h5ToUrl: true,
|
|
1469
1468
|
url: getFullUrl,
|
|
1470
1469
|
}).then(() => {
|
|
1471
1470
|
window.location.href = getFullUrl;
|
|
1472
1471
|
});
|
|
1473
1472
|
}
|
|
1474
1473
|
|
|
1475
1474
|
toWxAppLogin(options = {}) {
|
|
1476
1475
|
console.log('微信京购小程序中h5登录跳转', options);
|
|
1477
1476
|
return Promise.resolve(true).then(() => {
|
|
1478
1477
|
const { loginColor } = Object.assign(
|
|
1479
1478
|
{},
|
|
1480
1479
|
{
|
|
1481
1480
|
loginColor: {
|
|
1482
1481
|
biz: WXAPP_BIZ_KEY,
|
|
1483
1482
|
dpin: 1,
|
|
1484
1483
|
},
|
|
1485
1484
|
},
|
|
1486
1485
|
options,
|
|
1487
1486
|
);
|
|
1488
1487
|
window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${loginColor.biz
|
|
1489
1488
|
}&url=${encodeURIComponent(window.location.href)}`;
|
|
1490
1489
|
});
|
|
1491
1490
|
}
|
|
1492
1491
|
|
|
1493
1492
|
getLoginCookie() {
|
|
1494
1493
|
return Promise.resolve({
|
|
1495
1494
|
pin: cookie.get('pin') || '',
|
|
1496
1495
|
});
|
|
1497
1496
|
}
|
|
1498
1497
|
|
|
1499
1498
|
clearLoginCookie() {
|
|
1500
1499
|
cookie.remove('pin');
|
|
1501
1500
|
}
|
|
1502
1501
|
|
|
1503
1502
|
checkStatusAndLogin(options = {}) {
|
|
1504
1503
|
if (!this.checkStatusAndLoginPromise) {
|
|
1505
1504
|
this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
|
|
1506
1505
|
try {
|
|
1507
1506
|
const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
|
|
1508
1507
|
if (getLoginState) {
|
|
1509
1508
|
resolve(true);
|
|
1510
1509
|
} else {
|
|
1511
1510
|
this.toLogin(options);
|
|
1512
1511
|
reject(false);
|
|
1513
1512
|
}
|
|
1514
1513
|
} catch (e) {
|
|
1515
1514
|
this.toLogin(options);
|
|
1516
1515
|
reject(false);
|
|
1517
1516
|
}
|
|
1518
1517
|
});
|
|
1519
1518
|
return this.checkStatusAndLoginPromise;
|
|
1520
1519
|
} else {
|
|
1521
1520
|
return this.checkStatusAndLoginPromise
|
|
1522
1521
|
.then(() => {
|
|
1523
1522
|
return Promise.resolve(true);
|
|
1524
1523
|
})
|
|
1525
1524
|
.catch(() => {
|
|
1526
1525
|
this.toLogin(options);
|
|
1527
1526
|
return Promise.reject(true);
|
|
1528
1527
|
});
|
|
1529
1528
|
}
|
|
1530
1529
|
}
|
|
1531
1530
|
|
|
1532
1531
|
checkJdStatusAndLogin(
|
|
1533
1532
|
options = {
|
|
1534
1533
|
loginColor: {
|
|
1535
1534
|
biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
1536
1535
|
dpin: 0,
|
|
1537
1536
|
},
|
|
1538
1537
|
},
|
|
1539
1538
|
) {
|
|
1540
1539
|
return this.checkStatusAndLogin(options);
|
|
1541
1540
|
}
|
|
1542
1541
|
|
|
1543
1542
|
doCheckLoginStateAndForApiCheck(options) {
|
|
1544
1543
|
if (this.info.loginState) {
|
|
1545
1544
|
return Promise.resolve(true);
|
|
1546
1545
|
} else {
|
|
1547
1546
|
return new Promise((resolve, reject) => {
|
|
1548
1547
|
if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
|
|
1549
1548
|
const getWqAuthToken = cookie.get('wq_auth_token');
|
|
1550
1549
|
const getWqSkey = cookie.get('wq_skey');
|
|
1551
1550
|
const getWqUin = cookie.get('wq_uin');
|
|
1552
1551
|
const isLoginState =
|
|
1553
1552
|
options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
|
|
1554
1553
|
if (isLoginState) {
|
|
1555
1554
|
this.info.loginState = true;
|
|
1556
1555
|
resolve(true);
|
|
1557
1556
|
} else {
|
|
1558
1557
|
reject(false);
|
|
1559
1558
|
}
|
|
1560
1559
|
} else {
|
|
1561
1560
|
Taro.request({
|
|
1562
1561
|
url: api.isLogin,
|
|
1563
1562
|
jsonp: true,
|
|
1564
1563
|
timeout: 3000,
|
|
1565
1564
|
success: (res) => {
|
|
1566
1565
|
const { statusCode, data } = res;
|
|
1567
1566
|
if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
|
|
1568
1567
|
this.info.loginState = true;
|
|
1569
1568
|
resolve(true);
|
|
1570
1569
|
} else {
|
|
1571
1570
|
reject(false);
|
|
1572
1571
|
}
|
|
1573
1572
|
},
|
|
1574
1573
|
fail: (err) => {
|
|
1575
1574
|
console.log('登录检查异常', err);
|
|
1576
1575
|
reject(false);
|
|
1577
1576
|
},
|
|
1578
1577
|
});
|
|
1579
1578
|
}
|
|
1580
1579
|
});
|
|
1581
1580
|
}
|
|
1582
1581
|
}
|
|
1583
1582
|
|
|
1584
1583
|
checkLoginStatus(options) {
|
|
1585
1584
|
return new Promise(async (resolve, reject) => {
|
|
1586
1585
|
try {
|
|
1587
1586
|
const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
|
|
1588
1587
|
if (getLoginState) {
|
|
1589
1588
|
const { pin } = await this.getLoginCookie();
|
|
1590
1589
|
this.info.userInfo = {
|
|
1591
1590
|
pin,
|
|
1592
1591
|
encodePin: encodeURIComponent(pin),
|
|
1593
1592
|
ptkey: '',
|
|
1594
1593
|
};
|
|
1595
1594
|
resolve(true);
|
|
1596
1595
|
} else {
|
|
1597
1596
|
reject(false);
|
|
1598
1597
|
}
|
|
1599
1598
|
} catch (e) {
|
|
1600
1599
|
reject(false);
|
|
1601
1600
|
}
|
|
1602
1601
|
});
|
|
1603
1602
|
}
|
|
1604
1603
|
|
|
1605
1604
|
updatePageAndLogInfo(updateQuery = {}) {
|
|
1606
1605
|
const createUpdateQueryInfo: {
|
|
1607
1606
|
query: {
|
|
1608
1607
|
shopId?: string | number;
|
|
1609
1608
|
venderId?: string | number;
|
|
1610
1609
|
};
|
|
1611
1610
|
updateShopInfoState: boolean;
|
|
1612
1611
|
} = Object.assign(
|
|
1613
1612
|
{},
|
|
1614
1613
|
{
|
|
1615
1614
|
query: {},
|
|
1616
1615
|
updateShopInfoState: false,
|
|
1617
1616
|
},
|
|
1618
1617
|
updateQuery,
|
|
1619
1618
|
);
|
|
1620
1619
|
console.log(
|
|
1621
1620
|
'获取当前下发的店铺查询参数',
|
|
1622
1621
|
updateQuery,
|
|
1623
1622
|
'获取之前保存的shopInfo店铺查询参数',
|
|
1624
1623
|
this.info?.shopInfo,
|
|
1625
1624
|
);
|
|
1626
1625
|
const { query, updateShopInfoState } = createUpdateQueryInfo;
|
|
1627
1626
|
const { shopId, venderId, un_area } = query;
|
|
1628
1627
|
if (updateShopInfoState) {
|
|
1629
1628
|
this.info.queryInfo = {
|
|
1630
1629
|
...this.info.queryInfo,
|
|
1631
1630
|
...query,
|
|
1632
1631
|
};
|
|
1633
1632
|
if (shopId && venderId) {
|
|
1634
1633
|
this.info.shopInfo = {
|
|
1635
1634
|
shopId: `${shopId}`,
|
|
1636
1635
|
venderId: `${venderId}`,
|
|
1637
1636
|
};
|
|
1638
1637
|
}
|
|
1639
1638
|
} else {
|
|
1640
1639
|
this.info.queryInfo = {
|
|
1641
1640
|
...query,
|
|
1642
1641
|
};
|
|
1643
1642
|
if (
|
|
1644
1643
|
this.info.shopInfo?.shopId &&
|
|
1645
1644
|
this.info.shopInfo?.venderId &&
|
|
1646
1645
|
(this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
|
|
1647
1646
|
) {
|
|
1648
1647
|
this.info.queryInfo.shopId = this.info.shopInfo.shopId;
|
|
1649
1648
|
this.info.queryInfo.venderId = this.info.shopInfo.venderId;
|
|
1650
1649
|
console.log(
|
|
1651
1650
|
'当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
|
|
1652
1651
|
this.info.queryInfo,
|
|
1653
1652
|
);
|
|
1654
1653
|
}
|
|
1655
1654
|
}
|
|
1656
1655
|
this.info.queryInfo['shopId'] &&
|
|
1657
1656
|
(this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
|
|
1658
1657
|
this.info.queryInfo['venderId'] &&
|
|
1659
1658
|
(this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
|
|
1660
1659
|
console.log(
|
|
1661
1660
|
'h5==获取店铺下发查询参数\n',
|
|
1662
1661
|
query,
|
|
1663
1662
|
'\n获取店铺最后查询参数\n',
|
|
1664
1663
|
this.info.queryInfo,
|
|
1665
1664
|
'\n是否为更新店铺状态\n',
|
|
1666
1665
|
updateShopInfoState,
|
|
1667
1666
|
);
|
|
1668
1667
|
const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
|
|
1669
1668
|
if (changeArea) {
|
|
1670
1669
|
const getBottomAreaStr = changeArea.replace(/-/g, '_');
|
|
1671
1670
|
this.info.pageInfo.address = getBottomAreaStr;
|
|
1672
1671
|
this.info.pageInfo.un_area = getBottomAreaStr;
|
|
1673
1672
|
this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
|
|
1674
1673
|
}
|
|
1675
1674
|
}
|
|
1676
1675
|
|
|
1677
1676
|
dealLoadSdkList() {
|
|
1678
1677
|
const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
|
|
1679
1678
|
const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
|
|
1680
1679
|
const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
|
|
1681
1680
|
let mergeLoadJsList = globalLoadJsList;
|
|
1682
1681
|
try {
|
|
1683
1682
|
mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
|
|
1684
1683
|
const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
|
|
1685
1684
|
getFindIndex !== -1
|
|
1686
1685
|
? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
|
|
1687
1686
|
: accArr.push(current);
|
|
1688
1687
|
return accArr;
|
|
1689
1688
|
}, []);
|
|
1690
1689
|
} catch (e) {
|
|
1691
1690
|
console.log('LoadJsList合并错误', e);
|
|
1692
1691
|
}
|
|
1693
1692
|
console.log(
|
|
1694
1693
|
'globalLoadJsList',
|
|
1695
1694
|
globalLoadJsList,
|
|
1696
1695
|
'businessLoadJsList',
|
|
1697
1696
|
businessLoadJsList,
|
|
1698
1697
|
'两个加载jsList集合合并完成',
|
|
1699
1698
|
mergeLoadJsList,
|
|
1700
1699
|
);
|
|
1701
1700
|
this.loadJsSdkList = mergeLoadJsList;
|
|
1702
1701
|
return this.loadJsSdkList;
|
|
1703
1702
|
}
|
|
1704
1703
|
|
|
1705
1704
|
renderNextTickLoadSdk(delayTime = 1000) {
|
|
1706
1705
|
Taro.nextTick(() => {
|
|
1707
1706
|
console.log(
|
|
1708
1707
|
'页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
|
|
1709
1708
|
);
|
|
1710
1709
|
setTimeout(() => {
|
|
1711
1710
|
this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
|
|
1712
1711
|
}, delayTime);
|
|
1713
1712
|
});
|
|
1714
1713
|
}
|
|
1715
1714
|
|
|
1716
1715
|
loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
|
|
1717
1716
|
const getLoadJsList =
|
|
1718
1717
|
Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
|
|
1719
1718
|
const getLoadFilterList = getLoadJsList.filter((item) => {
|
|
1720
1719
|
if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
|
|
1721
1720
|
item.initLoadType = undefined;
|
|
1722
1721
|
}
|
|
1723
1722
|
const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
|
|
1724
1723
|
let getLoastLoadEventState = true;
|
|
1725
1724
|
if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
|
|
1726
1725
|
getLoastLoadEventState = isJdApp;
|
|
1727
1726
|
}
|
|
1728
1727
|
else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
|
|
1729
1728
|
getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
|
|
1730
1729
|
}
|
|
1731
1730
|
const getInitTriggerType =
|
|
1732
1731
|
isJdApp && item?.initJdAppTriggerType
|
|
1733
1732
|
? item?.initTriggerType
|
|
1734
1733
|
: item?.initTriggerType || LoadJsInitTriggerType.NOW;
|
|
1735
1734
|
const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
|
|
1736
1735
|
return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
|
|
1737
1736
|
});
|
|
1738
1737
|
console.log(
|
|
1739
1738
|
'获取当前触发方式',
|
|
1740
1739
|
triggerType,
|
|
1741
1740
|
'获取当前最后加载的js集合',
|
|
1742
1741
|
getLoadFilterList,
|
|
1743
1742
|
'过滤前的加载集合',
|
|
1744
1743
|
getLoadJsList,
|
|
1745
1744
|
);
|
|
1746
1745
|
getLoadFilterList.length > 0 &&
|
|
1747
1746
|
getLoadFilterList.forEach((item) => {
|
|
1748
1747
|
const isLoadState = /sgm/.test(item?.fileName)
|
|
1749
1748
|
? window?.shopGlobalSwitch?.openSgm === 'true'
|
|
1750
1749
|
: true;
|
|
1751
1750
|
isLoadState &&
|
|
1752
1751
|
this.loadItemSdkPromise(item)
|
|
1753
1752
|
.then((res) => {
|
|
1754
1753
|
console.info('当前js地址' + item?.src, '加载状态', res);
|
|
1755
1754
|
const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
|
|
1756
1755
|
if (isFileNameNewDraSdkJs && window?.dra?.run) {
|
|
1757
1756
|
window.dra.run('init', { aid: res?.aid });
|
|
1758
1757
|
window.dra.run('start');
|
|
1759
1758
|
}
|
|
1760
1759
|
})
|
|
1761
1760
|
.catch((err) => {
|
|
1762
1761
|
console.info('当前js地址加载异常', item?.src);
|
|
1763
1762
|
window?.fetchErrorData &&
|
|
1764
1763
|
window.fetchErrorData({
|
|
1765
1764
|
title: '公共js加载异常',
|
|
1766
1765
|
type: 'jsLoad',
|
|
1767
1766
|
data: err,
|
|
1768
1767
|
});
|
|
1769
1768
|
});
|
|
1770
1769
|
});
|
|
1771
1770
|
}
|
|
1772
1771
|
loadScriptEle(jsInfo, resolve, reject) {
|
|
1773
1772
|
const getFileName = jsInfo?.fileName;
|
|
1774
1773
|
if (getFileName) {
|
|
1775
1774
|
const getEleId = `J_loadJs_${getFileName}`;
|
|
1776
1775
|
const getEle = document.getElementById(getEleId);
|
|
1777
1776
|
if (!getEle) {
|
|
1778
1777
|
const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
|
|
1779
1778
|
const _sgmEle = document.createElement('script');
|
|
1780
1779
|
_sgmEle.id = getEleId;
|
|
1781
1780
|
_sgmEle.onload = function () {
|
|
1782
1781
|
resolve({
|
|
1783
1782
|
...jsInfo,
|
|
1784
1783
|
jsTip: 'js加载成功',
|
|
1785
1784
|
});
|
|
1786
1785
|
};
|
|
1787
1786
|
_sgmEle.onerror = function () {
|
|
1788
1787
|
reject({
|
|
1789
1788
|
...jsInfo,
|
|
1790
1789
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
1791
1790
|
jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
|
|
1792
1791
|
});
|
|
1793
1792
|
};
|
|
1794
1793
|
const dataAttrList = ['timeout', 'fileName', 'env'];
|
|
1795
1794
|
const getJsInfoKeyList = Object.keys(jsInfo);
|
|
1796
1795
|
getJsInfoKeyList.forEach((key) => {
|
|
1797
1796
|
if (key === 'async') {
|
|
1798
1797
|
_sgmEle.async = jsInfo[key];
|
|
1799
1798
|
} else if (key === 'crossOrigin') {
|
|
1800
1799
|
_sgmEle.crossOrigin = jsInfo[key];
|
|
1801
1800
|
} else if (key === 'src') {
|
|
1802
1801
|
_sgmEle.src = `${jsInfo[key]}`;
|
|
1803
1802
|
} else if (dataAttrList.includes(key) || /init/.test(key)) {
|
|
1804
1803
|
_sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
|
|
1805
1804
|
} else {
|
|
1806
1805
|
_sgmEle.setAttribute(key, jsInfo[key]);
|
|
1807
1806
|
}
|
|
1808
1807
|
});
|
|
1809
1808
|
document.head.appendChild(_sgmEle);
|
|
1810
1809
|
} else {
|
|
1811
1810
|
console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
|
|
1812
1811
|
resolve({
|
|
1813
1812
|
...jsInfo,
|
|
1814
1813
|
jsTip: 'js本身已存在页面中',
|
|
1815
1814
|
});
|
|
1816
1815
|
}
|
|
1817
1816
|
} else {
|
|
1818
1817
|
console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
|
|
1819
1818
|
}
|
|
1820
1819
|
}
|
|
1821
1820
|
|
|
1822
1821
|
loadItemSdkPromise(jsInfo = {}) {
|
|
1823
1822
|
if (jsInfo?.src) {
|
|
1824
1823
|
const getInitLoadType =
|
|
1825
1824
|
isJdApp && jsInfo?.initJdAppLoadType
|
|
1826
1825
|
? jsInfo?.initJdAppLoadType
|
|
1827
1826
|
: jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
|
|
1828
1827
|
if (getInitLoadType !== LoadJsInitLoadType.NONE) {
|
|
1829
1828
|
const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
|
|
1830
1829
|
if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
|
|
1831
1830
|
if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
|
|
1832
1831
|
this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
|
|
1833
1832
|
const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
|
|
1834
1833
|
try {
|
|
1835
1834
|
const jsXhrRequest = new XMLHttpRequest();
|
|
1836
1835
|
jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
|
|
1837
1836
|
const jsUrl = `${jsInfo?.src}`;
|
|
1838
1837
|
jsXhrRequest.open('GET', jsUrl, true);
|
|
1839
1838
|
jsXhrRequest.onreadystatechange = () => {
|
|
1840
1839
|
if (jsXhrRequest.readyState === 4) {
|
|
1841
1840
|
const getReqStatus = jsXhrRequest.status;
|
|
1842
1841
|
const statusText = jsXhrRequest.statusText;
|
|
1843
1842
|
if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
|
|
1844
1843
|
const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
|
|
1845
1844
|
if (getInsetHeadState) {
|
|
1846
1845
|
this.loadScriptEle(jsInfo, resolve, reject);
|
|
1847
1846
|
} else {
|
|
1848
1847
|
resolve({
|
|
1849
1848
|
...jsInfo,
|
|
1850
1849
|
jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
|
|
1851
1850
|
});
|
|
1852
1851
|
}
|
|
1853
1852
|
getReqStatus !== 200 &&
|
|
1854
1853
|
draBusinessCustomReport({
|
|
1855
1854
|
eventName: 'business',
|
|
1856
1855
|
errorName: 'js_load_special_code',
|
|
1857
1856
|
errorMessage: '当前js加载成功,状态非200,特殊上报观察',
|
|
1858
1857
|
extraData: JSON.stringify({
|
|
1859
1858
|
msg: '当前js加载成功,状态非200,特殊上报观察',
|
|
1860
1859
|
jsReqState: getReqStatus,
|
|
1861
1860
|
env: getSgmCustomCode('js_load_special_code'),
|
|
1862
1861
|
data: jsInfo,
|
|
1863
1862
|
}),
|
|
1864
1863
|
});
|
|
1865
1864
|
} else {
|
|
1866
1865
|
const getRes = {
|
|
1867
1866
|
...jsInfo,
|
|
1868
1867
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
1869
1868
|
jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
|
|
1870
1869
|
jsReqState: getReqStatus,
|
|
1871
1870
|
};
|
|
1872
1871
|
console.log('当前js请求状态异常,具体信息见', getRes);
|
|
1873
1872
|
reject(getRes);
|
|
1874
1873
|
}
|
|
1875
1874
|
}
|
|
1876
1875
|
};
|
|
1877
1876
|
jsXhrRequest.onerror = () => {
|
|
1878
1877
|
const getRes = {
|
|
1879
1878
|
...jsInfo,
|
|
1880
1879
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
1881
1880
|
jsReqError: '请求错误',
|
|
1882
1881
|
};
|
|
1883
1882
|
console.log('当前js请求错误', getRes);
|
|
1884
1883
|
jsXhrRequest.abort();
|
|
1885
1884
|
reject(getRes);
|
|
1886
1885
|
};
|
|
1887
1886
|
jsXhrRequest.ontimeout = () => {
|
|
1888
1887
|
const getRes = {
|
|
1889
1888
|
...jsInfo,
|
|
1890
1889
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
1891
1890
|
jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
|
|
1892
1891
|
jsReqState: jsXhrRequest.status,
|
|
1893
1892
|
};
|
|
1894
1893
|
console.log('当前js请求超时异常', getRes);
|
|
1895
1894
|
jsXhrRequest.abort();
|
|
1896
1895
|
reject(getRes);
|
|
1897
1896
|
};
|
|
1898
1897
|
jsXhrRequest.send();
|
|
1899
1898
|
} catch (e) {
|
|
1900
1899
|
console.log('执行js请求异常', e);
|
|
1901
1900
|
reject({
|
|
1902
1901
|
...jsInfo,
|
|
1903
1902
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
1904
1903
|
jsReqError: '未知异常',
|
|
1905
1904
|
error: e,
|
|
1906
1905
|
});
|
|
1907
1906
|
}
|
|
1908
1907
|
});
|
|
1909
1908
|
} else {
|
|
1910
1909
|
this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
|
|
1911
1910
|
return this.loadScriptEle(jsInfo, resolve, reject);
|
|
1912
1911
|
});
|
|
1913
1912
|
}
|
|
1914
1913
|
}
|
|
1915
1914
|
return this.loadJsSdkListCachePromise[getFileKeyName];
|
|
1916
1915
|
} else {
|
|
1917
1916
|
return Promise.resolve({
|
|
1918
1917
|
...jsInfo,
|
|
1919
1918
|
jsTip: 'js加载方式设置为不加载,当前不做处理',
|
|
1920
1919
|
});
|
|
1921
1920
|
}
|
|
1922
1921
|
} else {
|
|
1923
1922
|
return Promise.reject(jsInfo);
|
|
1924
1923
|
}
|
|
1925
1924
|
}
|
|
1926
1925
|
|
|
1927
1926
|
createLanguagePromise() {
|
|
1928
1927
|
const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
|
|
1929
1928
|
if (!this.languageCacheProimse) {
|
|
1930
1929
|
this.languageCacheProimse = new Promise((resolve, reject) => {
|
|
1931
1930
|
const { fileName, prefixUrl } = getLanguageConfig;
|
|
1932
1931
|
console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
|
|
1933
1932
|
const dealLanguageFile = () => {
|
|
1934
1933
|
this.getLanguageFilePromise(getLanguageConfig, languageNowType)
|
|
1935
1934
|
.then((res) => {
|
|
1936
1935
|
if (res && res?.data) {
|
|
1937
1936
|
this.languageJsonData = res.data;
|
|
1938
1937
|
|
|
1939
1938
|
setTimeout(() => {
|
|
1940
1939
|
const getOtherLanguageList = languageTypeList.filter(
|
|
1941
1940
|
(item) => item !== languageNowType,
|
|
1942
1941
|
);
|
|
1943
1942
|
getOtherLanguageList.length > 0 &&
|
|
1944
1943
|
getOtherLanguageList.map((languageTypeKey) => {
|
|
1945
1944
|
this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
|
|
1946
1945
|
});
|
|
1947
1946
|
}, 3000);
|
|
1948
1947
|
resolve(res);
|
|
1949
1948
|
} else {
|
|
1950
1949
|
reject(res);
|
|
1951
1950
|
}
|
|
1952
1951
|
})
|
|
1953
1952
|
.catch((err) => {
|
|
1954
1953
|
reject(err);
|
|
1955
1954
|
});
|
|
1956
1955
|
};
|
|
1957
1956
|
if (fileName && prefixUrl) {
|
|
1958
1957
|
const getLangStorageKey = `jshopx_lang_${languageNowType}`;
|
|
1959
1958
|
const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
|
|
1960
1959
|
if (getLocalLangRes) {
|
|
1961
1960
|
try {
|
|
1962
1961
|
const getLocalLangJsonData =
|
|
1963
1962
|
typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
|
|
1964
1963
|
if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
|
|
1965
1964
|
if (getLocalLangJsonData?.fileName === fileName) {
|
|
1966
1965
|
const geThisLangData = getLocalLangJsonData.data;
|
|
1967
1966
|
this.languageJsonData = geThisLangData;
|
|
1968
1967
|
return resolve({
|
|
1969
1968
|
...getLanguageConfig,
|
|
1970
1969
|
languageNowType,
|
|
1971
1970
|
data: geThisLangData,
|
|
1972
1971
|
});
|
|
1973
1972
|
} else {
|
|
1974
1973
|
dealLanguageFile();
|
|
1975
1974
|
}
|
|
1976
1975
|
} else {
|
|
1977
1976
|
dealLanguageFile();
|
|
1978
1977
|
}
|
|
1979
1978
|
} catch (e) {
|
|
1980
1979
|
return reject({
|
|
1981
1980
|
languageNowType,
|
|
1982
1981
|
msg: '转换错误',
|
|
1983
1982
|
...getLanguageConfig,
|
|
1984
1983
|
});
|
|
1985
1984
|
}
|
|
1986
1985
|
} else {
|
|
1987
1986
|
dealLanguageFile();
|
|
1988
1987
|
}
|
|
1989
1988
|
} else {
|
|
1990
1989
|
return reject({
|
|
1991
1990
|
languageNowType,
|
|
1992
1991
|
msg: '文件对象下发异常',
|
|
1993
1992
|
...getLanguageConfig,
|
|
1994
1993
|
});
|
|
1995
1994
|
}
|
|
1996
1995
|
});
|
|
1997
1996
|
}
|
|
1998
1997
|
return this.languageCacheProimse;
|
|
1999
1998
|
}
|
|
2000
1999
|
|
|
2001
2000
|
getLanguageFilePromise(info, languageTypeKey) {
|
|
2002
2001
|
const { fileName, prefixUrl, timeout } = info || {};
|
|
2003
2002
|
const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
|
|
2004
2003
|
return new Promise((resolve, reject) => {
|
|
2005
2004
|
const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
|
|
2006
2005
|
try {
|
|
2007
2006
|
const langXhrRequest = new XMLHttpRequest();
|
|
2008
2007
|
langXhrRequest.timeout = timeout || 2000;
|
|
2009
2008
|
langXhrRequest.open('GET', getUrl, true);
|
|
2010
2009
|
langXhrRequest.responseType = 'json';
|
|
2011
2010
|
langXhrRequest.onreadystatechange = () => {
|
|
2012
2011
|
if (langXhrRequest.readyState === 4) {
|
|
2013
2012
|
const getReqStatus = langXhrRequest.status;
|
|
2014
2013
|
const statusText = langXhrRequest.statusText;
|
|
2015
2014
|
if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
|
|
2016
2015
|
const getData = langXhrRequest?.response || false;
|
|
2017
2016
|
if (getData) {
|
|
2018
2017
|
setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
|
|
2019
2018
|
fileName,
|
|
2020
2019
|
data: getData,
|
|
2021
2020
|
});
|
|
2022
2021
|
resolve({
|
|
2023
2022
|
...info,
|
|
2024
2023
|
languageTypeKey,
|
|
2025
2024
|
data: getData,
|
|
2026
2025
|
});
|
|
2027
2026
|
} else {
|
|
2028
2027
|
reject({
|
|
2029
2028
|
...info,
|
|
2030
2029
|
languageTypeKey,
|
|
2031
2030
|
msg: '数据获取异常',
|
|
2032
2031
|
});
|
|
2033
2032
|
}
|
|
2034
2033
|
} else {
|
|
2035
2034
|
const getRes = {
|
|
2036
2035
|
...info,
|
|
2037
2036
|
languageTypeKey,
|
|
2038
2037
|
env: getSgmCustomCode(langLoadErrorSgmCode),
|
|
2039
2038
|
msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
|
|
2040
2039
|
};
|
|
2041
2040
|
console.log('当前lang请求状态异常,具体信息见', getRes);
|
|
2042
2041
|
reject(getRes);
|
|
2043
2042
|
}
|
|
2044
2043
|
}
|
|
2045
2044
|
};
|
|
2046
2045
|
langXhrRequest.onerror = () => {
|
|
2047
2046
|
const getRes = {
|
|
2048
2047
|
...info,
|
|
2049
2048
|
env: getSgmCustomCode(langLoadErrorSgmCode),
|
|
2050
2049
|
msg: '请求错误',
|
|
2051
2050
|
};
|
|
2052
2051
|
console.log('当前lang请求错误', getRes);
|
|
2053
2052
|
langXhrRequest.abort();
|
|
2054
2053
|
reject(getRes);
|
|
2055
2054
|
};
|
|
2056
2055
|
langXhrRequest.ontimeout = () => {
|
|
2057
2056
|
const getRes = {
|
|
2058
2057
|
...info,
|
|
2059
2058
|
msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
|
|
2060
2059
|
};
|
|
2061
2060
|
console.log('执行lang多语言请求超时异常', getRes);
|
|
2062
2061
|
langXhrRequest.abort();
|
|
2063
2062
|
reject(getRes);
|
|
2064
2063
|
};
|
|
2065
2064
|
langXhrRequest.send();
|
|
2066
2065
|
} catch (e) {
|
|
2067
2066
|
console.log('执行lang多语言请求异常', e);
|
|
2068
2067
|
reject({
|
|
2069
2068
|
...info,
|
|
2070
2069
|
env: getSgmCustomCode(langLoadErrorSgmCode),
|
|
2071
2070
|
msg: '未知异常',
|
|
2072
2071
|
error: e,
|
|
2073
2072
|
});
|
|
2074
2073
|
}
|
|
2075
2074
|
});
|
|
2076
2075
|
}
|
|
2076
|
+
import Taro from '@tarojs/taro';
|
|
2077
2077
|
BUSINESS_TYPE,
|
|
2078
2078
|
cacheAppKey,
|
|
2079
2079
|
cacheAppUuidKey,
|
|
2080
2080
|
cacheH5LbsAddressKey,
|
|
2081
2081
|
JSSDK_APP_WEBVIEW_CODE,
|
|
2082
2082
|
LoadJsInitLoadEnvType,
|
|
2083
2083
|
LoadJsInitLoadType,
|
|
2084
2084
|
LoadJsInitTriggerType,
|
|
2085
2085
|
MPAAS_CONFIG_APP_LOW_VERSION,
|
|
2086
2086
|
MPAAS_CONFIG_APP_VERSION,
|
|
2087
2087
|
SECTION_HOME_TAB_NAME_TYPE,
|
|
2088
2088
|
SECTION_HOME_TAB_TYPE,
|
|
2089
2089
|
TaroEventType,
|
|
2090
2090
|
WX_BUSINESS_TYPE,
|
|
2091
2091
|
WXAPP_BIZ_KEY,
|
|
2092
2092
|
WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
2093
2093
|
languageTypeList,
|
|
2094
2094
|
getSystemInfos,
|
|
2095
2095
|
getTaroStorageKeyValue,
|
|
2096
2096
|
ipLoc_djd,
|
|
2097
2097
|
setTaroStorage,
|
|
2098
2098
|
isInJdAppH5DebugMode
|
|
2099
2099
|
callRouterAndroid,
|
|
2100
2100
|
callRouterIOS,
|
|
2101
2101
|
getMPaasConfigByBussinessKey,
|
|
2102
2102
|
dealNativePixelToCssPixel,
|
|
2103
2103
|
draBusinessCustomReport,
|
|
2104
2104
|
isAndroidDevice,
|
|
2105
2105
|
isH5AndJingGouMini,
|
|
2106
2106
|
isIosDevice,
|
|
2107
2107
|
isJdAndAndroidDevice,
|
|
2108
2108
|
isObject,
|
|
2109
2109
|
isPc,
|
|
2110
2110
|
isString,
|
|
2111
2111
|
jdAppVersion,
|
|
2112
2112
|
jdAppVersionStr,
|
|
2113
2113
|
serialize,
|
|
2114
2114
|
languageNowType,
|
|
2115
2115
|
urlCookie,
|
|
2116
2116
|
jdAppVersionCompare
|
|
2117
2117
|
abTestLabels: {},
|
|
2118
2118
|
nonSellableSkuids: {},
|
|
2119
2119
|
loginState: false,
|
|
2120
2120
|
cookiesStr: '',
|
|
2121
2121
|
userInfo: userPinKey,
|
|
2122
2122
|
isImmersive: false,
|
|
2123
2123
|
isJingGouMiniViewState: false,
|
|
2124
2124
|
isJingxiMiniViewState: false,
|
|
2125
2125
|
pageInfo: {
|
|
2126
2126
|
wxBusinessType: WX_BUSINESS_TYPE.NO,
|
|
2127
2127
|
address: '',
|
|
2128
2128
|
addressCommaStr: '',
|
|
2129
2129
|
un_area: '',
|
|
2130
2130
|
userLbsAddress: '',
|
|
2131
2131
|
vapptype: '1',
|
|
2132
2132
|
pageType: 'home',
|
|
2133
2133
|
isExposureState: false,
|
|
2134
2134
|
moduleId: '',
|
|
2135
2135
|
entrance: '',
|
|
2136
2136
|
dataType: BUSINESS_TYPE.ONLINE,
|
|
2137
2137
|
floorExposureInfo: {},
|
|
2138
2138
|
floorVideInfo: {},
|
|
2139
2139
|
productVideInfo: {},
|
|
2140
2140
|
tabsLoadAllDataInfo: {
|
|
2141
2141
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: false,
|
|
2142
2142
|
},
|
|
2143
2143
|
updateShopInfosAllState: false,
|
|
2144
2144
|
isVipShop: false,
|
|
2145
2145
|
isJdShowNativeImmersivePlayer: false,
|
|
2146
2146
|
...shopConfig,
|
|
2147
2147
|
pageScrollTop: 0,
|
|
2148
2148
|
pageIdxHeightInfo: {
|
|
2149
2149
|
list: [],
|
|
2150
2150
|
},
|
|
2151
2151
|
shopNavBarHeight: 0,
|
|
2152
2152
|
},
|
|
2153
2153
|
defaultQueryLogInfo: {
|
|
2154
2154
|
sourceType: 'JDshop',
|
|
2155
2155
|
sourceValue: '',
|
|
2156
2156
|
moduleId: 'none',
|
|
2157
2157
|
entrance: 'none',
|
|
2158
2158
|
},
|
|
2159
2159
|
sysInfo: {
|
|
2160
2160
|
windowWidth: isPc ? 375 : 0,
|
|
2161
2161
|
containerWidth: isPc ? 375 : 0,
|
|
2162
2162
|
windowHeight: 0,
|
|
2163
2163
|
netWorkType: '4g',
|
|
2164
2164
|
jdBottomBarHeight: 0,
|
|
2165
2165
|
jdNativeHeaderHeight: 0,
|
|
2166
2166
|
isJdTabletDevice: false,
|
|
2167
2167
|
isJdTabletLandscape: false,
|
|
2168
2168
|
},
|
|
2169
2169
|
queryInfo: {},
|
|
2170
2170
|
shopInfo: {},
|
|
2171
2171
|
openAppData: {},
|
|
2172
2172
|
public info: CommonInterFace.BaseConfigInfo;
|
|
2173
2173
|
public config: {
|
|
2174
2174
|
[key: string]: any;
|
|
2175
2175
|
};
|
|
2176
2176
|
public lazyContainer: CommonInterFace.lazyContainer;
|
|
2177
2177
|
public renderedIsvComponents: CommonInterFace.renderedIsvComponents;
|
|
2178
2178
|
public rootEleNode: HTMLElement | null;
|
|
2179
2179
|
public checkStatusAndLoginPromise: object | null;
|
|
2180
2180
|
private jmfeRegisterStatePromise: Promise<any> | null;
|
|
2181
2181
|
private jdScreenSizeInfoPromise: Promise<any> | null;
|
|
2182
2182
|
private rootEleWidthRegisterPromise: Promise<any> | null;
|
|
2183
2183
|
private jmfeRegisterState: boolean;
|
|
2184
2184
|
public loadJsSdkList: Array<any>;
|
|
2185
2185
|
public loadJsSdkListCachePromise: any;
|
|
2186
2186
|
public rootEleInitWidth: number;
|
|
2187
2187
|
public lbsAddressCachePromise: Promise<any> | null;
|
|
2188
2188
|
public languageCacheProimse: Promise<any> | null;
|
|
2189
2189
|
public languageJsonData: any | null;
|
|
2190
2190
|
public businessWorkerReady: boolean;
|
|
2191
2191
|
public businessWorkerReadyPromise: Promise<any> | null;
|
|
2192
2192
|
public workerPreRequestData = new Map<string, any>();
|
|
2193
2193
|
constructor(opt) {
|
|
2194
2194
|
this.info = this._getConfig(opt);
|
|
2195
2195
|
this.config = {};
|
|
2196
2196
|
this.loadJsSdkList = [];
|
|
2197
2197
|
this.loadJsSdkListCachePromise = {};
|
|
2198
2198
|
this.lazyContainer = {
|
|
2199
2199
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN]]: {
|
|
2200
2200
|
appLazyContainerList: [],
|
|
2201
2201
|
appLazyFinishContainerList: [],
|
|
2202
2202
|
},
|
|
2203
2203
|
[SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_PROMOTION]]: {
|
|
2204
2204
|
appLazyContainerList: [],
|
|
2205
2205
|
appLazyFinishContainerList: [],
|
|
2206
2206
|
},
|
|
2207
2207
|
};
|
|
2208
2208
|
this.renderedIsvComponents = {};
|
|
2209
2209
|
this.rootEleNode = document.querySelector('body');
|
|
2210
2210
|
this.checkStatusAndLoginPromise = null;
|
|
2211
2211
|
this.jmfeRegisterStatePromise = null;
|
|
2212
2212
|
this.jdScreenSizeInfoPromise = null;
|
|
2213
2213
|
this.rootEleWidthRegisterPromise = null;
|
|
2214
2214
|
this.lbsAddressCachePromise = null;
|
|
2215
2215
|
this.languageCacheProimse = null;
|
|
2216
2216
|
this.businessWorkerReady = false;
|
|
2217
2217
|
this.businessWorkerReadyPromise = null;
|
|
2218
2218
|
this.workerPreRequestData = new Map<string, any>();
|
|
2219
2219
|
this.languageJsonData = langeJsonDataForCn;
|
|
2220
2220
|
this.rootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth || -1;
|
|
2221
2221
|
this.loadOtherSdk();
|
|
2222
2222
|
if (isJdApp) {
|
|
2223
2223
|
this.jmfeReayPromise().then(() => {
|
|
2224
2224
|
this.jdWorkerReadyPromise()
|
|
2225
2225
|
})
|
|
2226
2226
|
this._getJdPadMinWidthForListen() && this.getPadWindowRootEleWidthPromise();
|
|
2227
2227
|
if (isJdAndHarmonyDevice) {
|
|
2228
2228
|
this.renderNextTickLoadSdk(2000);
|
|
2229
2229
|
}
|
|
2230
2230
|
}
|
|
2231
2231
|
}
|
|
2232
2232
|
_getConfig(opt) {
|
|
2233
2233
|
return Object.assign({}, DefaultConfig, opt);
|
|
2234
2234
|
}
|
|
2235
2235
|
|
|
2236
2236
|
jmfeReayPromise(): Promise<any> {
|
|
2237
2237
|
if (isJdApp) {
|
|
2238
2238
|
if (this.jmfeRegisterState) {
|
|
2239
2239
|
return Promise.resolve(true);
|
|
2240
2240
|
} else {
|
|
2241
2241
|
!this.jmfeRegisterStatePromise &&
|
|
2242
2242
|
(this.jmfeRegisterStatePromise = new Promise((resolve, reject) => {
|
|
2243
2243
|
ready('jmfe', 3000)
|
|
2244
2244
|
.then(() => {
|
|
2245
2245
|
window?.jmfe && window.jmfe.registerCode(JSSDK_APP_WEBVIEW_CODE);
|
|
2246
2246
|
this.jmfeRegisterState = true;
|
|
2247
2247
|
resolve(true);
|
|
2248
2248
|
console.log(
|
|
2249
2249
|
'松果app内初始化注册jmfe认证完成',
|
|
2250
2250
|
window?.jmfe,
|
|
2251
2251
|
'当前版本',
|
|
2252
2252
|
window?.jmfe?.VERSION,
|
|
2253
2253
|
);
|
|
2254
2254
|
})
|
|
2255
2255
|
.catch((err) => {
|
|
2256
2256
|
console.error('jmfe ready error', err);
|
|
2257
2257
|
reject(false);
|
|
2258
2258
|
});
|
|
2259
2259
|
}));
|
|
2260
2260
|
return this.jmfeRegisterStatePromise;
|
|
2261
2261
|
}
|
|
2262
2262
|
} else {
|
|
2263
2263
|
return Promise.reject(false);
|
|
2264
2264
|
}
|
|
2265
2265
|
}
|
|
2266
2266
|
|
|
2267
2267
|
jdWorkerReadyPromise(): Promise<any> {
|
|
2268
2268
|
if (isJdApp) {
|
|
2269
2269
|
if (this.businessWorkerReady) {
|
|
2270
2270
|
return Promise.resolve(true);
|
|
2271
2271
|
} else {
|
|
2272
2272
|
const getOpenJdWorkerState = window?.PAGE_DATA?.businessData?.businessWorkerVersion && versionCompare(jdAppVersionStr, window?.shopGlobalSwitch?.jdAppWorkerOpenVersion || '15.3.10') >= 0;
|
|
2273
2273
|
!this.businessWorkerReadyPromise && (this.businessWorkerReadyPromise = getOpenJdWorkerState ?
|
|
2274
2274
|
new Promise((resolve) => {
|
|
2275
2275
|
this.jmfeReayPromise().then(() => {
|
|
2276
2276
|
window.jmfe
|
|
2277
2277
|
.onMsgForWorker(
|
|
2278
2278
|
{ version_code: window?.PAGE_DATA?.businessData?.businessWorkerVersion },
|
|
2279
2279
|
(workerData) => {
|
|
2280
2280
|
console.log(
|
|
2281
2281
|
'收到业务jd worker消息结果:',
|
|
2282
2282
|
workerData,
|
|
2283
2283
|
);
|
|
2284
2284
|
if (workerData && workerData?.workerType) {
|
|
2285
2285
|
const getWorkerType = workerData?.workerType
|
|
2286
2286
|
if (getWorkerType === TaroEventType.jdWorkerPreRequest) {
|
|
2287
2287
|
this.workerPreRequestData.set(workerData?.functionId, workerData);
|
|
2288
2288
|
Taro.eventCenter.trigger(
|
|
2289
2289
|
getWorkerType,
|
|
2290
2290
|
workerData);
|
|
2291
2291
|
} else if (getWorkerType === TaroEventType.jdWorkerRequest) {
|
|
2292
2292
|
Taro.eventCenter.trigger(
|
|
2293
2293
|
getWorkerType,
|
|
2294
2294
|
workerData);
|
|
2295
2295
|
}
|
|
2296
2296
|
}
|
|
2297
2297
|
},
|
|
2298
2298
|
)
|
|
2299
2299
|
.then(() => {
|
|
2300
2300
|
console.log('jd worker注册成功');
|
|
2301
2301
|
this.businessWorkerReady = true;
|
|
2302
2302
|
resolve(true);
|
|
2303
2303
|
})
|
|
2304
2304
|
.catch((error) => {
|
|
2305
2305
|
console.log('jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑', error);
|
|
2306
2306
|
draBusinessCustomReport({
|
|
2307
2307
|
eventName:'business',
|
|
2308
2308
|
errorName: 'jmfe_onMsgForWorker_error',
|
|
2309
2309
|
errorMessage: `jd worker注册失败,可能是客户端不支持worker,或者worker.js文件加载失败等原因。h5需要在此处做逻辑兜底,无法通过worker处理单独逻辑`,
|
|
2310
2310
|
extraData: JSON.stringify({
|
|
2311
2311
|
businessWorkerVersion:window?.PAGE_DATA?.businessData?.businessWorkerVersion,
|
|
2312
2312
|
error,
|
|
2313
2313
|
}),
|
|
2314
2314
|
});
|
|
2315
2315
|
resolve(false);
|
|
2316
2316
|
});
|
|
2317
2317
|
}).catch((err) => {
|
|
2318
2318
|
console.log('jmfe超时异常,worker注册失败', err);
|
|
2319
2319
|
resolve(false);
|
|
2320
2320
|
})
|
|
2321
2321
|
}) : Promise.resolve(false))
|
|
2322
2322
|
}
|
|
2323
2323
|
return this.businessWorkerReadyPromise
|
|
2324
2324
|
} else {
|
|
2325
2325
|
return Promise.resolve(false);
|
|
2326
2326
|
}
|
|
2327
2327
|
}
|
|
2328
2328
|
|
|
2329
2329
|
taskTimeoutPromise(callBack, timeout = 2000) {
|
|
2330
2330
|
return new Promise((resolve) => {
|
|
2331
2331
|
setTimeout(() => {
|
|
2332
2332
|
const getCallBackRes = typeof callBack === 'function' && callBack();
|
|
2333
2333
|
return resolve(getCallBackRes || false);
|
|
2334
2334
|
}, isInJdAppH5DebugMode ? 0 : timeout);
|
|
2335
2335
|
});
|
|
2336
2336
|
}
|
|
2337
2337
|
_getJdPadMinWidthForListen() {
|
|
2338
2338
|
return (
|
|
2339
2339
|
isJdApp &&
|
|
2340
2340
|
Math.min(window.screen.width, window.screen.height) >
|
|
2341
2341
|
(window?.shopGlobalSwitch?.checkPadRootEleMinWidth || 600)
|
|
2342
2342
|
);
|
|
2343
2343
|
}
|
|
2344
2344
|
|
|
2345
2345
|
getJdScreenSizeInfoPromise() {
|
|
2346
2346
|
!this.jdScreenSizeInfoPromise &&
|
|
2347
2347
|
(this.jdScreenSizeInfoPromise = new Promise((resolve) => {
|
|
2348
2348
|
const getThisTime = Date.now();
|
|
2349
2349
|
this.jmfeReayPromise().then(() => {
|
|
2350
2350
|
return Promise.race([
|
|
2351
2351
|
window.jmfe.getScreenSize(),
|
|
2352
2352
|
this.taskTimeoutPromise(() => {
|
|
2353
2353
|
return {
|
|
2354
2354
|
status: '-10',
|
|
2355
2355
|
msg: '获取大屏信息2s超时',
|
|
2356
2356
|
};
|
|
2357
2357
|
}),
|
|
2358
2358
|
])
|
|
2359
2359
|
.then((res) => {
|
|
2360
2360
|
console.warn('===获取app大屏信息====', res);
|
|
2361
2361
|
const { status, data } = res;
|
|
2362
2362
|
if (status === '0' && data) {
|
|
2363
2363
|
const { sizeType, isLandscape, pageHeight, pageWidth } = data;
|
|
2364
2364
|
const getPageInfo = dealNativePixelToCssPixel({
|
|
2365
2365
|
pageWidth,
|
|
2366
2366
|
pageHeight,
|
|
2367
2367
|
});
|
|
2368
2368
|
this.info.sysInfo.jdScreenSizeType = sizeType;
|
|
2369
2369
|
const getUseTime = Date.now() - getThisTime;
|
|
2370
2370
|
console.warn(
|
|
2371
2371
|
'===计算是否是app大屏信息,需满足宽度最新720===',
|
|
2372
2372
|
getPageInfo,
|
|
2373
2373
|
'原始数据',
|
|
2374
2374
|
data,
|
|
2375
2375
|
'是否是横屏isLandscape为1=',
|
|
2376
2376
|
isLandscape,
|
|
2377
2377
|
'用时',
|
|
2378
2378
|
getUseTime,
|
|
2379
2379
|
);
|
|
2380
2380
|
if (getPageInfo?.pageWidth > 0) {
|
|
2381
2381
|
this.rootEleInitWidth = getPageInfo?.pageWidth;
|
|
2382
2382
|
draBusinessCustomReport({
|
|
2383
2383
|
eventName: 'UIInteract',
|
|
2384
2384
|
errorName: 'rootEle_width_getJdScreenSizeInfo',
|
|
2385
2385
|
errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果,用时${getUseTime}`,
|
|
2386
2386
|
extraData: JSON.stringify({
|
|
2387
2387
|
isJdApp,
|
|
2388
2388
|
getPageInfo,
|
|
2389
2389
|
originData: res,
|
|
2390
2390
|
}),
|
|
2391
2391
|
});
|
|
2392
2392
|
resolve(getPageInfo);
|
|
2393
2393
|
} else {
|
|
2394
2394
|
resolve({
|
|
2395
2395
|
pageWidth: 0,
|
|
2396
2396
|
pageHeight: 0,
|
|
2397
2397
|
msg: '转换异常',
|
|
2398
2398
|
});
|
|
2399
2399
|
}
|
|
2400
2400
|
} else {
|
|
2401
2401
|
resolve({
|
|
2402
2402
|
pageWidth: 0,
|
|
2403
2403
|
pageHeight: 0,
|
|
2404
2404
|
msg: '获取大屏信息异常或者超时',
|
|
2405
2405
|
});
|
|
2406
2406
|
}
|
|
2407
2407
|
})
|
|
2408
2408
|
.catch((err) => {
|
|
2409
2409
|
console.log('获取大屏信息异常', err);
|
|
2410
2410
|
resolve({
|
|
2411
2411
|
pageWidth: 0,
|
|
2412
2412
|
pageHeight: 0,
|
|
2413
2413
|
msg: '获取大屏信息异常',
|
|
2414
2414
|
});
|
|
2415
2415
|
});
|
|
2416
2416
|
});
|
|
2417
2417
|
}));
|
|
2418
2418
|
return this.jdScreenSizeInfoPromise;
|
|
2419
2419
|
}
|
|
2420
2420
|
|
|
2421
2421
|
listenJdTabletScreenChange() {
|
|
2422
2422
|
this.jmfeReayPromise().then(() => {
|
|
2423
2423
|
try {
|
|
2424
2424
|
console.log('初始化监听大屏信息变化', window.jmfe.listenDeviceScreenChange);
|
|
2425
2425
|
window.jmfe.listenDeviceScreenChange((event) => {
|
|
2426
2426
|
console.log(
|
|
2427
2427
|
'监听app大屏信息变化,orientation为landscape表示横屏,multiScreen为1表示android端分屏',
|
|
2428
2428
|
event,
|
|
2429
2429
|
'通过前端判断是不是横屏',
|
|
2430
2430
|
window.matchMedia('(orientation: landscape)')?.matches,
|
|
2431
2431
|
);
|
|
2432
2432
|
const { orientation } = event?.data;
|
|
2433
2433
|
if (orientation) {
|
|
2434
2434
|
this.info.sysInfo.isJdTabletLandscape = orientation === 'landscape';
|
|
2435
2435
|
Taro.eventCenter.trigger(
|
|
2436
2436
|
TaroEventType.TABLE_SCREEN_CHANGE,
|
|
2437
2437
|
this.info.sysInfo.isJdTabletLandscape,
|
|
2438
2438
|
orientation,
|
|
2439
2439
|
);
|
|
2440
2440
|
}
|
|
2441
2441
|
});
|
|
2442
2442
|
} catch (error) {
|
|
2443
2443
|
console.log('listenScreenChange的打印error:', error);
|
|
2444
2444
|
}
|
|
2445
2445
|
});
|
|
2446
2446
|
}
|
|
2447
2447
|
|
|
2448
2448
|
updateBusinessDomainAndApi(domain, api) {
|
|
2449
2449
|
}
|
|
2450
2450
|
|
|
2451
2451
|
formatNativeScreenPageData(action) {
|
|
2452
2452
|
let getChangePageInfo: any = null;
|
|
2453
2453
|
try {
|
|
2454
2454
|
const getNativeScreenPageInfoStr = window.XWebView?._callNative(
|
|
2455
2455
|
JSON.stringify({
|
|
2456
2456
|
plugin: 'JDHybridScreenPlugin',
|
|
2457
2457
|
action,
|
|
2458
2458
|
sync: '1',
|
|
2459
2459
|
}),
|
|
2460
2460
|
);
|
|
2461
2461
|
const getChangePageInfoData =
|
|
2462
2462
|
typeof getNativeScreenPageInfoStr === 'string'
|
|
2463
2463
|
? JSON.parse(getNativeScreenPageInfoStr)
|
|
2464
2464
|
: null;
|
|
2465
2465
|
if (getChangePageInfoData && typeof getChangePageInfoData === 'object') {
|
|
2466
2466
|
const { code, data } = getChangePageInfoData;
|
|
2467
2467
|
getChangePageInfo = code && code === '0' ? data : null;
|
|
2468
2468
|
}
|
|
2469
2469
|
} catch (e) {
|
|
2470
2470
|
console.log('JDHybridScreenPlugin转换异常', e);
|
|
2471
2471
|
}
|
|
2472
2472
|
return getChangePageInfo;
|
|
2473
2473
|
}
|
|
2474
2474
|
|
|
2475
2475
|
isAndroidFoldScreen() {
|
|
2476
2476
|
return this.formatNativeScreenPageData('isFoldScreen') === '1';
|
|
2477
2477
|
}
|
|
2478
2478
|
|
|
2479
2479
|
isHarmonyFoldScreenPromise(): Promise<{
|
|
2480
2480
|
isFoldScreen: boolean,
|
|
2481
2481
|
getFoldDisplayMode?: number,
|
|
2482
2482
|
}> {
|
|
2483
2483
|
return new Promise(resolve => {
|
|
2484
2484
|
this.jmfeReayPromise().then(() => {
|
|
2485
2485
|
if (window.jmfe?.callNative) {
|
|
2486
2486
|
Promise.all([
|
|
2487
2487
|
window.jmfe.callNative('JDHybridScreenPlugin', 'isFoldScreen', {}),
|
|
2488
2488
|
window.jmfe.callNative('JDHybridScreenPlugin', 'getFoldDisplayMode', {})
|
|
2489
2489
|
]).then(res => {
|
|
2490
2490
|
resolve({
|
|
2491
2491
|
isFoldScreen: res?.[0]?.data === '1',
|
|
2492
2492
|
getFoldDisplayMode: res?.[1]?.data,
|
|
2493
2493
|
})
|
|
2494
2494
|
}).catch(() => {
|
|
2495
2495
|
resolve({
|
|
2496
2496
|
isFoldScreen: false,
|
|
2497
2497
|
getFoldDisplayMode: undefined,
|
|
2498
2498
|
});
|
|
2499
2499
|
});
|
|
2500
2500
|
} else {
|
|
2501
2501
|
resolve({
|
|
2502
2502
|
isFoldScreen: false,
|
|
2503
2503
|
getFoldDisplayMode: undefined,
|
|
2504
2504
|
});
|
|
2505
2505
|
}
|
|
2506
2506
|
}).catch(() => {
|
|
2507
2507
|
resolve({
|
|
2508
2508
|
isFoldScreen: false,
|
|
2509
2509
|
getFoldDisplayMode: undefined,
|
|
2510
2510
|
});
|
|
2511
2511
|
});
|
|
2512
2512
|
})
|
|
2513
2513
|
}
|
|
2514
2514
|
|
|
2515
2515
|
getJdAndroidPageChangeScreenInfo() {
|
|
2516
2516
|
const getPageScreenInfo = this.formatNativeScreenPageData('getScreenSize');
|
|
2517
2517
|
if (getPageScreenInfo && getPageScreenInfo?.pageWidth && getPageScreenInfo?.pageHeight) {
|
|
2518
2518
|
const { pageWidth, pageHeight } = dealNativePixelToCssPixel({
|
|
2519
2519
|
pageWidth: getPageScreenInfo.pageWidth,
|
|
2520
2520
|
pageHeight: getPageScreenInfo.pageHeight,
|
|
2521
2521
|
});
|
|
2522
2522
|
getPageScreenInfo.pageWidth = pageWidth;
|
|
2523
2523
|
getPageScreenInfo.pageHeight = pageHeight;
|
|
2524
2524
|
}
|
|
2525
2525
|
return getPageScreenInfo;
|
|
2526
2526
|
}
|
|
2527
2527
|
|
|
2528
2528
|
getRootEleWindowWidthInfo() {
|
|
2529
2529
|
const getRootEleWidth = document.documentElement.getBoundingClientRect().width;
|
|
2530
2530
|
const getWindowWidth = window.innerWidth;
|
|
2531
2531
|
const getScreenWidth = window.screen.width;
|
|
2532
2532
|
return {
|
|
2533
2533
|
getRootEleWidth,
|
|
2534
2534
|
getWindowWidth,
|
|
2535
2535
|
getScreenWidth,
|
|
2536
2536
|
};
|
|
2537
2537
|
}
|
|
2538
2538
|
|
|
2539
2539
|
dealRootEleWidthFn(reportParam = {}, timeout = 0) {
|
|
2540
2540
|
const { getRootEleWidth, getWindowWidth, getScreenWidth } = this.getRootEleWindowWidthInfo();
|
|
2541
2541
|
console.log(
|
|
2542
2542
|
'当前获取根元素的宽度',
|
|
2543
2543
|
getRootEleWidth,
|
|
2544
2544
|
'getWindowWidth',
|
|
2545
2545
|
getWindowWidth,
|
|
2546
2546
|
'getScreenWidth',
|
|
2547
2547
|
getScreenWidth,
|
|
2548
2548
|
);
|
|
2549
2549
|
const getLastWidth =
|
|
2550
2550
|
getRootEleWidth > 0
|
|
2551
2551
|
? Math.round(getRootEleWidth)
|
|
2552
2552
|
: Math.round(getWindowWidth > 0 ? getWindowWidth : getScreenWidth);
|
|
2553
2553
|
console.warn(
|
|
2554
2554
|
`根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
|
|
2555
2555
|
);
|
|
2556
2556
|
timeout > 0 &&
|
|
2557
2557
|
draBusinessCustomReport({
|
|
2558
2558
|
eventName: 'UIInteract',
|
|
2559
2559
|
errorName: 'rootEle_width_timeout_getJdScreenSizeInfo',
|
|
2560
2560
|
errorMessage: `根元素获取宽度初始化为0,通过getJdScreenSizeInfo获取结果超时,超时时间${timeout}ms,最终兜底再获取一次根元素宽度${getLastWidth}`,
|
|
2561
2561
|
extraData: JSON.stringify({
|
|
2562
2562
|
isJdApp,
|
|
2563
2563
|
getRootEleWidth,
|
|
2564
2564
|
getWindowWidth,
|
|
2565
2565
|
getScreenWidth,
|
|
2566
2566
|
...reportParam,
|
|
2567
2567
|
}),
|
|
2568
2568
|
});
|
|
2569
2569
|
return getLastWidth;
|
|
2570
2570
|
}
|
|
2571
2571
|
|
|
2572
2572
|
getPadWindowRootEleWidthPromise() {
|
|
2573
2573
|
if (this.rootEleInitWidth > 0) {
|
|
2574
2574
|
return Promise.resolve(this.rootEleInitWidth);
|
|
2575
2575
|
} else {
|
|
2576
2576
|
!this.rootEleWidthRegisterPromise &&
|
|
2577
2577
|
(this.rootEleWidthRegisterPromise = new Promise((resolve) => {
|
|
2578
2578
|
const getRootEleInitWidth = this.getRootEleWindowWidthInfo().getRootEleWidth;
|
|
2579
2579
|
if (getRootEleInitWidth > 0) {
|
|
2580
2580
|
console.log('初始化获取根元素宽度正常,为', getRootEleInitWidth);
|
|
2581
2581
|
this.rootEleInitWidth = Math.round(getRootEleInitWidth);
|
|
2582
2582
|
resolve(this.rootEleInitWidth);
|
|
2583
2583
|
} else {
|
|
2584
2584
|
const timerPromise = () => {
|
|
2585
2585
|
return new Promise((resolve2) => {
|
|
2586
2586
|
window.setTimeout(() => {
|
|
2587
2587
|
const { getRootEleWidth, getWindowWidth, getScreenWidth } =
|
|
2588
2588
|
this.getRootEleWindowWidthInfo();
|
|
2589
2589
|
if (getRootEleWidth > 0 || getWindowWidth > 0) {
|
|
2590
2590
|
console.warn(
|
|
2591
2591
|
`根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth},getScreenWidth为${getScreenWidth}`,
|
|
2592
2592
|
);
|
|
2593
2593
|
draBusinessCustomReport({
|
|
2594
2594
|
eventName: 'UIInteract',
|
|
2595
2595
|
errorName: 'rootEle_width_200_timeout_info',
|
|
2596
2596
|
errorMessage: `根元素获取宽度初始化为0,200ms后尝试获取最新结果,getRootEleWidth为${getRootEleWidth},getWindowWidth为${getWindowWidth}`,
|
|
2597
2597
|
extraData: JSON.stringify({
|
|
2598
2598
|
isJdApp,
|
|
2599
2599
|
getRootEleWidth,
|
|
2600
2600
|
getWindowWidth,
|
|
2601
2601
|
getScreenWidth,
|
|
2602
2602
|
}),
|
|
2603
2603
|
});
|
|
2604
2604
|
const getRes =
|
|
2605
2605
|
getRootEleWidth > 0 && getWindowWidth > 0
|
|
2606
2606
|
? Math.min(getRootEleWidth, getWindowWidth)
|
|
2607
2607
|
: Math.max(getRootEleWidth, getWindowWidth);
|
|
2608
2608
|
resolve2({
|
|
2609
2609
|
pageWidth: Math.round(getRes),
|
|
2610
2610
|
});
|
|
2611
2611
|
}
|
|
2612
2612
|
}, 200);
|
|
2613
2613
|
});
|
|
2614
2614
|
};
|
|
2615
2615
|
Promise.race([timerPromise(), this.getJdScreenSizeInfoPromise()]).then((res) => {
|
|
2616
2616
|
const { pageWidth } = res;
|
|
2617
2617
|
console.log('获取结果Promise.race getJdScreenSizeInfo', res);
|
|
2618
2618
|
pageWidth > 0 ? resolve(pageWidth) : resolve(this.dealRootEleWidthFn(res, 2000));
|
|
2619
2619
|
});
|
|
2620
2620
|
}
|
|
2621
2621
|
}));
|
|
2622
2622
|
return this.rootEleWidthRegisterPromise;
|
|
2623
2623
|
}
|
|
2624
2624
|
}
|
|
2625
2625
|
|
|
2626
2626
|
async getSystemInfo(params) {
|
|
2627
2627
|
const getParams = Object.assign({}, params || {});
|
|
2628
2628
|
if (this.rootEleInitWidth > 0) {
|
|
2629
2629
|
getParams['rootEleInitWidth'] = this.rootEleInitWidth;
|
|
2630
2630
|
console.log('获取当前系统信息的时候已经获取到根元素宽度,值为', this.rootEleInitWidth);
|
|
2631
2631
|
} else {
|
|
2632
2632
|
if (this._getJdPadMinWidthForListen()) {
|
|
2633
2633
|
getParams['rootEleInitWidth'] = await this.getPadWindowRootEleWidthPromise();
|
|
2634
2634
|
getParams['replaceSystemWidth'] = true;
|
|
2635
2635
|
}
|
|
2636
2636
|
}
|
|
2637
2637
|
isJdApp && this.createLanguagePromise();
|
|
2638
2638
|
let info: UtilsInterFace.taroGetSystemInfoSyncRes | any = getSystemInfos(getParams);
|
|
2639
2639
|
if (isJdAndAndroidDevice && info?.initWindowWidth <= 0) {
|
|
2640
2640
|
let _isfoldScreen = false;
|
|
2641
2641
|
const getStorageData = getTaroStorageKeyValue('jd_shopx_androidIsFoldScreen');
|
|
2642
2642
|
console.info(
|
|
2643
2643
|
'获取当前本地存储是否有jd_shopx_androidIsFoldScreen',
|
|
2644
2644
|
getStorageData,
|
|
2645
2645
|
'通过缓存值第一次判断是否是折叠屏',
|
|
2646
2646
|
getStorageData === 'true',
|
|
2647
2647
|
);
|
|
2648
2648
|
if (!getStorageData) {
|
|
2649
2649
|
_isfoldScreen = this.isAndroidFoldScreen();
|
|
2650
2650
|
setTaroStorage('jd_shopx_androidIsFoldScreen', `${_isfoldScreen}`);
|
|
2651
2651
|
} else {
|
|
2652
2652
|
_isfoldScreen = getStorageData === 'true';
|
|
2653
2653
|
}
|
|
2654
2654
|
if (_isfoldScreen) {
|
|
2655
2655
|
const getJdAndroidPageInfo = this.getJdAndroidPageChangeScreenInfo();
|
|
2656
2656
|
if (getJdAndroidPageInfo) {
|
|
2657
2657
|
info = getSystemInfos(getJdAndroidPageInfo);
|
|
2658
2658
|
console.warn(
|
|
2659
2659
|
'当前为松果安卓折叠屏app,获取折叠屏信息',
|
|
2660
2660
|
getJdAndroidPageInfo,
|
|
2661
2661
|
'获取转换后的系统信息',
|
|
2662
2662
|
info,
|
|
2663
2663
|
);
|
|
2664
2664
|
draBusinessCustomReport({
|
|
2665
2665
|
eventName: 'UIInteract',
|
|
2666
2666
|
errorName: 'android_jdapp_foldScreen_info',
|
|
2667
2667
|
errorMessage: '松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异',
|
|
2668
2668
|
extraData: JSON.stringify({
|
|
2669
2669
|
title: `松果安卓app为折叠屏,重置获取的系统宽高信息,因为获取宽高度信息初始化内部可能存在横竖屏差异`,
|
|
2670
2670
|
androidPageInfo: getJdAndroidPageInfo,
|
|
2671
2671
|
jdAppVersionStr,
|
|
2672
2672
|
taroSysInfo: info,
|
|
2673
2673
|
}),
|
|
2674
2674
|
});
|
|
2675
2675
|
}
|
|
2676
2676
|
}
|
|
2677
2677
|
}
|
|
2678
2678
|
if (isJdApp) {
|
|
2679
2679
|
info?.isJdTabletDevice && this.listenJdTabletScreenChange();
|
|
2680
2680
|
}
|
|
2681
2681
|
this.info.sysInfo = {
|
|
2682
2682
|
actualNavBarHeight: 0,
|
|
2683
2683
|
...this.info.sysInfo,
|
|
2684
2684
|
...info,
|
|
2685
2685
|
safeContentHeight: info?.screenHeight,
|
|
2686
2686
|
headerHeight: 0,
|
|
2687
2687
|
tabBarHeight: 0,
|
|
2688
2688
|
languageType: languageNowType,
|
|
2689
2689
|
};
|
|
2690
2690
|
if (isJdApp || isH5AndJingGouMini) {
|
|
2691
2691
|
this.getLbsAddressCachePromise();
|
|
2692
2692
|
}
|
|
2693
2693
|
if (isJdApp) {
|
|
2694
2694
|
this.info.sysInfo['hostVersionName'] = jdAppVersionStr;
|
|
2695
2695
|
this.info.sysInfo['hostAppVersion'] = jdAppVersion;
|
|
2696
2696
|
this.getJdAppBaseInfo();
|
|
2697
2697
|
this.getAddressCachePromise();
|
|
2698
2698
|
this.getElderModePromise();
|
|
2699
2699
|
this.getJDAppearanceStatePromise();
|
|
2700
2700
|
this.createJdAndroidRquestEventForTouchStart();
|
|
2701
2701
|
}
|
|
2702
2702
|
this.getWifiVideoAutoPlayAsync();
|
|
2703
2703
|
this.getMPaasConfigAsync();
|
|
2704
2704
|
this.getNetWorkType();
|
|
2705
2705
|
}
|
|
2706
2706
|
|
|
2707
2707
|
getElderModePromise() {
|
|
2708
2708
|
if (this.info.sysInfo.hasOwnProperty('jdAppModeType')) {
|
|
2709
2709
|
return Promise.resolve(this.info.sysInfo.jdAppModeType);
|
|
2710
2710
|
} else {
|
|
2711
2711
|
if (isJdAndAndroidDevice) {
|
|
2712
2712
|
this.info.sysInfo.jdAppModeType = '0';
|
|
2713
2713
|
return Promise.resolve(this.info.sysInfo.jdAppModeType);
|
|
2714
2714
|
} else {
|
|
2715
2715
|
return Promise.race([
|
|
2716
2716
|
this.taskTimeoutPromise(() => {
|
|
2717
2717
|
this.info.sysInfo.jdAppModeType = '0';
|
|
2718
2718
|
return this.info.sysInfo.jdAppModeType;
|
|
2719
2719
|
}),
|
|
2720
2720
|
new Promise((resolve) => {
|
|
2721
2721
|
const getCallBackName = `getJdCurrentModeType${Date.now()}`;
|
|
2722
2722
|
if (!window[getCallBackName]) {
|
|
2723
2723
|
window[getCallBackName] = (res) => {
|
|
2724
2724
|
try {
|
|
2725
2725
|
const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
|
|
2726
2726
|
const { status, data, msg } = getResJson;
|
|
2727
2727
|
console.log(`获取松果app展示模式成功,返回结果${data}`);
|
|
2728
2728
|
if (status === '0') {
|
|
2729
2729
|
this.info.sysInfo.jdAppModeType = data;
|
|
2730
2730
|
resolve(data);
|
|
2731
2731
|
} else {
|
|
2732
2732
|
resolve('0');
|
|
2733
2733
|
}
|
|
2734
2734
|
} catch (e) {
|
|
2735
2735
|
resolve('0');
|
|
2736
2736
|
}
|
|
2737
2737
|
window[getCallBackName] = null;
|
|
2738
2738
|
};
|
|
2739
2739
|
}
|
|
2740
2740
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
2741
2741
|
method: 'callSyncRouterModuleWithParams',
|
|
2742
2742
|
params: JSON.stringify({
|
|
2743
2743
|
routerURL: 'router://JDBModeModule/getCurrentMode',
|
|
2744
2744
|
routerParam: {},
|
|
2745
2745
|
callBackName: `window.${getCallBackName}`,
|
|
2746
2746
|
callBackId: `${getCallBackName}Ios`,
|
|
2747
2747
|
}),
|
|
2748
2748
|
});
|
|
2749
2749
|
}),
|
|
2750
2750
|
]);
|
|
2751
2751
|
}
|
|
2752
2752
|
}
|
|
2753
2753
|
}
|
|
2754
2754
|
getAPPUseStraightCorner() {
|
|
2755
2755
|
const routerURL = 'router://JDBaseUtilsModule/isUI14Enable';
|
|
2756
2756
|
const params = {
|
|
2757
2757
|
routerURL,
|
|
2758
2758
|
routerParam: {},
|
|
2759
2759
|
jdRouter: '1',
|
|
2760
2760
|
};
|
|
2761
2761
|
if (this.info.sysInfo.hasOwnProperty('jdStraightCorner')) {
|
|
2762
2762
|
return Promise.resolve(this.info.sysInfo.jdStraightCorner);
|
|
2763
2763
|
} else {
|
|
2764
2764
|
return this.jmfeReayPromise()
|
|
2765
2765
|
.then(() => {
|
|
2766
2766
|
if (isJdAndHarmonyDevice || !isJdApp) {
|
|
2767
2767
|
console.log('not APP or is Harmony');
|
|
2768
2768
|
return Promise.resolve(false);
|
|
2769
2769
|
}
|
|
2770
2770
|
console.log('jmfe setShareInfo', params);
|
|
2771
2771
|
return Promise.race([
|
|
2772
2772
|
window.jmfe.callRouter(params),
|
|
2773
2773
|
this.taskTimeoutPromise(() => {
|
|
2774
2774
|
return false;
|
|
2775
2775
|
}),
|
|
2776
2776
|
]).then(({ status, data }) => {
|
|
2777
2777
|
console.log('004 ~ file: index.tsx:133 ~ .then ~ data:', data);
|
|
2778
2778
|
console.log('004 ~ file: index.tsx:133 ~ .then ~ status:', status);
|
|
2779
2779
|
this.info.sysInfo.jdStraightCorner = status === '0' && Number(data) === 1;
|
|
2780
2780
|
return Promise.resolve(status === '0' && Number(data) === 1);
|
|
2781
2781
|
});
|
|
2782
2782
|
})
|
|
2783
2783
|
.catch((e) => {
|
|
2784
2784
|
console.log('jmfe error', e);
|
|
2785
2785
|
return Promise.resolve(false);
|
|
2786
2786
|
});
|
|
2787
2787
|
}
|
|
2788
2788
|
}
|
|
2789
2789
|
|
|
2790
2790
|
getJDAppearanceStatePromise() {
|
|
2791
2791
|
if (this.info.sysInfo.hasOwnProperty('jdAppearanceState')) {
|
|
2792
2792
|
return Promise.resolve(this.info.sysInfo.jdAppearanceState);
|
|
2793
2793
|
} else {
|
|
2794
2794
|
return Promise.race([
|
|
2795
2795
|
this.taskTimeoutPromise(() => {
|
|
2796
2796
|
this.info.sysInfo.jdAppearanceState = '0';
|
|
2797
2797
|
return this.info.sysInfo.jdAppearanceState;
|
|
2798
2798
|
}),
|
|
2799
2799
|
new Promise((resolve) => {
|
|
2800
2800
|
const getCallBackName = `getJdCurrentAppearanceState${Date.now()}`;
|
|
2801
2801
|
if (!window[getCallBackName]) {
|
|
2802
2802
|
window[getCallBackName] = (res) => {
|
|
2803
2803
|
try {
|
|
2804
2804
|
console.log('getJDAppearanceStatePromise', res);
|
|
2805
2805
|
const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
|
|
2806
2806
|
const { status, data, msg } = getResJson;
|
|
2807
2807
|
console.log(`获取松果app是否开启黑暗模式成功,返回结果${data}`);
|
|
2808
2808
|
if (status === '0') {
|
|
2809
2809
|
this.info.sysInfo.jdAppearanceState = data;
|
|
2810
2810
|
resolve(data);
|
|
2811
2811
|
} else {
|
|
2812
2812
|
resolve('0');
|
|
2813
2813
|
}
|
|
2814
2814
|
} catch (e) {
|
|
2815
2815
|
resolve('0');
|
|
2816
2816
|
}
|
|
2817
2817
|
window[getCallBackName] = null;
|
|
2818
2818
|
};
|
|
2819
2819
|
}
|
|
2820
2820
|
if (isAndroidDevice) {
|
|
2821
2821
|
const jsonString = JSON.stringify({
|
|
2822
2822
|
callBackName: `window.${getCallBackName}`,
|
|
2823
2823
|
});
|
|
2824
2824
|
console.log('window.JDAppearance', window?.JDAppearance);
|
|
2825
2825
|
window?.JDAppearance &&
|
|
2826
2826
|
window?.JDAppearance?.getUiState &&
|
|
2827
2827
|
window.JDAppearance.getUiState(jsonString);
|
|
2828
2828
|
} else {
|
|
2829
2829
|
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
2830
2830
|
method: 'callSyncRouterModuleWithParams',
|
|
2831
2831
|
params: JSON.stringify({
|
|
2832
2832
|
routerURL: 'router://JDWebViewBusinessModule/getJDAppearanceState',
|
|
2833
2833
|
routerParam: {},
|
|
2834
2834
|
callBackName: `window.${getCallBackName}`,
|
|
2835
2835
|
callBackId: `${getCallBackName}Ios`,
|
|
2836
2836
|
}),
|
|
2837
2837
|
});
|
|
2838
2838
|
}
|
|
2839
2839
|
}),
|
|
2840
2840
|
]);
|
|
2841
2841
|
}
|
|
2842
2842
|
}
|
|
2843
2843
|
|
|
2844
2844
|
createJdAndroidRquestEventForTouchStart() {
|
|
2845
2845
|
if (isJdAndAndroidDevice && window?.JdAndroid) {
|
|
2846
2846
|
const rootEleNode = document.querySelector('body');
|
|
2847
2847
|
if (rootEleNode) {
|
|
2848
2848
|
rootEleNode.addEventListener('touchstart', this.jdAndroidAddEventListenerTouchStart, false);
|
|
2849
2849
|
}
|
|
2850
2850
|
}
|
|
2851
2851
|
}
|
|
2852
2852
|
jdAndroidAddEventListenerTouchStart(e) {
|
|
2853
2853
|
const isH5SwiperCustomEle = e?.target?.closest('.J_h5SwiperCustom');
|
|
2854
2854
|
if (!isH5SwiperCustomEle && window?.JdAndroid) {
|
|
2855
2855
|
const hasCustomEle = e
|
|
2856
2856
|
? e?.target?.closest('.J_customScroll') || e?.target?.closest('.J_customLayout')
|
|
2857
2857
|
: false;
|
|
2858
2858
|
if (!hasCustomEle) {
|
|
2859
2859
|
window?.JdAndroid?.requestEvent && window.JdAndroid.requestEvent(false);
|
|
2860
2860
|
console.log(
|
|
2861
2861
|
'createJdAndroidRquestEvent 所有松果安卓APP内的document touch start事件执行检测requestEvent并重置为false',
|
|
2862
2862
|
);
|
|
2863
2863
|
}
|
|
2864
2864
|
}
|
|
2865
2865
|
}
|
|
2866
2866
|
removeJdAndroidRquestEventForTouchStart() {
|
|
2867
2867
|
if (isJdAndAndroidDevice && window.JdAndroid) {
|
|
2868
2868
|
const rootEleNode = document.querySelector('body');
|
|
2869
2869
|
if (rootEleNode) {
|
|
2870
2870
|
rootEleNode.removeEventListener(
|
|
2871
2871
|
'touchstart',
|
|
2872
2872
|
this.jdAndroidAddEventListenerTouchStart,
|
|
2873
2873
|
false,
|
|
2874
2874
|
);
|
|
2875
2875
|
}
|
|
2876
2876
|
}
|
|
2877
2877
|
}
|
|
2878
2878
|
|
|
2879
2879
|
getNetWorkType() {
|
|
2880
2880
|
if (isJdApp) {
|
|
2881
2881
|
this.jmfeReayPromise().then(() => {
|
|
2882
2882
|
window.jmfe
|
|
2883
2883
|
.getNetworkStatus()
|
|
2884
2884
|
.then(({ status, data }) => {
|
|
2885
2885
|
console.log('在app内初始化通过jmfe对象获取网络状态完成,当前网络状态====', data);
|
|
2886
2886
|
if (status === '0') {
|
|
2887
2887
|
this.info.sysInfo['netWorkType'] = data;
|
|
2888
2888
|
} else {
|
|
2889
2889
|
this._taroGetNetworkType();
|
|
2890
2890
|
}
|
|
2891
2891
|
})
|
|
2892
2892
|
.catch((err) => {
|
|
2893
2893
|
console.log('在app内初始化通过jmfe对象获取网络状态异常====', err);
|
|
2894
2894
|
this._taroGetNetworkType();
|
|
2895
2895
|
});
|
|
2896
2896
|
});
|
|
2897
2897
|
} else {
|
|
2898
2898
|
this._taroGetNetworkType();
|
|
2899
2899
|
}
|
|
2900
2900
|
}
|
|
2901
2901
|
_taroGetNetworkType() {
|
|
2902
2902
|
Taro.getNetworkType().then((getRes) => {
|
|
2903
2903
|
if (getRes && getRes.networkType) {
|
|
2904
2904
|
this.info.sysInfo['netWorkType'] = getRes.networkType;
|
|
2905
2905
|
console.log(
|
|
2906
2906
|
'在app内通过taro对象获取网络状态完成,当前网络状态',
|
|
2907
2907
|
this.info.sysInfo['netWorkType'],
|
|
2908
2908
|
);
|
|
2909
2909
|
}
|
|
2910
2910
|
});
|
|
2911
2911
|
}
|
|
2912
2912
|
|
|
2913
2913
|
getJdAppBaseInfo(){
|
|
2914
2914
|
const appKeyCacheToCookieMinuteTime = window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0,
|
|
2915
2915
|
appUuidCacheToCookieMinuteTime = window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0,
|
|
2916
2916
|
getAppKey = cookie.get(cacheAppKey),getAppUuidKey = cookie.get(cacheAppUuidKey);
|
|
2917
2917
|
console.log("在app内初始化优先通过cookie获取api请求参数集合baseApiKeyParam",cacheAppKey,getAppKey,cacheAppUuidKey,getAppUuidKey)
|
|
2918
2918
|
if(appKeyCacheToCookieMinuteTime && appUuidCacheToCookieMinuteTime && getAppKey && getAppUuidKey){
|
|
2919
2919
|
const [ uuid, eufv] = getAppUuidKey.split("@")
|
|
2920
2920
|
const baseApiKeyParam = {
|
|
2921
2921
|
uuid,
|
|
2922
2922
|
}
|
|
2923
2923
|
getAppKey !== "-1000" && (baseApiKeyParam['x_app_key'] = getAppKey)
|
|
2924
2924
|
if(eufv === "1" && /-/.test(uuid)){
|
|
2925
2925
|
const [eu, fv] = uuid.split('-');
|
|
2926
2926
|
baseApiKeyParam['eu'] = eu;
|
|
2927
2927
|
baseApiKeyParam['fv'] = fv;
|
|
2928
2928
|
}
|
|
2929
2929
|
this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam
|
|
2930
2930
|
this.jmfeReayPromise().then(() => {
|
|
2931
2931
|
console.log("在app内初始化通过cookie获取api请求参数集合baseApiKeyParam",baseApiKeyParam)
|
|
2932
2932
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam)
|
|
2933
2933
|
})
|
|
2934
2934
|
}else {
|
|
2935
2935
|
const checkGetJdAppKeyState = window?.shopGlobalSwitch?.getJdAppKeyVersion && jdAppVersionCompare(window?.shopGlobalSwitch?.getJdAppKeyVersion) >= 0
|
|
2936
2936
|
this.jmfeReayPromise().then(() => {
|
|
2937
2937
|
Promise.all([
|
|
2938
2938
|
checkGetJdAppKeyState && window.jmfe?.callNative ? window.jmfe.callNative('SwitchQueryPlugin', 'getAppKey', {}, '0') : Promise.resolve({
|
|
2939
2939
|
status: "-1000",
|
|
2940
2940
|
msg: "当前版本不支持获取松果app中的getAppKey",
|
|
2941
2941
|
data: "-1000"
|
|
2942
2942
|
}),
|
|
2943
2943
|
window.jmfe.getDeviceInfo()
|
|
2944
2944
|
]).then(resList => {
|
|
2945
2945
|
const [getAppKeyRes, deviceInfoRes] = resList;
|
|
2946
2946
|
console.log("在app内初始化通过jmfe获取getAppKey结果", getAppKeyRes, "通过jmfe获取getDeviceInfo获取结果", deviceInfoRes)
|
|
2947
2947
|
const baseApiKeyParam = {}
|
|
2948
2948
|
if (["0","-1000"].includes(getAppKeyRes?.status) && getAppKeyRes?.data) {
|
|
2949
2949
|
const getJmfeAppKey = getAppKeyRes?.data
|
|
2950
2950
|
if(getJmfeAppKey && getJmfeAppKey !== ""){
|
|
2951
2951
|
getJmfeAppKey !== "-1000" && (baseApiKeyParam['x_app_key'] = getJmfeAppKey);
|
|
2952
2952
|
const getJdAppKeyCacheToCookieMinuteTime = (window?.shopGlobalSwitch?.appKeyCacheToCookieMinuteTime || 0) * 60 * 1000;
|
|
2953
2953
|
if(getJdAppKeyCacheToCookieMinuteTime){
|
|
2954
2954
|
const expires = new Date(Date.now() + getJdAppKeyCacheToCookieMinuteTime);
|
|
2955
2955
|
cookie.set(cacheAppKey, getJmfeAppKey, {
|
|
2956
2956
|
path: '/',
|
|
2957
2957
|
expires,
|
|
2958
2958
|
})
|
|
2959
2959
|
}
|
|
2960
2960
|
}
|
|
2961
2961
|
}
|
|
2962
2962
|
if (deviceInfoRes?.status === "0" && deviceInfoRes?.data) {
|
|
2963
2963
|
const { uuid, eufv = "0", networkType } = deviceInfoRes?.data
|
|
2964
2964
|
if( uuid && uuid !== "" ){
|
|
2965
2965
|
networkType && (this.info.sysInfo['netWorkType'] = networkType);
|
|
2966
2966
|
baseApiKeyParam['uuid'] = uuid;
|
|
2967
2967
|
if (eufv === "1" && /-/.test(uuid)) {
|
|
2968
2968
|
const [eu, fv] = uuid.split('-');
|
|
2969
2969
|
baseApiKeyParam['eu'] = eu;
|
|
2970
2970
|
baseApiKeyParam['fv'] = fv;
|
|
2971
2971
|
}
|
|
2972
2972
|
const getAppUuidCacheToCookieMinuteTime = (window?.shopGlobalSwitch?.appUuidCacheToCookieMinuteTime || 0) * 60 * 1000;
|
|
2973
2973
|
if(getAppUuidCacheToCookieMinuteTime){
|
|
2974
2974
|
const expires = new Date(Date.now() + getAppUuidCacheToCookieMinuteTime);
|
|
2975
2975
|
cookie.set(cacheAppUuidKey, `${uuid}@${eufv}`, {
|
|
2976
2976
|
path: '/',
|
|
2977
2977
|
expires,
|
|
2978
2978
|
})
|
|
2979
2979
|
}
|
|
2980
2980
|
}
|
|
2981
2981
|
}
|
|
2982
2982
|
console.log("在app内初始化通过jmfe需要更新的基础api请求参数集合baseApiKeyParam", baseApiKeyParam)
|
|
2983
2983
|
if(Object.keys(baseApiKeyParam).length > 0){
|
|
2984
2984
|
this.info.sysInfo['baseApiKeyParam'] = baseApiKeyParam
|
|
2985
2985
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, baseApiKeyParam);
|
|
2986
2986
|
}
|
|
2987
2987
|
})
|
|
2988
2988
|
})
|
|
2989
2989
|
}
|
|
2990
2990
|
}
|
|
2991
2991
|
|
|
2992
2992
|
getCacheAddressRouter() {
|
|
2993
2993
|
if (isJdApp) {
|
|
2994
2994
|
if (!isJdAndHarmonyDevice) {
|
|
2995
2995
|
return Promise.race([
|
|
2996
2996
|
new Promise((resolve) => {
|
|
2997
2997
|
const getCallBackName = `getJdCacheAddress${Date.now()}`;
|
|
2998
2998
|
if (!window[getCallBackName]) {
|
|
2999
2999
|
window[getCallBackName] = (res) => {
|
|
3000
3000
|
console.warn(`获取松果appGetJdCacheAddressRes,返回结果`, res);
|
|
3001
3001
|
try {
|
|
3002
3002
|
const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
|
|
3003
3003
|
resolve(getResJson);
|
|
3004
3004
|
} catch (e) {
|
|
3005
3005
|
resolve({
|
|
3006
3006
|
status: '-1002',
|
|
3007
3007
|
msg: '地址信息解析json异常',
|
|
3008
3008
|
res,
|
|
3009
3009
|
});
|
|
3010
3010
|
}
|
|
3011
3011
|
window[getCallBackName] = null;
|
|
3012
3012
|
};
|
|
3013
3013
|
}
|
|
3014
3014
|
const getRouterParam = {
|
|
3015
3015
|
sceneId: 'basicShoppingProcess',
|
|
3016
3016
|
};
|
|
3017
3017
|
if (isAndroidDevice) {
|
|
3018
3018
|
return callRouterAndroid({
|
|
3019
3019
|
routerURL: 'router://JDAddressModule/getCacheAddress',
|
|
3020
3020
|
routerParam: getRouterParam,
|
|
3021
3021
|
callBackName: getCallBackName,
|
|
3022
3022
|
isSync: true,
|
|
3023
3023
|
});
|
|
3024
3024
|
} else {
|
|
3025
3025
|
return callRouterIOS({
|
|
3026
3026
|
routerURL: 'router://JDBAddressCacheManagerModule/getCacheAddress',
|
|
3027
3027
|
routerParam: getRouterParam,
|
|
3028
3028
|
callBackName: getCallBackName,
|
|
3029
3029
|
});
|
|
3030
3030
|
}
|
|
3031
3031
|
}),
|
|
3032
3032
|
this.taskTimeoutPromise(() => {
|
|
3033
3033
|
return {
|
|
3034
3034
|
status: '-1000',
|
|
3035
3035
|
msg: '原生router协议获取地址信息超时',
|
|
3036
3036
|
};
|
|
3037
3037
|
}, 3000),
|
|
3038
3038
|
]);
|
|
3039
3039
|
} else {
|
|
3040
3040
|
return Promise.race([
|
|
3041
3041
|
new Promise((resolve) => {
|
|
3042
3042
|
this.jmfeReayPromise()
|
|
3043
3043
|
.then(() => {
|
|
3044
3044
|
const plugin = 'JDHybridRouterPlugin';
|
|
3045
3045
|
const action = 'callSyncRouterModuleWithParams';
|
|
3046
3046
|
const params = {
|
|
3047
3047
|
routerURL: 'router://JDAddressCacheModule/getAddressCache?sceneId=1',
|
|
3048
3048
|
routerParam: '',
|
|
3049
3049
|
};
|
|
3050
3050
|
const sync = '1';
|
|
3051
3051
|
try {
|
|
3052
3052
|
window.jmfe.callNative(plugin, action, params, sync).then((res) => {
|
|
3053
3053
|
resolve(res);
|
|
3054
3054
|
});
|
|
3055
3055
|
} catch (error) {
|
|
3056
3056
|
resolve({
|
|
3057
3057
|
status: '-1001',
|
|
3058
3058
|
msg: '判断jmfe不存在,获取经纬度信息异常',
|
|
3059
3059
|
});
|
|
3060
3060
|
}
|
|
3061
3061
|
})
|
|
3062
3062
|
.catch(() => {
|
|
3063
3063
|
resolve({
|
|
3064
3064
|
status: '-1002',
|
|
3065
3065
|
msg: '鸿蒙系统调用jmfe异常,获取失败',
|
|
3066
3066
|
});
|
|
3067
3067
|
});
|
|
3068
3068
|
}),
|
|
3069
3069
|
this.taskTimeoutPromise(() => {
|
|
3070
3070
|
return {
|
|
3071
3071
|
status: '-1000',
|
|
3072
3072
|
msg: '原生router协议获取地址信息超时',
|
|
3073
3073
|
};
|
|
3074
3074
|
}, 3000),
|
|
3075
3075
|
]);
|
|
3076
3076
|
}
|
|
3077
3077
|
} else if (isH5AndJingGouMini) {
|
|
3078
3078
|
return Promise.resolve({
|
|
3079
3079
|
status: '-1002',
|
|
3080
3080
|
msg: '普通h5暂无业务需要,未实现,获取失败',
|
|
3081
3081
|
});
|
|
3082
3082
|
} else {
|
|
3083
3083
|
return Promise.resolve({
|
|
3084
3084
|
status: '-1002',
|
|
3085
3085
|
msg: '普通h5暂无业务需要,未实现,获取失败',
|
|
3086
3086
|
});
|
|
3087
3087
|
}
|
|
3088
3088
|
}
|
|
3089
3089
|
|
|
3090
3090
|
getAddressCachePromise() {
|
|
3091
3091
|
return new Promise((resolve) => {
|
|
3092
3092
|
if (this?.info?.sysInfo?.lat && this?.info?.sysInfo?.lng && this?.info?.sysInfo?.area) {
|
|
3093
3093
|
resolve({
|
|
3094
3094
|
lat: this.info.sysInfo.lat,
|
|
3095
3095
|
lng: this.info.sysInfo.lng,
|
|
3096
3096
|
area: this?.info?.sysInfo?.area,
|
|
3097
3097
|
});
|
|
3098
3098
|
} else {
|
|
3099
3099
|
this.getCacheAddressRouter()
|
|
3100
3100
|
.then((res) => {
|
|
3101
3101
|
const { status, data } = res;
|
|
3102
3102
|
console.log('原生端获取经纬度及四级地址原始数据结果', status, data, res);
|
|
3103
3103
|
if (status === '0' && data) {
|
|
3104
3104
|
const { lat, latitude, lng, longitude, provinceId, cityId, countyId, townId } =
|
|
3105
3105
|
data || {};
|
|
3106
3106
|
let area = '';
|
|
3107
3107
|
this.info.sysInfo['lat'] = `${lat || latitude || ''}`;
|
|
3108
3108
|
this.info.sysInfo['lng'] = `${lng || longitude || ''}`;
|
|
3109
3109
|
const getProvinceIdNum = provinceId ? Number(provinceId) : 0;
|
|
3110
3110
|
if (getProvinceIdNum && getProvinceIdNum > 0) {
|
|
3111
3111
|
area = `${provinceId}_${cityId || 0}_${countyId || 0}_${townId || 0}`;
|
|
3112
3112
|
this.info.pageInfo['address'] = area;
|
|
3113
3113
|
this.info.pageInfo['addressCommaStr'] = area.replace(/_/g, ',');
|
|
3114
3114
|
this.info.sysInfo['area'] = area;
|
|
3115
3115
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
|
|
3116
3116
|
area: this.info.pageInfo.address,
|
|
3117
3117
|
});
|
|
3118
3118
|
}
|
|
3119
3119
|
resolve({
|
|
3120
3120
|
lat: this.info.sysInfo['lat'],
|
|
3121
3121
|
lng: this.info.sysInfo['lng'],
|
|
3122
3122
|
area: area,
|
|
3123
3123
|
});
|
|
3124
3124
|
} else {
|
|
3125
3125
|
if (typeof res === 'object') {
|
|
3126
3126
|
draBusinessCustomReport({
|
|
3127
3127
|
eventName: 'business',
|
|
3128
3128
|
errorName: 'jdapp_getCacheAddress_info_err',
|
|
3129
3129
|
errorMessage: '松果app内通过router协议获取用户地址及经纬度信息异常',
|
|
3130
3130
|
extraData: JSON.stringify({
|
|
3131
3131
|
isJdApp,
|
|
3132
3132
|
jdAppVersion: jdAppVersionStr,
|
|
3133
3133
|
...res,
|
|
3134
3134
|
}),
|
|
3135
3135
|
});
|
|
3136
3136
|
}
|
|
3137
3137
|
resolve({ lat: '', lng: '', area: '' });
|
|
3138
3138
|
}
|
|
3139
3139
|
})
|
|
3140
3140
|
.catch((e) => {
|
|
3141
3141
|
console.log('getCacheAddressRouter catch e,获取经纬度信息异常e', e);
|
|
3142
3142
|
draBusinessCustomReport({
|
|
3143
3143
|
eventName: 'business',
|
|
3144
3144
|
errorName: 'jdapp_getCacheAddress_info_catch_err',
|
|
3145
3145
|
errorMessage: '松果app内通过router协议获取用户地址及经纬度信息catch异常',
|
|
3146
3146
|
extraData: JSON.stringify({
|
|
3147
3147
|
isJdApp,
|
|
3148
3148
|
jdAppVersion: jdAppVersionStr,
|
|
3149
3149
|
}),
|
|
3150
3150
|
});
|
|
3151
3151
|
resolve({ lat: '', lng: '', area: '' });
|
|
3152
3152
|
});
|
|
3153
3153
|
}
|
|
3154
3154
|
});
|
|
3155
3155
|
}
|
|
3156
3156
|
|
|
3157
3157
|
getLbsCacheAddressRouter() {
|
|
3158
3158
|
if (isJdApp) {
|
|
3159
3159
|
if (!isJdAndHarmonyDevice) {
|
|
3160
3160
|
return Promise.race([
|
|
3161
3161
|
new Promise((resolve) => {
|
|
3162
3162
|
const getCallBackName = `getJdLbsCacheAddress${Date.now()}`;
|
|
3163
3163
|
if (!window[getCallBackName]) {
|
|
3164
3164
|
window[getCallBackName] = (res) => {
|
|
3165
3165
|
console.warn(`获取松果appGetJdLbsCacheAddressRes,返回结果`, res);
|
|
3166
3166
|
try {
|
|
3167
3167
|
const getResJson = typeof res === 'string' ? JSON.parse(res) : res;
|
|
3168
3168
|
resolve(getResJson);
|
|
3169
3169
|
} catch (e) {
|
|
3170
3170
|
resolve({
|
|
3171
3171
|
status: '-1002',
|
|
3172
3172
|
msg: '地址信息解析json异常',
|
|
3173
3173
|
res,
|
|
3174
3174
|
});
|
|
3175
3175
|
}
|
|
3176
3176
|
window[getCallBackName] = null;
|
|
3177
3177
|
};
|
|
3178
3178
|
}
|
|
3179
3179
|
const getRouterParam = {
|
|
3180
3180
|
appid: '219f70bbbf7e4ede7968bedaa1beafb4',
|
|
3181
3181
|
sceneId: 'basicShoppingProcess',
|
|
3182
3182
|
};
|
|
3183
3183
|
if (isAndroidDevice) {
|
|
3184
3184
|
return callRouterAndroid({
|
|
3185
3185
|
routerURL: 'router://com.jingdong.app.mall.location.JSLocationManager/getLocation',
|
|
3186
3186
|
routerParam: getRouterParam,
|
|
3187
3187
|
callBackName: getCallBackName,
|
|
3188
3188
|
isSync: true,
|
|
3189
3189
|
hasJdRouter: false,
|
|
3190
3190
|
});
|
|
3191
3191
|
} else {
|
|
3192
3192
|
return callRouterIOS({
|
|
3193
3193
|
routerURL: 'router://JDBLBSKitModule/getCacheAddressInfo',
|
|
3194
3194
|
routerParam: getRouterParam,
|
|
3195
3195
|
callBackName: getCallBackName,
|
|
3196
3196
|
isSync: true,
|
|
3197
3197
|
});
|
|
3198
3198
|
}
|
|
3199
3199
|
}),
|
|
3200
3200
|
this.taskTimeoutPromise(() => {
|
|
3201
3201
|
return {
|
|
3202
3202
|
status: '-1000',
|
|
3203
3203
|
msg: '原生router协议获取lbs地址信息3s超时',
|
|
3204
3204
|
};
|
|
3205
3205
|
}, 3000),
|
|
3206
3206
|
]);
|
|
3207
3207
|
} else {
|
|
3208
3208
|
return Promise.resolve({
|
|
3209
3209
|
status: '-1001',
|
|
3210
3210
|
msg: '鸿蒙系统调用未实现,获取失败',
|
|
3211
3211
|
});
|
|
3212
3212
|
}
|
|
3213
3213
|
} else if (isH5AndJingGouMini) {
|
|
3214
3214
|
return this.getLocationForGpsPromise();
|
|
3215
3215
|
} else {
|
|
3216
3216
|
return Promise.resolve({
|
|
3217
3217
|
status: '-1002',
|
|
3218
3218
|
msg: '普通h5暂无业务需要,未实现,获取失败',
|
|
3219
3219
|
});
|
|
3220
3220
|
}
|
|
3221
3221
|
}
|
|
3222
3222
|
getLocationForGpsPromise() {
|
|
3223
3223
|
return new Promise((resolve) => {
|
|
3224
3224
|
let hasGetLocationForGps = true;
|
|
3225
3225
|
if (urlCookie && urlCookie['loc']) {
|
|
3226
3226
|
const [provinceid = 0, cityid = 0, districtid = 0, townid = 0] =
|
|
3227
3227
|
urlCookie['loc'].split('_');
|
|
3228
3228
|
const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
|
|
3229
3229
|
if (getProvinceIdNum && getProvinceIdNum > 0) {
|
|
3230
3230
|
hasGetLocationForGps = false;
|
|
3231
3231
|
resolve({
|
|
3232
3232
|
status: '0',
|
|
3233
3233
|
data: {
|
|
3234
3234
|
provinceid,
|
|
3235
3235
|
cityid,
|
|
3236
3236
|
districtid,
|
|
3237
3237
|
townid,
|
|
3238
3238
|
origin: 'wxapp',
|
|
3239
3239
|
},
|
|
3240
3240
|
});
|
|
3241
3241
|
}
|
|
3242
3242
|
}
|
|
3243
3243
|
if (hasGetLocationForGps && window?.navigator?.geolocation) {
|
|
3244
3244
|
window.navigator.geolocation.getCurrentPosition(
|
|
3245
3245
|
(position) => {
|
|
3246
3246
|
console.log('h5 浏览器通过原生geolocation获取经纬度结果', position?.coords);
|
|
3247
3247
|
if (position?.coords) {
|
|
3248
3248
|
resolve({
|
|
3249
3249
|
status: '0',
|
|
3250
3250
|
data: {
|
|
3251
3251
|
srclat: position.coords?.latitude,
|
|
3252
3252
|
srclng: position.coords.longitude,
|
|
3253
3253
|
origin: 'h5',
|
|
3254
3254
|
},
|
|
3255
3255
|
});
|
|
3256
3256
|
} else {
|
|
3257
3257
|
resolve({
|
|
3258
3258
|
status: '-1001',
|
|
3259
3259
|
msg: 'h5 浏览器通过原生geolocation获取经纬度结果异常,详情见position',
|
|
3260
3260
|
position,
|
|
3261
3261
|
});
|
|
3262
3262
|
}
|
|
3263
3263
|
},
|
|
3264
3264
|
(error) => {
|
|
3265
3265
|
resolve({
|
|
3266
3266
|
status: '-1001',
|
|
3267
3267
|
msg: 'h5 浏览器通过原生geolocation获取经纬度结果定位异常,详情见error',
|
|
3268
3268
|
error,
|
|
3269
3269
|
});
|
|
3270
3270
|
},
|
|
3271
3271
|
{
|
|
3272
3272
|
enableHighAccuracy: false,
|
|
3273
3273
|
timeout: 3 * 1000,
|
|
3274
3274
|
maximumAge: 10 * 60 * 1000,
|
|
3275
3275
|
},
|
|
3276
3276
|
);
|
|
3277
3277
|
} else {
|
|
3278
3278
|
resolve({
|
|
3279
3279
|
status: '-1001',
|
|
3280
3280
|
msg: '您的浏览器不支持地理定位',
|
|
3281
3281
|
});
|
|
3282
3282
|
}
|
|
3283
3283
|
});
|
|
3284
3284
|
}
|
|
3285
3285
|
|
|
3286
3286
|
createLbsCacheAddress(realTimeArea) {
|
|
3287
3287
|
const getLbsAddressCacheMinuteTime = Number(
|
|
3288
3288
|
window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime || 0,
|
|
3289
3289
|
);
|
|
3290
3290
|
console.log(
|
|
3291
3291
|
'获取lbs缓存到cookie的时间,分钟',
|
|
3292
3292
|
getLbsAddressCacheMinuteTime,
|
|
3293
3293
|
'lbsAddressCacheToCookieMinuteTime',
|
|
3294
3294
|
window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime,
|
|
3295
3295
|
);
|
|
3296
3296
|
if (getLbsAddressCacheMinuteTime > 0) {
|
|
3297
3297
|
const expires = new Date(Date.now() + getLbsAddressCacheMinuteTime * 60 * 1000);
|
|
3298
3298
|
realTimeArea &&
|
|
3299
3299
|
cookie.set(cacheH5LbsAddressKey, realTimeArea, {
|
|
3300
3300
|
path: '/',
|
|
3301
3301
|
expires,
|
|
3302
3302
|
});
|
|
3303
3303
|
}
|
|
3304
3304
|
}
|
|
3305
3305
|
|
|
3306
3306
|
getLbsAddressCachePromise() {
|
|
3307
3307
|
if (!this.lbsAddressCachePromise) {
|
|
3308
3308
|
this.lbsAddressCachePromise = new Promise((resolve) => {
|
|
3309
3309
|
const getCookieForLbsAddress = window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime
|
|
3310
3310
|
? cookie.get(cacheH5LbsAddressKey)
|
|
3311
3311
|
: '';
|
|
3312
3312
|
const getUserLbsAddress = this?.info?.pageInfo?.userLbsAddress;
|
|
3313
3313
|
if (getUserLbsAddress && getUserLbsAddress !== '') {
|
|
3314
3314
|
resolve({
|
|
3315
3315
|
ok: true,
|
|
3316
3316
|
realTimeArea: getUserLbsAddress,
|
|
3317
3317
|
});
|
|
3318
3318
|
} else if (getCookieForLbsAddress && getCookieForLbsAddress !== '') {
|
|
3319
3319
|
console.info(
|
|
3320
3320
|
`通过cookie获取缓存的userLbsAddress,${window?.shopGlobalSwitch?.lbsAddressCacheToCookieMinuteTime}分钟内有效`,
|
|
3321
3321
|
getCookieForLbsAddress,
|
|
3322
3322
|
);
|
|
3323
3323
|
this.info.pageInfo['userLbsAddress'] = getCookieForLbsAddress;
|
|
3324
3324
|
this.info.sysInfo['realTimeArea'] = getCookieForLbsAddress;
|
|
3325
3325
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
|
|
3326
3326
|
realTimeArea: getCookieForLbsAddress,
|
|
3327
3327
|
});
|
|
3328
3328
|
resolve({
|
|
3329
3329
|
ok: true,
|
|
3330
3330
|
realTimeArea: getCookieForLbsAddress,
|
|
3331
3331
|
});
|
|
3332
3332
|
} else {
|
|
3333
3333
|
this.getLbsCacheAddressRouter()
|
|
3334
3334
|
.then((res) => {
|
|
3335
3335
|
const { status, data } = res;
|
|
3336
3336
|
console.log(
|
|
3337
3337
|
'原生或者内嵌京购端获取基于lbs的经纬度及四级地址原始数据结果',
|
|
3338
3338
|
status,
|
|
3339
3339
|
data,
|
|
3340
3340
|
res,
|
|
3341
3341
|
);
|
|
3342
3342
|
if (status === '0' && data) {
|
|
3343
3343
|
const { srclat, srclng, provinceid, cityid, districtid, townid, origin } =
|
|
3344
3344
|
data || {};
|
|
3345
3345
|
let realTimeArea = '';
|
|
3346
3346
|
this.info.sysInfo['srclat'] = `${srclat || ''}`;
|
|
3347
3347
|
this.info.sysInfo['srclng'] = `${srclng || ''}`;
|
|
3348
3348
|
const getProvinceIdNum = provinceid ? Number(provinceid) : 0;
|
|
3349
3349
|
if (getProvinceIdNum && getProvinceIdNum > 0) {
|
|
3350
3350
|
realTimeArea = `${provinceid}_${cityid || 0}_${districtid || 0}_${townid || 0}`;
|
|
3351
3351
|
this.info.pageInfo['userLbsAddress'] = realTimeArea;
|
|
3352
3352
|
this.info.sysInfo['realTimeArea'] = realTimeArea;
|
|
3353
3353
|
Taro.eventCenter.trigger(TaroEventType.USER_AREA_UPDATE, {
|
|
3354
3354
|
realTimeArea: this.info.pageInfo.userLbsAddress,
|
|
3355
3355
|
});
|
|
3356
3356
|
this.createLbsCacheAddress(realTimeArea);
|
|
3357
3357
|
} else {
|
|
3358
3358
|
!origin && (this.lbsAddressCachePromise = null);
|
|
3359
3359
|
}
|
|
3360
3360
|
const getValidRealTimeArea = realTimeArea !== '';
|
|
3361
3361
|
resolve({
|
|
3362
3362
|
lat: this.info.sysInfo['srclat'],
|
|
3363
3363
|
lng: this.info.sysInfo['srclng'],
|
|
3364
3364
|
realTimeArea: realTimeArea,
|
|
3365
3365
|
ok: getValidRealTimeArea,
|
|
3366
3366
|
msg: getValidRealTimeArea
|
|
3367
3367
|
? '成功'
|
|
3368
3368
|
: origin
|
|
3369
3369
|
? origin
|
|
3370
3370
|
: '根据router底层获取lbs地址信息异常,详情见data',
|
|
3371
3371
|
data: getValidRealTimeArea ? null : res,
|
|
3372
3372
|
});
|
|
3373
3373
|
if (!getValidRealTimeArea && !origin) {
|
|
3374
3374
|
draBusinessCustomReport({
|
|
3375
3375
|
eventName: 'business',
|
|
3376
3376
|
errorName: 'h5_getLbsCacheAddress_info_err',
|
|
3377
3377
|
errorMessage: '松果app内通过router协议获取基于lbs实时用户地址及经纬度信息catch异常',
|
|
3378
3378
|
extraData: JSON.stringify({
|
|
3379
3379
|
isJdApp,
|
|
3380
3380
|
jdAppVersion: jdAppVersionStr,
|
|
3381
3381
|
}),
|
|
3382
3382
|
});
|
|
3383
3383
|
}
|
|
3384
3384
|
} else {
|
|
3385
3385
|
typeof res === 'object' &&
|
|
3386
3386
|
draBusinessCustomReport({
|
|
3387
3387
|
eventName: 'business',
|
|
3388
3388
|
errorName: 'h5_getLbsCacheAddress_info_err',
|
|
3389
3389
|
errorMessage: 'h5通过router协议或者浏览器gps获取基于lbs实时用户缓存地址及经纬度信息异常',
|
|
3390
3390
|
extraData: JSON.stringify({
|
|
3391
3391
|
isJdApp,
|
|
3392
3392
|
jdAppVersion: jdAppVersionStr,
|
|
3393
3393
|
...res,
|
|
3394
3394
|
}),
|
|
3395
3395
|
});
|
|
3396
3396
|
this.lbsAddressCachePromise = null;
|
|
3397
3397
|
resolve({ realTimeArea: '', ok: false });
|
|
3398
3398
|
}
|
|
3399
3399
|
})
|
|
3400
3400
|
.catch((e) => {
|
|
3401
3401
|
console.log('getLbsAddressCachePromise catch e,获取经纬度信息异常e', e);
|
|
3402
3402
|
this.lbsAddressCachePromise = null;
|
|
3403
3403
|
draBusinessCustomReport({
|
|
3404
3404
|
eventName: 'business',
|
|
3405
3405
|
errorName: 'h5_getLbsCacheAddress_info_err',
|
|
3406
3406
|
errorMessage: 'h5内通过router协议获取浏览器gps获取基于lbs实时用户地址及经纬度信息catch异常',
|
|
3407
3407
|
extraData: JSON.stringify({
|
|
3408
3408
|
isJdApp,
|
|
3409
3409
|
jdAppVersion: jdAppVersionStr,
|
|
3410
3410
|
}),
|
|
3411
3411
|
});
|
|
3412
3412
|
resolve({ realTimeArea: '', ok: false });
|
|
3413
3413
|
});
|
|
3414
3414
|
}
|
|
3415
3415
|
});
|
|
3416
3416
|
}
|
|
3417
3417
|
return this.lbsAddressCachePromise;
|
|
3418
3418
|
}
|
|
3419
3419
|
|
|
3420
3420
|
async updateMPaasConfigAsync(isBeforePageReady: boolean) {
|
|
3421
3421
|
console.log('updateMPaasConfigAsync isBeforePageReady:', isBeforePageReady);
|
|
3422
3422
|
if (!isJdApp) {
|
|
3423
3423
|
return;
|
|
3424
3424
|
}
|
|
3425
3425
|
const avifSwitch = await getMPaasConfigByBussinessKey('avifSwitch', isBeforePageReady);
|
|
3426
3426
|
this.info.sysInfo.dynamicConfig['avifSwitch'] = avifSwitch;
|
|
3427
3427
|
const hybridHttpSwitch = await getMPaasConfigByBussinessKey(
|
|
3428
3428
|
'hybridHttpSwitch',
|
|
3429
3429
|
isBeforePageReady,
|
|
3430
3430
|
);
|
|
3431
3431
|
const jshopIsVipShopSwitch = await getMPaasConfigByBussinessKey(
|
|
3432
3432
|
'jshopIsVipShop',
|
|
3433
3433
|
isBeforePageReady,
|
|
3434
3434
|
);
|
|
3435
3435
|
this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = hybridHttpSwitch;
|
|
3436
3436
|
this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = jshopIsVipShopSwitch;
|
|
3437
3437
|
const isFollowAppVideoPlayStatus = await getMPaasConfigByBussinessKey(
|
|
3438
3438
|
'isFollowAppVideoPlayStatus',
|
|
3439
3439
|
isBeforePageReady,
|
|
3440
3440
|
);
|
|
3441
3441
|
console.log(
|
|
3442
3442
|
'isBeforePageReady:',
|
|
3443
3443
|
isBeforePageReady,
|
|
3444
3444
|
'isFollowAppVideoPlayStatus:',
|
|
3445
3445
|
isFollowAppVideoPlayStatus,
|
|
3446
3446
|
);
|
|
3447
3447
|
if (isFollowAppVideoPlayStatus === true || isFollowAppVideoPlayStatus === 'true') {
|
|
3448
3448
|
this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = true;
|
|
3449
3449
|
}
|
|
3450
3450
|
}
|
|
3451
3451
|
|
|
3452
3452
|
async getWifiVideoAutoPlayAsync() {
|
|
3453
3453
|
this.info.sysInfo['wifiVideoAutoPlay'] = false;
|
|
3454
3454
|
if (!isJdApp) {
|
|
3455
3455
|
return;
|
|
3456
3456
|
}
|
|
3457
3457
|
const videoPlayStatus = await getWifiVideoAutoPlay().catch((e) => {
|
|
3458
3458
|
return 0;
|
|
3459
3459
|
});
|
|
3460
3460
|
if (Number(videoPlayStatus) === 1) {
|
|
3461
3461
|
this.info.sysInfo['wifiVideoAutoPlay'] = true;
|
|
3462
3462
|
}
|
|
3463
3463
|
}
|
|
3464
3464
|
|
|
3465
3465
|
async getMPaasConfigAsync() {
|
|
3466
3466
|
this.info.sysInfo.dynamicConfig = {};
|
|
3467
3467
|
this.info.sysInfo.dynamicConfig['avifSwitch'] = {};
|
|
3468
3468
|
this.info.sysInfo.dynamicConfig['hybridHttpSwitch'] = {};
|
|
3469
3469
|
this.info.sysInfo.dynamicConfig['jshopIsVipShopSwitch'] = {};
|
|
3470
3470
|
this.info.sysInfo.dynamicConfig['isFollowAppVideoPlayStatus'] = false;
|
|
3471
3471
|
return this.updateMPaasConfigAsync(true);
|
|
3472
3472
|
}
|
|
3473
3473
|
|
|
3474
3474
|
getDynamicConfig(key: string) {
|
|
3475
3475
|
return this.info.sysInfo?.dynamicConfig?.[key];
|
|
3476
3476
|
}
|
|
3477
3477
|
async updateMPaasConfig() {
|
|
3478
3478
|
console.log('updateMPaasConfig');
|
|
3479
3479
|
if (
|
|
3480
3480
|
isIosDevice &&
|
|
3481
3481
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_VERSION) < 0 &&
|
|
3482
3482
|
versionCompare(jdAppVersionStr, MPAAS_CONFIG_APP_LOW_VERSION) >= 0
|
|
3483
3483
|
) {
|
|
3484
3484
|
try {
|
|
3485
3485
|
await this.updateMPaasConfigAsync(false);
|
|
3486
3486
|
} catch (e) {
|
|
3487
3487
|
console.log('updateMPaasConfigAsync:', e);
|
|
3488
3488
|
}
|
|
3489
3489
|
}
|
|
3490
3490
|
}
|
|
3491
3491
|
|
|
3492
3492
|
toLogin(options) {
|
|
3493
3493
|
return this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState
|
|
3494
3494
|
? this.toWxAppLogin(options)
|
|
3495
3495
|
: this.toWebLogin(options);
|
|
3496
3496
|
}
|
|
3497
3497
|
|
|
3498
3498
|
doLogin(options) {
|
|
3499
3499
|
return this.toLogin(options);
|
|
3500
3500
|
}
|
|
3501
3501
|
|
|
3502
3502
|
doLoginForJdPin(options = {}) {
|
|
3503
3503
|
return this.doLogin({
|
|
3504
3504
|
loginColor: {
|
|
3505
3505
|
biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
3506
3506
|
dpin: 0,
|
|
3507
3507
|
},
|
|
3508
3508
|
...options,
|
|
3509
3509
|
});
|
|
3510
3510
|
}
|
|
3511
3511
|
|
|
3512
3512
|
toWebLogin(options) {
|
|
3513
3513
|
let params: {
|
|
3514
3514
|
returnurl: string;
|
|
3515
3515
|
} = {
|
|
3516
3516
|
returnurl: '',
|
|
3517
3517
|
};
|
|
3518
3518
|
const checkToPcLogin = options ? options?.isPc : isPc;
|
|
3519
3519
|
const loginUrl = checkToPcLogin
|
|
3520
3520
|
? `//passport.jd.com/new/login.aspx`
|
|
3521
3521
|
: `${domain.mobileLogin}/user/login.action`;
|
|
3522
3522
|
const defaultParams = {
|
|
3523
3523
|
appid: '100',
|
|
3524
3524
|
returnurl: window.location.href,
|
|
3525
3525
|
};
|
|
3526
3526
|
if (isString(options)) {
|
|
3527
3527
|
params = Object.assign({}, defaultParams, {
|
|
3528
3528
|
returnurl: options,
|
|
3529
3529
|
});
|
|
3530
3530
|
} else if (isObject(options)) {
|
|
3531
3531
|
const { loginColor, ...otherOptions } = options;
|
|
3532
3532
|
params = Object.assign({}, defaultParams, otherOptions);
|
|
3533
3533
|
} else {
|
|
3534
3534
|
params = defaultParams;
|
|
3535
3535
|
}
|
|
3536
3536
|
params.returnurl = encodeURIComponent(params.returnurl);
|
|
3537
3537
|
let getFullUrl = loginUrl + '?' + serialize(params);
|
|
3538
3538
|
if (checkToPcLogin) {
|
|
3539
3539
|
getFullUrl = getFullUrl.replace(/returnurl/, 'ReturnUrl');
|
|
3540
3540
|
}
|
|
3541
3541
|
return Promise.resolve({
|
|
3542
3542
|
h5ToUrl: true,
|
|
3543
3543
|
url: getFullUrl,
|
|
3544
3544
|
}).then(() => {
|
|
3545
3545
|
window.location.href = getFullUrl;
|
|
3546
3546
|
});
|
|
3547
3547
|
}
|
|
3548
3548
|
|
|
3549
3549
|
toWxAppLogin(options = {}) {
|
|
3550
3550
|
console.log('微信京购小程序中h5登录跳转', options);
|
|
3551
3551
|
return Promise.resolve(true).then(() => {
|
|
3552
3552
|
const { loginColor } = Object.assign(
|
|
3553
3553
|
{},
|
|
3554
3554
|
{
|
|
3555
3555
|
loginColor: {
|
|
3556
3556
|
biz: WXAPP_BIZ_KEY,
|
|
3557
3557
|
dpin: 1,
|
|
3558
3558
|
},
|
|
3559
3559
|
},
|
|
3560
3560
|
options,
|
|
3561
3561
|
);
|
|
3562
3562
|
window.location.href = `${domain.wq}/pinbind/pintokenredirect?biz=${loginColor.biz
|
|
3563
3563
|
}&url=${encodeURIComponent(window.location.href)}`;
|
|
3564
3564
|
});
|
|
3565
3565
|
}
|
|
3566
3566
|
|
|
3567
3567
|
getLoginCookie() {
|
|
3568
3568
|
return Promise.resolve({
|
|
3569
3569
|
pin: cookie.get('pin') || '',
|
|
3570
3570
|
});
|
|
3571
3571
|
}
|
|
3572
3572
|
|
|
3573
3573
|
clearLoginCookie() {
|
|
3574
3574
|
cookie.remove('pin');
|
|
3575
3575
|
}
|
|
3576
3576
|
|
|
3577
3577
|
checkStatusAndLogin(options = {}) {
|
|
3578
3578
|
if (!this.checkStatusAndLoginPromise) {
|
|
3579
3579
|
this.checkStatusAndLoginPromise = new Promise(async (resolve, reject) => {
|
|
3580
3580
|
try {
|
|
3581
3581
|
const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
|
|
3582
3582
|
if (getLoginState) {
|
|
3583
3583
|
resolve(true);
|
|
3584
3584
|
} else {
|
|
3585
3585
|
this.toLogin(options);
|
|
3586
3586
|
reject(false);
|
|
3587
3587
|
}
|
|
3588
3588
|
} catch (e) {
|
|
3589
3589
|
this.toLogin(options);
|
|
3590
3590
|
reject(false);
|
|
3591
3591
|
}
|
|
3592
3592
|
});
|
|
3593
3593
|
return this.checkStatusAndLoginPromise;
|
|
3594
3594
|
} else {
|
|
3595
3595
|
return this.checkStatusAndLoginPromise
|
|
3596
3596
|
.then(() => {
|
|
3597
3597
|
return Promise.resolve(true);
|
|
3598
3598
|
})
|
|
3599
3599
|
.catch(() => {
|
|
3600
3600
|
this.toLogin(options);
|
|
3601
3601
|
return Promise.reject(true);
|
|
3602
3602
|
});
|
|
3603
3603
|
}
|
|
3604
3604
|
}
|
|
3605
3605
|
|
|
3606
3606
|
checkJdStatusAndLogin(
|
|
3607
3607
|
options = {
|
|
3608
3608
|
loginColor: {
|
|
3609
3609
|
biz: WXAPP_BIZ_SHOP_LIGHT_KEY,
|
|
3610
3610
|
dpin: 0,
|
|
3611
3611
|
},
|
|
3612
3612
|
},
|
|
3613
3613
|
) {
|
|
3614
3614
|
return this.checkStatusAndLogin(options);
|
|
3615
3615
|
}
|
|
3616
3616
|
|
|
3617
3617
|
doCheckLoginStateAndForApiCheck(options) {
|
|
3618
3618
|
if (this.info.loginState) {
|
|
3619
3619
|
return Promise.resolve(true);
|
|
3620
3620
|
} else {
|
|
3621
3621
|
return new Promise((resolve, reject) => {
|
|
3622
3622
|
if (this.info.isJingGouMiniViewState || this.info.isJingxiMiniViewState) {
|
|
3623
3623
|
const getWqAuthToken = cookie.get('wq_auth_token');
|
|
3624
3624
|
const getWqSkey = cookie.get('wq_skey');
|
|
3625
3625
|
const getWqUin = cookie.get('wq_uin');
|
|
3626
3626
|
const isLoginState =
|
|
3627
3627
|
options?.loginColor?.dpin === 0 ? getWqAuthToken : getWqSkey && getWqUin;
|
|
3628
3628
|
if (isLoginState) {
|
|
3629
3629
|
this.info.loginState = true;
|
|
3630
3630
|
resolve(true);
|
|
3631
3631
|
} else {
|
|
3632
3632
|
reject(false);
|
|
3633
3633
|
}
|
|
3634
3634
|
} else {
|
|
3635
3635
|
Taro.request({
|
|
3636
3636
|
url: api.isLogin,
|
|
3637
3637
|
jsonp: true,
|
|
3638
3638
|
timeout: 3000,
|
|
3639
3639
|
success: (res) => {
|
|
3640
3640
|
const { statusCode, data } = res;
|
|
3641
3641
|
if (statusCode === 200 && data?.islogin && Number(data.islogin) === 1) {
|
|
3642
3642
|
this.info.loginState = true;
|
|
3643
3643
|
resolve(true);
|
|
3644
3644
|
} else {
|
|
3645
3645
|
reject(false);
|
|
3646
3646
|
}
|
|
3647
3647
|
},
|
|
3648
3648
|
fail: (err) => {
|
|
3649
3649
|
console.log('登录检查异常', err);
|
|
3650
3650
|
reject(false);
|
|
3651
3651
|
},
|
|
3652
3652
|
});
|
|
3653
3653
|
}
|
|
3654
3654
|
});
|
|
3655
3655
|
}
|
|
3656
3656
|
}
|
|
3657
3657
|
|
|
3658
3658
|
checkLoginStatus(options) {
|
|
3659
3659
|
return new Promise(async (resolve, reject) => {
|
|
3660
3660
|
try {
|
|
3661
3661
|
const getLoginState = await this.doCheckLoginStateAndForApiCheck(options);
|
|
3662
3662
|
if (getLoginState) {
|
|
3663
3663
|
const { pin } = await this.getLoginCookie();
|
|
3664
3664
|
this.info.userInfo = {
|
|
3665
3665
|
pin,
|
|
3666
3666
|
encodePin: encodeURIComponent(pin),
|
|
3667
3667
|
ptkey: '',
|
|
3668
3668
|
};
|
|
3669
3669
|
resolve(true);
|
|
3670
3670
|
} else {
|
|
3671
3671
|
reject(false);
|
|
3672
3672
|
}
|
|
3673
3673
|
} catch (e) {
|
|
3674
3674
|
reject(false);
|
|
3675
3675
|
}
|
|
3676
3676
|
});
|
|
3677
3677
|
}
|
|
3678
3678
|
|
|
3679
3679
|
updatePageAndLogInfo(updateQuery = {}) {
|
|
3680
3680
|
const createUpdateQueryInfo: {
|
|
3681
3681
|
query: {
|
|
3682
3682
|
shopId?: string | number;
|
|
3683
3683
|
venderId?: string | number;
|
|
3684
3684
|
};
|
|
3685
3685
|
updateShopInfoState: boolean;
|
|
3686
3686
|
} = Object.assign(
|
|
3687
3687
|
{},
|
|
3688
3688
|
{
|
|
3689
3689
|
query: {},
|
|
3690
3690
|
updateShopInfoState: false,
|
|
3691
3691
|
},
|
|
3692
3692
|
updateQuery,
|
|
3693
3693
|
);
|
|
3694
3694
|
console.log(
|
|
3695
3695
|
'获取当前下发的店铺查询参数',
|
|
3696
3696
|
updateQuery,
|
|
3697
3697
|
'获取之前保存的shopInfo店铺查询参数',
|
|
3698
3698
|
this.info?.shopInfo,
|
|
3699
3699
|
);
|
|
3700
3700
|
const { query, updateShopInfoState } = createUpdateQueryInfo;
|
|
3701
3701
|
const { shopId, venderId, un_area } = query;
|
|
3702
3702
|
if (updateShopInfoState) {
|
|
3703
3703
|
this.info.queryInfo = {
|
|
3704
3704
|
...this.info.queryInfo,
|
|
3705
3705
|
...query,
|
|
3706
3706
|
};
|
|
3707
3707
|
if (shopId && venderId) {
|
|
3708
3708
|
this.info.shopInfo = {
|
|
3709
3709
|
shopId: `${shopId}`,
|
|
3710
3710
|
venderId: `${venderId}`,
|
|
3711
3711
|
};
|
|
3712
3712
|
}
|
|
3713
3713
|
} else {
|
|
3714
3714
|
this.info.queryInfo = {
|
|
3715
3715
|
...query,
|
|
3716
3716
|
};
|
|
3717
3717
|
if (
|
|
3718
3718
|
this.info.shopInfo?.shopId &&
|
|
3719
3719
|
this.info.shopInfo?.venderId &&
|
|
3720
3720
|
(this.info.shopInfo.shopId == shopId || this.info.shopInfo.venderId == venderId)
|
|
3721
3721
|
) {
|
|
3722
3722
|
this.info.queryInfo.shopId = this.info.shopInfo.shopId;
|
|
3723
3723
|
this.info.queryInfo.venderId = this.info.shopInfo.venderId;
|
|
3724
3724
|
console.log(
|
|
3725
3725
|
'当前存储的店铺shopId和venderId与下发的店铺信息shopId或者venderId为同一个,补充shopId或者venderId查询参数',
|
|
3726
3726
|
this.info.queryInfo,
|
|
3727
3727
|
);
|
|
3728
3728
|
}
|
|
3729
3729
|
}
|
|
3730
3730
|
this.info.queryInfo['shopId'] &&
|
|
3731
3731
|
(this.info.queryInfo['shopId'] = `${this.info.queryInfo['shopId']}`);
|
|
3732
3732
|
this.info.queryInfo['venderId'] &&
|
|
3733
3733
|
(this.info.queryInfo['venderId'] = `${this.info.queryInfo['venderId']}`);
|
|
3734
3734
|
console.log(
|
|
3735
3735
|
'h5==获取店铺下发查询参数\n',
|
|
3736
3736
|
query,
|
|
3737
3737
|
'\n获取店铺最后查询参数\n',
|
|
3738
3738
|
this.info.queryInfo,
|
|
3739
3739
|
'\n是否为更新店铺状态\n',
|
|
3740
3740
|
updateShopInfoState,
|
|
3741
3741
|
);
|
|
3742
3742
|
const changeArea = un_area && un_area.length > 0 ? un_area : isPc && ipLoc_djd ? ipLoc_djd : '';
|
|
3743
3743
|
if (changeArea) {
|
|
3744
3744
|
const getBottomAreaStr = changeArea.replace(/-/g, '_');
|
|
3745
3745
|
this.info.pageInfo.address = getBottomAreaStr;
|
|
3746
3746
|
this.info.pageInfo.un_area = getBottomAreaStr;
|
|
3747
3747
|
this.info.pageInfo.addressCommaStr = getBottomAreaStr.replace(/_/g, ',');
|
|
3748
3748
|
}
|
|
3749
3749
|
}
|
|
3750
3750
|
|
|
3751
3751
|
dealLoadSdkList() {
|
|
3752
3752
|
const globalLoadJsList = window?.shopGlobalSwitch?.asyncLoadJsList ?? [];
|
|
3753
3753
|
const businessLoadJsList = window?.PAGE_DATA?.businessData?.asyncLoadJsList ?? [];
|
|
3754
3754
|
const concatLoadJsList = [].concat(globalLoadJsList, businessLoadJsList);
|
|
3755
3755
|
let mergeLoadJsList = globalLoadJsList;
|
|
3756
3756
|
try {
|
|
3757
3757
|
mergeLoadJsList = concatLoadJsList.reduce((accArr: any[], current: any) => {
|
|
3758
3758
|
const getFindIndex = accArr.findIndex((item) => item?.fileName === current?.fileName);
|
|
3759
3759
|
getFindIndex !== -1
|
|
3760
3760
|
? (accArr[getFindIndex] = { ...accArr[getFindIndex], ...current })
|
|
3761
3761
|
: accArr.push(current);
|
|
3762
3762
|
return accArr;
|
|
3763
3763
|
}, []);
|
|
3764
3764
|
} catch (e) {
|
|
3765
3765
|
console.log('LoadJsList合并错误', e);
|
|
3766
3766
|
}
|
|
3767
3767
|
console.log(
|
|
3768
3768
|
'globalLoadJsList',
|
|
3769
3769
|
globalLoadJsList,
|
|
3770
3770
|
'businessLoadJsList',
|
|
3771
3771
|
businessLoadJsList,
|
|
3772
3772
|
'两个加载jsList集合合并完成',
|
|
3773
3773
|
mergeLoadJsList,
|
|
3774
3774
|
);
|
|
3775
3775
|
this.loadJsSdkList = mergeLoadJsList;
|
|
3776
3776
|
return this.loadJsSdkList;
|
|
3777
3777
|
}
|
|
3778
3778
|
|
|
3779
3779
|
renderNextTickLoadSdk(delayTime = 1000) {
|
|
3780
3780
|
Taro.nextTick(() => {
|
|
3781
3781
|
console.log(
|
|
3782
3782
|
'页面渲染的下一帧执行的js加载方法,当前nextTick存在state的渲染问题,先延迟1s=======',
|
|
3783
3783
|
);
|
|
3784
3784
|
setTimeout(() => {
|
|
3785
3785
|
this.loadOtherSdk(LoadJsInitTriggerType.NRXT_TICK, this.loadJsSdkList);
|
|
3786
3786
|
}, delayTime);
|
|
3787
3787
|
});
|
|
3788
3788
|
}
|
|
3789
3789
|
|
|
3790
3790
|
loadOtherSdk(triggerType = LoadJsInitTriggerType.NOW, loadJsList: any[] = []) {
|
|
3791
3791
|
const getLoadJsList =
|
|
3792
3792
|
Array.isArray(loadJsList) && loadJsList.length > 0 ? loadJsList : this.dealLoadSdkList();
|
|
3793
3793
|
const getLoadFilterList = getLoadJsList.filter((item) => {
|
|
3794
3794
|
if (isJdAndHarmonyDevice && item.fileName === 'addCartJs') {
|
|
3795
3795
|
item.initLoadType = undefined;
|
|
3796
3796
|
}
|
|
3797
3797
|
const getInitLoadEnvType = item?.initLoadEnvType || LoadJsInitLoadEnvType.ALL;
|
|
3798
3798
|
let getLoastLoadEventState = true;
|
|
3799
3799
|
if (getInitLoadEnvType === LoadJsInitLoadEnvType.JD_APP) {
|
|
3800
3800
|
getLoastLoadEventState = isJdApp;
|
|
3801
3801
|
}
|
|
3802
3802
|
else if (getInitLoadEnvType === LoadJsInitLoadEnvType.M) {
|
|
3803
3803
|
getLoastLoadEventState = !isJdApp || !!isJdAndHarmonyDevice;
|
|
3804
3804
|
}
|
|
3805
3805
|
const getInitTriggerType =
|
|
3806
3806
|
isJdApp && item?.initJdAppTriggerType
|
|
3807
3807
|
? item?.initTriggerType
|
|
3808
3808
|
: item?.initTriggerType || LoadJsInitTriggerType.NOW;
|
|
3809
3809
|
const getInitLinkTriggerWay = window?.PAGE_DATA[item?.initLinkTriggerWay] || false;
|
|
3810
3810
|
return getLoastLoadEventState && getInitTriggerType === triggerType && getInitLinkTriggerWay;
|
|
3811
3811
|
});
|
|
3812
3812
|
console.log(
|
|
3813
3813
|
'获取当前触发方式',
|
|
3814
3814
|
triggerType,
|
|
3815
3815
|
'获取当前最后加载的js集合',
|
|
3816
3816
|
getLoadFilterList,
|
|
3817
3817
|
'过滤前的加载集合',
|
|
3818
3818
|
getLoadJsList,
|
|
3819
3819
|
);
|
|
3820
3820
|
getLoadFilterList.length > 0 &&
|
|
3821
3821
|
getLoadFilterList.forEach((item) => {
|
|
3822
3822
|
const isLoadState = /sgm/.test(item?.fileName)
|
|
3823
3823
|
? window?.shopGlobalSwitch?.openSgm === 'true'
|
|
3824
3824
|
: true;
|
|
3825
3825
|
isLoadState &&
|
|
3826
3826
|
this.loadItemSdkPromise(item)
|
|
3827
3827
|
.then((res) => {
|
|
3828
3828
|
console.info('当前js地址' + item?.src, '加载状态', res);
|
|
3829
3829
|
const isFileNameNewDraSdkJs = res?.fileName === 'newDraSdkJs';
|
|
3830
3830
|
if (isFileNameNewDraSdkJs && window?.dra?.run) {
|
|
3831
3831
|
window.dra.run('init', { aid: res?.aid });
|
|
3832
3832
|
window.dra.run('start');
|
|
3833
3833
|
}
|
|
3834
3834
|
})
|
|
3835
3835
|
.catch((err) => {
|
|
3836
3836
|
console.info('当前js地址加载异常', item?.src);
|
|
3837
3837
|
window?.fetchErrorData &&
|
|
3838
3838
|
window.fetchErrorData({
|
|
3839
3839
|
title: '公共js加载异常',
|
|
3840
3840
|
type: 'jsLoad',
|
|
3841
3841
|
data: err,
|
|
3842
3842
|
});
|
|
3843
3843
|
});
|
|
3844
3844
|
});
|
|
3845
3845
|
}
|
|
3846
3846
|
loadScriptEle(jsInfo, resolve, reject) {
|
|
3847
3847
|
const getFileName = jsInfo?.fileName;
|
|
3848
3848
|
if (getFileName) {
|
|
3849
3849
|
const getEleId = `J_loadJs_${getFileName}`;
|
|
3850
3850
|
const getEle = document.getElementById(getEleId);
|
|
3851
3851
|
if (!getEle) {
|
|
3852
3852
|
const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
|
|
3853
3853
|
const _sgmEle = document.createElement('script');
|
|
3854
3854
|
_sgmEle.id = getEleId;
|
|
3855
3855
|
_sgmEle.onload = function () {
|
|
3856
3856
|
resolve({
|
|
3857
3857
|
...jsInfo,
|
|
3858
3858
|
jsTip: 'js加载成功',
|
|
3859
3859
|
});
|
|
3860
3860
|
};
|
|
3861
3861
|
_sgmEle.onerror = function () {
|
|
3862
3862
|
reject({
|
|
3863
3863
|
...jsInfo,
|
|
3864
3864
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
3865
3865
|
jsReqError: '当前js创建标签触发onerror异常回调,请排查网络络错误或语法错误或运行时错误',
|
|
3866
3866
|
});
|
|
3867
3867
|
};
|
|
3868
3868
|
const dataAttrList = ['timeout', 'fileName', 'env'];
|
|
3869
3869
|
const getJsInfoKeyList = Object.keys(jsInfo);
|
|
3870
3870
|
getJsInfoKeyList.forEach((key) => {
|
|
3871
3871
|
if (key === 'async') {
|
|
3872
3872
|
_sgmEle.async = jsInfo[key];
|
|
3873
3873
|
} else if (key === 'crossOrigin') {
|
|
3874
3874
|
_sgmEle.crossOrigin = jsInfo[key];
|
|
3875
3875
|
} else if (key === 'src') {
|
|
3876
3876
|
_sgmEle.src = `${jsInfo[key]}`;
|
|
3877
3877
|
} else if (dataAttrList.includes(key) || /init/.test(key)) {
|
|
3878
3878
|
_sgmEle.setAttribute(`data-${key}`, jsInfo[key]);
|
|
3879
3879
|
} else {
|
|
3880
3880
|
_sgmEle.setAttribute(key, jsInfo[key]);
|
|
3881
3881
|
}
|
|
3882
3882
|
});
|
|
3883
3883
|
document.head.appendChild(_sgmEle);
|
|
3884
3884
|
} else {
|
|
3885
3885
|
console.log(`当前${jsInfo?.fileName || 'js'}已经存在页面中,可以直接调用相关方法`, jsInfo);
|
|
3886
3886
|
resolve({
|
|
3887
3887
|
...jsInfo,
|
|
3888
3888
|
jsTip: 'js本身已存在页面中',
|
|
3889
3889
|
});
|
|
3890
3890
|
}
|
|
3891
3891
|
} else {
|
|
3892
3892
|
console.warn('当前js资源信息缺少必要的参数fileName,请关注', jsInfo);
|
|
3893
3893
|
}
|
|
3894
3894
|
}
|
|
3895
3895
|
|
|
3896
3896
|
loadItemSdkPromise(jsInfo = {}) {
|
|
3897
3897
|
if (jsInfo?.src) {
|
|
3898
3898
|
const getInitLoadType =
|
|
3899
3899
|
isJdApp && jsInfo?.initJdAppLoadType
|
|
3900
3900
|
? jsInfo?.initJdAppLoadType
|
|
3901
3901
|
: jsInfo?.initLoadType || LoadJsInitLoadType.ALL;
|
|
3902
3902
|
if (getInitLoadType !== LoadJsInitLoadType.NONE) {
|
|
3903
3903
|
const getFileKeyName = jsInfo?.fileName || jsInfo?.src;
|
|
3904
3904
|
if (!this.loadJsSdkListCachePromise[getFileKeyName]) {
|
|
3905
3905
|
if (getInitLoadType !== LoadJsInitLoadType.INSERT_ELE) {
|
|
3906
3906
|
this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
|
|
3907
3907
|
const jsLoadErrorSgmCode = `jsLoadError_${jsInfo?.fileName || 'customJs'}`;
|
|
3908
3908
|
try {
|
|
3909
3909
|
const jsXhrRequest = new XMLHttpRequest();
|
|
3910
3910
|
jsXhrRequest.timeout = jsInfo?.timeout ?? 2000;
|
|
3911
3911
|
const jsUrl = `${jsInfo?.src}`;
|
|
3912
3912
|
jsXhrRequest.open('GET', jsUrl, true);
|
|
3913
3913
|
jsXhrRequest.onreadystatechange = () => {
|
|
3914
3914
|
if (jsXhrRequest.readyState === 4) {
|
|
3915
3915
|
const getReqStatus = jsXhrRequest.status;
|
|
3916
3916
|
const statusText = jsXhrRequest.statusText;
|
|
3917
3917
|
if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
|
|
3918
3918
|
const getInsetHeadState = getInitLoadType === LoadJsInitLoadType.ALL;
|
|
3919
3919
|
if (getInsetHeadState) {
|
|
3920
3920
|
this.loadScriptEle(jsInfo, resolve, reject);
|
|
3921
3921
|
} else {
|
|
3922
3922
|
resolve({
|
|
3923
3923
|
...jsInfo,
|
|
3924
3924
|
jsTip: 'js请求成功,暂未插入head节点,业务自行单独插入',
|
|
3925
3925
|
});
|
|
3926
3926
|
}
|
|
3927
3927
|
getReqStatus !== 200 &&
|
|
3928
3928
|
draBusinessCustomReport({
|
|
3929
3929
|
eventName: 'business',
|
|
3930
3930
|
errorName: 'js_load_special_code',
|
|
3931
3931
|
errorMessage: '当前js加载成功,状态非200,特殊上报观察',
|
|
3932
3932
|
extraData: JSON.stringify({
|
|
3933
3933
|
msg: '当前js加载成功,状态非200,特殊上报观察',
|
|
3934
3934
|
jsReqState: getReqStatus,
|
|
3935
3935
|
env: getSgmCustomCode('js_load_special_code'),
|
|
3936
3936
|
data: jsInfo,
|
|
3937
3937
|
}),
|
|
3938
3938
|
});
|
|
3939
3939
|
} else {
|
|
3940
3940
|
const getRes = {
|
|
3941
3941
|
...jsInfo,
|
|
3942
3942
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
3943
3943
|
jsReqError: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
|
|
3944
3944
|
jsReqState: getReqStatus,
|
|
3945
3945
|
};
|
|
3946
3946
|
console.log('当前js请求状态异常,具体信息见', getRes);
|
|
3947
3947
|
reject(getRes);
|
|
3948
3948
|
}
|
|
3949
3949
|
}
|
|
3950
3950
|
};
|
|
3951
3951
|
jsXhrRequest.onerror = () => {
|
|
3952
3952
|
const getRes = {
|
|
3953
3953
|
...jsInfo,
|
|
3954
3954
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
3955
3955
|
jsReqError: '请求错误',
|
|
3956
3956
|
};
|
|
3957
3957
|
console.log('当前js请求错误', getRes);
|
|
3958
3958
|
jsXhrRequest.abort();
|
|
3959
3959
|
reject(getRes);
|
|
3960
3960
|
};
|
|
3961
3961
|
jsXhrRequest.ontimeout = () => {
|
|
3962
3962
|
const getRes = {
|
|
3963
3963
|
...jsInfo,
|
|
3964
3964
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
3965
3965
|
jsReqError: `请求${jsXhrRequest.timeout}ms超时异常`,
|
|
3966
3966
|
jsReqState: jsXhrRequest.status,
|
|
3967
3967
|
};
|
|
3968
3968
|
console.log('当前js请求超时异常', getRes);
|
|
3969
3969
|
jsXhrRequest.abort();
|
|
3970
3970
|
reject(getRes);
|
|
3971
3971
|
};
|
|
3972
3972
|
jsXhrRequest.send();
|
|
3973
3973
|
} catch (e) {
|
|
3974
3974
|
console.log('执行js请求异常', e);
|
|
3975
3975
|
reject({
|
|
3976
3976
|
...jsInfo,
|
|
3977
3977
|
env: getSgmCustomCode(jsLoadErrorSgmCode),
|
|
3978
3978
|
jsReqError: '未知异常',
|
|
3979
3979
|
error: e,
|
|
3980
3980
|
});
|
|
3981
3981
|
}
|
|
3982
3982
|
});
|
|
3983
3983
|
} else {
|
|
3984
3984
|
this.loadJsSdkListCachePromise[getFileKeyName] = new Promise((resolve, reject) => {
|
|
3985
3985
|
return this.loadScriptEle(jsInfo, resolve, reject);
|
|
3986
3986
|
});
|
|
3987
3987
|
}
|
|
3988
3988
|
}
|
|
3989
3989
|
return this.loadJsSdkListCachePromise[getFileKeyName];
|
|
3990
3990
|
} else {
|
|
3991
3991
|
return Promise.resolve({
|
|
3992
3992
|
...jsInfo,
|
|
3993
3993
|
jsTip: 'js加载方式设置为不加载,当前不做处理',
|
|
3994
3994
|
});
|
|
3995
3995
|
}
|
|
3996
3996
|
} else {
|
|
3997
3997
|
return Promise.reject(jsInfo);
|
|
3998
3998
|
}
|
|
3999
3999
|
}
|
|
4000
4000
|
|
|
4001
4001
|
createLanguagePromise() {
|
|
4002
4002
|
const getLanguageConfig = window?.shopGlobalSwitch?.language || {};
|
|
4003
4003
|
if (!this.languageCacheProimse) {
|
|
4004
4004
|
this.languageCacheProimse = new Promise((resolve, reject) => {
|
|
4005
4005
|
const { fileName, prefixUrl } = getLanguageConfig;
|
|
4006
4006
|
console.log('getLanguageConfig', getLanguageConfig, 'languageNowType', languageNowType);
|
|
4007
4007
|
const dealLanguageFile = () => {
|
|
4008
4008
|
this.getLanguageFilePromise(getLanguageConfig, languageNowType)
|
|
4009
4009
|
.then((res) => {
|
|
4010
4010
|
if (res && res?.data) {
|
|
4011
4011
|
this.languageJsonData = res.data;
|
|
4012
4012
|
|
|
4013
4013
|
setTimeout(() => {
|
|
4014
4014
|
const getOtherLanguageList = languageTypeList.filter(
|
|
4015
4015
|
(item) => item !== languageNowType,
|
|
4016
4016
|
);
|
|
4017
4017
|
getOtherLanguageList.length > 0 &&
|
|
4018
4018
|
getOtherLanguageList.map((languageTypeKey) => {
|
|
4019
4019
|
this.getLanguageFilePromise(getLanguageConfig, languageTypeKey);
|
|
4020
4020
|
});
|
|
4021
4021
|
}, 3000);
|
|
4022
4022
|
resolve(res);
|
|
4023
4023
|
} else {
|
|
4024
4024
|
reject(res);
|
|
4025
4025
|
}
|
|
4026
4026
|
})
|
|
4027
4027
|
.catch((err) => {
|
|
4028
4028
|
reject(err);
|
|
4029
4029
|
});
|
|
4030
4030
|
};
|
|
4031
4031
|
if (fileName && prefixUrl) {
|
|
4032
4032
|
const getLangStorageKey = `jshopx_lang_${languageNowType}`;
|
|
4033
4033
|
const getLocalLangRes = getTaroStorageKeyValue(getLangStorageKey);
|
|
4034
4034
|
if (getLocalLangRes) {
|
|
4035
4035
|
try {
|
|
4036
4036
|
const getLocalLangJsonData =
|
|
4037
4037
|
typeof getLocalLangRes === 'string' ? JSON.parse(getLocalLangRes) : getLocalLangRes;
|
|
4038
4038
|
if (getLocalLangJsonData?.fileName && getLocalLangJsonData?.data) {
|
|
4039
4039
|
if (getLocalLangJsonData?.fileName === fileName) {
|
|
4040
4040
|
const geThisLangData = getLocalLangJsonData.data;
|
|
4041
4041
|
this.languageJsonData = geThisLangData;
|
|
4042
4042
|
return resolve({
|
|
4043
4043
|
...getLanguageConfig,
|
|
4044
4044
|
languageNowType,
|
|
4045
4045
|
data: geThisLangData,
|
|
4046
4046
|
});
|
|
4047
4047
|
} else {
|
|
4048
4048
|
dealLanguageFile();
|
|
4049
4049
|
}
|
|
4050
4050
|
} else {
|
|
4051
4051
|
dealLanguageFile();
|
|
4052
4052
|
}
|
|
4053
4053
|
} catch (e) {
|
|
4054
4054
|
return reject({
|
|
4055
4055
|
languageNowType,
|
|
4056
4056
|
msg: '转换错误',
|
|
4057
4057
|
...getLanguageConfig,
|
|
4058
4058
|
});
|
|
4059
4059
|
}
|
|
4060
4060
|
} else {
|
|
4061
4061
|
dealLanguageFile();
|
|
4062
4062
|
}
|
|
4063
4063
|
} else {
|
|
4064
4064
|
return reject({
|
|
4065
4065
|
languageNowType,
|
|
4066
4066
|
msg: '文件对象下发异常',
|
|
4067
4067
|
...getLanguageConfig,
|
|
4068
4068
|
});
|
|
4069
4069
|
}
|
|
4070
4070
|
});
|
|
4071
4071
|
}
|
|
4072
4072
|
return this.languageCacheProimse;
|
|
4073
4073
|
}
|
|
4074
4074
|
|
|
4075
4075
|
getLanguageFilePromise(info, languageTypeKey) {
|
|
4076
4076
|
const { fileName, prefixUrl, timeout } = info || {};
|
|
4077
4077
|
const getUrl = `${prefixUrl}${fileName}_${languageTypeKey}.json`;
|
|
4078
4078
|
return new Promise((resolve, reject) => {
|
|
4079
4079
|
const langLoadErrorSgmCode = `languageLoadError_${fileName || 'lang.json'}`;
|
|
4080
4080
|
try {
|
|
4081
4081
|
const langXhrRequest = new XMLHttpRequest();
|
|
4082
4082
|
langXhrRequest.timeout = timeout || 2000;
|
|
4083
4083
|
langXhrRequest.open('GET', getUrl, true);
|
|
4084
4084
|
langXhrRequest.responseType = 'json';
|
|
4085
4085
|
langXhrRequest.onreadystatechange = () => {
|
|
4086
4086
|
if (langXhrRequest.readyState === 4) {
|
|
4087
4087
|
const getReqStatus = langXhrRequest.status;
|
|
4088
4088
|
const statusText = langXhrRequest.statusText;
|
|
4089
4089
|
if ((getReqStatus >= 200 && getReqStatus < 300) || getReqStatus === 304) {
|
|
4090
4090
|
const getData = langXhrRequest?.response || false;
|
|
4091
4091
|
if (getData) {
|
|
4092
4092
|
setTaroStorage(`jshopx_lang_${languageTypeKey}`, {
|
|
4093
4093
|
fileName,
|
|
4094
4094
|
data: getData,
|
|
4095
4095
|
});
|
|
4096
4096
|
resolve({
|
|
4097
4097
|
...info,
|
|
4098
4098
|
languageTypeKey,
|
|
4099
4099
|
data: getData,
|
|
4100
4100
|
});
|
|
4101
4101
|
} else {
|
|
4102
4102
|
reject({
|
|
4103
4103
|
...info,
|
|
4104
4104
|
languageTypeKey,
|
|
4105
4105
|
msg: '数据获取异常',
|
|
4106
4106
|
});
|
|
4107
4107
|
}
|
|
4108
4108
|
} else {
|
|
4109
4109
|
const getRes = {
|
|
4110
4110
|
...info,
|
|
4111
4111
|
languageTypeKey,
|
|
4112
4112
|
env: getSgmCustomCode(langLoadErrorSgmCode),
|
|
4113
4113
|
msg: `请求状态异常,状态码为${getReqStatus},statusText:${statusText}`,
|
|
4114
4114
|
};
|
|
4115
4115
|
console.log('当前lang请求状态异常,具体信息见', getRes);
|
|
4116
4116
|
reject(getRes);
|
|
4117
4117
|
}
|
|
4118
4118
|
}
|
|
4119
4119
|
};
|
|
4120
4120
|
langXhrRequest.onerror = () => {
|
|
4121
4121
|
const getRes = {
|
|
4122
4122
|
...info,
|
|
4123
4123
|
env: getSgmCustomCode(langLoadErrorSgmCode),
|
|
4124
4124
|
msg: '请求错误',
|
|
4125
4125
|
};
|
|
4126
4126
|
console.log('当前lang请求错误', getRes);
|
|
4127
4127
|
langXhrRequest.abort();
|
|
4128
4128
|
reject(getRes);
|
|
4129
4129
|
};
|
|
4130
4130
|
langXhrRequest.ontimeout = () => {
|
|
4131
4131
|
const getRes = {
|
|
4132
4132
|
...info,
|
|
4133
4133
|
msg: `请求${langXhrRequest.timeout}ms超时异常,状态${langXhrRequest.status}`,
|
|
4134
4134
|
};
|
|
4135
4135
|
console.log('执行lang多语言请求超时异常', getRes);
|
|
4136
4136
|
langXhrRequest.abort();
|
|
4137
4137
|
reject(getRes);
|
|
4138
4138
|
};
|
|
4139
4139
|
langXhrRequest.send();
|
|
4140
4140
|
} catch (e) {
|
|
4141
4141
|
console.log('执行lang多语言请求异常', e);
|
|
4142
4142
|
reject({
|
|
4143
4143
|
...info,
|
|
4144
4144
|
env: getSgmCustomCode(langLoadErrorSgmCode),
|
|
4145
4145
|
msg: '未知异常',
|
|
4146
4146
|
error: e,
|
|
4147
4147
|
});
|
|
4148
4148
|
}
|
|
4149
4149
|
});
|
|
4150
4150
|
}
|