@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
|
isLanguageForEn,
|
|
13
12
|
isJdApp,
|
|
14
13
|
showSuccessToast,
|
|
15
14
|
showFailToast,
|
|
16
15
|
isH5,
|
|
17
16
|
isWxMinAndWxapp,
|
|
18
17
|
isMin,
|
|
19
18
|
isPc,
|
|
20
19
|
cookiesStr: '',
|
|
21
20
|
requestHeaderContentType: {
|
|
22
21
|
jsonHeader: {
|
|
23
22
|
'content-type': 'application/json;charset=utf-8',
|
|
24
23
|
},
|
|
25
24
|
formDataHeader: {
|
|
26
25
|
'content-type': 'application/x-www-form-urlencoded',
|
|
27
26
|
},
|
|
28
27
|
},
|
|
29
28
|
requestBaseParam: {
|
|
30
29
|
data: null,
|
|
31
30
|
header: {
|
|
32
31
|
'content-type': 'application/json;charset=utf-8',
|
|
33
32
|
},
|
|
34
33
|
},
|
|
35
34
|
timeOut: 7000,
|
|
36
35
|
apiClientParams: {
|
|
37
36
|
appid: 'wx_mini_app',
|
|
38
37
|
clientVersion: '11.0.0',
|
|
39
38
|
client: 'wh5',
|
|
40
39
|
area: '1_72_2799_0',
|
|
41
40
|
screen: `${Math.ceil(getSystemInfo?.screenWidth * devicePixelRatio)}*${Math.ceil(
|
|
42
41
|
getSystemInfo?.screenHeight * devicePixelRatio,
|
|
43
42
|
)}`,
|
|
44
43
|
uuid: UUID,
|
|
45
44
|
loginType: '11',
|
|
46
45
|
},
|
|
47
46
|
public addressFetchInfo: {
|
|
48
47
|
reqState: boolean;
|
|
49
48
|
promiseInstance: null | Promise<any>;
|
|
50
49
|
};
|
|
51
50
|
public getPromotionConfig: {
|
|
52
51
|
projectId: null | string | number;
|
|
53
52
|
pageId: null | string | number;
|
|
54
53
|
};
|
|
55
54
|
public resInfo: ServiceInterFace.HttpRequestInfo;
|
|
56
55
|
public api: ServiceInterFace.HttpApi;
|
|
57
56
|
public isPageDomain: boolean;
|
|
58
57
|
public verifyColorList: string[];
|
|
59
58
|
constructor(opt) {
|
|
60
59
|
this._init();
|
|
61
60
|
this.addressFetchInfo = {
|
|
62
61
|
reqState: false,
|
|
63
62
|
promiseInstance: null,
|
|
64
63
|
};
|
|
65
64
|
this.getPromotionConfig = {
|
|
66
65
|
projectId: null,
|
|
67
66
|
pageId: null,
|
|
68
67
|
};
|
|
69
68
|
this._userAreaUpdateListen();
|
|
70
69
|
this.resInfo = this._getResConfig(opt);
|
|
71
70
|
this.api = api;
|
|
72
71
|
this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
|
|
73
72
|
this.verifyColorList = [
|
|
74
73
|
...MobileVerifyColorList,
|
|
75
74
|
...AppVerifyColorList,
|
|
76
75
|
...JshopxVerifyColorList,
|
|
77
76
|
...BMallVerifyColorList,
|
|
78
77
|
];
|
|
79
78
|
}
|
|
80
79
|
_init(): void {
|
|
81
80
|
httpInterceptors.forEach((item) => {
|
|
82
81
|
Taro.addInterceptor((chain) => item(chain));
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
84
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
86
85
|
return Object.assign({}, DefaultConfig, opt);
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
_userAreaUpdateListen() {
|
|
90
89
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
|
|
91
90
|
this.updateApiClientParamsResInfo(areaInfo);
|
|
92
91
|
});
|
|
93
92
|
}
|
|
94
93
|
updateApiClientParamsResInfo(opt = {}) {
|
|
95
94
|
const { area, realTimeArea, ...others } = opt;
|
|
96
95
|
this.resInfo.apiClientParams = {
|
|
97
96
|
...this.resInfo.apiClientParams,
|
|
98
97
|
...others,
|
|
99
98
|
};
|
|
100
99
|
area && area !== '' && (this.resInfo.apiClientParams.area = area);
|
|
101
100
|
realTimeArea &&
|
|
102
101
|
realTimeArea !== '' &&
|
|
103
102
|
(this.resInfo.apiClientParams.realTimeArea = realTimeArea);
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
checkFunctionIdToReturnAppId(functionId) {
|
|
107
106
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
108
107
|
return APPID.JSHOPX_COLOR_APPID;
|
|
109
108
|
} else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
|
|
110
109
|
return APPID.PAGES_COLOR_APPID;
|
|
111
110
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
112
111
|
return APPID.SHOP_MEMBER_COLOR_APPID;
|
|
113
112
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
114
113
|
return APPID.B2B_COLOR_APPID;
|
|
115
114
|
} else if (isPc) {
|
|
116
115
|
return APPID.MALL_COLOR_APPID;
|
|
117
116
|
} else {
|
|
118
117
|
return APPID.SHOP_COLOR_APPID;
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
123
122
|
if (functionId === 'receiveShopCoupon') {
|
|
124
123
|
clientParams = Object.assign(
|
|
125
124
|
{},
|
|
126
125
|
{
|
|
127
126
|
loginType: '1',
|
|
128
127
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
129
128
|
},
|
|
130
129
|
clientParams,
|
|
131
130
|
);
|
|
132
131
|
}
|
|
133
132
|
const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
|
|
134
133
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
135
134
|
const getReqData = {
|
|
136
135
|
functionId: functionId,
|
|
137
136
|
body: JSON.stringify(bodyParams),
|
|
138
137
|
t: Date.now(),
|
|
139
138
|
...apiClientParams,
|
|
140
139
|
};
|
|
141
140
|
return http
|
|
142
141
|
.request({
|
|
143
142
|
url: this.api.apiFunc,
|
|
144
143
|
data: getReqData,
|
|
145
144
|
isColorVerify,
|
|
146
145
|
})
|
|
147
146
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
148
147
|
const { statusCode, data } = res;
|
|
149
148
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
150
149
|
ok: true,
|
|
151
150
|
};
|
|
152
151
|
if (statusCode === 200 && data) {
|
|
153
152
|
const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
|
|
154
153
|
? Number(res.data.code)
|
|
155
154
|
: -1;
|
|
156
155
|
const subCode = Object.prototype.hasOwnProperty.call(res.data, 'subCode')
|
|
157
156
|
? Number(res.data.subCode)
|
|
158
157
|
: -1;
|
|
159
158
|
if (
|
|
160
159
|
data.success === true ||
|
|
161
160
|
data.isSuccess ||
|
|
162
161
|
resCode === 0 ||
|
|
163
162
|
resCode === 200 ||
|
|
164
163
|
subCode === 0
|
|
165
164
|
) {
|
|
166
165
|
changeRes = {
|
|
167
166
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
168
167
|
? data.result
|
|
169
168
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
170
169
|
? data.data
|
|
171
170
|
: data,
|
|
172
171
|
code: data.code || 200,
|
|
173
172
|
ok: true,
|
|
174
173
|
source: data,
|
|
175
174
|
};
|
|
176
175
|
return changeRes;
|
|
177
176
|
} else {
|
|
178
177
|
changeRes = {
|
|
179
178
|
...data,
|
|
180
179
|
ok: false,
|
|
181
180
|
statusCode: res.statusCode,
|
|
182
181
|
};
|
|
183
182
|
return changeRes;
|
|
184
183
|
}
|
|
185
184
|
} else {
|
|
186
185
|
changeRes = {
|
|
187
186
|
...data,
|
|
188
187
|
ok: false,
|
|
189
188
|
statusCode: res.statusCode,
|
|
190
189
|
};
|
|
191
190
|
return changeRes;
|
|
192
191
|
}
|
|
193
192
|
})
|
|
194
193
|
.catch((res) => {
|
|
195
194
|
return {
|
|
196
195
|
...res,
|
|
197
196
|
ok: false,
|
|
198
197
|
} as ServiceInterFace.RequestResponseFormatRes;
|
|
199
198
|
});
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
async receiveCoupon(param = {}, clientParams) {
|
|
203
202
|
console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
204
203
|
return await this.gatewayReq(
|
|
205
204
|
'receiveShopCoupon',
|
|
206
205
|
{
|
|
207
206
|
operation: '3',
|
|
208
207
|
...param,
|
|
209
208
|
},
|
|
210
209
|
{ ...clientParams },
|
|
211
210
|
);
|
|
212
211
|
}
|
|
213
212
|
|
|
214
213
|
getCustomerCenterDispatch(params = {}) {
|
|
215
214
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
216
215
|
clientVersion: '9.2.0',
|
|
217
216
|
client: 'H5',
|
|
218
217
|
uuid: 88888,
|
|
219
218
|
appid: 'shopmember_m_jd_com',
|
|
220
219
|
});
|
|
221
220
|
}
|
|
222
221
|
|
|
223
222
|
batchAddCart(...args) {
|
|
224
223
|
let skuIds, num, showToast, giftCard;
|
|
225
224
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
226
225
|
[skuIds, num = 1, showToast = true, giftCard = false] = args;
|
|
227
226
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
228
227
|
const params = args[0];
|
|
229
228
|
skuIds = params.skuIds;
|
|
230
229
|
num = params.num || 1;
|
|
231
230
|
showToast = params.showToast !== undefined ? params.showToast : true;
|
|
232
231
|
giftCard = params.giftCard !== undefined ? params.giftCard : false;
|
|
233
232
|
} else {
|
|
234
233
|
console.error('batchAddCart() Invalid arguments!', args);
|
|
235
234
|
const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
|
|
236
235
|
showFailToast({
|
|
237
236
|
title: msg,
|
|
238
237
|
});
|
|
239
238
|
return Promise.resolve({
|
|
240
239
|
ok: false,
|
|
241
240
|
msg,
|
|
242
241
|
});
|
|
243
242
|
}
|
|
244
243
|
const addToWhereText = giftCard ? '购物清单' : '购物车';
|
|
245
244
|
const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
|
|
246
245
|
const failMsg = isLanguageForEn
|
|
247
246
|
? 'Please retry later'
|
|
248
247
|
: `加入${addToWhereText}失败,请稍后重试!`;
|
|
249
248
|
if (skuIds) {
|
|
250
249
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
|
|
251
250
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
252
251
|
if (res?.ok) {
|
|
253
252
|
if (showToast && !res?.isOpenApp)
|
|
254
253
|
showSuccessToast({
|
|
255
254
|
title: successMsg,
|
|
256
255
|
});
|
|
257
256
|
} else {
|
|
258
257
|
showToast &&
|
|
259
258
|
showFailToast({
|
|
260
259
|
title: res?.errMsg || failMsg,
|
|
261
260
|
});
|
|
262
261
|
}
|
|
263
262
|
return Promise.resolve(res);
|
|
264
263
|
})
|
|
265
264
|
.catch((e) => {
|
|
266
265
|
console.log('调用加购方法异常=======>', e);
|
|
267
266
|
return Promise.resolve({
|
|
268
267
|
ok: false,
|
|
269
268
|
msg: failMsg,
|
|
270
269
|
});
|
|
271
270
|
});
|
|
272
271
|
} else {
|
|
273
272
|
return Promise.resolve({
|
|
274
273
|
ok: false,
|
|
275
274
|
msg: failMsg,
|
|
276
275
|
});
|
|
277
276
|
}
|
|
278
277
|
}
|
|
279
278
|
|
|
280
279
|
async giftCardAddCart(skuList, num) {
|
|
281
280
|
return this.gatewayReq('giftCardAddCart', {
|
|
282
281
|
skuList,
|
|
283
282
|
num: Number(num),
|
|
284
283
|
});
|
|
285
284
|
}
|
|
286
285
|
|
|
287
286
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
|
|
288
287
|
return new Promise((resolve) => {
|
|
289
288
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
|
|
290
289
|
if (productIdsArr.length > 0) {
|
|
291
290
|
if (giftCard) {
|
|
292
291
|
this.giftCardAddCart(productIdsArr, addCardNum)
|
|
293
292
|
.then((res) => {
|
|
294
293
|
if (res?.code === '0' && res?.result?.value) {
|
|
295
294
|
resolve({
|
|
296
295
|
ok: true,
|
|
297
296
|
});
|
|
298
297
|
} else {
|
|
299
298
|
resolve({
|
|
300
299
|
ok: false,
|
|
301
300
|
msg: '加购失败,请稍后重试',
|
|
302
301
|
});
|
|
303
302
|
}
|
|
304
303
|
})
|
|
305
304
|
.catch((e) => {
|
|
306
305
|
console.error('礼品卡加车失败: ', e);
|
|
307
306
|
resolve({
|
|
308
307
|
ok: false,
|
|
309
308
|
msg: '加购失败,请稍后重试',
|
|
310
309
|
});
|
|
311
310
|
});
|
|
312
311
|
} else if (isJdApp) {
|
|
313
312
|
console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
|
|
314
313
|
} else if (isMin) {
|
|
315
314
|
console.log('==========>', '京购批量加车!');
|
|
316
315
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
317
316
|
return {
|
|
318
317
|
skuId: skuItem,
|
|
319
318
|
buyNum: addCardNum,
|
|
320
319
|
};
|
|
321
320
|
});
|
|
322
321
|
global.wxAppBizInstance
|
|
323
322
|
.addCart({ commArr: productsAddCartList })
|
|
324
323
|
.then((res) => {
|
|
325
324
|
console.log('dealCartSuccess: ', res);
|
|
326
325
|
resolve({
|
|
327
326
|
ok: true,
|
|
328
327
|
msg: '已加入购物车!',
|
|
329
328
|
data: res,
|
|
330
329
|
});
|
|
331
330
|
})
|
|
332
331
|
.catch((e) => {
|
|
333
332
|
console.log('京购小程序批量加车失败dealCartFail: ', e);
|
|
334
333
|
resolve({
|
|
335
334
|
ok: false,
|
|
336
335
|
msg: '加购失败,请稍后重试',
|
|
337
336
|
});
|
|
338
337
|
});
|
|
339
338
|
} else {
|
|
340
339
|
console.log('==========>', 'M站批量加车!');
|
|
341
340
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
|
|
342
341
|
}
|
|
343
342
|
} else {
|
|
344
343
|
resolve({
|
|
345
344
|
ok: false,
|
|
346
345
|
msg: '加购sku不能为空',
|
|
347
346
|
});
|
|
348
347
|
}
|
|
349
348
|
});
|
|
350
349
|
}
|
|
351
350
|
|
|
352
351
|
productAddToCart() {
|
|
353
352
|
return Promise.resolve({
|
|
354
353
|
ok: false,
|
|
355
354
|
msg: 'productAddToCart暂不支持小程序',
|
|
356
355
|
});
|
|
357
356
|
}
|
|
358
357
|
bMallGetUserInfo = () => {
|
|
359
358
|
return getBMallUserInfo();
|
|
360
359
|
};
|
|
361
360
|
async bMallAddCart(params = {}) {
|
|
362
361
|
console.warn('bMallAddCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
363
362
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
364
363
|
client: 'H5',
|
|
365
364
|
clientVersion: '5.5.0',
|
|
366
365
|
});
|
|
367
366
|
}
|
|
368
367
|
async bMallChangeCart(params = {}) {
|
|
369
368
|
console.warn('bMallChangeCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
370
369
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
371
370
|
client: 'H5',
|
|
372
371
|
clientVersion: '5.5.0',
|
|
373
372
|
});
|
|
374
373
|
}
|
|
375
374
|
async bMallRemoveCart(params = {}) {
|
|
376
375
|
console.warn('bMallRemoveCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
377
376
|
return await this.gatewayReq(
|
|
378
377
|
'bmall_cartRemove',
|
|
379
378
|
params,
|
|
380
379
|
{
|
|
381
380
|
client: 'H5',
|
|
382
381
|
clientVersion: '5.5.0',
|
|
383
382
|
},
|
|
384
383
|
);
|
|
385
384
|
}
|
|
386
385
|
async bMallGetOmittedProduct(params = {}) {
|
|
387
386
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
388
387
|
client: 'H5',
|
|
389
388
|
clientVersion: '5.5.0',
|
|
390
389
|
});
|
|
391
390
|
}
|
|
392
391
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
393
392
|
const params = await getParams({ ...data, skuId, bMallTag, num });
|
|
394
393
|
return await this.bMallAddCart(params);
|
|
395
394
|
}
|
|
396
395
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
397
396
|
const params = await getParams({ bMallTag });
|
|
398
397
|
delete params.operations;
|
|
399
398
|
return await this.bMallGetOmittedProduct(params);
|
|
400
399
|
}
|
|
401
400
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
402
401
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
403
402
|
return await this.bMallRemoveCart(params);
|
|
404
403
|
}
|
|
405
404
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
406
405
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
407
406
|
return await this.bMallChangeCart(params);
|
|
408
407
|
}
|
|
409
408
|
|
|
410
409
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
411
410
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
412
411
|
return window?.bMallCartData;
|
|
413
412
|
}
|
|
414
413
|
const cartData = await this.bMallGetSkuNumService(bMallTag);
|
|
415
414
|
let items;
|
|
416
415
|
if (cartData.ok && cartData.result) {
|
|
417
416
|
items = cartData?.result?.items || {};
|
|
418
417
|
}
|
|
419
418
|
if (isH5) {
|
|
420
419
|
window.bMallCartData = items;
|
|
421
420
|
}
|
|
422
421
|
return items;
|
|
423
422
|
}
|
|
424
423
|
|
|
425
424
|
async bMallCartHandle(goodItem, num) {
|
|
426
425
|
try {
|
|
427
426
|
const {
|
|
428
427
|
skuUuid,
|
|
429
428
|
limitUpper,
|
|
430
429
|
limitLower,
|
|
431
430
|
} = goodItem;
|
|
432
431
|
let cartNum = Number(num);
|
|
433
432
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
434
433
|
cartNum = limitLower;
|
|
435
434
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
436
435
|
cartNum = limitUpper;
|
|
437
436
|
}
|
|
438
437
|
if (skuUuid && cartNum > 0) {
|
|
439
438
|
return this.bMallChangeCartService({
|
|
440
439
|
...goodItem,
|
|
441
440
|
skuUuid,
|
|
442
441
|
num: cartNum,
|
|
443
442
|
});
|
|
444
443
|
} else if (!skuUuid && cartNum > 0) {
|
|
445
444
|
return this.bMallAddCartService({ ...goodItem, num: cartNum });
|
|
446
445
|
} else if (skuUuid && !cartNum) {
|
|
447
446
|
return this.bMallRemoveCartService({
|
|
448
447
|
...goodItem,
|
|
449
448
|
skuUuid,
|
|
450
449
|
num: cartNum,
|
|
451
450
|
});
|
|
452
451
|
} else {
|
|
453
452
|
console.error('参数不全');
|
|
454
453
|
return false;
|
|
455
454
|
}
|
|
456
455
|
} catch (e) {
|
|
457
456
|
console.error(e);
|
|
458
457
|
}
|
|
459
458
|
}
|
|
459
|
+
import Taro from '@tarojs/taro';
|
|
460
460
|
WxappVerifyColorList,
|
|
461
461
|
isLanguageForEn,
|
|
462
462
|
isJdApp,
|
|
463
463
|
showSuccessToast,
|
|
464
464
|
showFailToast,
|
|
465
465
|
isMin,
|
|
466
466
|
cookiesStr: '',
|
|
467
467
|
requestHeaderContentType: {
|
|
468
468
|
jsonHeader: {
|
|
469
469
|
'content-type': 'application/json;charset=utf-8',
|
|
470
470
|
},
|
|
471
471
|
formDataHeader: {
|
|
472
472
|
'content-type': 'application/x-www-form-urlencoded',
|
|
473
473
|
},
|
|
474
474
|
},
|
|
475
475
|
requestBaseParam: {
|
|
476
476
|
data: null,
|
|
477
477
|
header: {
|
|
478
478
|
'content-type': 'application/json;charset=utf-8',
|
|
479
479
|
},
|
|
480
480
|
},
|
|
481
481
|
timeOut: 7000,
|
|
482
482
|
apiClientParams: {
|
|
483
483
|
appid: 'wx_mini_app',
|
|
484
484
|
clientVersion: '11.0.0',
|
|
485
485
|
client: 'wh5',
|
|
486
486
|
area: '1_72_2799_0',
|
|
487
487
|
screen: `${Math.ceil(getSystemInfo?.screenWidth * devicePixelRatio)}*${Math.ceil(
|
|
488
488
|
getSystemInfo?.screenHeight * devicePixelRatio,
|
|
489
489
|
)}`,
|
|
490
490
|
uuid: '-1',
|
|
491
491
|
loginType: '11',
|
|
492
492
|
},
|
|
493
493
|
public addressFetchInfo: {
|
|
494
494
|
reqState: boolean;
|
|
495
495
|
promiseInstance: null | Promise<any>;
|
|
496
496
|
};
|
|
497
497
|
public getPromotionConfig: {
|
|
498
498
|
projectId: null | string | number;
|
|
499
499
|
pageId: null | string | number;
|
|
500
500
|
};
|
|
501
501
|
public resInfo: ServiceInterFace.HttpRequestInfo;
|
|
502
502
|
public api: ServiceInterFace.HttpApi;
|
|
503
503
|
public verifyColorList: string[];
|
|
504
504
|
constructor(opt) {
|
|
505
505
|
this._init();
|
|
506
506
|
this.addressFetchInfo = {
|
|
507
507
|
reqState: false,
|
|
508
508
|
promiseInstance: null,
|
|
509
509
|
};
|
|
510
510
|
this.getPromotionConfig = {
|
|
511
511
|
projectId: null,
|
|
512
512
|
pageId: null,
|
|
513
513
|
};
|
|
514
514
|
this._userAreaUpdateListen();
|
|
515
515
|
this.resInfo = this._getResConfig(opt);
|
|
516
516
|
this.api = api;
|
|
517
517
|
this.verifyColorList = [
|
|
518
518
|
...WxappVerifyColorList,
|
|
519
519
|
];
|
|
520
520
|
}
|
|
521
521
|
_init(): void {
|
|
522
522
|
httpInterceptors.forEach((item) => {
|
|
523
523
|
Taro.addInterceptor((chain) => item(chain));
|
|
524
524
|
});
|
|
525
525
|
}
|
|
526
526
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
527
527
|
return Object.assign({}, DefaultConfig, opt);
|
|
528
528
|
}
|
|
529
529
|
|
|
530
530
|
_userAreaUpdateListen() {
|
|
531
531
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
|
|
532
532
|
this.updateApiClientParamsResInfo(areaInfo);
|
|
533
533
|
});
|
|
534
534
|
}
|
|
535
535
|
updateApiClientParamsResInfo(opt = {}) {
|
|
536
536
|
const { area, realTimeArea, ...others } = opt;
|
|
537
537
|
this.resInfo.apiClientParams = {
|
|
538
538
|
...this.resInfo.apiClientParams,
|
|
539
539
|
...others,
|
|
540
540
|
};
|
|
541
541
|
area && area !== '' && (this.resInfo.apiClientParams.area = area);
|
|
542
542
|
realTimeArea &&
|
|
543
543
|
realTimeArea !== '' &&
|
|
544
544
|
(this.resInfo.apiClientParams.realTimeArea = realTimeArea);
|
|
545
545
|
}
|
|
546
546
|
|
|
547
547
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
548
548
|
if (functionId === 'receiveShopCoupon') {
|
|
549
549
|
clientParams = Object.assign(
|
|
550
550
|
{},
|
|
551
551
|
{
|
|
552
552
|
loginType: '1',
|
|
553
553
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
554
554
|
},
|
|
555
555
|
clientParams,
|
|
556
556
|
);
|
|
557
557
|
}
|
|
558
558
|
const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
|
|
559
559
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
560
560
|
const getReqData = {
|
|
561
561
|
functionId: functionId,
|
|
562
562
|
body: JSON.stringify(bodyParams),
|
|
563
563
|
t: Date.now(),
|
|
564
564
|
...apiClientParams,
|
|
565
565
|
};
|
|
566
566
|
return http
|
|
567
567
|
.request({
|
|
568
568
|
url: this.api.apiFunc,
|
|
569
569
|
data: getReqData,
|
|
570
570
|
isColorVerify,
|
|
571
571
|
})
|
|
572
572
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
573
573
|
const { statusCode, data } = res;
|
|
574
574
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
575
575
|
ok: true,
|
|
576
576
|
};
|
|
577
577
|
if (statusCode === 200 && data) {
|
|
578
578
|
const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
|
|
579
579
|
? Number(res.data.code)
|
|
580
580
|
: -1;
|
|
581
581
|
const subCode = Object.prototype.hasOwnProperty.call(res.data, 'subCode')
|
|
582
582
|
? Number(res.data.subCode)
|
|
583
583
|
: -1;
|
|
584
584
|
if (
|
|
585
585
|
data.success === true ||
|
|
586
586
|
data.isSuccess ||
|
|
587
587
|
resCode === 0 ||
|
|
588
588
|
resCode === 200 ||
|
|
589
589
|
subCode === 0
|
|
590
590
|
) {
|
|
591
591
|
changeRes = {
|
|
592
592
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
593
593
|
? data.result
|
|
594
594
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
595
595
|
? data.data
|
|
596
596
|
: data,
|
|
597
597
|
code: data.code || 200,
|
|
598
598
|
ok: true,
|
|
599
599
|
source: data,
|
|
600
600
|
};
|
|
601
601
|
return changeRes;
|
|
602
602
|
} else {
|
|
603
603
|
changeRes = {
|
|
604
604
|
...data,
|
|
605
605
|
ok: false,
|
|
606
606
|
statusCode: res.statusCode,
|
|
607
607
|
};
|
|
608
608
|
return changeRes;
|
|
609
609
|
}
|
|
610
610
|
} else {
|
|
611
611
|
changeRes = {
|
|
612
612
|
...data,
|
|
613
613
|
ok: false,
|
|
614
614
|
statusCode: res.statusCode,
|
|
615
615
|
};
|
|
616
616
|
return changeRes;
|
|
617
617
|
}
|
|
618
618
|
})
|
|
619
619
|
.catch((res) => {
|
|
620
620
|
return {
|
|
621
621
|
...res,
|
|
622
622
|
ok: false,
|
|
623
623
|
} as ServiceInterFace.RequestResponseFormatRes;
|
|
624
624
|
});
|
|
625
625
|
}
|
|
626
626
|
|
|
627
627
|
async receiveCoupon(param = {}, clientParams) {
|
|
628
628
|
console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
629
629
|
return await this.gatewayReq(
|
|
630
630
|
'receiveShopCoupon',
|
|
631
631
|
{
|
|
632
632
|
operation: '3',
|
|
633
633
|
...param,
|
|
634
634
|
},
|
|
635
635
|
{ ...clientParams },
|
|
636
636
|
);
|
|
637
637
|
}
|
|
638
638
|
|
|
639
639
|
getCustomerCenterDispatch(params = {}) {
|
|
640
640
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
641
641
|
clientVersion: '9.2.0',
|
|
642
642
|
client: 'H5',
|
|
643
643
|
uuid: 88888,
|
|
644
644
|
appid: 'shopmember_m_jd_com',
|
|
645
645
|
});
|
|
646
646
|
}
|
|
647
647
|
|
|
648
648
|
batchAddCart(...args) {
|
|
649
649
|
let skuIds, num, showToast, giftCard;
|
|
650
650
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
651
651
|
[skuIds, num = 1, showToast = true, giftCard = false] = args;
|
|
652
652
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
653
653
|
const params = args[0];
|
|
654
654
|
skuIds = params.skuIds;
|
|
655
655
|
num = params.num || 1;
|
|
656
656
|
showToast = params.showToast !== undefined ? params.showToast : true;
|
|
657
657
|
giftCard = params.giftCard !== undefined ? params.giftCard : false;
|
|
658
658
|
} else {
|
|
659
659
|
console.error('batchAddCart() Invalid arguments!', args);
|
|
660
660
|
const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
|
|
661
661
|
showFailToast({
|
|
662
662
|
title: msg,
|
|
663
663
|
});
|
|
664
664
|
return Promise.resolve({
|
|
665
665
|
ok: false,
|
|
666
666
|
msg,
|
|
667
667
|
});
|
|
668
668
|
}
|
|
669
669
|
const addToWhereText = giftCard ? '购物清单' : '购物车';
|
|
670
670
|
const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
|
|
671
671
|
const failMsg = isLanguageForEn
|
|
672
672
|
? 'Please retry later'
|
|
673
673
|
: `加入${addToWhereText}失败,请稍后重试!`;
|
|
674
674
|
if (skuIds) {
|
|
675
675
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
|
|
676
676
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
677
677
|
if (res?.ok) {
|
|
678
678
|
if (showToast && !res?.isOpenApp)
|
|
679
679
|
showSuccessToast({
|
|
680
680
|
title: successMsg,
|
|
681
681
|
});
|
|
682
682
|
} else {
|
|
683
683
|
showToast &&
|
|
684
684
|
showFailToast({
|
|
685
685
|
title: res?.errMsg || failMsg,
|
|
686
686
|
});
|
|
687
687
|
}
|
|
688
688
|
return Promise.resolve(res);
|
|
689
689
|
})
|
|
690
690
|
.catch((e) => {
|
|
691
691
|
console.log('调用加购方法异常=======>', e);
|
|
692
692
|
return Promise.resolve({
|
|
693
693
|
ok: false,
|
|
694
694
|
msg: failMsg,
|
|
695
695
|
});
|
|
696
696
|
});
|
|
697
697
|
} else {
|
|
698
698
|
return Promise.resolve({
|
|
699
699
|
ok: false,
|
|
700
700
|
msg: failMsg,
|
|
701
701
|
});
|
|
702
702
|
}
|
|
703
703
|
}
|
|
704
704
|
|
|
705
705
|
async giftCardAddCart(skuList, num) {
|
|
706
706
|
return this.gatewayReq('giftCardAddCart', {
|
|
707
707
|
skuList,
|
|
708
708
|
num: Number(num),
|
|
709
709
|
});
|
|
710
710
|
}
|
|
711
711
|
|
|
712
712
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
|
|
713
713
|
return new Promise((resolve) => {
|
|
714
714
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
|
|
715
715
|
if (productIdsArr.length > 0) {
|
|
716
716
|
if (giftCard) {
|
|
717
717
|
this.giftCardAddCart(productIdsArr, addCardNum)
|
|
718
718
|
.then((res) => {
|
|
719
719
|
if (res?.code === '0' && res?.result?.value) {
|
|
720
720
|
resolve({
|
|
721
721
|
ok: true,
|
|
722
722
|
});
|
|
723
723
|
} else {
|
|
724
724
|
resolve({
|
|
725
725
|
ok: false,
|
|
726
726
|
msg: '加购失败,请稍后重试',
|
|
727
727
|
});
|
|
728
728
|
}
|
|
729
729
|
})
|
|
730
730
|
.catch((e) => {
|
|
731
731
|
console.error('礼品卡加车失败: ', e);
|
|
732
732
|
resolve({
|
|
733
733
|
ok: false,
|
|
734
734
|
msg: '加购失败,请稍后重试',
|
|
735
735
|
});
|
|
736
736
|
});
|
|
737
737
|
} else if (isJdApp) {
|
|
738
738
|
console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
|
|
739
739
|
} else if (isMin) {
|
|
740
740
|
console.log('==========>', '京购批量加车!');
|
|
741
741
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
742
742
|
return {
|
|
743
743
|
skuId: skuItem,
|
|
744
744
|
buyNum: addCardNum,
|
|
745
745
|
};
|
|
746
746
|
});
|
|
747
747
|
global.wxAppBizInstance
|
|
748
748
|
.addCart({ commArr: productsAddCartList })
|
|
749
749
|
.then((res) => {
|
|
750
750
|
console.log('dealCartSuccess: ', res);
|
|
751
751
|
resolve({
|
|
752
752
|
ok: true,
|
|
753
753
|
msg: '已加入购物车!',
|
|
754
754
|
data: res,
|
|
755
755
|
});
|
|
756
756
|
})
|
|
757
757
|
.catch((e) => {
|
|
758
758
|
console.log('京购小程序批量加车失败dealCartFail: ', e);
|
|
759
759
|
resolve({
|
|
760
760
|
ok: false,
|
|
761
761
|
msg: '加购失败,请稍后重试',
|
|
762
762
|
});
|
|
763
763
|
});
|
|
764
764
|
} else {
|
|
765
765
|
console.log('==========>', 'M站批量加车!');
|
|
766
766
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
|
|
767
767
|
}
|
|
768
768
|
} else {
|
|
769
769
|
resolve({
|
|
770
770
|
ok: false,
|
|
771
771
|
msg: '加购sku不能为空',
|
|
772
772
|
});
|
|
773
773
|
}
|
|
774
774
|
});
|
|
775
775
|
}
|
|
776
776
|
|
|
777
777
|
productAddToCart() {
|
|
778
778
|
return Promise.resolve({
|
|
779
779
|
ok: false,
|
|
780
780
|
msg: 'productAddToCart暂不支持小程序',
|
|
781
781
|
});
|
|
782
782
|
}
|
|
783
783
|
bMallGetUserInfo(){
|
|
784
784
|
return Promise.resolve({
|
|
785
785
|
ok: false,
|
|
786
786
|
msg: 'productAddToCart暂不支持小程序',
|
|
787
787
|
});
|
|
788
788
|
}
|
|
789
789
|
bMallGetSkuNumApi(){
|
|
790
790
|
return Promise.resolve({
|
|
791
791
|
ok: false,
|
|
792
792
|
msg: 'productAddToCart暂不支持小程序',
|
|
793
793
|
});
|
|
794
794
|
}
|
|
795
795
|
bMallCartHandle(){
|
|
796
796
|
return Promise.resolve({
|
|
797
797
|
ok: false,
|
|
798
798
|
msg: 'productAddToCart暂不支持小程序',
|
|
799
799
|
});
|
|
800
800
|
}
|