提交 | 用户 | 时间
|
820397
|
1 |
import { generateUUID } from '@/utils' |
H |
2 |
import * as DictDataApi from '@/api/system/dict/dict.type' |
|
3 |
import { localeProps, makeRequiredRule } from '@/components/FormCreate/src/utils' |
|
4 |
import { selectRule } from '@/components/FormCreate/src/config/selectRule' |
|
5 |
import { cloneDeep } from 'lodash-es' |
|
6 |
|
|
7 |
/** |
|
8 |
* 字典选择器规则,如果规则使用到动态数据则需要单独配置不能使用 useSelectRule |
|
9 |
*/ |
|
10 |
export const useDictSelectRule = () => { |
|
11 |
const label = '字典选择器' |
|
12 |
const name = 'DictSelect' |
|
13 |
const rules = cloneDeep(selectRule) |
|
14 |
const dictOptions = ref<{ label: string; value: string }[]>([]) // 字典类型下拉数据 |
|
15 |
onMounted(async () => { |
|
16 |
const data = await DictDataApi.getSimpleDictTypeList() |
|
17 |
if (!data || data.length === 0) { |
|
18 |
return |
|
19 |
} |
|
20 |
dictOptions.value = |
|
21 |
data?.map((item: DictDataApi.DictTypeVO) => ({ |
|
22 |
label: item.name, |
|
23 |
value: item.type |
|
24 |
})) ?? [] |
|
25 |
}) |
|
26 |
return { |
|
27 |
icon: 'icon-doc-text', |
|
28 |
label, |
|
29 |
name, |
|
30 |
rule() { |
|
31 |
return { |
|
32 |
type: name, |
|
33 |
field: generateUUID(), |
|
34 |
title: label, |
|
35 |
info: '', |
|
36 |
$required: false |
|
37 |
} |
|
38 |
}, |
|
39 |
props(_, { t }) { |
|
40 |
return localeProps(t, name + '.props', [ |
|
41 |
makeRequiredRule(), |
|
42 |
{ |
|
43 |
type: 'select', |
|
44 |
field: 'dictType', |
|
45 |
title: '字典类型', |
|
46 |
value: '', |
|
47 |
options: dictOptions.value |
|
48 |
}, |
|
49 |
{ |
|
50 |
type: 'select', |
3e359e
|
51 |
field: 'valueType', |
820397
|
52 |
title: '字典值类型', |
H |
53 |
value: 'str', |
|
54 |
options: [ |
|
55 |
{ label: '数字', value: 'int' }, |
|
56 |
{ label: '字符串', value: 'str' }, |
|
57 |
{ label: '布尔值', value: 'bool' } |
|
58 |
] |
|
59 |
}, |
|
60 |
...rules |
|
61 |
]) |
|
62 |
} |
|
63 |
} |
|
64 |
} |