|
|
@@ -1,15 +1,20 @@
|
|
|
<template>
|
|
|
<a-form
|
|
|
- :label-col="{ span: 8 }"
|
|
|
- :wrapper-col="{ span: 16 }"
|
|
|
+
|
|
|
autocomplete="off"
|
|
|
- @finish="onFinish"
|
|
|
>
|
|
|
- <a-form-item
|
|
|
+ <!-- <a-form-item
|
|
|
v-for="item in modelRef"
|
|
|
:key="item.id"
|
|
|
+ :label="item.label"
|
|
|
+ name="7788"
|
|
|
+ v-bind="validateInfos[item.key]"
|
|
|
>
|
|
|
+ <a-input v-model:value="item[item.key]" />
|
|
|
+ </a-form-item> -->
|
|
|
|
|
|
+ <a-form-item label="测试title" v-bind="validateInfos.modelLabel">
|
|
|
+ <a-input v-model:value="modelRef.modelLabel" />
|
|
|
</a-form-item>
|
|
|
</a-form>
|
|
|
</template>
|
|
|
@@ -27,7 +32,8 @@ export interface FormItemProps {
|
|
|
rules?: {required: boolean, message: string} | boolean,
|
|
|
type: COMMON.COMPONENTS.ComType,
|
|
|
key: string,
|
|
|
- value?: any
|
|
|
+ value?: any,
|
|
|
+ label: string,
|
|
|
request?: () => {
|
|
|
id?: string,
|
|
|
name?: string,
|
|
|
@@ -55,34 +61,32 @@ const props: FormProProps = {
|
|
|
message: '此项为必填项'
|
|
|
},
|
|
|
type: 'input',
|
|
|
- key: 'modelLabel'
|
|
|
+ key: 'modelLabel',
|
|
|
+ label: '测试title'
|
|
|
}]
|
|
|
}
|
|
|
|
|
|
-const modelRef = reactive<Record<string, any>[]>([
|
|
|
- {
|
|
|
- name: '',
|
|
|
- region: undefined,
|
|
|
- type: []
|
|
|
- }
|
|
|
-])
|
|
|
+const modelRef = reactive<Record<string, any>>({
|
|
|
+ modelLabel: ''
|
|
|
+})
|
|
|
|
|
|
const rulesRef = reactive<Record<string, any>>({})
|
|
|
|
|
|
props.formProps.forEach(item => {
|
|
|
- rulesRef[item.key] = item.rules
|
|
|
- modelRef.push({ [item.key]: item.value, id: useId })
|
|
|
-})
|
|
|
-
|
|
|
-const emit = defineEmits(['onFinish'])
|
|
|
+ rulesRef[item.key] = [item.rules]
|
|
|
|
|
|
-const onFinish = () => emit('onFinish')
|
|
|
+ // modelRef.push({ ...item, [item.key]: item.value, id: useId, key: item.key })
|
|
|
+})
|
|
|
|
|
|
const { resetFields, validate, validateInfos } = useForm(modelRef, rulesRef, {
|
|
|
onValidate: (...args) => console.log(...args)
|
|
|
})
|
|
|
+console.log(rulesRef)
|
|
|
+console.log('validateInfos:', validateInfos)
|
|
|
|
|
|
const onSubmit = () => {
|
|
|
+ console.log('onSubmit')
|
|
|
+
|
|
|
validate()
|
|
|
.then(() => {
|
|
|
console.log(toRaw(modelRef))
|
|
|
@@ -92,6 +96,10 @@ const onSubmit = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+defineExpose({
|
|
|
+ onSubmit
|
|
|
+})
|
|
|
+
|
|
|
const reset = () => {
|
|
|
// resetFields
|
|
|
}
|