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