feat(frontend): 添加部门管理和系统配置页面
- 添加 department.ts 部门管理服务 - 添加 DepartmentManagementView.vue 部门管理页面 - 添加 SystemConfigView.vue 系统配置页面 - 更新路由配置添加新页面 - 更新 App.vue 添加系统菜单入口 - 前端编译验证通过
This commit is contained in:
87
frontend/admin/src/services/department.ts
Normal file
87
frontend/admin/src/services/department.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 部门管理服务
|
||||
*/
|
||||
|
||||
export interface Department {
|
||||
id?: number
|
||||
deptName: string
|
||||
parentId?: number
|
||||
deptCode?: string
|
||||
leaderId?: number
|
||||
sortOrder?: number
|
||||
status: number
|
||||
createdAt?: string
|
||||
}
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
code: number
|
||||
data: T
|
||||
message?: string
|
||||
}
|
||||
|
||||
class DepartmentService {
|
||||
private baseUrl = '/api'
|
||||
|
||||
async getDepartments(): Promise<Department[]> {
|
||||
const response = await fetch(`${this.baseUrl}/departments`, {
|
||||
credentials: 'include'
|
||||
})
|
||||
const result = await response.json() as ApiResponse<Department[]>
|
||||
if (result.code !== 200) {
|
||||
throw new Error(result.message || '获取部门列表失败')
|
||||
}
|
||||
return result.data
|
||||
}
|
||||
|
||||
async getDepartmentById(id: number): Promise<Department | null> {
|
||||
const response = await fetch(`${this.baseUrl}/departments/${id}`, {
|
||||
credentials: 'include'
|
||||
})
|
||||
const result = await response.json() as ApiResponse<Department>
|
||||
if (result.code !== 200) {
|
||||
return null
|
||||
}
|
||||
return result.data
|
||||
}
|
||||
|
||||
async createDepartment(data: Department): Promise<number> {
|
||||
const response = await fetch(`${this.baseUrl}/departments`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
const result = await response.json() as ApiResponse<number>
|
||||
if (result.code !== 200) {
|
||||
throw new Error(result.message || '创建部门失败')
|
||||
}
|
||||
return result.data
|
||||
}
|
||||
|
||||
async updateDepartment(id: number, data: Department): Promise<void> {
|
||||
const response = await fetch(`${this.baseUrl}/departments/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
const result = await response.json() as ApiResponse<void>
|
||||
if (result.code !== 200) {
|
||||
throw new Error(result.message || '更新部门失败')
|
||||
}
|
||||
}
|
||||
|
||||
async deleteDepartment(id: number): Promise<void> {
|
||||
const response = await fetch(`${this.baseUrl}/departments/${id}`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include'
|
||||
})
|
||||
const result = await response.json() as ApiResponse<void>
|
||||
if (result.code !== 200) {
|
||||
throw new Error(result.message || '删除部门失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const departmentService = new DepartmentService()
|
||||
export default departmentService
|
||||
Reference in New Issue
Block a user