fix(documents): 保存文档归属并支持所有院区筛选
This commit is contained in:
@@ -111,6 +111,8 @@ const libraryError = ref('')
|
||||
const library = ref<DocumentDepartment[]>([])
|
||||
const campuses = ref<CampusRecord[]>([])
|
||||
const departments = ref<DepartmentRecord[]>([])
|
||||
const allCampusesSelected = ref(false)
|
||||
const libraryCampusId = computed(() => (allCampusesSelected.value ? '' : appStore.selectedCampusId))
|
||||
|
||||
const filters = reactive<DocumentFilterForm>({
|
||||
keyword: '',
|
||||
@@ -169,13 +171,16 @@ const allTemplates = computed<DocumentTemplate[]>(() =>
|
||||
const campusTabs = computed<CampusTab[]>(() =>
|
||||
useMockLibrary
|
||||
? []
|
||||
: [...campuses.value]
|
||||
.filter((campus) => campus.status !== 'DISABLED')
|
||||
.sort(
|
||||
(left, right) =>
|
||||
left.sortNo - right.sortNo || left.name.localeCompare(right.name, 'zh-CN'),
|
||||
)
|
||||
.map((campus) => ({ key: campus.id, label: campus.name })),
|
||||
: [
|
||||
{ key: '', label: '所有院区' },
|
||||
...[...campuses.value]
|
||||
.filter((campus) => campus.status !== 'DISABLED')
|
||||
.sort(
|
||||
(left, right) =>
|
||||
left.sortNo - right.sortNo || left.name.localeCompare(right.name, 'zh-CN'),
|
||||
)
|
||||
.map((campus) => ({ key: campus.id, label: campus.name })),
|
||||
],
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -195,7 +200,7 @@ const departmentTabs = computed<DepartmentTab[]>(() => {
|
||||
const countOf = (key: string) =>
|
||||
allTemplates.value.filter((template) => template.departmentKey === key).length
|
||||
|
||||
const campusId = appStore.selectedCampusId
|
||||
const campusId = libraryCampusId.value
|
||||
const campusDepartments = [...departments.value]
|
||||
.filter((department) => department.status !== 'DISABLED')
|
||||
// 演示文库没有院区维度(科室字典的 campusId 是演示值,与全局院区对不上),不按院区过滤
|
||||
@@ -214,7 +219,9 @@ const departmentTabs = computed<DepartmentTab[]>(() => {
|
||||
{ key: GENERAL_GROUP_KEY, label: '全院通用', count: countOf(GENERAL_GROUP_KEY) },
|
||||
...campusDepartments.map((department) => ({
|
||||
key: department.id,
|
||||
label: department.name,
|
||||
label: allCampusesSelected.value
|
||||
? `${campuses.value.find((campus) => campus.id === department.campusId)?.name ?? '未知院区'} · ${department.name}`
|
||||
: department.name,
|
||||
count: countOf(department.id),
|
||||
})),
|
||||
...orphans.map((group) => ({ key: group.key, label: group.name, count: countOf(group.key) })),
|
||||
@@ -307,7 +314,7 @@ function groupDocuments(
|
||||
department.categories.push(category)
|
||||
}
|
||||
|
||||
category.documents.push(record)
|
||||
category.documents.push({ ...record, departmentName })
|
||||
})
|
||||
|
||||
// 全院通用的模板排最前,其余按科室名排序,保证每次进页面分组顺序稳定
|
||||
@@ -330,12 +337,13 @@ function groupDocuments(
|
||||
* 表现为"文档库里少了几份文书",很难排查。
|
||||
*/
|
||||
async function fetchAllDocuments(): Promise<DocumentRecord[]> {
|
||||
const campusId = libraryCampusId.value || undefined
|
||||
const pageSize = 200
|
||||
const firstPage = await getDocuments({
|
||||
page: 1,
|
||||
pageSize,
|
||||
status: 'all',
|
||||
campusId: appStore.selectedCampusId || undefined,
|
||||
campusId,
|
||||
})
|
||||
const effectivePageSize = Math.max(firstPage.pageSize, 1)
|
||||
const pageCount = Math.ceil(firstPage.total / effectivePageSize)
|
||||
@@ -350,7 +358,7 @@ async function fetchAllDocuments(): Promise<DocumentRecord[]> {
|
||||
page: index + 2,
|
||||
pageSize: effectivePageSize,
|
||||
status: 'all',
|
||||
campusId: appStore.selectedCampusId || undefined,
|
||||
campusId,
|
||||
}),
|
||||
),
|
||||
)
|
||||
@@ -358,6 +366,8 @@ async function fetchAllDocuments(): Promise<DocumentRecord[]> {
|
||||
return [firstPage, ...remaining].flatMap((page) => page.records)
|
||||
}
|
||||
|
||||
let libraryRequestId = 0
|
||||
|
||||
async function loadLibrary() {
|
||||
if (useMockLibrary) {
|
||||
libraryError.value = ''
|
||||
@@ -367,15 +377,18 @@ async function loadLibrary() {
|
||||
|
||||
libraryLoading.value = true
|
||||
libraryError.value = ''
|
||||
const requestId = ++libraryRequestId
|
||||
|
||||
try {
|
||||
const records = await fetchAllDocuments()
|
||||
if (requestId !== libraryRequestId) return
|
||||
library.value = groupDocuments(records, departments.value)
|
||||
} catch {
|
||||
if (requestId !== libraryRequestId) return
|
||||
library.value = []
|
||||
libraryError.value = '文书库加载失败,请确认后端模板接口可访问后重试'
|
||||
} finally {
|
||||
libraryLoading.value = false
|
||||
if (requestId === libraryRequestId) libraryLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,11 +700,25 @@ async function handlePropsSubmit(form: DocumentPropsForm) {
|
||||
propsSaving.value = true
|
||||
|
||||
try {
|
||||
const targetDepartment = departments.value.find((item) => item.id === departmentId)
|
||||
if (departmentId && !targetDepartment) {
|
||||
ElMessage.error('所选科室不存在,请刷新后重试')
|
||||
return
|
||||
}
|
||||
const campusId =
|
||||
targetDepartment?.campusId ||
|
||||
(form.id ? propsTemplate.value?.campusId : appStore.selectedCampusId || campuses.value[0]?.id)
|
||||
if (!campusId) {
|
||||
ElMessage.error('无法确定文档所属院区,请选择院区后重试')
|
||||
return
|
||||
}
|
||||
if (form.id) {
|
||||
await updateTemplate(form.id, {
|
||||
name: form.name,
|
||||
description: form.description,
|
||||
category: form.category,
|
||||
campusId,
|
||||
departmentId,
|
||||
})
|
||||
closePropsDialog()
|
||||
await loadLibrary()
|
||||
@@ -703,7 +730,7 @@ async function handlePropsSubmit(form: DocumentPropsForm) {
|
||||
templateCode: generateTemplateCode(form.name),
|
||||
name: form.name,
|
||||
description: form.description,
|
||||
campusId: appStore.selectedCampusId || campuses.value[0]?.id || '',
|
||||
campusId,
|
||||
departmentId,
|
||||
category: form.category,
|
||||
})
|
||||
@@ -894,9 +921,8 @@ async function handleToggleStatus(template: DocumentTemplate) {
|
||||
return
|
||||
}
|
||||
|
||||
const versionId = action === 'disable'
|
||||
? template.currentVersionId ?? template.versionId
|
||||
: template.versionId
|
||||
const versionId =
|
||||
action === 'disable' ? (template.currentVersionId ?? template.versionId) : template.versionId
|
||||
if (!versionId) {
|
||||
ElMessage.error('该文书没有可操作的版本,请刷新后重试')
|
||||
return
|
||||
@@ -1140,15 +1166,16 @@ function clearFilters() {
|
||||
/**
|
||||
* 切换院区。
|
||||
*
|
||||
* 走全局院区状态而不是页面自己存一份:右上角的院区选择器读的就是这个值,
|
||||
* 两处共用一份状态,就不会出现「右上角写着本部院区、筛选条却选中东院区」。
|
||||
* 重新取数由下面的 watch 负责,这里只改状态。
|
||||
* 所有院区仅用于文档库查询;具体院区仍与全局选择器同步。
|
||||
* 重新取数由下面的 watch 负责。
|
||||
*/
|
||||
function handleCampusSelect(campusId: string) {
|
||||
if (campusId === appStore.selectedCampusId) {
|
||||
if (!campusId) {
|
||||
allCampusesSelected.value = true
|
||||
return
|
||||
}
|
||||
|
||||
allCampusesSelected.value = false
|
||||
appStore.selectCampus(campusId)
|
||||
}
|
||||
|
||||
@@ -1156,6 +1183,8 @@ function useTemplate(template: DocumentTemplate) {
|
||||
void openSigningDialog(template)
|
||||
}
|
||||
|
||||
let libraryInitialized = false
|
||||
|
||||
async function initializePage() {
|
||||
if (useMockLibrary) {
|
||||
await loadOrganizationOptions()
|
||||
@@ -1164,28 +1193,25 @@ async function initializePage() {
|
||||
await loadOrganizationOptions()
|
||||
}
|
||||
|
||||
libraryInitialized = true
|
||||
await loadLibrary()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => appStore.selectedCampusId,
|
||||
(campusId, previousCampusId) => {
|
||||
if (!campusId || campusId === previousCampusId) {
|
||||
return
|
||||
}
|
||||
watch(libraryCampusId, (campusId, previousCampusId) => {
|
||||
if (campusId === previousCampusId) {
|
||||
return
|
||||
}
|
||||
|
||||
// 院区变了,原先选中的科室不一定属于新院区,清掉以免筛出一片空结果
|
||||
filters.department = null
|
||||
// 院区变了,原先选中的科室不一定属于新院区,清掉以免筛出一片空结果
|
||||
filters.department = null
|
||||
|
||||
// 演示模式没有院区维度;首次进页面时院区从空值变成第一个院区,
|
||||
// 那一次由 initializePage 负责取数,这里跳过,避免重复拉一遍文库
|
||||
if (useMockLibrary || !previousCampusId) {
|
||||
return
|
||||
}
|
||||
// 初始化由 initializePage 取数,演示文库没有院区维度。
|
||||
if (useMockLibrary || !libraryInitialized) {
|
||||
return
|
||||
}
|
||||
|
||||
void loadLibrary()
|
||||
},
|
||||
)
|
||||
void loadLibrary()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void initializePage()
|
||||
@@ -1206,7 +1232,7 @@ onMounted(() => {
|
||||
<DocumentFilterTabs
|
||||
v-model:department="filters.department"
|
||||
v-model:status="filters.status"
|
||||
:campus="appStore.selectedCampusId"
|
||||
:campus="libraryCampusId"
|
||||
:campuses="campusTabs"
|
||||
:departments="departmentTabs"
|
||||
:statuses="statusTabs"
|
||||
|
||||
Reference in New Issue
Block a user