修复bug

This commit is contained in:
2026-01-30 19:00:31 +08:00
parent fcc976680d
commit 3de5e9ebe9
91 changed files with 4966 additions and 847 deletions

View File

@@ -45,7 +45,7 @@
</template>
<script setup lang="uts">
import { ref, computed, watch, withDefaults } from 'vue'
import { ref, computed, watch, withDefaults, onMounted } from 'vue'
import type { MenuGroup, MenuChild } from '../types.uts'
const props = withDefaults(defineProps<{
@@ -269,34 +269,44 @@ const handleClick = (c: MenuChild) => {
emit('sub-click', c)
}
/** 自动groups 变更/activeSubId 无效时,默认跳第一个 leaf 并展开对应 group */
/** 自动groups 变更/activeSubId 无效时,只做状态同步(展开对应 group),不触发导航 */
const ensureDefault = () => {
if (!props.groups || props.groups.length === 0) return
const hit = findChildById(props.activeSubId)
if (hit) {
openGroupKey.value = findGroupKeyByChildId(hit.id)
return
}
if (hit) { openGroupKey.value = findGroupKeyByChildId(hit.id); return }
// ✅ 再按当前 route 找一次
try {
const pages = getCurrentPages()
// @ts-ignore
const cur: any = pages[pages.length - 1]
const route: string = cur?.route ?? ''
const byRoute = findChildByPath(route)
if (byRoute) { openGroupKey.value = findGroupKeyByChildId(byRoute.id); return }
} catch(e) {}
const first = firstLeaf()
if (first) {
openGroupKey.value = findGroupKeyByChildId(first.id)
emit('sub-click', first)
}
if (first) openGroupKey.value = findGroupKeyByChildId(first.id)
}
// ✅ 移除 watch(immediate: true) 中的自动 emit仅在 groups/activeSubId 变更时同步状态
watch(
() => props.groups,
() => { ensureDefault() },
{ immediate: true, deep: true }
{ immediate: false, deep: true }
)
watch(
() => props.activeSubId,
() => { ensureDefault() },
{ immediate: true }
{ immediate: false }
)
// ✅ 初始化时只做一次状态同步(不通过 watch immediate
onMounted(() => {
ensureDefault()
})
</script>
<style>