@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.
@@ -1 +1 @@
1
- import { isApp, getUrlQuery } from '../utils/jm-common'
1
+ import { isApp, getUrlQuery } from '../utils/jm-common'
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  console.log('京购商详页跳转:', this.jumpMiniPath.detail)
2
+ import Taro from '@tarojs/taro'
3
3
  console.log('京购商详页跳转:', this.jumpMiniPath.detail)
4
4
  const getJsonParam = etModelInfo && logBaseInfo ? logBaseInfo : Object.assign({},{
5
5
  shopid: global.info.queryInfo?.shopId,
6
6
  },jsonParam)
@@ -1 +1 @@
1
- export enum LogPnameInfo {
1
+ export enum LogPnameInfo {
2
2
  MOBILE_SEARCH = 'MShop_SearchResult'
@@ -1 +1 @@
1
- import global from '../common'
1
+ import global from '../common'
2
2
  const pageParamStr = typeof pageParam === 'object' ? JSON.stringify(pageParam) : pageParam
3
3
 
4
4
  jdJumpToTabAllProductInner(shopId, venderId, logEventInfo = {}){
5
5
  this.jdJumpToTabAllProduct(shopId, venderId, logEventInfo)
6
6
  }
7
7
  const getJsonParam = etModelInfo && logBaseInfo ? logBaseInfo : Object.assign({},{
8
8
  shopid: global.info.queryInfo?.shopId,
9
9
  },jsonParam)
10
10
  jsonParam: JSON.stringify(getJsonParam),
@@ -0,0 +1 @@
1
+ import { JdJumpJdApp } from './jdJumpJdApp'
2
  reportClick,
1
3
  reportToCart,
2
4
  routerInfo: {
3
5
  params: {},
4
6
  },
5
7
  nativeEvent: null,
6
8
  jumpConfig: {
7
9
  venderId: null,
8
10
  shopId: null,
9
11
  sourceValue: '',
10
12
  sourceType: 'App-H5',
11
13
  activityType: 'shopx',
12
14
  moduleId: 'none',
13
15
  entrance: 'none',
14
16
  },
15
17
  logPageParamStr: '',
16
18
  public logPageId: string
17
19
  public jumpConfig: JumpEventReportInterFace.JumpH5ReportConfig
18
20
  constructor(opt = {}) {
19
21
  console.log("jdb加载==========")
20
22
  super(opt)
21
23
  this.getConfig(opt)
22
24
  }
23
25
 
24
26
  jdJumpToProduct(skuParams, logEventInfo) {
25
27
  if(typeof skuParams !== 'object') {
26
28
  console.error('万商app跳转商品详情参数需要对象,详情请查看文档')
27
29
  return
28
30
  }
29
31
 
30
32
  let { skuId, bMallTag, skuUniformBizInfo } = skuParams
31
33
  skuId = skuId.toString().trim()
32
34
  this.jdNavigateToNative({
33
35
  category: 'jump',
34
36
  des: 'skudetail',
35
37
  param: {
36
38
  skuId: skuId,
37
39
  bMallTag: bMallTag,
38
40
  skuUniformBizInfo
39
41
  },
40
42
  logEventInfo,
41
43
  })
42
44
  }
43
45
  jdNavigateToNative(
44
46
  console.log("otherParams", otherParams)
45
47
  const paramsStr = JSON.stringify(otherParams)
46
48
  console.log(
47
49
  '跳转web jd open协议',
48
50
  `${url}?params=${paramsStr}`,
49
51
  )
50
52
  console.log('catch', e)
51
53
  clickEventLog(
52
54
  getConfig(opt = {}) {
53
55
  return Object.assign(this, {}, defaultConfig, opt)
54
56
  }
@@ -1 +1 @@
1
- import * as device from './device'
1
+ import * as device from './device'
2
2
  device,
3
3
  environment,
4
4
  jump,
5
5
  storage,
6
6
  util,
7
7
  moduleUtil,
8
8
  track,
9
9
  trackPromise,
10
10
  global,
11
11
  http,
12
12
  shopMember,
13
13
  requestServer,
@@ -1 +1 @@
1
- import { JumpEventReport, JumpEventReportPromise } from '../../jumpEventReport'
2
1
  jdJumpToShopHome: (info: object) => void
3
2
  jdJumpToProduct: (skuId: string | null, logEventInfo: object) => void
4
3
  jdJumpConfigUrl: (detail: object, logEventInfo: object) => void
5
4
  jdJumpToShopMemberInfo: (logEventInfo: object) => void
6
5
  jdJumpToShopMemberPointDetail: (logEventInfo: object) => void
7
6
  jdJumpToShopMemberBenefit: (logEventInfo: object) => void
8
7
  jdJumpToShopMemberRule: (logEventInfo: object) => void
9
8
  jdJumpToShopMemberCloseAccount: (
10
9
  venderType: number,
11
10
  logEventInfo: object,
12
11
  ) => void
13
12
  jdJumpToShopMemberPointExchange: (
14
13
  venderType: number,
15
14
  channel: number,
16
15
  levelZeroMenuUrl: string,
17
16
  logEventInfo: object,
18
17
  ) => void
19
18
  jdJumpToShopMemberBonusPurchase: (
20
19
  customerLevel: number,
21
20
  logEventInfo: object,
22
21
  ) => void
23
22
  jdJumpToShopMemberGood: (customerLevel: number, logEventInfo: object) => void
24
23
  jdJumpToBeanDetail: (logEventInfo: object) => void
25
24
  jdJumpToMyRedEnvelope: (logEventInfo: object) => void
26
25
  jdJumpToMyCoupon: (logEventInfo: object) => void
27
26
  jdJumpToShopHome: () => {},
28
27
  jdJumpToProduct: () => {},
29
28
  jdJumpConfigUrl: () => {},
30
29
  jdJumpToShopMemberInfo: () => {},
31
30
  jdJumpToShopMemberPointDetail: () => {},
32
31
  jdJumpToShopMemberBenefit: () => {},
33
32
  jdJumpToShopMemberRule: () => {},
34
33
  jdJumpToShopMemberCloseAccount: () => {},
35
34
  jdJumpToShopMemberPointExchange: () => {},
36
35
  jdJumpToShopMemberBonusPurchase: () => {},
37
36
  jdJumpToShopMemberGood: () => {},
38
37
  jdJumpToBeanDetail: () => {},
39
38
  jdJumpToMyRedEnvelope: () => {},
40
39
  jdJumpToMyCoupon: () => {},
41
40
  jdJumpToWeb: (url: string, logEventInfo: object) => void
42
41
  jdJumpToAppMiniProgram: (path: string, logEventInfo: object) => void
43
42
  jdJumpToShopLight: (detail: object) => void
44
43
  jdJumpToAppMiniProgram: () => {},
45
44
  jdJumpToShopLight: () => {},
46
45
  jdJumpToWeb: () => {},
47
46
  [key: string]: any
48
47
  [key: string]: any
49
48
  const {
50
49
  jdJumpToTabAllProduct,
51
50
  jdJumpToShopHome,
52
51
  jdJumpToProduct,
53
52
  jdJumpToShopSearch,
54
53
  jdJumpConfigUrl,
55
54
  jdJumpToShopMemberInfo,
56
55
  jdJumpToShopMemberPointDetail,
57
56
  jdJumpToShopMemberBenefit,
58
57
  jdJumpToShopMemberRule,
59
58
  jdJumpToShopMemberCloseAccount,
60
59
  jdJumpToShopMemberPointExchange,
61
60
  jdJumpToShopMemberBonusPurchase,
62
61
  jdJumpToShopMemberGood,
63
62
  jdJumpToBeanDetail,
64
63
  jdJumpToMyRedEnvelope,
65
64
  jdJumpToMyCoupon,
66
65
  } = JumpEventReport
67
66
  const {
68
67
  jdJumpToAppMiniProgram,
69
68
  jdJumpToShopLight,
70
69
  jdJumpToWeb,
71
70
  jumpWebUrl,
72
71
  jumpMiniPath,
73
72
  } = JumpEventReport
74
73
  Object.assign(business, {
75
74
  jdJumpToShopHome: jdJumpToShopHome.bind(JumpEventReport),
76
75
  jdJumpToProduct: jdJumpToProduct.bind(JumpEventReport),
77
76
  jdJumpConfigUrl: jdJumpConfigUrl.bind(JumpEventReport),
78
77
  jdJumpToShopMemberInfo: jdJumpToShopMemberInfo.bind(JumpEventReport),
79
78
  jdJumpToShopMemberPointDetail:
80
79
  jdJumpToShopMemberPointDetail.bind(JumpEventReport),
81
80
  jdJumpToShopMemberBenefit: jdJumpToShopMemberBenefit.bind(JumpEventReport),
82
81
  jdJumpToShopMemberRule: jdJumpToShopMemberRule.bind(JumpEventReport),
83
82
  jdJumpToShopMemberCloseAccount:
84
83
  jdJumpToShopMemberCloseAccount.bind(JumpEventReport),
85
84
  jdJumpToShopMemberPointExchange:
86
85
  jdJumpToShopMemberPointExchange.bind(JumpEventReport),
87
86
  jdJumpToShopMemberBonusPurchase:
88
87
  jdJumpToShopMemberBonusPurchase.bind(JumpEventReport),
89
88
  jdJumpToShopMemberGood: jdJumpToShopMemberGood.bind(JumpEventReport),
90
89
  jdJumpToBeanDetail: jdJumpToBeanDetail.bind(JumpEventReport),
91
90
  jdJumpToMyRedEnvelope: jdJumpToMyRedEnvelope.bind(JumpEventReport),
92
91
  jdJumpToMyCoupon: jdJumpToMyCoupon.bind(JumpEventReport),
93
92
  })
94
93
  Object.assign(side, {
95
94
  jdJumpToAppMiniProgram: jdJumpToAppMiniProgram.bind(JumpEventReport),
96
95
  jdJumpToShopLight: jdJumpToShopLight.bind(JumpEventReport),
97
96
  jdJumpToWeb: jdJumpToWeb.bind(JumpEventReport),
98
97
  jumpWebUrl,
99
98
  jumpMiniPath,
100
99
  })
101
100
  Object.assign(webUrl, jumpWebUrl)
102
101
  Object.assign(minPath, jumpMiniPath)
102
+ import { JumpEventReport, JumpEventReportPromise } from '../../jumpEventReport'
103
103
  jdJumpToShopHome: (info: object) => void
104
104
  jdJumpToProduct: (skuId: string | null, logEventInfo: object) => void
105
105
  jdJumpConfigUrl: (detail: object, logEventInfo: object) => void
106
106
  jdJumpToShopMemberInfo: (logEventInfo: object) => void
107
107
  jdJumpToShopMemberPointDetail: (logEventInfo: object) => void
108
108
  jdJumpToShopMemberBenefit: (logEventInfo: object) => void
109
109
  jdJumpToShopMemberRule: (logEventInfo: object) => void
110
110
  jdJumpToShopMemberCloseAccount: (
111
111
  venderType: number,
112
112
  logEventInfo: object,
113
113
  ) => void
114
114
  jdJumpToShopMemberPointExchange: (
115
115
  venderType: number,
116
116
  channel: number,
117
117
  levelZeroMenuUrl: string,
118
118
  logEventInfo: object,
119
119
  ) => void
120
120
  jdJumpToShopMemberBonusPurchase: (
121
121
  customerLevel: number,
122
122
  logEventInfo: object,
123
123
  ) => void
124
124
  jdJumpToShopMemberGood: (customerLevel: number, logEventInfo: object) => void
125
125
  jdJumpToBeanDetail: (logEventInfo: object) => void
126
126
  jdJumpToMyRedEnvelope: (logEventInfo: object) => void
127
127
  jdJumpToMyCoupon: (logEventInfo: object) => void
128
128
  jdJumpToTabAllProduct: (shopId: string | number,venderId: string | number,logEventInfo: object) => void
129
129
  jdJumpToTabAllProductInner: (shopId: string | number,venderId: string | number,logEventInfo: object) => void
130
130
  jdJumpToShopHome: () => {},
131
131
  jdJumpToProduct: () => {},
132
132
  jdJumpConfigUrl: () => {},
133
133
  jdJumpToShopMemberInfo: () => {},
134
134
  jdJumpToShopMemberPointDetail: () => {},
135
135
  jdJumpToShopMemberBenefit: () => {},
136
136
  jdJumpToShopMemberRule: () => {},
137
137
  jdJumpToShopMemberCloseAccount: () => {},
138
138
  jdJumpToShopMemberPointExchange: () => {},
139
139
  jdJumpToShopMemberBonusPurchase: () => {},
140
140
  jdJumpToShopMemberGood: () => {},
141
141
  jdJumpToBeanDetail: () => {},
142
142
  jdJumpToMyRedEnvelope: () => {},
143
143
  jdJumpToMyCoupon: () => {},
144
144
  jdJumpToTabAllProductInner: () => {},
145
145
  jdJumpToWeb: (url: string, logEventInfo: object) => void
146
146
  jdJumpToAppMiniProgram: (path: string, logEventInfo: object) => void
147
147
  jdJumpToShopLight: (detail: object) => void
148
148
  jdJumpToAppMiniProgram: () => {},
149
149
  jdJumpToShopLight: () => {},
150
150
  jdJumpToWeb: () => {},
151
151
  [key: string]: any
152
152
  [key: string]: any
153
153
  const {
154
154
  jdJumpToShopHome,
155
155
  jdJumpToProduct,
156
156
  jdJumpConfigUrl,
157
157
  jdJumpToShopMemberInfo,
158
158
  jdJumpToShopMemberPointDetail,
159
159
  jdJumpToShopMemberBenefit,
160
160
  jdJumpToShopMemberRule,
161
161
  jdJumpToShopMemberCloseAccount,
162
162
  jdJumpToShopMemberPointExchange,
163
163
  jdJumpToShopMemberBonusPurchase,
164
164
  jdJumpToShopMemberGood,
165
165
  jdJumpToBeanDetail,
166
166
  jdJumpToMyRedEnvelope,
167
167
  jdJumpToMyCoupon,
168
168
  jdJumpToTabAllProduct,
169
169
  jdJumpToTabAllProductInner,
170
170
  } = JumpEventReport
171
171
  const {
172
172
  jdJumpToAppMiniProgram,
173
173
  jdJumpToShopLight,
174
174
  jdJumpToWeb,
175
175
  jumpWebUrl,
176
176
  jumpMiniPath,
177
177
  } = JumpEventReport
178
178
  Object.assign(business, {
179
179
  jdJumpToShopHome: jdJumpToShopHome.bind(JumpEventReport),
180
180
  jdJumpToProduct: jdJumpToProduct.bind(JumpEventReport),
181
181
  jdJumpConfigUrl: jdJumpConfigUrl.bind(JumpEventReport),
182
182
  jdJumpToShopMemberInfo: jdJumpToShopMemberInfo.bind(JumpEventReport),
183
183
  jdJumpToShopMemberPointDetail:
184
184
  jdJumpToShopMemberPointDetail.bind(JumpEventReport),
185
185
  jdJumpToShopMemberBenefit: jdJumpToShopMemberBenefit.bind(JumpEventReport),
186
186
  jdJumpToShopMemberRule: jdJumpToShopMemberRule.bind(JumpEventReport),
187
187
  jdJumpToShopMemberCloseAccount:
188
188
  jdJumpToShopMemberCloseAccount.bind(JumpEventReport),
189
189
  jdJumpToShopMemberPointExchange:
190
190
  jdJumpToShopMemberPointExchange.bind(JumpEventReport),
191
191
  jdJumpToShopMemberBonusPurchase:
192
192
  jdJumpToShopMemberBonusPurchase.bind(JumpEventReport),
193
193
  jdJumpToShopMemberGood: jdJumpToShopMemberGood.bind(JumpEventReport),
194
194
  jdJumpToBeanDetail: jdJumpToBeanDetail.bind(JumpEventReport),
195
195
  jdJumpToMyRedEnvelope: jdJumpToMyRedEnvelope.bind(JumpEventReport),
196
196
  jdJumpToMyCoupon: jdJumpToMyCoupon.bind(JumpEventReport),
197
197
  jdJumpToTabAllProduct: jdJumpToTabAllProduct.bind(JumpEventReport),
198
198
  jdJumpToTabAllProductInner: jdJumpToTabAllProductInner.bind(JumpEventReport),
199
199
  })
200
200
  Object.assign(side, {
201
201
  jdJumpToAppMiniProgram: jdJumpToAppMiniProgram.bind(JumpEventReport),
202
202
  jdJumpToShopLight: jdJumpToShopLight.bind(JumpEventReport),
203
203
  jdJumpToWeb: jdJumpToWeb.bind(JumpEventReport),
204
204
  jumpWebUrl,
205
205
  jumpMiniPath,
206
206
  })
207
207
  Object.assign(webUrl, jumpWebUrl)
208
208
  Object.assign(minPath, jumpMiniPath)
@@ -0,0 +1 @@
1
+ const userInfo =
2
  (window.WebViewCommon && window.WebViewCommon.getUserInfo()) || '{}'
1
3
  buId: JSON.parse(userInfo)?.data?.buId,
2
4
  process.env.NODE_ENV === 'development'
3
5
  ? {
4
6
  apolloId: '48ee955b0fb04d19b9f9fe8cb73d387f',
5
7
  apolloSecret: '0d9c76ee66b0487da4e17d3cf1d7af7a',
6
8
  }
7
9
  : {
8
10
  apolloId: '80c46fd06e4442998609d9f6a4ab96f0',
9
11
  apolloSecret: 'f36bef08bcba4683b409732095793fb2',
10
12
  }
11
13
  if (typeof window.crypto === 'object') {
12
14
  if (typeof (window.crypto as any).randomUUID === 'function') {
13
15
  return (window.crypto as any).randomUUID()
14
16
  }
15
17
  if (
16
18
  typeof (window.crypto as any).getRandomValues === 'function' &&
17
19
  typeof Uint8Array === 'function'
18
20
  ) {
19
21
  const callback = (c) => {
20
22
  const num = Number(c)
21
23
  return (
22
24
  num ^
23
25
  ((window.crypto as any).getRandomValues(new Uint8Array(1))[0] &
24
26
  (15 >> (num / 4)))
25
27
  ).toString(16)
26
28
  }
27
29
  return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, callback)
28
30
  }
29
31
  }
30
32
  let timestamp = new Date().getTime()
31
33
  let perforNow =
32
34
  (typeof window.performance !== 'undefined' &&
33
35
  window.performance.now &&
34
36
  window.performance.now() * 1000) ||
35
37
  0
36
38
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
37
39
  let random = Math.random() * 16
38
40
  if (timestamp > 0) {
39
41
  random = (timestamp + random) % 16 | 0
40
42
  timestamp = Math.floor(timestamp / 16)
41
43
  } else {
42
44
  random = (perforNow + random) % 16 | 0
43
45
  perforNow = Math.floor(perforNow / 16)
44
46
  }
45
47
  return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
46
48
  })
47
49
  let params = {
48
50
  uniformBizInfo: {
49
51
  tenantId: 1024,
50
52
  ua: 1,
51
53
  buId: commonParam.buId || 377,
52
54
  bMallTag: bMallTag,
53
55
  },
54
56
  commonParam: {
55
57
  pid: 100,
56
58
  verticalCode: 'cn_retail_bmall',
57
59
  ua: 1,
58
60
  language: 'zh',
59
61
  },
60
62
  operations: [{ TheSkus: [{ Id: skuId, num: num || 1 }] }],
61
63
  apolloId: APOLLO.apolloId,
62
64
  apolloSecret: APOLLO.apolloSecret,
63
65
  client: 'H5',
64
66
  verticalTag: 'cn_retail_bmall',
65
67
  carttype: bMallTag == 1 ? 21 : 22,
66
68
  bMallTag: bMallTag,
67
69
  traceId: getUuid(),
68
70
  noResponse: true,
69
71
  }
70
72
  if (skuUuid) {
71
73
  params.operations[0].TheSkus[0].skuUuid = skuUuid
72
74
  }
73
75
  if (window?.siteTransResult?.gridInfoList) {
74
76
  params = {
75
77
  ...params,
76
78
  cartLocationList: [
77
79
  {
78
80
  gridInfos:
79
81
  window?.siteTransResult?.gridInfoList &&
80
82
  JSON.parse(window?.siteTransResult?.gridInfoList),
81
83
  areaIdSet:
82
84
  window?.siteTransResult?.area &&
83
85
  window?.siteTransResult?.area?.split('-'),
84
86
  },
85
87
  ],
86
88
  }
87
89
  }
88
90
  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]: "成功"
