@conecli/cone-render 0.10.1-beta.8 → 0.10.1-beta.9
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/const.ts +1 -1
- package/dist/common/index.h5.ts +1 -1
- package/dist/common/jssdk.ts +1 -1
- package/dist/common/token/token.jd.ts +1 -1
- package/dist/components/base/CustomScrollView/index.tsx +1 -1
- package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
- package/dist/components/base/InViewRender/index.tsx +1 -1
- package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
- package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
- package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
- package/dist/components/base/LazyLoadImage/index.h5.module.scss +4 -8
- package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
- package/dist/components/base/LazyLoadImage/index.tsx +1 -1
- package/dist/components/base/NetworkDataError/index.tsx +1 -1
- package/dist/components/debug/DebugLayout/index.module.scss +2 -2
- package/dist/components/decorate/PlaceHolder/index.tsx +1 -1
- package/dist/components/floorItem.jd.tsx +1 -1
- package/dist/components/floorItem.tsx +1 -1
- package/dist/components/floorItem.weapp.tsx +1 -1
- package/dist/interface/component.ts +1 -1
- package/dist/interface/jumpEventReport.ts +1 -1
- package/dist/jumpEventReport/logEventConfig.ts +1 -1
- package/dist/jumpEventReport/web.tjm.ts +1 -1
- package/dist/open/api/device.ts +1 -1
- package/dist/sass/app.h5.scss +0 -18
- package/dist/service/http/colorSign.ts +1 -1
- package/dist/service/requestServer.ts +1 -1
- package/dist/utils/connectNativeJsBridge.ts +1 -1
- package/dist/utils/index.h5.ts +1 -1
- package/dist/utils/taroRenderUtil.ts +1 -1
- package/dist/utils/utils.ts +1 -1
- package/package.json +53 -64
- package/dist/components/base/CustomScrollView/index-back.tsx +0 -1
- package/dist/utils/log.ts +0 -1
|
@@ -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
|
isIosDevice,
|
|
15
14
|
isAndroidDevice,
|
|
16
15
|
showSuccessToast,
|
|
17
16
|
showFailToast,
|
|
18
17
|
isH5,
|
|
19
18
|
isWxMinAndWxapp,
|
|
20
19
|
isMin,
|
|
21
20
|
isPc,
|
|
22
21
|
cookiesStr: '',
|
|
23
22
|
requestHeaderContentType: {
|
|
24
23
|
jsonHeader: {
|
|
25
24
|
'content-type': 'application/json;charset=utf-8',
|
|
26
25
|
},
|
|
27
26
|
formDataHeader: {
|
|
28
27
|
'content-type': 'application/x-www-form-urlencoded',
|
|
29
28
|
},
|
|
30
29
|
},
|
|
31
30
|
requestBaseParam: {
|
|
32
31
|
data: null,
|
|
33
32
|
header: {
|
|
34
33
|
'content-type': 'application/json;charset=utf-8',
|
|
35
34
|
},
|
|
36
35
|
},
|
|
37
36
|
timeOut: 7000,
|
|
38
37
|
apiClientParams: {
|
|
39
38
|
appid: 'wx_mini_app',
|
|
40
39
|
clientVersion: '11.0.0',
|
|
41
40
|
client: 'wh5',
|
|
42
41
|
area: '1_72_2799_0',
|
|
43
42
|
screen: `${Math.ceil(
|
|
44
43
|
getSystemInfo?.screenWidth * devicePixelRatio,
|
|
45
44
|
)}*${Math.ceil(getSystemInfo?.screenHeight * devicePixelRatio)}`,
|
|
46
45
|
uuid: UUID,
|
|
47
46
|
loginType: '11',
|
|
48
47
|
},
|
|
49
48
|
public addressFetchInfo: {
|
|
50
49
|
reqState: boolean
|
|
51
50
|
promiseInstance: null | Promise<any>
|
|
52
51
|
}
|
|
53
52
|
public getPromotionConfig: {
|
|
54
53
|
projectId: null | string | number
|
|
55
54
|
pageId: null | string | number
|
|
56
55
|
}
|
|
57
56
|
public resInfo: ServiceInterFace.HttpRequestInfo
|
|
58
57
|
public api: ServiceInterFace.HttpApi
|
|
59
58
|
public isPageDomain: boolean
|
|
60
59
|
public verifyColorList: string[]
|
|
61
60
|
constructor(opt) {
|
|
62
61
|
this._init()
|
|
63
62
|
this.addressFetchInfo = {
|
|
64
63
|
reqState: false,
|
|
65
64
|
promiseInstance: null,
|
|
66
65
|
}
|
|
67
66
|
this.getPromotionConfig = {
|
|
68
67
|
projectId: null,
|
|
69
68
|
pageId: null,
|
|
70
69
|
}
|
|
71
70
|
this._userAreaUpdateListen()
|
|
72
71
|
this.resInfo = this._getResConfig(opt)
|
|
73
72
|
this.api = api
|
|
74
73
|
this.isPageDomain = isH5
|
|
75
74
|
? window?.location?.hostname === PAGES_DOMAIN
|
|
76
75
|
: false
|
|
77
76
|
this.verifyColorList = [
|
|
78
77
|
...MobileVerifyColorList,
|
|
79
78
|
...AppVerifyColorList,
|
|
80
79
|
...JshopxVerifyColorList,
|
|
81
80
|
...BMallVerifyColorList,
|
|
82
81
|
]
|
|
83
82
|
}
|
|
84
83
|
_init(): void {
|
|
85
84
|
httpInterceptors.forEach((item) => {
|
|
86
85
|
Taro.addInterceptor((chain) => item(chain))
|
|
87
86
|
})
|
|
88
87
|
}
|
|
89
88
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
90
89
|
return Object.assign({}, DefaultConfig, opt)
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
_userAreaUpdateListen() {
|
|
94
93
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
|
|
95
94
|
this.updateApiClientParamsResInfo(areaInfo);
|
|
96
95
|
});
|
|
97
96
|
}
|
|
98
97
|
updateApiClientParamsResInfo(opt = {}) {
|
|
99
98
|
const { area, realTimeArea, ...others } = opt;
|
|
100
99
|
this.resInfo.apiClientParams = {
|
|
101
100
|
...this.resInfo.apiClientParams,
|
|
102
101
|
...others,
|
|
103
102
|
};
|
|
104
103
|
area && area !== '' && (this.resInfo.apiClientParams.area = area);
|
|
105
104
|
realTimeArea &&
|
|
106
105
|
realTimeArea !== '' &&
|
|
107
106
|
(this.resInfo.apiClientParams.realTimeArea = realTimeArea);
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
checkFunctionIdToReturnAppId(functionId) {
|
|
111
110
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
112
111
|
return APPID.JSHOPX_COLOR_APPID
|
|
113
112
|
} else if (
|
|
114
113
|
this.isPageDomain &&
|
|
115
114
|
PagesColorFunctionIdList.includes(functionId)
|
|
116
115
|
) {
|
|
117
116
|
return APPID.PAGES_COLOR_APPID
|
|
118
117
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
119
118
|
return APPID.SHOP_MEMBER_COLOR_APPID
|
|
120
119
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
121
120
|
return APPID.B2B_COLOR_APPID
|
|
122
121
|
} else if (isPc) {
|
|
123
122
|
return APPID.MALL_COLOR_APPID
|
|
124
123
|
} else {
|
|
125
124
|
return APPID.SHOP_COLOR_APPID
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
130
129
|
if (functionId === 'receiveShopCoupon') {
|
|
131
130
|
clientParams = Object.assign(
|
|
132
131
|
{},
|
|
133
132
|
{
|
|
134
133
|
loginType: '1',
|
|
135
134
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
136
135
|
},
|
|
137
136
|
clientParams,
|
|
138
137
|
)
|
|
139
138
|
}
|
|
140
139
|
const apiClientParams = Object.assign(
|
|
141
140
|
{},
|
|
142
141
|
this.resInfo.apiClientParams,
|
|
143
142
|
clientParams,
|
|
144
143
|
)
|
|
145
144
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
146
145
|
const getReqData = {
|
|
147
146
|
functionId: functionId,
|
|
148
147
|
body: JSON.stringify(bodyParams),
|
|
149
148
|
t: Date.now(),
|
|
150
149
|
...apiClientParams,
|
|
151
150
|
}
|
|
152
151
|
const requestParams = {
|
|
153
152
|
functionId: getReqData?.functionId,
|
|
154
153
|
body: getReqData?.body,
|
|
155
154
|
appid: getReqData?.appid,
|
|
156
155
|
client: getReqData?.client,
|
|
157
156
|
clientVersion: getReqData?.clientVersion,
|
|
158
157
|
area: getReqData?.area,
|
|
159
158
|
requestTimeStamp: getReqData?.t,
|
|
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, getReqData)
|
|
174
173
|
return changeRes
|
|
175
174
|
} else {
|
|
176
175
|
sgmCustomReport({
|
|
177
176
|
code: getSgmCustomCode('interface_data_error'),
|
|
178
177
|
msg: {
|
|
179
178
|
subMsg: '接口请求异常',
|
|
180
179
|
functionId,
|
|
181
180
|
statusCode,
|
|
182
181
|
source: 'remote',
|
|
183
182
|
status,
|
|
184
183
|
msg,
|
|
185
184
|
requestParams,
|
|
186
185
|
},
|
|
187
186
|
})
|
|
188
187
|
draInterfaceCustomReport({
|
|
189
188
|
...getReqData,
|
|
190
189
|
...res,
|
|
191
190
|
source: 'remote',
|
|
192
191
|
})
|
|
193
192
|
changeRes = {
|
|
194
193
|
...data,
|
|
195
194
|
statusCode,
|
|
196
195
|
status,
|
|
197
196
|
msg,
|
|
198
197
|
ok: false,
|
|
199
198
|
}
|
|
200
199
|
return changeRes
|
|
201
200
|
}
|
|
202
201
|
})
|
|
203
202
|
.catch((res) => {
|
|
204
203
|
const propertyNames = Object.getOwnPropertyNames(res)
|
|
205
204
|
const resObject = {}
|
|
206
205
|
propertyNames.forEach((propertyName) => {
|
|
207
206
|
resObject[propertyName] = res[propertyName]
|
|
208
207
|
})
|
|
209
208
|
sgmCustomReport({
|
|
210
209
|
code: getSgmCustomCode('interface_data_error'),
|
|
211
210
|
msg: {
|
|
212
211
|
subMsg: '接口请求错误',
|
|
213
212
|
functionId,
|
|
214
213
|
source: 'remote',
|
|
215
214
|
requestParams,
|
|
216
215
|
catchError: resObject,
|
|
217
216
|
},
|
|
218
217
|
})
|
|
219
218
|
draInterfaceCustomReport({
|
|
220
219
|
...getReqData,
|
|
221
220
|
...resObject,
|
|
222
221
|
source: 'remote',
|
|
223
222
|
})
|
|
224
223
|
return {
|
|
225
224
|
...resObject,
|
|
226
225
|
ok: false,
|
|
227
226
|
} as ServiceInterFace.RequestResponseFormatRes
|
|
228
227
|
})
|
|
229
228
|
}
|
|
230
229
|
|
|
231
230
|
dealResponseFormatRes(data, reqData) {
|
|
232
231
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
233
232
|
ok: true,
|
|
234
233
|
}
|
|
235
234
|
const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
|
|
236
235
|
? Number(data.code)
|
|
237
236
|
: -1
|
|
238
237
|
const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
|
|
239
238
|
? Number(data.subCode)
|
|
240
239
|
: -1
|
|
241
240
|
if (
|
|
242
241
|
data.success === true ||
|
|
243
242
|
data.isSuccess ||
|
|
244
243
|
resCode === 0 ||
|
|
245
244
|
resCode === 200 ||
|
|
246
245
|
subCode === 0
|
|
247
246
|
) {
|
|
248
247
|
changeRes = {
|
|
249
248
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
250
249
|
? data.result
|
|
251
250
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
252
251
|
? data.data
|
|
253
252
|
: data,
|
|
254
253
|
code: data.code ?? 200,
|
|
255
254
|
ok: true,
|
|
256
255
|
source: data,
|
|
257
256
|
}
|
|
258
257
|
return changeRes
|
|
259
258
|
} else {
|
|
260
259
|
changeRes = {
|
|
261
260
|
...data,
|
|
262
261
|
ok: false,
|
|
263
262
|
}
|
|
264
263
|
if (reqData && resCode !== 3) {
|
|
265
264
|
const getReportMsgData = reqData['hybridId']
|
|
266
265
|
? {
|
|
267
266
|
subMsg: '预加载接口请求数据异常',
|
|
268
267
|
hybridId: reqData?.hybridId,
|
|
269
268
|
requestId: reqData?.requestId,
|
|
270
269
|
param: reqData?.param,
|
|
271
270
|
source: 'remote',
|
|
272
271
|
}
|
|
273
272
|
: {
|
|
274
273
|
subMsg: '接口请求返回数据异常',
|
|
275
274
|
functionId: reqData?.functionId,
|
|
276
275
|
code: resCode,
|
|
277
276
|
source: 'remote',
|
|
278
277
|
requestParams: {
|
|
279
278
|
functionId: reqData?.functionId,
|
|
280
279
|
body: reqData?.body,
|
|
281
280
|
appid: reqData?.appid,
|
|
282
281
|
client: reqData?.client,
|
|
283
282
|
clientVersion: reqData?.clientVersion,
|
|
284
283
|
area: reqData?.area,
|
|
285
284
|
requestTimeStamp: reqData?.t,
|
|
286
285
|
},
|
|
287
286
|
resData: data,
|
|
288
287
|
}
|
|
289
288
|
sgmCustomReport({
|
|
290
289
|
code: getSgmCustomCode('interface_data_error'),
|
|
291
290
|
msg: getReportMsgData,
|
|
292
291
|
})
|
|
293
292
|
draInterfaceCustomReport({
|
|
294
293
|
...reqData,
|
|
295
294
|
...data,
|
|
296
295
|
source: 'remote',
|
|
297
296
|
})
|
|
298
297
|
}
|
|
299
298
|
return changeRes
|
|
300
299
|
}
|
|
301
300
|
}
|
|
302
301
|
|
|
303
302
|
async receiveCoupon(param = {}, clientParams) {
|
|
304
303
|
console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
305
304
|
return await this.gatewayReq(
|
|
306
305
|
'receiveShopCoupon',
|
|
307
306
|
{
|
|
308
307
|
operation: '3',
|
|
309
308
|
...param,
|
|
310
309
|
},
|
|
311
310
|
{ ...clientParams },
|
|
312
311
|
);
|
|
313
312
|
}
|
|
314
313
|
|
|
315
314
|
getCustomerCenterDispatch(params = {}) {
|
|
316
315
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
317
316
|
clientVersion: '9.2.0',
|
|
318
317
|
client: 'H5',
|
|
319
318
|
uuid: 88888,
|
|
320
319
|
appid: 'shopmember_m_jd_com',
|
|
321
320
|
})
|
|
322
321
|
}
|
|
323
322
|
|
|
324
323
|
batchAddCart(...args) {
|
|
325
324
|
let skuIds, num, showToast, giftCard;
|
|
326
325
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
327
326
|
[skuIds, num = 1, showToast = true, giftCard = false] = args;
|
|
328
327
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
329
328
|
const params = args[0];
|
|
330
329
|
skuIds = params.skuIds;
|
|
331
330
|
num = params.num || 1;
|
|
332
331
|
showToast = params.showToast !== undefined ? params.showToast : true;
|
|
333
332
|
giftCard = params.giftCard !== undefined ? params.giftCard : false;
|
|
334
333
|
} else {
|
|
335
334
|
console.error('batchAddCart() Invalid arguments!', args);
|
|
336
335
|
const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
|
|
337
336
|
showFailToast({
|
|
338
337
|
title: msg,
|
|
339
338
|
});
|
|
340
339
|
return Promise.resolve({
|
|
341
340
|
ok: false,
|
|
342
341
|
msg,
|
|
343
342
|
});
|
|
344
343
|
}
|
|
345
344
|
const addToWhereText = giftCard ? '购物清单' : '购物车';
|
|
346
345
|
const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
|
|
347
346
|
const failMsg = isLanguageForEn
|
|
348
347
|
? 'Please retry later'
|
|
349
348
|
: `加入${addToWhereText}失败,请稍后重试!`;
|
|
350
349
|
if (skuIds) {
|
|
351
350
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
|
|
352
351
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
353
352
|
if (res?.ok) {
|
|
354
353
|
if (showToast && !res?.isOpenApp)
|
|
355
354
|
showSuccessToast({
|
|
356
355
|
title: successMsg,
|
|
357
356
|
});
|
|
358
357
|
} else {
|
|
359
358
|
showToast &&
|
|
360
359
|
showFailToast({
|
|
361
360
|
title: res?.errMsg || failMsg,
|
|
362
361
|
});
|
|
363
362
|
}
|
|
364
363
|
return Promise.resolve(res)
|
|
365
364
|
})
|
|
366
365
|
.catch((e) => {
|
|
367
366
|
console.log('调用加购方法异常=======>', e)
|
|
368
367
|
return Promise.resolve({
|
|
369
368
|
ok: false,
|
|
370
369
|
msg: failMsg,
|
|
371
370
|
});
|
|
372
371
|
});
|
|
373
372
|
} else {
|
|
374
373
|
return Promise.resolve({
|
|
375
374
|
ok: false,
|
|
376
375
|
msg: failMsg,
|
|
377
376
|
});
|
|
378
377
|
}
|
|
379
378
|
}
|
|
380
379
|
|
|
381
380
|
async giftCardAddCart(skuList, num) {
|
|
382
381
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
383
382
|
return this.gatewayReq(
|
|
384
383
|
'giftCardAddCart',
|
|
385
384
|
{
|
|
386
385
|
skuList,
|
|
387
386
|
num: Number(num),
|
|
388
387
|
},
|
|
389
388
|
{ ...loginType },
|
|
390
389
|
);
|
|
391
390
|
}
|
|
392
391
|
|
|
393
392
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
|
|
394
393
|
return new Promise((resolve) => {
|
|
395
394
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
|
|
396
395
|
if (productIdsArr.length > 0) {
|
|
397
396
|
if (giftCard) {
|
|
398
397
|
this.giftCardAddCart(productIdsArr, addCardNum)
|
|
399
398
|
.then((res) => {
|
|
400
399
|
if (res?.code === '0' && res?.result?.value) {
|
|
401
400
|
resolve({
|
|
402
401
|
ok: true,
|
|
403
402
|
});
|
|
404
403
|
} else {
|
|
405
404
|
resolve({
|
|
406
405
|
ok: false,
|
|
407
406
|
msg: '加购失败,请稍后重试',
|
|
408
407
|
});
|
|
409
408
|
}
|
|
410
409
|
})
|
|
411
410
|
.catch((e) => {
|
|
412
411
|
console.error('礼品卡加车失败: ', e);
|
|
413
412
|
resolve({
|
|
414
413
|
ok: false,
|
|
415
414
|
msg: '加购失败,请稍后重试',
|
|
416
415
|
});
|
|
417
416
|
});
|
|
418
417
|
} else if (isJdApp) {
|
|
419
418
|
console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
|
|
420
419
|
} else if (isMin) {
|
|
421
420
|
console.log('==========>', '京购批量加车!')
|
|
422
421
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
423
422
|
return {
|
|
424
423
|
skuId: skuItem,
|
|
425
424
|
buyNum: addCardNum,
|
|
426
425
|
}
|
|
427
426
|
})
|
|
428
427
|
global.wxAppBizInstance
|
|
429
428
|
.addCart({ commArr: productsAddCartList })
|
|
430
429
|
.then((res) => {
|
|
431
430
|
console.log('dealCartSuccess: ', res)
|
|
432
431
|
resolve({
|
|
433
432
|
ok: true,
|
|
434
433
|
msg: '已加入购物车!',
|
|
435
434
|
data: res,
|
|
436
435
|
})
|
|
437
436
|
})
|
|
438
437
|
.catch((e) => {
|
|
439
438
|
console.log('京购小程序批量加车失败dealCartFail: ', e)
|
|
440
439
|
resolve({
|
|
441
440
|
ok: false,
|
|
442
441
|
msg: '加购失败,请稍后重试',
|
|
443
442
|
})
|
|
444
443
|
})
|
|
445
444
|
} else {
|
|
446
445
|
console.log('==========>', 'M站批量加车!')
|
|
447
446
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
|
|
448
447
|
resolve(res),
|
|
449
448
|
)
|
|
450
449
|
}
|
|
451
450
|
} else {
|
|
452
451
|
resolve({
|
|
453
452
|
ok: false,
|
|
454
453
|
msg: '加购sku不能为空',
|
|
455
454
|
})
|
|
456
455
|
}
|
|
457
456
|
})
|
|
458
457
|
}
|
|
459
458
|
|
|
460
459
|
productAddToCart() {
|
|
461
460
|
return Promise.resolve({
|
|
462
461
|
ok: false,
|
|
463
462
|
msg: 'productAddToCart暂不支持小程序',
|
|
464
463
|
});
|
|
465
464
|
}
|
|
466
465
|
bMallGetUserInfo = () => {
|
|
467
466
|
return getBMallUserInfo()
|
|
468
467
|
}
|
|
469
468
|
async bMallAddCart(params = {}) {
|
|
470
469
|
console.warn('bMallAddCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
471
470
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
472
471
|
client: 'H5',
|
|
473
472
|
clientVersion: '5.5.0',
|
|
474
473
|
})
|
|
475
474
|
}
|
|
476
475
|
async bMallChangeCart(params = {}) {
|
|
477
476
|
console.warn('bMallChangeCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
478
477
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
479
478
|
client: 'H5',
|
|
480
479
|
clientVersion: '5.5.0',
|
|
481
480
|
})
|
|
482
481
|
}
|
|
483
482
|
async bMallRemoveCart(params = {}) {
|
|
484
483
|
console.warn('bMallRemoveCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
485
484
|
return await this.gatewayReq(
|
|
486
485
|
'bmall_cartRemove',
|
|
487
486
|
params,
|
|
488
487
|
{
|
|
489
488
|
client: 'H5',
|
|
490
489
|
clientVersion: '5.5.0',
|
|
491
490
|
},
|
|
492
491
|
)
|
|
493
492
|
}
|
|
494
493
|
async bMallGetOmittedProduct(params = {}) {
|
|
495
494
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
496
495
|
client: 'H5',
|
|
497
496
|
clientVersion: '5.5.0',
|
|
498
497
|
})
|
|
499
498
|
}
|
|
500
499
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
501
500
|
const params = await getParams({ ...data, skuId, bMallTag, num })
|
|
502
501
|
return await this.bMallAddCart(params)
|
|
503
502
|
}
|
|
504
503
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
505
504
|
const params = await getParams({ bMallTag })
|
|
506
505
|
delete params.operations
|
|
507
506
|
return await this.bMallGetOmittedProduct(params)
|
|
508
507
|
}
|
|
509
508
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
510
509
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
511
510
|
return await this.bMallRemoveCart(params)
|
|
512
511
|
}
|
|
513
512
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
514
513
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
515
514
|
return await this.bMallChangeCart(params)
|
|
516
515
|
}
|
|
517
516
|
|
|
518
517
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
519
518
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
520
519
|
return window?.bMallCartData
|
|
521
520
|
}
|
|
522
521
|
const cartData = await this.bMallGetSkuNumService(bMallTag)
|
|
523
522
|
let items
|
|
524
523
|
if (cartData.ok && cartData.result) {
|
|
525
524
|
items = cartData?.result?.items || {}
|
|
526
525
|
}
|
|
527
526
|
if (isH5) {
|
|
528
527
|
window.bMallCartData = items
|
|
529
528
|
}
|
|
530
529
|
return items
|
|
531
530
|
}
|
|
532
531
|
|
|
533
532
|
async bMallCartHandle(goodItem, num) {
|
|
534
533
|
try {
|
|
535
534
|
const {
|
|
536
535
|
skuUuid,
|
|
537
536
|
limitUpper,
|
|
538
537
|
limitLower,
|
|
539
538
|
} = goodItem
|
|
540
539
|
let cartNum = Number(num)
|
|
541
540
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
542
541
|
cartNum = limitLower
|
|
543
542
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
544
543
|
cartNum = limitUpper
|
|
545
544
|
}
|
|
546
545
|
if (skuUuid && cartNum > 0) {
|
|
547
546
|
return this.bMallChangeCartService({
|
|
548
547
|
...goodItem,
|
|
549
548
|
skuUuid,
|
|
550
549
|
num: cartNum,
|
|
551
550
|
})
|
|
552
551
|
} else if (!skuUuid && cartNum > 0) {
|
|
553
552
|
return this.bMallAddCartService({ ...goodItem, num: cartNum })
|
|
554
553
|
} else if (skuUuid && !cartNum) {
|
|
555
554
|
return this.bMallRemoveCartService({
|
|
556
555
|
...goodItem,
|
|
557
556
|
skuUuid,
|
|
558
557
|
num: cartNum,
|
|
559
558
|
})
|
|
560
559
|
} else {
|
|
561
560
|
console.error('参数不全')
|
|
562
561
|
return false
|
|
563
562
|
}
|
|
564
563
|
} catch (e) {
|
|
565
564
|
console.error(e)
|
|
566
565
|
}
|
|
567
566
|
}
|
|
567
|
+
import Taro from '@tarojs/taro';
|
|
568
568
|
APPID,
|
|
569
569
|
JshopxColorFunctionIdList,
|
|
570
570
|
PagesColorFunctionIdList,
|
|
571
571
|
PAGES_DOMAIN,
|
|
572
572
|
B2BColorFunctionIdList,
|
|
573
573
|
MobileVerifyColorList,
|
|
574
574
|
AppVerifyColorList,
|
|
575
575
|
JshopxVerifyColorList,
|
|
576
576
|
BMallVerifyColorList,
|
|
577
577
|
shopMemberColorFunctionIdList,
|
|
578
578
|
isLanguageForEn,
|
|
579
579
|
isJdApp,
|
|
580
580
|
showSuccessToast,
|
|
581
581
|
showFailToast,
|
|
582
582
|
isH5,
|
|
583
583
|
isWxMinAndWxapp,
|
|
584
584
|
isMin,
|
|
585
585
|
isPc,
|
|
586
586
|
cookiesStr: '',
|
|
587
587
|
requestHeaderContentType: {
|
|
588
588
|
jsonHeader: {
|
|
589
589
|
'content-type': 'application/json;charset=utf-8',
|
|
590
590
|
},
|
|
591
591
|
formDataHeader: {
|
|
592
592
|
'content-type': 'application/x-www-form-urlencoded',
|
|
593
593
|
},
|
|
594
594
|
},
|
|
595
595
|
requestBaseParam: {
|
|
596
596
|
data: null,
|
|
597
597
|
header: {
|
|
598
598
|
'content-type': 'application/json;charset=utf-8',
|
|
599
599
|
},
|
|
600
600
|
},
|
|
601
601
|
timeOut: 7000,
|
|
602
602
|
apiClientParams: {
|
|
603
603
|
clientVersion: '11.0.0',
|
|
604
604
|
client: 'wh5',
|
|
605
605
|
area: '1_72_2799_0',
|
|
606
606
|
screen: `${Math.ceil(getSystemInfo?.screenWidth * devicePixelRatio)}*${Math.ceil(
|
|
607
607
|
getSystemInfo?.screenHeight * devicePixelRatio,
|
|
608
608
|
)}`,
|
|
609
609
|
uuid: UUID,
|
|
610
610
|
},
|
|
611
611
|
public addressFetchInfo: {
|
|
612
612
|
reqState: boolean;
|
|
613
613
|
promiseInstance: null | Promise<any>;
|
|
614
614
|
};
|
|
615
615
|
public getPromotionConfig: {
|
|
616
616
|
projectId: null | string | number;
|
|
617
617
|
pageId: null | string | number;
|
|
618
618
|
};
|
|
619
619
|
public resInfo: ServiceInterFace.HttpRequestInfo;
|
|
620
620
|
public api: ServiceInterFace.HttpApi;
|
|
621
621
|
public isPageDomain: boolean;
|
|
622
622
|
public verifyColorList: string[];
|
|
623
623
|
constructor(opt) {
|
|
624
624
|
this._init();
|
|
625
625
|
this.addressFetchInfo = {
|
|
626
626
|
reqState: false,
|
|
627
627
|
promiseInstance: null,
|
|
628
628
|
};
|
|
629
629
|
this.getPromotionConfig = {
|
|
630
630
|
projectId: null,
|
|
631
631
|
pageId: null,
|
|
632
632
|
};
|
|
633
633
|
this._userAreaUpdateListen();
|
|
634
634
|
this.resInfo = this._getResConfig(opt);
|
|
635
635
|
this.api = api;
|
|
636
636
|
this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
|
|
637
637
|
this.verifyColorList = [
|
|
638
638
|
...MobileVerifyColorList,
|
|
639
639
|
...AppVerifyColorList,
|
|
640
640
|
...JshopxVerifyColorList,
|
|
641
641
|
...BMallVerifyColorList,
|
|
642
642
|
];
|
|
643
643
|
}
|
|
644
644
|
_init(): void {
|
|
645
645
|
httpInterceptors.forEach((item) => {
|
|
646
646
|
Taro.addInterceptor((chain) => item(chain));
|
|
647
647
|
});
|
|
648
648
|
}
|
|
649
649
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
650
650
|
return Object.assign({}, DefaultConfig, opt);
|
|
651
651
|
}
|
|
652
652
|
|
|
653
653
|
_userAreaUpdateListen() {
|
|
654
654
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
|
|
655
655
|
this.updateApiClientParamsResInfo(areaInfo);
|
|
656
656
|
});
|
|
657
657
|
}
|
|
658
658
|
updateApiClientParamsResInfo(opt = {}) {
|
|
659
659
|
const { area, realTimeArea, ...others } = opt;
|
|
660
660
|
this.resInfo.apiClientParams = {
|
|
661
661
|
...this.resInfo.apiClientParams,
|
|
662
662
|
...others,
|
|
663
663
|
};
|
|
664
664
|
area && area !== '' && (this.resInfo.apiClientParams.area = area);
|
|
665
665
|
realTimeArea &&
|
|
666
666
|
realTimeArea !== '' &&
|
|
667
667
|
(this.resInfo.apiClientParams.realTimeArea = realTimeArea);
|
|
668
668
|
}
|
|
669
669
|
|
|
670
670
|
checkFunctionIdToReturnAppId(functionId) {
|
|
671
671
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
672
672
|
return APPID.JSHOPX_COLOR_APPID;
|
|
673
673
|
} else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
|
|
674
674
|
return APPID.PAGES_COLOR_APPID;
|
|
675
675
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
676
676
|
return APPID.SHOP_MEMBER_COLOR_APPID;
|
|
677
677
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
678
678
|
return APPID.B2B_COLOR_APPID;
|
|
679
679
|
} else if (isPc) {
|
|
680
680
|
return APPID.MALL_COLOR_APPID;
|
|
681
681
|
} else {
|
|
682
682
|
return APPID.SHOP_COLOR_APPID;
|
|
683
683
|
}
|
|
684
684
|
}
|
|
685
685
|
|
|
686
686
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
687
687
|
if (
|
|
688
688
|
functionId === 'receiveShopCoupon' &&
|
|
689
689
|
((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
|
|
690
690
|
isWxMinAndWxapp)
|
|
691
691
|
) {
|
|
692
692
|
clientParams = Object.assign(
|
|
693
693
|
{},
|
|
694
694
|
{
|
|
695
695
|
loginType: '1',
|
|
696
696
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
697
697
|
},
|
|
698
698
|
clientParams,
|
|
699
699
|
);
|
|
700
700
|
}
|
|
701
701
|
const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
|
|
702
702
|
typeof apiClientParams.appid === 'undefined' &&
|
|
703
703
|
(apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
|
|
704
704
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
705
705
|
const getReqData = {
|
|
706
706
|
functionId: functionId,
|
|
707
707
|
body: JSON.stringify(bodyParams),
|
|
708
708
|
t: Date.now(),
|
|
709
709
|
...apiClientParams,
|
|
710
710
|
};
|
|
711
711
|
return http
|
|
712
712
|
.request({
|
|
713
713
|
url: this.api.apiFunc,
|
|
714
714
|
data: getReqData,
|
|
715
715
|
isColorVerify,
|
|
716
716
|
})
|
|
717
717
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
718
718
|
const { statusCode, data } = res;
|
|
719
719
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
720
720
|
ok: true,
|
|
721
721
|
};
|
|
722
722
|
if (statusCode === 200 && data) {
|
|
723
723
|
const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
|
|
724
724
|
? Number(res.data.code)
|
|
725
725
|
: -1;
|
|
726
726
|
const subCode = Object.prototype.hasOwnProperty.call(res.data, 'subCode')
|
|
727
727
|
? Number(res.data.subCode)
|
|
728
728
|
: -1;
|
|
729
729
|
if (
|
|
730
730
|
data.success === true ||
|
|
731
731
|
data.isSuccess ||
|
|
732
732
|
resCode === 0 ||
|
|
733
733
|
resCode === 200 ||
|
|
734
734
|
subCode === 0
|
|
735
735
|
) {
|
|
736
736
|
changeRes = {
|
|
737
737
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
738
738
|
? data.result
|
|
739
739
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
740
740
|
? data.data
|
|
741
741
|
: data,
|
|
742
742
|
code: data.code || 200,
|
|
743
743
|
ok: true,
|
|
744
744
|
source: data,
|
|
745
745
|
};
|
|
746
746
|
return changeRes;
|
|
747
747
|
} else {
|
|
748
748
|
changeRes = {
|
|
749
749
|
...data,
|
|
750
750
|
ok: false,
|
|
751
751
|
statusCode: res.statusCode,
|
|
752
752
|
};
|
|
753
753
|
return changeRes;
|
|
754
754
|
}
|
|
755
755
|
} else {
|
|
756
756
|
changeRes = {
|
|
757
757
|
...data,
|
|
758
758
|
ok: false,
|
|
759
759
|
statusCode: res.statusCode,
|
|
760
760
|
};
|
|
761
761
|
return changeRes;
|
|
762
762
|
}
|
|
763
763
|
})
|
|
764
764
|
.catch((res) => {
|
|
765
765
|
return {
|
|
766
766
|
...res,
|
|
767
767
|
ok: false,
|
|
768
768
|
} as ServiceInterFace.RequestResponseFormatRes;
|
|
769
769
|
});
|
|
770
770
|
}
|
|
771
771
|
|
|
772
772
|
async receiveCoupon(param = {}, clientParams) {
|
|
773
773
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
774
774
|
return await this.gatewayReq(
|
|
775
775
|
'receiveShopCoupon',
|
|
776
776
|
{
|
|
777
777
|
operation: '3',
|
|
778
778
|
...param,
|
|
779
779
|
},
|
|
780
780
|
{ ...loginType, ...clientParams },
|
|
781
781
|
);
|
|
782
782
|
}
|
|
783
783
|
|
|
784
784
|
getCustomerCenterDispatch(params = {}) {
|
|
785
785
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
786
786
|
clientVersion: '9.2.0',
|
|
787
787
|
client: 'H5',
|
|
788
788
|
uuid: 88888,
|
|
789
789
|
appid: 'shopmember_m_jd_com',
|
|
790
790
|
});
|
|
791
791
|
}
|
|
792
792
|
|
|
793
793
|
batchAddCart(...args) {
|
|
794
794
|
let skuIds, num, showToast, giftCard;
|
|
795
795
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
796
796
|
[skuIds, num = 1, showToast = true, giftCard = false] = args;
|
|
797
797
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
798
798
|
const params = args[0];
|
|
799
799
|
skuIds = params.skuIds;
|
|
800
800
|
num = params.num || 1;
|
|
801
801
|
showToast = params.showToast !== undefined ? params.showToast : true;
|
|
802
802
|
giftCard = params.giftCard !== undefined ? params.giftCard : false;
|
|
803
803
|
} else {
|
|
804
804
|
console.error('batchAddCart() Invalid arguments!', args);
|
|
805
805
|
const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
|
|
806
806
|
showFailToast({
|
|
807
807
|
title: msg,
|
|
808
808
|
});
|
|
809
809
|
return Promise.resolve({
|
|
810
810
|
ok: false,
|
|
811
811
|
msg,
|
|
812
812
|
});
|
|
813
813
|
}
|
|
814
814
|
const addToWhereText = giftCard ? '购物清单' : '购物车';
|
|
815
815
|
const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
|
|
816
816
|
const failMsg = isLanguageForEn
|
|
817
817
|
? 'Please retry later'
|
|
818
818
|
: `加入${addToWhereText}失败,请稍后重试!`;
|
|
819
819
|
if (skuIds) {
|
|
820
820
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
|
|
821
821
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
822
822
|
if (res?.ok) {
|
|
823
823
|
if (showToast && !res?.isOpenApp)
|
|
824
824
|
showSuccessToast({
|
|
825
825
|
title: successMsg,
|
|
826
826
|
});
|
|
827
827
|
} else {
|
|
828
828
|
showToast &&
|
|
829
829
|
showFailToast({
|
|
830
830
|
title: res?.errMsg || failMsg,
|
|
831
831
|
});
|
|
832
832
|
}
|
|
833
833
|
return Promise.resolve(res);
|
|
834
834
|
})
|
|
835
835
|
.catch((e) => {
|
|
836
836
|
console.log('调用加购方法异常=======>', e);
|
|
837
837
|
return Promise.resolve({
|
|
838
838
|
ok: false,
|
|
839
839
|
msg: failMsg,
|
|
840
840
|
});
|
|
841
841
|
});
|
|
842
842
|
} else {
|
|
843
843
|
return Promise.resolve({
|
|
844
844
|
ok: false,
|
|
845
845
|
msg: failMsg,
|
|
846
846
|
});
|
|
847
847
|
}
|
|
848
848
|
}
|
|
849
849
|
|
|
850
850
|
async giftCardAddCart(skuList, num) {
|
|
851
851
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
852
852
|
return this.gatewayReq(
|
|
853
853
|
'giftCardAddCart',
|
|
854
854
|
{
|
|
855
855
|
skuList,
|
|
856
856
|
num: Number(num),
|
|
857
857
|
},
|
|
858
858
|
{ ...loginType },
|
|
859
859
|
);
|
|
860
860
|
}
|
|
861
861
|
|
|
862
862
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
|
|
863
863
|
return new Promise((resolve) => {
|
|
864
864
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
|
|
865
865
|
if (productIdsArr.length > 0) {
|
|
866
866
|
if (giftCard) {
|
|
867
867
|
this.giftCardAddCart(productIdsArr, addCardNum)
|
|
868
868
|
.then((res) => {
|
|
869
869
|
if (res?.code === '0' && res?.result?.value) {
|
|
870
870
|
resolve({
|
|
871
871
|
ok: true,
|
|
872
872
|
});
|
|
873
873
|
} else {
|
|
874
874
|
resolve({
|
|
875
875
|
ok: false,
|
|
876
876
|
msg: '加购失败,请稍后重试',
|
|
877
877
|
});
|
|
878
878
|
}
|
|
879
879
|
})
|
|
880
880
|
.catch((e) => {
|
|
881
881
|
console.error('礼品卡加车失败: ', e);
|
|
882
882
|
resolve({
|
|
883
883
|
ok: false,
|
|
884
884
|
msg: '加购失败,请稍后重试',
|
|
885
885
|
});
|
|
886
886
|
});
|
|
887
887
|
} else if (isJdApp) {
|
|
888
888
|
console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
|
|
889
889
|
} else if (isMin) {
|
|
890
890
|
console.log('==========>', '京购批量加车!');
|
|
891
891
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
892
892
|
return {
|
|
893
893
|
skuId: skuItem,
|
|
894
894
|
buyNum: addCardNum,
|
|
895
895
|
};
|
|
896
896
|
});
|
|
897
897
|
global.wxAppBizInstance
|
|
898
898
|
.addCart({ commArr: productsAddCartList })
|
|
899
899
|
.then((res) => {
|
|
900
900
|
console.log('dealCartSuccess: ', res);
|
|
901
901
|
resolve({
|
|
902
902
|
ok: true,
|
|
903
903
|
msg: '已加入购物车!',
|
|
904
904
|
data: res,
|
|
905
905
|
});
|
|
906
906
|
})
|
|
907
907
|
.catch((e) => {
|
|
908
908
|
console.log('京购小程序批量加车失败dealCartFail: ', e);
|
|
909
909
|
resolve({
|
|
910
910
|
ok: false,
|
|
911
911
|
msg: '加购失败,请稍后重试',
|
|
912
912
|
});
|
|
913
913
|
});
|
|
914
914
|
} else {
|
|
915
915
|
console.log('==========>', 'M站批量加车!');
|
|
916
916
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
|
|
917
917
|
}
|
|
918
918
|
} else {
|
|
919
919
|
resolve({
|
|
920
920
|
ok: false,
|
|
921
921
|
msg: '加购sku不能为空',
|
|
922
922
|
});
|
|
923
923
|
}
|
|
924
924
|
});
|
|
925
925
|
}
|
|
926
926
|
|
|
927
927
|
productAddToCart(skuIdsStr, num) {
|
|
928
928
|
return new Promise((resolve) => {
|
|
929
929
|
if (window.AddcartToolObj) {
|
|
930
930
|
window.AddcartToolObj.addCart({
|
|
931
931
|
skuId: skuIdsStr,
|
|
932
932
|
num,
|
|
933
933
|
source: 'sjdpyw',
|
|
934
934
|
actId: '1',
|
|
935
935
|
loginType: window?.isJingGouMiniViewState ? '11' : '2',
|
|
936
936
|
sucFun(res) {
|
|
937
937
|
console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
|
|
938
938
|
if (res.errId === '0' && res.cartJson) {
|
|
939
939
|
resolve({
|
|
940
940
|
ok: true,
|
|
941
941
|
msg: '已加入购物车!',
|
|
942
942
|
...res,
|
|
943
943
|
});
|
|
944
944
|
} else {
|
|
945
945
|
if (res.errId === '13') {
|
|
946
946
|
global.doLogin();
|
|
947
947
|
} else {
|
|
948
948
|
resolve({
|
|
949
949
|
ok: false,
|
|
950
950
|
msg: '加购失败,请稍后重试',
|
|
951
951
|
...res,
|
|
952
952
|
});
|
|
953
953
|
}
|
|
954
954
|
}
|
|
955
955
|
},
|
|
956
956
|
failFun(err) {
|
|
957
957
|
console.log('fail', err);
|
|
958
958
|
resolve({
|
|
959
959
|
ok: false,
|
|
960
960
|
msg: '加购失败,请稍后重试',
|
|
961
961
|
...err,
|
|
962
962
|
});
|
|
963
963
|
},
|
|
964
964
|
});
|
|
965
965
|
} else {
|
|
966
966
|
resolve({
|
|
967
967
|
ok: false,
|
|
968
968
|
msg: '购物车方法检查异常',
|
|
969
969
|
});
|
|
970
970
|
}
|
|
971
971
|
});
|
|
972
972
|
}
|
|
973
973
|
bMallGetUserInfo = () => {
|
|
974
974
|
return getBMallUserInfo();
|
|
975
975
|
};
|
|
976
976
|
async bMallAddCart(params = {}) {
|
|
977
977
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
978
978
|
client: 'H5',
|
|
979
979
|
clientVersion: '5.5.0',
|
|
980
980
|
});
|
|
981
981
|
}
|
|
982
982
|
async bMallChangeCart(params = {}) {
|
|
983
983
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
984
984
|
client: 'H5',
|
|
985
985
|
clientVersion: '5.5.0',
|
|
986
986
|
});
|
|
987
987
|
}
|
|
988
988
|
async bMallRemoveCart(params = {}) {
|
|
989
989
|
return await this.gatewayReq(
|
|
990
990
|
'bmall_cartRemove',
|
|
991
991
|
params,
|
|
992
992
|
{
|
|
993
993
|
client: 'H5',
|
|
994
994
|
clientVersion: '5.5.0',
|
|
995
995
|
},
|
|
996
996
|
);
|
|
997
997
|
}
|
|
998
998
|
async bMallGetOmittedProduct(params = {}) {
|
|
999
999
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
1000
1000
|
client: 'H5',
|
|
1001
1001
|
clientVersion: '5.5.0',
|
|
1002
1002
|
});
|
|
1003
1003
|
}
|
|
1004
1004
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
1005
1005
|
const params = await getParams({ ...data, skuId, bMallTag, num });
|
|
1006
1006
|
return await this.bMallAddCart(params);
|
|
1007
1007
|
}
|
|
1008
1008
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
1009
1009
|
const params = await getParams({ bMallTag });
|
|
1010
1010
|
delete params.operations;
|
|
1011
1011
|
return await this.bMallGetOmittedProduct(params);
|
|
1012
1012
|
}
|
|
1013
1013
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
1014
1014
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
1015
1015
|
return await this.bMallRemoveCart(params);
|
|
1016
1016
|
}
|
|
1017
1017
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
1018
1018
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
1019
1019
|
return await this.bMallChangeCart(params);
|
|
1020
1020
|
}
|
|
1021
1021
|
|
|
1022
1022
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
1023
1023
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
1024
1024
|
return window?.bMallCartData;
|
|
1025
1025
|
}
|
|
1026
1026
|
const cartData = await this.bMallGetSkuNumService(bMallTag);
|
|
1027
1027
|
let items;
|
|
1028
1028
|
if (cartData.ok && cartData.result) {
|
|
1029
1029
|
items = cartData?.result?.items || {};
|
|
1030
1030
|
}
|
|
1031
1031
|
if (isH5) {
|
|
1032
1032
|
window.bMallCartData = items;
|
|
1033
1033
|
}
|
|
1034
1034
|
return items;
|
|
1035
1035
|
}
|
|
1036
1036
|
|
|
1037
1037
|
async bMallCartHandle(goodItem, num) {
|
|
1038
1038
|
try {
|
|
1039
1039
|
const {
|
|
1040
1040
|
skuUuid,
|
|
1041
1041
|
limitUpper,
|
|
1042
1042
|
limitLower,
|
|
1043
1043
|
} = goodItem;
|
|
1044
1044
|
let cartNum = Number(num);
|
|
1045
1045
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
1046
1046
|
cartNum = limitLower;
|
|
1047
1047
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
1048
1048
|
cartNum = limitUpper;
|
|
1049
1049
|
}
|
|
1050
1050
|
if (skuUuid && cartNum > 0) {
|
|
1051
1051
|
return this.bMallChangeCartService({
|
|
1052
1052
|
...goodItem,
|
|
1053
1053
|
skuUuid,
|
|
1054
1054
|
num: cartNum,
|
|
1055
1055
|
});
|
|
1056
1056
|
} else if (!skuUuid && cartNum > 0) {
|
|
1057
1057
|
return this.bMallAddCartService({ ...goodItem, num: cartNum });
|
|
1058
1058
|
} else if (skuUuid && !cartNum) {
|
|
1059
1059
|
return this.bMallRemoveCartService({
|
|
1060
1060
|
...goodItem,
|
|
1061
1061
|
skuUuid,
|
|
1062
1062
|
num: cartNum,
|
|
1063
1063
|
});
|
|
1064
1064
|
} else {
|
|
1065
1065
|
console.error('参数不全');
|
|
1066
1066
|
return false;
|
|
1067
1067
|
}
|
|
1068
1068
|
} catch (e) {
|
|
1069
1069
|
console.error(e);
|
|
1070
1070
|
}
|
|
1071
1071
|
}
|