@conecli/cone-render 0.8.22-beta.0 → 0.8.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- const userInfo =
2
  (window.WebViewCommon && window.WebViewCommon.getUserInfo()) || {}
3
1
  buId: userInfo.buId,
4
2
  process.env.NODE_ENV === 'development'
5
3
  ? {
6
4
  apolloId: '48ee955b0fb04d19b9f9fe8cb73d387f',
7
5
  apolloSecret: '0d9c76ee66b0487da4e17d3cf1d7af7a',
8
6
  }
9
7
  : {
10
8
  apolloId: '80c46fd06e4442998609d9f6a4ab96f0',
11
9
  apolloSecret: 'f36bef08bcba4683b409732095793fb2',
12
10
  }
13
11
  if (typeof window.crypto === 'object') {
14
12
  if (typeof (window.crypto as any).randomUUID === 'function') {
15
13
  return (window.crypto as any).randomUUID()
16
14
  }
17
15
  if (
18
16
  typeof (window.crypto as any).getRandomValues === 'function' &&
19
17
  typeof Uint8Array === 'function'
20
18
  ) {
21
19
  const callback = (c) => {
22
20
  const num = Number(c)
23
21
  return (
24
22
  num ^
25
23
  ((window.crypto as any).getRandomValues(new Uint8Array(1))[0] &
26
24
  (15 >> (num / 4)))
27
25
  ).toString(16)
28
26
  }
29
27
  return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, callback)
30
28
  }
31
29
  }
32
30
  let timestamp = new Date().getTime()
33
31
  let perforNow =
34
32
  (typeof window.performance !== 'undefined' &&
35
33
  window.performance.now &&
36
34
  window.performance.now() * 1000) ||
37
35
  0
38
36
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
39
37
  let random = Math.random() * 16
40
38
  if (timestamp > 0) {
41
39
  random = (timestamp + random) % 16 | 0
42
40
  timestamp = Math.floor(timestamp / 16)
43
41
  } else {
44
42
  random = (perforNow + random) % 16 | 0
45
43
  perforNow = Math.floor(perforNow / 16)
46
44
  }
47
45
  return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
48
46
  })
49
47
  let params = {
50
48
  uniformBizInfo: {
51
49
  tenantId: 1024,
52
50
  ua: 1,
53
51
  buId: commonParam.buId || 377,
54
52
  bMallTag: bMallTag,
55
53
  },
56
54
  commonParam: {
57
55
  pid: 100,
58
56
  verticalCode: 'cn_retail_bmall',
59
57
  ua: 1,
60
58
  language: 'zh',
61
59
  },
62
60
  operations: [{ TheSkus: [{ Id: skuId, num: num || 1 }] }],
63
61
  apolloId: APOLLO.apolloId,
64
62
  apolloSecret: APOLLO.apolloSecret,
65
63
  client: 'H5',
66
64
  verticalTag: 'cn_retail_bmall',
67
65
  carttype: bMallTag == 1 ? 21 : 22,
68
66
  bMallTag: bMallTag,
69
67
  traceId: getUuid(),
70
68
  noResponse: true,
71
69
  }
72
70
  if (skuUuid) {
73
71
  params.operations[0].TheSkus[0].skuUuid = skuUuid
74
72
  }
75
73
  if (window?.siteTransResult?.gridInfoList) {
76
74
  params = {
77
75
  ...params,
78
76
  cartLocationList: [
79
77
  {
80
78
  gridInfos:
81
79
  window?.siteTransResult?.gridInfoList &&
82
80
  JSON.parse(window?.siteTransResult?.gridInfoList),
83
81
  areaIdSet:
84
82
  window?.siteTransResult?.area &&
85
83
  window?.siteTransResult?.area?.split('-'),
86
84
  },
87
85
  ],
88
86
  }
89
87
  }
90
88
  return params
@@ -1 +0,0 @@
1
- import Taro from '@tarojs/taro'
2
  SHOP_COLOR_APPID,
3
1
  JshopxColorFunctionIdList,
4
2
  PagesColorFunctionIdList,
5
3
  JSHOPX_COLOR_APPID,
6
4
  PAGES_COLOR_APPID,
7
5
  PAGES_DOMAIN,
8
6
  B2BColorFunctionIdList,
9
7
  B2B_COLOR_APPID,
10
8
  cookiesStr: '',
11
9
  requestHeaderContentType: {
12
10
  jsonHeader: {
13
11
  'content-type': 'application/json;charset=utf-8',
14
12
  },
15
13
  formDataHeader: {
16
14
  'content-type': 'application/x-www-form-urlencoded',
17
15
  },
18
16
  },
19
17
  requestBaseParam: {
20
18
  data: null,
21
19
  header: {
22
20
  'content-type': 'application/json;charset=utf-8',
23
21
  },
24
22
  },
