提交代码

This commit is contained in:
zlwu committed 2025-08-18 10:18:11 +08:00
1 parent adfbb74699
commit 6f02f0459e
4 files changed
+6721 -1283

No files matched your search

-633
View File
@@ -1,633 +0,0 @@
# 班干部管理API文档
## 概述
**模块名称**: 班干部管理
**模块标识**: xg:classCadre
**版本**: V1.0.0
**创建时间**: 2025-01-08
**更新时间**: 2025-01-08
## 功能描述
班干部管理模块提供完整的班级干部信息管理功能,包括班干部的任命、免职、调任、续任、辞职等全生命周期管理,以及统计分析和查询功能。
## 核心功能
- **基础管理**: 班干部信息的增删改查、导入导出
- **任免操作**: 任命、免职、调任、续任、辞职等操作
- **查询功能**: 按班级、学生、职务等多维度查询
- **统计分析**: 班干部统计数据和图表分析
- **权限控制**: 完整的角色权限管理
## API接口列表
### 基础管理接口
#### 1. 获取班干部列表
```http
GET /xg-xx/classCadre/list
```
**权限要求**: `xg:classCadre:list`
**请求参数**:
```json
{
"pageNum": 1,
"pageSize": 10,
"studentId": "学生ID",
"classId": "班级ID",
"positionId": "职务ID",
"positionLevel": "职务级别",
"status": "任职状态",
"isCurrent": "是否现任",
"startDate": "开始日期",
"endDate": "结束日期"
}
```
**响应示例**:
```json
{
"code": 200,
"msg": "查询成功",
"rows": [
{
"id": "1234567890123456789",
"studentId": "1001",
"studentName": "张三",
"classId": "C001",
"className": "计算机一班",
"positionId": "P001",
"positionName": "班长",
"positionLevel": 1,
"status": "在任",
"isCurrent": true,
"startDate": "2024-09-01",
"endDate": "2025-07-01",
"termMonths": 10,
"workPerformance": "优秀",
"phoneNumber": "13800138000",
"email": "zhangsan@example.com",
"createTime": "2024-09-01 10:00:00"
}
],
"total": 100
}
```
#### 2. 获取班干部详情
```http
GET /xg-xx/classCadre/{id}
```
**权限要求**: `xg:classCadre:query`
**路径参数**:
- `id`: 班干部记录ID
**响应示例**:
```json
{
"code": 200,
"msg": "查询成功",
"data": {
"id": "1234567890123456789",
"studentId": "1001",
"studentName": "张三",
"classId": "C001",
"className": "计算机一班",
"positionId": "P001",
"positionName": "班长",
"positionLevel": 1,
"status": "在任",
"isCurrent": true,
"startDate": "2024-09-01",
"endDate": "2025-07-01",
"termMonths": 10,
"workPerformance": "优秀",
"phoneNumber": "13800138000",
"email": "zhangsan@example.com",
"responsibilities": "负责班级日常管理工作",
"permissions": "班级活动组织权限",
"createTime": "2024-09-01 10:00:00"
}
}
```
#### 3. 新增班干部
```http
POST /xg-xx/classCadre
```
**权限要求**: `xg:classCadre:add`
**请求体**:
```json
{
"studentId": "1001",
"classId": "C001",
"positionId": "P001",
"startDate": "2024-09-01",
"endDate": "2025-07-01",
"termMonths": 10,
"workPerformance": "良好",
"phoneNumber": "13800138000",
"email": "zhangsan@example.com",
"responsibilities": "负责班级日常管理工作",
"permissions": "班级活动组织权限",
"remark": "备注信息"
}
```
**响应示例**:
```json
{
"code": 200,
"msg": "新增成功"
}
```
#### 4. 修改班干部
```http
PUT /xg-xx/classCadre
```
**权限要求**: `xg:classCadre:edit`
**请求体**:
```json
{
"id": "1234567890123456789",
"studentId": "1001",
"classId": "C001",
"positionId": "P001",
"startDate": "2024-09-01",
"endDate": "2025-07-01",
"termMonths": 10,
"workPerformance": "优秀",
"phoneNumber": "13800138000",
"email": "zhangsan@example.com",
"responsibilities": "负责班级日常管理工作",
"permissions": "班级活动组织权限",
"remark": "备注信息"
}
```
#### 5. 删除班干部
```http
DELETE /xg-xx/classCadre/{ids}
```
**权限要求**: `xg:classCadre:remove`
**路径参数**:
- `ids`: 班干部记录ID,多个用逗号分隔
#### 6. 导出班干部数据
```http
POST /xg-xx/classCadre/export
```
**权限要求**: `xg:classCadre:export`
**请求体**: 同列表查询参数
**响应**: Excel文件下载
### 业务功能接口
#### 7. 按班级查询班干部
```http
GET /xg-xx/classCadre/listByClass/{classId}
```
**权限要求**: `xg:classCadre:queryByClass`
**路径参数**:
- `classId`: 班级ID
#### 8. 按学生查询班干部
```http
GET /xg-xx/classCadre/listByStudent/{studentId}
```
**权限要求**: `xg:classCadre:queryByStudent`
**路径参数**:
- `studentId`: 学生ID
#### 9. 按职务查询班干部
```http
GET /xg-xx/classCadre/listByPosition/{positionId}
```
**权限要求**: `xg:classCadre:queryByPosition`
**路径参数**:
- `positionId`: 职务ID
#### 10. 获取我的班干部信息
```http
GET /xg-xx/classCadre/myInfo
```
**权限要求**: `xg:classCadre:query`
#### 11. 获取待处理任务
```http
GET /xg-xx/classCadre/pendingTasks
```
**权限要求**: `xg:classCadre:query`
#### 12. 获取可用职务选项
```http
GET /xg-xx/classCadre/availablePositions
```
**权限要求**: `xg:classCadre:query`
### 任免操作接口
#### 13. 任命班干部
```http
POST /xg-xx/classCadre/appoint
```
**权限要求**: `xg:classCadre:appoint`
**请求体**:
```json
{
"studentId": "1001",
"classId": "C001",
"positionId": "P001",
"startDate": "2024-09-01",
"endDate": "2025-07-01",
"reason": "任命原因",
"remark": "备注信息"
}
```
#### 14. 免职班干部
```http
POST /xg-xx/classCadre/dismiss
```
**权限要求**: `xg:classCadre:dismiss`
**请求体**:
```json
{
"id": "1234567890123456789",
"reason": "免职原因",
"effectiveDate": "2024-12-01",
"remark": "备注信息"
}
```
#### 15. 调任班干部
```http
POST /xg-xx/classCadre/transfer
```
**权限要求**: `xg:classCadre:transfer`
**请求体**:
```json
{
"id": "1234567890123456789",
"newPositionId": "P002",
"reason": "调任原因",
"effectiveDate": "2024-12-01",
"remark": "备注信息"
}
```
#### 16. 续任班干部
```http
POST /xg-xx/classCadre/renew
```
**权限要求**: `xg:classCadre:renew`
**请求体**:
```json
{
"id": "1234567890123456789",
"newEndDate": "2025-12-01",
"reason": "续任原因",
"remark": "备注信息"
}
```
#### 17. 辞职申请
```http
POST /xg-xx/classCadre/resign
```
**权限要求**: `xg:classCadre:resign`
**请求体**:
```json
{
"id": "1234567890123456789",
"reason": "辞职原因",
"effectiveDate": "2024-12-01",
"remark": "备注信息"
}
```
### 统计查询接口
#### 18. 获取统计数据
```http
GET /xg-xx/classCadre/statistics
```
**权限要求**: `xg:classCadre:statistics`
**请求参数**:
```json
{
"collegeId": "学院ID",
"gradeId": "年级ID",
"startDate": "开始日期",
"endDate": "结束日期"
}
```
**响应示例**:
```json
{
"code": 200,
"msg": "查询成功",
"data": {
"totalCount": 500,
"currentCount": 450,
"excellentCount": 200,
"expiringSoonCount": 50,
"positionDistribution": [
{"positionName": "班长", "count": 50},
{"positionName": "副班长", "count": 45}
],
"statusDistribution": [
{"status": "在任", "count": 450},
{"status": "已免职", "count": 30}
],
"collegeStatistics": [
{"collegeName": "计算机学院", "count": 100},
{"collegeName": "机械学院", "count": 80}
]
}
}
```
#### 19. 获取按学院统计
```http
GET /xg-xx/classCadre/statisticsByCollege
```
**权限要求**: `xg:classCadre:statistics`
#### 20. 获取按年级统计
```http
GET /xg-xx/classCadre/statisticsByGrade
```
**权限要求**: `xg:classCadre:statistics`
#### 21. 获取到期提醒
```http
GET /xg-xx/classCadre/expiringReminder
```
**权限要求**: `xg:classCadre:expireReminder`
**请求参数**:
```json
{
"days": 30
}
```
### 辅助功能接口
#### 22. 批量操作
```http
POST /xg-xx/classCadre/batch
```
**权限要求**: `xg:classCadre:batch`
**请求体**:
```json
{
"operation": "dismiss",
"ids": ["id1", "id2", "id3"],
"reason": "批量操作原因",
"effectiveDate": "2024-12-01"
}
```
#### 23. 数据校验
```http
POST /xg-xx/classCadre/validate
```
**权限要求**: `xg:classCadre:validate`
**请求体**:
```json
{
"studentId": "1001",
"classId": "C001",
"positionId": "P001",
"startDate": "2024-09-01",
"endDate": "2025-07-01"
}
```
## 数据模型
### 班干部信息 (XgClassCadre)
| 字段名 | 类型 | 说明 | 必填 |
|--------|------|------|------|
| id | Long | 主键ID | 是 |
| studentId | String | 学生ID | 是 |
| studentName | String | 学生姓名 | 是 |
| classId | String | 班级ID | 是 |
| className | String | 班级名称 | 是 |
| positionId | String | 职务ID | 是 |
| positionName | String | 职务名称 | 是 |
| positionLevel | Integer | 职务级别 | 是 |
| status | String | 任职状态 | 是 |
| isCurrent | Boolean | 是否现任 | 是 |
| startDate | Date | 任职开始日期 | 是 |
| endDate | Date | 任职结束日期 | 否 |
| termMonths | Integer | 任期月数 | 否 |
| workPerformance | String | 工作表现 | 否 |
| phoneNumber | String | 联系电话 | 否 |
| email | String | 邮箱地址 | 否 |
| responsibilities | String | 职责描述 | 否 |
| permissions | String | 权限描述 | 否 |
| remark | String | 备注 | 否 |
### 班干部变更记录 (XgCadreChangeLog)
| 字段名 | 类型 | 说明 | 必填 |
|--------|------|------|------|
| id | Long | 主键ID | 是 |
| cadreId | Long | 班干部ID | 是 |
| operationType | String | 操作类型 | 是 |
| oldPositionId | String | 原职务ID | 否 |
| newPositionId | String | 新职务ID | 否 |
| reason | String | 变更原因 | 否 |
| effectiveDate | Date | 生效日期 | 是 |
| operatorId | Long | 操作人ID | 是 |
| operatorName | String | 操作人姓名 | 是 |
| remark | String | 备注 | 否 |
### 班干部职务配置 (XgCadrePositionConfig)
| 字段名 | 类型 | 说明 | 必填 |
|--------|------|------|------|
| id | Long | 主键ID | 是 |
| positionCode | String | 职务代码 | 是 |
| positionName | String | 职务名称 | 是 |
| positionLevel | Integer | 职务级别 | 是 |
| maxCount | Integer | 最大人数 | 是 |
| responsibilities | String | 职责描述 | 否 |
| permissions | String | 权限描述 | 否 |
| isActive | Boolean | 是否启用 | 是 |
| sortOrder | Integer | 排序 | 是 |
| remark | String | 备注 | 否 |
## 状态码说明
### 任职状态 (status)
- `draft`: 草稿
- `waiting`: 待审核
- `complete`: 在任
- `expired`: 已到期
- `dismissed`: 已免职
- `transferred`: 已调任
- `resigned`: 已辞职
### 操作类型 (operationType)
- `appoint`: 任命
- `dismiss`: 免职
- `transfer`: 调任
- `renew`: 续任
- `resign`: 辞职
- `modify`: 修改
### 工作表现 (workPerformance)
- `excellent`: 优秀
- `good`: 良好
- `average`: 一般
- `poor`: 较差
## 权限说明
### 角色权限分配
| 角色 | 权限范围 | 说明 |
|------|----------|------|
| 超级管理员 | 全部权限 | 所有操作权限 |
| 学生处管理员 | 全部权限 | 所有操作权限 |
| 二级学院管理员 | 除删除外的权限 | 不能删除班干部记录 |
| 辅导员 | 基础管理和任免权限 | 可进行班干部任免操作 |
| 班级教师 | 查看和统计权限 | 只能查看相关信息 |
| 学生 | 仅查看权限 | 只能查看班干部信息 |
### 权限标识列表
| 权限标识 | 权限名称 | 说明 |
|----------|----------|------|
| xg:classCadre:list | 班干部列表 | 查看班干部列表 |
| xg:classCadre:query | 班干部查询 | 查询班干部详情 |
| xg:classCadre:add | 班干部新增 | 新增班干部 |
| xg:classCadre:edit | 班干部修改 | 修改班干部信息 |
| xg:classCadre:remove | 班干部删除 | 删除班干部记录 |
| xg:classCadre:export | 班干部导出 | 导出班干部数据 |
| xg:classCadre:import | 班干部导入 | 导入班干部数据 |
| xg:classCadre:appoint | 班干部任命 | 任命班干部 |
| xg:classCadre:dismiss | 班干部免职 | 免职班干部 |
| xg:classCadre:transfer | 班干部调任 | 调任班干部 |
| xg:classCadre:renew | 班干部续任 | 续任班干部 |
| xg:classCadre:resign | 班干部辞职 | 辞职申请 |
| xg:classCadre:statistics | 统计查看 | 查看统计数据 |
| xg:classCadre:batch | 批量操作 | 批量处理 |
| xg:classCadre:validate | 数据校验 | 数据有效性校验 |
## 错误码说明
| 错误码 | 错误信息 | 说明 |
|--------|----------|------|
| 40001 | 学生不存在 | 指定的学生ID不存在 |
| 40002 | 班级不存在 | 指定的班级ID不存在 |
| 40003 | 职务不存在 | 指定的职务ID不存在 |
| 40004 | 学生已担任该职务 | 学生已经担任该职务 |
| 40005 | 职务人数已满 | 该职务已达到最大人数限制 |
| 40006 | 任职日期冲突 | 任职时间与现有记录冲突 |
| 40007 | 班干部记录不存在 | 指定的班干部记录不存在 |
| 40008 | 操作权限不足 | 当前用户没有操作权限 |
| 40009 | 数据校验失败 | 提交的数据不符合规则 |
| 40010 | 批量操作失败 | 批量操作部分失败 |
## 使用示例
### 1. 查询班级班干部
```javascript
// 查询计算机一班的所有班干部
const response = await api.get('/xg-xx/classCadre/listByClass/C001');
console.log(response.data);
```
### 2. 任命班干部
```javascript
// 任命张三为班长
const appointData = {
studentId: '1001',
classId: 'C001',
positionId: 'P001',
startDate: '2024-09-01',
endDate: '2025-07-01',
reason: '综合表现优秀,具备领导能力'
};
const response = await api.post('/xg-xx/classCadre/appoint', appointData);
```
### 3. 获取统计数据
```javascript
// 获取计算机学院的班干部统计
const response = await api.get('/xg-xx/classCadre/statistics', {
params: { collegeId: 'COL001' }
});
console.log(response.data);
```
## 注意事项
1. **数据一致性**: 班干部信息与学生信息、班级信息保持一致
2. **权限控制**: 严格按照角色权限进行操作控制
3. **变更记录**: 所有重要操作都会记录变更日志
4. **任期管理**: 注意任期时间的合理性和连续性
5. **状态管理**: 正确维护班干部的任职状态
6. **并发控制**: 防止同时操作导致的数据冲突
## 更新日志
| 版本 | 日期 | 更新内容 |
|------|------|----------|
| V1.0.0 | 2025-01-08 | 初始版本,完整的班干部管理API |
---
**文档维护**: Cursor AI 辅助
**最后更新**: 2025-01-08
**文档状态**: 已完成
@@ -1,299 +0,0 @@
# 班级教师关联管理API文档
## 文档信息
- **模块名称**: 班级教师关联管理
- **版本**: 1.0.1
- **最后更新**: 2025-07-24
- **更新人**: zlwu
## API概览
本文档主要描述班级与教师(班主任/辅导员)关联的相关API接口,提供班主任和辅导员的设置、更新、查询等功能。
### 基础数据结构
#### 班级教师关联对象 (XgClassTeacherCounselorRelBo)
| 字段名 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| id | Long | 否(新增)/是(修改) | 主键ID |
| classId | Long | 是 | 班级ID |
| teacherId | Long | 否 | 班主任ID |
| teacherName | String | 否 | 班主任姓名 |
| counselorId | Long | 否 | 辅导员ID |
| counselorName | String | 否 | 辅导员姓名 |
| relationType | Integer | 是 | 关联类型: 1-班主任, 2-辅导员 |
| startDate | Date | 否 | 开始日期 |
| endDate | Date | 否 | 结束日期 |
| remark | String | 否 | 备注信息 |
| createTime | Date | 是 | 创建时间 |
| createBy | Long | 是 | 创建者 |
| updateTime | Date | 是 | 更新时间 |
| updateBy | Long | 是 | 更新者 |
## 接口列表
### 1. 查询班级教师关联列表
- **接口URL**: `/teacherCounselorRel/classTeacherCounselorRel/list`
- **请求方式**: GET
- **权限标识**: `teacherCounselorRel:classTeacherCounselorRel:list`
#### 请求参数
| 参数名 | 类型 | 必填 | 位置 | 描述 |
| --- | --- | --- | --- | --- |
| classId | Long | 否 | query | 班级ID |
| relationType | Integer | 否 | query | 关联类型: 1-班主任, 2-辅导员 |
| pageNum | Integer | 否 | query | 当前页码, 默认为1 |
| pageSize | Integer | 否 | query | 每页数量, 默认为10 |
#### 响应结果
```json
{
"total": 100,
"rows": [
{
"id": 1,
"classId": 1001,
"teacherId": 2001,
"teacherName": "张老师",
"counselorId": 3001,
"counselorName": "李辅导员",
"relationType": 1,
"remark": "高一年级班主任",
"createTime": "2025-07-01 10:00:00",
"createBy": 1,
"updateTime": "2025-07-20 15:30:00",
"updateBy": 1
}
],
"code": 200,
"msg": "查询成功"
}
```
### 2. 获取班级教师关联详情
- **接口URL**: `/teacherCounselorRel/classTeacherCounselorRel/{id}`
- **请求方式**: GET
- **权限标识**: `teacherCounselorRel:classTeacherCounselorRel:query`
#### 请求参数
| 参数名 | 类型 | 必填 | 位置 | 描述 |
| --- | --- | --- | --- | --- |
| id | Long | 是 | path | 关联ID |
#### 响应结果
```json
{
"code": 200,
"data": {
"id": 1,
"classId": 1001,
"teacherId": 2001,
"teacherName": "张老师",
"counselorId": 3001,
"counselorName": "李辅导员",
"relationType": 1,
"remark": "高一年级班主任",
"createTime": "2025-07-01 10:00:00",
"createBy": 1,
"updateTime": "2025-07-20 15:30:00",
"updateBy": 1
},
"msg": "操作成功"
}
```
### 3. 新增班级教师关联
- **接口URL**: `/teacherCounselorRel/classTeacherCounselorRel`
- **请求方式**: POST
- **权限标识**: `teacherCounselorRel:classTeacherCounselorRel:add`
#### 请求参数
| 参数名 | 类型 | 必填 | 位置 | 描述 |
| --- | --- | --- | --- | --- |
| classId | Long | 是 | body | 班级ID |
| teacherId | Long | 否 | body | 班主任ID |
| teacherName | String | 否 | body | 班主任姓名 |
| counselorId | Long | 否 | body | 辅导员ID |
| counselorName | String | 否 | body | 辅导员姓名 |
| relationType | Integer | 是 | body | 关联类型: 1-班主任, 2-辅导员 |
| remark | String | 否 | body | 备注信息 |
#### 请求示例
```json
{
"classId": 1001,
"teacherId": 2001,
"teacherName": "张老师",
"relationType": 1,
"remark": "高一年级班主任"
}
```
#### 响应结果
```json
{
"code": 200,
"msg": "操作成功"
}
```
### 4. 修改班级教师关联
- **接口URL**: `/teacherCounselorRel/classTeacherCounselorRel`
- **请求方式**: PUT
- **权限标识**: `teacherCounselorRel:classTeacherCounselorRel:edit`
#### 请求参数
| 参数名 | 类型 | 必填 | 位置 | 描述 |
| --- | --- | --- | --- | --- |
| id | Long | 是 | body | 关联ID |
| classId | Long | 否 | body | 班级ID |
| teacherId | Long | 否 | body | 班主任ID |
| teacherName | String | 否 | body | 班主任姓名 |
| counselorId | Long | 否 | body | 辅导员ID |
| counselorName | String | 否 | body | 辅导员姓名 |
| relationType | Integer | 否 | body | 关联类型: 1-班主任, 2-辅导员 |
| remark | String | 否 | body | 备注信息 |
#### 班主任更换机制
当通过此接口更换班主任时(relationType=1),系统会执行以下操作:
1. 将当前班级的所有未删除的班主任记录标记为已删除(deleted=1)
2. 设置原班主任记录的结束日期(endDate)为当前日期时间
3. 创建新的班主任关联记录,设置开始日期(startDate)为当前日期时间
4. 同步更新班级表中的班主任信息
这样确保了班主任更换记录的完整性,可以通过查看历史记录追踪班级班主任的变更情况。
#### 请求示例
```json
{
"id": 1,
"classId": 1001,
"teacherId": 2002,
"teacherName": "王老师",
"relationType": 1,
"remark": "高一年级新班主任"
}
```
#### 响应结果
```json
{
"code": 200,
"msg": "操作成功"
}
```
### 5. 删除班级教师关联
- **接口URL**: `/teacherCounselorRel/classTeacherCounselorRel/{ids}`
- **请求方式**: DELETE
- **权限标识**: `teacherCounselorRel:classTeacherCounselorRel:remove`
#### 请求参数
| 参数名 | 类型 | 必填 | 位置 | 描述 |
| --- | --- | --- | --- | --- |
| ids | Long[] | 是 | path | 关联ID数组,多个以英文逗号分隔 |
#### 响应结果
```json
{
"code": 200,
"msg": "操作成功"
}
```
### 6. 导出班级教师关联数据
- **接口URL**: `/teacherCounselorRel/classTeacherCounselorRel/export`
- **请求方式**: POST
- **权限标识**: `teacherCounselorRel:classTeacherCounselorRel:export`
- **响应类型**: application/vnd.ms-excel
#### 请求参数
| 参数名 | 类型 | 必填 | 位置 | 描述 |
| --- | --- | --- | --- | --- |
| classId | Long | 否 | query | 班级ID |
| relationType | Integer | 否 | query | 关联类型: 1-班主任, 2-辅导员 |
## 前端调用示例
### 设置班主任
```typescript
// 导入API
import { addClassTeacherCounselorRel } from '@/api/xg/classTeacherCounselorRel';
// 构造数据
const teacherRelData = {
classId: classId,
teacherId: teacherId,
teacherName: teacherName,
relationType: 1 // 1表示班主任类型
};
// 调用API
try {
await addClassTeacherCounselorRel(teacherRelData);
this.$modal.msgSuccess('班主任设置成功');
} catch (error) {
this.$modal.msgError('设置失败,请重试');
}
```
### 设置辅导员
```typescript
// 导入API
import { addClassTeacherCounselorRel } from '@/api/xg/classTeacherCounselorRel';
// 构造数据
const counselorRelData = {
classId: classId,
counselorId: counselorId,
counselorName: counselorName,
relationType: 2 // 2表示辅导员类型
};
// 调用API
try {
await addClassTeacherCounselorRel(counselorRelData);
this.$modal.msgSuccess('辅导员设置成功');
} catch (error) {
this.$modal.msgError('设置失败,请重试');
}
```
## 错误码说明
| 错误码 | 描述 | 解决方案 |
| --- | --- | --- |
| 400 | 请求参数错误 | 检查请求参数是否正确 |
| 401 | 未授权 | 检查登录状态和权限 |
| 500 | 服务器内部错误 | 联系管理员 |
## 更新记录
| 日期 | 更新人 | 版本 | 变更内容 |
| --- | --- | --- | --- |
| 2025-07-24 | zlwu | 1.0.1 | 添加班主任更换机制说明,补充开始/结束日期字段 |
| 2025-07-24 | zlwu | 1.0.0 | 初始版本 |
@@ -1,351 +0,0 @@
# 移动端 iconfont 图标使用指南
## 📋 概述
本项目已集成 iconfont.cn 图标字体库,提供丰富的矢量图标,替代 emoji 和 uview-plus 图标,确保跨平台兼容性。
## 🎯 解决的问题
- **uview-plus 图标显示异常**:u-icon 组件在某些环境下显示为横线
- **emoji 兼容性问题**:不同设备和系统 emoji 显示效果不一致
- **图标扩展性**:iconfont 提供更丰富的图标选择
## 📦 安装配置
### 1. 字体文件配置
**文件位置**:`mobile/src/static/fonts/iconfont.css`
```css
@font-face {
font-family: 'iconfont';
src: url('//at.alicdn.com/t/c/font_4793979_9m3yqql3ybj.woff2?t=1704153600') format('woff2'), url('//at.alicdn.com/t/c/font_4793979_9m3yqql3ybj.woff?t=1704153600')
format('woff'),
url('//at.alicdn.com/t/c/font_4793979_9m3yqql3ybj.ttf?t=1704153600') format('truetype');
}
.iconfont {
font-family: 'iconfont' !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
```
### 2. 全局引入
**文件位置**:`mobile/src/main.js`
```javascript
// 导入 iconfont 样式
import '@/static/fonts/iconfont.css';
```
## 🎨 可用图标列表
### 基础图标
| 图标 | 类名 | 说明 | 编码 |
| ---- | ---------------- | -------- | ------- |
| 👤 | `icon-user` | 用户 | `\e7ae` |
| 🔒 | `icon-lock` | 锁定 | `\e60e` |
| 👁️ | `icon-eye` | 显示密码 | `\e61c` |
| 🙈 | `icon-eye-close` | 隐藏密码 | `\e61d` |
### 操作图标
| 图标 | 类名 | 说明 | 编码 |
| ---- | ------------- | ---- | ------- |
| 🚪 | `icon-login` | 登录 | `\e612` |
| 🔍 | `icon-search` | 搜索 | `\e6b4` |
| ➕ | `icon-add` | 添加 | `\e6a4` |
| ✅ | `icon-check` | 确认 | `\e6a8` |
| ❌ | `icon-close` | 关闭 | `\e6a9` |
### 导航图标
| 图标 | 类名 | 说明 | 编码 |
| ---- | ------------------ | ------ | ------- |
| 🏠 | `icon-home` | 首页 | `\e65e` |
| 💬 | `icon-message` | 消息 | `\e6a7` |
| ⚙️ | `icon-setting` | 设置 | `\e6b8` |
| ➡️ | `icon-arrow-right` | 箭头右 | `\e6a3` |
### 联系图标
| 图标 | 类名 | 说明 | 编码 |
| ---- | ------------ | ---- | ------- |
| 📞 | `icon-phone` | 电话 | `\e69a` |
| 📧 | `icon-mail` | 邮箱 | `\e692` |
## 🚀 使用方法
### 1. 基础用法
```vue
<template>
<!-- 基础图标 -->
<text class="iconfont icon-user"></text>
<text class="iconfont icon-lock"></text>
<!-- 带样式的图标 -->
<text class="iconfont icon-home custom-icon"></text>
</template>
<style>
.custom-icon {
font-size: 24px;
color: #5d87ff;
}
</style>
```
### 2. 登录表单中的应用
```vue
<template>
<view class="input-group">
<!-- 用户名输入框 -->
<text class="iconfont icon-user input-icon"></text>
<input class="login-input" type="text" placeholder="账号" />
</view>
<view class="input-group">
<!-- 密码输入框 -->
<text class="iconfont icon-lock input-icon"></text>
<input class="login-input" type="password" placeholder="密码" />
</view>
<!-- 登录按钮 -->
<button class="login-btn">
<text class="iconfont icon-login"></text>
<text>登录</text>
</button>
</template>
<style lang="scss">
.input-group {
position: relative;
display: flex;
align-items: center;
}
.input-icon {
position: absolute;
left: 14px;
z-index: 2;
font-size: 18px;
color: #b0b8c9;
}
.login-input {
width: 100%;
height: 44px;
padding: 0 12px 0 44px;
border: 1px solid #e3e8f0;
border-radius: 8px;
background: #fff;
}
.login-btn {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
background: #5d87ff;
color: #fff;
}
</style>
```
### 3. 动态图标切换
```vue
<template>
<view class="password-toggle">
<text
:class="['iconfont', showPassword ? 'icon-eye-close' : 'icon-eye']"
@click="togglePassword"
></text>
</view>
</template>
<script>
export default {
data() {
return {
showPassword: false,
};
},
methods: {
togglePassword() {
this.showPassword = !this.showPassword;
},
},
};
</script>
```
## 🎨 样式自定义
### 1. 基础样式属性
```css
.iconfont {
/* 字体大小 */
font-size: 16px;
/* 颜色 */
color: #333;
/* 其他样式 */
opacity: 0.8;
transition: all 0.3s ease;
}
```
### 2. 响应式设计
```css
/* 小屏幕 */
@media (max-width: 375px) {
.iconfont {
font-size: 14px;
}
}
/* 大屏幕 */
@media (min-width: 768px) {
.iconfont {
font-size: 20px;
}
}
```
### 3. 主题适配
```css
/* 亮色主题 */
.light-theme .iconfont {
color: #333;
}
/* 暗色主题 */
.dark-theme .iconfont {
color: #fff;
}
```
## 🔧 扩展图标
### 1. 从 iconfont.cn 添加新图标
1. **访问项目**:打开 [iconfont.cn](https://www.iconfont.cn/) 的项目页面
2. **选择图标**:浏览并添加需要的图标到项目
3. **生成代码**:下载新的字体文件和 CSS 代码
4. **更新项目**:替换 `iconfont.css` 中的字体链接和图标类名
### 2. 图标命名规范
```css
/* 建议的命名格式 */
.icon-[功能]-[状态]
例如:
.icon-user /* 用户图标 */
.icon-eye-open /* 眼睛打开 */
.icon-eye-close /* 眼睛关闭 */
.icon-arrow-left /* 左箭头 */
.icon-arrow-right; /* 右箭头 */
```
## 📱 演示页面
**页面位置**:`mobile/src/pages/iconfont-demo/index.vue`
访问路径:`/pages/iconfont-demo/index`
演示页面包含:
- 所有可用图标的预览
- 图标分类展示(基础、操作、导航、联系)
- 使用代码示例
- 自定义样式演示
## ⚠️ 注意事项
### 1. 兼容性
- ✅ **支持平台**:H5、微信小程序、App、支付宝小程序
- ✅ **浏览器支持**:Chrome、Safari、Firefox、Edge
- ✅ **设备支持**:iOS、Android、HarmonyOS
### 2. 性能优化
```css
/* 字体预加载 */
.iconfont {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
```
### 3. 缓存策略
- 字体文件使用 CDN 加载,自动缓存
- 本地 CSS 文件确保离线可用
- 建议定期更新字体链接时间戳
### 4. 回退方案
```vue
<template>
<!-- 图标 + 文字回退 -->
<view class="icon-with-fallback">
<text class="iconfont icon-user"></text>
<text class="icon-fallback">用户</text>
</view>
</template>
<style>
.icon-fallback {
display: none;
}
/* 当字体加载失败时显示文字 */
@font-face {
font-family: 'iconfont-fallback';
src: local('Arial'), local('sans-serif');
}
.iconfont:before {
font-family: 'iconfont', 'iconfont-fallback';
}
</style>
```
## 📚 相关文件
- **样式文件**:`mobile/src/static/fonts/iconfont.css`
- **演示页面**:`mobile/src/pages/iconfont-demo/index.vue`
- **登录页面**:`mobile/src/pages/login/index.vue`
- **配置文件**:`mobile/src/main.js`
## 🎯 最佳实践
1. **统一使用**:项目中统一使用 iconfont,避免混用多种图标方案
2. **语义化命名**:使用有意义的类名,便于维护
3. **适当大小**:根据使用场景选择合适的字体大小
4. **颜色一致**:遵循设计规范,保持图标颜色的一致性
5. **性能考虑**:避免一次性加载过多不使用的图标
## 📝 更新日志
- **2025-07-01**:初始版本,集成 iconfont 字体库
- **预计扩展**:根据业务需求持续添加新图标
---
**维护者**:移动端开发团队
**更新时间**:2025-07-01
File diff suppressed because it is too large. Load diff