1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
| import type { SystemDictTypeApi } from '#/api/system/dict/type';
|
| import { onMounted, ref } from 'vue';
|
| import { buildUUID, cloneDeep } from '@vben/utils';
|
| import { getSimpleDictTypeList } from '#/api/system/dict/type';
| import {
| localeProps,
| makeRequiredRule,
| } from '#/components/form-create/helpers';
| import { selectRule } from '#/components/form-create/rules/data';
|
| /** 字典选择器规则,如果规则使用到动态数据则需要单独配置不能使用 useSelectRule */
| export function useDictSelectRule() {
| const label = '字典选择器';
| const name = 'DictSelect';
| const rules = cloneDeep(selectRule);
| const dictOptions = ref<{ label: string; value: string }[]>([]); // 字典类型下拉数据
| onMounted(async () => {
| const data = await getSimpleDictTypeList();
| if (!data || data.length === 0) {
| return;
| }
| dictOptions.value =
| data?.map((item: SystemDictTypeApi.DictType) => ({
| label: item.name,
| value: item.type,
| })) ?? [];
| });
| return {
| icon: 'icon-descriptions',
| label,
| name,
| rule() {
| return {
| type: name,
| field: buildUUID(),
| title: label,
| info: '',
| $required: false,
| modelField: 'value', // Ant Design Vue 组件使用 value;web-ele 自定义组件使用默认 modelValue
| };
| },
| props(_: any, { t }: any) {
| return localeProps(t, `${name}.props`, [
| makeRequiredRule(),
| {
| type: 'select',
| field: 'dictType',
| title: '字典类型',
| value: '',
| options: dictOptions.value,
| },
| {
| type: 'select',
| field: 'valueType',
| title: '字典值类型',
| value: 'str',
| options: [
| { label: '数字', value: 'int' },
| { label: '字符串', value: 'str' },
| { label: '布尔值', value: 'bool' },
| ],
| },
| ...rules,
| ]);
| },
| };
| }
|
|