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