From 5fdf4c80e640dbb91af44f4a216cf55e6083572b Mon Sep 17 00:00:00 2001 From: EL <1175065040@qq.com> Date: Wed, 18 Mar 2026 17:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BB=E9=99=A2=E7=AE=A1=E7=90=86=E9=A1=B5?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8C=BB=E9=99=A2=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E5=88=97=E5=B9=B6=E6=94=AF=E6=8C=81=E4=BB=BB=E5=91=BD=E5=8C=BB?= =?UTF-8?q?=E9=99=A2=E7=AE=A1=E7=90=86=E5=91=98=20=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=E6=A0=91=E5=B1=95=E7=A4=BA=E5=8C=BB=E9=99=A2?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E4=BF=A1=E6=81=AF=20=E7=A7=91?= =?UTF-8?q?=E5=AE=A4=E4=B8=8E=E5=B0=8F=E7=BB=84=E5=BC=B9=E7=AA=97=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=AE=BE=E7=BD=AE=E4=B8=BB=E4=BB=BB/=E7=BB=84?= =?UTF-8?q?=E9=95=BF=E5=B9=B6=E9=99=90=E5=88=B6=E5=80=99=E9=80=89=E8=A7=92?= =?UTF-8?q?=E8=89=B2=20=E6=82=A3=E8=80=85=E9=A1=B5=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BD=92=E5=B1=9E=E5=8C=BB=E7=94=9F=E9=80=89=E6=8B=A9=E4=B8=8E?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=96=87=E6=A1=88=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E2=80=9C=E5=B0=8F=E7=BB=84=E7=BB=84=E9=95=BF=E2=80=9D=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tyt-admin/src/views/Login.vue | 45 +- .../src/views/organization/Departments.vue | 14 +- tyt-admin/src/views/organization/Groups.vue | 22 +- .../src/views/organization/Hospitals.vue | 117 ++-- tyt-admin/src/views/organization/OrgTree.vue | 589 +++++++++++++----- tyt-admin/src/views/patients/Patients.vue | 94 ++- tyt-admin/src/views/users/Users.vue | 85 ++- 7 files changed, 691 insertions(+), 275 deletions(-) diff --git a/tyt-admin/src/views/Login.vue b/tyt-admin/src/views/Login.vue index 1f76d26..9179f04 100644 --- a/tyt-admin/src/views/Login.vue +++ b/tyt-admin/src/views/Login.vue @@ -4,15 +4,34 @@ - + - + - + - + @@ -27,17 +46,23 @@ :min="1" :controls="false" placeholder="医院 ID(多账号场景建议填写)" - style="width: 100%;" + style="width: 100%" /> - + @@ -68,13 +93,13 @@ const loginForm = reactive({ const rules = { phone: [ { required: true, message: '请输入手机号', trigger: 'blur' }, - { pattern: /^1\d{10}$/, message: '请输入正确的手机号', trigger: 'blur' } + { pattern: /^1\d{10}$/, message: '请输入正确的手机号', trigger: 'blur' }, ], password: [ { required: true, message: '请输入密码', trigger: 'blur' }, - { min: 8, message: '密码长度至少为 8 位', trigger: 'blur' } + { min: 8, message: '密码长度至少为 8 位', trigger: 'blur' }, ], - role: [{ required: true, message: '请选择角色', trigger: 'change' }] + role: [{ required: true, message: '请选择角色', trigger: 'change' }], }; const handleLogin = async () => { diff --git a/tyt-admin/src/views/organization/Departments.vue b/tyt-admin/src/views/organization/Departments.vue index 07e49b4..e88d468 100644 --- a/tyt-admin/src/views/organization/Departments.vue +++ b/tyt-admin/src/views/organization/Departments.vue @@ -163,7 +163,7 @@ placeholder="可选:选择后将任命为科室主任" clearable filterable - style="width: 100%;" + style="width: 100%" > { let targetHospitalId = form.hospitalId; if (isEdit.value) { // Some backend update APIs don't allow changing hospitalId, but we'll send it if needed, or just name - const updated = await updateDepartment(currentId.value, { name: form.name }); + const updated = await updateDepartment(currentId.value, { + name: form.name, + }); targetDepartmentId = updated?.id ?? currentId.value; targetHospitalId = updated?.hospitalId ?? form.hospitalId; ElMessage.success('更新成功'); @@ -431,10 +433,10 @@ const handleSubmit = async () => { } if ( - canAssignDirectorInDialog.value - && form.directorUserId - && targetDepartmentId - && targetHospitalId + canAssignDirectorInDialog.value && + form.directorUserId && + targetDepartmentId && + targetHospitalId ) { await updateUser(form.directorUserId, { role: 'DIRECTOR', diff --git a/tyt-admin/src/views/organization/Groups.vue b/tyt-admin/src/views/organization/Groups.vue index 4fda2cf..4224a0e 100644 --- a/tyt-admin/src/views/organization/Groups.vue +++ b/tyt-admin/src/views/organization/Groups.vue @@ -200,7 +200,7 @@ placeholder="可选:选择后将任命为小组组长" clearable filterable - style="width: 100%;" + style="width: 100%" > { let targetHospitalId = form.hospitalId; if (isEdit.value) { // Backend patch dto might just accept name. Sending departmentId may not be allowed or needed. - const updated = await updateGroup(currentId.value, { name: form.name }); + const updated = await updateGroup(currentId.value, { + name: form.name, + }); targetGroupId = updated?.id ?? currentId.value; targetDepartmentId = updated?.departmentId ?? form.departmentId; targetHospitalId = updated?.department?.hospitalId ?? form.hospitalId; @@ -513,11 +515,11 @@ const handleSubmit = async () => { } if ( - canAssignLeaderInDialog.value - && form.leaderUserId - && targetGroupId - && targetDepartmentId - && targetHospitalId + canAssignLeaderInDialog.value && + form.leaderUserId && + targetGroupId && + targetDepartmentId && + targetHospitalId ) { await updateUser(form.leaderUserId, { role: 'LEADER', @@ -586,7 +588,11 @@ watch( if (!dialogVisible.value) { return; } - await loadLeaderOptions(hospitalId, departmentId, isEdit.value ? currentId.value : null); + await loadLeaderOptions( + hospitalId, + departmentId, + isEdit.value ? currentId.value : null, + ); }, ); diff --git a/tyt-admin/src/views/organization/Hospitals.vue b/tyt-admin/src/views/organization/Hospitals.vue index 3c04b70..33654e6 100644 --- a/tyt-admin/src/views/organization/Hospitals.vue +++ b/tyt-admin/src/views/organization/Hospitals.vue @@ -5,18 +5,36 @@
- + - 查询 + 查询 重置 - 新增医院 + 新增医院
- + @@ -31,9 +49,19 @@ @@ -54,18 +82,26 @@ - + - + @@ -90,7 +131,12 @@ import { ref, reactive, onMounted } from 'vue'; import { useRouter } from 'vue-router'; import { ElMessage, ElMessageBox } from 'element-plus'; -import { getHospitals, createHospital, updateHospital, deleteHospital } from '../../api/organization'; +import { + getHospitals, + createHospital, + updateHospital, + deleteHospital, +} from '../../api/organization'; import { getUsers, updateUser } from '../../api/users'; import { useUserStore } from '../../store/user'; @@ -117,7 +163,7 @@ const roleMap = { const getRoleName = (role) => roleMap[role] || role; const searchForm = reactive({ - keyword: '' + keyword: '', }); // Dialog State @@ -133,7 +179,7 @@ const form = reactive({ }); const rules = { - name: [{ required: true, message: '请输入医院名称', trigger: 'blur' }] + name: [{ required: true, message: '请输入医院名称', trigger: 'blur' }], }; // --- Methods --- @@ -143,7 +189,7 @@ const fetchData = async () => { const res = await getHospitals({ page: page.value, pageSize: pageSize.value, - keyword: searchForm.keyword || undefined + keyword: searchForm.keyword || undefined, }); let hospitalAdminNameMap = {}; @@ -166,7 +212,8 @@ const fetchData = async () => { tableData.value = (res.list || []).map((hospital) => ({ ...hospital, - adminDisplay: (hospitalAdminNameMap[hospital.id] || []).join('、') || '未设置', + adminDisplay: + (hospitalAdminNameMap[hospital.id] || []).join('、') || '未设置', })); total.value = res.total || 0; } catch (error) { @@ -233,7 +280,9 @@ const handleSubmit = async () => { try { let targetHospitalId = null; if (isEdit.value) { - const updated = await updateHospital(currentId.value, { name: form.name }); + const updated = await updateHospital(currentId.value, { + name: form.name, + }); targetHospitalId = updated?.id ?? currentId.value; ElMessage.success('更新成功'); } else { @@ -272,29 +321,27 @@ const handleSubmit = async () => { }; const handleDelete = (row) => { - ElMessageBox.confirm( - `确定要删除医院 "${row.name}" 吗?`, - '警告', - { - confirmButtonText: '确定', - cancelButtonText: '取消', - type: 'warning', - } - ).then(async () => { - try { - await deleteHospital(row.id); - ElMessage.success('删除成功'); - fetchData(); - } catch (error) { - console.error('Delete failed', error); - } - }).catch(() => {}); + ElMessageBox.confirm(`确定要删除医院 "${row.name}" 吗?`, '警告', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }) + .then(async () => { + try { + await deleteHospital(row.id); + ElMessage.success('删除成功'); + fetchData(); + } catch (error) { + console.error('Delete failed', error); + } + }) + .catch(() => {}); }; const goToDepartments = (row) => { router.push({ path: '/organization/departments', - query: { hospitalId: row.id, hospitalName: row.name } + query: { hospitalId: row.id, hospitalName: row.name }, }); }; diff --git a/tyt-admin/src/views/organization/OrgTree.vue b/tyt-admin/src/views/organization/OrgTree.vue index e9651a0..7245c05 100644 --- a/tyt-admin/src/views/organization/OrgTree.vue +++ b/tyt-admin/src/views/organization/OrgTree.vue @@ -6,8 +6,17 @@ @@ -26,38 +35,58 @@
- - - - + + + +
{{ node.label }} - + 医院管理员:{{ data.adminDisplay || '未设置' }} - + 主任:{{ data.directorDisplay || '未设置' }} - + 组长:{{ data.leaderDisplay || '未设置' }}
- {{ getRoleName(data.role) }}
- +
{{ data.type === 'department' ? '设主任' : '设组长' }} - + 编辑 - + 删除
- +
@@ -86,50 +132,62 @@ - -
+ +
- + - +
- +
- {{ selectedUserDetail.name || '-' }} - {{ getRoleName(selectedUserDetail.role) }} - {{ selectedUserDetail.phone || '-' }} - {{ selectedUserDetail.hospitalName || '-' }} - {{ selectedUserDetail.departmentName || '-' }} - {{ selectedUserDetail.groupName || '-' }} + {{ + selectedUserDetail.name || '-' + }} + {{ + getRoleName(selectedUserDetail.role) + }} + {{ + selectedUserDetail.phone || '-' + }} + {{ + selectedUserDetail.hospitalName || '-' + }} + {{ + selectedUserDetail.departmentName || '-' + }} + {{ + selectedUserDetail.groupName || '-' + }} - - + + - + @@ -224,7 +353,7 @@ v-model="selectedOwnerUserId" filterable placeholder="请选择人员" - style="width: 100%;" + style="width: 100%" > @@ -256,10 +389,33 @@ import { ref, reactive, onMounted, computed } from 'vue'; import { useRouter } from 'vue-router'; import { ElMessage, ElMessageBox } from 'element-plus'; -import { getHospitals, getDepartments, getGroups, createDepartment, updateDepartment, deleteDepartment, createGroup, updateGroup, deleteGroup, updateHospital, deleteHospital } from '../../api/organization'; +import { + getHospitals, + getDepartments, + getGroups, + createDepartment, + updateDepartment, + deleteDepartment, + createGroup, + updateGroup, + deleteGroup, + updateHospital, + deleteHospital, +} from '../../api/organization'; import { getUsers, updateUser } from '../../api/users'; import { useUserStore } from '../../store/user'; -import { OfficeBuilding, Filter, Connection, UserFilled, Refresh, Plus, EditPen, Delete, Menu, User } from '@element-plus/icons-vue'; +import { + OfficeBuilding, + Filter, + Connection, + UserFilled, + Refresh, + Plus, + EditPen, + Delete, + Menu, + User, +} from '@element-plus/icons-vue'; const router = useRouter(); const userStore = useUserStore(); @@ -288,7 +444,7 @@ const roleMap = { DIRECTOR: '科室主任', LEADER: '小组组长', DOCTOR: '医生', - ENGINEER: '工程师' + ENGINEER: '工程师', }; const getRoleName = (role) => roleMap[role] || role; @@ -302,12 +458,22 @@ const getRoleTagType = (role) => { }; const getTypeName = (type) => { - const map = { hospital: '医院', department: '科室', group: '小组', user: '人员' }; + const map = { + hospital: '医院', + department: '科室', + group: '小组', + user: '人员', + }; return map[type] || type; }; const getNodeTypeTag = (type) => { - const map = { hospital: 'primary', department: 'success', group: 'warning', user: 'info' }; + const map = { + hospital: 'primary', + department: 'success', + group: 'warning', + user: 'info', + }; return map[type] || 'info'; }; @@ -326,16 +492,16 @@ const canCreateDepartment = (node) => const canCreateGroup = (node) => Boolean( - node - && node.type === 'department' - && (isOrgAdmin.value || isDirector.value), + node && + node.type === 'department' && + (isOrgAdmin.value || isDirector.value), ); const canAddUser = (node) => Boolean( - node - && (node.type === 'department' || node.type === 'group') - && isOrgAdmin.value, + node && + (node.type === 'department' || node.type === 'group') && + isOrgAdmin.value, ); const canEditNode = (node) => { @@ -382,9 +548,9 @@ const activePanelTitle = computed(() => { const activeNodeChildren = computed(() => { if ( - !activeNode.value - || activeNode.value.type === 'user' - || !Array.isArray(activeNode.value.children) + !activeNode.value || + activeNode.value.type === 'user' || + !Array.isArray(activeNode.value.children) ) { return []; } @@ -410,7 +576,9 @@ const selectedUserDetail = computed(() => { return null; } - const current = allUsers.value.find((user) => user.id === activeNode.value.id); + const current = allUsers.value.find( + (user) => user.id === activeNode.value.id, + ); const userData = current || activeNode.value; const hospitalId = userData.hospitalId || null; const departmentId = userData.departmentId || null; @@ -466,7 +634,7 @@ const fetchTreeData = async () => { const [deptRes, groupRes, userRes] = await Promise.all([ getDepartments({ pageSize: 100 }), getGroups({ pageSize: 100 }), - getUsers() + getUsers(), ]); const departments = deptRes.list || []; @@ -507,51 +675,86 @@ const fetchTreeData = async () => { } }); - const tree = hospitals.map(h => { - const hDepts = departments.filter(d => d.hospitalId === h.id); + const tree = hospitals.map((h) => { + const hDepts = departments.filter((d) => d.hospitalId === h.id); const adminDisplay = (hospitalAdminNameMap[h.id] || []).join('、') || '未设置'; - - const deptNodes = hDepts.map(d => { - const dGroups = groups.filter(g => g.departmentId === d.id); + + const deptNodes = hDepts.map((d) => { + const dGroups = groups.filter((g) => g.departmentId === d.id); const directorDisplay = (directorNameMap[d.id] || []).join('、') || '未设置'; - - const groupNodes = dGroups.map(g => { - const gUsers = users.filter(u => u.groupId === g.id); + + const groupNodes = dGroups.map((g) => { + const gUsers = users.filter((u) => u.groupId === g.id); const leaderDisplay = (leaderNameMap[g.id] || []).join('、') || '未设置'; - const userNodes = gUsers.map(u => ({ - key: `u_${u.id}`, id: u.id, name: u.name, type: 'user', role: u.role, - hospitalId: h.id, departmentId: d.id, groupId: g.id + const userNodes = gUsers.map((u) => ({ + key: `u_${u.id}`, + id: u.id, + name: u.name, + type: 'user', + role: u.role, + hospitalId: h.id, + departmentId: d.id, + groupId: g.id, })); return { - key: `g_${g.id}`, id: g.id, name: g.name, type: 'group', - departmentId: d.id, hospitalId: h.id, leaderDisplay, children: userNodes + key: `g_${g.id}`, + id: g.id, + name: g.name, + type: 'group', + departmentId: d.id, + hospitalId: h.id, + leaderDisplay, + children: userNodes, }; }); - const dUsers = users.filter(u => u.departmentId === d.id && !u.groupId); - const dUserNodes = dUsers.map(u => ({ - key: `u_${u.id}`, id: u.id, name: u.name, type: 'user', role: u.role, - hospitalId: h.id, departmentId: d.id + const dUsers = users.filter( + (u) => u.departmentId === d.id && !u.groupId, + ); + const dUserNodes = dUsers.map((u) => ({ + key: `u_${u.id}`, + id: u.id, + name: u.name, + type: 'user', + role: u.role, + hospitalId: h.id, + departmentId: d.id, })); return { - key: `d_${d.id}`, id: d.id, name: d.name, type: 'department', - hospitalId: h.id, directorDisplay, children: [...groupNodes, ...dUserNodes] + key: `d_${d.id}`, + id: d.id, + name: d.name, + type: 'department', + hospitalId: h.id, + directorDisplay, + children: [...groupNodes, ...dUserNodes], }; }); - const hUsers = users.filter(u => u.hospitalId === h.id && !u.departmentId); - const hUserNodes = hUsers.map(u => ({ - key: `u_${u.id}`, id: u.id, name: u.name, type: 'user', role: u.role, - hospitalId: h.id + const hUsers = users.filter( + (u) => u.hospitalId === h.id && !u.departmentId, + ); + const hUserNodes = hUsers.map((u) => ({ + key: `u_${u.id}`, + id: u.id, + name: u.name, + type: 'user', + role: u.role, + hospitalId: h.id, })); return { - key: `h_${h.id}`, id: h.id, name: h.name, type: 'hospital', adminDisplay, children: [...deptNodes, ...hUserNodes] + key: `h_${h.id}`, + id: h.id, + name: h.name, + type: 'hospital', + adminDisplay, + children: [...deptNodes, ...hUserNodes], }; }); @@ -580,17 +783,19 @@ const openSetOwnerDialog = (node) => { selectedOwnerUserId.value = null; if (node.type === 'department') { - ownerCandidates.value = allUsers.value.filter((user) => - user.hospitalId === node.hospitalId - && user.departmentId === node.id - && user.role === 'DIRECTOR', + ownerCandidates.value = allUsers.value.filter( + (user) => + user.hospitalId === node.hospitalId && + user.departmentId === node.id && + user.role === 'DIRECTOR', ); } else { - ownerCandidates.value = allUsers.value.filter((user) => - user.hospitalId === node.hospitalId - && user.departmentId === node.departmentId - && user.groupId === node.id - && user.role === 'LEADER', + ownerCandidates.value = allUsers.value.filter( + (user) => + user.hospitalId === node.hospitalId && + user.departmentId === node.departmentId && + user.groupId === node.id && + user.role === 'LEADER', ); } @@ -600,7 +805,9 @@ const openSetOwnerDialog = (node) => { } const currentOwner = ownerCandidates.value.find((user) => - node.type === 'department' ? user.role === 'DIRECTOR' : user.role === 'LEADER', + node.type === 'department' + ? user.role === 'DIRECTOR' + : user.role === 'LEADER', ); selectedOwnerUserId.value = currentOwner?.id ?? ownerCandidates.value[0].id; ownerDialogVisible.value = true; @@ -623,14 +830,14 @@ const handleSetOwner = async () => { const isDepartment = ownerTargetNode.value.type === 'department'; const payload = isDepartment ? { - role: 'DIRECTOR', - // 后端约束:非 DOCTOR 不允许“调整”科室/小组归属。 - // 这里仅做角色变更,并清空小组归属,避免触发该约束。 - groupId: null, - } + role: 'DIRECTOR', + // 后端约束:非 DOCTOR 不允许“调整”科室/小组归属。 + // 这里仅做角色变更,并清空小组归属,避免触发该约束。 + groupId: null, + } : { - role: 'LEADER', - }; + role: 'LEADER', + }; ownerSubmitLoading.value = true; try { @@ -644,15 +851,16 @@ const handleSetOwner = async () => { }; const goToAddUser = (nodeData) => { - // We navigate to the Users list page. In a full implementation, you could + // We navigate to the Users list page. In a full implementation, you could // pass query params to pre-fill a creation form or open a dialog directly. router.push({ path: '/users', query: { action: 'create', hospitalId: nodeData.hospitalId, - departmentId: nodeData.type === 'department' ? nodeData.id : nodeData.departmentId, - } + departmentId: + nodeData.type === 'department' ? nodeData.id : nodeData.departmentId, + }, }); }; @@ -660,23 +868,51 @@ const goToAddUser = (nodeData) => { const dialogVisible = ref(false); const submitLoading = ref(false); const formRef = ref(null); -const dialogType = ref(''); -const dialogMode = ref(''); +const dialogType = ref(''); +const dialogMode = ref(''); const parentId = ref(null); const currentId = ref(null); const form = reactive({ name: '' }); -const rules = { name: [{ required: true, message: '请输入名称', trigger: 'blur' }] }; +const rules = { + name: [{ required: true, message: '请输入名称', trigger: 'blur' }], +}; const dialogTitle = computed(() => { - const typeName = dialogType.value === 'hospital' ? '医院' : (dialogType.value === 'department' ? '科室' : '小组'); + const typeName = + dialogType.value === 'hospital' + ? '医院' + : dialogType.value === 'department' + ? '科室' + : '小组'; return dialogMode.value === 'create' ? `新增${typeName}` : `编辑${typeName}`; }); -const formLabel = computed(() => dialogType.value === 'hospital' ? '医院名称' : (dialogType.value === 'department' ? '科室名称' : '小组名称')); +const formLabel = computed(() => + dialogType.value === 'hospital' + ? '医院名称' + : dialogType.value === 'department' + ? '科室名称' + : '小组名称', +); -const openCreateDialog = (type, pId) => { dialogType.value = type; dialogMode.value = 'create'; parentId.value = pId; currentId.value = null; dialogVisible.value = true; }; -const openEditDialog = (data) => { dialogType.value = data.type; dialogMode.value = 'edit'; currentId.value = data.id; form.name = data.name; dialogVisible.value = true; }; -const resetForm = () => { if (formRef.value) formRef.value.resetFields(); form.name = ''; }; +const openCreateDialog = (type, pId) => { + dialogType.value = type; + dialogMode.value = 'create'; + parentId.value = pId; + currentId.value = null; + dialogVisible.value = true; +}; +const openEditDialog = (data) => { + dialogType.value = data.type; + dialogMode.value = 'edit'; + currentId.value = data.id; + form.name = data.name; + dialogVisible.value = true; +}; +const resetForm = () => { + if (formRef.value) formRef.value.resetFields(); + form.name = ''; +}; const handleSubmit = async () => { if (!formRef.value) return; @@ -685,45 +921,78 @@ const handleSubmit = async () => { submitLoading.value = true; try { if (dialogMode.value === 'create') { - if (dialogType.value === 'department') await createDepartment({ name: form.name, hospitalId: parentId.value }); - else if (dialogType.value === 'group') await createGroup({ name: form.name, departmentId: parentId.value }); + if (dialogType.value === 'department') + await createDepartment({ + name: form.name, + hospitalId: parentId.value, + }); + else if (dialogType.value === 'group') + await createGroup({ + name: form.name, + departmentId: parentId.value, + }); ElMessage.success('创建成功'); } else { - if (dialogType.value === 'hospital') await updateHospital(currentId.value, { name: form.name }); - else if (dialogType.value === 'department') await updateDepartment(currentId.value, { name: form.name }); - else if (dialogType.value === 'group') await updateGroup(currentId.value, { name: form.name }); + if (dialogType.value === 'hospital') + await updateHospital(currentId.value, { name: form.name }); + else if (dialogType.value === 'department') + await updateDepartment(currentId.value, { name: form.name }); + else if (dialogType.value === 'group') + await updateGroup(currentId.value, { name: form.name }); ElMessage.success('更新成功'); - + // Update activeNode locally if it's the one edited - if (activeNode.value && activeNode.value.id === currentId.value && activeNode.value.type === dialogType.value) { + if ( + activeNode.value && + activeNode.value.id === currentId.value && + activeNode.value.type === dialogType.value + ) { activeNode.value.name = form.name; } } dialogVisible.value = false; fetchTreeData(); - } catch (error) { console.error(error); } finally { submitLoading.value = false; } + } catch (error) { + console.error(error); + } finally { + submitLoading.value = false; + } } }); }; const handleDelete = (data) => { - const typeName = data.type === 'hospital' ? '医院' : (data.type === 'department' ? '科室' : '小组'); - ElMessageBox.confirm(`确定要删除${typeName} "${data.name}" 吗?`, '警告', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }) - .then(async () => { - try { - if (data.type === 'hospital') await deleteHospital(data.id); - else if (data.type === 'department') await deleteDepartment(data.id); - else if (data.type === 'group') await deleteGroup(data.id); - ElMessage.success('删除成功'); - if (activeNode.value && activeNode.value.key === data.key) { - activeNode.value = null; // Clear active node if deleted + const typeName = + data.type === 'hospital' + ? '医院' + : data.type === 'department' + ? '科室' + : '小组'; + ElMessageBox.confirm(`确定要删除${typeName} "${data.name}" 吗?`, '警告', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }) + .then(async () => { + try { + if (data.type === 'hospital') await deleteHospital(data.id); + else if (data.type === 'department') await deleteDepartment(data.id); + else if (data.type === 'group') await deleteGroup(data.id); + ElMessage.success('删除成功'); + if (activeNode.value && activeNode.value.key === data.key) { + activeNode.value = null; // Clear active node if deleted + } + fetchTreeData(); + } catch (error) { + console.error(error); } - fetchTreeData(); - } catch (error) { console.error(error); } - }).catch(() => {}); + }) + .catch(() => {}); }; -onMounted(() => { fetchTreeData(); }); +onMounted(() => { + fetchTreeData(); +});