17
+ export const HttpStatus = {
18
18
  SUCCESS: 200,
19
19
  CREATED: 201,
20
20
  ACCEPTED: 202,
21
21
  CLIENT_ERROR: 400,
22
22
  AUTHENTICATE: 401,
23
23
  FORBIDDEN: 403,
24
24
  NOT_FOUND: 404,
25
25
  SERVER_ERROR: 500,
26
26
  BAD_GATEWAY: 502,
27
27
  SERVICE_UNAVAILABLE: 503,
28
28
  GATEWAY_TIMEOUT: 504
29
29
  [HttpStatus.NOT_FOUND]: "请求资源不存在",
30
30
  [HttpStatus.BAD_GATEWAY]: "服务端异常,请稍后重试",
31
31
  [HttpStatus.FORBIDDEN]: "没有权限访问",
32
32
  [HttpStatus.AUTHENTICATE]: "需要鉴权",
33
33
  [HttpStatus.SUCCESS]: "成功"
34
34
  "getPagePreview"
35
35
  "getShopHomeFloorInfo",
36
36
  "getShopCategory",
37
37
  "getShopNavigationCategory",
38
38
  "receiveShopCoupon",
39
39
  "getShopHomePromotionWebPage",
40
40
  "shopGuessYouLike",
41
41
  "addRemind",
42
42
  "cancelRemind",
43
43
  "getVipDetail",
44
44
  "shopDetail",
45
45
  "address_queryAddress",
46
46
  "shopMemberSprintJoinActivity",
47
47
  "shopMemberSprintReceivePrize"
@@ -1 +1 @@
1
- import Taro, { RequestTask } from "@tarojs/taro";
2
1
  jsonHeader = "application/json;charset=utf-8",
3
2
  formDataHeader = "application/x-www-form-urlencoded"
4
3
  constructor() {
5
4
  this._init()
6
5
  }
7
6
  _init(): void {
8
7
  httpInterceptors.forEach((item) => {
9
8
  Taro.addInterceptor((chain) => item(chain))
10
9
  })
11
10
  }
12
11
 
13
12
  get(url: string, data: any = null, otherOptions = {}): Taro.RequestTask<any> {
14
13
  return this.request({url, data, method:"GET", ...otherOptions})
15
14
  }
16
15
 
17
16
  post(
18
17
  url: string,
19
18
  data: any = null,
20
19
  otherOptions = {}
21
20
  ): Taro.RequestTask<any> {
22
21
  return this.request({url, data, method:"POST", ...otherOptions})
23
22
  }
24
23
 
25
24
  request({url, method = "POST", timeout = 7000, ...otherOptions}): RequestTask<any> {
26
25
  const header = {
27
26
  "content-type": method === "POST" ? RequestHeaderContentType.formDataHeader : RequestHeaderContentType.jsonHeader
28
27
  }
29
28
  const requestTask = Taro.request({
30
29
  url,
31
30
  method,
32
31
  timeout,
33
32
  header,
34
33
  credentials: 'include',
35
34
  ...otherOptions,
36
35
  })
37
36
  const requestTimeoutPromise =
38
37
  new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
39
38
  setTimeout(() => {
40
39
  resolve({
41
40
  statusCode: 500,
42
41
  resTimeoutState: true,
43
42
  errMsg: 'request timeout',
44
43
  })
45
44
  }, timeout)
46
45
  })
