Merge branch 'develop'

This commit is contained in:
kailong321200875 2022-11-21 16:13:49 +08:00
commit a47c054f2c
5 changed files with 33 additions and 6 deletions

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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,
// 当前行的数据 // 当前行的数据

View File

@ -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') }}

View File

@ -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>