Files
aiot-platform-ui/apps/web-antd/src/views/system/dict/modules/data-grid.vue

164 lines
4.0 KiB
Vue
Raw Normal View History

2025-04-06 18:56:42 +08:00
<script lang="ts" setup>
2025-05-19 11:21:04 +08:00
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemDictDataApi } from '#/api/system/dict/data';
2025-04-06 18:56:42 +08:00
2025-04-22 11:25:11 +08:00
import { watch } from 'vue';
2025-04-06 18:56:42 +08:00
import { useVbenModal } from '@vben/common-ui';
import { Download, Plus } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils';
2025-04-06 18:56:42 +08:00
2025-04-22 11:25:11 +08:00
import { Button, message } from 'ant-design-vue';
2025-04-06 18:56:42 +08:00
import { useVbenVxeGrid } from '#/adapter/vxe-table';
2025-04-22 11:25:11 +08:00
import {
deleteDictData,
exportDictData,
getDictDataPage,
} from '#/api/system/dict/data';
2025-05-19 11:21:04 +08:00
import { ACTION_KEY, TableAction } from '#/components/table-action';
2025-04-22 11:25:11 +08:00
import { $t } from '#/locales';
2025-04-06 18:56:42 +08:00
2025-04-22 11:25:11 +08:00
import { useDataGridColumns, useDataGridFormSchema } from '../data';
import DataForm from './data-form.vue';
2025-04-06 18:56:42 +08:00
const props = defineProps({
dictType: {
type: String,
default: undefined,
},
});
const [DataFormModal, dataFormModalApi] = useVbenModal({
connectedComponent: DataForm,
destroyOnClose: true,
});
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 导出表格 */
async function onExport() {
const data = await exportDictData(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '字典数据.xls', source: data });
2025-04-06 18:56:42 +08:00
}
/** 创建字典数据 */
function onCreate() {
dataFormModalApi.setData({ dictType: props.dictType }).open();
}
/** 编辑字典数据 */
2025-05-19 11:21:04 +08:00
function onEdit(row: SystemDictDataApi.DictData) {
2025-04-06 18:56:42 +08:00
dataFormModalApi.setData(row).open();
}
/** 删除字典数据 */
2025-05-19 11:21:04 +08:00
async function onDelete(row: SystemDictDataApi.DictData) {
message.loading({
content: $t('ui.actionMessage.deleting', [row.label]),
key: ACTION_KEY,
2025-04-06 18:56:42 +08:00
});
2025-05-19 11:21:04 +08:00
await deleteDictData(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.label]),
key: ACTION_KEY,
});
onRefresh();
2025-04-06 18:56:42 +08:00
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useDataGridFormSchema(),
},
gridOptions: {
2025-05-19 11:21:04 +08:00
columns: useDataGridColumns(),
2025-04-06 18:56:42 +08:00
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getDictDataPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
dictType: props.dictType,
...formValues,
2025-04-06 18:56:42 +08:00
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
2025-04-22 11:25:11 +08:00
},
} as VxeTableGridOptions<SystemDictDataApi.DictData>,
2025-04-06 18:56:42 +08:00
});
/** 监听 dictType 变化,重新查询 */
watch(
() => props.dictType,
() => {
if (props.dictType) {
onRefresh();
}
},
);
</script>
<template>
2025-04-22 11:25:11 +08:00
<div class="flex h-full flex-col">
2025-04-06 18:56:42 +08:00
<DataFormModal @success="onRefresh" />
<Grid table-title="字典数据列表">
<template #toolbar-tools>
2025-04-22 11:25:11 +08:00
<Button
type="primary"
@click="onCreate"
v-access:code="['system:dict:create']"
>
2025-04-06 18:56:42 +08:00
<Plus class="size-5" />
{{ $t('ui.actionTitle.create', ['字典数据']) }}
</Button>
2025-04-22 11:25:11 +08:00
<Button
type="primary"
class="ml-2"
@click="onExport"
v-access:code="['system:dict:export']"
>
2025-04-06 18:56:42 +08:00
<Download class="size-5" />
{{ $t('ui.actionTitle.export') }}
</Button>
</template>
2025-05-19 11:21:04 +08:00
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: 'ant-design:edit-outlined',
auth: ['system:dict:update'],
onClick: onEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: 'ant-design:delete-outlined',
auth: ['system:dict:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.label]),
confirm: onDelete.bind(null, row),
},
},
]"
/>
</template>
2025-04-06 18:56:42 +08:00
</Grid>
</div>
</template>