Skip to content

Commit

Permalink
fix: docTree not show in some case
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Nov 15, 2024
1 parent 10270b7 commit 3902a87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

[自部署免费版体验地址](https://freeshare.terwergreen.com)

[收费版版体验地址](https://share.terwergreen.com)
[收费版体验地址](https://share.terwergreen.com)

## 核心特色

Expand Down
19 changes: 17 additions & 2 deletions components/static/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<script setup lang="ts">
import { computed, defineEmits, defineProps, watch } from "vue"
import SidebarItem from "~/components/static/SidebarItem.vue"
import { createAppLogger } from "~/common/appLogger"
const logger = createAppLogger("static-sidebar")
const { t } = useI18n()
const props = defineProps({
Expand All @@ -44,7 +46,7 @@ const props = defineProps({
const emit = defineEmits(["update-expanded-ids", "update-all-expanded"])
// 构建树形数据
const buildTree = (list: any[], parentId = "", depth = 1): any => {
const buildTree = (list: any[], parentId: string, depth = 1): any => {
if (!list || !Array.isArray(list)) return []
return list
Expand All @@ -59,7 +61,20 @@ const buildTree = (list: any[], parentId = "", depth = 1): any => {
// 计算属性 items,用于构建树形结构
const items = computed(() => {
const itemData = props.treeData
return itemData && itemData.length > 0 ? buildTree(itemData) : []
if (itemData && itemData.length > 0) {
let parentId = ""
// 没有父亲的当做父节点
itemData.forEach((item: any) => {
if (!itemData.find((x: any) => x.id === item.parentId)) {
parentId = item.parentId
}
})
logger.info("found parentId=>", parentId)
return buildTree(itemData, parentId)
} else {
return []
}
})
// 监听 expandedIds 变化并向父组件 emit 更新
Expand Down

0 comments on commit 3902a87

Please sign in to comment.