|
|
@@ -1,53 +1,87 @@
|
|
|
<script lang="ts" setup>
|
|
|
-import { useAccess } from '@vben/access';
|
|
|
+import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/';
|
|
|
+
|
|
|
import { Page, useVbenDrawer } from '@vben/common-ui';
|
|
|
|
|
|
-import { Button, message, Modal } from 'ant-design-vue';
|
|
|
+import { Button, message } from 'ant-design-vue';
|
|
|
|
|
|
-import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
|
+import { useTableGridOptions, useVbenVxeGrid } from '#/adapter';
|
|
|
import { MenuApi } from '#/api';
|
|
|
-import { TableAction } from '#/components/table-action';
|
|
|
|
|
|
import FormEdit from './components/edit.vue';
|
|
|
-import { gridOptions, searchFormOptions } from './data.config';
|
|
|
-
|
|
|
-const { hasAccessByCodes } = useAccess();
|
|
|
-
|
|
|
-const [Grid, { reload }] = useVbenVxeGrid({
|
|
|
- formOptions: searchFormOptions,
|
|
|
- gridOptions,
|
|
|
-});
|
|
|
+import { useColumns, useSearchSchema } from './data.config';
|
|
|
|
|
|
const [FormEditModal, formEditApi] = useVbenDrawer({
|
|
|
connectedComponent: FormEdit,
|
|
|
});
|
|
|
|
|
|
-const handleDelete = (id: number) => {
|
|
|
- Modal.confirm({
|
|
|
- iconType: 'info',
|
|
|
- title: '删除提示',
|
|
|
- content: `确定要删除选择的记录吗?`,
|
|
|
- cancelText: `关闭`,
|
|
|
- onOk: async () => {
|
|
|
- await MenuApi.deleteDetail(id);
|
|
|
- message.success('数据删除成功');
|
|
|
- reload();
|
|
|
- },
|
|
|
- });
|
|
|
+const handelSuccess = () => {
|
|
|
+ reload();
|
|
|
};
|
|
|
|
|
|
-const handleEdit = (record: any, isUpdate: boolean) => {
|
|
|
- formEditApi.setData({
|
|
|
- isUpdate,
|
|
|
- baseData: { ...record },
|
|
|
- });
|
|
|
+const handleDelete = async (id: number) => {
|
|
|
+ await MenuApi.deleteDetail(id);
|
|
|
+ message.success('数据删除成功');
|
|
|
+ reload();
|
|
|
+};
|
|
|
|
|
|
- formEditApi.open();
|
|
|
+const handleEdit = (record: any, isUpdate: boolean) => {
|
|
|
+ formEditApi
|
|
|
+ .setData({
|
|
|
+ isUpdate,
|
|
|
+ baseData: { ...record },
|
|
|
+ })
|
|
|
+ .open();
|
|
|
};
|
|
|
|
|
|
-const handelSuccess = () => {
|
|
|
- reload();
|
|
|
+const handleActionClick = async ({
|
|
|
+ code,
|
|
|
+ row,
|
|
|
+}: OnActionClickParams<MenuApi.RecordItem>) => {
|
|
|
+ switch (code) {
|
|
|
+ case 'append': {
|
|
|
+ handleEdit({ pid: row.id }, false);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'delete': {
|
|
|
+ await handleDelete(row.id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'edit': {
|
|
|
+ handleEdit({ id: row.id }, true);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
+
|
|
|
+const [Grid, { reload }] = useVbenVxeGrid(
|
|
|
+ useTableGridOptions({
|
|
|
+ formOptions: {
|
|
|
+ schema: useSearchSchema(),
|
|
|
+ },
|
|
|
+ gridOptions: {
|
|
|
+ pagerConfig: {
|
|
|
+ enabled: false,
|
|
|
+ },
|
|
|
+ treeConfig: {
|
|
|
+ rowField: 'id',
|
|
|
+ childrenField: 'children',
|
|
|
+ },
|
|
|
+ columns: useColumns(handleActionClick),
|
|
|
+ proxyConfig: {
|
|
|
+ ajax: {
|
|
|
+ query: async ({ page }, formValues) => {
|
|
|
+ return await MenuApi.getList({
|
|
|
+ pageIndex: page.currentPage,
|
|
|
+ pageSize: page.pageSize,
|
|
|
+ ...formValues,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ } as VxeTableGridOptions,
|
|
|
+ }),
|
|
|
+);
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -64,33 +98,6 @@ const handelSuccess = () => {
|
|
|
新增菜单
|
|
|
</Button>
|
|
|
</template>
|
|
|
- <template #action="{ row }">
|
|
|
- <TableAction
|
|
|
- :actions="[
|
|
|
- {
|
|
|
- label: '添加项',
|
|
|
- type: 'text',
|
|
|
- disabled: !hasAccessByCodes(['menu:add']),
|
|
|
- onClick: handleEdit.bind(null, { pid: row.id }, false),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '编辑',
|
|
|
- type: 'text',
|
|
|
- danger: true,
|
|
|
- disabled: !hasAccessByCodes(['menu:edit']),
|
|
|
- onClick: handleEdit.bind(null, { id: row.id }, true),
|
|
|
- },
|
|
|
- ]"
|
|
|
- :drop-down-actions="[
|
|
|
- {
|
|
|
- label: '删除',
|
|
|
- type: 'link',
|
|
|
- disabled: !hasAccessByCodes(['menu:delete']),
|
|
|
- onClick: handleDelete.bind(null, row.id),
|
|
|
- },
|
|
|
- ]"
|
|
|
- />
|
|
|
- </template>
|
|
|
</Grid>
|
|
|
</Page>
|
|
|
</template>
|