Files
zyt/DOCTOR_FEATURE_IMPLEMENTATION.md
T
2026-03-11 14:33:49 +08:00

275 lines
6.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 医生功能实现总结
## 功能概述
实现了小程序首页医生展示功能,包括:
1. 古典卷轴风格幻灯片
2. 动态医生列表展示(从后端API获取)
3. 医生卡片点击跳转到挂号页面
## 后端实现
### 1. 医生逻辑层 (DoctorLogic)
**文件**: `server/app/api/logic/DoctorLogic.php`
**功能**:
- `getDoctorList()` - 获取医生列表,支持分页和搜索
- `getDoctorDetail()` - 获取单个医生详情
- `getDoctorRoster()` - 获取医生排班信息
**数据来源**: `zyt_admin` 表(role_id = 1 的医生)
**返回字段**:
```php
[
'id' => 医生ID,
'name' => 医生名字,
'account' => 医生账号,
'avatar' => 医生头像URL,
'mobile' => 医生手机,
'email' => 医生邮箱,
'specialty' => 专科,
'title' => 职位,
'rating' => 评分
]
```
### 2. 医生控制器 (DoctorController)
**文件**: `server/app/api/controller/DoctorController.php`
**API端点**:
- `GET /api/doctor/lists` - 获取医生列表
- `GET /api/doctor/detail` - 获取医生详情
- `GET /api/doctor/roster` - 获取医生排班
**无需登录的端点**: `lists`, `detail`
## 前端实现
### 1. API 服务层
**文件**: `TUICallKit-Vue3/utils/api.js`
**功能**:
- 统一的API请求管理
- 自动添加认证token
- 错误处理
**使用示例**:
```javascript
import { doctorApi } from '@/utils/api'
// 获取医生列表
const response = await doctorApi.getDoctorList({
page_no: 1,
page_size: 10
})
```
### 2. 首页组件
**文件**: `TUICallKit-Vue3/pages/index/index.vue`
**功能**:
- 古典卷轴风格幻灯片(自动轮播)
- 医生列表展示(动态加载)
- 医生卡片交互(点击跳转)
**样式特点**:
- 金色卷轴装饰(#d4af37
- 渐变背景效果
- 响应式布局
- 医生卡片网格展示(2列)
## 数据库表结构
### zyt_admin 表(医生数据来源)
```sql
CREATE TABLE `zyt_admin` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`name` varchar(50) NOT NULL COMMENT '管理员名称',
`account` varchar(50) NOT NULL COMMENT '管理员账号',
`avatar` varchar(255) DEFAULT NULL COMMENT '头像',
`mobile` varchar(20) DEFAULT NULL COMMENT '手机号',
`email` varchar(100) DEFAULT NULL COMMENT '邮箱',
`role_id` int(11) DEFAULT NULL COMMENT '角色ID1=医生)',
`disable` tinyint(1) DEFAULT '0' COMMENT '是否禁用(0=否,1=是)',
`create_time` int(10) unsigned DEFAULT NULL COMMENT '创建时间',
`update_time` int(10) unsigned DEFAULT NULL COMMENT '更新时间',
`delete_time` int(10) unsigned DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
KEY `idx_role_id` (`role_id`),
KEY `idx_disable` (`disable`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管理员表';
```
### la_doctor_roster 表(医生排班)
```sql
CREATE TABLE `la_doctor_roster` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`doctor_id` int(11) NOT NULL COMMENT '医生ID',
`date` date NOT NULL COMMENT '日期',
`period` varchar(20) NOT NULL COMMENT '时段(morning/afternoon',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态(1-出诊 2-停诊 3-休息 4-请假)',
`quota` int(11) DEFAULT '0' COMMENT '号源数',
`max_patients` int(11) DEFAULT '0' COMMENT '最大接诊数',
`create_time` int(11) NOT NULL COMMENT '创建时间',
`update_time` int(11) NOT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_doctor_date_period` (`doctor_id`,`date`,`period`),
KEY `idx_date` (`date`),
KEY `idx_doctor` (`doctor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='医生排班表';
```
## 配置说明
### 后端配置
1. 确保 `zyt_admin` 表中有医生记录(role_id = 1
2. 医生的 `disable` 字段应为 0
3. 医生的 `avatar` 字段应包含完整的URL或相对路径
### 前端配置
1. 创建 `.env` 文件(参考 `.env.example`):
```
VUE_APP_API_URL=http://your-api-domain/api
```
2. 或在 `utils/api.js` 中直接修改 `API_BASE_URL`
## 使用流程
### 1. 后端准备
```bash
# 确保医生数据已添加到 zyt_admin 表
# 示例SQL
INSERT INTO zyt_admin (name, account, avatar, mobile, email, role_id, disable, create_time)
VALUES ('张医生', 'doctor1', 'http://example.com/avatar.jpg', '13800138000', 'doctor@example.com', 1, 0, UNIX_TIMESTAMP());
```
### 2. 前端使用
首页会自动:
1. 加载医生列表
2. 展示医生卡片
3. 支持点击跳转到挂号页面
## 测试
### 运行测试脚本
```bash
php server/test_doctor_api.php
```
### 手动测试
1. 获取医生列表:
```
GET http://localhost:8000/api/doctor/lists?page_no=1&page_size=10
```
2. 获取医生详情:
```
GET http://localhost:8000/api/doctor/detail?id=1
```
3. 获取医生排班:
```
GET http://localhost:8000/api/doctor/roster?doctor_id=1&date=2024-03-11
```
## 扩展功能
### 1. 添加医生专科和职位
修改 `DoctorLogic.php`
```php
// 从科室表获取专科
$doctor['specialty'] = Dept::find($doctor['dept_id'])->name ?? '医生';
// 从职位表获取职位
$doctor['title'] = Jobs::find($doctor['jobs_id'])->name ?? '医生';
```
### 2. 添加医生评分
```php
// 从评价表计算平均评分
$doctor['rating'] = DoctorRating::where('doctor_id', $doctor['id'])
->avg('rating') ?? '4.8';
```
### 3. 添加医生简介
```php
// 从医生表获取简介
$doctor['introduction'] = DoctorInfo::where('doctor_id', $doctor['id'])
->value('introduction') ?? '';
```
### 4. 添加在线状态
```php
// 检查医生是否在线
$doctor['is_online'] = DoctorSession::where('doctor_id', $doctor['id'])
->where('expire_time', '>', time())
->exists();
```
## 常见问题
### Q: 医生列表为空?
A:
1. 检查 `zyt_admin` 表中是否有 `role_id = 1` 的记录
2. 检查医生的 `disable` 字段是否为 0
3. 检查API是否正确返回数据
### Q: 头像无法显示?
A:
1. 确保 `avatar` 字段包含完整的URL
2. 检查图片服务器是否可访问
3. 检查CORS配置
### Q: 如何修改医生信息?
A:
1. 在后台管理系统中编辑医生信息
2. 或直接修改 `zyt_admin`
### Q: 如何添加新医生?
A:
1. 在后台管理系统中创建新管理员
2. 设置 `role_id = 1`(医生角色)
3. 设置 `disable = 0`(启用)
## 相关文件清单
### 后端文件
- `server/app/api/logic/DoctorLogic.php` - 医生逻辑层
- `server/app/api/controller/DoctorController.php` - 医生控制器
- `server/test_doctor_api.php` - API测试脚本
### 前端文件
- `TUICallKit-Vue3/utils/api.js` - API服务层
- `TUICallKit-Vue3/pages/index/index.vue` - 首页组件
- `TUICallKit-Vue3/.env.example` - 环境配置示例
### 文档文件
- `DOCTOR_API_GUIDE.md` - API接口文档
- `DOCTOR_FEATURE_IMPLEMENTATION.md` - 本文件
## 下一步
1. 根据实际需求扩展医生信息字段
2. 添加医生搜索和筛选功能
3. 实现医生评价和评分系统
4. 添加医生在线状态显示
5. 实现医生排班查询功能