@uxda/appkit 1.2.2 → 1.2.4

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/index.js CHANGED
@@ -388,7 +388,8 @@ const appKitOptions = {
388
388
  tempToken: () => "",
389
389
  baseUrl: () => "",
390
390
  401() {
391
- }
391
+ },
392
+ gray: () => ""
392
393
  };
393
394
  const useAppKitOptions = () => {
394
395
  if (!globalData.$appKitOptions) {
@@ -422,7 +423,8 @@ function useHttp$1() {
422
423
  const headers = {
423
424
  Token: appkitOptions.token(),
424
425
  Appcode: appkitOptions.app(),
425
- cookie: `tid=${appkitOptions.tenant()}`
426
+ cookie: `tid=${appkitOptions.tenant()}`,
427
+ gray: appkitOptions.gray()
426
428
  };
427
429
  const $http = createHttp({
428
430
  vendor: vendor$1,
@@ -809,7 +811,8 @@ function useHttp() {
809
811
  const headers = {
810
812
  Token: appkitOptions.token(),
811
813
  Appcode: appkitOptions.app(),
812
- cookie: `tid=${appkitOptions.tenant()}`
814
+ cookie: `tid=${appkitOptions.tenant()}`,
815
+ gray: appkitOptions.gray()
813
816
  };
814
817
  const $http = createHttp({
815
818
  vendor,
@@ -2227,11 +2230,11 @@ var script$2 = /* @__PURE__ */ defineComponent({
2227
2230
  if (props.type === "province") {
2228
2231
  return [provinceOption];
2229
2232
  }
2230
- const cityOption = provinceOption[tmpSelectedIndex.value[0]].children;
2233
+ const cityOption = provinceOption[tmpSelectedIndex.value[0]]?.children ?? [];
2231
2234
  if (props.type === "city") {
2232
2235
  return [provinceOption, cityOption];
2233
2236
  }
2234
- const regionOption = cityOption[tmpSelectedIndex.value[1]].children;
2237
+ const regionOption = cityOption[tmpSelectedIndex.value[1]]?.children ?? [];
2235
2238
  return [provinceOption, cityOption, regionOption];
2236
2239
  });
2237
2240
  function init() {
@@ -2240,7 +2243,7 @@ var script$2 = /* @__PURE__ */ defineComponent({
2240
2243
  if (props.value) {
2241
2244
  const items = [];
2242
2245
  for (let index = 0; index < options.value.length; index++) {
2243
- const item = options.value[index][selectedIndex.value[index]];
2246
+ const item = options.value[index]?.[selectedIndex.value[index]];
2244
2247
  if (item) {
2245
2248
  items.push(item);
2246
2249
  }
@@ -2281,9 +2284,11 @@ var script$2 = /* @__PURE__ */ defineComponent({
2281
2284
  labels: []
2282
2285
  };
2283
2286
  for (let index = 0; index <= lastSelectedIndex; index++) {
2284
- const item = options.value[index][tmpSelectedIndex.value[index]];
2285
- result.values.push(item.value);
2286
- result.labels.push(item.label);
2287
+ const item = options.value[index]?.[tmpSelectedIndex.value[index]];
2288
+ if (item) {
2289
+ result.values.push(item.value);
2290
+ result.labels.push(item.label);
2291
+ }
2287
2292
  }
2288
2293
  emit("update:value", result.values[result.values.length - 1]);
2289
2294
  emit("change", result);
@@ -2784,9 +2789,7 @@ const nutComponents = [
2784
2789
  const appComponents = {
2785
2790
  ...components
2786
2791
  };
2787
- const services = [
2788
- ...services$1
2789
- ];
2792
+ const services = [...services$1];
2790
2793
  const $app = {
2791
2794
  setToken: (token) => {
2792
2795
  const appKitOptions = useAppKitOptions();
@@ -2815,6 +2818,7 @@ const AppKit = {
2815
2818
  appKitOptions.token = options.token;
2816
2819
  appKitOptions.baseUrl = options.baseUrl;
2817
2820
  appKitOptions[401] = options[401];
2821
+ appKitOptions.gray = options.gray;
2818
2822
  nutComponents.forEach((component) => {
2819
2823
  app.use(component);
2820
2824
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxda/appkit",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "小程序应用开发包",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.ts",
package/src/Appkit.ts CHANGED
@@ -8,34 +8,38 @@ export type AppKitOptions = {
8
8
  /**
9
9
  * 应用
10
10
  */
11
- app (): string,
11
+ app(): string
12
12
  /**
13
13
  * 租户
14
14
  */
15
- tenant (): string,
15
+ tenant(): string
16
16
  /**
17
17
  * token 获取方法
18
18
  * 由使用场景提供
19
19
  */
20
- token (): string,
20
+ token(): string
21
21
  /**
22
22
  * 临时 token 获取方法
23
23
  * 由使用场景提供
24
24
  */
25
- tempToken: () => string,
25
+ tempToken: () => string
26
26
  /**
27
27
  * 调用 API 时使用的 base url
28
28
  */
29
- baseUrl (): string,
30
-
31
- 401 (): void
29
+ baseUrl(): string
30
+
31
+ 401(): void
32
+ /**
33
+ * http灰度标记
34
+ */
35
+ gray(): string
32
36
  }
33
37
 
34
38
  export type DollarApp = {
35
- setToken: (token: () => string) => void,
36
- setTempToken: (token: () => string) => void,
37
- requestPayment: (options: PaymentParams) => void,
38
- invokeRecharge: (options: RechargeParams) => void,
39
+ setToken: (token: () => string) => void
40
+ setTempToken: (token: () => string) => void
41
+ requestPayment: (options: PaymentParams) => void
42
+ invokeRecharge: (options: RechargeParams) => void
39
43
  }
40
44
 
41
45
  /**
@@ -47,7 +51,8 @@ const appKitOptions: AppKitOptions = {
47
51
  token: () => '',
48
52
  tempToken: () => '',
49
53
  baseUrl: () => '',
50
- 401 () {}
54
+ 401() {},
55
+ gray: () => '',
51
56
  }
52
57
 
53
58
  const useAppKitOptions = () => {
@@ -57,8 +62,4 @@ const useAppKitOptions = () => {
57
62
  return globalData.$appKitOptions as AppKitOptions
58
63
  }
59
64
 
60
-
61
-
62
- export {
63
- useAppKitOptions,
64
- }
65
+ export { useAppKitOptions }
@@ -3,38 +3,40 @@ import { HttpRequestConfig, PagingData, PagingParams, ResponseRaw, createHttp }
3
3
  import { translates, transforms } from './endpoints'
4
4
  import { useAppKitOptions } from '../../Appkit'
5
5
 
6
-
7
6
  /**
8
7
  * 小程序端 Http
9
8
  * 使用 Taro.request 实现
10
9
  */
11
10
  const vendor = {
12
- async request <T>(config: HttpRequestConfig) {
11
+ async request<T>(config: HttpRequestConfig) {
13
12
  return new Promise<ResponseRaw<T>>((resolve, reject) => {
14
13
  Taro.request({
15
14
  url: config.url,
16
15
  method: config.method,
17
16
  header: config.headers,
18
- data: config.data
19
- }).then(({data}) => {
20
- resolve({
21
- status: +data.code,
22
- message: data.msg,
23
- data: data.result as T
24
- })
25
- }).catch((e: any) => {
26
- reject(e)
17
+ data: config.data,
27
18
  })
19
+ .then(({ data }) => {
20
+ resolve({
21
+ status: +data.code,
22
+ message: data.msg,
23
+ data: data.result as T,
24
+ })
25
+ })
26
+ .catch((e: any) => {
27
+ reject(e)
28
+ })
28
29
  })
29
- }
30
+ },
30
31
  }
31
32
 
32
- function useHttp () {
33
+ function useHttp() {
33
34
  const appkitOptions = useAppKitOptions()
34
35
  const headers = {
35
36
  Token: appkitOptions.token(),
36
37
  Appcode: appkitOptions.app(),
37
- cookie: `tid=${appkitOptions.tenant()}`
38
+ cookie: `tid=${appkitOptions.tenant()}`,
39
+ gray: appkitOptions.gray(),
38
40
  }
39
41
  /**
40
42
  * 传入配置获取 Http instanse
@@ -44,30 +46,30 @@ function useHttp () {
44
46
  baseUrl: appkitOptions.baseUrl(),
45
47
  headers,
46
48
  interceptors: [
47
- raw => {
49
+ (raw) => {
48
50
  if (raw.status == 401) {
49
51
  appkitOptions[401]()
50
52
  return true
51
53
  }
52
54
  return false
53
55
  },
54
- raw => {
56
+ (raw) => {
55
57
  if (raw.status > 500) {
56
58
  return true
57
59
  }
58
60
  return false
59
- }
61
+ },
60
62
  ],
61
63
  paging: {
62
64
  translate: (params: PagingParams) => ({
63
65
  pageNum: params.page,
64
- pageSize: params.pageSize
66
+ pageSize: params.pageSize,
65
67
  }),
66
- transform (data: any): PagingData {
68
+ transform(data: any): PagingData {
67
69
  return {
68
- totalPages: data.pages
70
+ totalPages: data.pages,
69
71
  }
70
- }
72
+ },
71
73
  },
72
74
  translates,
73
75
  transforms,
@@ -75,8 +77,6 @@ function useHttp () {
75
77
  return $http
76
78
  }
77
79
 
78
- export {
79
- useHttp
80
- }
80
+ export { useHttp }
81
81
 
82
82
  export * from './endpoints'
@@ -88,21 +88,21 @@ const options = computed<AreaItem[][]>(() => {
88
88
  if (props.type === 'province') {
89
89
  return [provinceOption]
90
90
  }
91
- const cityOption = provinceOption[tmpSelectedIndex.value[0]].children
91
+ const cityOption = provinceOption[tmpSelectedIndex.value[0]]?.children ?? []
92
92
  if (props.type === 'city') {
93
93
  return [provinceOption, cityOption]
94
94
  }
95
- const regionOption = cityOption[tmpSelectedIndex.value[1]].children
95
+ const regionOption = cityOption[tmpSelectedIndex.value[1]]?.children ?? []
96
96
  return [provinceOption, cityOption, regionOption]
97
97
  })
98
98
 
99
99
  function init() {
100
100
  selectedIndex.value = findIndexByValue()
101
101
  tmpSelectedIndex.value = [...selectedIndex.value]
102
- if (props.value){
102
+ if (props.value) {
103
103
  const items = []
104
104
  for (let index = 0; index < options.value.length; index++) {
105
- const item = options.value[index][selectedIndex.value[index]]
105
+ const item = options.value[index]?.[selectedIndex.value[index]]
106
106
  if (item){
107
107
  items.push(item)
108
108
  }
@@ -145,9 +145,11 @@ function onChange() {
145
145
  labels: []
146
146
  }
147
147
  for (let index = 0; index <= lastSelectedIndex; index++) {
148
- const item = options.value[index][tmpSelectedIndex.value[index]]
149
- result.values.push(item.value)
150
- result.labels.push(item.label)
148
+ const item = options.value[index]?.[tmpSelectedIndex.value[index]]
149
+ if (item){
150
+ result.values.push(item.value)
151
+ result.labels.push(item.label)
152
+ }
151
153
  }
152
154
  emit('update:value', result.values[result.values.length-1])
153
155
  emit('change', result)
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  Form,
13
13
  FormItem,
14
14
  Cell,
15
- CellGroup
15
+ CellGroup,
16
16
  } from '@nutui/nutui-taro'
17
17
  import { type AppKitOptions, useAppKitOptions, DollarApp } from './Appkit'
18
18
  import { PaymentParams, RechargeParams } from './payment/types'
@@ -29,16 +29,14 @@ const nutComponents = [
29
29
  Form,
30
30
  FormItem,
31
31
  Cell,
32
- CellGroup
32
+ CellGroup,
33
33
  ]
34
34
 
35
35
  const appComponents = {
36
- ...paymentComponents
36
+ ...paymentComponents,
37
37
  }
38
38
 
39
- const services = [
40
- ...paymentServices
41
- ]
39
+ const services = [...paymentServices]
42
40
 
43
41
  const $app: DollarApp = {
44
42
  setToken: (token: () => string) => {
@@ -50,32 +48,33 @@ const $app: DollarApp = {
50
48
  appKitOptions.tempToken = token
51
49
  },
52
50
  requestPayment: (options: PaymentParams) => {},
53
- invokeRecharge: (options: RechargeParams) => {}
51
+ invokeRecharge: (options: RechargeParams) => {},
54
52
  }
55
53
 
56
- services.forEach(service => {
54
+ services.forEach((service) => {
57
55
  service.install($app)
58
56
  })
59
57
 
60
- export function useAppKit (): DollarApp {
58
+ export function useAppKit(): DollarApp {
61
59
  return $app
62
60
  }
63
61
 
64
62
  const AppKit = {
65
- install (app: App, options: AppKitOptions) {
63
+ install(app: App, options: AppKitOptions) {
66
64
  const appKitOptions = useAppKitOptions()
67
65
  appKitOptions.app = options.app
68
66
  appKitOptions.tenant = options.tenant
69
67
  appKitOptions.token = options.token
70
68
  appKitOptions.baseUrl = options.baseUrl
71
69
  appKitOptions[401] = options[401]
72
- nutComponents.forEach(component => {
70
+ appKitOptions.gray = options.gray
71
+ nutComponents.forEach((component) => {
73
72
  app.use(component)
74
73
  })
75
74
  Object.entries(appComponents).forEach(([name, component]) => {
76
75
  app.component(name, component)
77
76
  })
78
- }
77
+ },
79
78
  }
80
79
 
81
80
  export default AppKit
@@ -84,6 +83,4 @@ export * from './payment'
84
83
  export * from './balance'
85
84
  export * from './shared'
86
85
  export * from './register'
87
- export {
88
- type AppKitOptions
89
- }
86
+ export { type AppKitOptions }
@@ -3,38 +3,40 @@ import { HttpRequestConfig, ResponseRaw, createHttp } from '../../shared'
3
3
  import { translates, transforms } from './endpoints'
4
4
  import { useAppKitOptions } from '../../Appkit'
5
5
 
6
-
7
6
  /**
8
7
  * 小程序端 Http
9
8
  * 使用 Taro.request 实现
10
9
  */
11
10
  const vendor = {
12
- async request <T>(config: HttpRequestConfig) {
11
+ async request<T>(config: HttpRequestConfig) {
13
12
  return new Promise<ResponseRaw<T>>((resolve, reject) => {
14
13
  Taro.request({
15
14
  url: config.url,
16
15
  method: config.method,
17
16
  header: config.headers,
18
- data: config.data
19
- }).then(({data}) => {
20
- resolve({
21
- status: data.code,
22
- message: data.msg,
23
- data: data.result as T
24
- })
25
- }).catch((e: any) => {
26
- reject(e)
17
+ data: config.data,
27
18
  })
19
+ .then(({ data }) => {
20
+ resolve({
21
+ status: data.code,
22
+ message: data.msg,
23
+ data: data.result as T,
24
+ })
25
+ })
26
+ .catch((e: any) => {
27
+ reject(e)
28
+ })
28
29
  })
29
- }
30
+ },
30
31
  }
31
32
 
32
- function useHttp () {
33
+ function useHttp() {
33
34
  const appkitOptions = useAppKitOptions()
34
35
  const headers = {
35
36
  Token: appkitOptions.token(),
36
37
  Appcode: appkitOptions.app(),
37
- cookie: `tid=${appkitOptions.tenant()}`
38
+ cookie: `tid=${appkitOptions.tenant()}`,
39
+ gray: appkitOptions.gray(),
38
40
  }
39
41
  /**
40
42
  * 传入配置获取 Http instanse
@@ -44,19 +46,19 @@ function useHttp () {
44
46
  baseUrl: appkitOptions.baseUrl(),
45
47
  headers,
46
48
  interceptors: [
47
- raw => {
49
+ (raw) => {
48
50
  if (raw.status == 401) {
49
51
  appkitOptions[401]()
50
52
  return true
51
53
  }
52
54
  return false
53
55
  },
54
- raw => {
56
+ (raw) => {
55
57
  if (raw.status > 500) {
56
58
  return true
57
59
  }
58
60
  return false
59
- }
61
+ },
60
62
  ],
61
63
  translates,
62
64
  transforms,
@@ -64,8 +66,6 @@ function useHttp () {
64
66
  return $http
65
67
  }
66
68
 
67
- export {
68
- useHttp
69
- }
69
+ export { useHttp }
70
70
 
71
71
  export * from './endpoints'