@conecli/cone-render 0.8.21 → 0.8.22-beta.1

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.
@@ -0,0 +1 @@
1
+ import Taro from '@tarojs/taro'
2
  SHOP_COLOR_APPID,
1
3
  JshopxColorFunctionIdList,
2
4
  PagesColorFunctionIdList,
3
5
  JSHOPX_COLOR_APPID,
4
6
  PAGES_COLOR_APPID,
5
7
  PAGES_DOMAIN,
6
8
  B2BColorFunctionIdList,
7
9
  B2B_COLOR_APPID,
8
10
  cookiesStr: '',
9
11
  requestHeaderContentType: {
10
12
  jsonHeader: {
11
13
  'content-type': 'application/json;charset=utf-8',
12
14
  },
13
15
  formDataHeader: {
14
16
  'content-type': 'application/x-www-form-urlencoded',
15
17
  },
16
18
  },
17
19
  requestBaseParam: {
18
20
  data: null,
19
21
  header: {
20
22
  'content-type': 'application/json;charset=utf-8',
21
23
  },
22
24
  },
23
25
  timeOut: 7000,
24
26
  apiClientParams: {
25
27
  appid: SHOP_COLOR_APPID,
26
28
  clientVersion:
27
29
  isH5AndJdShopView && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
28
30
  client: isH5AndJdShopView ? (isIosDevice ? 'apple' : 'android') : 'wh5',
29
31
  area: '1_72_2799_0',
30
32
  uuid: UUID,
31
33
  },
32
34
  public addressFetchInfo: {
33
35
  reqState: boolean
34
36
  promiseInstance: null | Promise<any>
35
37
  }
36
38
  public getPromotionConfig: {
37
39
  projectId: null | string | number
38
40
  pageId: null | string | number
39
41
  }
40
42
  public resInfo: ServiceInterFace.HttpRequestInfo
41
43
  public api: ServiceInterFace.HttpApi
42
44
  public isPageDomain: boolean
43
45
  constructor(opt) {
44
46
  this._init()
45
47
  this.addressFetchInfo = {
46
48
  reqState: false,
47
49
  promiseInstance: null,
48
50
  }
49
51
  this.getPromotionConfig = {
50
52
  projectId: null,
51
53
  pageId: null,
52
54
  }
53
55
  this._userAreaUpdateListen()
54
56
  this.resInfo = this._getResConfig(opt)
55
57
  this.api = api
56
58
  this.isPageDomain = window.location.hostname === PAGES_DOMAIN
57
59
  }
58
60
  _init(): void {
59
61
  httpInterceptors.forEach((item) => {
60
62
  Taro.addInterceptor((chain) => item(chain))
61
63
  })
62
64
  }
63
65
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
64
66
  return Object.assign({}, DefaultConfig, opt)
65
67
  }
66
68
 
67
69
  _userAreaUpdateListen() {
68
70
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
69
71
  this.updateApiClientParamsResInfo({
70
72
  area,
71
73
  })
72
74
  })
73
75
  }
74
76
  updateApiClientParamsResInfo(opt = {}) {
75
77
  this.resInfo.apiClientParams = {
76
78
  ...this.resInfo.apiClientParams,
77
79
  ...opt,
78
80
  }
79
81
  }
80
82
 
81
83
  _paramsSign(data) {
82
84
  return Promise.resolve(data)
83
85
  }
84
86
 
85
87
  checkFunctionIdToReturnAppId(functionId) {
86
88
  if (JshopxColorFunctionIdList.includes(functionId)) {
87
89
  return JSHOPX_COLOR_APPID
88
90
  } else if (
89
91
  this.isPageDomain &&
90
92
  PagesColorFunctionIdList.includes(functionId)
91
93
  ) {
92
94
  return PAGES_COLOR_APPID
93
95
  } else if (B2BColorFunctionIdList.includes(functionId)) {
94
96
  return B2B_COLOR_APPID
95
97
  } else {
96
98
  return SHOP_COLOR_APPID
97
99
  }
98
100
  }
99
101
 
100
102
  gatewayReq(
101
103
  functionId: string,
102
104
  bodyParams = {},
103
105
  clientParams = {},
104
106
  ): Promise<any> {
105
107
  if (
106
108
  functionId === 'receiveShopCoupon' &&
107
109
  ((isH5 && window.isJingGouMiniViewState) || isWxMinAndWxapp)
108
110
  ) {
109
111
  clientParams = Object.assign(
110
112
  {},
111
113
  {
112
114
  loginType: '1',
113
115
  loginWQBiz: WXAPP_BIZ_KEY,
114
116
  },
115
117
  clientParams,
116
118
  )
117
119
  }
118
120
  const apiClientParams = Object.assign(
119
121
  {},
120
122
  this.resInfo.apiClientParams,
121
123
  clientParams,
122
124
  )
123
125
  apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId)
