@conecli/cone-render 0.10.1-shop3.4 → 0.10.1-shop3.5
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro';
|
|
2
1
|
APPID,
|
|
3
2
|
JshopxColorFunctionIdList,
|
|
4
3
|
PagesColorFunctionIdList,
|
|
5
4
|
PAGES_DOMAIN,
|
|
6
5
|
B2BColorFunctionIdList,
|
|
7
6
|
MobileVerifyColorList,
|
|
8
7
|
AppVerifyColorList,
|
|
9
8
|
JshopxVerifyColorList,
|
|
10
9
|
BMallVerifyColorList,
|
|
11
10
|
shopMemberColorFunctionIdList,
|
|
12
11
|
isJdApp,
|
|
13
12
|
isIosDevice,
|
|
14
13
|
isAndroidDevice,
|
|
15
14
|
isJdAndHarmonyDevice,
|
|
16
15
|
showSuccessToast,
|
|
17
16
|
showFailToast,
|
|
18
17
|
isH5,
|
|
19
18
|
isWxMinAndWxapp,
|
|
20
19
|
isMin,
|
|
21
20
|
isPc,
|
|
22
21
|
draInterfaceCustomReport,
|
|
23
22
|
callRouterIOS,
|
|
24
23
|
callRouterAndroid,
|
|
25
24
|
sendNativePageToShowCartFloatBtn,
|
|
26
25
|
cookiesStr: '',
|
|
27
26
|
requestHeaderContentType: {
|
|
28
27
|
jsonHeader: {
|
|
29
28
|
'content-type': 'application/json;charset=utf-8',
|
|
30
29
|
},
|
|
31
30
|
formDataHeader: {
|
|
32
31
|
'content-type': 'application/x-www-form-urlencoded',
|
|
33
32
|
},
|
|
34
33
|
},
|
|
35
34
|
requestBaseParam: {
|
|
36
35
|
data: null,
|
|
37
36
|
header: {
|
|
38
37
|
'content-type': 'application/json;charset=utf-8',
|
|
39
38
|
},
|
|
40
39
|
},
|
|
41
40
|
timeOut: 7000,
|
|
42
41
|
apiClientParams: {
|
|
43
42
|
clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
|
|
44
43
|
client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
|
|
45
44
|
area: '1_72_2799_0',
|
|
46
45
|
screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
|
|
47
46
|
window.screen?.height * devicePixelRatio,
|
|
48
47
|
)}`,
|
|
49
48
|
uuid: UUID,
|
|
50
49
|
},
|
|
51
50
|
public addressFetchInfo: {
|
|
52
51
|
reqState: boolean;
|
|
53
52
|
promiseInstance: null | Promise<any>;
|
|
54
53
|
};
|
|
55
54
|
public getPromotionConfig: {
|
|
56
55
|
projectId: null | string | number;
|
|
57
56
|
pageId: null | string | number;
|
|
58
57
|
};
|
|
59
58
|
public resInfo: ServiceInterFace.HttpRequestInfo;
|
|
60
59
|
public api: ServiceInterFace.HttpApi;
|
|
61
60
|
public isPageDomain: boolean;
|
|
62
61
|
public verifyColorList: string[];
|
|
63
62
|
private isShowJdShopCartFloatBtn: boolean;
|
|
64
63
|
constructor(opt) {
|
|
65
64
|
this._init();
|
|
66
65
|
this.addressFetchInfo = {
|
|
67
66
|
reqState: false,
|
|
68
67
|
promiseInstance: null,
|
|
69
68
|
};
|
|
70
69
|
this.getPromotionConfig = {
|
|
71
70
|
projectId: null,
|
|
72
71
|
pageId: null,
|
|
73
72
|
};
|
|
74
73
|
this._userAreaUpdateListen();
|
|
75
74
|
this.resInfo = this._getResConfig(opt);
|
|
76
75
|
this.api = api;
|
|
77
76
|
this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
|
|
78
77
|
this.verifyColorList = [
|
|
79
78
|
...MobileVerifyColorList,
|
|
80
79
|
...AppVerifyColorList,
|
|
81
80
|
...JshopxVerifyColorList,
|
|
82
81
|
...BMallVerifyColorList,
|
|
83
82
|
];
|
|
84
83
|
this.isShowJdShopCartFloatBtn =
|
|
85
84
|
jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
|
|
86
85
|
}
|
|
87
86
|
_init(): void {
|
|
88
87
|
httpInterceptors.forEach((item) => {
|
|
89
88
|
Taro.addInterceptor((chain) => item(chain));
|
|
90
89
|
});
|
|
91
90
|
}
|
|
92
91
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
93
92
|
return Object.assign({}, DefaultConfig, opt);
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
_userAreaUpdateListen() {
|
|
97
96
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
|
|
98
97
|
area &&
|
|
99
98
|
area !== '' &&
|
|
100
99
|
this.updateApiClientParamsResInfo({
|
|
101
100
|
area,
|
|
102
101
|
});
|
|
103
102
|
console.log(
|
|
104
103
|
'cone-render收到原生端获取传来的四级地址信息',
|
|
105
104
|
area,
|
|
106
105
|
'更新后的接口底层信息',
|
|
107
106
|
this.resInfo.apiClientParams,
|
|
108
107
|
);
|
|
109
108
|
});
|
|
110
109
|
}
|
|
111
110
|
updateApiClientParamsResInfo(opt = {}) {
|
|
112
111
|
const { area, ...others } = opt;
|
|
113
112
|
this.resInfo.apiClientParams = {
|
|
114
113
|
...this.resInfo.apiClientParams,
|
|
115
114
|
...others,
|
|
116
115
|
};
|
|
117
116
|
if (area) {
|
|
118
117
|
this.resInfo.apiClientParams.area = area;
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
checkFunctionIdToReturnAppId(functionId) {
|
|
123
122
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
124
123
|
return APPID.JSHOPX_COLOR_APPID;
|
|
125
124
|
} else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
|
|
126
125
|
return APPID.PAGES_COLOR_APPID;
|
|
127
126
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
128
127
|
return APPID.SHOP_MEMBER_COLOR_APPID;
|
|
129
128
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
130
129
|
return APPID.B2B_COLOR_APPID;
|
|
131
130
|
} else if (isPc) {
|
|
132
131
|
return APPID.MALL_COLOR_APPID;
|
|
133
132
|
} else {
|
|
134
133
|
return APPID.SHOP_COLOR_APPID;
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
139
138
|
if (
|
|
140
139
|
functionId === 'receiveShopCoupon' &&
|
|
141
140
|
((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
|
|
142
141
|
isWxMinAndWxapp)
|
|
143
142
|
) {
|
|
144
143
|
clientParams = Object.assign(
|
|
145
144
|
{},
|
|
146
145
|
{
|
|
147
146
|
loginType: '1',
|
|
148
147
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
149
148
|
},
|
|
150
149
|
clientParams,
|
|
151
150
|
);
|
|
152
151
|
}
|
|
153
152
|
const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
|
|
154
153
|
typeof apiClientParams.appid === 'undefined' &&
|
|
155
154
|
(apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
|
|
156
155
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
157
156
|
const getReqData = {
|
|
158
157
|
functionId: functionId,
|
|
159
158
|
body: JSON.stringify(bodyParams),
|
|
160
159
|
t: Date.now(),
|
|
161
160
|
...apiClientParams,
|
|
162
161
|
};
|
|
163
162
|
return http
|
|
164
163
|
.request({
|
|
165
164
|
url: this.api.apiFunc,
|
|
166
165
|
data: getReqData,
|
|
167
166
|
isColorVerify,
|
|
168
167
|
})
|
|
169
168
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
170
169
|
const { statusCode, data, status, msg } = res;
|
|
171
170
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
172
171
|
ok: true,
|
|
173
172
|
};
|
|
174
173
|
if ((statusCode === 200 || status === '0') && data) {
|
|
175
174
|
changeRes = this.dealResponseFormatRes(data);
|
|
176
175
|
return changeRes;
|
|
177
176
|
} else {
|
|
178
177
|
changeRes = {
|
|
179
178
|
...data,
|
|
180
179
|
statusCode,
|
|
181
180
|
status,
|
|
182
181
|
msg,
|
|
183
182
|
ok: false,
|
|
184
183
|
};
|
|
185
184
|
return changeRes;
|
|
186
185
|
}
|
|
187
186
|
})
|
|
188
187
|
.catch((res) => {
|
|
189
188
|
const propertyNames = Object.getOwnPropertyNames(res);
|
|
190
189
|
const resObject = {};
|
|
191
190
|
propertyNames.forEach((propertyName) => {
|
|
192
191
|
resObject[propertyName] = res[propertyName];
|
|
193
192
|
});
|
|
194
193
|
draInterfaceCustomReport({
|
|
195
194
|
subMsg:
|
|
196
195
|
'接口请求异常,进入catch逻辑,例如h5请求神盾(反爬、小号、风控)或加固拦截返回status为403等',
|
|
197
196
|
url: this.api.apiFunc,
|
|
198
197
|
source: 'remote',
|
|
199
198
|
requestType: res?.requestType,
|
|
200
199
|
errorType: 'catchError',
|
|
201
200
|
functionId: getReqData?.functionId,
|
|
202
201
|
appid: getReqData?.appid,
|
|
203
202
|
client: getReqData?.client,
|
|
204
203
|
clientVersion: getReqData?.clientVersion,
|
|
205
204
|
statusCode: res?.statusCode,
|
|
206
205
|
status: res?.status,
|
|
207
206
|
statusText: res?.statusText,
|
|
208
207
|
code: res?.data?.code || res?.data?.subCode,
|
|
209
208
|
errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
|
|
210
209
|
originReqDataStr: JSON.stringify(getReqData),
|
|
211
210
|
originResDataStr: JSON.stringify(res, propertyNames),
|
|
212
211
|
});
|
|
213
212
|
return {
|
|
214
213
|
...resObject,
|
|
215
214
|
ok: false,
|
|
216
215
|
} as ServiceInterFace.RequestResponseFormatRes;
|
|
217
216
|
});
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
dealResponseFormatRes(data) {
|
|
221
220
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
222
221
|
ok: true,
|
|
223
222
|
};
|
|
224
223
|
const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
|
|
225
224
|
const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
|
|
226
225
|
? Number(data.subCode)
|
|
227
226
|
: -1;
|
|
228
227
|
if (
|
|
229
228
|
data.success === true ||
|
|
230
229
|
data.isSuccess ||
|
|
231
230
|
resCode === 0 ||
|
|
232
231
|
resCode === 200 ||
|
|
233
232
|
subCode === 0
|
|
234
233
|
) {
|
|
235
234
|
changeRes = {
|
|
236
235
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
237
236
|
? data.result
|
|
238
237
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
239
238
|
? data.data
|
|
240
239
|
: data,
|
|
241
240
|
code: data.code ?? 200,
|
|
242
241
|
ok: true,
|
|
243
242
|
source: data,
|
|
244
243
|
};
|
|
245
244
|
return changeRes;
|
|
246
245
|
} else {
|
|
247
246
|
changeRes = {
|
|
248
247
|
...data,
|
|
249
248
|
ok: false,
|
|
250
249
|
};
|
|
251
250
|
return changeRes;
|
|
252
251
|
}
|
|
253
252
|
}
|
|
254
253
|
|
|
255
254
|
async receiveCoupon(param = {}, clientParams) {
|
|
256
255
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
257
256
|
return await this.gatewayReq(
|
|
258
257
|
'receiveShopCoupon',
|
|
259
258
|
{
|
|
260
259
|
operation: '3',
|
|
261
260
|
...param,
|
|
262
261
|
},
|
|
263
262
|
{ ...loginType, ...clientParams },
|
|
264
263
|
);
|
|
265
264
|
}
|
|
266
265
|
|
|
267
266
|
getCustomerCenterDispatch(params = {}) {
|
|
268
267
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
269
268
|
clientVersion: '9.2.0',
|
|
270
269
|
client: 'H5',
|
|
271
270
|
uuid: 88888,
|
|
272
271
|
appid: 'shopmember_m_jd_com',
|
|
273
272
|
});
|
|
274
273
|
}
|
|
275
274
|
|
|
276
275
|
batchAddCart(skuIdsStr, num = 1, showToast = true) {
|
|
277
276
|
if (skuIdsStr) {
|
|
278
277
|
return this._addShopGoodCart(`${skuIdsStr}`, `${num}`)
|
|
279
278
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
280
279
|
if (res?.ok) {
|
|
281
280
|
showToast &&
|
|
282
281
|
!res?.isOpenApp &&
|
|
283
282
|
showSuccessToast({
|
|
284
283
|
title: '加入购物车成功',
|
|
285
284
|
});
|
|
286
285
|
this.isShowJdShopCartFloatBtn &&
|
|
287
286
|
sendNativePageToShowCartFloatBtn({
|
|
288
287
|
isShow: true,
|
|
289
288
|
});
|
|
290
289
|
} else {
|
|
291
290
|
showToast &&
|
|
292
291
|
showFailToast({
|
|
293
292
|
title: res?.errMsg || '加入购物车失败,请稍后重试!',
|
|
294
293
|
});
|
|
295
294
|
}
|
|
296
295
|
return Promise.resolve(res);
|
|
297
296
|
})
|
|
298
297
|
.catch((e) => {
|
|
299
298
|
console.log('调用加购方法异常=======>', e);
|
|
300
299
|
return Promise.resolve({
|
|
301
300
|
ok: false,
|
|
302
301
|
msg: '加入购物车失败,请稍后重试!',
|
|
303
302
|
});
|
|
304
303
|
});
|
|
305
304
|
} else {
|
|
306
305
|
return Promise.resolve({
|
|
307
306
|
ok: false,
|
|
308
307
|
msg: '加入购物车失败,请稍后重试!',
|
|
309
308
|
});
|
|
310
309
|
}
|
|
311
310
|
}
|
|
312
311
|
|
|
313
312
|
_addShopGoodCart(skuIdsStr, addCardNum = '1') {
|
|
314
313
|
return new Promise((resolve) => {
|
|
315
314
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
|
|
316
315
|
if (productIdsArr.length > 0) {
|
|
317
316
|
if (isJdApp && !isJdAndHarmonyDevice) {
|
|
318
317
|
console.log('==========>', '原生批量加车!');
|
|
319
318
|
const nativeAddCartCallBack = `nativeBatchAddCart${Date.now()}`;
|
|
320
319
|
if (!window[nativeAddCartCallBack]) {
|
|
321
320
|
window[nativeAddCartCallBack] = (res) => {
|
|
322
321
|
const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
|
|
323
322
|
console.info(
|
|
324
323
|
'获取批量加车原始数据',
|
|
325
324
|
res,
|
|
326
325
|
'====转换后的json数据为===',
|
|
327
326
|
getMessageJsonData,
|
|
328
327
|
);
|
|
329
328
|
try {
|
|
330
329
|
if (isAndroidDevice) {
|
|
331
330
|
getMessageJsonData?.status === '0'
|
|
332
331
|
? resolve({
|
|
333
332
|
ok: true,
|
|
334
333
|
msg: '已加入购物车!',
|
|
335
334
|
})
|
|
336
335
|
: resolve({
|
|
337
336
|
ok: false,
|
|
338
337
|
msg: '加购失败,请稍后重试',
|
|
339
338
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
340
339
|
});
|
|
341
340
|
} else if (isIosDevice) {
|
|
342
341
|
getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0
|
|
343
342
|
? resolve({
|
|
344
343
|
ok: true,
|
|
345
344
|
msg: '已加入购物车!',
|
|
346
345
|
})
|
|
347
346
|
: resolve({
|
|
348
347
|
ok: false,
|
|
349
348
|
msg: '批量加车失败,请稍后重试',
|
|
350
349
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
351
350
|
});
|
|
352
351
|
} else {
|
|
353
352
|
resolve({
|
|
354
353
|
ok: false,
|
|
355
354
|
msg: '加购失败,请稍后重试',
|
|
356
355
|
});
|
|
357
356
|
}
|
|
358
357
|
} catch (e) {
|
|
359
358
|
resolve({
|
|
360
359
|
ok: false,
|
|
361
360
|
msg: '加购失败,请稍后重试',
|
|
362
361
|
});
|
|
363
362
|
console.warn('批量加车转换数据异常', e);
|
|
364
363
|
}
|
|
365
364
|
window[nativeAddCartCallBack] = null;
|
|
366
365
|
};
|
|
367
366
|
}
|
|
368
367
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
369
368
|
return isAndroidDevice
|
|
370
369
|
? {
|
|
371
370
|
sku: skuItem,
|
|
372
371
|
num: addCardNum,
|
|
373
372
|
}
|
|
374
373
|
: {
|
|
375
374
|
productCode: skuItem,
|
|
376
375
|
buyCount: addCardNum,
|
|
377
376
|
};
|
|
378
377
|
});
|
|
379
378
|
if (isAndroidDevice) {
|
|
380
379
|
const androidProductsStr = JSON.stringify(productsAddCartList);
|
|
381
380
|
callRouterAndroid({
|
|
382
381
|
routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
|
|
383
382
|
routerParam: {
|
|
384
383
|
wareList: productsAddCartList,
|
|
385
384
|
},
|
|
386
385
|
callBackName: nativeAddCartCallBack,
|
|
387
386
|
});
|
|
388
387
|
} else if (isIosDevice) {
|
|
389
388
|
if (isLowAppVer) {
|
|
390
389
|
const lowVersionAppList = productIdsArr.map((skuItem) => {
|
|
391
390
|
return {
|
|
392
391
|
sku: skuItem,
|
|
393
392
|
num: addCardNum,
|
|
394
393
|
};
|
|
395
394
|
});
|
|
396
395
|
const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
|
|
397
396
|
const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
|
|
398
397
|
jump.side.jdJumpToWeb(url, {});
|
|
399
398
|
resolve({
|
|
400
399
|
ok: true,
|
|
401
400
|
isOpenApp: true,
|
|
402
401
|
msg: '加购完成, 加购结果请点击购物车确认',
|
|
403
402
|
});
|
|
404
403
|
} else {
|
|
405
404
|
callRouterIOS({
|
|
406
405
|
routerURL: 'router://JDCartModule/batchAddService',
|
|
407
406
|
routerParam: {
|
|
408
407
|
sourceType: 'h5',
|
|
409
408
|
sourceValue: '店铺批量加购',
|
|
410
409
|
businessName: 'storeModel',
|
|
411
410
|
isNewMode: '1',
|
|
412
411
|
NotPassWebview: '1',
|
|
413
412
|
products: productsAddCartList,
|
|
414
413
|
},
|
|
415
414
|
callBackName: nativeAddCartCallBack,
|
|
416
415
|
});
|
|
417
416
|
}
|
|
418
417
|
}
|
|
419
418
|
} else if (isMin) {
|
|
420
419
|
console.log('==========>', '京购批量加车!');
|
|
421
420
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
422
421
|
return {
|
|
423
422
|
skuId: skuItem,
|
|
424
423
|
buyNum: addCardNum,
|
|
425
424
|
};
|
|
426
425
|
});
|
|
427
426
|
global.wxAppBizInstance
|
|
428
427
|
.addCart({ commArr: productsAddCartList })
|
|
429
428
|
.then((res) => {
|
|
430
429
|
console.log('dealCartSuccess: ', res);
|
|
431
430
|
resolve({
|
|
432
431
|
ok: true,
|
|
433
432
|
msg: '已加入购物车!',
|
|
434
433
|
data: res,
|
|
435
434
|
});
|
|
436
435
|
})
|
|
437
436
|
.catch((e) => {
|
|
438
437
|
console.log('京购小程序批量加车失败dealCartFail: ', e);
|
|
439
438
|
resolve({
|
|
440
439
|
ok: false,
|
|
441
440
|
msg: '加购失败,请稍后重试',
|
|
442
441
|
});
|
|
443
442
|
});
|
|
444
443
|
} else {
|
|
445
444
|
console.log('==========>', 'M站批量加车!');
|
|
446
445
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
|
|
447
446
|
}
|
|
448
447
|
} else {
|
|
449
448
|
resolve({
|
|
450
449
|
ok: false,
|
|
451
450
|
msg: '加购sku不能为空',
|
|
452
451
|
});
|
|
453
452
|
}
|
|
454
453
|
});
|
|
455
454
|
}
|
|
456
455
|
|
|
457
456
|
productAddToCart(skuIdsStr, num) {
|
|
458
457
|
return new Promise((resolve) => {
|
|
459
458
|
if (window.AddcartToolObj) {
|
|
460
459
|
window.AddcartToolObj.addCart({
|
|
461
460
|
skuId: skuIdsStr,
|
|
462
461
|
num,
|
|
463
462
|
source: 'sjdpyw',
|
|
464
463
|
actId: '1',
|
|
465
464
|
loginType: window?.isJingGouMiniViewState ? '11' : '2',
|
|
466
465
|
sucFun(res) {
|
|
467
466
|
console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
|
|
468
467
|
if (res.errId === '0' && res.cartJson) {
|
|
469
468
|
resolve({
|
|
470
469
|
ok: true,
|
|
471
470
|
msg: '已加入购物车!',
|
|
472
471
|
...res,
|
|
473
472
|
});
|
|
474
473
|
} else {
|
|
475
474
|
if (res.errId === '13') {
|
|
476
475
|
global.doLogin();
|
|
477
476
|
} else {
|
|
478
477
|
resolve({
|
|
479
478
|
ok: false,
|
|
480
479
|
msg: '加购失败,请稍后重试',
|
|
481
480
|
...res,
|
|
482
481
|
});
|
|
483
482
|
}
|
|
484
483
|
}
|
|
485
484
|
},
|
|
486
485
|
failFun(err) {
|
|
487
486
|
console.log('fail', err);
|
|
488
487
|
resolve({
|
|
489
488
|
ok: false,
|
|
490
489
|
msg: '加购失败,请稍后重试',
|
|
491
490
|
...err,
|
|
492
491
|
});
|
|
493
492
|
},
|
|
494
493
|
});
|
|
495
494
|
} else {
|
|
496
495
|
resolve({
|
|
497
496
|
ok: false,
|
|
498
497
|
msg: '购物车方法检查异常',
|
|
499
498
|
});
|
|
500
499
|
}
|
|
501
500
|
});
|
|
502
501
|
}
|
|
503
502
|
bMallGetUserInfo = () => {
|
|
504
503
|
return getBMallUserInfo();
|
|
505
504
|
};
|
|
506
505
|
async bMallAddCart(params = {}) {
|
|
507
506
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
508
507
|
client: 'H5',
|
|
509
508
|
clientVersion: '5.5.0',
|
|
510
509
|
});
|
|
511
510
|
}
|
|
512
511
|
async bMallChangeCart(params = {}) {
|
|
513
512
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
514
513
|
client: 'H5',
|
|
515
514
|
clientVersion: '5.5.0',
|
|
516
515
|
});
|
|
517
516
|
}
|
|
518
517
|
async bMallRemoveCart(params = {}) {
|
|
519
518
|
return await this.gatewayReq(
|
|
520
519
|
'bmall_cartRemove',
|
|
521
520
|
params,
|
|
522
521
|
{
|
|
523
522
|
client: 'H5',
|
|
524
523
|
clientVersion: '5.5.0',
|
|
525
524
|
},
|
|
526
525
|
);
|
|
527
526
|
}
|
|
528
527
|
async bMallGetOmittedProduct(params = {}) {
|
|
529
528
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
530
529
|
client: 'H5',
|
|
531
530
|
clientVersion: '5.5.0',
|
|
532
531
|
});
|
|
533
532
|
}
|
|
534
533
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
535
534
|
const params = await getParams({ ...data, skuId, bMallTag, num });
|
|
536
535
|
return await this.bMallAddCart(params);
|
|
537
536
|
}
|
|
538
537
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
539
538
|
const params = await getParams({ bMallTag });
|
|
540
539
|
delete params.operations;
|
|
541
540
|
return await this.bMallGetOmittedProduct(params);
|
|
542
541
|
}
|
|
543
542
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
544
543
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
545
544
|
return await this.bMallRemoveCart(params);
|
|
546
545
|
}
|
|
547
546
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
548
547
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
549
548
|
return await this.bMallChangeCart(params);
|
|
550
549
|
}
|
|
551
550
|
|
|
552
551
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
553
552
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
554
553
|
return window?.bMallCartData;
|
|
555
554
|
}
|
|
556
555
|
const cartData = await this.bMallGetSkuNumService(bMallTag);
|
|
557
556
|
let items;
|
|
558
557
|
if (cartData.ok && cartData.result) {
|
|
559
558
|
items = cartData?.result?.items || {};
|
|
560
559
|
}
|
|
561
560
|
if (isH5) {
|
|
562
561
|
window.bMallCartData = items;
|
|
563
562
|
}
|
|
564
563
|
return items;
|
|
565
564
|
}
|
|
566
565
|
|
|
567
566
|
async bMallCartHandle(goodItem, num) {
|
|
568
567
|
try {
|
|
569
568
|
const {
|
|
570
569
|
skuUuid,
|
|
571
570
|
limitUpper,
|
|
572
571
|
limitLower,
|
|
573
572
|
} = goodItem;
|
|
574
573
|
let cartNum = Number(num);
|
|
575
574
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
576
575
|
cartNum = limitLower;
|
|
577
576
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
578
577
|
cartNum = limitUpper;
|
|
579
578
|
}
|
|
580
579
|
if (skuUuid && cartNum > 0) {
|
|
581
580
|
return this.bMallChangeCartService({
|
|
582
581
|
...goodItem,
|
|
583
582
|
skuUuid,
|
|
584
583
|
num: cartNum,
|
|
585
584
|
});
|
|
586
585
|
} else if (!skuUuid && cartNum > 0) {
|
|
587
586
|
return this.bMallAddCartService({ ...goodItem, num: cartNum });
|
|
588
587
|
} else if (skuUuid && !cartNum) {
|
|
589
588
|
return this.bMallRemoveCartService({
|
|
590
589
|
...goodItem,
|
|
591
590
|
skuUuid,
|
|
592
591
|
num: cartNum,
|
|
593
592
|
});
|
|
594
593
|
} else {
|
|
595
594
|
console.error('参数不全');
|
|
596
595
|
return false;
|
|
597
596
|
}
|
|
598
597
|
} catch (e) {
|
|
599
598
|
console.error(e);
|
|
600
599
|
}
|
|
601
600
|
}
|
|
601
|
+
import Taro from '@tarojs/taro';
|
|
602
602
|
APPID,
|
|
603
603
|
JshopxColorFunctionIdList,
|
|
604
604
|
PagesColorFunctionIdList,
|
|
605
605
|
PAGES_DOMAIN,
|
|
606
606
|
B2BColorFunctionIdList,
|
|
607
607
|
MobileVerifyColorList,
|
|
608
608
|
AppVerifyColorList,
|
|
609
609
|
JshopxVerifyColorList,
|
|
610
610
|
BMallVerifyColorList,
|
|
611
611
|
shopMemberColorFunctionIdList,
|
|
612
612
|
draBusinessCustomReport,
|
|
613
613
|
isLanguageForEn,
|
|
614
614
|
isJdApp,
|
|
615
615
|
isIosDevice,
|
|
616
616
|
isAndroidDevice,
|
|
617
617
|
isJdAndHarmonyDevice,
|
|
618
618
|
showSuccessToast,
|
|
619
619
|
showFailToast,
|
|
620
620
|
isH5,
|
|
621
621
|
isWxMinAndWxapp,
|
|
622
622
|
isMin,
|
|
623
623
|
isPc,
|
|
624
624
|
draInterfaceCustomReport,
|
|
625
625
|
callRouterIOS,
|
|
626
626
|
callRouterAndroid,
|
|
627
627
|
sendNativePageToShowCartFloatBtn,
|
|
628
628
|
cookiesStr: '',
|
|
629
629
|
requestHeaderContentType: {
|
|
630
630
|
jsonHeader: {
|
|
631
631
|
'content-type': 'application/json;charset=utf-8',
|
|
632
632
|
},
|
|
633
633
|
formDataHeader: {
|
|
634
634
|
'content-type': 'application/x-www-form-urlencoded',
|
|
635
635
|
},
|
|
636
636
|
},
|
|
637
637
|
requestBaseParam: {
|
|
638
638
|
data: null,
|
|
639
639
|
header: {
|
|
640
640
|
'content-type': 'application/json;charset=utf-8',
|
|
641
641
|
},
|
|
642
642
|
},
|
|
643
643
|
timeOut: 7000,
|
|
644
644
|
apiClientParams: {
|
|
645
645
|
clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
|
|
646
646
|
client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
|
|
647
647
|
area: '1_72_2799_0',
|
|
648
648
|
screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
|
|
649
649
|
window.screen?.height * devicePixelRatio,
|
|
650
650
|
)}`,
|
|
651
651
|
uuid: UUID,
|
|
652
652
|
},
|
|
653
653
|
public addressFetchInfo: {
|
|
654
654
|
reqState: boolean;
|
|
655
655
|
promiseInstance: null | Promise<any>;
|
|
656
656
|
};
|
|
657
657
|
public getPromotionConfig: {
|
|
658
658
|
projectId: null | string | number;
|
|
659
659
|
pageId: null | string | number;
|
|
660
660
|
};
|
|
661
661
|
public resInfo: ServiceInterFace.HttpRequestInfo;
|
|
662
662
|
public api: ServiceInterFace.HttpApi;
|
|
663
663
|
public isPageDomain: boolean;
|
|
664
664
|
public verifyColorList: string[];
|
|
665
665
|
private isShowJdShopCartFloatBtn: boolean;
|
|
666
666
|
constructor(opt) {
|
|
667
667
|
this._init();
|
|
668
668
|
this.addressFetchInfo = {
|
|
669
669
|
reqState: false,
|
|
670
670
|
promiseInstance: null,
|
|
671
671
|
};
|
|
672
672
|
this.getPromotionConfig = {
|
|
673
673
|
projectId: null,
|
|
674
674
|
pageId: null,
|
|
675
675
|
};
|
|
676
676
|
this._userAreaUpdateListen();
|
|
677
677
|
this.resInfo = this._getResConfig(opt);
|
|
678
678
|
this.api = api;
|
|
679
679
|
this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
|
|
680
680
|
this.verifyColorList = [
|
|
681
681
|
...MobileVerifyColorList,
|
|
682
682
|
...AppVerifyColorList,
|
|
683
683
|
...JshopxVerifyColorList,
|
|
684
684
|
...BMallVerifyColorList,
|
|
685
685
|
];
|
|
686
686
|
this.isShowJdShopCartFloatBtn =
|
|
687
687
|
jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
|
|
688
688
|
}
|
|
689
689
|
_init(): void {
|
|
690
690
|
httpInterceptors.forEach((item) => {
|
|
691
691
|
Taro.addInterceptor((chain) => item(chain));
|
|
692
692
|
});
|
|
693
693
|
}
|
|
694
694
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
695
695
|
return Object.assign({}, DefaultConfig, opt);
|
|
696
696
|
}
|
|
697
697
|
|
|
698
698
|
_userAreaUpdateListen() {
|
|
699
699
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
|
|
700
700
|
area &&
|
|
701
701
|
area !== '' &&
|
|
702
702
|
this.updateApiClientParamsResInfo({
|
|
703
703
|
area,
|
|
704
704
|
});
|
|
705
705
|
console.log(
|
|
706
706
|
'cone-render收到原生端获取传来的四级地址信息',
|
|
707
707
|
area,
|
|
708
708
|
'更新后的接口底层信息',
|
|
709
709
|
this.resInfo.apiClientParams,
|
|
710
710
|
);
|
|
711
711
|
});
|
|
712
712
|
}
|
|
713
713
|
updateApiClientParamsResInfo(opt = {}) {
|
|
714
714
|
const { area, ...others } = opt;
|
|
715
715
|
this.resInfo.apiClientParams = {
|
|
716
716
|
...this.resInfo.apiClientParams,
|
|
717
717
|
...others,
|
|
718
718
|
};
|
|
719
719
|
if (area) {
|
|
720
720
|
this.resInfo.apiClientParams.area = area;
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
723
|
|
|
724
724
|
checkFunctionIdToReturnAppId(functionId) {
|
|
725
725
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
726
726
|
return APPID.JSHOPX_COLOR_APPID;
|
|
727
727
|
} else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
|
|
728
728
|
return APPID.PAGES_COLOR_APPID;
|
|
729
729
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
730
730
|
return APPID.SHOP_MEMBER_COLOR_APPID;
|
|
731
731
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
732
732
|
return APPID.B2B_COLOR_APPID;
|
|
733
733
|
} else if (isPc) {
|
|
734
734
|
return APPID.MALL_COLOR_APPID;
|
|
735
735
|
} else {
|
|
736
736
|
return APPID.SHOP_COLOR_APPID;
|
|
737
737
|
}
|
|
738
738
|
}
|
|
739
739
|
|
|
740
740
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
741
741
|
if (
|
|
742
742
|
functionId === 'receiveShopCoupon' &&
|
|
743
743
|
((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
|
|
744
744
|
isWxMinAndWxapp)
|
|
745
745
|
) {
|
|
746
746
|
clientParams = Object.assign(
|
|
747
747
|
{},
|
|
748
748
|
{
|
|
749
749
|
loginType: '1',
|
|
750
750
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
751
751
|
},
|
|
752
752
|
clientParams,
|
|
753
753
|
);
|
|
754
754
|
}
|
|
755
755
|
const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
|
|
756
756
|
typeof apiClientParams.appid === 'undefined' &&
|
|
757
757
|
(apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
|
|
758
758
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
759
759
|
const getReqData = {
|
|
760
760
|
functionId: functionId,
|
|
761
761
|
body: JSON.stringify(bodyParams),
|
|
762
762
|
t: Date.now(),
|
|
763
763
|
...apiClientParams,
|
|
764
764
|
};
|
|
765
765
|
return http
|
|
766
766
|
.request({
|
|
767
767
|
url: this.api.apiFunc,
|
|
768
768
|
data: getReqData,
|
|
769
769
|
isColorVerify,
|
|
770
770
|
})
|
|
771
771
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
772
772
|
const { statusCode, data, status, msg } = res;
|
|
773
773
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
774
774
|
ok: true,
|
|
775
775
|
};
|
|
776
776
|
if ((statusCode === 200 || status === '0') && data) {
|
|
777
777
|
changeRes = this.dealResponseFormatRes(data);
|
|
778
778
|
return changeRes;
|
|
779
779
|
} else {
|
|
780
780
|
changeRes = {
|
|
781
781
|
...data,
|
|
782
782
|
statusCode,
|
|
783
783
|
status,
|
|
784
784
|
msg,
|
|
785
785
|
ok: false,
|
|
786
786
|
};
|
|
787
787
|
return changeRes;
|
|
788
788
|
}
|
|
789
789
|
})
|
|
790
790
|
.catch((res) => {
|
|
791
791
|
const propertyNames = Object.getOwnPropertyNames(res);
|
|
792
792
|
const resObject = {};
|
|
793
793
|
propertyNames.forEach((propertyName) => {
|
|
794
794
|
resObject[propertyName] = res[propertyName];
|
|
795
795
|
});
|
|
796
796
|
draInterfaceCustomReport({
|
|
797
797
|
subMsg:
|
|
798
798
|
'接口请求异常,进入catch逻辑,例如h5请求神盾(反爬、小号、风控)或加固拦截返回status为403等',
|
|
799
799
|
url: this.api.apiFunc,
|
|
800
800
|
source: 'remote',
|
|
801
801
|
requestType: res?.requestType,
|
|
802
802
|
errorType: 'catchError',
|
|
803
803
|
functionId: getReqData?.functionId,
|
|
804
804
|
appid: getReqData?.appid,
|
|
805
805
|
client: getReqData?.client,
|
|
806
806
|
clientVersion: getReqData?.clientVersion,
|
|
807
807
|
statusCode: res?.statusCode,
|
|
808
808
|
status: res?.status,
|
|
809
809
|
statusText: res?.statusText,
|
|
810
810
|
code: res?.data?.code || res?.data?.subCode,
|
|
811
811
|
errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
|
|
812
812
|
originReqDataStr: JSON.stringify(getReqData),
|
|
813
813
|
originResDataStr: JSON.stringify(res, propertyNames),
|
|
814
814
|
});
|
|
815
815
|
return {
|
|
816
816
|
...resObject,
|
|
817
817
|
ok: false,
|
|
818
818
|
} as ServiceInterFace.RequestResponseFormatRes;
|
|
819
819
|
});
|
|
820
820
|
}
|
|
821
821
|
|
|
822
822
|
dealResponseFormatRes(data) {
|
|
823
823
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
824
824
|
ok: true,
|
|
825
825
|
};
|
|
826
826
|
const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
|
|
827
827
|
const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
|
|
828
828
|
? Number(data.subCode)
|
|
829
829
|
: -1;
|
|
830
830
|
if (
|
|
831
831
|
data.success === true ||
|
|
832
832
|
data.isSuccess ||
|
|
833
833
|
resCode === 0 ||
|
|
834
834
|
resCode === 200 ||
|
|
835
835
|
subCode === 0
|
|
836
836
|
) {
|
|
837
837
|
changeRes = {
|
|
838
838
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
839
839
|
? data.result
|
|
840
840
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
841
841
|
? data.data
|
|
842
842
|
: data,
|
|
843
843
|
code: data.code ?? 200,
|
|
844
844
|
ok: true,
|
|
845
845
|
source: data,
|
|
846
846
|
};
|
|
847
847
|
return changeRes;
|
|
848
848
|
} else {
|
|
849
849
|
changeRes = {
|
|
850
850
|
...data,
|
|
851
851
|
ok: false,
|
|
852
852
|
};
|
|
853
853
|
return changeRes;
|
|
854
854
|
}
|
|
855
855
|
}
|
|
856
856
|
|
|
857
857
|
async receiveCoupon(param = {}, clientParams) {
|
|
858
858
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
859
859
|
return await this.gatewayReq(
|
|
860
860
|
'receiveShopCoupon',
|
|
861
861
|
{
|
|
862
862
|
operation: '3',
|
|
863
863
|
...param,
|
|
864
864
|
},
|
|
865
865
|
{ ...loginType, ...clientParams },
|
|
866
866
|
);
|
|
867
867
|
}
|
|
868
868
|
|
|
869
869
|
getCustomerCenterDispatch(params = {}) {
|
|
870
870
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
871
871
|
clientVersion: '9.2.0',
|
|
872
872
|
client: 'H5',
|
|
873
873
|
uuid: 88888,
|
|
874
874
|
appid: 'shopmember_m_jd_com',
|
|
875
875
|
});
|
|
876
876
|
}
|
|
877
877
|
|
|
878
878
|
batchAddCart(...args) {
|
|
879
879
|
let skuIds, num, showToast, giftCard;
|
|
880
880
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
881
881
|
[skuIds, num = 1, showToast = true, giftCard = false] = args;
|
|
882
882
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
883
883
|
const params = args[0];
|
|
884
884
|
skuIds = params.skuIds;
|
|
885
885
|
num = params.num || 1;
|
|
886
886
|
showToast = params.showToast !== undefined ? params.showToast : true;
|
|
887
887
|
giftCard = params.giftCard !== undefined ? params.giftCard : false;
|
|
888
888
|
} else {
|
|
889
889
|
console.error('batchAddCart() Invalid arguments!', args)
|
|
890
890
|
try{
|
|
891
891
|
const data = {
|
|
892
892
|
type: 'batchAddCart',
|
|
893
893
|
subType: 'invalidInputParameter',
|
|
894
894
|
errMsg: '入参不合法',
|
|
895
895
|
originData: args
|
|
896
896
|
}
|
|
897
897
|
draBusinessCustomReport(data)
|
|
898
898
|
}catch(e){
|
|
899
899
|
console.error('draBusinessCustomReport error:', e)
|
|
900
900
|
}
|
|
901
901
|
const msg = isLanguageForEn? 'Please retry later': '加入购物车失败,请稍后重试!'
|
|
902
902
|
showFailToast({
|
|
903
903
|
title: msg,
|
|
904
904
|
});
|
|
905
905
|
return Promise.resolve({
|
|
906
906
|
ok: false,
|
|
907
907
|
msg,
|
|
908
908
|
});
|
|
909
909
|
}
|
|
910
910
|
const addToWhereText = giftCard? '购物清单': '购物车'
|
|
911
911
|
const successMsg = isLanguageForEn? 'Success': `加入${addToWhereText}成功`
|
|
912
912
|
const failMsg = isLanguageForEn? 'Please retry later': `加入${addToWhereText}失败,请稍后重试!`
|
|
913
913
|
if (skuIds) {
|
|
914
914
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, {giftCard})
|
|
915
915
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
916
916
|
if (res?.ok) {
|
|
917
917
|
showToast &&
|
|
918
918
|
!res?.isOpenApp &&
|
|
919
919
|
showSuccessToast({
|
|
920
920
|
title: successMsg,
|
|
921
921
|
});
|
|
922
922
|
this.isShowJdShopCartFloatBtn &&
|
|
923
923
|
sendNativePageToShowCartFloatBtn({
|
|
924
924
|
isShow: true,
|
|
925
925
|
});
|
|
926
926
|
} else {
|
|
927
927
|
showToast &&
|
|
928
928
|
showFailToast({
|
|
929
929
|
title: res?.errMsg || failMsg,
|
|
930
930
|
});
|
|
931
931
|
}
|
|
932
932
|
return Promise.resolve(res);
|
|
933
933
|
})
|
|
934
934
|
.catch((e) => {
|
|
935
935
|
console.log('调用加购方法异常=======>', e);
|
|
936
936
|
return Promise.resolve({
|
|
937
937
|
ok: false,
|
|
938
938
|
msg: failMsg,
|
|
939
939
|
});
|
|
940
940
|
});
|
|
941
941
|
} else {
|
|
942
942
|
try{
|
|
943
943
|
const data = {
|
|
944
944
|
type: 'batchAddCart',
|
|
945
945
|
subType: 'invalidInputParameter',
|
|
946
946
|
errMsg: '没有传入合法的skuIds',
|
|
947
947
|
originData: skuIds
|
|
948
948
|
}
|
|
949
949
|
draBusinessCustomReport(data)
|
|
950
950
|
}catch(e){
|
|
951
951
|
console.error('draBusinessCustomReport error:', e)
|
|
952
952
|
}
|
|
953
953
|
return Promise.resolve({
|
|
954
954
|
ok: false,
|
|
955
955
|
msg: failMsg,
|
|
956
956
|
});
|
|
957
957
|
}
|
|
958
958
|
}
|
|
959
959
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
960
960
|
return this.gatewayReq(
|
|
961
961
|
'giftCardAddCart',
|
|
962
962
|
{
|
|
963
963
|
skuList,
|
|
964
964
|
num: Number(num)
|
|
965
965
|
},
|
|
966
966
|
{ ...loginType},
|
|
967
967
|
);
|
|
968
968
|
}
|
|
969
969
|
|
|
970
970
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', {giftCard}) {
|
|
971
971
|
return new Promise((resolve) => {
|
|
972
972
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
|
|
973
973
|
if (productIdsArr.length > 0) {
|
|
974
974
|
if(giftCard){
|
|
975
975
|
this.giftCardAddCart(productIdsArr, addCardNum).then((res) => {
|
|
976
976
|
if(res?.code === '0' && res?.result?.value){
|
|
977
977
|
resolve({
|
|
978
978
|
ok: true,
|
|
979
979
|
})
|
|
980
980
|
}else{
|
|
981
981
|
try{
|
|
982
982
|
const data = {
|
|
983
983
|
type: 'batchAddCart',
|
|
984
984
|
subType: 'addCartFailByGiftCard',
|
|
985
985
|
errMsg: '礼品卡加车接口返回加车失败标识',
|
|
986
986
|
originData: res
|
|
987
987
|
}
|
|
988
988
|
draBusinessCustomReport(data)
|
|
989
989
|
}catch(e){
|
|
990
990
|
console.error('draBusinessCustomReport error:', e)
|
|
991
991
|
}
|
|
992
992
|
resolve({
|
|
993
993
|
ok: false,
|
|
994
994
|
msg: '加购失败,请稍后重试',
|
|
995
995
|
});
|
|
996
996
|
}
|
|
997
997
|
}).catch((e) => {
|
|
998
998
|
console.error('礼品卡加车失败: ', e);
|
|
999
999
|
resolve({
|
|
1000
1000
|
ok: false,
|
|
1001
1001
|
msg: '加购失败,请稍后重试',
|
|
1002
1002
|
});
|
|
1003
1003
|
});
|
|
1004
1004
|
}
|
|
1005
1005
|
else
|
|
1006
1006
|
if (isJdApp && !isJdAndHarmonyDevice) {
|
|
1007
1007
|
console.log('==========>', '原生批量加车!');
|
|
1008
1008
|
const nativeAddCartCallBack = `nativeBatchAddCart${Date.now()}`;
|
|
1009
1009
|
if (!window[nativeAddCartCallBack]) {
|
|
1010
1010
|
window[nativeAddCartCallBack] = (res) => {
|
|
1011
1011
|
const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
|
|
1012
1012
|
console.info(
|
|
1013
1013
|
'获取批量加车原始数据',
|
|
1014
1014
|
res,
|
|
1015
1015
|
'====转换后的json数据为===',
|
|
1016
1016
|
getMessageJsonData,
|
|
1017
1017
|
);
|
|
1018
1018
|
try {
|
|
1019
1019
|
if (isAndroidDevice) {
|
|
1020
1020
|
const isOk = getMessageJsonData?.status === '0';
|
|
1021
1021
|
isOk? resolve({
|
|
1022
1022
|
ok: true,
|
|
1023
1023
|
msg: '已加入购物车!',
|
|
1024
1024
|
})
|
|
1025
1025
|
: resolve({
|
|
1026
1026
|
ok: false,
|
|
1027
1027
|
msg: '加购失败,请稍后重试',
|
|
1028
1028
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
1029
1029
|
});
|
|
1030
1030
|
|
|
1031
1031
|
if(!isOk){
|
|
1032
1032
|
const data = {
|
|
1033
1033
|
type: 'batchAddCart',
|
|
1034
1034
|
subType: 'addCartFailByH5CallAndroidNative',
|
|
1035
1035
|
errMsg: 'H5调用安卓原生加车失败',
|
|
1036
1036
|
originData: getMessageJsonData
|
|
1037
1037
|
}
|
|
1038
1038
|
draBusinessCustomReport(data)
|
|
1039
1039
|
}
|
|
1040
1040
|
} else if (isIosDevice) {
|
|
1041
1041
|
const isOk = getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
|
|
1042
1042
|
isOk? resolve({
|
|
1043
1043
|
ok: true,
|
|
1044
1044
|
msg: '已加入购物车!',
|
|
1045
1045
|
})
|
|
1046
1046
|
: resolve({
|
|
1047
1047
|
ok: false,
|
|
1048
1048
|
msg: '批量加车失败,请稍后重试',
|
|
1049
1049
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
1050
1050
|
});
|
|
1051
1051
|
if(!isOk){
|
|
1052
1052
|
const data = {
|
|
1053
1053
|
type: 'batchAddCart',
|
|
1054
1054
|
subType: 'addCartFailByH5CallIosNative',
|
|
1055
1055
|
errMsg: 'H5调用IOS原生加车失败',
|
|
1056
1056
|
originData: getMessageJsonData
|
|
1057
1057
|
}
|
|
1058
1058
|
draBusinessCustomReport(data)
|
|
1059
1059
|
}
|
|
1060
1060
|
} else {
|
|
1061
1061
|
resolve({
|
|
1062
1062
|
ok: false,
|
|
1063
1063
|
msg: '加购失败,请稍后重试',
|
|
1064
1064
|
});
|
|
1065
1065
|
const data = {
|
|
1066
1066
|
type: 'batchAddCart',
|
|
1067
1067
|
subType: 'addCartFailByH5CallUnknownNative',
|
|
1068
1068
|
errMsg: 'H5调用未知原生加车失败',
|
|
1069
1069
|
}
|
|
1070
1070
|
draBusinessCustomReport(data)
|
|
1071
1071
|
}
|
|
1072
1072
|
} catch (e) {
|
|
1073
1073
|
resolve({
|
|
1074
1074
|
ok: false,
|
|
1075
1075
|
msg: '加购失败,请稍后重试',
|
|
1076
1076
|
});
|
|
1077
1077
|
console.warn('批量加车转换数据异常', e);
|
|
1078
1078
|
const data = {
|
|
1079
1079
|
type: 'batchAddCart',
|
|
1080
1080
|
subType: 'addCartFailByTransformData',
|
|
1081
1081
|
errMsg: '批量加车转换数据异常',
|
|
1082
1082
|
originData: e
|
|
1083
1083
|
}
|
|
1084
1084
|
draBusinessCustomReport(data)
|
|
1085
1085
|
}
|
|
1086
1086
|
window[nativeAddCartCallBack] = null;
|
|
1087
1087
|
};
|
|
1088
1088
|
}
|
|
1089
1089
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
1090
1090
|
return isAndroidDevice
|
|
1091
1091
|
? {
|
|
1092
1092
|
sku: skuItem,
|
|
1093
1093
|
num: addCardNum,
|
|
1094
1094
|
}
|
|
1095
1095
|
: {
|
|
1096
1096
|
productCode: skuItem,
|
|
1097
1097
|
buyCount: addCardNum,
|
|
1098
1098
|
};
|
|
1099
1099
|
});
|
|
1100
1100
|
if (isAndroidDevice) {
|
|
1101
1101
|
const androidProductsStr = JSON.stringify(productsAddCartList);
|
|
1102
1102
|
callRouterAndroid({
|
|
1103
1103
|
routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
|
|
1104
1104
|
routerParam: {
|
|
1105
1105
|
wareList: productsAddCartList,
|
|
1106
1106
|
},
|
|
1107
1107
|
callBackName: nativeAddCartCallBack,
|
|
1108
1108
|
});
|
|
1109
1109
|
} else if (isIosDevice) {
|
|
1110
1110
|
if (isLowAppVer) {
|
|
1111
1111
|
const lowVersionAppList = productIdsArr.map((skuItem) => {
|
|
1112
1112
|
return {
|
|
1113
1113
|
sku: skuItem,
|
|
1114
1114
|
num: addCardNum,
|
|
1115
1115
|
};
|
|
1116
1116
|
});
|
|
1117
1117
|
const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
|
|
1118
1118
|
const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
|
|
1119
1119
|
jump.side.jdJumpToWeb(url, {});
|
|
1120
1120
|
resolve({
|
|
1121
1121
|
ok: true,
|
|
1122
1122
|
isOpenApp: true,
|
|
1123
1123
|
msg: '加购完成, 加购结果请点击购物车确认',
|
|
1124
1124
|
});
|
|
1125
1125
|
} else {
|
|
1126
1126
|
callRouterIOS({
|
|
1127
1127
|
routerURL: 'router://JDCartModule/batchAddService',
|
|
1128
1128
|
routerParam: {
|
|
1129
1129
|
sourceType: 'h5',
|
|
1130
1130
|
sourceValue: '店铺批量加购',
|
|
1131
1131
|
businessName: 'storeModel',
|
|
1132
1132
|
isNewMode: '1',
|
|
1133
1133
|
NotPassWebview: '1',
|
|
1134
1134
|
products: productsAddCartList,
|
|
1135
1135
|
},
|
|
1136
1136
|
callBackName: nativeAddCartCallBack,
|
|
1137
1137
|
});
|
|
1138
1138
|
}
|
|
1139
1139
|
}
|
|
1140
1140
|
} else if (isMin) {
|
|
1141
1141
|
console.log('==========>', '京购批量加车!');
|
|
1142
1142
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
1143
1143
|
return {
|
|
1144
1144
|
skuId: skuItem,
|
|
1145
1145
|
buyNum: addCardNum,
|
|
1146
1146
|
};
|
|
1147
1147
|
});
|
|
1148
1148
|
global.wxAppBizInstance
|
|
1149
1149
|
.addCart({ commArr: productsAddCartList })
|
|
1150
1150
|
.then((res) => {
|
|
1151
1151
|
console.log('dealCartSuccess: ', res);
|
|
1152
1152
|
resolve({
|
|
1153
1153
|
ok: true,
|
|
1154
1154
|
msg: '已加入购物车!',
|
|
1155
1155
|
data: res,
|
|
1156
1156
|
});
|
|
1157
1157
|
})
|
|
1158
1158
|
.catch((e) => {
|
|
1159
1159
|
console.log('京购小程序批量加车失败dealCartFail: ', e);
|
|
1160
1160
|
resolve({
|
|
1161
1161
|
ok: false,
|
|
1162
1162
|
msg: '加购失败,请稍后重试',
|
|
1163
1163
|
});
|
|
1164
1164
|
|
|
1165
1165
|
const data = {
|
|
1166
1166
|
type: 'batchAddCart',
|
|
1167
1167
|
subType: 'addCartFailByH5CallMini',
|
|
1168
1168
|
errMsg: 'H5调用小程序加车失败',
|
|
1169
1169
|
originData: e
|
|
1170
1170
|
}
|
|
1171
1171
|
draBusinessCustomReport(data)
|
|
1172
1172
|
});
|
|
1173
1173
|
} else {
|
|
1174
1174
|
console.log('==========>', 'M站批量加车!');
|
|
1175
1175
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
|
|
1176
1176
|
}
|
|
1177
1177
|
} else {
|
|
1178
1178
|
resolve({
|
|
1179
1179
|
ok: false,
|
|
1180
1180
|
msg: '加购sku不能为空',
|
|
1181
1181
|
});
|
|
1182
1182
|
const data = {
|
|
1183
1183
|
type: 'batchAddCart',
|
|
1184
1184
|
subType: 'addCartFailNoSku',
|
|
1185
1185
|
errMsg: '加购sku不能为空',
|
|
1186
1186
|
originData: skuIdsStr
|
|
1187
1187
|
}
|
|
1188
1188
|
draBusinessCustomReport(data)
|
|
1189
1189
|
}
|
|
1190
1190
|
});
|
|
1191
1191
|
}
|
|
1192
1192
|
|
|
1193
1193
|
productAddToCart(skuIdsStr, num) {
|
|
1194
1194
|
return new Promise((resolve) => {
|
|
1195
1195
|
if (window.AddcartToolObj) {
|
|
1196
1196
|
window.AddcartToolObj.addCart({
|
|
1197
1197
|
skuId: skuIdsStr,
|
|
1198
1198
|
num,
|
|
1199
1199
|
source: 'sjdpyw',
|
|
1200
1200
|
actId: '1',
|
|
1201
1201
|
loginType: window?.isJingGouMiniViewState ? '11' : '2',
|
|
1202
1202
|
sucFun(res) {
|
|
1203
1203
|
console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
|
|
1204
1204
|
if (res.errId === '0' && res.cartJson) {
|
|
1205
1205
|
resolve({
|
|
1206
1206
|
ok: true,
|
|
1207
1207
|
msg: '已加入购物车!',
|
|
1208
1208
|
...res,
|
|
1209
1209
|
});
|
|
1210
1210
|
} else {
|
|
1211
1211
|
if (res.errId === '13') {
|
|
1212
1212
|
global.doLogin();
|
|
1213
1213
|
} else {
|
|
1214
1214
|
resolve({
|
|
1215
1215
|
ok: false,
|
|
1216
1216
|
msg: '加购失败,请稍后重试',
|
|
1217
1217
|
...res,
|
|
1218
1218
|
});
|
|
1219
1219
|
const data = {
|
|
1220
1220
|
type: 'batchAddCart',
|
|
1221
1221
|
subType: 'addCartFailByH5CallM',
|
|
1222
1222
|
errMsg: 'H5调用M站加车失败',
|
|
1223
1223
|
originData: res
|
|
1224
1224
|
}
|
|
1225
1225
|
draBusinessCustomReport(data)
|
|
1226
1226
|
}
|
|
1227
1227
|
}
|
|
1228
1228
|
},
|
|
1229
1229
|
failFun(err) {
|
|
1230
1230
|
console.log('fail', err);
|
|
1231
1231
|
resolve({
|
|
1232
1232
|
ok: false,
|
|
1233
1233
|
msg: '加购失败,请稍后重试',
|
|
1234
1234
|
...err,
|
|
1235
1235
|
});
|
|
1236
1236
|
const data = {
|
|
1237
1237
|
type: 'batchAddCart',
|
|
1238
1238
|
subType: 'addCartFailByH5CallM',
|
|
1239
1239
|
errMsg: 'H5调用M站加车失败',
|
|
1240
1240
|
originData: err
|
|
1241
1241
|
}
|
|
1242
1242
|
draBusinessCustomReport(data)
|
|
1243
1243
|
},
|
|
1244
1244
|
});
|
|
1245
1245
|
} else {
|
|
1246
1246
|
resolve({
|
|
1247
1247
|
ok: false,
|
|
1248
1248
|
msg: '购物车方法检查异常',
|
|
1249
1249
|
});
|
|
1250
1250
|
const data = {
|
|
1251
1251
|
type: 'batchAddCart',
|
|
1252
1252
|
subType: 'addCartFailByH5CallM',
|
|
1253
1253
|
errMsg: 'H5调用M站加车检查依赖方法异常',
|
|
1254
1254
|
}
|
|
1255
1255
|
draBusinessCustomReport(data)
|
|
1256
1256
|
}
|
|
1257
1257
|
});
|
|
1258
1258
|
}
|
|
1259
1259
|
bMallGetUserInfo = () => {
|
|
1260
1260
|
return getBMallUserInfo();
|
|
1261
1261
|
};
|
|
1262
1262
|
async bMallAddCart(params = {}) {
|
|
1263
1263
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
1264
1264
|
client: 'H5',
|
|
1265
1265
|
clientVersion: '5.5.0',
|
|
1266
1266
|
});
|
|
1267
1267
|
}
|
|
1268
1268
|
async bMallChangeCart(params = {}) {
|
|
1269
1269
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
1270
1270
|
client: 'H5',
|
|
1271
1271
|
clientVersion: '5.5.0',
|
|
1272
1272
|
});
|
|
1273
1273
|
}
|
|
1274
1274
|
async bMallRemoveCart(params = {}) {
|
|
1275
1275
|
return await this.gatewayReq(
|
|
1276
1276
|
'bmall_cartRemove',
|
|
1277
1277
|
params,
|
|
1278
1278
|
{
|
|
1279
1279
|
client: 'H5',
|
|
1280
1280
|
clientVersion: '5.5.0',
|
|
1281
1281
|
},
|
|
1282
1282
|
);
|
|
1283
1283
|
}
|
|
1284
1284
|
async bMallGetOmittedProduct(params = {}) {
|
|
1285
1285
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
1286
1286
|
client: 'H5',
|
|
1287
1287
|
clientVersion: '5.5.0',
|
|
1288
1288
|
});
|
|
1289
1289
|
}
|
|
1290
1290
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
1291
1291
|
const params = await getParams({ ...data, skuId, bMallTag, num });
|
|
1292
1292
|
return await this.bMallAddCart(params);
|
|
1293
1293
|
}
|
|
1294
1294
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
1295
1295
|
const params = await getParams({ bMallTag });
|
|
1296
1296
|
delete params.operations;
|
|
1297
1297
|
return await this.bMallGetOmittedProduct(params);
|
|
1298
1298
|
}
|
|
1299
1299
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
1300
1300
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
1301
1301
|
return await this.bMallRemoveCart(params);
|
|
1302
1302
|
}
|
|
1303
1303
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
1304
1304
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
1305
1305
|
return await this.bMallChangeCart(params);
|
|
1306
1306
|
}
|
|
1307
1307
|
|
|
1308
1308
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
1309
1309
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
1310
1310
|
return window?.bMallCartData;
|
|
1311
1311
|
}
|
|
1312
1312
|
const cartData = await this.bMallGetSkuNumService(bMallTag);
|
|
1313
1313
|
let items;
|
|
1314
1314
|
if (cartData.ok && cartData.result) {
|
|
1315
1315
|
items = cartData?.result?.items || {};
|
|
1316
1316
|
}
|
|
1317
1317
|
if (isH5) {
|
|
1318
1318
|
window.bMallCartData = items;
|
|
1319
1319
|
}
|
|
1320
1320
|
return items;
|
|
1321
1321
|
}
|
|
1322
1322
|
|
|
1323
1323
|
async bMallCartHandle(goodItem, num) {
|
|
1324
1324
|
try {
|
|
1325
1325
|
const {
|
|
1326
1326
|
skuUuid,
|
|
1327
1327
|
limitUpper,
|
|
1328
1328
|
limitLower,
|
|
1329
1329
|
} = goodItem;
|
|
1330
1330
|
let cartNum = Number(num);
|
|
1331
1331
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
1332
1332
|
cartNum = limitLower;
|
|
1333
1333
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
1334
1334
|
cartNum = limitUpper;
|
|
1335
1335
|
}
|
|
1336
1336
|
if (skuUuid && cartNum > 0) {
|
|
1337
1337
|
return this.bMallChangeCartService({
|
|
1338
1338
|
...goodItem,
|
|
1339
1339
|
skuUuid,
|
|
1340
1340
|
num: cartNum,
|
|
1341
1341
|
});
|
|
1342
1342
|
} else if (!skuUuid && cartNum > 0) {
|
|
1343
1343
|
return this.bMallAddCartService({ ...goodItem, num: cartNum });
|
|
1344
1344
|
} else if (skuUuid && !cartNum) {
|
|
1345
1345
|
return this.bMallRemoveCartService({
|
|
1346
1346
|
...goodItem,
|
|
1347
1347
|
skuUuid,
|
|
1348
1348
|
num: cartNum,
|
|
1349
1349
|
});
|
|
1350
1350
|
} else {
|
|
1351
1351
|
console.error('参数不全');
|
|
1352
1352
|
return false;
|
|
1353
1353
|
}
|
|
1354
1354
|
} catch (e) {
|
|
1355
1355
|
console.error(e);
|
|
1356
1356
|
}
|
|
1357
1357
|
}
|