Files
zyt/ASSISTANT_API_FIX.md
T
2026-03-04 15:32:30 +08:00

180 lines
4.3 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.
# 医助列表接口优化
## 问题描述
在诊单管理页面中,获取医助列表时调用了 `adminapi/auth.admin/lists` 接口,该接口需要管理员权限,可能导致权限不足的问题。
## 解决方案
创建一个专门的接口 `adminapi/tcm.diagnosis/getAssistants` 用于获取医助列表,不需要额外的权限验证。
## 实现细节
### 1. 后端实现
#### 控制器方法
**文件:** `server/app/adminapi/controller/tcm/DiagnosisController.php`
```php
/**
* @notes 获取医助列表
* @return \think\response\Json
*/
public function getAssistants()
{
$result = DiagnosisLogic::getAssistants();
return $this->data($result);
}
```
#### 逻辑层方法
**文件:** `server/app/adminapi/logic/tcm/DiagnosisLogic.php`
```php
/**
* @notes 获取医助列表
* @return array
*/
public static function getAssistants()
{
try {
// 查询角色ID为2的管理员(医助)
$assistants = \app\common\model\auth\Admin::where('role_id', 2)
->where('disable', 0)
->field(['id', 'name', 'account'])
->order('id', 'asc')
->select()
->toArray();
return $assistants;
} catch (\Exception $e) {
\think\facade\Log::error('获取医助列表失败: ' . $e->getMessage());
return [];
}
}
```
### 2. 前端实现
#### API 方法
**文件:** `admin/src/api/tcm.ts`
```typescript
// 获取医助列表
export function getAssistants() {
return request.get({ url: '/tcm.diagnosis/getAssistants' })
}
```
#### 组件更新
**文件:** `admin/src/views/tcm/diagnosis/index.vue`
```typescript
// 导入新的 API
import { tcmDiagnosisLists, tcmDiagnosisDelete, tcmDiagnosisAssign, getAssistants } from '@/api/tcm'
// 移除旧的导入
// import { adminLists } from '@/api/perms/admin'
// 更新获取医助列表的方法
const getDictOptions = async () => {
try {
const [diagnosisType, syndromeType, assistants] = await Promise.all([
getDictData({ type: 'diagnosis_type' }),
getDictData({ type: 'syndrome_type' }),
getAssistants() // 使用新的 API
])
diagnosisTypeOptions.value = diagnosisType?.diagnosis_type || []
syndromeTypeOptions.value = syndromeType?.syndrome_type || []
assistantOptions.value = assistants || [] // 直接使用返回的数组
} catch (error) {
console.error('获取字典数据失败:', error)
}
}
```
## 接口说明
### 请求
```
GET /adminapi/tcm.diagnosis/getAssistants
```
### 响应
```json
{
"code": 1,
"msg": "success",
"data": [
{
"id": 1,
"name": "医助张三",
"account": "assistant1"
},
{
"id": 2,
"name": "医助李四",
"account": "assistant2"
}
]
}
```
### 返回字段说明
| 字段 | 类型 | 说明 |
|------|------|------|
| id | int | 医助ID |
| name | string | 医助姓名 |
| account | string | 医助账号 |
## 优势
1. **权限独立**:不依赖管理员列表接口的权限
2. **数据精简**:只返回必要的字段(id、name、account
3. **性能优化**:直接查询医助角色,不需要额外的权限判断
4. **易于维护**:专门的接口更容易理解和维护
## 查询条件
- `role_id = 2`:只查询医助角色
- `disable = 0`:只查询启用状态的医助
-`id` 升序排列
## 测试
### 测试步骤
1. 登录管理后台
2. 访问诊单管理页面
3. 查看医助下拉列表是否正常显示
4. 尝试筛选和指派医助
### 预期结果
- ✅ 医助列表正常加载
- ✅ 下拉框显示所有启用的医助
- ✅ 不会出现权限不足的错误
- ✅ 可以正常筛选和指派医助
## 已修改的文件
-`server/app/adminapi/controller/tcm/DiagnosisController.php`
-`server/app/adminapi/logic/tcm/DiagnosisLogic.php`
-`admin/src/api/tcm.ts`
-`admin/src/views/tcm/diagnosis/index.vue`
## 注意事项
1. **角色ID**:确保医助的 `role_id` 为 2
2. **状态检查**:只返回 `disable = 0` 的医助
3. **字段精简**:只返回必要的字段,减少数据传输
4. **错误处理**:捕获异常并记录日志,返回空数组而不是抛出错误
---
**修复日期:** 2024-03-04
**状态:** ✅ 完成