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