47
46
  return Promise.race([requestTask, requestTimeoutPromise]).then(
48
47
  (res: any) => {
49
48
  if (res && res.statusCode === 500 && res.resTimeoutState) {
50
49
  console.log('request 请求超时 url:' + url)
51
50
  requestTask.abort && requestTask.abort()
52
51
  }
53
52
  return res
54
53
  }
55
54
  )
56
55
  }
56
+ import Taro, { RequestTask } from '@tarojs/taro'
57
57
  jsonHeader = 'application/json;charset=utf-8',
58
58
  formDataHeader = 'application/x-www-form-urlencoded',
59
59
  public fmInfo: {
60
60
  eid?: string
61
61
  fp?: string
62
62
  jsToken?: string
63
63
  sdkToken?: string
64
64
  }
65
65
  public api: ServiceInterFace.HttpApi
66
66
  constructor() {
67
67
  this._init()
68
68
  this.api = api
69
69
  this.fmInfo = {}
70
70
  }
71
71
  _init(): void {
72
72
  httpInterceptors.forEach((item) => {
73
73
  Taro.addInterceptor((chain) => item(chain))
74
74
  })
75
75
  }
76
76
 
77
77
  get(url: string, data: any = null, otherOptions = {}): Taro.RequestTask<any> {
78
78
  return this.request({ url, data, method: 'GET', ...otherOptions })
79
79
  }
