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