feat: 调整项目结构
This commit is contained in:
@@ -21,17 +21,80 @@
|
||||
</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>()
|
||||
let cleanupListener: (() => void) | undefined
|
||||
|
||||
const handleClick = async (item: any) => {
|
||||
const getHtmlPath = (menuUrl: string) => {
|
||||
const cleanUrl = menuUrl.startsWith('/') ? menuUrl.slice(1) : menuUrl
|
||||
switch (cleanUrl) {
|
||||
case 'home': return 'home.html'
|
||||
case 'knowledge': return 'knowledge.html'
|
||||
case 'task': return 'task.html'
|
||||
case 'setting': return 'setting.html'
|
||||
default: return 'home.html'
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (window.api && window.api.tabs) {
|
||||
cleanupListener = 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
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
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(() => {
|
||||
if (cleanupListener) cleanupListener()
|
||||
})
|
||||
|
||||
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>
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export const menus: MenuItem[] = [
|
||||
icon: RiApps2AiLine,
|
||||
color: '#525866',
|
||||
activeColor: '#2B7FFF',
|
||||
url: '/stock',
|
||||
url: '/task',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
|
||||
8
src/renderer/views/home/HomeTab.vue
Normal file
8
src/renderer/views/home/HomeTab.vue
Normal file
@@ -0,0 +1,8 @@
|
||||
<template>
|
||||
<div class="bg-white h-full w-full p-[20px]">
|
||||
<h1>首页 Dashboard</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
@@ -1,12 +1,6 @@
|
||||
<template>
|
||||
<div class="bg-gray-100 h-screen flex flex-col">
|
||||
<header-bar>
|
||||
<drag-region class="w-full" />
|
||||
</header-bar>
|
||||
|
||||
<layout>
|
||||
<div class="bg-gray-100 h-full flex flex-col p-[20px]">
|
||||
任务中心
|
||||
</layout>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user