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