diff --git a/web/src/view/superAdmin/dictionary/sysDictionaryDetail.vue b/web/src/view/superAdmin/dictionary/sysDictionaryDetail.vue index 12131159a..66fc538fa 100644 --- a/web/src/view/superAdmin/dictionary/sysDictionaryDetail.vue +++ b/web/src/view/superAdmin/dictionary/sysDictionaryDetail.vue @@ -4,24 +4,6 @@
字典详细内容
- - - - 表格视图 - - - 层级视图 - - - 搜索 @@ -47,16 +29,16 @@
- + @@ -70,20 +52,6 @@ - - - - - - -
- - - -
- - -
- -
{ - pageSize.value = val - getTableData() - } - - const handleCurrentChange = (val) => { - page.value = val - getTableData() - } - - // 查询表格数据 - const getTableData = async () => { - if (!props.sysDictionaryID) return - - // 首先获取树形数据以便查找父级标签 - try { - const treeRes = await getDictionaryTreeList({ - sysDictionaryID: props.sysDictionaryID - }) - if (treeRes.code === 0) { - treeData.value = treeRes.data || [] - updateParentOptions(treeRes.data.list || []) - } - } catch (error) { - console.error('获取树形数据失败:', error) - } - - // 然后获取表格数据 - const table = await getSysDictionaryDetailList({ - page: page.value, - pageSize: pageSize.value, - sysDictionaryID: props.sysDictionaryID, - label: searchName.value.trim() - }) - if (table.code === 0) { - tableData.value = table.data.list - total.value = table.data.total - page.value = table.data.page - pageSize.value = table.data.pageSize - } - } // 获取树形数据 const getTreeData = async () => { @@ -427,8 +263,6 @@ }) if (res.code === 0) { treeData.value = res.data.list || [] - // 同时更新父级选项 - updateParentOptions(res.data.list || []) } } catch (error) { console.error('获取树形数据失败:', error) @@ -436,74 +270,14 @@ } } - // 更新父级选项 - const updateParentOptions = (data) => { - const convertToOptions = (items) => { - return items.map((item) => ({ - ID: item.ID, - label: item.label, - value: item.ID, // 使用ID作为value - children: - item.children && item.children.length > 0 - ? convertToOptions(item.children) - : undefined - })) - } - - // 添加根级选项(无父级) - const rootOption = { - ID: null, - label: '无父级(根级)', - value: null - } - - parentOptions.value = [rootOption, ...convertToOptions(data)] + const rootOption = { + ID: null, + label: '无父级(根级)' } - // 根据父级ID获取父级标签 - const getParentLabel = (parentID) => { - if (!parentID) return '根级' - - // 从表格数据中查找父级项 - const parentItem = tableData.value.find((item) => item.ID === parentID) - if (parentItem) { - return parentItem.label - } - - // 从树形数据中递归查找父级项 - const findInTree = (items) => { - for (const item of items) { - if (item.ID === parentID) { - return item.label - } - if (item.children && item.children.length > 0) { - const found = findInTree(item.children) - if (found) return found - } - } - return null - } - - const treeResult = findInTree(treeData.value) - return treeResult || `ID: ${parentID}` - } - - // 根据视图模式获取数据 - const loadData = () => { - if (viewMode.value === 'table') { - getTableData() - } else { - getTreeData() - } - } - - // 监听视图模式变化 - watch(viewMode, () => { - loadData() - }) // 初始加载 - loadData() + getTreeData() const type = ref('') const drawerFormVisible = ref(false) @@ -566,7 +340,7 @@ if (tableData.value.length === 1 && page.value > 1) { page.value-- } - loadData() // 重新加载数据 + await getTreeData() // 重新加载数据 } }) } @@ -594,7 +368,7 @@ message: '创建/更改成功' }) closeDrawer() - loadData() // 重新加载数据 + await getTreeData() // 重新加载数据 } }) } @@ -608,7 +382,7 @@ const clearSearchInput = () => { searchName.value = '' - loadData() + getTreeData() } const handleCloseSearchInput = () => { @@ -617,72 +391,18 @@ const handleInputKeyDown = (e) => { if (e.key === 'Enter' && searchName.value.trim() !== '') { - loadData() + getTreeData() } } watch( () => props.sysDictionaryID, () => { - loadData() + getTreeData() } )