Skip to content

Commit

Permalink
feat(BasicTable): 新增表格搜索获取参数的方法 (#3715)
Browse files Browse the repository at this point in the history
* feat(BasicTable): 新增表格搜索获取参数的方法

* feat(BasicTable): 新增表格搜索获取参数的方法

* feat(BasicTable): 新增表格搜索获取参数的方法

* feat(BasicTable): 新增表格搜索获取参数的方法
  • Loading branch information
zwtvip authored Apr 5, 2024
1 parent 38d58ab commit de5f9e3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/Table/src/BasicTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
getDataSourceRef,
getDataSource,
getRawDataSource,
getSearchInfo,
setTableData,
updateTableDataRecord,
deleteTableDataRecord,
Expand Down Expand Up @@ -300,6 +301,7 @@
setLoading,
getDataSource,
getRawDataSource,
getSearchInfo,
setProps,
getRowSelection,
getPaginationRef: getPagination,
Expand Down
9 changes: 8 additions & 1 deletion src/components/Table/src/hooks/useDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function useDataSource(
});
const dataSourceRef = ref<Recordable[]>([]);
const rawDataSourceRef = ref<Recordable>({});
const searchInfoRef = ref<Recordable>({});

watchEffect(() => {
tableData.value = unref(dataSourceRef);
Expand Down Expand Up @@ -275,7 +276,7 @@ export function useDataSource(
if (beforeFetch && isFunction(beforeFetch)) {
params = (await beforeFetch(params)) || params;
}

searchInfoRef.value = params;
const res = await api(params);
rawDataSourceRef.value = res;

Expand Down Expand Up @@ -339,6 +340,10 @@ export function useDataSource(
return await fetch(opt);
}

function getSearchInfo<T = Recordable>() {
return searchInfoRef.value as T;
}

onMounted(() => {
useTimeoutFn(() => {
unref(propsRef).immediate && fetch();
Expand All @@ -349,6 +354,8 @@ export function useDataSource(
getDataSourceRef,
getDataSource,
getRawDataSource,
searchInfoRef,
getSearchInfo,
getRowKey,
setTableData,
getAutoCreateKey,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Table/src/hooks/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export function useTable(tableProps?: Props): [
getRawDataSource: () => {
return getTableInstance().getRawDataSource();
},
getSearchInfo: () => {
return getTableInstance().getSearchInfo();
},
getColumns: ({ ignoreIndex = false }: { ignoreIndex?: boolean } = {}) => {
const columns = getTableInstance().getColumns({ ignoreIndex }) || [];
return toRaw(columns);
Expand Down
1 change: 1 addition & 0 deletions src/components/Table/src/types/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export interface TableActionType {
setColumns: (columns: BasicColumn[] | string[]) => void;
getDataSource: <T = Recordable>() => T[];
getRawDataSource: <T = Recordable>() => T;
getSearchInfo: <T = Recordable>() => T;
setLoading: (loading: boolean) => void;
setProps: (props: Partial<BasicTableProps>) => void;
redoHeight: () => void;
Expand Down
7 changes: 6 additions & 1 deletion src/views/demo/system/account/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<BasicTable @register="registerTable" class="w-3/4 xl:w-4/5" :searchInfo="searchInfo">
<template #toolbar>
<a-button type="primary" @click="handleCreate">新增账号</a-button>
<a-button type="primary" @click="handleExport">导出账号</a-button>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
Expand Down Expand Up @@ -56,7 +57,7 @@
const go = useGo();
const [registerModal, { openModal }] = useModal();
const searchInfo = reactive<Recordable>({});
const [registerTable, { reload, updateTableDataRecord }] = useTable({
const [registerTable, { reload, updateTableDataRecord, getSearchInfo }] = useTable({
title: '账号列表',
api: getAccountList,
rowKey: 'id',
Expand Down Expand Up @@ -99,6 +100,10 @@
console.log(record);
}
function handleExport() {
console.log(getSearchInfo());
}
function handleSuccess({ isUpdate, values }) {
if (isUpdate) {
// 演示不刷新表格直接更新内部数据。
Expand Down

0 comments on commit de5f9e3

Please sign in to comment.