refact: 重构目录架构

This commit is contained in:
ah--desktop
2025-10-26 10:03:58 +08:00
parent 9447d05ea1
commit 39ade97a16
91 changed files with 259 additions and 731 deletions
@@ -0,0 +1,338 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
deletePermissionApi,
getPermissionPageApi,
type PermissionVO,
type PermissionDTO
} from '#/api/system/permission';
import type { PageQueryDTO } from '#/types/common';
import PermissionFormModal from './components/PermissionFormModal.vue';
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'PermissionManagement' });
// 响应式数据
const loading = ref(false);
const permissionFormModalRef = ref();
// 搜索表单
const searchForm = ref({
code: undefined as undefined | string,
name: undefined as undefined | string,
type: undefined as undefined | string,
status: undefined as undefined | number,
});
// 状态选项
const statusOptions = [
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
];
// 权限类型选项
const typeOptions = [
{ label: '接口权限', value: 'api' },
{ label: '按钮权限', value: 'button' },
{ label: '数据权限', value: 'data' },
];
// 搜索表单配置
const formOptions = computed(() => ({
schemas: [
{
fieldName: 'code',
label: '权限码',
},
{
fieldName: 'name',
label: '权限名称',
},
{
fieldName: 'type',
label: '权限类型',
component: 'Select',
componentProps: {
options: typeOptions,
placeholder: '请选择权限类型',
},
},
{
fieldName: 'status',
label: '状态',
component: 'Select',
componentProps: {
options: statusOptions,
placeholder: '请选择状态',
},
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
field: 'code',
title: '权限码',
minWidth: 200,
},
{
field: 'name',
title: '权限名称',
minWidth: 150,
},
{
field: 'type',
title: '权限类型',
minWidth: 120,
slots: { default: 'type' },
},
{
field: 'status',
title: '状态',
minWidth: 80,
slots: { default: 'status' },
},
{
field: 'remark',
title: '备注',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
field: 'createTime',
title: '创建时间',
minWidth: 160,
},
{
title: '操作',
width: 120,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<PermissionDTO.PermissionFilterDTO> = {
page: page.currentPage,
pageSize: page.pageSize,
...searchForm.value,
};
const response = await getPermissionPageApi(params);
return {
items: response.records,
total: response.total,
};
} catch (error: any) {
console.error('查询数据失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
message.error(errorMessage);
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
};
// 表格实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '权限管理',
});
// 计算属性
const hasSelected = computed(() => {
const vxeTable = (gridApi as any).grid;
return vxeTable?.getCheckboxRecords?.()?.length > 0;
});
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
const handleAdd = () => {
permissionFormModalRef.value?.open();
};
const handleEdit = (row: PermissionVO.PermissionInfoVO) => {
permissionFormModalRef.value?.open(row);
};
const handleDelete = async (row: PermissionVO.PermissionInfoVO) => {
try {
await deletePermissionApi(row.id);
message.success('删除成功');
refreshTable();
} catch (error: any) {
console.error('删除失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
message.error(errorMessage);
}
};
const handleBatchDelete = async () => {
const vxeTable = (gridApi as any).grid;
const selectedRows = vxeTable?.getCheckboxRecords?.();
if (!selectedRows?.length) {
message.warning('请选择要删除的数据');
return;
}
try {
const deletePromises = selectedRows.map((row: PermissionVO.PermissionInfoVO) =>
deletePermissionApi(row.id)
);
await Promise.all(deletePromises);
message.success(`成功删除 ${selectedRows.length} 条记录`);
refreshTable();
} catch (error: any) {
console.error('批量删除失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '批量删除失败';
message.error(errorMessage);
}
};
// 处理模态框成功回调
function handleModalSuccess() {
refreshTable();
}
// 获取权限类型文本
const getTypeText = (type: string) => {
const typeMap = {
api: '接口权限',
button: '按钮权限',
data: '数据权限',
};
return typeMap[type as keyof typeof typeMap] || type;
};
// 获取权限类型颜色
const getTypeColor = (type: string) => {
const colorMap = {
api: 'blue',
button: 'green',
data: 'orange',
};
return colorMap[type as keyof typeof colorMap] || 'default';
};
// 获取状态文本
const getStatusText = (status: number) => {
return status === 1 ? '启用' : '禁用';
};
// 获取状态颜色
const getStatusColor = (status: number) => {
return status === 1 ? 'green' : 'red';
};
</script>
<template>
<Page title="权限管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理系统权限码,支持权限的增删改查操作
</div>
</template>
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
>
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon />
添加权限
</Button>
<Button
v-if="hasSelected"
danger
@click="handleBatchDelete"
>
批量删除
</Button>
</Space>
</template>
<!-- 权限类型列 -->
<template #type="{ row }">
<Tag :color="getTypeColor(row.type)">
{{ getTypeText(row.type) }}
</Tag>
</template>
<!-- 状态列 -->
<template #status="{ row }">
<Tag :color="getStatusColor(row.status)">
{{ getStatusText(row.status) }}
</Tag>
</template>
<!-- 操作列 -->
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
</Space>
</template>
</Grid>
<!-- 权限表单弹窗 -->
<PermissionFormModal ref="permissionFormModalRef" @success="handleModalSuccess" />
</Page>
</template>