25
23
  timeOut: 7000,
26
24
  apiClientParams: {
27
25
  appid: SHOP_COLOR_APPID,
28
26
  clientVersion:
29
27
  isH5AndJdShopView && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
30
28
  client: isH5AndJdShopView ? (isIosDevice ? 'apple' : 'android') : 'wh5',
31
29
  area: '1_72_2799_0',
32
30
  uuid: UUID,
33
31
  },
34
32
  public addressFetchInfo: {
35
33
  reqState: boolean
36
34
  promiseInstance: null | Promise<any>
37
35
  }
38
36
  public getPromotionConfig: {
39
37
  projectId: null | string | number
40
38
  pageId: null | string | number
41
39
  }
42
40
  public resInfo: ServiceInterFace.HttpRequestInfo
43
41
  public api: ServiceInterFace.HttpApi
44
42
  public isPageDomain: boolean
45
43
  constructor(opt) {
46
44
  this._init()
47
45
  this.addressFetchInfo = {
48
46
  reqState: false,
49
47
  promiseInstance: null,
50
48
  }
51
49
  this.getPromotionConfig = {
52
50
  projectId: null,
53
51
  pageId: null,
54
52
  }
55
53
  this._userAreaUpdateListen()
56
54
  this.resInfo = this._getResConfig(opt)
57
55
  this.api = api
58
56
  this.isPageDomain = window.location.hostname === PAGES_DOMAIN
59
57
  }
60
58
  _init(): void {
61
59
  httpInterceptors.forEach((item) => {
62
60
  Taro.addInterceptor((chain) => item(chain))
63
61
  })
64
62
  }
65
63
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
66
64
  return Object.assign({}, DefaultConfig, opt)
67
65
  }
68
66
 
69
67
  _userAreaUpdateListen() {
70
68
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
71
69
  this.updateApiClientParamsResInfo({
72
70
  area,
73
71
  })
74
72
  })
75
73
  }
76
74
  updateApiClientParamsResInfo(opt = {}) {
77
75
  this.resInfo.apiClientParams = {
78
76
  ...this.resInfo.apiClientParams,
79
77
  ...opt,
80
78
  }
81
79
  }
82
80
 
83
81
  _paramsSign(data) {
84
82
  return Promise.resolve(data)
85
83
  }
86
84
 
87
85
  checkFunctionIdToReturnAppId(functionId) {
88
86
  if (JshopxColorFunctionIdList.includes(functionId)) {
89
87
  return JSHOPX_COLOR_APPID
90
88
  } else if (
91
89
  this.isPageDomain &&
92
90
  PagesColorFunctionIdList.includes(functionId)
93
91
  ) {
94
92
  return PAGES_COLOR_APPID
95
93
  } else if (B2BColorFunctionIdList.includes(functionId)) {
96
94
  return B2B_COLOR_APPID
97
95
  } else {
98
96
  return SHOP_COLOR_APPID
99
97
  }
100
98
  }
101
99
 
102
100
  gatewayReq(
103
101
  functionId: string,
104
102
  bodyParams = {},
105
103
  clientParams = {},
106
104
  ): Promise<any> {
107
105
  if (
108
106
  functionId === 'receiveShopCoupon' &&
109
107
  ((isH5 && window.isJingGouMiniViewState) || isWxMinAndWxapp)
110
108
  ) {
111
109
  clientParams = Object.assign(
112
110
  {},
113
111
  {
114
112
  loginType: '1',
115
113
  loginWQBiz: WXAPP_BIZ_KEY,
116
114
  },
117
115
  clientParams,
118
116
  )
119
117
  }
120
118
  const apiClientParams = Object.assign(
121
119
  {},
122
120
  this.resInfo.apiClientParams,
123
121
  clientParams,
124
122
  )
125
123
  apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId)
126
124
  const getReqData = {
127
125
  functionId: functionId,
128
126
  body: JSON.stringify(bodyParams),
129
127
  t: Date.now(),
130
128
  ...apiClientParams,
131
129
  }
132
130
  return http
133
131
  .request({
134
132
  url: this.api.apiFunc,
135
133
  data: getReqData,
136
134
  method: 'GET',
137
135
  })
