From c2b791e784d560df0b33e9f9f5f4586bd9c79dc7 Mon Sep 17 00:00:00 2001 From: ChenQiuYu Date: Tue, 20 May 2025 12:50:35 +0800 Subject: [PATCH] dev --- src/views/settings/section.vue | 58 ++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/src/views/settings/section.vue b/src/views/settings/section.vue index 37a8266..d609c1d 100644 --- a/src/views/settings/section.vue +++ b/src/views/settings/section.vue @@ -28,7 +28,11 @@ - + + + @@ -66,6 +70,7 @@ import Mask from '@/components/common/Mask.vue' import SectionEdit from "@/components/settings/SectionEdit.vue"; import {post} from "@/utils/request.ts"; import deptsObj from '@/assets/config/directory/depts.json' + import {formatDate} from '@/utils/dateUtils.ts' import depts from "@/assets/config/directory/depts.json"; import {Plus} from "@element-plus/icons-vue"; @@ -91,14 +96,13 @@ interface Dept { } const init = () => { - id.value='' - post('organization/section/list', {page: page.value, size: pageSize.value, ...search.value}).then((res: any) => { + id.value = '' + post('organization/section/list', { + page: page.value, + size: pageSize.value, ...search.value + }).then((res: any) => { tableData.value = res.list - tableData.value.forEach((item: any) => { - let dept: Dept = deptsObj - item.caty = dept[item.caty] - console.log(item.caty) - }) + total.value = res.total_count }) } const changePage = (val: any) => { @@ -126,6 +130,41 @@ const resetSearch = () => { search.value = {} init() } +// 修改 depts 的类型定义,允许字符串索引 +interface DeptMap { + [key: string]: string | { name: string; children?: { [key: string]: string } }; +} +const getDeptDisplayName = (code: string): string => { + if (!code) return '未知科室' + + const dept = (depts as DeptMap)[code] + + // 如果是一级科室,并且是字符串类型 + if (typeof dept === 'string') { + return dept + } + + // 如果是一级科室,并且是对象类型(包含 name) + if (typeof dept === 'object' && dept !== null && 'name' in dept) { + return dept.name + } + + // 如果是二级科室,尝试查找父级下的 value + for (const key in depts) { + const parentDept = depts[key] + if ( + typeof parentDept === 'object' && + parentDept !== null && + 'children' in parentDept && + code in (parentDept.children || {}) + ) { + return parentDept.children?.[code] || '未知科室' + } + } + + return '未知科室' +} + \ No newline at end of file