This commit is contained in:
zlwu committed 2025-12-26 10:52:43 +08:00
1 parent abfc5cd746
commit b0b3da3451
9 files changed
+2149

No files matched your search

+4
View File
@@ -100,6 +100,8 @@
| 日期 | 版本 | 更新内容 | 更新人 | | 日期 | 版本 | 更新内容 | 更新人 |
|------|------|---------|-------| |------|------|---------|-------|
| 2025-12-26 | 1.6 | 新增专业信息管理API,支持树形菜单+列表的专业管理 | Cursor |
| 2025-12-26 | 1.5 | 新增二级学院管理API,支持二级学院的增删改查 | Cursor |
| 2025-01-03 | 1.1 | 社团管理API更新:删除副社长信息卡片,role_type字段改为字符串类型 | 系统管理员 | | 2025-01-03 | 1.1 | 社团管理API更新:删除副社长信息卡片,role_type字段改为字符串类型 | 系统管理员 |
| 2025-07-01 | 1.0 | 初始版本 | 系统管理员 | | 2025-07-01 | 1.0 | 初始版本 | 系统管理员 |
| 2025-07-15 | 1.1 | 添加心理健康测评API | 张工 | | 2025-07-15 | 1.1 | 添加心理健康测评API | 张工 |
@@ -167,6 +169,8 @@
| [学生信息收集批次管理API](./学生信息收集批次管理API.md) | 学生信息收集批次班级权限管理 | ✅ 完成 | 2025-01-27 | | [学生信息收集批次管理API](./学生信息收集批次管理API.md) | 学生信息收集批次班级权限管理 | ✅ 完成 | 2025-01-27 |
| [学生信息批次收集API](./学生信息批次收集API.md) | 学生信息批次收集管理(新增) | ✅ 完成 | 2025-01-27 | | [学生信息批次收集API](./学生信息批次收集API.md) | 学生信息批次收集管理(新增) | ✅ 完成 | 2025-01-27 |
| [班级信息管理API](./班级信息管理API.md) | 班级基础信息增删改查 | ✅ 完成 | 2025-01-27 | | [班级信息管理API](./班级信息管理API.md) | 班级基础信息增删改查 | ✅ 完成 | 2025-01-27 |
| [二级学院管理API](./二级学院管理API.md) | 二级学院组织信息管理 | ✅ 完成 | 2025-12-26 |
| [专业信息管理API](./专业信息管理API.md) | 专业信息管理(树形菜单+列表) | ✅ 完成 | 2025-12-26 |
| [班级干部信息管理API](./班级干部信息管理API.md) | 班级干部信息管理(含用户角色关联) | ✅ 完成 | 2025-01-27 | | [班级干部信息管理API](./班级干部信息管理API.md) | 班级干部信息管理(含用户角色关联) | ✅ 完成 | 2025-01-27 |
| [班干部管理API](./班干部管理API.md) | 班级干部职务管理 | ✅ 完成 | 2025-01-27 | | [班干部管理API](./班干部管理API.md) | 班级干部职务管理 | ✅ 完成 | 2025-01-27 |
| [班级教师关联管理API](./班级教师关联管理API.md) | 班主任辅导员关联关系 | ✅ 完成 | 2025-01-27 | | [班级教师关联管理API](./班级教师关联管理API.md) | 班主任辅导员关联关系 | ✅ 完成 | 2025-01-27 |
@@ -0,0 +1,592 @@
# 专业信息管理 API 接口文档
### 模块概述
**模块名称**:majormsg / 专业信息管理
**基础路径**:`/system/dept`
**版本**:v1.0
**负责人**:Cursor AI
**更新时间**:2025-12-26
### 模块功能
专业信息管理模块主要用于管理学校的专业组织信息,通过sys_dept表存储专业基本信息,包括专业名称、所属学院、类别编码等。支持专业信息的增删改查操作,为学校专业架构管理提供基础数据支撑。
专业信息通过 `dept_category` 字段以 "zy-" 开头进行标识,属于二级学院的下级组织。
### 权限说明
- **权限前缀**:`majormsg:`
- **权限列表**:
- `majormsg:major:list` - 查询权限
- `majormsg:major:add` - 新增权限
- `majormsg:major:edit` - 编辑权限
- `majormsg:major:remove` - 删除权限
---
## 📊 接口概览
### 接口分类
#### 基础 CRUD 接口
| 接口名称 | HTTP 方法 | 路径 | 权限要求 | 功能描述 |
| -------------- | --------- | --------------------- | ---------------------- | ---------------------- |
| 查询专业列表 | GET | `/system/dept/list` | `majormsg:major:list` | 分页查询专业列表 |
| 查询专业详情 | GET | `/system/dept/{deptId}` | `majormsg:major:list` | 根据 ID 查询专业详情 |
| 新增专业 | POST | `/system/dept` | `majormsg:major:add` | 创建新的专业 |
| 修改专业 | PUT | `/system/dept` | `majormsg:major:edit` | 更新专业信息 |
| 删除专业 | DELETE | `/system/dept/{deptId}` | `majormsg:major:remove` | 删除专业 |
#### 业务逻辑接口
| 接口名称 | HTTP 方法 | 路径 | 权限要求 | 功能描述 |
| ---------------- | --------- | ------------------- | --------------------- | ---------------- |
| 获取学院树结构 | GET | `/system/dept/list` | `majormsg:major:list` | 获取二级学院树结构 |
### 通用响应格式
#### 成功响应
```json
{
"code": 200,
"msg": "操作成功",
"data": {
// 响应数据
}
}
```
#### 分页响应
```json
{
"code": 200,
"msg": "查询成功",
"rows": [
// 数据列表
],
"total": 100
}
```
#### 错误响应
```json
{
"code": 400001,
"msg": "参数错误",
"data": null
}
```
---
## 🔍 接口详细说明
### 1. 查询专业列表
#### 接口信息
**接口地址**: `GET /system/dept/list`
**接口描述**: 分页查询专业列表,支持多条件筛选,固定查询dept_category以"zy-"开头的数据
**权限要求**: `majormsg:major:list`
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| --------------- | ------- | ---- | ------------------------ | ------------ |
| pageNum | Integer | N | 页码,默认 1 | 1 |
| pageSize | Integer | N | 每页大小,默认 10 | 10 |
| deptName | String | N | 专业名称 | "计算机科学" |
| deptCategory | String | N | 部门类别编码 | "zy-001" |
| deptCategoryLike| String | Y | 部门类别模糊匹配(zy-) | "zy-" |
| parentId | Integer | N | 所属学院ID | 102 |
| status | String | N | 状态:0 正常,1 停用 | "0" |
#### 请求示例
```bash
curl -X GET "http://localhost:8080/system/dept/list?pageNum=1&pageSize=10&deptCategoryLike=zy-" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
```
#### 响应示例
```json
{
"code": 200,
"msg": "查询成功",
"rows": [
{
"deptId": 201,
"parentId": 102,
"parentName": "计算机学院",
"deptName": "计算机科学与技术",
"deptCategory": "zy-001",
"orderNum": 1,
"status": "0",
"delFlag": "0",
"createBy": 1,
"createTime": "2025-12-26 10:00:00",
"updateBy": 1,
"updateTime": "2025-12-26 10:00:00"
}
],
"total": 1
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | -------- | -------------------- |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
| 400001 | 参数错误 | 检查请求参数格式 |
---
### 2. 查询专业详情
#### 接口信息
**接口地址**: `GET /system/dept/{deptId}`
**接口描述**: 根据部门ID查询专业的详细信息
**权限要求**: `majormsg:major:list`
#### 路径参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| ------ | ---- | ---- | ------ | ------ |
| deptId | Long | Y | 部门ID | 201 |
#### 请求示例
```bash
curl -X GET "http://localhost:8080/system/dept/201" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
```
#### 响应示例
```json
{
"code": 200,
"msg": "查询成功",
"data": {
"deptId": 201,
"parentId": 102,
"parentName": "计算机学院",
"deptName": "计算机科学与技术",
"deptCategory": "zy-001",
"orderNum": 1,
"status": "0",
"delFlag": "0",
"createBy": 1,
"createTime": "2025-12-26 10:00:00",
"updateBy": 1,
"updateTime": "2025-12-26 10:00:00"
}
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | ---------- | -------------------- |
| 404001 | 数据不存在 | 检查 ID 是否正确 |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
---
### 3. 新增专业
#### 接口信息
**接口地址**: `POST /system/dept`
**接口描述**: 创建新的专业记录,dept_category必须以"zy-"开头
**权限要求**: `majormsg:major:add`
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| ----------- | ------- | ---- | ---------------------------- | ------------------- |
| parentId | Integer | Y | 所属学院ID | 102 |
| deptName | String | Y | 专业名称 | "计算机科学与技术" |
| deptCategory| String | Y | 部门类别编码(必须以zy-开头)| "zy-001" |
| orderNum | Integer | Y | 显示顺序 | 1 |
| status | String | Y | 状态:0 正常,1 停用 | "0" |
#### 请求体
```json
{
"parentId": 102,
"deptName": "计算机科学与技术",
"deptCategory": "zy-001",
"orderNum": 1,
"status": "0"
}
```
#### 请求示例
```bash
curl -X POST "http://localhost:8080/system/dept" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"parentId": 102,
"deptName": "计算机科学与技术",
"deptCategory": "zy-001",
"orderNum": 1,
"status": "0"
}'
```
#### 响应示例
```json
{
"code": 200,
"msg": "新增成功",
"data": {
"deptId": 201
}
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | ---------- | -------------------- |
| 400001 | 参数错误 | 检查必填参数是否缺失 |
| 400002 | 数据已存在 | 检查专业名称是否重复 |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
#### 参数验证规则
- `parentId`: 必须是有效的二级学院ID
- `deptName`: 长度 2-50 字符,不能为空
- `deptCategory`: 必须以 "zy-" 开头,长度 4-30 字符,不能为空
- `orderNum`: 必须为正整数
- `status`: 只能为 "0" 或 "1"
---
### 4. 修改专业
#### 接口信息
**接口地址**: `PUT /system/dept`
**接口描述**: 更新专业信息
**权限要求**: `majormsg:major:edit`
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| ----------- | ------- | ---- | ---------------------------- | ------------------- |
| deptId | Integer | Y | 专业ID | 201 |
| parentId | Integer | Y | 所属学院ID | 102 |
| deptName | String | Y | 专业名称 | "计算机科学与技术" |
| deptCategory| String | Y | 部门类别编码(必须以zy-开头)| "zy-001" |
| orderNum | Integer | Y | 显示顺序 | 1 |
| status | String | Y | 状态:0 正常,1 停用 | "0" |
#### 请求体
```json
{
"deptId": 201,
"parentId": 102,
"deptName": "计算机科学与技术(本)",
"deptCategory": "zy-001",
"orderNum": 1,
"status": "0"
}
```
#### 请求示例
```bash
curl -X PUT "http://localhost:8080/system/dept" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"deptId": 201,
"parentId": 102,
"deptName": "计算机科学与技术(本)",
"deptCategory": "zy-001",
"orderNum": 1,
"status": "0"
}'
```
#### 响应示例
```json
{
"code": 200,
"msg": "修改成功",
"data": null
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | ---------- | -------------------- |
| 404001 | 数据不存在 | 检查 ID 是否正确 |
| 400001 | 参数错误 | 检查参数格式是否正确 |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
---
### 5. 删除专业
#### 接口信息
**接口地址**: `DELETE /system/dept/{deptId}`
**接口描述**: 删除专业,支持逻辑删除
**权限要求**: `majormsg:major:remove`
#### 路径参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| ------ | ---- | ---- | -------- | ------ |
| deptId | Long | Y | 专业ID | 201 |
#### 请求示例
```bash
curl -X DELETE "http://localhost:8080/system/dept/201" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
```
#### 响应示例
```json
{
"code": 200,
"msg": "删除成功",
"data": null
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | ---------- | -------------------- |
| 400001 | 参数错误 | 检查 ID 格式是否正确 |
| 400003 | 数据被引用 | 请先删除关联数据 |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
---
### 6. 获取学院树结构
#### 接口信息
**接口地址**: `GET /system/dept/list`
**接口描述**: 获取二级学院的树形结构,用于左侧导航菜单
**权限要求**: `majormsg:major:list`
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| -------- | ------- | ---- | ---------------- | ------ |
| parentId | Integer | Y | 父节点ID(固定为101) | 101 |
#### 请求示例
```bash
curl -X GET "http://localhost:8080/system/dept/list?parentId=101" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
```
#### 响应示例
```json
{
"code": 200,
"msg": "查询成功",
"data": [
{
"deptId": 102,
"parentId": 101,
"deptName": "计算机学院",
"deptCategory": "xy-19",
"orderNum": 1,
"status": "0"
},
{
"deptId": 103,
"parentId": 101,
"deptName": "人文学院",
"deptCategory": "xy-19",
"orderNum": 2,
"status": "0"
}
]
}
```
---
## 📋 数据字典
### 专业状态枚举
| 值 | 名称 | 说明 |
| --- | ---- | -------- |
| 0 | 正常 | 专业正常运行 |
| 1 | 停用 | 专业已停用 |
### 专业类别编码规范
| 前缀 | 说明 | 示例 |
| ---- | ---- | ---- |
| zy- | 专业标识前缀 | zy-001(计算机科学与技术)<br>zy-002(软件工程) |
---
## 🔧 SDK 使用示例
### JavaScript SDK
```javascript
// 查询专业列表
const queryParams = {
pageNum: 1,
pageSize: 10,
deptCategoryLike: 'zy-',
parentId: 102
};
const listResult = await listMajor(queryParams);
// 新增专业
const majorData = {
parentId: 102,
deptName: "计算机科学与技术",
deptCategory: "zy-001",
orderNum: 1,
status: "0"
};
const addResult = await addMajor(majorData);
// 修改专业
majorData.deptId = 201;
majorData.deptName = "计算机科学与技术(本)";
const updateResult = await updateMajor(majorData);
// 删除专业
const deleteResult = await delMajor(201);
// 获取学院树
const collegeTree = await getCollegeTree();
```
---
## 🧪 测试用例
### 接口测试
```javascript
// Jest 测试示例
describe('专业信息管理 API Tests', () => {
test('查询专业列表接口', async () => {
const response = await request(app)
.get('/system/dept/list?deptCategoryLike=zy-')
.set('Authorization', `Bearer ${token}`)
.expect(200);
expect(response.body.code).toBe(200);
expect(response.body.data).toBeDefined();
});
test('新增专业接口', async () => {
const majorData = {
parentId: 102,
deptName: "测试专业",
deptCategory: "zy-test",
orderNum: 1,
status: "0"
};
const response = await request(app)
.post('/system/dept')
.set('Authorization', `Bearer ${token}`)
.send(majorData)
.expect(200);
expect(response.body.code).toBe(200);
expect(response.body.data.deptId).toBeDefined();
});
});
```
---
## 🔄 版本历史
### v1.0.0 - 2025-12-26
- ✅ 初始版本发布
- ✅ 完成基础 CRUD 接口
- ✅ 实现学院树形菜单和专业列表联动
- ✅ 支持专业的增删改查功能
---
## 📖 相关文档
- **数据库设计**:[数据库设计文档](../设计文档/database/)
- **业务需求**:[业务需求文档](../需求文档/)
- **二级学院管理**:[二级学院管理API](./二级学院管理API.md)
- **技术架构**:[技术架构文档](./技术架构/)
- **开发规范**:[开发规范文档](./开发规范/)
---
## 📞 联系方式
**开发团队**:Cursor AI
**负责人**:Cursor AI
**邮箱**:无
**文档维护**:实时更新,如有问题请及时反馈
---
**📌 重要提醒**:
1. 所有接口都需要先登录获取 token
2. 请求头必须包含 `Authorization: Bearer {token}`
3. 专业类别编码必须以 "zy-" 开头
4. 新增专业时必须选择所属的二级学院
5. 删除操作会进行关联数据检查
6. 左侧学院树点击后,右侧列表会筛选对应学院的专业
7. 生产环境请使用 HTTPS 协议
@@ -0,0 +1,540 @@
# 二级学院管理 API 接口文档
### 模块概述
**模块名称**:collegemsg / 二级学院管理
**基础路径**:`/system/dept`
**版本**:v1.0
**负责人**:Cursor AI
**更新时间**:2025-12-26
### 模块功能
二级学院管理模块主要用于管理学校的二级学院组织信息,通过sys_dept表存储学院基本信息,包括学院名称、负责人、联系方式等。支持二级学院的增删改查操作,为学校组织架构管理提供基础数据支撑。
### 权限说明
- **权限前缀**:`collegemsg:`
- **权限列表**:
- `collegemsg:college:list` - 查询权限
- `collegemsg:college:add` - 新增权限
- `collegemsg:college:edit` - 编辑权限
- `collegemsg:college:remove` - 删除权限
---
## 📊 接口概览
### 接口分类
#### 基础 CRUD 接口
| 接口名称 | HTTP 方法 | 路径 | 权限要求 | 功能描述 |
| -------------- | --------- | --------------------- | ---------------------- | ---------------------- |
| 查询二级学院列表 | GET | `/system/dept/list` | `collegemsg:college:list` | 分页查询二级学院列表 |
| 查询二级学院详情 | GET | `/system/dept/{deptId}` | `collegemsg:college:list` | 根据 ID 查询二级学院详情 |
| 新增二级学院 | POST | `/system/dept` | `collegemsg:college:add` | 创建新的二级学院 |
| 修改二级学院 | PUT | `/system/dept` | `collegemsg:college:edit` | 更新二级学院信息 |
| 删除二级学院 | DELETE | `/system/dept/{deptId}` | `collegemsg:college:remove` | 删除二级学院 |
### 通用响应格式
#### 成功响应
```json
{
"code": 200,
"msg": "操作成功",
"data": {
// 响应数据
}
}
```
#### 分页响应
```json
{
"code": 200,
"msg": "查询成功",
"rows": [
// 数据列表
],
"total": 100
}
```
#### 错误响应
```json
{
"code": 400001,
"msg": "参数错误",
"data": null
}
```
---
## 🔍 接口详细说明
### 1. 查询二级学院列表
#### 接口信息
**接口地址**: `GET /system/dept/list`
**接口描述**: 分页查询二级学院列表,支持多条件筛选,固定查询parent_id=101的二级学院
**权限要求**: `collegemsg:college:list`
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| --------- | ------- | ---- | -------------------- | ------------ |
| pageNum | Integer | N | 页码,默认 1 | 1 |
| pageSize | Integer | N | 每页大小,默认 10 | 10 |
| deptName | String | N | 学院名称 | "计算机学院" |
| deptCategory | String | N | 部门类别编码 | "COLLEGE" |
| status | String | N | 状态:0 正常,1 停用 | "0" |
| parentId | Integer | Y | 父节点ID,固定为101 | 101 |
#### 请求示例
```bash
curl -X GET "http://localhost:8080/system/dept/list?pageNum=1&pageSize=10&deptName=计算机&parentId=101" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
```
#### 响应示例
```json
{
"code": 200,
"msg": "查询成功",
"rows": [
{
"deptId": 102,
"parentId": 101,
"deptName": "计算机学院",
"deptCategory": "COLLEGE",
"orderNum": 1,
"status": "0",
"delFlag": "0",
"createBy": 1,
"createTime": "2025-12-26 10:00:00",
"updateBy": 1,
"updateTime": "2025-12-26 10:00:00"
}
],
"total": 1
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | -------- | -------------------- |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
| 400001 | 参数错误 | 检查请求参数格式 |
---
### 2. 查询二级学院详情
#### 接口信息
**接口地址**: `GET /system/dept/{deptId}`
**接口描述**: 根据部门ID查询二级学院的详细信息
**权限要求**: `collegemsg:college:list`
#### 路径参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| ------ | ---- | ---- | -------- | ------ |
| deptId | Long | Y | 部门ID | 102 |
#### 请求示例
```bash
curl -X GET "http://localhost:8080/system/dept/102" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
```
#### 响应示例
```json
{
"code": 200,
"msg": "查询成功",
"data": {
"deptId": 102,
"parentId": 101,
"deptName": "计算机学院",
"deptCategory": "COLLEGE",
"orderNum": 1,
"leader": "1",
"phone": "13800138000",
"email": "computer@school.edu.cn",
"status": "0",
"delFlag": "0",
"remark": "计算机科学与技术专业",
"createBy": 1,
"createTime": "2025-12-26 10:00:00",
"updateBy": 1,
"updateTime": "2025-12-26 10:00:00"
}
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | ---------- | -------------------- |
| 404001 | 数据不存在 | 检查 ID 是否正确 |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
---
### 3. 新增二级学院
#### 接口信息
**接口地址**: `POST /system/dept`
**接口描述**: 创建新的二级学院记录,自动设置parentId为101
**权限要求**: `collegemsg:college:add`
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| ----------- | ------- | ---- | ---------------------------- | ------------------- |
| parentId | Integer | Y | 父节点ID,固定为101 | 101 |
| deptName | String | Y | 学院名称 | "计算机学院" |
| deptCategory| String | Y | 部门类别编码 | "COLLEGE" |
| orderNum | Integer | Y | 显示顺序 | 1 |
| status | String | Y | 状态:0 正常,1 停用 | "0" |
| remark | String | N | 备注信息 | "计算机科学与技术专业" |
#### 请求体
```json
{
"parentId": 101,
"deptName": "计算机学院",
"deptCategory": "COLLEGE",
"orderNum": 1,
"status": "0"
}
```
#### 请求示例
```bash
curl -X POST "http://localhost:8080/system/dept" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"parentId": 101,
"deptName": "计算机学院",
"deptCategory": "COLLEGE",
"orderNum": 1,
"leader": "1",
"phone": "13800138000",
"email": "computer@school.edu.cn",
"status": "0",
"remark": "计算机科学与技术专业"
}'
```
#### 响应示例
```json
{
"code": 200,
"msg": "新增成功",
"data": {
"deptId": 102
}
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | ---------- | -------------------- |
| 400001 | 参数错误 | 检查必填参数是否缺失 |
| 400002 | 数据已存在 | 检查学院名称是否重复 |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
#### 参数验证规则
- `deptName`: 长度 2-50 字符,不能为空
- `deptCategory`: 长度 1-30 字符,不能为空
- `orderNum`: 必须为正整数
- `status`: 只能为 "0" 或 "1"
---
### 4. 修改二级学院
#### 接口信息
**接口地址**: `PUT /system/dept`
**接口描述**: 更新二级学院信息
**权限要求**: `collegemsg:college:edit`
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| ----------- | ------- | ---- | ---------------------------- | ------------------- |
| deptId | Integer | Y | 部门ID | 102 |
| parentId | Integer | Y | 父节点ID,固定为101 | 101 |
| deptName | String | Y | 学院名称 | "计算机学院" |
| deptCategory| String | Y | 部门类别编码 | "COLLEGE" |
| orderNum | Integer | Y | 显示顺序 | 1 |
| status | String | Y | 状态:0 正常,1 停用 | "0" |
| remark | String | N | 备注信息 | "计算机科学与技术专业" |
#### 请求体
```json
{
"deptId": 102,
"parentId": 101,
"deptName": "计算机与人工智能学院",
"deptCategory": "COLLEGE",
"orderNum": 1,
"leader": "1",
"phone": "13800138000",
"email": "csai@school.edu.cn",
"status": "0",
"remark": "计算机科学与人工智能专业"
}
```
#### 请求示例
```bash
curl -X PUT "http://localhost:8080/system/dept" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"deptId": 102,
"parentId": 101,
"deptName": "计算机与人工智能学院",
"deptCategory": "COLLEGE",
"orderNum": 1,
"leader": "1",
"phone": "13800138000",
"email": "csai@school.edu.cn",
"status": "0",
"remark": "计算机科学与人工智能专业"
}'
```
#### 响应示例
```json
{
"code": 200,
"msg": "修改成功",
"data": null
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | ---------- | -------------------- |
| 404001 | 数据不存在 | 检查 ID 是否正确 |
| 400001 | 参数错误 | 检查参数格式是否正确 |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
---
### 5. 删除二级学院
#### 接口信息
**接口地址**: `DELETE /system/dept/{deptId}`
**接口描述**: 删除二级学院,支持逻辑删除
**权限要求**: `collegemsg:college:remove`
#### 路径参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
| ------ | ---- | ---- | -------- | ------ |
| deptId | Long | Y | 部门ID | 102 |
#### 请求示例
```bash
curl -X DELETE "http://localhost:8080/system/dept/102" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
```
#### 响应示例
```json
{
"code": 200,
"msg": "删除成功",
"data": null
}
```
#### 错误码
| 错误码 | 说明 | 解决方案 |
| ------ | ---------- | -------------------- |
| 400001 | 参数错误 | 检查 ID 格式是否正确 |
| 400003 | 数据被引用 | 请先删除关联数据 |
| 401001 | 未登录 | 请先登录获取 token |
| 403001 | 无权限 | 请联系管理员分配权限 |
---
## 📋 数据字典
### 二级学院状态枚举
| 值 | 名称 | 说明 |
| --- | ---- | -------- |
| 0 | 正常 | 学院正常运行 |
| 1 | 停用 | 学院已停用 |
### 部门类别枚举
| 值 | 名称 | 说明 |
| ------ | ---- | -------- |
| COLLEGE | 学院 | 二级学院 |
---
## 🔧 SDK 使用示例
### JavaScript SDK
```javascript
// 查询二级学院列表
const queryParams = {
pageNum: 1,
pageSize: 10,
deptName: "计算机",
parentId: 101
};
const listResult = await listCollege(queryParams);
// 新增二级学院
const collegeData = {
parentId: 101,
deptName: "计算机学院",
deptCategory: "COLLEGE",
orderNum: 1,
status: "0"
};
const addResult = await addCollege(collegeData);
// 修改二级学院
collegeData.deptId = 102;
collegeData.deptName = "计算机与人工智能学院";
const updateResult = await updateCollege(collegeData);
// 删除二级学院
const deleteResult = await delCollege(102);
```
---
## 🧪 测试用例
### 接口测试
```javascript
// Jest 测试示例
describe('二级学院管理 API Tests', () => {
test('查询二级学院列表接口', async () => {
const response = await request(app)
.get('/system/dept/list?parentId=101')
.set('Authorization', `Bearer ${token}`)
.expect(200);
expect(response.body.code).toBe(200);
expect(response.body.rows).toBeDefined();
expect(response.body.total).toBeGreaterThanOrEqual(0);
});
test('新增二级学院接口', async () => {
const collegeData = {
parentId: 101,
deptName: "测试学院",
deptCategory: "COLLEGE",
orderNum: 1,
status: "0"
};
const response = await request(app)
.post('/system/dept')
.set('Authorization', `Bearer ${token}`)
.send(collegeData)
.expect(200);
expect(response.body.code).toBe(200);
expect(response.body.data.deptId).toBeDefined();
});
});
```
---
## 🔄 版本历史
### v1.0.0 - 2025-12-26
- ✅ 初始版本发布
- ✅ 完成基础 CRUD 接口
- ✅ 完成二级学院管理功能
---
## 📖 相关文档
- **数据库设计**:[数据库设计文档](../设计文档/database/)
- **业务需求**:[业务需求文档](../需求文档/)
- **技术架构**:[技术架构文档](./技术架构/)
- **开发规范**:[开发规范文档](./开发规范/)
---
## 📞 联系方式
**开发团队**:Cursor AI
**负责人**:Cursor AI
**邮箱**:无
**文档维护**:实时更新,如有问题请及时反馈
---
**📌 重要提醒**:
1. 所有接口都需要先登录获取 token
2. 请求头必须包含 `Authorization: Bearer {token}`
3. 新增和修改操作会自动设置 parentId 为 101
4. 学院名称具有唯一性约束
5. 删除操作会进行关联数据检查
6. 生产环境请使用 HTTPS 协议
@@ -0,0 +1,55 @@
import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MajorVO, MajorQuery, MajorForm } from './types';
// 查询专业列表 (dept_category 以 zy- 开头的) - 注意:此接口不支持分页,返回所有数据
export const listMajor = (query?: MajorQuery) => {
return request({
url: '/system/dept/list',
method: 'get',
params: { ...query, deptCategoryLike: 'zy-' } // 查询以 zy- 开头的专业
});
};
// 查询专业详细
export const getMajor = (deptId: string | number): AxiosPromise<MajorVO> => {
return request({
url: '/system/dept/' + deptId,
method: 'get'
});
};
// 新增专业
export const addMajor = (data: MajorForm) => {
return request({
url: '/system/dept',
method: 'post',
data: data
});
};
// 修改专业
export const updateMajor = (data: MajorForm) => {
return request({
url: '/system/dept',
method: 'put',
data: data
});
};
// 删除专业
export const delMajor = (deptId: number | string) => {
return request({
url: '/system/dept/' + deptId,
method: 'delete'
});
};
// 获取二级学院树形结构
export const getCollegeTree = () => {
return request({
url: '/system/dept/list',
method: 'get',
params: { parentId: 101 } // 获取二级学院
});
};
@@ -0,0 +1,54 @@
/**
* 专业查询参数
*/
export interface MajorQuery extends PageQuery {
deptName?: string;
deptCategory?: string;
parentId?: number;
deptCategoryLike?: string;
status?: string;
}
/**
* 专业类型
*/
export interface MajorVO extends BaseEntity {
id: number | string;
parentName: string;
parentId: number | string;
children: MajorVO[];
deptId: number | string;
deptName: string;
deptCategory: string;
orderNum: number;
status: string;
delFlag: string;
ancestors: string;
menuId: string | number;
}
/**
* 专业表单类型
*/
export interface MajorForm {
parentName?: string;
parentId?: number | string;
children?: MajorForm[];
deptId?: number | string;
deptName?: string;
deptCategory?: string;
orderNum?: number;
status?: string;
delFlag?: string;
ancestors?: string;
}
/**
* 学院树节点类型
*/
export interface CollegeTreeNode {
id: number | string;
label: string;
parentId: number | string;
children?: CollegeTreeNode[];
}
+46
View File
@@ -0,0 +1,46 @@
import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CollegeVO, CollegeQuery, CollegeForm } from './types';
// 查询二级学院列表 (parent_id = 101)
export const listCollege = (query?: CollegeQuery) => {
return request({
url: '/system/dept/list',
method: 'get',
params: { ...query, parentId: 101 } // 固定查询parent_id = 101的二级学院
});
};
// 查询二级学院详细
export const getCollege = (deptId: string | number): AxiosPromise<CollegeVO> => {
return request({
url: '/system/dept/' + deptId,
method: 'get'
});
};
// 新增二级学院
export const addCollege = (data: CollegeForm) => {
return request({
url: '/system/dept',
method: 'post',
data: { ...data, parentId: 101 } // 固定设置parentId为101
});
};
// 修改二级学院
export const updateCollege = (data: CollegeForm) => {
return request({
url: '/system/dept',
method: 'put',
data: data
});
};
// 删除二级学院
export const delCollege = (deptId: number | string) => {
return request({
url: '/system/dept/' + deptId,
method: 'delete'
});
};
+43
View File
@@ -0,0 +1,43 @@
/**
* 二级学院查询参数
*/
export interface CollegeQuery extends PageQuery {
deptName?: string;
deptCategory?: string;
status?: string;
parentId?: number;
}
/**
* 二级学院类型
*/
export interface CollegeVO extends BaseEntity {
id: number | string;
parentName: string;
parentId: number | string;
children: CollegeVO[];
deptId: number | string;
deptName: string;
deptCategory: string;
orderNum: number;
status: string;
delFlag: string;
ancestors: string;
menuId: string | number;
}
/**
* 二级学院表单类型
*/
export interface CollegeForm {
parentName?: string;
parentId?: number | string;
children?: CollegeForm[];
deptId?: number | string;
deptName?: string;
deptCategory?: string;
orderNum?: number;
status?: string;
delFlag?: string;
ancestors?: string;
}
@@ -0,0 +1,316 @@
<template>
<div class="p-2 page-container">
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
<div v-show="showSearch" class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :model="queryParams" label-width="100px">
<el-row :gutter="20">
<el-col :span="6">
<el-form-item label="学院名称" prop="deptName">
<el-input v-model="queryParams.deptName" placeholder="请输入学院名称" clearable @keyup.enter="handleQuery" />
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="部门类别" prop="deptCategory">
<el-input v-model="queryParams.deptCategory" placeholder="请输入部门类别" clearable @keyup.enter="handleQuery" />
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
<el-option label="正常" :value="'0'" />
<el-option label="停用" :value="'1'" />
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24" class="search-btn-container">
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-card>
</div>
</transition>
<el-card shadow="never">
<template #header>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['collegemsg:college:add']">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['collegemsg:college:edit']"
>修改</el-button
>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['collegemsg:college:remove']"
>删除</el-button
>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
</template>
<el-table v-loading="loading" border :data="collegeList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="部门ID" align="center" prop="deptId" />
<el-table-column label="学院名称" align="center" prop="deptName" />
<el-table-column label="部门类别" align="center" prop="deptCategory" />
<el-table-column label="显示顺序" align="center" prop="orderNum" />
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<el-tag :type="scope.row.status === '0' ? 'success' : 'danger'">
{{ scope.row.status === '0' ? '正常' : '停用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="255" fixed="right">
<template #default="scope">
<el-tooltip content="修改" placement="top">
<el-button link type="primary" plain icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['collegemsg:college:edit']"></el-button>
</el-tooltip>
<el-tooltip content="删除" placement="top">
<el-button
link
type="danger"
plain
icon="Delete"
@click="handleDelete(scope.row)"
v-hasPermi="['collegemsg:college:remove']"
></el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
</el-card>
<!-- 添加或修改二级学院对话框 -->
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
<el-form ref="collegeFormRef" :model="form" :rules="rules" label-width="100px">
<el-form-item label="学院名称" prop="deptName">
<el-input v-model="form.deptName" placeholder="请输入学院名称" />
</el-form-item>
<el-form-item label="部门类别" prop="deptCategory">
<el-input v-model="form.deptCategory" placeholder="请输入部门类别编码" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input-number v-model="form.orderNum" :min="0" :max="999" controls-position="right" placeholder="请输入显示顺序" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="form.status" placeholder="请选择状态" style="width: 100%">
<el-option label="正常" :value="'0'" />
<el-option label="停用" :value="'1'" />
</el-select>
</el-form-item>
<el-form-item label="备注信息" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="CollegeMsg" lang="ts">
import { listCollege, getCollege, delCollege, addCollege, updateCollege } from '@/api/xg/xsjcxx/collegemsg';
import { CollegeVO, CollegeQuery, CollegeForm } from '@/api/xg/xsjcxx/collegemsg/types';
import { ComponentInternalInstance, ref, reactive, toRefs, onMounted, getCurrentInstance } from 'vue';
import type { FormInstance as ElFormInstance } from 'element-plus';
interface DialogOption {
visible: boolean;
title: string;
}
interface PageData<T, Q> {
form: T;
queryParams: Q;
rules: Record<string, any[]>;
}
interface ComponentInternalInstance {
proxy?: any;
}
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const collegeList = ref<CollegeVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const collegeFormRef = ref<ElFormInstance>();
const dialog = reactive<DialogOption>({
visible: false,
title: ''
});
const initFormData: CollegeForm = {
deptId: undefined,
parentId: 101, // 固定为二级学院的父节点ID
deptName: undefined,
deptCategory: undefined,
orderNum: 0,
status: '0',
delFlag: undefined,
ancestors: undefined
};
const data = reactive<PageData<CollegeForm, CollegeQuery>>({
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
deptName: undefined,
deptCategory: undefined,
status: undefined,
parentId: 101, // 固定查询parent_id = 101的二级学院
params: {}
},
rules: {
deptName: [{ required: true, message: '学院名称不能为空', trigger: 'blur' }],
deptCategory: [{ required: true, message: '部门类别不能为空', trigger: 'blur' }],
orderNum: [{ required: true, message: '显示顺序不能为空', trigger: 'change' }],
status: [{ required: true, message: '状态不能为空', trigger: 'change' }]
}
});
const { queryParams, form, rules } = toRefs(data);
/** 查询二级学院列表 */
const getList = async () => {
loading.value = true;
const res = await listCollege(queryParams.value);
collegeList.value = res.data || [];
total.value = res.data ? res.data.length : 0;
loading.value = false;
};
/** 取消按钮 */
const cancel = () => {
reset();
dialog.visible = false;
};
/** 表单重置 */
const reset = () => {
form.value = { ...initFormData };
collegeFormRef.value?.resetFields();
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
handleQuery();
};
/** 多选框选中数据 */
const handleSelectionChange = (selection: CollegeVO[]) => {
ids.value = selection.map((item) => item.deptId);
single.value = selection.length != 1;
multiple.value = !selection.length;
};
/** 新增按钮操作 */
const handleAdd = () => {
reset();
dialog.visible = true;
dialog.title = '添加二级学院';
};
/** 修改按钮操作 */
const handleUpdate = async (row?: CollegeVO) => {
reset();
const _deptId = row?.deptId || ids.value[0];
const res = await getCollege(_deptId);
Object.assign(form.value, res.data);
dialog.visible = true;
dialog.title = '修改二级学院';
};
/** 提交按钮 */
const submitForm = () => {
collegeFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
buttonLoading.value = true;
if (form.value.deptId) {
await updateCollege(form.value).finally(() => (buttonLoading.value = false));
} else {
await addCollege(form.value).finally(() => (buttonLoading.value = false));
}
proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false;
await getList();
}
});
};
/** 删除按钮操作 */
const handleDelete = async (row?: CollegeVO) => {
const _deptIds = row?.deptId || ids.value;
// 获取要删除的学院名称
let deptNames = '';
if (row) {
// 单个删除时直接使用行数据中的学院名称
deptNames = row.deptName;
} else {
// 批量删除时,根据ids查找对应的学院名称并拼接
deptNames = collegeList.value
.filter((item) => ids.value.includes(item.deptId))
.map((item) => item.deptName)
.join('、');
}
await proxy?.$modal.confirm('是否确认删除学院"' + deptNames + '"?').finally(() => (loading.value = false));
await delCollege(_deptIds);
proxy?.$modal.msgSuccess('删除成功');
await getList();
};
onMounted(() => {
getList();
});
</script>
<style scoped>
/* 页面容器样式 */
.page-container {
padding: 8px;
}
/* 搜索按钮容器样式 */
.search-btn-container {
display: flex;
justify-content: flex-end;
margin-top: 10px;
}
.search-btn-container .el-form-item {
margin-bottom: 0 !important;
}
</style>
@@ -0,0 +1,499 @@
<template>
<div class="p-2 page-container">
<div class="flex h-full">
<!-- 左侧学院树 -->
<div class="w-80 mr-4">
<el-card shadow="never" class="h-full">
<template #header>
<div class="flex items-center">
<span class="text-lg font-medium">二级学院</span>
</div>
</template>
<el-tree
ref="collegeTreeRef"
:data="collegeTreeData"
:props="treeProps"
:current-node-key="currentNodeKey"
node-key="deptId"
highlight-current
@node-click="handleCollegeNodeClick"
class="college-tree"
>
<template #default="{ node, data }">
<div class="flex items-start py-1">
<span class="text-sm leading-6">{{ node.label }}</span>
<span class="text-xs text-gray-400 ml-2 leading-6">({{ data.deptCategory }})</span>
</div>
</template>
</el-tree>
</el-card>
</div>
<!-- 右侧专业列表 -->
<div class="flex-1">
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
<div v-show="showSearch" class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :model="queryParams" label-width="100px">
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="专业名称" prop="deptName">
<el-input v-model="queryParams.deptName" placeholder="请输入专业名称" clearable @keyup.enter="handleQuery" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="部门类别" prop="deptCategory">
<el-input v-model="queryParams.deptCategory" placeholder="请输入部门类别" clearable @keyup.enter="handleQuery" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
<el-option label="正常" :value="'0'" />
<el-option label="停用" :value="'1'" />
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24" class="search-btn-container">
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-card>
</div>
</transition>
<el-card shadow="never">
<template #header>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['majormsg:major:add']">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['majormsg:major:edit']"
>修改</el-button
>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['majormsg:major:remove']"
>删除</el-button
>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
</template>
<div class="table-wrapper">
<el-table v-loading="loading" border :data="majorList" @selection-change="handleSelectionChange" style="min-width: 900px; width: auto">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="部门ID" align="center" prop="deptId" :min-width="120" />
<el-table-column label="专业名称" align="center" prop="deptName" :min-width="220" />
<el-table-column label="部门类别" align="center" prop="deptCategory" :min-width="150" />
<el-table-column label="所属学院" align="center" prop="parentName" :min-width="180" />
<el-table-column label="显示顺序" align="center" prop="orderNum" :min-width="100" />
<el-table-column label="状态" align="center" prop="status" :min-width="100">
<template #default="scope">
<el-tag :type="scope.row.status === '0' ? 'success' : 'danger'">
{{ scope.row.status === '0' ? '正常' : '停用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="255" fixed="right">
<template #default="scope">
<el-tooltip content="修改" placement="top">
<el-button
link
type="primary"
plain
icon="Edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['majormsg:major:edit']"
></el-button>
</el-tooltip>
<el-tooltip content="删除" placement="top">
<el-button
link
type="danger"
plain
icon="Delete"
@click="handleDelete(scope.row)"
v-hasPermi="['majormsg:major:remove']"
></el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>
</div>
<pagination
v-show="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</el-card>
</div>
</div>
<!-- 添加或修改专业对话框 -->
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
<el-form ref="majorFormRef" :model="form" :rules="rules" label-width="100px">
<el-form-item label="所属学院" prop="parentId">
<el-select v-model="form.parentId" placeholder="请选择所属学院" style="width: 100%" @change="handleCollegeChange">
<el-option v-for="item in collegeOptions" :key="item.deptId" :label="item.deptName" :value="item.deptId" />
</el-select>
</el-form-item>
<el-form-item label="专业名称" prop="deptName">
<el-input v-model="form.deptName" placeholder="请输入专业名称" />
</el-form-item>
<el-form-item label="部门类别" prop="deptCategory">
<el-input v-model="form.deptCategory" placeholder="请输入部门类别编码(zy-开头)" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input-number v-model="form.orderNum" :min="0" :max="999" controls-position="right" placeholder="请输入显示顺序" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="form.status" placeholder="请选择状态" style="width: 100%">
<el-option label="正常" :value="'0'" />
<el-option label="停用" :value="'1'" />
</el-select>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="MajorMsg" lang="ts">
import { listMajor, getMajor, delMajor, addMajor, updateMajor, getCollegeTree } from '@/api/xg/xsjcxx/classmsg/majormsg';
import { MajorVO, MajorQuery, MajorForm, CollegeTreeNode } from '@/api/xg/xsjcxx/classmsg/majormsg/types';
import { ComponentInternalInstance, ref, reactive, toRefs, onMounted, getCurrentInstance } from 'vue';
import type { FormInstance as ElFormInstance } from 'element-plus';
import type { ElTree } from 'element-plus';
interface DialogOption {
visible: boolean;
title: string;
}
interface PageData<T, Q> {
form: T;
queryParams: Q;
rules: Record<string, any[]>;
}
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const majorList = ref<MajorVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(false);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const collegeTreeData = ref<CollegeTreeNode[]>([]);
const collegeOptions = ref<MajorVO[]>([]);
const selectedCollegeId = ref<number | string>('');
const currentNodeKey = ref<number | string | null>(null);
const queryFormRef = ref<ElFormInstance>();
const majorFormRef = ref<ElFormInstance>();
const collegeTreeRef = ref<InstanceType<typeof ElTree>>();
const treeProps = {
children: 'children',
label: 'deptName'
};
const dialog = reactive<DialogOption>({
visible: false,
title: ''
});
const initFormData: MajorForm = {
deptId: undefined,
parentId: undefined,
deptName: undefined,
deptCategory: 'zy-',
orderNum: 0,
status: '0',
delFlag: undefined,
ancestors: undefined
};
const data = reactive<PageData<MajorForm, MajorQuery>>({
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
deptName: undefined,
deptCategory: undefined,
deptCategoryLike: 'zy-',
parentId: undefined,
status: undefined,
params: {}
},
rules: {
parentId: [{ required: true, message: '所属学院不能为空', trigger: 'change' }],
deptName: [{ required: true, message: '专业名称不能为空', trigger: 'blur' }],
deptCategory: [{ required: true, message: '部门类别不能为空', trigger: 'blur' }],
orderNum: [{ required: true, message: '显示顺序不能为空', trigger: 'change' }],
status: [{ required: true, message: '状态不能为空', trigger: 'change' }]
}
});
const { queryParams, form, rules } = toRefs(data);
/** 查询专业列表 */
const getList = async () => {
// 确保学院数据已加载
if (collegeOptions.value.length === 0) {
await getCollegeList();
}
loading.value = true;
const res: any = await listMajor(queryParams.value);
// 处理后端返回的数据:由于后端接口不支持分页,返回所有数据,需要前端实现分页
let allMajors = (res && (res.rows || res.data)) || [];
const totalCount = allMajors.length;
// 为每个专业设置所属学院名称
allMajors = allMajors.map((major: MajorVO) => {
const college = collegeOptions.value.find((college) => college.deptId === major.parentId);
return {
...major,
parentName: college ? college.deptName : ''
};
});
// 前端分页:计算当前页的数据
const { pageNum, pageSize } = queryParams.value;
const startIndex = (pageNum - 1) * pageSize;
const endIndex = startIndex + pageSize;
const pageMajors = allMajors.slice(startIndex, endIndex);
majorList.value = pageMajors;
total.value = totalCount;
loading.value = false;
};
/** 获取学院树形结构 */
const getCollegeList = async () => {
const res = await getCollegeTree();
collegeTreeData.value = res.data || [];
collegeOptions.value = res.data || [];
};
/** 学院树节点点击事件 */
const handleCollegeNodeClick = (data: CollegeTreeNode) => {
selectedCollegeId.value = data.deptId as string;
currentNodeKey.value = data.deptId as string;
queryParams.value.parentId = data.deptId as number;
getList();
};
/** 学院选择框变化事件 */
const handleCollegeChange = (value: number) => {
if (value) {
const college = collegeOptions.value.find((item) => item.deptId === value);
if (college) {
form.value.parentName = college.deptName;
}
} else {
form.value.parentName = undefined;
}
};
/** 取消按钮 */
const cancel = () => {
reset();
dialog.visible = false;
};
/** 表单重置 */
const reset = () => {
form.value = { ...initFormData };
majorFormRef.value?.resetFields();
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
// 只重置搜索条件,保持选中的学院不变
queryParams.value.deptName = undefined;
queryParams.value.deptCategory = undefined;
queryParams.value.pageNum = 1;
// 重置后重新查询当前选中的学院
getList();
};
/** 多选框选中数据 */
const handleSelectionChange = (selection: MajorVO[]) => {
ids.value = selection.map((item) => item.deptId);
single.value = selection.length != 1;
multiple.value = !selection.length;
};
/** 新增按钮操作 */
const handleAdd = () => {
if (!selectedCollegeId.value) {
proxy?.$modal.msgWarning('请先选择左侧的二级学院');
return;
}
reset();
form.value.parentId = selectedCollegeId.value;
dialog.visible = true;
dialog.title = '添加专业';
};
/** 修改按钮操作 */
const handleUpdate = async (row?: MajorVO) => {
reset();
const _deptId = row?.deptId || ids.value[0];
const res = await getMajor(_deptId);
Object.assign(form.value, res.data);
dialog.visible = true;
dialog.title = '修改专业';
};
/** 提交按钮 */
const submitForm = () => {
majorFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
buttonLoading.value = true;
if (form.value.deptId) {
await updateMajor(form.value).finally(() => (buttonLoading.value = false));
} else {
await addMajor(form.value).finally(() => (buttonLoading.value = false));
}
proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false;
await getList();
}
});
};
/** 删除按钮操作 */
const handleDelete = async (row?: MajorVO) => {
const _deptIds = row?.deptId || ids.value;
// 获取要删除的专业名称
let deptNames = '';
if (row) {
// 单个删除时直接使用行数据中的专业名称
deptNames = row.deptName;
} else {
// 批量删除时,根据ids查找对应的专业名称并拼接
deptNames = majorList.value
.filter((item) => ids.value.includes(item.deptId))
.map((item) => item.deptName)
.join('、');
}
await proxy?.$modal.confirm('是否确认删除专业"' + deptNames + '"?').finally(() => (loading.value = false));
await delMajor(_deptIds);
proxy?.$modal.msgSuccess('删除成功');
await getList();
};
onMounted(() => {
getCollegeList();
// 页面初始化时不加载专业数据,等待用户选择学院
});
</script>
<style scoped>
/* 页面容器样式 */
.page-container {
padding: 8px;
height: calc(100vh - 120px);
}
/* 搜索按钮容器样式 */
.search-btn-container {
display: flex;
justify-content: flex-end;
margin-top: 10px;
}
.search-btn-container .el-form-item {
margin-bottom: 0 !important;
}
/* 学院树样式 */
.college-tree {
height: calc(100vh - 200px);
overflow-y: auto;
}
:deep(.el-tree-node__content) {
height: 40px;
padding: 0 8px;
}
:deep(.el-tree-node__label) {
font-size: 14px;
}
/* 表格布局修复:固定表格布局并允许横向滚动,避免无数据时列宽异常扩展 */
.table-wrapper {
overflow-x: auto;
}
/* 防止空数据时 el-table 的空白块被拉伸过宽 */
.table-wrapper :deep(.el-table__empty-block) {
min-width: 0 !important;
width: auto !important;
max-width: 100% !important;
display: flex;
justify-content: center;
}
.table-wrapper :deep(.el-table) {
width: auto !important;
}
/* 使用固定布局防止列在空数据时被浏览器不稳定拉伸 */
.table-wrapper :deep(.el-table) {
table-layout: fixed !important;
width: 100% !important;
}
.table-wrapper :deep(.el-table__body-wrapper) {
overflow-x: auto;
}
</style>
<style scoped>
/* 选中节点样式:加深背景并突出文字(覆盖 element-plus 默认) */
::deep(.el-tree-node__content.is-current) {
background-color: #409eff !important;
border-left: 4px solid #2b7cd1 !important;
border-radius: 4px 0 0 4px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}
/* 覆盖Element Plus默认的浅色选中样式 */
::deep(.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content) {
background-color: #409eff !important;
}
::deep(.el-tree-node__content.is-current .el-tree-node__label) {
color: #409eff;
font-weight: 600;
}
</style>