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