124
126
  const getReqData = {
125
127
  functionId: functionId,
126
128
  body: JSON.stringify(bodyParams),
127
129
  t: Date.now(),
128
130
  ...apiClientParams,
129
131
  }
130
132
  return http
131
133
  .request({
132
134
  url: this.api.apiFunc,
133
135
  data: getReqData,
134
136
  method: 'GET',
135
137
  })
136
138
  .then((res: ServiceInterFace.RequestPromiseRes) => {
137
139
  const { statusCode, data } = res
138
140
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
139
141
  ok: true,
140
142
  }
141
143
  if (statusCode === 200 && data) {
142
144
  const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
143
145
  ? Number(res.data.code)
144
146
  : -1
145
147
  const subCode = Object.prototype.hasOwnProperty.call(
146
148
  res.data,
147
149
  'subCode',
148
150
  )
149
151
  ? Number(res.data.subCode)
150
152
  : -1
151
153
  if (
152
154
  data.success === true ||
153
155
  data.isSuccess ||
154
156
  resCode === 0 ||
155
157
  resCode === 200 ||
156
158
  subCode === 0
157
159
  ) {
158
160
  changeRes = {
159
161
  result: Object.prototype.hasOwnProperty.call(data, 'result')
160
162
  ? data.result
161
163
  : Object.prototype.hasOwnProperty.call(data, 'data')
162
164
  ? data.data
163
165
  : data,
164
166
  code: data.code || 200,
165
167
  ok: true,
166
168
  source: data,
167
169
  }
168
170
  return changeRes
169
171
  } else {
170
172
  changeRes = {
171
173
  ...data,
172
174
  ok: false,
173
175
  statusCode: res.statusCode,
174
176
  }
175
177
  return changeRes
176
178
  }
177
179
  } else {
178
180
  changeRes = {
179
181
  ...data,
180
182
  ok: false,
181
183
  statusCode: res.statusCode,
182
184
  }
183
185
  return changeRes
184
186
  }
185
187
  })
186
188
  .catch((res) => {
187
189
  return {
188
190
  ...res,
189
191
  ok: false,
190
192
  } as ServiceInterFace.RequestResponseFormatRes
191
193
  })
192
194
  }
193
195
 
194
196
  async receiveCoupon(param = {}, clientParams) {
195
197
  return await this.gatewayReq(
196
198
  'receiveShopCoupon',
197
199
  {
198
200
  operation: '3',
199
201
  ...param,
200
202
  },
201
203
  clientParams,
202
204
  )
203
205
  }
204
206
  async bMallAddCart(params = {}) {
205
207
  return await this.gatewayReq('bmall_cartAdd', params, {
206
208
  client: 'H5',
207
209
  })
208
210
  }
209
211
  async bMallChangeCart(params = {}) {
210
212
  return await this.gatewayReq('bmall_cartChange', params, {
211
213
  client: 'H5',
212
214
  })
213
215
  }
214
216
  async bMallRemoveCart(params = {}) {
215
217
  return await this.gatewayReq(
216
218
  'bmall_cartRemove',
217
219
  params,
218
220
  {
219
221
  client: 'H5',
220
222
  },
221
223
  )
222
224
  }
223
225
  async bMallGetOmittedProduct(params = {}) {
224
226
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
225
227
  client: 'H5',
226
228
  })
227
229
  }
228
230
  async bMallAddCartService({ skuId, bMallTag, num }) {
229
231
  const params = getParams({ skuId, bMallTag, num })
230
232
  return await this.bMallAddCart(params)
231
233
  }
232
234
  async bMallGetSkuNumService(bMallTag = 1) {
233
235
  const params = getParams({ bMallTag })
234
236
  delete params.operations
235
237
  return await this.bMallGetOmittedProduct(params)
236
238
  }
237
239
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid }) {
238
240
  let params = getParams({ skuId, bMallTag, num, skuUuid })
239
241
  return await this.bMallRemoveCart(params)
240
242
  }
241
243
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid }) {
242
244
  let params = getParams({ skuId, bMallTag, num, skuUuid })
243
245
  return await this.bMallChangeCart(params)
244
246
  }
245
247
 
246
248
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
247
249
  if (!needRequest && window.bMallCartData) {
248
250
  return window.bMallCartData
249
251
  }
250
252
  const cartData = await this.bMallGetSkuNumService(bMallTag)
251
253
  let items
252
254
  if (cartData.ok && cartData.result) {
253
255
  items = cartData?.result?.items || {}
254
256
  }
