Merge branch 'feature/dsw' of https://git.nianxx.cn/duanshuwen/zn-ai into feature/lishaohua

This commit is contained in:
kongbeiwu
2025-12-28 16:08:45 +08:00
28 changed files with 547 additions and 645 deletions

View File

@@ -21,17 +21,107 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { menus } from '@constant/menus'
import { useRouter } from "vue-router"
import { ref, onMounted, onUnmounted } from 'vue'
import { menus, type MenuItem } from '@constant/menus'
const router = useRouter()
const currentId = ref(1)
const tabMap = new Map<number, string>()
const cleanupListeners: (() => void)[] = []
const handleClick = async (item: any) => {
const getHtmlPath = (menuUrl: string) => {
const cleanUrl = menuUrl.startsWith('/') ? menuUrl.slice(1) : menuUrl
let filename = ''
switch (cleanUrl) {
case 'home':
filename = 'home.html'
break
case 'knowledge':
filename = 'knowledge.html'
break
case 'task':
filename = 'task.html'
break
case 'setting':
filename = 'setting.html'
break
default:
filename = 'home.html'
}
if (import.meta.env.DEV) {
return `/html/${filename}`
}
return filename
}
onMounted(async () => {
if (window.api && window.api.tabs) {
const cleanupClosed = window.api.tabs.on('tab-closed', (payload: any) => {
const { tabId } = payload
for (const [menuId, id] of tabMap.entries()) {
if (id === tabId) {
tabMap.delete(menuId)
break
}
}
})
if (cleanupClosed) cleanupListeners.push(cleanupClosed)
const cleanupCreated = window.api.tabs.on('tab-created', (tab: any) => {
for (const menu of menus) {
const targetHtml = getHtmlPath(menu.url)
if (tab.url.includes(targetHtml)) {
tabMap.set(menu.id, tab.id)
break
}
}
})
if (cleanupCreated) cleanupListeners.push(cleanupCreated)
try {
const tabs = await window.api.tabs.list()
if (tabs && tabs.length > 0) {
for (const tab of tabs) {
for (const menu of menus) {
const targetHtml = getHtmlPath(menu.url)
if (tab.url.includes(targetHtml)) {
tabMap.set(menu.id, tab.id)
break
}
}
}
}
} catch (e) {
console.error('Failed to sync tabs', e)
}
}
})
onUnmounted(() => {
cleanupListeners.forEach(fn => fn())
})
const handleClick = async (item: MenuItem) => {
console.log("🚀 ~ handleClick ~ item:", item)
currentId.value = item.id
router.push(item.url);
const existingTabId = tabMap.get(item.id)
if (existingTabId) {
await window.api.tabs.switch(existingTabId)
} else {
const htmlFile = getHtmlPath(item.url)
const targetUrl = new URL(htmlFile, window.location.href).href
try {
const tabInfo = await window.api.tabs.create(targetUrl)
if (tabInfo && tabInfo.id) {
tabMap.set(item.id, tabInfo.id)
await window.api.tabs.switch(tabInfo.id)
}
} catch (e) {
console.error('Failed to create tab', e)
}
}
}
</script>