@tmagic/form 1.4.1 → 1.4.3

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.
@@ -19,25 +19,63 @@
19
19
  @change="changeHandler"
20
20
  @visible-change="visibleHandler"
21
21
  >
22
- <template v-if="config.group"><SelectOptionGroups :options="groupOptions"></SelectOptionGroups></template>
23
- <template v-else><SelectOptions :options="itemOptions"></SelectOptions></template>
22
+ <template v-if="config.group">
23
+ <component
24
+ v-for="(group, index) in (options as SelectGroupOption[])"
25
+ :key="index"
26
+ :is="optionGroupComponent?.component"
27
+ v-bind="
28
+ optionGroupComponent?.props({
29
+ label: group.label,
30
+ disabled: group.disabled,
31
+ })
32
+ "
33
+ >
34
+ <component
35
+ v-for="(item, index) in group.options"
36
+ :is="optionComponent?.component"
37
+ :key="index"
38
+ v-bind="
39
+ optionComponent?.props({
40
+ label: item.label || item.text,
41
+ value: item.value,
42
+ disabled: item.disabled,
43
+ })
44
+ "
45
+ >
46
+ </component>
47
+ </component>
48
+ </template>
49
+ <template v-else>
50
+ <component
51
+ v-for="option in (options as SelectOption[])"
52
+ class="tmagic-design-option"
53
+ :key="config.valueKey ? option.value[config.valueKey] : option.value"
54
+ :is="optionComponent?.component"
55
+ v-bind="
56
+ optionComponent?.props({
57
+ label: option.text,
58
+ value: option.value,
59
+ disabled: option.disabled,
60
+ })
61
+ "
62
+ >
63
+ </component>
64
+ </template>
24
65
  <div v-loading="true" v-if="moreLoadingVisible"></div>
25
66
  </TMagicSelect>
26
67
  </template>
27
68
 
28
69
  <script lang="ts" setup>
29
- import { inject, nextTick, onBeforeMount, Ref, ref, watch, watchEffect } from 'vue';
70
+ import { inject, nextTick, onBeforeMount, ref, watch, watchEffect } from 'vue';
30
71
 
31
- import { TMagicSelect } from '@tmagic/design';
72
+ import { getConfig as getDesignConfig, TMagicSelect } from '@tmagic/design';
32
73
  import { getValueByKeyPath } from '@tmagic/utils';
33
74
 
34
75
  import type { FieldProps, FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
35
76
  import { getConfig } from '../utils/config';
36
77
  import { useAddField } from '../utils/useAddField';
37
78
 
38
- import SelectOptionGroups from './SelectOptionGroups.vue';
39
- import SelectOptions from './SelectOptions.vue';
40
-
41
79
  defineOptions({
42
80
  name: 'MFormSelect',
43
81
  });
@@ -46,6 +84,9 @@ const props = defineProps<FieldProps<SelectConfig>>();
46
84
 
47
85
  const emit = defineEmits(['change']);
48
86
 
87
+ const optionComponent = getDesignConfig('components')?.option;
88
+ const optionGroupComponent = getDesignConfig('components')?.optionGroup;
89
+
49
90
  if (!props.model) throw new Error('不能没有model');
50
91
  useAddField(props.prop);
51
92
 
@@ -394,7 +435,4 @@ const remoteMethod = async (q: string) => {
394
435
  }, 0);
395
436
  }
396
437
  };
397
-
398
- const itemOptions = options as Ref<SelectOption[]>;
399
- const groupOptions = options as Ref<SelectGroupOption[]>;
400
438
  </script>
@@ -1,29 +0,0 @@
1
- <template>
2
- <TMagicOptionGroup v-for="(group, index) in options" :key="index" :label="group.label" :disabled="group.disabled">
3
- <component
4
- v-for="(item, index) in group.options"
5
- :is="uiComponent"
6
- :key="index"
7
- :label="item.label || item.text"
8
- :value="item.value"
9
- :disabled="item.disabled"
10
- >
11
- </component>
12
- </TMagicOptionGroup>
13
- </template>
14
-
15
- <script lang="ts" setup>
16
- import { getConfig, TMagicOptionGroup } from '@tmagic/design';
17
-
18
- import { SelectGroupOption } from '../schema';
19
-
20
- defineOptions({
21
- name: 'MFormSelectOptionGroups',
22
- });
23
-
24
- defineProps<{
25
- options: SelectGroupOption[];
26
- }>();
27
-
28
- const uiComponent = getConfig('components')?.option.component || 'el-option';
29
- </script>
@@ -1,24 +0,0 @@
1
- <template>
2
- <TMagicOption
3
- v-for="option in options"
4
- :label="option.text"
5
- :value="option.value"
6
- :key="valueKey ? option.value[valueKey] : option.value"
7
- :disabled="option.disabled"
8
- ></TMagicOption>
9
- </template>
10
-
11
- <script lang="ts" setup>
12
- import { TMagicOption } from '@tmagic/design';
13
-
14
- import { SelectOption } from '../schema';
15
-
16
- defineOptions({
17
- name: 'MFormSelectOptions',
18
- });
19
-
20
- defineProps<{
21
- options: SelectOption[];
22
- valueKey?: string;
23
- }>();
24
- </script>
@@ -1,16 +0,0 @@
1
- import { SelectGroupOption } from '../schema';
2
- declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<{
3
- options: SelectGroupOption[];
4
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<{
5
- options: SelectGroupOption[];
6
- }>>>, {}, {}>;
7
- export default _default;
8
- type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
9
- type __VLS_TypePropsToOption<T> = {
10
- [K in keyof T]-?: {} extends Pick<T, K> ? {
11
- type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
12
- } : {
13
- type: import('vue').PropType<T[K]>;
14
- required: true;
15
- };
16
- };
@@ -1,18 +0,0 @@
1
- import { SelectOption } from '../schema';
2
- declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<{
3
- options: SelectOption[];
4
- valueKey?: string | undefined;
5
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<{
6
- options: SelectOption[];
7
- valueKey?: string | undefined;
8
- }>>>, {}, {}>;
9
- export default _default;
10
- type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
11
- type __VLS_TypePropsToOption<T> = {
12
- [K in keyof T]-?: {} extends Pick<T, K> ? {
13
- type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
14
- } : {
15
- type: import('vue').PropType<T[K]>;
16
- required: true;
17
- };
18
- };