提交 | 用户 | 时间
|
820397
|
1 |
import { generateUUID } from '@/utils' |
H |
2 |
import { localeProps, makeRequiredRule } from '@/components/FormCreate/src/utils' |
|
3 |
import { selectRule } from '@/components/FormCreate/src/config/selectRule' |
|
4 |
import { SelectRuleOption } from '@/components/FormCreate/src/type' |
|
5 |
import { cloneDeep } from 'lodash-es' |
|
6 |
|
|
7 |
/** |
|
8 |
* 通用选择器规则 hook |
|
9 |
* |
|
10 |
* @param option 规则配置 |
|
11 |
*/ |
|
12 |
export const useSelectRule = (option: SelectRuleOption) => { |
|
13 |
const label = option.label |
|
14 |
const name = option.name |
|
15 |
const rules = cloneDeep(selectRule) |
|
16 |
return { |
|
17 |
icon: option.icon, |
|
18 |
label, |
|
19 |
name, |
|
20 |
rule() { |
|
21 |
return { |
|
22 |
type: name, |
|
23 |
field: generateUUID(), |
|
24 |
title: label, |
|
25 |
info: '', |
|
26 |
$required: false |
|
27 |
} |
|
28 |
}, |
|
29 |
props(_, { t }) { |
|
30 |
if (!option.props) { |
|
31 |
option.props = [] |
|
32 |
} |
|
33 |
return localeProps(t, name + '.props', [makeRequiredRule(), ...option.props, ...rules]) |
|
34 |
} |
|
35 |
} |
|
36 |
} |