d-render
Version:
基于 Element Plus 二次封装的数据驱动渲染组件库 - 表单、搜索表单、表格配置化渲染
30 lines (29 loc) • 977 B
text/typescript
import { computed, ComputedRef } from 'vue'
import type { Ref } from 'vue'
import { getRulesByFieldConfig } from '../form-item-rules'
import type { IAnyObject, TFormConfig } from '@d-render/shared'
import type { Translator } from '../../locale'
export const useRules = (
config: ComputedRef<TFormConfig>,
isReadonly: Ref<boolean>,
status: ComputedRef<'read'|'read-write'|'hidden'>,
otherValue: ComputedRef<unknown>,
dependOnValues: Ref<IAnyObject>,
outDependOnValues: Ref<IAnyObject>,
t?: Translator
) => {
const usingRules = computed(() => {
return !(isReadonly.value || config.value.disabled || config.value._isShow === false || status.value !== 'read-write')
})
const rules = computed(() => {
if (usingRules.value) {
return getRulesByFieldConfig(config.value, otherValue.value, dependOnValues.value, outDependOnValues.value, t)
} else {
return []
}
})
return {
usingRules,
rules
}
}