@conecli/cone-render 0.8.19-beta.1 → 0.8.19-beta.2

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
- import Taro, { RequestTask } 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
  cookiesStr: '',
9
7
  requestHeaderContentType: {
10
8
  jsonHeader: {
11
9
  'content-type': 'application/json;charset=utf-8',
12
10
  },
13
11
  formDataHeader: {
14
12
  'content-type': 'application/x-www-form-urlencoded',
15
13
  },
16
14
  },
17
15
  requestBaseParam: {
18
16
  data: null,
19
17
  header: {
20
18
  'content-type': 'application/json;charset=utf-8',
21
19
  },
22
20
  },
23
21
  timeOut: 7000,
24
22
  apiClientParams: {
25
23
  appid: SHOP_COLOR_APPID,
26
24
  clientVersion:
27
25
  isH5AndJdShopView && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
28
26
  client: isH5AndJdShopView ? (isIosDevice ? 'apple' : 'android') : 'wh5',
29
27
  area: '1_72_2799_0',
30
28
  uuid: UUID,
31
29
  loginType: "11",
32
30
  },
33
31
  public addressFetchInfo: {
34
32
  reqState: boolean
35
33
  promiseInstance: null | Promise<any>
36
34
  }
37
35
  public getPromotionConfig: {
38
36
  projectId: null | string | number
39
37
  pageId: null | string | number
40
38
  }
41
39
  public resInfo: ServiceInterFace.HttpRequestInfo
42
40
  public api: ServiceInterFace.HttpApi
43
41
  public isPageDomain: boolean
44
42
  constructor(opt) {
45
43
  this._init()
46
44
  this.addressFetchInfo = {
47
45
  reqState: false,
48
46
  promiseInstance: null,
49
47
  }
50
48
  this.getPromotionConfig = {
51
49
  projectId: null,
52
50
  pageId: null,
53
51
  }
54
52
  this._userAreaUpdateListen()
55
53
  this.resInfo = this._getResConfig(opt)
56
54
  this.api = api
57
55
  this.isPageDomain = window.location.hostname === PAGES_DOMAIN
58
56
  }
59
57
  _init(): void {
60
58
  httpInterceptors.forEach((item) => {
61
59
  Taro.addInterceptor((chain) => item(chain))
62
60
  })
63
61
  }
64
62
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
65
63
  return Object.assign({}, DefaultConfig, opt)
66
64
  }
67
65
 
68
66
  _userAreaUpdateListen() {
69
67
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
70
68
  this.updateApiClientParamsResInfo({
71
69
  area,
72
70
  })
73
71
  })
74
72
  }
75
73
  updateApiClientParamsResInfo(opt = {}) {
76
74
  this.resInfo.apiClientParams = {
77
75
  ...this.resInfo.apiClientParams,
78
76
  ...opt,
79
77
  }
80
78
  }
81
79
 
82
80
  _paramsSign(data) {
83
81
  return Promise.resolve(data)
84
82
  }
85
83
 
86
84
  checkFunctionIdToReturnAppId(functionId) {
87
85
  return JshopxColorFunctionIdList.includes(functionId)
88
86
  ? JSHOPX_COLOR_APPID
89
87
  : this.isPageDomain && PagesColorFunctionIdList.includes(functionId)
90
88
  ? PAGES_COLOR_APPID
91
89
  : SHOP_COLOR_APPID
92
90
  }
93
91
 
94
92
  apiReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
95
93
  if (
96
94
  functionId === 'receiveShopCoupon' &&
97
95
  ((isH5 && window.isJingGouMiniViewState) || isWxMinAndWxapp)
98
96
  ) {
99
97
  clientParams = Object.assign(
100
98
  {},
101
99
  {
102
100
  loginType: '1',
103
101
  loginWQBiz: WXAPP_BIZ_KEY,
104
102
  },
105
103
  clientParams,
106
104
  )
107
105
  }
108
106
  const apiClientParams = Object.assign(
109
107
  {},
110
108
  this.resInfo.apiClientParams,
111
109
  clientParams,
112
110
  )
113
111
  const getReqData = {
114
112
  functionId: functionId,
115
113
  body: JSON.stringify(bodyParams),
116
114
  t: Date.now(),
117
115
  ...apiClientParams,
118
116
  }