255
257
  window.bMallCartData = items
256
258
  return items
257
259
  }
258
260
 
259
261
  async bMallCartHandle(goodItem, num) {
260
262
  try {
261
263
  const {
262
264
  skuUuid,
263
265
  limitUpper,
264
266
  limitLower,
265
267
  } = goodItem
266
268
  let cartNum = Number(num)
267
269
  if (limitLower && cartNum && cartNum < limitLower) {
268
270
  cartNum = limitLower
269
271
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
270
272
  cartNum = limitUpper
271
273
  }
272
274
  if (skuUuid && cartNum > 0) {
273
275
  return this.bMallChangeCartService({
274
276
  ...goodItem,
275
277
  skuUuid,
276
278
  num: cartNum,
277
279
  })
278
280
  } else if (!skuUuid && cartNum > 0) {
279
281
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
280
282
  } else if (skuUuid && !cartNum) {
281
283
  return this.bMallRemoveCartService({
282
284
  ...goodItem,
283
285
  skuUuid,
284
286
  num: cartNum,
285
287
  })
286
288
  } else {
287
289
  console.error('参数不全')
288
290
  return false
289
291
  }
290
292
  } catch (e) {
291
293
  console.error(e)
292
294
  }
293
295
  }
@@ -1 +1 @@
1
- var splitOnFirst = function splitOnFirst(string, separator) {
2
1
  return Object.prototype.toString.call(obj);
3
2
  return typeof obj === 'function';
4
3
  return '[object Object]' === getType(obj);
5
4
  return '[object Array]' == getType(obj);
6
5
  return '[object Undefined]' === getType(obj);
7
6
  return '[object Null]' == getType(obj);
8
7
  return typeof obj === 'string';
9
8
  return typeof obj === 'boolean';
10
9
  return '[object Number]' === getType(num);
11
10
  ua = ua || navigator.userAgent;
12
11
  if (name === 'wx') return (/micromessenger/i.test(ua)
13
12
  );
14
13
  if (name === 'qq') return (/qq\//i.test(ua)
15
14
  );
16
15
  if (name === 'weibo') return (/weibo/i.test(ua)
17
16
  );
18
17
  if (name === 'jd') return (/^jdapp/i.test(ua)
19
18
  );
20
19
  if (name === 'jdlittle') return (/^jdltapp/i.test(ua)
21
20
  );
22
21
  if (name === 'mp') return navigator.userAgent.match(/micromessenger/i) && navigator.userAgent.match(/miniprogram/i) || window.__wxjs_environment === 'miniprogram';
23
22
  return false;
24
23
  ua = ua || navigator.userAgent;
25
24
  return (/android/i.test(ua) && !isIOS()
26
25
  );
27
26
  ua = ua || navigator.userAgent;
28
27
  return (/ip(hone|od)|ipad/i.test(ua)
29
28
  );
30
29
  ua = ua || navigator.userAgent;
31
30
  return (/ipad/i.test(ua) || /android/i.test(ua) && !/mobi|mini|fennec/i.test(ua)
32
31
  );
33
32
  ua = ua || navigator.userAgent;
34
33
  return !!ua.match(/ip(hone|od)|android.+mobile|windows (ce|phone)|blackberry|bb10|symbian|webos|firefox.+fennec|opera m(ob|in)i|polaris|iemobile|lgtelecom|nokia|sonyericsson|dolfin|uzard|natebrowser|ktf;|skt;/i);
35
34
  ua = ua || navigator.userAgent;
36
35
  return !!ua.match(/iphone/i);
37
36
  ua = ua || navigator.userAgent;
38
37
  return !!ua.match(/ipad/i);
39
38
  ua = ua || navigator.userAgent;
40
39
  if (name === 'xview') return typeof window.XView !== 'undefined';
41
40
  if (name === 'wk') return !!ua.match(/supportjdshwk/i) || window._is_jdsh_wkwebview == 1;
42
41
  return false;
43
42
  ua = ua || navigator.userAgent;
44
43
  var re = /nettype\/([\S]*)/i;
45
44
  if (isApp('jd', ua)) re = /network\/([^;]*)/i;
46
45
  return re.test(ua) ? RegExp.$1.toLowerCase() : 'unknown';
47
46
  ua = ua || navigator.userAgent;
48
47
  if (!isApp('jd', ua)) return null;
49
48
  return ua.split(';')[4];
50
49
  ua = ua || navigator.userAgent;
51
50
  if (appName === 'jd') return ua.split(';')[2] || null;
52
51
  if (appName === 'wx') return (/micromessenger\/([\S]*)/i.test(ua) ? RegExp.$1 : null
53
52
  );
54
53
  if (appName === 'qq') return (/qq\/([\S]*)/i.test(ua) ? RegExp.$1 : null
55
54
  );
56
55
  return null;
57
56
  ua = ua || navigator.userAgent;
58
57
  var match = ua.match(/android\s([0-9\.]*)/i);
59
58
  return match ? match[1] : 'unknown';
60
59
  ua = ua || navigator.userAgent;
61
60
  var match = ua.match(/OS ((\d+_?){2,3})\s/i);
62
61
  return match ? match[1].replace(/_/g, '.') : 'unknown';
62
+ var splitOnFirst = function splitOnFirst(string, separator) {
63
63
  return Object.prototype.toString.call(obj);
64
64
  return typeof obj === 'function';
65
65
  return '[object Object]' === getType(obj);
66
66
  return '[object Array]' == getType(obj);
67
67
  return '[object Undefined]' === getType(obj);
68
68
  return '[object Null]' == getType(obj);
69
69
  return typeof obj === 'string';
70
70
  return typeof obj === 'boolean';
71
71
  return '[object Number]' === getType(num);
72
72
  ua = ua || navigator.userAgent;
73
73
  if (name === 'wx') return (/micromessenger/i.test(ua)
74
74
  );
75
75
  if (name === 'qq') return (/qq\//i.test(ua)
76
76
  );
77
77
  if (name === 'weibo') return (/weibo/i.test(ua)
78
78
  );
79
79
  if (name === 'jd') return (/^jdapp/i.test(ua)
80
80
  );
81
81
  if (name === 'jdlittle') return (/^jdltapp/i.test(ua)
82
82
  );
83
83
  if (name === 'mp') return navigator.userAgent.match(/micromessenger/i) && navigator.userAgent.match(/miniprogram/i) || window.__wxjs_environment === 'miniprogram';
84
84
  if (name === 'jdb') return (/JDBmall/i.test(ua)
85
85
  );
86
86
  return false;
87
87
  ua = ua || navigator.userAgent;
88
88
  return (/android/i.test(ua) && !isIOS()
89
89
  );
90
90
  ua = ua || navigator.userAgent;
91
91
  return (/ip(hone|od)|ipad/i.test(ua)
92
92
  );
93
93
  ua = ua || navigator.userAgent;
94
94
  return (/ipad/i.test(ua) || /android/i.test(ua) && !/mobi|mini|fennec/i.test(ua)
95
95
  );
96
96
  ua = ua || navigator.userAgent;
97
97
  return !!ua.match(/ip(hone|od)|android.+mobile|windows (ce|phone)|blackberry|bb10|symbian|webos|firefox.+fennec|opera m(ob|in)i|polaris|iemobile|lgtelecom|nokia|sonyericsson|dolfin|uzard|natebrowser|ktf;|skt;/i);
98
98
  ua = ua || navigator.userAgent;
99
99
  return !!ua.match(/iphone/i);
100
100
  ua = ua || navigator.userAgent;
101
101
  return !!ua.match(/ipad/i);
102
102
  ua = ua || navigator.userAgent;
103
103
  if (name === 'xview') return typeof window.XView !== 'undefined';
104
104
  if (name === 'wk') return !!ua.match(/supportjdshwk/i) || window._is_jdsh_wkwebview == 1;
105
105
  return false;
106
106
  ua = ua || navigator.userAgent;
107
107
  var re = /nettype\/([\S]*)/i;
108
108
  if (isApp('jd', ua)) re = /network\/([^;]*)/i;
109
109
  return re.test(ua) ? RegExp.$1.toLowerCase() : 'unknown';
110
110
  ua = ua || navigator.userAgent;
111
111
  if (!isApp('jd', ua)) return null;
112
112
  return ua.split(';')[4];
113
113
  ua = ua || navigator.userAgent;
114
114
  if (appName === 'jd') return ua.split(';')[2] || null;
115
115
  if (appName === 'wx') return (/micromessenger\/([\S]*)/i.test(ua) ? RegExp.$1 : null
116
116
  );
117
117
  if (appName === 'qq') return (/qq\/([\S]*)/i.test(ua) ? RegExp.$1 : null
118
118
  );
119
119
  return null;
120
120
  ua = ua || navigator.userAgent;
121
121
  var match = ua.match(/android\s([0-9\.]*)/i);
122
122
  return match ? match[1] : 'unknown';
123
123
  ua = ua || navigator.userAgent;
124
124
  var match = ua.match(/OS ((\d+_?){2,3})\s/i);
125
125
  return match ? match[1].replace(/_/g, '.') : 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conecli/cone-render",
3
- "version": "0.8.21",
3
+ "version": "0.8.22-beta.1",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist/"