80
80
 
81
81
  post(
82
82
  url: string,
83
83
  data: any = null,
84
84
  otherOptions = {},
85
85
  ): Taro.RequestTask<any> {
86
86
  return this.request({ url, data, method: 'POST', ...otherOptions })
87
87
  }
88
88
 
89
89
  _getMobileJsToken(): Promise<{
90
90
  ok: boolean
91
91
  data?: any
92
92
  error?: any
93
93
  }> {
94
94
  return new Promise((resolve, reject) => {
95
95
  try {
96
96
  if (window?.getJsToken) {
97
97
  window.getJsToken(function (res) {
98
98
  console.log('JS token 获取结果:', res)
99
99
  resolve({
100
100
  ok: true,
101
101
  data: res,
102
102
  })
103
103
  }, 600)
104
104
  } else {
105
105
  reject({
106
106
  ok: false,
107
107
  error: '没有识别到getJsToken全局方法',
108
108
  })
109
109
  }
110
110
  } catch (e) {
111
111
  console.log('获取指纹JS token 异常', e)
112
112
  reject({
113
113
  ok: false,
114
114
  error: e,
115
115
  })
116
116
  }
117
117
  })
118
118
  }
119
119
 
120
120
  async _getFmInfo() {
121
121
  try {
122
122
  const { ok, data } = await this._getMobileJsToken()
123
123
  this.fmInfo = ok && data ? data : this.fmInfo
124
124
  return this.fmInfo
125
125
  } catch (e) {
126
126
  console.log('获取指纹信息异常', e)
127
127
  return this.fmInfo
128
128
  }
129
129
  }
