完善权限系统

This commit is contained in:
BBIT-Kai
2025-12-08 18:11:48 +08:00
parent c53926afd6
commit dbdc222541
1503 changed files with 132197 additions and 885 deletions
+1
View File
@@ -1,3 +1,4 @@
export * from './core';
export * from './cv';
export * from './llm';
export * from './manager';
+53
View File
@@ -0,0 +1,53 @@
import { pyRequestClient } from '#/api/request';
export namespace SystemDeptApi {
export interface SystemDept {
[key: string]: any;
children?: SystemDept[];
id: string;
name: string;
comment?: string;
}
}
/**
* 获取部门列表数据
*/
async function getDeptList() {
return pyRequestClient.get<Array<SystemDeptApi.SystemDept>>(
'/system/dept/list',
);
}
/**
* 创建部门
* @param data 部门数据
*/
async function createDept(
data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
) {
return pyRequestClient.post('/system/dept/add', data);
}
/**
* 更新部门
*
* @param id 部门 ID
* @param data 部门数据
*/
async function updateDept(
id: string,
data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
) {
return pyRequestClient.put(`/system/dept/${id}`, data);
}
/**
* 删除部门
* @param id 部门 ID
*/
async function deleteDept(id: string) {
return pyRequestClient.delete(`/system/dept/${id}`);
}
export { createDept, deleteDept, getDeptList, updateDept };
@@ -0,0 +1 @@
export * from './dept';
+1 -1
View File
@@ -49,6 +49,6 @@ export const overridesPreferences = defineOverridesPreferences({
},
tabbar: {
middleClickToClose: true,
keepAlive: false,
keepAlive: true,
},
});
@@ -0,0 +1,54 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'ic:popcorn',
authority: ['manager'],
keepAlive: true,
order: 2,
title: $t('管理后台'),
},
name: 'Manager',
path: '/manager',
children: [
{
name: 'M-department',
path: '/manager/department',
meta: {
authority: ['manager'],
icon: 'mdi:cupcake',
title: '部门管理',
keepAlive: true,
},
component: () => import('#/views/manager/department/index.vue'),
},
{
name: 'M-department',
path: '/manager/role',
meta: {
authority: ['manager'],
icon: 'mdi:cupcake',
title: '部门管理',
keepAlive: true,
},
component: () => import('#/views/manager/department/index.vue'),
},
{
name: 'M-department',
path: '/manager/user',
meta: {
authority: ['manager'],
icon: 'mdi:cupcake',
title: '部门管理',
keepAlive: true,
},
component: () => import('#/views/manager/department/index.vue'),
},
],
},
];
export default routes;
@@ -0,0 +1,113 @@
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn } from '#/adapter/vxe-table';
import type { SystemDeptApi } from '#/api/system/dept';
import { z } from '#/adapter/form';
import * as api from '#/api';
import { $t } from '#/locales';
/**
* 获取编辑表单的字段配置。如果没有使用多语言,可以直接export一个数组常量
*/
export function useSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'name',
label: '部门名',
rules: z
.string()
.min(2, $t('ui.formRules.minLength', ['部门名', 2]))
.max(20, $t('ui.formRules.maxLength', ['部门名', 20])),
},
{
component: 'ApiTreeSelect',
componentProps: {
allowClear: true,
api: api.getDeptList,
class: 'w-full',
labelField: 'name',
valueField: 'id',
childrenField: 'children',
},
fieldName: 'pid',
label: '父部门',
},
{
component: 'Textarea',
componentProps: {
maxLength: 50,
rows: 3,
showCount: true,
},
fieldName: 'remark',
label: '备注',
rules: z
.string()
.max(50, $t('ui.formRules.maxLength', ['备注', 50]))
.optional(),
},
];
}
/**
* 获取表格列配置
* @description 使用函数的形式返回列数据而不是直接export一个Array常量,是为了响应语言切换时重新翻译表头
* @param onActionClick 表格操作按钮点击事件
*/
export function useColumns(
onActionClick?: OnActionClickFn<SystemDeptApi.SystemDept>,
): VxeTableGridOptions<SystemDeptApi.SystemDept>['columns'] {
return [
{
align: 'left',
field: 'name',
fixed: 'left',
title: '部门名',
treeNode: true,
width: 150,
},
{
field: 'createTime',
title: '创建时间',
width: 180,
},
{
field: 'remark',
title: '备注',
},
{
align: 'right',
field: 'operation',
fixed: 'right',
headerAlign: 'center',
showOverflow: false,
title: '操作',
width: 200,
cellRender: {
attrs: {
nameField: 'name',
nameTitle: '部门名',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'append',
text: '新增下级',
},
'edit', // 默认的编辑按钮
{
code: 'delete', // 默认的删除按钮
disabled: (row: SystemDeptApi.SystemDept) => {
return !!(row.children && row.children.length > 0);
},
},
],
},
},
];
}
@@ -0,0 +1,78 @@
<script lang="ts" setup>
import type { SystemDeptApi } from '#/api/system/dept';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Button } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import * as api from '#/api';
import { $t } from '#/locales';
import { useSchema } from './data';
const emit = defineEmits(['success']);
const formData = ref<SystemDeptApi.SystemDept>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['部门'])
: $t('ui.actionTitle.create', ['部门']);
});
const [Form, formApi] = useVbenForm({
layout: 'vertical',
schema: useSchema(),
showDefaultActions: false,
});
function resetForm() {
formApi.resetForm();
formApi.setValues(formData.value || {});
}
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (valid) {
modalApi.lock();
const data = await formApi.getValues();
try {
await (formData.value?.id
? api.updateDept(formData.value.id, data)
: api.createDept(data));
modalApi.close();
emit('success');
} finally {
modalApi.lock(false);
}
}
},
onOpenChange(isOpen) {
if (isOpen) {
const data = modalApi.getData<SystemDeptApi.SystemDept>();
if (data) {
if (data.pid === 0) {
data.pid = undefined;
}
formData.value = data;
formApi.setValues(formData.value);
}
}
},
});
</script>
<template>
<Modal :title="getTitle">
<Form class="mx-4" />
<template #prepend-footer>
<div class="flex-auto">
<Button type="primary" danger @click="resetForm">
{{ $t('common.reset') }}
</Button>
</div>
</template>
</Modal>
</template>
@@ -0,0 +1,144 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { SystemDeptApi } from '#/api/system/dept';
import { Page, useVbenModal } from '@vben/common-ui';
import { Plus } from '@vben/icons';
import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import * as api from '#/api';
import { $t } from '#/locales';
import { useColumns } from './data';
import Form from './form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/**
* 编辑部门
* @param row
*/
function onEdit(row: SystemDeptApi.SystemDept) {
formModalApi.setData(row).open();
}
/**
* 添加下级部门
* @param row
*/
function onAppend(row: SystemDeptApi.SystemDept) {
formModalApi.setData({ pid: row.id }).open();
}
/**
* 创建新部门
*/
function onCreate() {
formModalApi.setData(null).open();
}
/**
* 删除部门
* @param row
*/
function onDelete(row: SystemDeptApi.SystemDept) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
key: 'action_process_msg',
});
api
.deleteDept(row.id)
.then(() => {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_process_msg',
});
refreshGrid();
})
.catch(() => {
hideLoading();
});
}
/**
* 表格操作按钮的回调函数
*/
function onActionClick({
code,
row,
}: OnActionClickParams<SystemDeptApi.SystemDept>) {
switch (code) {
case 'append': {
onAppend(row);
break;
}
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({
gridEvents: {},
gridOptions: {
columns: useColumns(onActionClick),
height: 'auto',
keepSource: true,
pagerConfig: {
enabled: false,
},
proxyConfig: {
ajax: {
query: async (_params) => {
return { items: await api.getDeptList() };
},
},
},
toolbarConfig: {
custom: true,
export: false,
refresh: { code: 'query' },
zoom: true,
},
treeConfig: {
parentField: 'pid',
rowField: 'id',
transform: false,
},
} as VxeTableGridOptions,
});
/**
* 刷新表格
*/
function refreshGrid() {
gridApi.query();
}
</script>
<template>
<Page auto-content-height>
<FormModal @success="refreshGrid" />
<Grid table-title="部门列表">
<template #toolbar-tools>
<Button type="primary" @click="onCreate">
<Plus class="size-5" />
新增部门
</Button>
</template>
</Grid>
</Page>
</template>