ECG/src/components/FormCreate/src/config/useSelectRule.ts

34 lines
858 B
TypeScript
Raw Normal View History

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'
/**
* hook
* @param option
*/
export const useSelectRule = (option: SelectRuleOption) => {
const label = option.label
const name = option.name
return {
2024-05-06 02:12:09 +08:00
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, ...selectRule])
}
}
}