|
@@ -1,8 +1,9 @@
|
|
<script lang="tsx">
|
|
<script lang="tsx">
|
|
|
|
+ import { type Recordable, type Nullable } from '@vben/types';
|
|
import type { PropType, Ref } from 'vue';
|
|
import type { PropType, Ref } from 'vue';
|
|
import { computed, defineComponent, toRefs, unref } from 'vue';
|
|
import { computed, defineComponent, toRefs, unref } from 'vue';
|
|
import type { FormActionType, FormProps, FormSchema } from '../types/form';
|
|
import type { FormActionType, FormProps, FormSchema } from '../types/form';
|
|
- import type { Rule } from 'ant-design-vue/lib/form';
|
|
|
|
|
|
+ import type { ValidationRule } from 'ant-design-vue/lib/form/Form';
|
|
import type { TableActionType } from '/@/components/Table';
|
|
import type { TableActionType } from '/@/components/Table';
|
|
import { Col, Divider, Form } from 'ant-design-vue';
|
|
import { Col, Divider, Form } from 'ant-design-vue';
|
|
import { componentMap } from '../componentMap';
|
|
import { componentMap } from '../componentMap';
|
|
@@ -31,11 +32,11 @@
|
|
default: () => ({}),
|
|
default: () => ({}),
|
|
},
|
|
},
|
|
allDefaultValues: {
|
|
allDefaultValues: {
|
|
- type: Object as PropType<Recordable>,
|
|
|
|
|
|
+ type: Object as PropType<Recordable<any>>,
|
|
default: () => ({}),
|
|
default: () => ({}),
|
|
},
|
|
},
|
|
formModel: {
|
|
formModel: {
|
|
- type: Object as PropType<Recordable>,
|
|
|
|
|
|
+ type: Object as PropType<Recordable<any>>,
|
|
default: () => ({}),
|
|
default: () => ({}),
|
|
},
|
|
},
|
|
setFormModel: {
|
|
setFormModel: {
|
|
@@ -72,7 +73,7 @@
|
|
...mergeDynamicData,
|
|
...mergeDynamicData,
|
|
...allDefaultValues,
|
|
...allDefaultValues,
|
|
...formModel,
|
|
...formModel,
|
|
- } as Recordable,
|
|
|
|
|
|
+ } as Recordable<any>,
|
|
schema: schema,
|
|
schema: schema,
|
|
};
|
|
};
|
|
});
|
|
});
|
|
@@ -93,7 +94,7 @@
|
|
componentProps,
|
|
componentProps,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
- return componentProps as Recordable;
|
|
|
|
|
|
+ return componentProps as Recordable<any>;
|
|
});
|
|
});
|
|
|
|
|
|
const getDisable = computed(() => {
|
|
const getDisable = computed(() => {
|
|
@@ -138,7 +139,7 @@
|
|
return { isShow, isIfShow };
|
|
return { isShow, isIfShow };
|
|
}
|
|
}
|
|
|
|
|
|
- function handleRules(): Rule[] {
|
|
|
|
|
|
+ function handleRules(): ValidationRule[] {
|
|
const {
|
|
const {
|
|
rules: defRules = [],
|
|
rules: defRules = [],
|
|
component,
|
|
component,
|
|
@@ -149,10 +150,10 @@
|
|
} = props.schema;
|
|
} = props.schema;
|
|
|
|
|
|
if (isFunction(dynamicRules)) {
|
|
if (isFunction(dynamicRules)) {
|
|
- return dynamicRules(unref(getValues)) as Rule[];
|
|
|
|
|
|
+ return dynamicRules(unref(getValues)) as ValidationRule[];
|
|
}
|
|
}
|
|
|
|
|
|
- let rules: Rule[] = cloneDeep(defRules) as Rule[];
|
|
|
|
|
|
+ let rules: ValidationRule[] = cloneDeep(defRules) as ValidationRule[];
|
|
const { rulesMessageJoinLabel: globalRulesMessageJoinLabel } = props.formProps;
|
|
const { rulesMessageJoinLabel: globalRulesMessageJoinLabel } = props.formProps;
|
|
|
|
|
|
const joinLabel = Reflect.has(props.schema, 'rulesMessageJoinLabel')
|
|
const joinLabel = Reflect.has(props.schema, 'rulesMessageJoinLabel')
|
|
@@ -235,7 +236,7 @@
|
|
if (characterInx !== -1 && !rules[characterInx].validator) {
|
|
if (characterInx !== -1 && !rules[characterInx].validator) {
|
|
rules[characterInx].message =
|
|
rules[characterInx].message =
|
|
rules[characterInx].message ||
|
|
rules[characterInx].message ||
|
|
- t('component.form.maxTip', [rules[characterInx].max] as Recordable);
|
|
|
|
|
|
+ t('component.form.maxTip', [rules[characterInx].max] as Recordable<any>);
|
|
}
|
|
}
|
|
return rules;
|
|
return rules;
|
|
}
|
|
}
|
|
@@ -254,7 +255,7 @@
|
|
const eventKey = `on${upperFirst(changeEvent)}`;
|
|
const eventKey = `on${upperFirst(changeEvent)}`;
|
|
|
|
|
|
const on = {
|
|
const on = {
|
|
- [eventKey]: (...args: Nullable<Recordable>[]) => {
|
|
|
|
|
|
+ [eventKey]: (...args: Nullable<Recordable<any>>[]) => {
|
|
const [e] = args;
|
|
const [e] = args;
|
|
if (propsData[eventKey]) {
|
|
if (propsData[eventKey]) {
|
|
propsData[eventKey](...args);
|
|
propsData[eventKey](...args);
|
|
@@ -267,7 +268,7 @@
|
|
const Comp = componentMap.get(component) as ReturnType<typeof defineComponent>;
|
|
const Comp = componentMap.get(component) as ReturnType<typeof defineComponent>;
|
|
|
|
|
|
const { autoSetPlaceHolder, size } = props.formProps;
|
|
const { autoSetPlaceHolder, size } = props.formProps;
|
|
- const propsData: Recordable = {
|
|
|
|
|
|
+ const propsData: Recordable<any> = {
|
|
allowClear: true,
|
|
allowClear: true,
|
|
getPopupContainer: (trigger: Element) => trigger.parentNode,
|
|
getPopupContainer: (trigger: Element) => trigger.parentNode,
|
|
size,
|
|
size,
|
|
@@ -284,11 +285,11 @@
|
|
propsData.codeField = field;
|
|
propsData.codeField = field;
|
|
propsData.formValues = unref(getValues);
|
|
propsData.formValues = unref(getValues);
|
|
|
|
|
|
- const bindValue: Recordable = {
|
|
|
|
|
|
+ const bindValue: Recordable<any> = {
|
|
[valueField || (isCheck ? 'checked' : 'value')]: props.formModel[field],
|
|
[valueField || (isCheck ? 'checked' : 'value')]: props.formModel[field],
|
|
};
|
|
};
|
|
|
|
|
|
- const compAttr: Recordable = {
|
|
|
|
|
|
+ const compAttr: Recordable<any> = {
|
|
...propsData,
|
|
...propsData,
|
|
...on,
|
|
...on,
|
|
...bindValue,
|
|
...bindValue,
|
|
@@ -365,7 +366,7 @@
|
|
name={field}
|
|
name={field}
|
|
colon={colon}
|
|
colon={colon}
|
|
class={{ 'suffix-item': showSuffix }}
|
|
class={{ 'suffix-item': showSuffix }}
|
|
- {...(itemProps as Recordable)}
|
|
|
|
|
|
+ {...(itemProps as Recordable<any>)}
|
|
label={renderLabelHelpMessage()}
|
|
label={renderLabelHelpMessage()}
|
|
rules={handleRules()}
|
|
rules={handleRules()}
|
|
labelCol={labelCol}
|
|
labelCol={labelCol}
|