XQueryForm 查询表单
示例
基础用法
<template>
<div>
<XQueryForm ref="formRef" size="default" :model="model" :items="items">
<template #custom>
<XField label="自定义"></XField>
</template>
</XQueryForm>
<XAction @click="onClick" label="提交"></XAction>
</div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { XQueryForm, XAction, XField, type QueryFormItems } from '@vtj/ui';
const formRef = ref();
const model = reactive({
F1: 'abc'
});
const items: QueryFormItems = [
{
label: '姓名',
name: 'name',
required: true,
editor: 'select',
options: [
{
label: '选项一',
value: 1
}
]
},
{
label: '年龄',
name: 'age',
required: true
},
'custom'
];
const onClick = () => {
formRef.value.submit();
};
</script>
行内用法
<template>
<div>
<XQueryForm
ref="formRef"
size="default"
:model="model"
:items="items"
:inlineColumns="1">
<template #custom>
<XField label="自定义"></XField>
</template>
</XQueryForm>
<XQueryForm
ref="formRef"
size="default"
:model="model"
:items="items"
:collapsible="false"
:inline="true">
<template #custom>
<XField label="自定义"></XField>
</template>
</XQueryForm>
<XQueryForm
ref="formRef"
size="default"
:model="model"
:items="items"
:collapsible="false"
:inline="false">
<template #custom>
<XField label="自定义"></XField>
</template>
</XQueryForm>
</div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { XQueryForm, XField, type QueryFormItems } from '@vtj/ui';
const formRef = ref();
const model = reactive({
F1: 'abc'
});
const items: QueryFormItems = [
{
label: '姓名',
name: 'name',
required: true,
editor: 'select',
options: [
{
label: '选项一',
value: 1
}
]
},
{
label: '年龄',
name: 'age',
required: true
},
'custom'
];
const onClick = () => {
formRef.value.submit();
};
</script>
表单验证
<template>
<div>
<XQueryForm
ref="formRef"
size="default"
:model="model"
:items="items"
:inlineColumns="1"
:rules="rules">
<template #custom>
<XField name="custom" required label="自定义"></XField>
</template>
</XQueryForm>
</div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { XQueryForm, XField, type QueryFormItems } from '@vtj/ui';
const formRef = ref();
const model = reactive({
F1: 'abc'
});
const items: QueryFormItems = [
{
label: '姓名',
name: 'name',
required: true,
editor: 'select',
options: [
{
label: '选项一',
value: 1
}
]
},
{
label: '年龄',
name: 'age'
},
'custom'
];
const validateCustom = (rule: any, value: any, callback: any) => {
if (value === '') {
callback(new Error('Please input the custom'));
} else {
callback();
}
};
const rules = reactive({
name: [
{
required: true,
message: 'Please input name',
trigger: ['blur', 'change']
}
],
age: [
{
required: true,
message: 'Please input name',
trigger: ['blur', 'change']
}
],
custom: [{ validator: validateCustom, trigger: 'blur' }]
});
</script>
按钮
<template>
<div>
<XAction
label="showFooter"
type="primary"
@click="showFooter = !showFooter">
</XAction>
<XQueryForm
ref="formRef"
size="default"
:model="model"
:items="items"
:inlineColumns="1"
:rules="rules"
:submitMethod="onSubmitMethod"
submitText="提交"
resetText="重置">
<template #custom>
<XField name="custom" required label="自定义"></XField>
</template>
</XQueryForm>
<XQueryForm
ref="formRef"
size="default"
:model="model"
:items="items"
:inlineColumns="1"
:rules="rules"
:submitMethod="onSubmitMethod"
:footer="showFooter"
submitText="提交"
resetText="重置">
<template #custom>
<XField name="custom" required label="自定义"></XField>
</template>
</XQueryForm>
</div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { XQueryForm, XField, XAction, type QueryFormItems } from '@vtj/ui';
const formRef = ref();
const model = reactive({
F1: 'abc'
});
const showFooter = ref(false);
const items: QueryFormItems = [
{
label: '姓名',
name: 'name',
required: true,
editor: 'select',
options: [
{
label: '选项一',
value: 1
}
]
},
{
label: '年龄',
name: 'age'
},
'custom'
];
const validateCustom = (rule: any, value: any, callback: any) => {
if (value === '') {
callback(new Error('Please input the custom'));
} else {
callback();
}
};
const rules = reactive({
name: [
{
required: true,
message: 'Please input name',
trigger: ['blur', 'change']
}
],
age: [
{
required: true,
message: 'Please input name',
trigger: ['blur', 'change']
}
],
custom: [{ validator: validateCustom, trigger: 'blur' }]
});
const onSubmitMethod = (model: any) => {
console.log('onSubmitMethod', model);
};
</script>
API
属性
属性名 | 说明 | 类型 | 默认值 |
---|---|---|---|
collapsible | 是否折叠面板 | boolean | true |
items | 表单中的项 | array | - |
inlineColumns | inline模式显示列数 | number | - |
inline | 行内表单模式 | boolean | false |
model | 表单数据对象 | object | - |
footer | 显示底部按钮 | boolean | false |
submitText | 提交按钮文本 | string | 提交 |
resetText | 重置按钮文本 | string | 重置 |
submitMethod | 表单提交处理方法 | function | - |
tooltipMessage | 是否在tooltip显示校验信息 | boolean | false |
label | 标签 | string | - |
label-width | 标签宽度 | string | number | - |
required | 是否必填 | boolean | false |
rules | 校验规则 | object | - |
error | 错误信息 | string | - |
show-message | 是否显示校验错误信息 | boolean | true |
inline-message | 是否以行内形式展示校验信息 | boolean | false |
size | 用于控制该表单内组件的尺寸 | string | default |
接收 ElForm 的所有属性
插槽
插槽名 | 说明 | 类型 |
---|---|---|
custom | 自定义内容 | - |
暴露
名称 | 说明 | 类型 |
---|---|---|
validate | 校验方法 | |
submit | - | |
reset | - | |
formRef | - | |
$vtjDynamicSlots | - |