@uxda/appkit 1.0.28 → 1.0.30

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/appkit.css CHANGED
@@ -77,7 +77,7 @@
77
77
  background-position: center center;
78
78
  }
79
79
  .page-header.color-mode-dark {
80
- color: var(--text-color-dark-mode, "#fff");
80
+ color: var(--text-color-dark-mode, #fff);
81
81
  }
82
82
  .page-header.color-mode-dark .back-button {
83
83
  background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDIiIGhlaWdodD0iNDIiIHZpZXdCb3g9IjAgMCA0MiA0MiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggb3BhY2l0eT0iMC4wMSIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wLjk5OTg0NyA0MUw0MC45OTk4IDQxTDQwLjk5OTggMUwwLjk5OTg0NyAxTDAuOTk5ODQ3IDQxWiIgZmlsbD0iI0Q4RDhEOCIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLW9wYWNpdHk9IjAuMDEiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMi45OTM0IDE4Ljk0NzVDMTEuODYzNCAyMC4wMTQzIDExLjgxMjEgMjEuNzk1MiAxMi44Nzg5IDIyLjkyNTJMMjcuOTEwNiAzNy4xMzQzQzI4LjY5MjcgMzcuODczMSAyOS45MjU2IDM3LjgzODIgMzAuNjY0NSAzNy4wNTYyQzMxLjM2ODIgMzYuMzExNCAzMS4zNyAzNS4xNTc2IDMwLjY5MyAzNC40MTExTDE2LjUwMTMgMjAuOTkzNkwzMC41ODU4IDcuNjk3NjFDMzEuMzMwOSA2Ljk5NDI0IDMxLjI5ODMgNS43Mjc3MSAzMC42NjUxIDQuOTQzNzdDMjkuOTYxNyA0LjE5ODcxIDI4LjgwOTkgNC4xMzEwNCAyOC4wMjYgNC43NjQyN0wxMi45OTM0IDE4Ljk0NzVaIiBmaWxsPSJ3aGl0ZSIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLW9wYWNpdHk9IjAuMDEiLz4KPC9zdmc+Cg==");
package/dist/index.js CHANGED
@@ -92,10 +92,11 @@ script$a.__file = "src/payment/components/UserAgreement.vue";
92
92
 
93
93
  function requestPayment$2(json) {
94
94
  return new Promise((resolve, reject) => {
95
- const success = (message) => {
95
+ const success = (res) => {
96
96
  resolve(true);
97
97
  };
98
- const fail = (message) => {
98
+ const fail = (res) => {
99
+ console.log("wx.requestPayment FAIL:", res);
99
100
  resolve(false);
100
101
  };
101
102
  wx.requestPayment({
@@ -210,12 +211,20 @@ const defaultClientConfig = {
210
211
  getCode: (data) => data.code,
211
212
  getMessage: (data) => data.msg,
212
213
  getData: (data) => data.result
214
+ },
215
+ interceptors: {
216
+ auth: (data) => data.code == "401",
217
+ server: (data) => false
213
218
  }
214
219
  };
215
220
  let clientConfig = {
216
221
  ...defaultClientConfig
217
222
  };
218
223
  const request = (config) => {
224
+ clientConfig = {
225
+ ...clientConfig,
226
+ ...config
227
+ };
219
228
  return new Promise((resolve, reject) => {
220
229
  const data = config.data && clientConfig.translates && clientConfig.translates[config.url] ? clientConfig.translates[config.url](config.data) : config.data;
221
230
  console.log(`[][][][][][][][][][][][] HTTP.${config.method}, ${clientConfig.baseUrl}${config.url}`, data);
@@ -232,7 +241,7 @@ const request = (config) => {
232
241
  const { data: raw } = res;
233
242
  if (clientConfig.interceptors?.auth(raw)) {
234
243
  clientConfig.onAuthError?.();
235
- reject("auth failed");
244
+ reject("--- 401 ---");
236
245
  }
237
246
  if (clientConfig.interceptors?.server(raw)) {
238
247
  clientConfig.onServerError?.();
@@ -276,11 +285,8 @@ function useHttp(config) {
276
285
  post
277
286
  };
278
287
  }
279
- const successResonseCodes = [
280
- "200"
281
- ];
282
288
  function isSuccess(res) {
283
- return /^2/.test(res.statusCode.toString()) && successResonseCodes.includes(`${clientConfig.response?.getCode(res.data)}`);
289
+ return /^2/.test(res.statusCode.toString());
284
290
  }
285
291
 
286
292
  const endpointsList$1 = {
@@ -353,7 +359,9 @@ const globalData = {};
353
359
 
354
360
  const appKitOptions = {
355
361
  token: () => "",
356
- baseUrl: () => ""
362
+ baseUrl: () => "",
363
+ 401() {
364
+ }
357
365
  };
358
366
  const useAppKitOptions = () => {
359
367
  if (!globalData.$appKitOptions) {
@@ -370,6 +378,9 @@ const makeHttp$1 = () => {
370
378
  const $http = useHttp({
371
379
  baseUrl: appkitOptions.baseUrl(),
372
380
  header,
381
+ onAuthError: () => {
382
+ appkitOptions["401"]();
383
+ },
373
384
  translates: translates$1,
374
385
  transforms: transforms$1
375
386
  });
@@ -476,7 +487,6 @@ var script$7 = /* @__PURE__ */ defineComponent({
476
487
  return false;
477
488
  }
478
489
  state.buttonLoading = true;
479
- console.log("state.selected", state.selected);
480
490
  wx.login({
481
491
  success({ code }) {
482
492
  requestPayment({
@@ -717,6 +727,9 @@ const makeHttp = () => {
717
727
  const $http = useHttp({
718
728
  baseUrl: appkitOptions.baseUrl(),
719
729
  header,
730
+ onAuthError() {
731
+ appkitOptions[401]();
732
+ },
720
733
  translates,
721
734
  transforms
722
735
  });
@@ -1653,7 +1666,7 @@ const _hoisted_2 = /* @__PURE__ */ createElementVNode(
1653
1666
  { class: "body" },
1654
1667
  [
1655
1668
  /* @__PURE__ */ createElementVNode("h2", null, "\u64CD\u4F5C\u5931\u8D25"),
1656
- /* @__PURE__ */ createElementVNode("p", null, "\u60A8\u7684\u8D26\u6237\u4F59\u989D\u53EF\u80FD\u4E0D\u8DB3\uFF0C\u8BF7\u5145\u503C\u540E\u518D\u8FDB\u884C\u67E5\u8BE2")
1669
+ /* @__PURE__ */ createElementVNode("p", null, "\u60A8\u7684\u8D26\u6237\u53EF\u7528\u4F59\u989D\u4E0D\u8DB3\uFF0C\u8BF7\u5145\u503C\u540E\u518D\u8FDB\u884C\u67E5\u8BE2")
1657
1670
  ],
1658
1671
  -1
1659
1672
  /* HOISTED */
@@ -1759,6 +1772,7 @@ const AppKit = {
1759
1772
  const appKitOptions = useAppKitOptions();
1760
1773
  appKitOptions.token = options.token;
1761
1774
  appKitOptions.baseUrl = options.baseUrl;
1775
+ appKitOptions[401] = options[401];
1762
1776
  nutComponents.forEach((component) => {
1763
1777
  app.use(component);
1764
1778
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxda/appkit",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "小程序应用开发包",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.ts",
package/src/Appkit.ts CHANGED
@@ -14,6 +14,7 @@ export type AppKitOptions = {
14
14
  * 调用 API 时使用的 base url
15
15
  */
16
16
  baseUrl (): string,
17
+ 401 (): void
17
18
  }
18
19
 
19
20
  export type DollarApp = {
@@ -27,7 +28,8 @@ export type DollarApp = {
27
28
  */
28
29
  const appKitOptions: AppKitOptions = {
29
30
  token: () => '',
30
- baseUrl: () => ''
31
+ baseUrl: () => '',
32
+ 401 () {}
31
33
  }
32
34
 
33
35
  const useAppKitOptions = () => {
@@ -12,6 +12,9 @@ const makeHttp = () => {
12
12
  const $http = useHttp({
13
13
  baseUrl: appkitOptions.baseUrl(),
14
14
  header,
15
+ onAuthError () {
16
+ appkitOptions[401]()
17
+ },
15
18
  translates,
16
19
  transforms,
17
20
  })
@@ -8,7 +8,7 @@
8
8
  <div class="balance-reminder">
9
9
  <div class="body">
10
10
  <h2>操作失败</h2>
11
- <p>您的账户余额可能不足,请充值后再进行查询</p>
11
+ <p>您的账户可用余额不足,请充值后再进行查询</p>
12
12
  </div>
13
13
  <div class="footer">
14
14
  <div class="col">
package/src/index.ts CHANGED
@@ -57,6 +57,7 @@ const AppKit = {
57
57
  const appKitOptions = useAppKitOptions()
58
58
  appKitOptions.token = options.token
59
59
  appKitOptions.baseUrl = options.baseUrl
60
+ appKitOptions[401] = options[401]
60
61
  nutComponents.forEach(component => {
61
62
  app.use(component)
62
63
  })
@@ -12,6 +12,9 @@ const makeHttp = () => {
12
12
  const $http = useHttp({
13
13
  baseUrl: appkitOptions.baseUrl(),
14
14
  header,
15
+ onAuthError: () => {
16
+ appkitOptions['401']()
17
+ },
15
18
  translates,
16
19
  transforms,
17
20
  })
@@ -100,7 +100,6 @@ const onPayClick = () => {
100
100
  return false
101
101
  }
102
102
  state.buttonLoading = true
103
- console.log('state.selected', state.selected)
104
103
  wx.login({
105
104
  success ({code}: {code: string}) {
106
105
  requestPayment({
@@ -63,7 +63,7 @@ const onBackButtonClick = () => {
63
63
  background-position: center center;
64
64
  }
65
65
  &.color-mode-dark {
66
- color: var(--text-color-dark-mode, '#fff');
66
+ color: var(--text-color-dark-mode, #fff);
67
67
  .back-button {
68
68
  background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDIiIGhlaWdodD0iNDIiIHZpZXdCb3g9IjAgMCA0MiA0MiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggb3BhY2l0eT0iMC4wMSIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wLjk5OTg0NyA0MUw0MC45OTk4IDQxTDQwLjk5OTggMUwwLjk5OTg0NyAxTDAuOTk5ODQ3IDQxWiIgZmlsbD0iI0Q4RDhEOCIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLW9wYWNpdHk9IjAuMDEiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMi45OTM0IDE4Ljk0NzVDMTEuODYzNCAyMC4wMTQzIDExLjgxMjEgMjEuNzk1MiAxMi44Nzg5IDIyLjkyNTJMMjcuOTEwNiAzNy4xMzQzQzI4LjY5MjcgMzcuODczMSAyOS45MjU2IDM3LjgzODIgMzAuNjY0NSAzNy4wNTYyQzMxLjM2ODIgMzYuMzExNCAzMS4zNyAzNS4xNTc2IDMwLjY5MyAzNC40MTExTDE2LjUwMTMgMjAuOTkzNkwzMC41ODU4IDcuNjk3NjFDMzEuMzMwOSA2Ljk5NDI0IDMxLjI5ODMgNS43Mjc3MSAzMC42NjUxIDQuOTQzNzdDMjkuOTYxNyA0LjE5ODcxIDI4LjgwOTkgNC4xMzEwNCAyOC4wMjYgNC43NjQyN0wxMi45OTM0IDE4Ljk0NzVaIiBmaWxsPSJ3aGl0ZSIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLW9wYWNpdHk9IjAuMDEiLz4KPC9zdmc+Cg==");
69
69
  }
@@ -24,6 +24,10 @@ const defaultClientConfig: HttpClientConfig = {
24
24
  getCode: (data: ResponseRaw) => data.code,
25
25
  getMessage: (data: ResponseRaw) => data.msg,
26
26
  getData: (data: ResponseRaw) => data.result
27
+ },
28
+ interceptors: {
29
+ auth: (data) => data.code == '401',
30
+ server: (data) => false,
27
31
  }
28
32
  }
29
33
 
@@ -37,6 +41,10 @@ let clientConfig = {
37
41
  * @returns
38
42
  */
39
43
  const request: Http['request'] = <T>(config: HttpRequestConfig) => {
44
+ clientConfig = {
45
+ ...clientConfig,
46
+ ...config,
47
+ }
40
48
  return new Promise<T>((resolve, reject) => {
41
49
  const data = config.data
42
50
  && clientConfig.translates
@@ -57,7 +65,7 @@ const request: Http['request'] = <T>(config: HttpRequestConfig) => {
57
65
  const { data: raw } = res
58
66
  if (clientConfig.interceptors?.auth(raw)) {
59
67
  clientConfig.onAuthError?.()
60
- reject('auth failed')
68
+ reject('--- 401 ---')
61
69
  }
62
70
  if (clientConfig.interceptors?.server(raw)) {
63
71
  clientConfig.onServerError?.()
@@ -118,11 +126,8 @@ export function useHttp (config: HttpClientConfig): Http {
118
126
  }
119
127
  }
120
128
 
121
- const successResonseCodes = [
122
- '200'
123
- ]
129
+
124
130
 
125
131
  function isSuccess (res: Taro.request.SuccessCallbackResult<ResponseRaw>) {
126
132
  return /^2/.test(res.statusCode.toString())
127
- && successResonseCodes.includes(`${clientConfig.response?.getCode(res.data)}`)
128
133
  }
@@ -22,10 +22,11 @@ export function requestPayment(json: any): Promise<boolean> {
22
22
  // /**接口调用结束的回调函数(调用成功、失败都会执行)*/
23
23
  // complete = () => {}
24
24
  return new Promise<boolean>((resolve, reject) => {
25
- const success = (message: string) => {
25
+ const success = (res) => {
26
26
  resolve(true)
27
27
  }
28
- const fail = (message: string) => {
28
+ const fail = (res) => {
29
+ console.log('wx.requestPayment FAIL:', res)
29
30
  resolve(false)
30
31
  }
31
32
  wx.requestPayment({