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