138
136
  .then((res: ServiceInterFace.RequestPromiseRes) => {
139
137
  const { statusCode, data } = res
140
138
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
141
139
  ok: true,
142
140
  }
143
141
  if (statusCode === 200 && data) {
144
142
  const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
145
143
  ? Number(res.data.code)
146
144
  : -1
147
145
  const subCode = Object.prototype.hasOwnProperty.call(
148
146
  res.data,
149
147
  'subCode',
150
148
  )
151
149
  ? Number(res.data.subCode)
152
150
  : -1
153
151
  if (
154
152
  data.success === true ||
155
153
  data.isSuccess ||
156
154
  resCode === 0 ||
157
155
  resCode === 200 ||
158
156
  subCode === 0
159
157
  ) {
160
158
  changeRes = {
161
159
  result: Object.prototype.hasOwnProperty.call(data, 'result')
162
160
  ? data.result
163
161
  : Object.prototype.hasOwnProperty.call(data, 'data')
164
162
  ? data.data
165
163
  : data,
166
164
  code: data.code || 200,
167
165
  ok: true,
168
166
  source: data,
169
167
  }
170
168
  return changeRes
171
169
  } else {
172
170
  changeRes = {
173
171
  ...data,
174
172
  ok: false,
175
173
  statusCode: res.statusCode,
176
174
  }
177
175
  return changeRes
178
176
  }
179
177
  } else {
180
178
  changeRes = {
181
179
  ...data,
182
180
  ok: false,
183
181
  statusCode: res.statusCode,
184
182
  }
185
183
  return changeRes
186
184
  }
187
185
  })
188
186
  .catch((res) => {
189
187
  return {
190
188
  ...res,
191
189
  ok: false,
192
190
  } as ServiceInterFace.RequestResponseFormatRes
193
191
  })
194
192
  }
195
193
 
196
194
  async receiveCoupon(param = {}, clientParams) {
197
195
  return await this.gatewayReq(
198
196
  'receiveShopCoupon',
199
197
  {
200
198
  operation: '3',
201
199
  ...param,
202
200
  },
203
201
  clientParams,
204
202
  )
205
203
  }
206
204
  async bMallAddCart(params = {}) {
207
205
  return await this.gatewayReq('bmall_cartAdd', params, {
208
206
  client: 'H5',
209
207
  })
210
208
  }
211
209
  async bMallChangeCart(params = {}) {
212
210
  return await this.gatewayReq('bmall_cartChange', params, {
213
211
  client: 'H5',
214
212
  })
215
213
  }
216
214
  async bMallRemoveCart(params = {}) {
217
215
  return await this.gatewayReq(
218
216
  'bmall_cartRemove',
219
217
  params,
220
218
  {
221
219
  client: 'H5',
222
220
  },
223
221
  )
224
222
  }
225
223
  async bMallGetOmittedProduct(params = {}) {
226
224
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
227
225
  client: 'H5',
228
226
  })
229
227
  }
230
228
  async bMallAddCartService({ skuId, bMallTag, num }) {
231
229
  const params = getParams({ skuId, bMallTag, num })
232
230
  return await this.bMallAddCart(params)
233
231
  }
234
232
  async bMallGetSkuNumService(bMallTag = 1) {
235
233
  const params = getParams({ bMallTag })
236
234
  delete params.operations
237
235
  return await this.bMallGetOmittedProduct(params)
238
236
  }
239
237
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid }) {
240
238
  let params = getParams({ skuId, bMallTag, num, skuUuid })
241
239
  return await this.bMallRemoveCart(params)
242
240
  }
243
241
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid }) {
244
242
  let params = getParams({ skuId, bMallTag, num, skuUuid })
245
243
  return await this.bMallChangeCart(params)
246
244
  }
247
245
 
248
246
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
249
247
  if (!needRequest && window.bMallCartData) {
250
248
  return window.bMallCartData
251
249
  }
252
250
  const cartData = await this.bMallGetSkuNumService(bMallTag)
253
251
  let items
254
252
  if (cartData.ok && cartData.result) {
255
253
  items = cartData?.result?.items || {}
256
254
  }
257
255
  window.bMallCartData = items
258
256
  return items
259
257
  }
260
258
 
261
259
  async bMallCartHandle(goodItem, num) {
262
260
  try {
263
261
  const {
264
262
  skuUuid,
265
263
  limitUpper,
266
264
  limitLower,
267
265
  } = goodItem
268
266
  let cartNum = Number(num)
269
267
  if (limitLower && cartNum && cartNum < limitLower) {
270
268
  cartNum = limitLower
271
269
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
272
270
  cartNum = limitUpper
273
271
  }
274
272
  if (skuUuid && cartNum > 0) {
275
273
  return this.bMallChangeCartService({
276
274
  ...goodItem,
277
275
  skuUuid,
278
276
  num: cartNum,
279
277
  })
280
278
  } else if (!skuUuid && cartNum > 0) {
281
279
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
282
280
  } else if (skuUuid && !cartNum) {
283
281
  return this.bMallRemoveCartService({
284
282
  ...goodItem,
285
283
  skuUuid,
286
284
  num: cartNum,
287
285
  })
288
286
  } else {
289
287
  console.error('参数不全')
290
288
  return false
291
289
  }
292
290
  } catch (e) {
293
291
  console.error(e)
294
292
  }
295
293
  }