119
117
  console.log(`apiReq:${this.api.apiFunc}`)
120
118
  return this.request(this.api.apiFunc, getReqData, {}, 'GET')
121
119
  .then((res: ServiceInterFace.RequestPromiseRes) => {
122
120
  const { statusCode, data } = res
123
121
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
124
122
  ok: true,
125
123
  }
126
124
  if (statusCode === 200 && data) {
127
125
  const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
128
126
  ? Number(res.data.code)
129
127
  : -1
130
128
  const subCode = Object.prototype.hasOwnProperty.call(
131
129
  res.data,
132
130
  'subCode',
133
131
  )
134
132
  ? Number(res.data.subCode)
135
133
  : -1
136
134
  if (
137
135
  data.success === true ||
138
136
  data.isSuccess ||
139
137
  resCode === 0 ||
140
138
  resCode === 200 ||
141
139
  subCode === 0
142
140
  ) {
143
141
  changeRes = {
144
142
  result: Object.prototype.hasOwnProperty.call(data, 'result')
145
143
  ? data.result
146
144
  : Object.prototype.hasOwnProperty.call(data, 'data')
147
145
  ? data.data
148
146
  : data,
149
147
  code: data.code || 200,
150
148
  ok: true,
151
149
  source: data,
152
150
  }
153
151
  return changeRes
154
152
  } else {
155
153
  changeRes = {
156
154
  ...data,
157
155
  ok: false,
158
156
  statusCode: res.statusCode,
159
157
  }
160
158
  return changeRes
161
159
  }
162
160
  } else {
163
161
  changeRes = {
164
162
  ...data,
165
163
  ok: false,
166
164
  statusCode: res.statusCode,
167
165
  }
168
166
  return changeRes
169
167
  }
170
168
  })
171
169
  .catch((res) => {
172
170
  return {
173
171
  ...res,
174
172
  ok: false,
175
173
  } as ServiceInterFace.RequestResponseFormatRes
176
174
  })
177
175
  }
178
176
 
179
177
  request(
180
178
  url: string,
181
179
  data: string | object,
182
180
  otherOptions = {},
183
181
  method: keyof ServiceInterFace.Method = 'POST',
184
182
  ): RequestTask<any> {
185
183
  const header =
186
184
  method === 'POST'
187
185
  ? this.resInfo.requestHeaderContentType.formDataHeader
188
186
  : {}
189
187
  return Taro.request({
190
188
  ...this.resInfo.requestBaseParam,
191
189
  url,
192
190
  data,
193
191
  method,
194
192
  timeout: this.resInfo.timeOut,
195
193
  header,
196
194
  ...otherOptions,
197
195
  })
198
196
  }
199
197
 
200
198
  async receiveCoupon(param = {}, clientParams) {
201
199
  console.log(process.env.NODE_ENV)
202
200
  if(process.env.NODE_ENV === 'development'){
203
201
  return Promise.reject('本地环境不能领券')
204
202
  }
205
203
  return await this.apiReq(
206
204
  'receiveShopCoupon',
207
205
  {
208
206
  operation: '3',
209
207
  ...param,
210
208
  },
211
209
  clientParams,
212
210
  )
213
211
  }
@@ -1 +0,0 @@
1
- import HttpBase from './http'
2
  constructor() {
3
1
  super()
4
2
  }
5
3
 
6
4
  request({url, timeout = 7000, ...otherOptions}): any {
7
5
  const requestTask = super.request({url, timeout, ...otherOptions})
8
6
  const requestTimeoutPromise =
9
7
  new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
10
8
  setTimeout(() => {
11
9
  resolve({
12
10
  statusCode: 500,
13
11
  resTimeoutState: true,
14
12
  errMsg: 'request timeout',
15
13
  })
16
14
  }, timeout)
17
15
  })
18
16
  return Promise.race([requestTask, requestTimeoutPromise]).then(
19
17
  (res: ServiceInterFace.RequestPromiseRes) => {
20
18
  if (res && res.statusCode === 500 && res.resTimeoutState) {
21
19
  console.log('request 请求超时 url:' + url)
22
20
  requestTask.abort()
23
21
  }
24
22
  return res
25
23
  }
26
24
  )
27
25
  }