feat: sort

This commit is contained in:
dap 2024-10-05 18:57:06 +08:00
parent 44c53eb5bf
commit 107035a9d9
2 changed files with 24 additions and 6 deletions

View File

@ -53,6 +53,7 @@ export const columns: VxeGridProps['columns'] = [
{ {
title: '创建时间', title: '创建时间',
field: 'createTime', field: 'createTime',
sortable: true,
}, },
{ {
title: '上传人', title: '上传人',

View File

@ -17,6 +17,7 @@ import {
Tooltip, Tooltip,
} from 'ant-design-vue'; } from 'ant-design-vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { isEmpty } from 'lodash-es';
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter'; import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
import { configInfoByKey } from '#/api/system/config'; import { configInfoByKey } from '#/api/system/config';
@ -45,7 +46,7 @@ const gridOptions: VxeGridProps = {
pagerConfig: {}, pagerConfig: {},
proxyConfig: { proxyConfig: {
ajax: { ajax: {
query: async ({ page }, formValues) => { query: async ({ page, sort }, formValues = {}) => {
// //
if (formValues?.createTime) { if (formValues?.createTime) {
formValues.params = { formValues.params = {
@ -61,11 +62,16 @@ const gridOptions: VxeGridProps = {
Reflect.deleteProperty(formValues, 'params'); Reflect.deleteProperty(formValues, 'params');
} }
return await ossList({ const params: any = {
pageNum: page.currentPage, pageNum: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
...formValues, ...formValues,
}); };
if (!isEmpty(sort)) {
params.orderByColumn = sort.field;
params.isAsc = sort.order;
}
return await ossList(params);
}, },
}, },
}, },
@ -73,12 +79,23 @@ const gridOptions: VxeGridProps = {
isHover: true, isHover: true,
keyField: 'ossId', keyField: 'ossId',
}, },
sortConfig: {
remote: true,
},
round: true, round: true,
align: 'center', align: 'center',
showOverflow: true, showOverflow: true,
}; };
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions }); const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
gridEvents: {
sortChange: () => {
tableApi.query();
},
},
});
async function handleDownload(row: Recordable<any>) { async function handleDownload(row: Recordable<any>) {
const hideLoading = message.loading($t('pages.common.downloadLoading'), 0); const hideLoading = message.loading($t('pages.common.downloadLoading'), 0);
@ -92,7 +109,7 @@ async function handleDownload(row: Recordable<any>) {
async function handleDelete(row: Recordable<any>) { async function handleDelete(row: Recordable<any>) {
await ossRemove(row.ossId); await ossRemove(row.ossId);
await tableApi.reload(); await tableApi.query();
} }
function handleMultiDelete() { function handleMultiDelete() {
@ -104,7 +121,7 @@ function handleMultiDelete() {
content: `确认删除选中的${ids.length}条记录吗?`, content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => { onOk: async () => {
await ossRemove(ids); await ossRemove(ids);
await tableApi.reload(); await tableApi.query();
}, },
}); });
} }