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