feat(documents): 支持全院通用和院区通用归属选择与展示

This commit is contained in:
xy
2026-10-07 19:22:34 +08:00
parent 46bbbfee06
commit 98c94ad3d6
8 changed files with 130 additions and 56 deletions
@@ -42,6 +42,9 @@ import {
canInitiateSigning,
DOCUMENT_LIBRARY_STATUSES,
GENERAL_OWNERSHIP,
ownershipCampusId,
isGlobalOwnership,
CAMPUS_OWNERSHIP_PREFIX,
readLibraryStatus,
resolveOwnershipDepartmentId,
templateWorkflowAction,
@@ -79,6 +82,7 @@ const useMockLibrary = mockFlags.documents
/** 没有绑定科室的文书归到这一组(全院通用),不属于任何一个科室页签 */
const GENERAL_GROUP_KEY = '__all__'
const CAMPUS_GROUP_KEY = '__campus_common__'
/**
* 页面操作的服务端校验兜底。
@@ -211,12 +215,16 @@ const departmentTabs = computed<DepartmentTab[]>(() => {
const knownKeys = new Set(campusDepartments.map((department) => department.id))
const orphans = library.value.filter(
(group) => group.key !== GENERAL_GROUP_KEY && !knownKeys.has(group.key),
(group) =>
group.key !== GENERAL_GROUP_KEY &&
group.key !== CAMPUS_GROUP_KEY &&
!knownKeys.has(group.key),
)
return [
{ key: null, label: '全部', count: allTemplates.value.length },
{ key: GENERAL_GROUP_KEY, label: '全院通用', count: countOf(GENERAL_GROUP_KEY) },
{ key: CAMPUS_GROUP_KEY, label: '院区通用', count: countOf(CAMPUS_GROUP_KEY) },
...campusDepartments.map((department) => ({
key: department.id,
label: allCampusesSelected.value
@@ -282,7 +290,7 @@ function cloneLibrary(source: DocumentDepartment[]): DocumentDepartment[] {
* 把扁平的模板列表组织成页面需要的 科室 → 分类 → 文书 树。
*
* 分组键使用 departmentId,并用组织接口返回的科室字典补齐名称;没有绑定科室的模板
* 归入“全院通用”。这样同一科室的模板无论接口返回顺序如何都会落进同一个分组。
* 按明确归属范围分别归入“全院通用”或“院区通用”。同一科室的模板落入同一分组。
*/
function groupDocuments(
records: DocumentRecord[],
@@ -294,10 +302,15 @@ function groupDocuments(
)
records.forEach((record) => {
const departmentKey = record.departmentId ?? GENERAL_GROUP_KEY
const departmentKey =
record.departmentId ?? (isGlobalOwnership(record) ? GENERAL_GROUP_KEY : CAMPUS_GROUP_KEY)
const departmentName =
record.departmentName ??
(record.departmentId ? (departmentNames.get(record.departmentId) ?? '未知科室') : '全院通用')
(record.departmentId
? (departmentNames.get(record.departmentId) ?? '未知科室')
: isGlobalOwnership(record)
? '全院通用'
: '院区通用')
let department = grouped.get(departmentKey)
@@ -314,7 +327,11 @@ function groupDocuments(
department.categories.push(category)
}
category.documents.push({ ...record, departmentName })
category.documents.push({
...record,
departmentName,
campusName: campuses.value.find((campus) => campus.id === record.campusId)?.name,
})
})
// 全院通用的模板排最前,其余按科室名排序,保证每次进页面分组顺序稳定
@@ -539,7 +556,12 @@ function generateTemplateCode(name: string) {
*/
function sharedDepartmentNames(ownership: string[], primaryDepartmentId: string | null): string[] {
return ownership
.filter((value) => value !== GENERAL_OWNERSHIP && value !== primaryDepartmentId)
.filter(
(value) =>
value !== GENERAL_OWNERSHIP &&
!value.startsWith(CAMPUS_OWNERSHIP_PREFIX) &&
value !== primaryDepartmentId,
)
.map((id) => departments.value.find((department) => department.id === id)?.name)
.filter((name): name is string => Boolean(name))
}
@@ -567,9 +589,11 @@ function locateLocalDocument(id: string) {
/** 演示模式:把新文书追加进本地文库(分组按科室名匹配已有分组) */
function addLocalTemplate(form: DocumentPropsForm, departmentId: string | null): DocumentTemplate {
const department = departments.value.find((item) => item.id === departmentId)
const departmentName = department?.name ?? '全院通用'
const global = form.ownership.includes(GENERAL_OWNERSHIP)
const campusId = global ? null : department?.campusId || ownershipCampusId(form.ownership)
const departmentName = department?.name ?? (global ? '全院通用' : '院区通用')
// 真实模式用 departmentId 当分组键,演示模式没有 UUID,用品名保持同样语义
const departmentKey = department?.id ?? GENERAL_GROUP_KEY
const departmentKey = department?.id ?? (global ? GENERAL_GROUP_KEY : CAMPUS_GROUP_KEY)
let departmentGroup = library.value.find((item) => item.key === departmentKey)
if (!departmentGroup) {
@@ -607,7 +631,9 @@ function addLocalTemplate(form: DocumentPropsForm, departmentId: string | null):
versionId: `local-version-${timestamp}`,
departmentId: departmentId,
departmentName,
campusId: campuses.value[0]?.id ?? '',
campusId,
ownershipScope: global ? 'GLOBAL' : departmentId ? 'DEPARTMENT' : 'CAMPUS',
campusName: campuses.value.find((campus) => campus.id === campusId)?.name,
contentHtml: '',
sharedDepartments: sharedDepartmentNames(form.ownership, departmentId),
}
@@ -626,9 +652,11 @@ function addLocalTemplate(form: DocumentPropsForm, departmentId: string | null):
*/
function updateLocalProps(form: DocumentPropsForm, departmentId: string | null) {
const target = departments.value.find((item) => item.id === departmentId)
const targetName = target?.name ?? '全院通用'
const global = form.ownership.includes(GENERAL_OWNERSHIP)
const campusId = global ? null : target?.campusId || ownershipCampusId(form.ownership)
const targetName = target?.name ?? (global ? '全院通用' : '院区通用')
// 与 addLocalTemplate 同一套分组键口径:演示模式没有 UUID 时落 GENERAL_GROUP_KEY
const targetKey = target?.id ?? GENERAL_GROUP_KEY
const targetKey = target?.id ?? (global ? GENERAL_GROUP_KEY : CAMPUS_GROUP_KEY)
const located = locateLocalDocument(form.id ?? '')
if (!located) {
@@ -644,6 +672,9 @@ function updateLocalProps(form: DocumentPropsForm, departmentId: string | null)
document.updatedAt = new Date().toISOString()
document.departmentId = departmentId
document.departmentName = targetName
document.campusId = campusId
document.campusName = campuses.value.find((campus) => campus.id === campusId)?.name
document.ownershipScope = global ? 'GLOBAL' : departmentId ? 'DEPARTMENT' : 'CAMPUS'
// 主科室进 departmentId,其余勾选科室留在 sharedDepartments(与新建时同一口径)
document.sharedDepartments = sharedDepartmentNames(form.ownership, departmentId)
@@ -705,10 +736,10 @@ async function handlePropsSubmit(form: DocumentPropsForm) {
ElMessage.error('所选科室不存在,请刷新后重试')
return
}
const campusId =
targetDepartment?.campusId ||
(form.id ? propsTemplate.value?.campusId : appStore.selectedCampusId || campuses.value[0]?.id)
if (!campusId) {
const global = form.ownership.includes(GENERAL_OWNERSHIP)
const campusId = global ? null : targetDepartment?.campusId || ownershipCampusId(form.ownership)
const ownershipScope = global ? 'GLOBAL' : departmentId ? 'DEPARTMENT' : 'CAMPUS'
if (!global && !campusId) {
ElMessage.error('无法确定文档所属院区,请选择院区后重试')
return
}
@@ -719,6 +750,7 @@ async function handlePropsSubmit(form: DocumentPropsForm) {
category: form.category,
campusId,
departmentId,
ownershipScope,
})
closePropsDialog()
await loadLibrary()
@@ -732,6 +764,7 @@ async function handlePropsSubmit(form: DocumentPropsForm) {
description: form.description,
campusId,
departmentId,
ownershipScope,
category: form.category,
})