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
| import { generateUUID } from '@/utils'
| import { localeProps, makeRequiredRule } from '@/components/FormCreate/src/utils'
| import { selectRule } from '@/components/FormCreate/src/config/selectRule'
| import { SelectRuleOption } from '@/components/FormCreate/src/type'
| import { cloneDeep } from 'lodash-es'
|
| /**
| * 通用选择器规则 hook
| *
| * @param option 规则配置
| */
| export const useSelectRule = (option: SelectRuleOption) => {
| const label = option.label
| const name = option.name
| const rules = cloneDeep(selectRule)
| return {
| icon: option.icon,
| label,
| name,
| rule() {
| return {
| type: name,
| field: generateUUID(),
| title: label,
| info: '',
| $required: false
| }
| },
| props(_, { t }) {
| if (!option.props) {
| option.props = []
| }
| return localeProps(t, name + '.props', [makeRequiredRule(), ...option.props, ...rules])
| }
| }
| }
|
|