Merge branch 'master' of https://gitea.xinyuxi.com/zhanggaoming/xh-medical-sign-web
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
updateTemplateVersionStatus,
|
||||
type TemplateVersionAction,
|
||||
} from '@/api/management/documents'
|
||||
import { getCampuses, getDepartments } from '@/api/management/organization'
|
||||
import { getAllDepartments, getCampuses } from '@/api/management/organization'
|
||||
import type {
|
||||
CampusRecord,
|
||||
CreateTemplateRequest,
|
||||
@@ -219,16 +219,23 @@ function cloneLibrary(source: DocumentDepartment[]): DocumentDepartment[] {
|
||||
/**
|
||||
* 把扁平的模板列表组织成页面需要的 科室 → 分类 → 文书 树。
|
||||
*
|
||||
* 分组键用 departmentId(真实模式)或科室名(未指定科室的模板归"全院通用"),
|
||||
* 这样同一科室的模板无论接口返回顺序如何都会落进同一个分组。
|
||||
* 分组键使用 departmentId,并用组织接口返回的科室字典补齐名称;没有绑定科室的模板
|
||||
* 归入“全院通用”。这样同一科室的模板无论接口返回顺序如何都会落进同一个分组。
|
||||
*/
|
||||
function groupDocuments(records: DocumentRecord[]): DocumentDepartment[] {
|
||||
function groupDocuments(
|
||||
records: DocumentRecord[],
|
||||
departmentOptions: DepartmentRecord[],
|
||||
): DocumentDepartment[] {
|
||||
const departments = new Map<string, DocumentDepartment>()
|
||||
const departmentNames = new Map(
|
||||
departmentOptions.map((department) => [department.id, department.name]),
|
||||
)
|
||||
|
||||
records.forEach((record) => {
|
||||
const departmentKey = record.departmentId ?? '__all__'
|
||||
const departmentName =
|
||||
record.departmentName ?? (record.departmentId ? '未指定科室' : '全院通用')
|
||||
record.departmentName ??
|
||||
(record.departmentId ? (departmentNames.get(record.departmentId) ?? '未知科室') : '全院通用')
|
||||
|
||||
let department = departments.get(departmentKey)
|
||||
|
||||
@@ -308,7 +315,7 @@ async function loadLibrary() {
|
||||
|
||||
try {
|
||||
const records = await fetchAllDocuments()
|
||||
library.value = groupDocuments(records)
|
||||
library.value = groupDocuments(records, departments.value)
|
||||
} catch {
|
||||
library.value = []
|
||||
libraryError.value = '文书库加载失败,请确认后端模板接口可访问后重试'
|
||||
@@ -337,7 +344,7 @@ async function loadOrganizationOptions() {
|
||||
|
||||
const [campusesResult, departmentsResult] = await Promise.allSettled([
|
||||
getCampuses(),
|
||||
getDepartments(),
|
||||
getAllDepartments(),
|
||||
])
|
||||
|
||||
campuses.value = campusesResult.status === 'fulfilled' ? campusesResult.value : []
|
||||
@@ -346,6 +353,10 @@ async function loadOrganizationOptions() {
|
||||
if (campusesResult.status === 'rejected') {
|
||||
ElMessage.error('院区字典加载失败,新增文书时无法选择所属院区')
|
||||
}
|
||||
|
||||
if (departmentsResult.status === 'rejected') {
|
||||
ElMessage.error('科室字典加载失败,文书所属科室暂时无法正确显示')
|
||||
}
|
||||
}
|
||||
|
||||
// 演示数据落本地:刷新后文书库还在,不用每次重新建文书。
|
||||
|
||||
Reference in New Issue
Block a user