130
130
 
131
131
  async request({
132
132
  url,
133
133
  method = 'POST',
134
134
  timeout = 7000,
135
135
  ...otherOptions
136
136
  }): RequestTask<any> {
137
137
  const header = {
138
138
  'content-type':
139
139
  method === 'POST'
140
140
  ? RequestHeaderContentType.formDataHeader
141
141
  : RequestHeaderContentType.jsonHeader,
142
142
  }
143
143
  const getReqData = otherOptions.data
144
144
  if (url === this.api.apiFunc && typeof getReqData === 'object') {
145
145
  const { jsToken } = await this._getFmInfo()
146
146
  jsToken && (getReqData['x-api-eid-token'] = jsToken)
147
147
  }
148
148
  const requestTask = Taro.request({
149
149
  url,
150
150
  method,
151
151
  timeout,
152
152
  header,
153
153
  credentials: 'include',
154
154
  ...otherOptions,
155
155
  })
156
156
  const requestTimeoutPromise =
157
157
  new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
158
158
  setTimeout(() => {
159
159
  resolve({
160
160
  statusCode: 500,
161
161
  resTimeoutState: true,
162
162
  errMsg: 'request timeout',
163
163
  })
164
164
  }, timeout)
165
165
  })
166
166
  return Promise.race([requestTask, requestTimeoutPromise]).then(
167
167
  (res: any) => {
168
168
  if (res && res.statusCode === 500 && res.resTimeoutState) {
169
169
  console.log('request 请求超时 url:' + url)
170
170
  requestTask.abort && requestTask.abort()
171
171
  }
172
172
  return res
173
173
  },
174
174
  )
175
175
  }