[add] 添加了部门管理的加载动画

This commit is contained in:
LiuYuanchi 2025-04-27 12:33:59 +08:00
parent 9840e6d823
commit 7ad6f1f093
2 changed files with 50 additions and 38 deletions

View File

@ -40,6 +40,7 @@ declare module 'vue' {
ASelect: typeof import('ant-design-vue/es')['Select']
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
ASpace: typeof import('ant-design-vue/es')['Space']
ASpin: typeof import('ant-design-vue/es')['Spin']
AStatistic: typeof import('ant-design-vue/es')['Statistic']
ASwitch: typeof import('ant-design-vue/es')['Switch']
ATable: typeof import('ant-design-vue/es')['Table']

View File

@ -6,44 +6,46 @@
<div class="toolbar">
<a-button type="primary" @click="showAddModal(null)">添加部门</a-button>
</div>
<a-tree
v-if="treeData.length > 0"
:tree-data="treeData"
show-line
:default-expand-all="true"
:selected-keys.sync="selectedKeys"
>
<template #title="{ dataRef }">
<div class="tree-node">
<span>{{ dataRef.departmentName }}</span>
<div class="node-actions">
<a-button
size="small"
type="link"
@click="showAddModal(dataRef)"
>
添加子部门
</a-button>
<a-button
size="small"
type="link"
@click="showEditModal(dataRef)"
>
编辑
</a-button>
<a-button
size="small"
type="link"
danger
@click="confirmDelete(dataRef)"
>
删除
</a-button>
<a-spin :spinning="loading">
<a-tree
v-if="treeData.length > 0"
:tree-data="treeData"
show-line
:default-expand-all="true"
:selected-keys.sync="selectedKeys"
>
<template #title="{ dataRef }">
<div class="tree-node">
<span>{{ dataRef.departmentName }}</span>
<div class="node-actions">
<a-button
size="small"
type="link"
@click="showAddModal(dataRef)"
>
添加子部门
</a-button>
<a-button
size="small"
type="link"
@click="showEditModal(dataRef)"
>
编辑
</a-button>
<a-button
size="small"
type="link"
danger
@click="confirmDelete(dataRef)"
>
删除
</a-button>
</div>
</div>
</div>
</template>
</a-tree>
<a-empty v-else description="暂无数据" />
</template>
</a-tree>
<a-empty v-else description="暂无数据" />
</a-spin>
</a-card>
</a-col>
</a-row>
@ -74,10 +76,13 @@
import { ref, onMounted } from 'vue';
import { message, Modal } from 'ant-design-vue';
import axios from 'axios';
import { apiRequestGet } from '@/utils/api'
import { apiRequestGet } from '@/utils/api';
import { localStg } from '@/utils/storage';
//
const treeData = ref([]);
//
const loading = ref(false);
//
const modalVisible = ref(false);
const modalTitle = ref('添加部门');
@ -97,6 +102,7 @@ const selectedKeys = ref([]);
//
const fetchDepartments = async () => {
try {
loading.value = true; //
const response = await apiRequestGet('/department/allDepartment');
if (response.data.success) {
@ -125,6 +131,8 @@ const fetchDepartments = async () => {
}
} catch (error) {
message.error('请求失败: ' + error.message);
} finally {
loading.value = false; //
}
};
@ -195,11 +203,14 @@ const confirmDelete = (dept) => {
content: `确定要删除部门 ${dept.departmentName} 吗?`,
async onOk() {
try {
loading.value = true; //
await axios.delete(`http://localhost:8080/api/departments/${dept.key}`);
message.success('删除成功');
fetchDepartments(); //
} catch (error) {
message.error('删除失败: ' + error.message);
} finally {
loading.value = false; //
}
},
});