@conecli/cone-render 0.8.20-shop.12 → 0.8.20-shop.14
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/isvStorage/index.h5.ts +1 -0
- package/dist/common/isvStorage/index.ts +1 -0
- package/dist/common/token/index.h5.ts +1 -1
- package/dist/open/api/index.ts +1 -1
- package/dist/open/api/request.ts +1 -0
- package/dist/service/bMallConst.ts +1 -1
- package/dist/service/http/const.ts +1 -1
- package/dist/service/requestServer.ts +1 -1
- package/dist/utils/ready.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const ISV_GLOBAL_CACHE_KEY = '_isvGlobalStorage'
|
|
2
|
if (!key) {
|
|
1
3
|
console.error('setItem key cannot be empty or null')
|
|
2
4
|
return
|
|
3
5
|
}
|
|
4
6
|
console.log('setItem key:', key, value)
|
|
5
7
|
let globalCache = window[ISV_GLOBAL_CACHE_KEY]
|
|
6
8
|
if (!globalCache) {
|
|
7
9
|
globalCache = {}
|
|
8
10
|
window[ISV_GLOBAL_CACHE_KEY] = globalCache
|
|
9
11
|
}
|
|
10
12
|
globalCache[key] = value
|
|
11
13
|
if (!key) {
|
|
12
14
|
console.error('getItem key cannot be empty or null')
|
|
13
15
|
return
|
|
14
16
|
}
|
|
15
17
|
console.log('getItem key:', key)
|
|
16
18
|
let globalCache = window[ISV_GLOBAL_CACHE_KEY] || {}
|
|
17
19
|
const value: any = globalCache[key]
|
|
18
20
|
return value
|
|
19
21
|
if (!key) {
|
|
20
22
|
console.error('removeItem key cannot be empty or null')
|
|
21
23
|
return
|
|
22
24
|
}
|
|
23
25
|
console.log('removeItem key:', key)
|
|
24
26
|
let globalCache = window[ISV_GLOBAL_CACHE_KEY]
|
|
25
27
|
if (globalCache) {
|
|
26
28
|
delete globalCache[key]
|
|
27
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import { isApp } from '../../utils/jm-common'
|
|
2
1
|
return new Promise((resolve, reject) => {
|
|
3
2
|
let platform: string = getPlatform()
|
|
4
3
|
if (platform === TokenPlatform.TYPE_JDAPP) {
|
|
5
4
|
import('./token.jd')
|
|
6
5
|
.then((data) => {
|
|
7
6
|
console.log('data:', data)
|
|
8
7
|
resolve(data)
|
|
9
8
|
})
|
|
10
9
|
.catch((err) => {
|
|
11
10
|
reject(err)
|
|
12
11
|
})
|
|
13
12
|
}
|
|
14
13
|
else if (platform === TokenPlatform.TYPE_WQ) {
|
|
15
14
|
import('./token.wxapp')
|
|
16
15
|
.then((data) => {
|
|
17
16
|
console.log('data:', data)
|
|
18
17
|
resolve(data)
|
|
19
18
|
})
|
|
20
19
|
.catch((err) => {
|
|
21
20
|
reject(err)
|
|
22
21
|
})
|
|
23
22
|
} else {
|
|
24
23
|
import('./token')
|
|
25
24
|
.then((data) => {
|
|
26
25
|
console.log('data:', data)
|
|
27
26
|
resolve(data)
|
|
28
27
|
})
|
|
29
28
|
.catch((err) => {
|
|
30
29
|
reject(err)
|
|
31
30
|
})
|
|
32
31
|
}
|
|
33
32
|
})
|
|
34
33
|
return new Promise((resolve) => {
|
|
35
34
|
loadTokenPromise.then((proxy: any) => {
|
|
36
35
|
if (proxy?.isLogin) {
|
|
37
36
|
proxy?.isLogin().then((data: boolean) => {
|
|
38
37
|
resolve(data)
|
|
39
38
|
})
|
|
40
39
|
} else {
|
|
41
40
|
resolve(false)
|
|
42
41
|
}
|
|
43
42
|
})
|
|
44
43
|
})
|
|
45
44
|
return new Promise((resolve) => {
|
|
46
45
|
loadTokenPromise.then((proxy: any) => {
|
|
47
46
|
if (proxy?.getIsvToken) {
|
|
48
47
|
proxy?.getIsvToken().then((data: string) => {
|
|
49
48
|
resolve(data)
|
|
50
49
|
})
|
|
51
50
|
} else {
|
|
52
51
|
resolve('')
|
|
53
52
|
}
|
|
54
53
|
})
|
|
55
54
|
})
|
|
56
55
|
return new Promise((resolve) => {
|
|
57
56
|
loadTokenPromise.then((proxy: any) => {
|
|
58
57
|
if (proxy?.toLogin) {
|
|
59
58
|
proxy?.toLogin(options)
|
|
60
59
|
resolve(true)
|
|
61
60
|
} else {
|
|
62
61
|
resolve(false)
|
|
63
62
|
}
|
|
64
63
|
})
|
|
65
64
|
})
|
|
66
65
|
let platform = TokenPlatform.TYPE_M
|
|
67
66
|
if (isApp('jd')) {
|
|
68
67
|
platform = TokenPlatform.TYPE_JDAPP
|
|
69
68
|
}
|
|
70
69
|
else if (isApp('wx') && isApp('mp')) {
|
|
71
70
|
platform = TokenPlatform.TYPE_WQ
|
|
72
71
|
}
|
|
73
72
|
return platform
|
|
74
73
|
let platform = getPlatform()
|
|
75
74
|
let source = platform
|
|
76
75
|
if (platform === TokenPlatform.TYPE_M || platform === TokenPlatform.TYPE_WQ) {
|
|
77
76
|
source = TokenPlatform.TYPE_JDAPP
|
|
78
77
|
}
|
|
79
78
|
return source
|
|
80
79
|
return window?.page_data?.pageChannel || ''
|
|
80
|
+
import { isApp } from '../../utils/jm-common'
|
|
81
81
|
return new Promise((resolve, reject) => {
|
|
82
82
|
let platform: string = getPlatform()
|
|
83
83
|
if (platform === TokenPlatform.TYPE_JDAPP) {
|
|
84
84
|
ready('jmfe', 3000)
|
|
85
85
|
.then(() => {
|
|
86
86
|
console.log('window.jmfe已经存在:', jmfe)
|
|
87
87
|
import('./token.jd')
|
|
88
88
|
.then((data) => {
|
|
89
89
|
console.log('data:', data)
|
|
90
90
|
resolve(data)
|
|
91
91
|
})
|
|
92
92
|
.catch((err) => {
|
|
93
93
|
reject(err)
|
|
94
94
|
})
|
|
95
95
|
})
|
|
96
96
|
.catch((e) => {
|
|
97
97
|
console.log('window.jmfe不存在')
|
|
98
98
|
reject(e)
|
|
99
99
|
})
|
|
100
100
|
}
|
|
101
101
|
else if (platform === TokenPlatform.TYPE_WQ) {
|
|
102
102
|
import('./token.wxapp')
|
|
103
103
|
.then((data) => {
|
|
104
104
|
console.log('data:', data)
|
|
105
105
|
resolve(data)
|
|
106
106
|
})
|
|
107
107
|
.catch((err) => {
|
|
108
108
|
reject(err)
|
|
109
109
|
})
|
|
110
110
|
} else {
|
|
111
111
|
import('./token')
|
|
112
112
|
.then((data) => {
|
|
113
113
|
console.log('data:', data)
|
|
114
114
|
resolve(data)
|
|
115
115
|
})
|
|
116
116
|
.catch((err) => {
|
|
117
117
|
reject(err)
|
|
118
118
|
})
|
|
119
119
|
}
|
|
120
120
|
})
|
|
121
121
|
return new Promise((resolve) => {
|
|
122
122
|
loadTokenPromise
|
|
123
123
|
.then((proxy: any) => {
|
|
124
124
|
if (proxy?.isLogin) {
|
|
125
125
|
proxy?.isLogin().then((data: boolean) => {
|
|
126
126
|
resolve(data)
|
|
127
127
|
})
|
|
128
128
|
} else {
|
|
129
129
|
resolve(false)
|
|
130
130
|
}
|
|
131
131
|
})
|
|
132
132
|
.catch((err) => {
|
|
133
133
|
resolve(false)
|
|
134
134
|
})
|
|
135
135
|
})
|
|
136
136
|
return new Promise((resolve) => {
|
|
137
137
|
loadTokenPromise
|
|
138
138
|
.then((proxy: any) => {
|
|
139
139
|
if (proxy?.getIsvToken) {
|
|
140
140
|
proxy?.getIsvToken().then((data: string) => {
|
|
141
141
|
resolve(data)
|
|
142
142
|
})
|
|
143
143
|
} else {
|
|
144
144
|
resolve('')
|
|
145
145
|
}
|
|
146
146
|
})
|
|
147
147
|
.catch((err) => {
|
|
148
148
|
resolve('')
|
|
149
149
|
})
|
|
150
150
|
})
|
|
151
151
|
return new Promise((resolve) => {
|
|
152
152
|
loadTokenPromise
|
|
153
153
|
.then((proxy: any) => {
|
|
154
154
|
if (proxy?.toLogin) {
|
|
155
155
|
proxy?.toLogin(options)
|
|
156
156
|
resolve(true)
|
|
157
157
|
} else {
|
|
158
158
|
resolve(false)
|
|
159
159
|
}
|
|
160
160
|
})
|
|
161
161
|
.catch((err) => {
|
|
162
162
|
resolve(false)
|
|
163
163
|
})
|
|
164
164
|
})
|
|
165
165
|
let platform = TokenPlatform.TYPE_M
|
|
166
166
|
if (isApp('jd')) {
|
|
167
167
|
platform = TokenPlatform.TYPE_JDAPP
|
|
168
168
|
}
|
|
169
169
|
else if (isApp('wx') && isApp('mp')) {
|
|
170
170
|
platform = TokenPlatform.TYPE_WQ
|
|
171
171
|
}
|
|
172
172
|
return platform
|
|
173
173
|
let platform = getPlatform()
|
|
174
174
|
let source = platform
|
|
175
175
|
if (platform === TokenPlatform.TYPE_M || platform === TokenPlatform.TYPE_WQ) {
|
|
176
176
|
source = TokenPlatform.TYPE_JDAPP
|
|
177
177
|
}
|
|
178
178
|
return source
|
|
179
179
|
return window?.page_data?.pageChannel || ''
|
package/dist/open/api/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import * as device from './device'
|
|
2
1
|
device,
|
|
3
2
|
environment,
|
|
4
3
|
jump,
|
|
5
4
|
storage,
|
|
6
5
|
util,
|
|
7
6
|
moduleUtil,
|
|
8
7
|
track,
|
|
9
8
|
trackPromise,
|
|
10
9
|
global,
|
|
11
10
|
http,
|
|
12
11
|
shopMember,
|
|
13
12
|
userToken,
|
|
14
13
|
TokenPlatform,
|
|
15
14
|
requestServer,
|
|
15
|
+
import * as device from './device'
|
|
16
16
|
device,
|
|
17
17
|
environment,
|
|
18
18
|
jump,
|
|
19
19
|
storage,
|
|
20
20
|
util,
|
|
21
21
|
moduleUtil,
|
|
22
22
|
track,
|
|
23
23
|
trackPromise,
|
|
24
24
|
global,
|
|
25
25
|
http,
|
|
26
26
|
shopMember,
|
|
27
27
|
userToken,
|
|
28
28
|
TokenPlatform,
|
|
29
29
|
requestServer,
|
|
30
30
|
isvStorage,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import requestServer from '../../service/requestServer'
|
|
2
|
return requestServer.receiveCoupon(param, clientParams)
|
|
1
3
|
return requestServer.bMallGetUserInfo()
|
|
2
4
|
return requestServer.bMallGetSkuNumApi(needRequest, bMallTag)
|
|
3
5
|
return requestServer.bMallCartHandle(goodItem, num)
|
|
4
6
|
receiveCoupon,
|
|
5
7
|
bMallGetUserInfo,
|
|
6
8
|
bMallGetSkuNumApi,
|
|
7
9
|
bMallCartHandle
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import { isAndroidDevice } from '../utils'
|
|
2
1
|
buId: '',
|
|
3
2
|
const requestTimeoutPromise = new Promise((resolve) => {
|
|
4
3
|
setTimeout(() => {
|
|
5
4
|
resolve({})
|
|
6
5
|
}, 3000)
|
|
7
6
|
})
|
|
8
7
|
const userInfoPromise = new Promise((resolve) => {
|
|
9
8
|
let result: any = {}
|
|
10
9
|
try {
|
|
11
10
|
if (isAndroidDevice) {
|
|
12
11
|
result = JSON.parse(
|
|
13
12
|
window.WebViewCommon && window.WebViewCommon.getUserInfo(),
|
|
14
13
|
)
|
|
15
14
|
commonParam.buId = result?.data?.buId
|
|
16
15
|
resolve(result)
|
|
17
16
|
} else {
|
|
18
17
|
window.getUserInfoCallBack = null
|
|
19
18
|
window.getUserInfoCallBack = function (callBackJson) {
|
|
20
19
|
console.log('in???callBackJson', callBackJson)
|
|
21
20
|
if (callBackJson) {
|
|
22
21
|
result.data = JSON.parse(callBackJson)
|
|
23
22
|
commonParam.buId = result?.data?.buId
|
|
24
23
|
resolve(result)
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
console.log(
|
|
28
27
|
'window?.webkit?.messageHandlers?.WebViewCommon?.postMessage',
|
|
29
28
|
window?.webkit?.messageHandlers?.WebViewCommon?.postMessage,
|
|
30
29
|
)
|
|
31
30
|
window?.webkit?.messageHandlers?.WebViewCommon?.postMessage({
|
|
32
31
|
businessType: 'router://com.jd.jlstudio/getUserInfo',
|
|
33
32
|
params: {},
|
|
34
33
|
callBackName: 'getUserInfoCallBack',
|
|
35
34
|
method: 'callRouterModuleWithParams',
|
|
36
35
|
})
|
|
37
36
|
}
|
|
38
37
|
} catch (e) {
|
|
39
38
|
resolve(result)
|
|
40
39
|
}
|
|
41
40
|
})
|
|
42
41
|
return Promise.race([userInfoPromise, requestTimeoutPromise])
|
|
43
42
|
process.env.NODE_ENV === 'development'
|
|
44
43
|
? {
|
|
45
44
|
apolloId: '48ee955b0fb04d19b9f9fe8cb73d387f',
|
|
46
45
|
apolloSecret: '0d9c76ee66b0487da4e17d3cf1d7af7a',
|
|
47
46
|
}
|
|
48
47
|
: {
|
|
49
48
|
apolloId: '80c46fd06e4442998609d9f6a4ab96f0',
|
|
50
49
|
apolloSecret: 'f36bef08bcba4683b409732095793fb2',
|
|
51
50
|
}
|
|
52
51
|
if (typeof window.crypto === 'object') {
|
|
53
52
|
if (typeof (window.crypto as any).randomUUID === 'function') {
|
|
54
53
|
return (window.crypto as any).randomUUID()
|
|
55
54
|
}
|
|
56
55
|
if (
|
|
57
56
|
typeof (window.crypto as any).getRandomValues === 'function' &&
|
|
58
57
|
typeof Uint8Array === 'function'
|
|
59
58
|
) {
|
|
60
59
|
const callback = (c) => {
|
|
61
60
|
const num = Number(c)
|
|
62
61
|
return (
|
|
63
62
|
num ^
|
|
64
63
|
((window.crypto as any).getRandomValues(new Uint8Array(1))[0] &
|
|
65
64
|
(15 >> (num / 4)))
|
|
66
65
|
).toString(16)
|
|
67
66
|
}
|
|
68
67
|
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, callback)
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
let timestamp = new Date().getTime()
|
|
72
71
|
let perforNow =
|
|
73
72
|
(typeof window.performance !== 'undefined' &&
|
|
74
73
|
window.performance.now &&
|
|
75
74
|
window.performance.now() * 1000) ||
|
|
76
75
|
0
|
|
77
76
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
78
77
|
let random = Math.random() * 16
|
|
79
78
|
if (timestamp > 0) {
|
|
80
79
|
random = (timestamp + random) % 16 | 0
|
|
81
80
|
timestamp = Math.floor(timestamp / 16)
|
|
82
81
|
} else {
|
|
83
82
|
random = (perforNow + random) % 16 | 0
|
|
84
83
|
perforNow = Math.floor(perforNow / 16)
|
|
85
84
|
}
|
|
86
85
|
return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
|
|
87
86
|
})
|
|
88
87
|
skuId,
|
|
89
88
|
bMallTag = 1,
|
|
90
89
|
num,
|
|
91
90
|
skuUuid,
|
|
92
91
|
...otherGoodParams
|
|
93
92
|
let buId = commonParam.buId
|
|
94
93
|
if (!buId) {
|
|
95
94
|
const useInfo: any = await getBMallUserInfo()
|
|
96
95
|
buId = useInfo?.data?.buId
|
|
97
96
|
}
|
|
98
97
|
let params: any = {
|
|
99
98
|
uniformBizInfo: {
|
|
100
99
|
tenantId: 1024,
|
|
101
100
|
ua: 1,
|
|
102
101
|
buId: buId || 456,
|
|
103
102
|
bMallTag: bMallTag,
|
|
104
103
|
},
|
|
105
104
|
commonParam: {
|
|
106
105
|
pid: 100,
|
|
107
106
|
verticalCode: 'cn_retail_bmall',
|
|
108
107
|
ua: 1,
|
|
109
108
|
language: 'zh',
|
|
110
109
|
},
|
|
111
110
|
operations: [{ TheSkus: [{ Id: skuId, num: num ?? 1 }] }],
|
|
112
111
|
apolloId: APOLLO.apolloId,
|
|
113
112
|
apolloSecret: APOLLO.apolloSecret,
|
|
114
113
|
client: 'H5',
|
|
115
114
|
verticalTag: 'cn_retail_bmall',
|
|
116
115
|
carttype: bMallTag == 1 ? 21 : 22,
|
|
117
116
|
bMallTag: bMallTag,
|
|
118
117
|
traceId: getUuid(),
|
|
119
118
|
noResponse: true,
|
|
120
119
|
}
|
|
121
120
|
if (skuUuid) {
|
|
122
121
|
params.operations[0].TheSkus[0].skuUuid = skuUuid
|
|
123
122
|
}
|
|
124
123
|
if (otherGoodParams.buId) {
|
|
125
124
|
const uniformBizInfo = {
|
|
126
125
|
buId: otherGoodParams.buId,
|
|
127
126
|
}
|
|
128
127
|
params.operations[0].TheSkus[0].uniformBizInfo = uniformBizInfo
|
|
129
128
|
}
|
|
130
129
|
if (window?.siteTransResult?.gridInfoList) {
|
|
131
130
|
params = {
|
|
132
131
|
...params,
|
|
133
132
|
cartLocationList: [
|
|
134
133
|
{
|
|
135
134
|
gridInfos:
|
|
136
135
|
window?.siteTransResult?.gridInfoList &&
|
|
137
136
|
JSON.parse(window?.siteTransResult?.gridInfoList),
|
|
138
137
|
areaIdSet:
|
|
139
138
|
window?.siteTransResult?.area &&
|
|
140
139
|
window?.siteTransResult?.area?.split('-'),
|
|
141
140
|
},
|
|
142
141
|
],
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
return params
|
|
145
|
+
import { isAndroidDevice } from '../utils'
|
|
146
146
|
buId: '',
|
|
147
147
|
console.log('getBMallUserInfo')
|
|
148
148
|
if (!isApp('jdb')) {
|
|
149
149
|
return null
|
|
150
150
|
}
|
|
151
151
|
const requestTimeoutPromise = new Promise((resolve) => {
|
|
152
152
|
setTimeout(() => {
|
|
153
153
|
resolve({})
|
|
154
154
|
}, 3000)
|
|
155
155
|
})
|
|
156
156
|
const userInfoPromise = new Promise((resolve) => {
|
|
157
157
|
let result: any = {}
|
|
158
158
|
try {
|
|
159
159
|
if (isAndroidDevice) {
|
|
160
160
|
result = JSON.parse(
|
|
161
161
|
window.WebViewCommon && window.WebViewCommon.getUserInfo(),
|
|
162
162
|
)
|
|
163
163
|
commonParam.buId = result?.data?.buId
|
|
164
164
|
resolve(result)
|
|
165
165
|
} else {
|
|
166
166
|
window.getUserInfoCallBack = null
|
|
167
167
|
window.getUserInfoCallBack = function (callBackJson) {
|
|
168
168
|
console.log('in???callBackJson', callBackJson)
|
|
169
169
|
if (callBackJson) {
|
|
170
170
|
result.data = JSON.parse(callBackJson)
|
|
171
171
|
commonParam.buId = result?.data?.buId
|
|
172
172
|
resolve(result)
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
console.log(
|
|
176
176
|
'window?.webkit?.messageHandlers?.WebViewCommon?.postMessage',
|
|
177
177
|
window?.webkit?.messageHandlers?.WebViewCommon?.postMessage,
|
|
178
178
|
)
|
|
179
179
|
window?.webkit?.messageHandlers?.WebViewCommon?.postMessage({
|
|
180
180
|
businessType: 'router://com.jd.jlstudio/getUserInfo',
|
|
181
181
|
params: {},
|
|
182
182
|
callBackName: 'getUserInfoCallBack',
|
|
183
183
|
method: 'callRouterModuleWithParams',
|
|
184
184
|
})
|
|
185
185
|
}
|
|
186
186
|
} catch (e) {
|
|
187
187
|
resolve(result)
|
|
188
188
|
}
|
|
189
189
|
})
|
|
190
190
|
return Promise.race([userInfoPromise, requestTimeoutPromise])
|
|
191
191
|
process.env.NODE_ENV === 'development'
|
|
192
192
|
? {
|
|
193
193
|
apolloId: '48ee955b0fb04d19b9f9fe8cb73d387f',
|
|
194
194
|
apolloSecret: '0d9c76ee66b0487da4e17d3cf1d7af7a',
|
|
195
195
|
}
|
|
196
196
|
: {
|
|
197
197
|
apolloId: '80c46fd06e4442998609d9f6a4ab96f0',
|
|
198
198
|
apolloSecret: 'f36bef08bcba4683b409732095793fb2',
|
|
199
199
|
}
|
|
200
200
|
if (typeof window.crypto === 'object') {
|
|
201
201
|
if (typeof (window.crypto as any).randomUUID === 'function') {
|
|
202
202
|
return (window.crypto as any).randomUUID()
|
|
203
203
|
}
|
|
204
204
|
if (
|
|
205
205
|
typeof (window.crypto as any).getRandomValues === 'function' &&
|
|
206
206
|
typeof Uint8Array === 'function'
|
|
207
207
|
) {
|
|
208
208
|
const callback = (c) => {
|
|
209
209
|
const num = Number(c)
|
|
210
210
|
return (
|
|
211
211
|
num ^
|
|
212
212
|
((window.crypto as any).getRandomValues(new Uint8Array(1))[0] &
|
|
213
213
|
(15 >> (num / 4)))
|
|
214
214
|
).toString(16)
|
|
215
215
|
}
|
|
216
216
|
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, callback)
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
let timestamp = new Date().getTime()
|
|
220
220
|
let perforNow =
|
|
221
221
|
(typeof window.performance !== 'undefined' &&
|
|
222
222
|
window.performance.now &&
|
|
223
223
|
window.performance.now() * 1000) ||
|
|
224
224
|
0
|
|
225
225
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
226
226
|
let random = Math.random() * 16
|
|
227
227
|
if (timestamp > 0) {
|
|
228
228
|
random = (timestamp + random) % 16 | 0
|
|
229
229
|
timestamp = Math.floor(timestamp / 16)
|
|
230
230
|
} else {
|
|
231
231
|
random = (perforNow + random) % 16 | 0
|
|
232
232
|
perforNow = Math.floor(perforNow / 16)
|
|
233
233
|
}
|
|
234
234
|
return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
|
|
235
235
|
})
|
|
236
236
|
skuId,
|
|
237
237
|
bMallTag = 1,
|
|
238
238
|
num,
|
|
239
239
|
skuUuid,
|
|
240
240
|
...otherGoodParams
|
|
241
241
|
let buId = commonParam.buId
|
|
242
242
|
if (!buId) {
|
|
243
243
|
const useInfo: any = await getBMallUserInfo()
|
|
244
244
|
buId = useInfo?.data?.buId
|
|
245
245
|
}
|
|
246
246
|
let params: any = {
|
|
247
247
|
uniformBizInfo: {
|
|
248
248
|
tenantId: 1024,
|
|
249
249
|
ua: 1,
|
|
250
250
|
buId: buId || 456,
|
|
251
251
|
bMallTag: bMallTag,
|
|
252
252
|
},
|
|
253
253
|
commonParam: {
|
|
254
254
|
pid: 100,
|
|
255
255
|
verticalCode: 'cn_retail_bmall',
|
|
256
256
|
ua: 1,
|
|
257
257
|
language: 'zh',
|
|
258
258
|
},
|
|
259
259
|
operations: [{ TheSkus: [{ Id: skuId, num: num ?? 1 }] }],
|
|
260
260
|
apolloId: APOLLO.apolloId,
|
|
261
261
|
apolloSecret: APOLLO.apolloSecret,
|
|
262
262
|
client: 'H5',
|
|
263
263
|
verticalTag: 'cn_retail_bmall',
|
|
264
264
|
carttype: bMallTag == 1 ? 21 : 22,
|
|
265
265
|
bMallTag: bMallTag,
|
|
266
266
|
traceId: getUuid(),
|
|
267
267
|
noResponse: true,
|
|
268
268
|
}
|
|
269
269
|
if (skuUuid) {
|
|
270
270
|
params.operations[0].TheSkus[0].skuUuid = skuUuid
|
|
271
271
|
}
|
|
272
272
|
if (otherGoodParams.buId) {
|
|
273
273
|
const uniformBizInfo = {
|
|
274
274
|
buId: otherGoodParams.buId,
|
|
275
275
|
}
|
|
276
276
|
params.operations[0].TheSkus[0].uniformBizInfo = uniformBizInfo
|
|
277
277
|
}
|
|
278
278
|
if (window?.siteTransResult?.gridInfoList) {
|
|
279
279
|
params = {
|
|
280
280
|
...params,
|
|
281
281
|
cartLocationList: [
|
|
282
282
|
{
|
|
283
283
|
gridInfos:
|
|
284
284
|
window?.siteTransResult?.gridInfoList &&
|
|
285
285
|
JSON.parse(window?.siteTransResult?.gridInfoList),
|
|
286
286
|
areaIdSet:
|
|
287
287
|
window?.siteTransResult?.area &&
|
|
288
288
|
window?.siteTransResult?.area?.split('-'),
|
|
289
289
|
},
|
|
290
290
|
],
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
return params
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const HttpStatus = {
|
|
2
1
|
SUCCESS: 200,
|
|
3
2
|
CREATED: 201,
|
|
4
3
|
ACCEPTED: 202,
|
|
5
4
|
CLIENT_ERROR: 400,
|
|
6
5
|
AUTHENTICATE: 401,
|
|
7
6
|
FORBIDDEN: 403,
|
|
8
7
|
NOT_FOUND: 404,
|
|
9
8
|
SERVER_ERROR: 500,
|
|
10
9
|
BAD_GATEWAY: 502,
|
|
11
10
|
SERVICE_UNAVAILABLE: 503,
|
|
12
11
|
GATEWAY_TIMEOUT: 504,
|
|
13
12
|
[HttpStatus.NOT_FOUND]: '请求资源不存在',
|
|
14
13
|
[HttpStatus.BAD_GATEWAY]: '服务端异常,请稍后重试',
|
|
15
14
|
[HttpStatus.FORBIDDEN]: '没有权限访问',
|
|
16
15
|
[HttpStatus.AUTHENTICATE]: '需要鉴权',
|
|
17
16
|
[HttpStatus.SUCCESS]: '成功',
|
|
18
17
|
'whx_getShopHomeFloorInfo',
|
|
19
18
|
'whx_searchWare',
|
|
20
19
|
'shopGuessYouLike',
|
|
21
20
|
'whx_getMShopCategory',
|
|
22
21
|
'whx_newWareList',
|
|
23
22
|
'getShopHomePromotionWebPage',
|
|
24
23
|
'whx_getShopCampaignPage',
|
|
25
24
|
'whx_getPromotionWares',
|
|
26
25
|
'whx_buyerShowPage',
|
|
27
26
|
'whx_getShopGwredPage',
|
|
28
27
|
'whx_getShopSpeciSecKillPage',
|
|
29
28
|
'whx_getSignInfo',
|
|
30
29
|
'whx_getSignPrize',
|
|
31
30
|
'getShopHomeFloorInfo',
|
|
32
31
|
'shopGuessYouLike',
|
|
33
32
|
'getShopHomePromotionWebPage',
|
|
34
33
|
'getVipDetail',
|
|
35
34
|
'getShopCategory',
|
|
36
35
|
'getShopNavigationCategory',
|
|
37
36
|
'getPagePreview',
|
|
38
37
|
'bmall_cart',
|
|
39
38
|
'bmall_getOmittedProduct',
|
|
40
39
|
'bmall_cartAdd',
|
|
41
40
|
'bmall_cartChange',
|
|
42
41
|
'bmall_cartRemove',
|
|
43
42
|
'getShopHomeFloorInfo',
|
|
44
43
|
'getShopCategory',
|
|
45
44
|
'getShopNavigationCategory',
|
|
46
45
|
'receiveShopCoupon',
|
|
47
46
|
'getShopHomePromotionWebPage',
|
|
48
47
|
'shopGuessYouLike',
|
|
49
48
|
'addRemind',
|
|
50
49
|
'cancelRemind',
|
|
51
50
|
'getVipDetail',
|
|
52
51
|
'shopDetail',
|
|
53
52
|
'address_queryAddress',
|
|
54
53
|
'shopMemberSprintJoinActivity',
|
|
55
54
|
'shopMemberSprintReceivePrize',
|
|
56
55
|
'bmall_cart',
|
|
57
56
|
'bmall_getOmittedProduct',
|
|
58
57
|
'bmall_cartAdd',
|
|
59
58
|
'bmall_cartChange',
|
|
60
59
|
'bmall_cartRemove',
|
|
60
|
+
export const HttpStatus = {
|
|
61
61
|
SUCCESS: 200,
|
|
62
62
|
CREATED: 201,
|
|
63
63
|
ACCEPTED: 202,
|
|
64
64
|
CLIENT_ERROR: 400,
|
|
65
65
|
AUTHENTICATE: 401,
|
|
66
66
|
FORBIDDEN: 403,
|
|
67
67
|
NOT_FOUND: 404,
|
|
68
68
|
SERVER_ERROR: 500,
|
|
69
69
|
BAD_GATEWAY: 502,
|
|
70
70
|
SERVICE_UNAVAILABLE: 503,
|
|
71
71
|
GATEWAY_TIMEOUT: 504,
|
|
72
72
|
[HttpStatus.NOT_FOUND]: '请求资源不存在',
|
|
73
73
|
[HttpStatus.BAD_GATEWAY]: '服务端异常,请稍后重试',
|
|
74
74
|
[HttpStatus.FORBIDDEN]: '没有权限访问',
|
|
75
75
|
[HttpStatus.AUTHENTICATE]: '需要鉴权',
|
|
76
76
|
[HttpStatus.SUCCESS]: '成功',
|
|
77
77
|
'whx_getShopHomeFloorInfo',
|
|
78
78
|
'whx_searchWare',
|
|
79
79
|
'shopGuessYouLike',
|
|
80
80
|
'whx_getMShopCategory',
|
|
81
81
|
'whx_newWareList',
|
|
82
82
|
'getShopHomePromotionWebPage',
|
|
83
83
|
'whx_getShopCampaignPage',
|
|
84
84
|
'whx_getPromotionWares',
|
|
85
85
|
'whx_buyerShowPage',
|
|
86
86
|
'whx_getShopGwredPage',
|
|
87
87
|
'whx_getShopSpeciSecKillPage',
|
|
88
88
|
'whx_getSignInfo',
|
|
89
89
|
'whx_getSignPrize',
|
|
90
90
|
'getShopHomeFloorInfo',
|
|
91
91
|
'shopGuessYouLike',
|
|
92
92
|
'getShopHomePromotionWebPage',
|
|
93
93
|
'getVipDetail',
|
|
94
94
|
'getShopCategory',
|
|
95
95
|
'getShopNavigationCategory',
|
|
96
96
|
'getPagePreview',
|
|
97
97
|
'bmall_cart',
|
|
98
98
|
'bmall_getOmittedProduct',
|
|
99
99
|
'bmall_cartAdd',
|
|
100
100
|
'bmall_cartChange',
|
|
101
101
|
'bmall_cartRemove',
|
|
102
102
|
'getShopHomeFloorInfo',
|
|
103
103
|
'getShopCategory',
|
|
104
104
|
'getShopNavigationCategory',
|
|
105
105
|
'receiveShopCoupon',
|
|
106
106
|
'getShopHomePromotionWebPage',
|
|
107
107
|
'shopGuessYouLike',
|
|
108
108
|
'addRemind',
|
|
109
109
|
'cancelRemind',
|
|
110
110
|
'getVipDetail',
|
|
111
111
|
'shopDetail',
|
|
112
112
|
'address_queryAddress',
|
|
113
113
|
'shopMemberSprintJoinActivity',
|
|
114
114
|
'shopMemberSprintReceivePrize',
|
|
115
115
|
'customerCenterDispatch'
|
|
116
116
|
'bmall_cart',
|
|
117
117
|
'bmall_getOmittedProduct',
|
|
118
118
|
'bmall_cartAdd',
|
|
119
119
|
'bmall_cartChange',
|
|
120
120
|
'bmall_cartRemove',
|
|
121
121
|
SHOP_COLOR_APPID: 'shop_m_jd_com',
|
|
122
122
|
JSHOPX_COLOR_APPID: 'jshopx_jd_com',
|
|
123
123
|
PAGES_COLOR_APPID: 'pages_jd_com',
|
|
124
124
|
B2B_COLOR_APPID: 'b2b',
|
|
125
125
|
SHOP_MEMBER_COLOR_APPID: 'shopmember_m_jd_com'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
2
1
|
SHOP_COLOR_APPID,
|
|
3
2
|
JshopxColorFunctionIdList,
|
|
4
3
|
PagesColorFunctionIdList,
|
|
5
4
|
JSHOPX_COLOR_APPID,
|
|
6
5
|
PAGES_COLOR_APPID,
|
|
7
6
|
PAGES_DOMAIN,
|
|
8
7
|
B2BColorFunctionIdList,
|
|
9
8
|
B2B_COLOR_APPID,
|
|
10
9
|
MobileVerifyColorList,
|
|
11
10
|
AppVerifyColorList,
|
|
12
11
|
JshopxVerifyColorList,
|
|
13
12
|
BMallVerifyColorList,
|
|
14
13
|
cookiesStr: '',
|
|
15
14
|
requestHeaderContentType: {
|
|
16
15
|
jsonHeader: {
|
|
17
16
|
'content-type': 'application/json;charset=utf-8',
|
|
18
17
|
},
|
|
19
18
|
formDataHeader: {
|
|
20
19
|
'content-type': 'application/x-www-form-urlencoded',
|
|
21
20
|
},
|
|
22
21
|
},
|
|
23
22
|
requestBaseParam: {
|
|
24
23
|
data: null,
|
|
25
24
|
header: {
|
|
26
25
|
'content-type': 'application/json;charset=utf-8',
|
|
27
26
|
},
|
|
28
27
|
},
|
|
29
28
|
timeOut: 7000,
|
|
30
29
|
apiClientParams: {
|
|
31
30
|
appid: SHOP_COLOR_APPID,
|
|
32
31
|
clientVersion:
|
|
33
32
|
isH5AndJdShopView && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
|
|
34
33
|
client: isH5AndJdShopView ? (isIosDevice ? 'apple' : 'android') : 'wh5',
|
|
35
34
|
area: '1_72_2799_0',
|
|
36
35
|
uuid: UUID,
|
|
37
36
|
},
|
|
38
37
|
public addressFetchInfo: {
|
|
39
38
|
reqState: boolean
|
|
40
39
|
promiseInstance: null | Promise<any>
|
|
41
40
|
}
|
|
42
41
|
public getPromotionConfig: {
|
|
43
42
|
projectId: null | string | number
|
|
44
43
|
pageId: null | string | number
|
|
45
44
|
}
|
|
46
45
|
public resInfo: ServiceInterFace.HttpRequestInfo
|
|
47
46
|
public api: ServiceInterFace.HttpApi
|
|
48
47
|
public isPageDomain: boolean
|
|
49
48
|
public verifyColorList: string[]
|
|
50
49
|
constructor(opt) {
|
|
51
50
|
this._init()
|
|
52
51
|
this.addressFetchInfo = {
|
|
53
52
|
reqState: false,
|
|
54
53
|
promiseInstance: null,
|
|
55
54
|
}
|
|
56
55
|
this.getPromotionConfig = {
|
|
57
56
|
projectId: null,
|
|
58
57
|
pageId: null,
|
|
59
58
|
}
|
|
60
59
|
this._userAreaUpdateListen()
|
|
61
60
|
this.resInfo = this._getResConfig(opt)
|
|
62
61
|
this.api = api
|
|
63
62
|
this.isPageDomain = window.location.hostname === PAGES_DOMAIN
|
|
64
63
|
this.verifyColorList = [
|
|
65
64
|
...MobileVerifyColorList,
|
|
66
65
|
...AppVerifyColorList,
|
|
67
66
|
...JshopxVerifyColorList,
|
|
68
67
|
...BMallVerifyColorList,
|
|
69
68
|
]
|
|
70
69
|
}
|
|
71
70
|
_init(): void {
|
|
72
71
|
httpInterceptors.forEach((item) => {
|
|
73
72
|
Taro.addInterceptor((chain) => item(chain))
|
|
74
73
|
})
|
|
75
74
|
}
|
|
76
75
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
77
76
|
return Object.assign({}, DefaultConfig, opt)
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
_userAreaUpdateListen() {
|
|
81
80
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
|
|
82
81
|
this.updateApiClientParamsResInfo({
|
|
83
82
|
area,
|
|
84
83
|
})
|
|
85
84
|
})
|
|
86
85
|
}
|
|
87
86
|
updateApiClientParamsResInfo(opt = {}) {
|
|
88
87
|
this.resInfo.apiClientParams = {
|
|
89
88
|
...this.resInfo.apiClientParams,
|
|
90
89
|
...opt,
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
checkFunctionIdToReturnAppId(functionId) {
|
|
95
94
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
96
95
|
return JSHOPX_COLOR_APPID
|
|
97
96
|
} else if (
|
|
98
97
|
this.isPageDomain &&
|
|
99
98
|
PagesColorFunctionIdList.includes(functionId)
|
|
100
99
|
) {
|
|
101
100
|
return PAGES_COLOR_APPID
|
|
102
101
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
103
102
|
return B2B_COLOR_APPID
|
|
104
103
|
} else {
|
|
105
104
|
return SHOP_COLOR_APPID
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
gatewayReq(
|
|
110
109
|
functionId: string,
|
|
111
110
|
bodyParams = {},
|
|
112
111
|
clientParams = {},
|
|
113
112
|
): Promise<any> {
|
|
114
113
|
if (
|
|
115
114
|
functionId === 'receiveShopCoupon' &&
|
|
116
115
|
((isH5 && window.isJingGouMiniViewState) || isWxMinAndWxapp)
|
|
117
116
|
) {
|
|
118
117
|
clientParams = Object.assign(
|
|
119
118
|
{},
|
|
120
119
|
{
|
|
121
120
|
loginType: '1',
|
|
122
121
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
123
122
|
},
|
|
124
123
|
clientParams,
|
|
125
124
|
)
|
|
126
125
|
}
|
|
127
126
|
const apiClientParams = Object.assign(
|
|
128
127
|
{},
|
|
129
128
|
this.resInfo.apiClientParams,
|
|
130
129
|
clientParams,
|
|
131
130
|
)
|
|
132
131
|
apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId)
|
|
133
132
|
const isColorVerify = this.verifyColorList.includes(functionId)
|
|
134
133
|
const getReqData = {
|
|
135
134
|
functionId: functionId,
|
|
136
135
|
body: JSON.stringify(bodyParams),
|
|
137
136
|
t: Date.now(),
|
|
138
137
|
...apiClientParams,
|
|
139
138
|
}
|
|
140
139
|
return http
|
|
141
140
|
.request({
|
|
142
141
|
url: this.api.apiFunc,
|
|
143
142
|
data: getReqData,
|
|
144
143
|
isColorVerify,
|
|
145
144
|
})
|
|
146
145
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
147
146
|
const { statusCode, data } = res
|
|
148
147
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
149
148
|
ok: true,
|
|
150
149
|
}
|
|
151
150
|
if (statusCode === 200 && data) {
|
|
152
151
|
const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
|
|
153
152
|
? Number(res.data.code)
|
|
154
153
|
: -1
|
|
155
154
|
const subCode = Object.prototype.hasOwnProperty.call(
|
|
156
155
|
res.data,
|
|
157
156
|
'subCode',
|
|
158
157
|
)
|
|
159
158
|
? Number(res.data.subCode)
|
|
160
159
|
: -1
|
|
161
160
|
if (
|
|
162
161
|
data.success === true ||
|
|
163
162
|
data.isSuccess ||
|
|
164
163
|
resCode === 0 ||
|
|
165
164
|
resCode === 200 ||
|
|
166
165
|
subCode === 0
|
|
167
166
|
) {
|
|
168
167
|
changeRes = {
|
|
169
168
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
170
169
|
? data.result
|
|
171
170
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
172
171
|
? data.data
|
|
173
172
|
: data,
|
|
174
173
|
code: data.code || 200,
|
|
175
174
|
ok: true,
|
|
176
175
|
source: data,
|
|
177
176
|
}
|
|
178
177
|
return changeRes
|
|
179
178
|
} else {
|
|
180
179
|
changeRes = {
|
|
181
180
|
...data,
|
|
182
181
|
ok: false,
|
|
183
182
|
statusCode: res.statusCode,
|
|
184
183
|
}
|
|
185
184
|
return changeRes
|
|
186
185
|
}
|
|
187
186
|
} else {
|
|
188
187
|
changeRes = {
|
|
189
188
|
...data,
|
|
190
189
|
ok: false,
|
|
191
190
|
statusCode: res.statusCode,
|
|
192
191
|
}
|
|
193
192
|
return changeRes
|
|
194
193
|
}
|
|
195
194
|
})
|
|
196
195
|
.catch((res) => {
|
|
197
196
|
return {
|
|
198
197
|
...res,
|
|
199
198
|
ok: false,
|
|
200
199
|
} as ServiceInterFace.RequestResponseFormatRes
|
|
201
200
|
})
|
|
202
201
|
}
|
|
203
202
|
|
|
204
203
|
async receiveCoupon(param = {}, clientParams) {
|
|
205
204
|
return await this.gatewayReq(
|
|
206
205
|
'receiveShopCoupon',
|
|
207
206
|
{
|
|
208
207
|
operation: '3',
|
|
209
208
|
...param,
|
|
210
209
|
},
|
|
211
210
|
clientParams,
|
|
212
211
|
)
|
|
213
212
|
}
|
|
214
213
|
bMallGetUserInfo = () => {
|
|
215
214
|
return bMallUserInfo
|
|
216
215
|
}
|
|
217
216
|
async bMallAddCart(params = {}) {
|
|
218
217
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
219
218
|
client: 'H5',
|
|
220
219
|
clientVersion: '5.5.0'
|
|
221
220
|
})
|
|
222
221
|
}
|
|
223
222
|
async bMallChangeCart(params = {}) {
|
|
224
223
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
225
224
|
client: 'H5',
|
|
226
225
|
clientVersion: '5.5.0'
|
|
227
226
|
})
|
|
228
227
|
}
|
|
229
228
|
async bMallRemoveCart(params = {}) {
|
|
230
229
|
return await this.gatewayReq(
|
|
231
230
|
'bmall_cartRemove',
|
|
232
231
|
params,
|
|
233
232
|
{
|
|
234
233
|
client: 'H5',
|
|
235
234
|
clientVersion: '5.5.0'
|
|
236
235
|
},
|
|
237
236
|
)
|
|
238
237
|
}
|
|
239
238
|
async bMallGetOmittedProduct(params = {}) {
|
|
240
239
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
241
240
|
client: 'H5',
|
|
242
241
|
clientVersion: '5.5.0'
|
|
243
242
|
})
|
|
244
243
|
}
|
|
245
244
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
246
245
|
const params = await getParams({ ...data, skuId, bMallTag, num })
|
|
247
246
|
return await this.bMallAddCart(params)
|
|
248
247
|
}
|
|
249
248
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
250
249
|
const params = await getParams({ bMallTag })
|
|
251
250
|
delete params.operations
|
|
252
251
|
return await this.bMallGetOmittedProduct(params)
|
|
253
252
|
}
|
|
254
253
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
255
254
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
256
255
|
return await this.bMallRemoveCart(params)
|
|
257
256
|
}
|
|
258
257
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
259
258
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
260
259
|
return await this.bMallChangeCart(params)
|
|
261
260
|
}
|
|
262
261
|
|
|
263
262
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
264
263
|
if (!needRequest && window.bMallCartData) {
|
|
265
264
|
return window.bMallCartData
|
|
266
265
|
}
|
|
267
266
|
const cartData = await this.bMallGetSkuNumService(bMallTag)
|
|
268
267
|
let items
|
|
269
268
|
if (cartData.ok && cartData.result) {
|
|
270
269
|
items = cartData?.result?.items || {}
|
|
271
270
|
}
|
|
272
271
|
window.bMallCartData = items
|
|
273
272
|
return items
|
|
274
273
|
}
|
|
275
274
|
|
|
276
275
|
async bMallCartHandle(goodItem, num) {
|
|
277
276
|
try {
|
|
278
277
|
const {
|
|
279
278
|
skuUuid,
|
|
280
279
|
limitUpper,
|
|
281
280
|
limitLower,
|
|
282
281
|
} = goodItem
|
|
283
282
|
let cartNum = Number(num)
|
|
284
283
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
285
284
|
cartNum = limitLower
|
|
286
285
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
287
286
|
cartNum = limitUpper
|
|
288
287
|
}
|
|
289
288
|
if (skuUuid && cartNum > 0) {
|
|
290
289
|
return this.bMallChangeCartService({
|
|
291
290
|
...goodItem,
|
|
292
291
|
skuUuid,
|
|
293
292
|
num: cartNum,
|
|
294
293
|
})
|
|
295
294
|
} else if (!skuUuid && cartNum > 0) {
|
|
296
295
|
return this.bMallAddCartService({ ...goodItem, num: cartNum })
|
|
297
296
|
} else if (skuUuid && !cartNum) {
|
|
298
297
|
return this.bMallRemoveCartService({
|
|
299
298
|
...goodItem,
|
|
300
299
|
skuUuid,
|
|
301
300
|
num: cartNum,
|
|
302
301
|
})
|
|
303
302
|
} else {
|
|
304
303
|
console.error('参数不全')
|
|
305
304
|
return false
|
|
306
305
|
}
|
|
307
306
|
} catch (e) {
|
|
308
307
|
console.error(e)
|
|
309
308
|
}
|
|
310
309
|
}
|
|
310
|
+
import Taro from '@tarojs/taro'
|
|
311
311
|
APPID,
|
|
312
312
|
JshopxColorFunctionIdList,
|
|
313
313
|
PagesColorFunctionIdList,
|
|
314
314
|
PAGES_DOMAIN,
|
|
315
315
|
B2BColorFunctionIdList,
|
|
316
316
|
MobileVerifyColorList,
|
|
317
317
|
AppVerifyColorList,
|
|
318
318
|
JshopxVerifyColorList,
|
|
319
319
|
BMallVerifyColorList,
|
|
320
320
|
shopMemberColorFunctionIdList
|
|
321
321
|
cookiesStr: '',
|
|
322
322
|
requestHeaderContentType: {
|
|
323
323
|
jsonHeader: {
|
|
324
324
|
'content-type': 'application/json;charset=utf-8',
|
|
325
325
|
},
|
|
326
326
|
formDataHeader: {
|
|
327
327
|
'content-type': 'application/x-www-form-urlencoded',
|
|
328
328
|
},
|
|
329
329
|
},
|
|
330
330
|
requestBaseParam: {
|
|
331
331
|
data: null,
|
|
332
332
|
header: {
|
|
333
333
|
'content-type': 'application/json;charset=utf-8',
|
|
334
334
|
},
|
|
335
335
|
},
|
|
336
336
|
timeOut: 7000,
|
|
337
337
|
apiClientParams: {
|
|
338
338
|
appid: APPID.SHOP_COLOR_APPID,
|
|
339
339
|
clientVersion:
|
|
340
340
|
isH5AndJdShopView && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
|
|
341
341
|
client: isH5AndJdShopView ? (isIosDevice ? 'apple' : 'android') : 'wh5',
|
|
342
342
|
area: '1_72_2799_0',
|
|
343
343
|
uuid: UUID,
|
|
344
344
|
},
|
|
345
345
|
public addressFetchInfo: {
|
|
346
346
|
reqState: boolean
|
|
347
347
|
promiseInstance: null | Promise<any>
|
|
348
348
|
}
|
|
349
349
|
public getPromotionConfig: {
|
|
350
350
|
projectId: null | string | number
|
|
351
351
|
pageId: null | string | number
|
|
352
352
|
}
|
|
353
353
|
public resInfo: ServiceInterFace.HttpRequestInfo
|
|
354
354
|
public api: ServiceInterFace.HttpApi
|
|
355
355
|
public isPageDomain: boolean
|
|
356
356
|
public verifyColorList: string[]
|
|
357
357
|
constructor(opt) {
|
|
358
358
|
this._init()
|
|
359
359
|
this.addressFetchInfo = {
|
|
360
360
|
reqState: false,
|
|
361
361
|
promiseInstance: null,
|
|
362
362
|
}
|
|
363
363
|
this.getPromotionConfig = {
|
|
364
364
|
projectId: null,
|
|
365
365
|
pageId: null,
|
|
366
366
|
}
|
|
367
367
|
this._userAreaUpdateListen()
|
|
368
368
|
this.resInfo = this._getResConfig(opt)
|
|
369
369
|
this.api = api
|
|
370
370
|
this.isPageDomain = window.location.hostname === PAGES_DOMAIN
|
|
371
371
|
this.verifyColorList = [
|
|
372
372
|
...MobileVerifyColorList,
|
|
373
373
|
...AppVerifyColorList,
|
|
374
374
|
...JshopxVerifyColorList,
|
|
375
375
|
...BMallVerifyColorList,
|
|
376
376
|
]
|
|
377
377
|
}
|
|
378
378
|
_init(): void {
|
|
379
379
|
httpInterceptors.forEach((item) => {
|
|
380
380
|
Taro.addInterceptor((chain) => item(chain))
|
|
381
381
|
})
|
|
382
382
|
}
|
|
383
383
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
384
384
|
return Object.assign({}, DefaultConfig, opt)
|
|
385
385
|
}
|
|
386
386
|
|
|
387
387
|
_userAreaUpdateListen() {
|
|
388
388
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
|
|
389
389
|
this.updateApiClientParamsResInfo({
|
|
390
390
|
area,
|
|
391
391
|
})
|
|
392
392
|
})
|
|
393
393
|
}
|
|
394
394
|
updateApiClientParamsResInfo(opt = {}) {
|
|
395
395
|
this.resInfo.apiClientParams = {
|
|
396
396
|
...this.resInfo.apiClientParams,
|
|
397
397
|
...opt,
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
checkFunctionIdToReturnAppId(functionId) {
|
|
402
402
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
403
403
|
return APPID.JSHOPX_COLOR_APPID
|
|
404
404
|
} else if (
|
|
405
405
|
this.isPageDomain &&
|
|
406
406
|
PagesColorFunctionIdList.includes(functionId)
|
|
407
407
|
) {
|
|
408
408
|
return APPID.PAGES_COLOR_APPID
|
|
409
409
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
410
410
|
return APPID.SHOP_MEMBER_COLOR_APPID
|
|
411
411
|
}else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
412
412
|
return APPID.B2B_COLOR_APPID
|
|
413
413
|
} else {
|
|
414
414
|
return APPID.SHOP_COLOR_APPID
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
gatewayReq(
|
|
419
419
|
functionId: string,
|
|
420
420
|
bodyParams = {},
|
|
421
421
|
clientParams = {},
|
|
422
422
|
): Promise<any> {
|
|
423
423
|
if (
|
|
424
424
|
functionId === 'receiveShopCoupon' &&
|
|
425
425
|
((isH5 && window.isJingGouMiniViewState) || isWxMinAndWxapp)
|
|
426
426
|
) {
|
|
427
427
|
clientParams = Object.assign(
|
|
428
428
|
{},
|
|
429
429
|
{
|
|
430
430
|
loginType: '1',
|
|
431
431
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
432
432
|
},
|
|
433
433
|
clientParams,
|
|
434
434
|
)
|
|
435
435
|
}
|
|
436
436
|
const apiClientParams = Object.assign(
|
|
437
437
|
{},
|
|
438
438
|
this.resInfo.apiClientParams,
|
|
439
439
|
clientParams,
|
|
440
440
|
)
|
|
441
441
|
typeof apiClientParams.appid === 'undefined' && (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId))
|
|
442
442
|
const isColorVerify = this.verifyColorList.includes(functionId)
|
|
443
443
|
const getReqData = {
|
|
444
444
|
functionId: functionId,
|
|
445
445
|
body: JSON.stringify(bodyParams),
|
|
446
446
|
t: Date.now(),
|
|
447
447
|
...apiClientParams,
|
|
448
448
|
}
|
|
449
449
|
return http
|
|
450
450
|
.request({
|
|
451
451
|
url: this.api.apiFunc,
|
|
452
452
|
data: getReqData,
|
|
453
453
|
isColorVerify,
|
|
454
454
|
})
|
|
455
455
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
456
456
|
const { statusCode, data } = res
|
|
457
457
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
458
458
|
ok: true,
|
|
459
459
|
}
|
|
460
460
|
if (statusCode === 200 && data) {
|
|
461
461
|
const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
|
|
462
462
|
? Number(res.data.code)
|
|
463
463
|
: -1
|
|
464
464
|
const subCode = Object.prototype.hasOwnProperty.call(
|
|
465
465
|
res.data,
|
|
466
466
|
'subCode',
|
|
467
467
|
)
|
|
468
468
|
? Number(res.data.subCode)
|
|
469
469
|
: -1
|
|
470
470
|
if (
|
|
471
471
|
data.success === true ||
|
|
472
472
|
data.isSuccess ||
|
|
473
473
|
resCode === 0 ||
|
|
474
474
|
resCode === 200 ||
|
|
475
475
|
subCode === 0
|
|
476
476
|
) {
|
|
477
477
|
changeRes = {
|
|
478
478
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
479
479
|
? data.result
|
|
480
480
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
481
481
|
? data.data
|
|
482
482
|
: data,
|
|
483
483
|
code: data.code || 200,
|
|
484
484
|
ok: true,
|
|
485
485
|
source: data,
|
|
486
486
|
}
|
|
487
487
|
return changeRes
|
|
488
488
|
} else {
|
|
489
489
|
changeRes = {
|
|
490
490
|
...data,
|
|
491
491
|
ok: false,
|
|
492
492
|
statusCode: res.statusCode,
|
|
493
493
|
}
|
|
494
494
|
return changeRes
|
|
495
495
|
}
|
|
496
496
|
} else {
|
|
497
497
|
changeRes = {
|
|
498
498
|
...data,
|
|
499
499
|
ok: false,
|
|
500
500
|
statusCode: res.statusCode,
|
|
501
501
|
}
|
|
502
502
|
return changeRes
|
|
503
503
|
}
|
|
504
504
|
})
|
|
505
505
|
.catch((res) => {
|
|
506
506
|
return {
|
|
507
507
|
...res,
|
|
508
508
|
ok: false,
|
|
509
509
|
} as ServiceInterFace.RequestResponseFormatRes
|
|
510
510
|
})
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
async receiveCoupon(param = {}, clientParams) {
|
|
514
514
|
return await this.gatewayReq(
|
|
515
515
|
'receiveShopCoupon',
|
|
516
516
|
{
|
|
517
517
|
operation: '3',
|
|
518
518
|
...param,
|
|
519
519
|
},
|
|
520
520
|
clientParams,
|
|
521
521
|
)
|
|
522
522
|
}
|
|
523
523
|
|
|
524
524
|
getCustomerCenterDispatch(params = {}) {
|
|
525
525
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
526
526
|
clientVersion: '9.2.0',
|
|
527
527
|
client: 'H5',
|
|
528
528
|
uuid: 88888,
|
|
529
529
|
appid: 'shopmember_m_jd_com',
|
|
530
530
|
})
|
|
531
531
|
}
|
|
532
532
|
bMallGetUserInfo = () => {
|
|
533
533
|
return bMallUserInfo
|
|
534
534
|
}
|
|
535
535
|
async bMallAddCart(params = {}) {
|
|
536
536
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
537
537
|
client: 'H5',
|
|
538
538
|
clientVersion: '5.5.0'
|
|
539
539
|
})
|
|
540
540
|
}
|
|
541
541
|
async bMallChangeCart(params = {}) {
|
|
542
542
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
543
543
|
client: 'H5',
|
|
544
544
|
clientVersion: '5.5.0'
|
|
545
545
|
})
|
|
546
546
|
}
|
|
547
547
|
async bMallRemoveCart(params = {}) {
|
|
548
548
|
return await this.gatewayReq(
|
|
549
549
|
'bmall_cartRemove',
|
|
550
550
|
params,
|
|
551
551
|
{
|
|
552
552
|
client: 'H5',
|
|
553
553
|
clientVersion: '5.5.0'
|
|
554
554
|
},
|
|
555
555
|
)
|
|
556
556
|
}
|
|
557
557
|
async bMallGetOmittedProduct(params = {}) {
|
|
558
558
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
559
559
|
client: 'H5',
|
|
560
560
|
clientVersion: '5.5.0'
|
|
561
561
|
})
|
|
562
562
|
}
|
|
563
563
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
564
564
|
const params = await getParams({ ...data, skuId, bMallTag, num })
|
|
565
565
|
return await this.bMallAddCart(params)
|
|
566
566
|
}
|
|
567
567
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
568
568
|
const params = await getParams({ bMallTag })
|
|
569
569
|
delete params.operations
|
|
570
570
|
return await this.bMallGetOmittedProduct(params)
|
|
571
571
|
}
|
|
572
572
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
573
573
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
574
574
|
return await this.bMallRemoveCart(params)
|
|
575
575
|
}
|
|
576
576
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
577
577
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
578
578
|
return await this.bMallChangeCart(params)
|
|
579
579
|
}
|
|
580
580
|
|
|
581
581
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
582
582
|
if (!needRequest && window.bMallCartData) {
|
|
583
583
|
return window.bMallCartData
|
|
584
584
|
}
|
|
585
585
|
const cartData = await this.bMallGetSkuNumService(bMallTag)
|
|
586
586
|
let items
|
|
587
587
|
if (cartData.ok && cartData.result) {
|
|
588
588
|
items = cartData?.result?.items || {}
|
|
589
589
|
}
|
|
590
590
|
window.bMallCartData = items
|
|
591
591
|
return items
|
|
592
592
|
}
|
|
593
593
|
|
|
594
594
|
async bMallCartHandle(goodItem, num) {
|
|
595
595
|
try {
|
|
596
596
|
const {
|
|
597
597
|
skuUuid,
|
|
598
598
|
limitUpper,
|
|
599
599
|
limitLower,
|
|
600
600
|
} = goodItem
|
|
601
601
|
let cartNum = Number(num)
|
|
602
602
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
603
603
|
cartNum = limitLower
|
|
604
604
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
605
605
|
cartNum = limitUpper
|
|
606
606
|
}
|
|
607
607
|
if (skuUuid && cartNum > 0) {
|
|
608
608
|
return this.bMallChangeCartService({
|
|
609
609
|
...goodItem,
|
|
610
610
|
skuUuid,
|
|
611
611
|
num: cartNum,
|
|
612
612
|
})
|
|
613
613
|
} else if (!skuUuid && cartNum > 0) {
|
|
614
614
|
return this.bMallAddCartService({ ...goodItem, num: cartNum })
|
|
615
615
|
} else if (skuUuid && !cartNum) {
|
|
616
616
|
return this.bMallRemoveCartService({
|
|
617
617
|
...goodItem,
|
|
618
618
|
skuUuid,
|
|
619
619
|
num: cartNum,
|
|
620
620
|
})
|
|
621
621
|
} else {
|
|
622
622
|
console.error('参数不全')
|
|
623
623
|
return false
|
|
624
624
|
}
|
|
625
625
|
} catch (e) {
|
|
626
626
|
console.error(e)
|
|
627
627
|
}
|
|
628
628
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function checkExpression(expression: any, context: any = window) {
|
|
2
|
let isExist = false
|
|
1
3
|
const isFunction = typeof expression === 'function'
|
|
2
4
|
if (isFunction) {
|
|
3
5
|
if (expression()) {
|
|
4
6
|
isExist = true
|
|
5
7
|
}
|
|
6
8
|
} else {
|
|
7
9
|
if (context[expression] !== undefined) {
|
|
8
10
|
isExist = true
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
return isExist
|
|
12
14
|
expression: any,
|
|
13
15
|
timeout: number = 1000,
|
|
14
16
|
context: any = window,
|
|
15
17
|
return new Promise((resolve, reject) => {
|
|
16
18
|
const interval = 16 * 5
|
|
17
19
|
const endTime = Date.now() + timeout
|
|
18
20
|
function checkReady() {
|
|
19
21
|
if (checkExpression(expression, context)) {
|
|
20
22
|
resolve()
|
|
21
23
|
} else if (Date.now() < endTime) {
|
|
22
24
|
setTimeout(checkReady, interval)
|
|
23
25
|
} else {
|
|
24
26
|
reject('ready check timeout')
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
checkReady()
|
|
28
30
|
})
|