| | |
| | | import type { ValidationRule } from 'ant-design-vue/lib/form/Form'; |
| | | import type { ComponentType } from './types/index'; |
| | | import { useI18n } from '/@/hooks/web/useI18n'; |
| | | import { dateUtil } from '/@/utils/dateUtil'; |
| | | import { isNumber, isObject } from '/@/utils/is'; |
| | | import type { Rule as ValidationRule } from 'ant-design-vue/lib/form/interface'; |
| | | import type { ComponentType } from './types'; |
| | | import { useI18n } from '@/hooks/web/useI18n'; |
| | | import { dateUtil } from '@/utils/dateUtil'; |
| | | import { isObject } from '@/utils/is'; |
| | | |
| | | const { t } = useI18n(); |
| | | |
| | |
| | | |
| | | const DATE_TYPE = ['DatePicker', 'MonthPicker', 'WeekPicker', 'TimePicker']; |
| | | |
| | | /** |
| | | * 上传组件 |
| | | */ |
| | | export const uploadItemType: ComponentType[] = [ |
| | | 'Upload', |
| | | 'ImageUpload' |
| | | ]; |
| | | |
| | | |
| | | function genType() { |
| | | return [...DATE_TYPE, 'RangePicker']; |
| | | return [...DATE_TYPE, 'RangePicker',"TimeRangePicker"]; |
| | | } |
| | | |
| | | export function setComponentRuleType( |
| | |
| | | component: ComponentType, |
| | | valueFormat: string, |
| | | ) { |
| | | if (Reflect.has(rule, 'type')) { |
| | | return; |
| | | } |
| | | if (['DatePicker', 'MonthPicker', 'WeekPicker', 'TimePicker'].includes(component)) { |
| | | rule.type = valueFormat ? 'string' : 'object'; |
| | | } else if (['RangePicker', 'Upload', 'CheckboxGroup', 'TimePicker'].includes(component)) { |
| | | } else if (['RangePicker', 'CheckboxGroup'].includes(component)) { |
| | | rule.type = 'array'; |
| | | } else if (['InputNumber'].includes(component)) { |
| | | rule.type = 'number'; |
| | |
| | | export function processDateValue(attr: Recordable, component: string) { |
| | | const { valueFormat, value } = attr; |
| | | if (valueFormat) { |
| | | attr.value = isObject(value) ? dateUtil(value).format(valueFormat) : value; |
| | | attr.value = isObject(value) ? dateUtil(value as unknown as Date).format(valueFormat) : value; |
| | | } else if (DATE_TYPE.includes(component) && value) { |
| | | attr.value = dateUtil(attr.value); |
| | | } |
| | | } |
| | | |
| | | export function handleInputNumberValue(component?: ComponentType, val?: any) { |
| | | if (!component) return val; |
| | | if (['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(component)) { |
| | | return val && isNumber(val) ? `${val}` : val; |
| | | } |
| | | return val; |
| | | } |
| | | export const defaultValueComponents = [ |
| | | 'Input', |
| | | 'InputPassword', |
| | | 'InputNumber', |
| | | 'InputSearch', |
| | | 'InputTextArea', |
| | | ]; |
| | | |
| | | /** |
| | | * 时间字段 |
| | | */ |
| | | export const dateItemType = genType(); |
| | | |
| | | export const defaultValueComponents = ['Input', 'InputPassword', 'InputSearch', 'InputTextArea']; |
| | | |
| | | // TODO 自定义组件封装会出现验证问题,因此这里目前改成手动触发验证 |
| | | export const NO_AUTO_LINK_COMPONENTS: ComponentType[] = [ |
| | | 'Upload', |
| | | 'ApiTransfer', |
| | | 'ApiTree', |
| | | 'ApiSelect', |
| | | 'ApiTreeSelect', |
| | | 'ApiRadioGroup', |
| | | 'ApiCascader', |
| | | 'AutoComplete', |
| | | 'RadioButtonGroup', |
| | | 'ImageUpload', |
| | | 'ApiSelect', |
| | | ]; |
| | | |
| | | export const simpleComponents = ['Divider', 'BasicTitle']; |
| | | |
| | | export function isIncludeSimpleComponents(component?: ComponentType) { |
| | | return simpleComponents.includes(component || ''); |
| | | } |