mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 02:00:25 +08:00
feat(BasicTable): 新增表格搜索获取参数的方法 (#3715)
* feat(BasicTable): 新增表格搜索获取参数的方法 * feat(BasicTable): 新增表格搜索获取参数的方法 * feat(BasicTable): 新增表格搜索获取参数的方法 * feat(BasicTable): 新增表格搜索获取参数的方法
This commit is contained in:
parent
38d58ab47a
commit
de5f9e3047
@ -144,6 +144,7 @@
|
|||||||
getDataSourceRef,
|
getDataSourceRef,
|
||||||
getDataSource,
|
getDataSource,
|
||||||
getRawDataSource,
|
getRawDataSource,
|
||||||
|
getSearchInfo,
|
||||||
setTableData,
|
setTableData,
|
||||||
updateTableDataRecord,
|
updateTableDataRecord,
|
||||||
deleteTableDataRecord,
|
deleteTableDataRecord,
|
||||||
@ -300,6 +301,7 @@
|
|||||||
setLoading,
|
setLoading,
|
||||||
getDataSource,
|
getDataSource,
|
||||||
getRawDataSource,
|
getRawDataSource,
|
||||||
|
getSearchInfo,
|
||||||
setProps,
|
setProps,
|
||||||
getRowSelection,
|
getRowSelection,
|
||||||
getPaginationRef: getPagination,
|
getPaginationRef: getPagination,
|
||||||
|
@ -50,6 +50,7 @@ export function useDataSource(
|
|||||||
});
|
});
|
||||||
const dataSourceRef = ref<Recordable[]>([]);
|
const dataSourceRef = ref<Recordable[]>([]);
|
||||||
const rawDataSourceRef = ref<Recordable>({});
|
const rawDataSourceRef = ref<Recordable>({});
|
||||||
|
const searchInfoRef = ref<Recordable>({});
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
tableData.value = unref(dataSourceRef);
|
tableData.value = unref(dataSourceRef);
|
||||||
@ -275,7 +276,7 @@ export function useDataSource(
|
|||||||
if (beforeFetch && isFunction(beforeFetch)) {
|
if (beforeFetch && isFunction(beforeFetch)) {
|
||||||
params = (await beforeFetch(params)) || params;
|
params = (await beforeFetch(params)) || params;
|
||||||
}
|
}
|
||||||
|
searchInfoRef.value = params;
|
||||||
const res = await api(params);
|
const res = await api(params);
|
||||||
rawDataSourceRef.value = res;
|
rawDataSourceRef.value = res;
|
||||||
|
|
||||||
@ -339,6 +340,10 @@ export function useDataSource(
|
|||||||
return await fetch(opt);
|
return await fetch(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSearchInfo<T = Recordable>() {
|
||||||
|
return searchInfoRef.value as T;
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
useTimeoutFn(() => {
|
useTimeoutFn(() => {
|
||||||
unref(propsRef).immediate && fetch();
|
unref(propsRef).immediate && fetch();
|
||||||
@ -349,6 +354,8 @@ export function useDataSource(
|
|||||||
getDataSourceRef,
|
getDataSourceRef,
|
||||||
getDataSource,
|
getDataSource,
|
||||||
getRawDataSource,
|
getRawDataSource,
|
||||||
|
searchInfoRef,
|
||||||
|
getSearchInfo,
|
||||||
getRowKey,
|
getRowKey,
|
||||||
setTableData,
|
setTableData,
|
||||||
getAutoCreateKey,
|
getAutoCreateKey,
|
||||||
|
@ -89,6 +89,9 @@ export function useTable(tableProps?: Props): [
|
|||||||
getRawDataSource: () => {
|
getRawDataSource: () => {
|
||||||
return getTableInstance().getRawDataSource();
|
return getTableInstance().getRawDataSource();
|
||||||
},
|
},
|
||||||
|
getSearchInfo: () => {
|
||||||
|
return getTableInstance().getSearchInfo();
|
||||||
|
},
|
||||||
getColumns: ({ ignoreIndex = false }: { ignoreIndex?: boolean } = {}) => {
|
getColumns: ({ ignoreIndex = false }: { ignoreIndex?: boolean } = {}) => {
|
||||||
const columns = getTableInstance().getColumns({ ignoreIndex }) || [];
|
const columns = getTableInstance().getColumns({ ignoreIndex }) || [];
|
||||||
return toRaw(columns);
|
return toRaw(columns);
|
||||||
|
@ -114,6 +114,7 @@ export interface TableActionType {
|
|||||||
setColumns: (columns: BasicColumn[] | string[]) => void;
|
setColumns: (columns: BasicColumn[] | string[]) => void;
|
||||||
getDataSource: <T = Recordable>() => T[];
|
getDataSource: <T = Recordable>() => T[];
|
||||||
getRawDataSource: <T = Recordable>() => T;
|
getRawDataSource: <T = Recordable>() => T;
|
||||||
|
getSearchInfo: <T = Recordable>() => T;
|
||||||
setLoading: (loading: boolean) => void;
|
setLoading: (loading: boolean) => void;
|
||||||
setProps: (props: Partial<BasicTableProps>) => void;
|
setProps: (props: Partial<BasicTableProps>) => void;
|
||||||
redoHeight: () => void;
|
redoHeight: () => void;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<BasicTable @register="registerTable" class="w-3/4 xl:w-4/5" :searchInfo="searchInfo">
|
<BasicTable @register="registerTable" class="w-3/4 xl:w-4/5" :searchInfo="searchInfo">
|
||||||
<template #toolbar>
|
<template #toolbar>
|
||||||
<a-button type="primary" @click="handleCreate">新增账号</a-button>
|
<a-button type="primary" @click="handleCreate">新增账号</a-button>
|
||||||
|
<a-button type="primary" @click="handleExport">导出账号</a-button>
|
||||||
</template>
|
</template>
|
||||||
<template #bodyCell="{ column, record }">
|
<template #bodyCell="{ column, record }">
|
||||||
<template v-if="column.key === 'action'">
|
<template v-if="column.key === 'action'">
|
||||||
@ -56,7 +57,7 @@
|
|||||||
const go = useGo();
|
const go = useGo();
|
||||||
const [registerModal, { openModal }] = useModal();
|
const [registerModal, { openModal }] = useModal();
|
||||||
const searchInfo = reactive<Recordable>({});
|
const searchInfo = reactive<Recordable>({});
|
||||||
const [registerTable, { reload, updateTableDataRecord }] = useTable({
|
const [registerTable, { reload, updateTableDataRecord, getSearchInfo }] = useTable({
|
||||||
title: '账号列表',
|
title: '账号列表',
|
||||||
api: getAccountList,
|
api: getAccountList,
|
||||||
rowKey: 'id',
|
rowKey: 'id',
|
||||||
@ -99,6 +100,10 @@
|
|||||||
console.log(record);
|
console.log(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleExport() {
|
||||||
|
console.log(getSearchInfo());
|
||||||
|
}
|
||||||
|
|
||||||
function handleSuccess({ isUpdate, values }) {
|
function handleSuccess({ isUpdate, values }) {
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
// 演示不刷新表格直接更新内部数据。
|
// 演示不刷新表格直接更新内部数据。
|
||||||
|
Loading…
Reference in New Issue
Block a user