fix: 修复Search组件无法默认值
This commit is contained in:
parent
f37cc1b580
commit
3368fda251
|
@ -33,7 +33,11 @@ const props = defineProps({
|
||||||
expand: propTypes.bool.def(false),
|
expand: propTypes.bool.def(false),
|
||||||
// 伸缩的界限字段
|
// 伸缩的界限字段
|
||||||
expandField: propTypes.string.def(''),
|
expandField: propTypes.string.def(''),
|
||||||
inline: propTypes.bool.def(true)
|
inline: propTypes.bool.def(true),
|
||||||
|
model: {
|
||||||
|
type: Object as PropType<Recordable>,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['search', 'reset'])
|
const emit = defineEmits(['search', 'reset'])
|
||||||
|
@ -62,7 +66,9 @@ const newSchema = computed(() => {
|
||||||
return schema
|
return schema
|
||||||
})
|
})
|
||||||
|
|
||||||
const { register, elFormRef, methods } = useForm()
|
const { register, elFormRef, methods } = useForm({
|
||||||
|
model: props.model || {}
|
||||||
|
})
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
await unref(elFormRef)?.validate(async (isValid) => {
|
await unref(elFormRef)?.validate(async (isValid) => {
|
||||||
|
|
|
@ -41,6 +41,9 @@ export const useForm = (props?: FormProps) => {
|
||||||
setProps: async (props: FormProps = {}) => {
|
setProps: async (props: FormProps = {}) => {
|
||||||
const form = await getForm()
|
const form = await getForm()
|
||||||
form?.setProps(props)
|
form?.setProps(props)
|
||||||
|
if (props.model) {
|
||||||
|
form?.setValues(props.model)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setValues: async (data: Recordable) => {
|
setValues: async (data: Recordable) => {
|
||||||
|
|
|
@ -23,6 +23,8 @@ interface UseTableConfig<T = any> {
|
||||||
list: string
|
list: string
|
||||||
total?: string
|
total?: string
|
||||||
}
|
}
|
||||||
|
// 默认传递的参数
|
||||||
|
defaultParams?: Recordable
|
||||||
props?: TableProps
|
props?: TableProps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +49,9 @@ export const useTable = <T = any>(config?: UseTableConfig<T>) => {
|
||||||
// 表格数据
|
// 表格数据
|
||||||
tableList: [],
|
tableList: [],
|
||||||
// AxiosConfig 配置
|
// AxiosConfig 配置
|
||||||
params: {},
|
params: {
|
||||||
|
...(config?.defaultParams || {})
|
||||||
|
},
|
||||||
// 加载中
|
// 加载中
|
||||||
loading: true,
|
loading: true,
|
||||||
// 当前行的数据
|
// 当前行的数据
|
||||||
|
|
|
@ -31,7 +31,8 @@ const columns: TableColumn[] = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'display_time',
|
field: 'display_time',
|
||||||
label: t('tableDemo.displayTime')
|
label: t('tableDemo.displayTime'),
|
||||||
|
sortable: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'importance',
|
field: 'importance',
|
||||||
|
@ -90,7 +91,12 @@ const actionFn = (data: TableSlotDefault) => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ContentWrap :title="t('tableDemo.table')" :message="t('tableDemo.tableDes')">
|
<ContentWrap :title="t('tableDemo.table')" :message="t('tableDemo.tableDes')">
|
||||||
<Table :columns="columns" :data="tableDataList" :loading="loading">
|
<Table
|
||||||
|
:columns="columns"
|
||||||
|
:data="tableDataList"
|
||||||
|
:loading="loading"
|
||||||
|
:defaultSort="{ prop: 'display_time', order: 'descending' }"
|
||||||
|
>
|
||||||
<template #action="data">
|
<template #action="data">
|
||||||
<ElButton type="primary" @click="actionFn(data as TableSlotDefault)">
|
<ElButton type="primary" @click="actionFn(data as TableSlotDefault)">
|
||||||
{{ t('tableDemo.action') }}
|
{{ t('tableDemo.action') }}
|
||||||
|
|
|
@ -20,6 +20,9 @@ const { register, tableObject, methods } = useTable<TableData>({
|
||||||
response: {
|
response: {
|
||||||
list: 'list',
|
list: 'list',
|
||||||
total: 'total'
|
total: 'total'
|
||||||
|
},
|
||||||
|
defaultParams: {
|
||||||
|
title: 's'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -212,7 +215,12 @@ const save = async () => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ContentWrap>
|
<ContentWrap>
|
||||||
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
|
<Search
|
||||||
|
:model="{ title: 's' }"
|
||||||
|
:schema="allSchemas.searchSchema"
|
||||||
|
@search="setSearchParams"
|
||||||
|
@reset="setSearchParams"
|
||||||
|
/>
|
||||||
|
|
||||||
<div class="mb-10px">
|
<div class="mb-10px">
|
||||||
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
||||||
|
|
Loading…
Reference in New Issue