144 lines
3.9 KiB
Vue
144 lines
3.9 KiB
Vue
<script lang="ts" setup>
|
||
// 导入 VxeGridListeners 类型用于定义表格事件监听器
|
||
import type { VxeGridListeners } from '#/adapter/vxe-table';
|
||
|
||
// 导入 Vue 的 ref 函数用于创建响应式数据
|
||
import { ref } from 'vue';
|
||
|
||
// 导入 Vben 的公共 UI 组件和 Hook
|
||
import { Page, useVbenModal } from '@vben/common-ui';
|
||
|
||
// 导入 Ant Design Vue 的组件和消息提示函数
|
||
import { Button, message } from 'ant-design-vue';
|
||
|
||
// 导入自定义的 VxeGrid Hook 和 TableAction 组件
|
||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||
import { TableAction } from '#/components/table-action';
|
||
|
||
// 导入删除 API 函数和模态框组件
|
||
import { deleteupperCamelCase } from './api';
|
||
import upperCamelCase from './components/modal.vue';
|
||
|
||
// 导入搜索表单和表格配置
|
||
import { formOptions } from './config/search';
|
||
import { gridOptions } from './config/table';
|
||
|
||
// 定义是否显示顶部表格下拉操作的响应式数据
|
||
const hasTopTableDropDownActions = ref(false);
|
||
|
||
// 定义表格事件监听器
|
||
const gridEvents: VxeGridListeners<any> = {
|
||
// 监听表格复选框变化事件
|
||
checkboxChange() {
|
||
const records = gridApi.grid.getCheckboxRecords();
|
||
hasTopTableDropDownActions.value = records.length > 0;
|
||
},
|
||
// 监听表格全选复选框变化事件
|
||
checkboxAll() {
|
||
const records = gridApi.grid.getCheckboxRecords();
|
||
hasTopTableDropDownActions.value = records.length > 0;
|
||
},
|
||
};
|
||
|
||
// 使用自定义的 VxeGrid Hook
|
||
const [Grid, gridApi] = useVbenVxeGrid({
|
||
formOptions,
|
||
gridOptions,
|
||
gridEvents,
|
||
});
|
||
|
||
// 使用 Vben 的 Modal Hook
|
||
const [FormModal, formModalApi] = useVbenModal({
|
||
connectedComponent: upperCamelCase,
|
||
});
|
||
|
||
// 定义显示模态框的函数
|
||
const showModal = (data = {}, isUpdate = false) => {
|
||
formModalApi.setData({
|
||
values: data,
|
||
update: isUpdate,
|
||
gridApi,
|
||
});
|
||
formModalApi.open();
|
||
};
|
||
|
||
// 定义删除操作的 API 函数
|
||
const deleteApi = (row: any) => {
|
||
let ids = [];
|
||
if (row) {
|
||
ids.push(row);
|
||
} else {
|
||
ids = gridApi.grid.getCheckboxRecords().map((item) => item.id);
|
||
}
|
||
deleteupperCamelCase({ ids }).then(() => {
|
||
message.success('删除成功!');
|
||
gridApi.reload();
|
||
});
|
||
};
|
||
</script>
|
||
|
||
<template>
|
||
<!-- 使用 Page 组件包裹整个页面 -->
|
||
<Page auto-content-height title="模板名称管理">
|
||
<!-- 渲染表单模态框 -->
|
||
<FormModal />
|
||
<!-- 渲染表格 -->
|
||
<Grid>
|
||
<!-- 定义表格工具栏按钮 -->
|
||
<template #toolbar-buttons>
|
||
<TableAction
|
||
:actions="[
|
||
{
|
||
label: '新增',
|
||
type: 'primary',
|
||
icon: 'ant-design:plus-outlined',
|
||
onClick: showModal.bind(null),
|
||
},
|
||
]"
|
||
:drop-down-actions="[
|
||
{
|
||
label: '删除',
|
||
icon: 'ant-design:delete-outlined',
|
||
ifShow: hasTopTableDropDownActions,
|
||
popConfirm: {
|
||
title: '确定删除吗?',
|
||
confirm: deleteApi.bind(null, false),
|
||
},
|
||
},
|
||
]"
|
||
>
|
||
<template #more>
|
||
<Button style="margin-left: 16px">
|
||
批量操作
|
||
</Button>
|
||
</template>
|
||
</TableAction>
|
||
</template>
|
||
<!-- 定义操作列的自定义模板 -->
|
||
<template #action="{ row }">
|
||
<TableAction
|
||
:actions="[
|
||
{
|
||
label: '编辑',
|
||
type: 'link',
|
||
icon: 'uil:edit',
|
||
size: 'small',
|
||
onClick: showModal.bind(null, row, true),
|
||
},
|
||
{
|
||
label: '删除',
|
||
type: 'link',
|
||
icon: 'ant-design:delete-outlined',
|
||
size: 'small',
|
||
popConfirm: {
|
||
title: '确定删除吗?',
|
||
confirm: deleteApi.bind(null, row.id),
|
||
},
|
||
},
|
||
]"
|
||
/>
|
||
</template>
|
||
</Grid>
|
||
</Page>
|
||
</template>
|