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