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