@uxda/appkit 1.2.0 → 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,
@@ -2169,6 +2172,7 @@ var script$2 = /* @__PURE__ */ defineComponent({
2169
2172
  rightIcon: { type: Boolean, required: false, default: true },
2170
2173
  placeholder: { type: String, required: false, default: "\u8BF7\u9009\u62E9" },
2171
2174
  disabled: { type: Boolean, required: false, default: false },
2175
+ type: { type: String, required: false, default: "region" },
2172
2176
  formatter: { type: Function, required: false, default: (values) => values.map((item) => item.label).join("") }
2173
2177
  },
2174
2178
  emits: ["update:value", "change", "cancel"],
@@ -2223,8 +2227,14 @@ var script$2 = /* @__PURE__ */ defineComponent({
2223
2227
  const selectedItem = ref([]);
2224
2228
  const options = computed(() => {
2225
2229
  const provinceOption = areaFormatOptions.value;
2226
- const cityOption = provinceOption[tmpSelectedIndex.value[0]].children;
2227
- const regionOption = cityOption[tmpSelectedIndex.value[1]].children;
2230
+ if (props.type === "province") {
2231
+ return [provinceOption];
2232
+ }
2233
+ const cityOption = provinceOption[tmpSelectedIndex.value[0]]?.children ?? [];
2234
+ if (props.type === "city") {
2235
+ return [provinceOption, cityOption];
2236
+ }
2237
+ const regionOption = cityOption[tmpSelectedIndex.value[1]]?.children ?? [];
2228
2238
  return [provinceOption, cityOption, regionOption];
2229
2239
  });
2230
2240
  function init() {
@@ -2232,8 +2242,8 @@ var script$2 = /* @__PURE__ */ defineComponent({
2232
2242
  tmpSelectedIndex.value = [...selectedIndex.value];
2233
2243
  if (props.value) {
2234
2244
  const items = [];
2235
- for (let index = 0; index < selectedIndex.value.length; index++) {
2236
- const item = options.value[index][selectedIndex.value[index]];
2245
+ for (let index = 0; index < options.value.length; index++) {
2246
+ const item = options.value[index]?.[selectedIndex.value[index]];
2237
2247
  if (item) {
2238
2248
  items.push(item);
2239
2249
  }
@@ -2268,15 +2278,17 @@ var script$2 = /* @__PURE__ */ defineComponent({
2268
2278
  return [0, 0, 0];
2269
2279
  }
2270
2280
  function onChange() {
2271
- const lastSelectedIndex = options.value[2].length ? 2 : 1;
2281
+ const lastSelectedIndex = options.value.length - 1;
2272
2282
  const result = {
2273
2283
  values: [],
2274
2284
  labels: []
2275
2285
  };
2276
2286
  for (let index = 0; index <= lastSelectedIndex; index++) {
2277
- const item = options.value[index][tmpSelectedIndex.value[index]];
2278
- result.values.push(item.value);
2279
- 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
+ }
2280
2292
  }
2281
2293
  emit("update:value", result.values[result.values.length - 1]);
2282
2294
  emit("change", result);
@@ -2724,6 +2736,7 @@ var script = /* @__PURE__ */ defineComponent({
2724
2736
  createVNode(script$2, {
2725
2737
  value: formState.areaCode,
2726
2738
  "onUpdate:value": _cache[6] || (_cache[6] = ($event) => formState.areaCode = $event),
2739
+ type: "city",
2727
2740
  placeholder: "\u8BF7\u9009\u62E9"
2728
2741
  }, null, 8, ["value"])
2729
2742
  ]),
@@ -2776,9 +2789,7 @@ const nutComponents = [
2776
2789
  const appComponents = {
2777
2790
  ...components
2778
2791
  };
2779
- const services = [
2780
- ...services$1
2781
- ];
2792
+ const services = [...services$1];
2782
2793
  const $app = {
2783
2794
  setToken: (token) => {
2784
2795
  const appKitOptions = useAppKitOptions();
@@ -2807,6 +2818,7 @@ const AppKit = {
2807
2818
  appKitOptions.token = options.token;
2808
2819
  appKitOptions.baseUrl = options.baseUrl;
2809
2820
  appKitOptions[401] = options[401];
2821
+ appKitOptions.gray = options.gray;
2810
2822
  nutComponents.forEach((component) => {
2811
2823
  app.use(component);
2812
2824
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxda/appkit",
3
- "version": "1.2.0",
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'
@@ -14,11 +14,14 @@ interface AreaItem {
14
14
  children: AreaItem[]
15
15
  }
16
16
 
17
- interface PropsType {
17
+ export type AreaType = 'province' | 'city' | 'region'
18
+
19
+ export interface PropsType {
18
20
  value?: string // 地址code
19
21
  rightIcon?: boolean
20
22
  placeholder?: string
21
23
  disabled?: boolean
24
+ type?: AreaType
22
25
  formatter?: (values: AreaItem[]) => string
23
26
  }
24
27
 
@@ -27,6 +30,7 @@ const props = withDefaults(defineProps<PropsType>(), {
27
30
  rightIcon: true,
28
31
  placeholder: '请选择',
29
32
  disabled: false,
33
+ type: 'region',
30
34
  formatter: (values: AreaItem[]) => values.map((item:AreaItem) => item.label).join('')
31
35
  })
32
36
  const emit = defineEmits(['update:value', 'change', 'cancel'])
@@ -81,18 +85,24 @@ const selectedItem = ref<AreaItem[]>([])
81
85
 
82
86
  const options = computed<AreaItem[][]>(() => {
83
87
  const provinceOption = areaFormatOptions.value
84
- const cityOption = provinceOption[tmpSelectedIndex.value[0]].children
85
- const regionOption = cityOption[tmpSelectedIndex.value[1]].children
88
+ if (props.type === 'province') {
89
+ return [provinceOption]
90
+ }
91
+ const cityOption = provinceOption[tmpSelectedIndex.value[0]]?.children ?? []
92
+ if (props.type === 'city') {
93
+ return [provinceOption, cityOption]
94
+ }
95
+ const regionOption = cityOption[tmpSelectedIndex.value[1]]?.children ?? []
86
96
  return [provinceOption, cityOption, regionOption]
87
97
  })
88
98
 
89
99
  function init() {
90
100
  selectedIndex.value = findIndexByValue()
91
101
  tmpSelectedIndex.value = [...selectedIndex.value]
92
- if (props.value){
102
+ if (props.value) {
93
103
  const items = []
94
- for (let index = 0; index < selectedIndex.value.length; index++) {
95
- const item = options.value[index][selectedIndex.value[index]]
104
+ for (let index = 0; index < options.value.length; index++) {
105
+ const item = options.value[index]?.[selectedIndex.value[index]]
96
106
  if (item){
97
107
  items.push(item)
98
108
  }
@@ -129,15 +139,17 @@ function findIndexByValue() {
129
139
  }
130
140
 
131
141
  function onChange() {
132
- const lastSelectedIndex = options.value[2].length ? 2 : 1
142
+ const lastSelectedIndex = options.value.length - 1
133
143
  const result = {
134
144
  values: [],
135
145
  labels: []
136
146
  }
137
147
  for (let index = 0; index <= lastSelectedIndex; index++) {
138
- const item = options.value[index][tmpSelectedIndex.value[index]]
139
- result.values.push(item.value)
140
- 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
+ }
141
153
  }
142
154
  emit('update:value', result.values[result.values.length-1])
143
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'
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
- import {reactive, ref} from 'vue'
2
+ import { reactive } from 'vue'
3
3
  import OcrId from './../../components/ocr-id/index.vue'
4
- import {OcrResultType} from './../../components/ocr-id/index.vue'
4
+ import { OcrResultType } from '../../components/ocr-id/types'
5
5
  import DdArea from './../../components/dd-area/index.vue'
6
6
  import DdSelector from './../../components/dd-selector/index.vue'
7
7
  import Taro from "@tarojs/taro";
@@ -144,6 +144,7 @@ async function submit() {
144
144
  <nut-form-item label="所在地区" required>
145
145
  <DdArea
146
146
  v-model:value="formState.areaCode"
147
+ type="city"
147
148
  placeholder="请选择"/>
148
149
  </nut-form-item>
149
150
  </template>