ForcePilot/web/src/layouts/AppLayout.vue

223 lines
5.0 KiB
Vue
Raw Normal View History

2024-07-14 16:42:38 +08:00
<script setup>
import { KeepAlive, onMounted } from 'vue'
2024-07-14 16:42:38 +08:00
import { RouterLink, RouterView, useRoute } from 'vue-router'
import {
MessageOutlined,
MessageFilled,
SettingOutlined,
SettingFilled,
BookOutlined,
2024-07-27 14:32:57 +08:00
BookFilled,
GithubOutlined,
2024-07-14 16:42:38 +08:00
} from '@ant-design/icons-vue'
2024-07-16 18:14:27 +08:00
import { themeConfig } from '@/assets/theme'
2024-07-27 14:32:57 +08:00
import { useConfigStore } from '@/stores/config'
import { useDatabaseStore } from '@/stores/database'
const configStore = useConfigStore()
const databaseStore = useDatabaseStore()
const getRemoteConfig = () => {
fetch('/api/config').then(res => res.json()).then(data => {
console.log(data)
configStore.setConfig(data)
})
}
const getRemoteDatabase = () => {
2024-07-31 20:22:05 +08:00
if (!configStore.config.enable_knowledge_base) {
return
}
fetch('/api/database').then(res => res.json()).then(data => {
console.log("database", data)
databaseStore.setDatabase(data.databases)
})
}
onMounted(() => {
getRemoteDatabase()
getRemoteConfig()
})
2024-07-14 16:42:38 +08:00
// 打印当前页面的路由信息,使用 vue3 的 setup composition API
const route = useRoute()
console.log(route)
</script>
<template>
<div class="app-layout">
<div class="header">
<div class="logo">
<router-link to="/"><img src="/jnu.png"> </router-link>
</div>
<div class="nav">
<RouterLink to="/chat" class="nav-item" active-class="active">
<component class="icon" :is="route.path === '/chat' ? MessageFilled : MessageOutlined" />
2024-07-14 16:42:38 +08:00
</RouterLink>
2024-07-16 18:14:27 +08:00
<RouterLink to="/database" class="nav-item" active-class="active">
<component class="icon" :is="route.path.startsWith('/database') ? BookFilled : BookOutlined" />
2024-07-14 16:42:38 +08:00
</RouterLink>
</div>
<div class="fill" style="flex-grow: 1;"></div>
2024-07-27 14:32:57 +08:00
<div class="github nav-item">
<a href="https://github.com/xerrors/ProjectAthena" target="_blank">
<GithubOutlined class="icon" style="color: #222;"/>
</a>
</div>
<RouterLink class="nav-item setting" to="/setting" active-class="active">
<component class="icon" :is="route.path === '/setting' ? SettingFilled : SettingOutlined" />
2024-07-14 16:42:38 +08:00
</RouterLink>
</div>
2024-07-27 14:32:57 +08:00
<div class="header-mobile">
<RouterLink to="/chat" class="nav-item" active-class="active">对话</RouterLink>
<RouterLink to="/database" class="nav-item" active-class="active">知识</RouterLink>
<RouterLink to="/setting" class="nav-item" active-class="active">设置</RouterLink>
</div>
2024-07-16 18:14:27 +08:00
<a-config-provider :theme="themeConfig">
2024-07-14 16:42:38 +08:00
<router-view v-slot="{ Component }" id="app-router-view">
<keep-alive>
<component :is="Component" />
</keep-alive>
</router-view>
2024-07-16 18:14:27 +08:00
</a-config-provider>
2024-07-14 16:42:38 +08:00
</div>
</template>
<style lang="less" scoped>
@import '@/assets/main.css';
.app-layout {
display: flex;
flex-direction: row;
width: 100%;
height: 100vh;
min-width: var(--min-width);
2024-07-27 14:32:57 +08:00
.header-mobile {
display: none;
}
2024-07-14 16:42:38 +08:00
}
div.header, #app-router-view {
height: 100%;
max-width: 100%;
}
#app-router-view {
flex: 1 1 auto;
overflow-y: auto;
}
.header {
display: flex;
flex-direction: column;
flex: 0 0 80px;
justify-content: flex-start;
align-items: center;
2024-07-26 14:13:05 +08:00
background-color: var(--main-light-4);
2024-07-14 16:42:38 +08:00
height: 100%;
width: 80px;
2024-07-26 14:13:05 +08:00
border-right: 1px solid var(--main-light-2);
2024-07-14 16:42:38 +08:00
.logo {
width: 40px;
height: 40px;
margin: 30px 0;
2024-07-14 16:42:38 +08:00
img {
width: 100%;
height: 100%;
border-radius: 50%;
}
& > a {
text-decoration: none;
font-size: 24px;
font-weight: bold;
color: #333;
}
}
2024-07-16 18:14:27 +08:00
.nav-item {
padding: 8px 16px;
border: none;
border-radius: 8px;
background-color: transparent;
color: #222;
font-size: 20px;
transition: background-color 0.2s ease-in-out;
margin: 0 10px;
2024-07-14 16:42:38 +08:00
&.active {
font-weight: bold;
color: var(--main-color);
2024-07-26 14:13:05 +08:00
background-color: var(--main-light-2);
}
&:hover {
2024-07-26 14:13:05 +08:00
background-color: var(--main-light-2);
cursor: pointer;
}
2024-07-14 16:42:38 +08:00
}
2024-07-27 14:32:57 +08:00
.setting {
width: auto;
font-size: 20px;
color: #333;
margin: 20px 0;
&:hover {
cursor: pointer;
}
}
}
.header .nav {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
position: relative;
height: 45px;
gap: 16px;
2024-07-14 16:42:38 +08:00
}
2024-07-16 18:14:27 +08:00
@media (max-width: 520px) {
2024-07-14 16:42:38 +08:00
.app-layout {
flex-direction: column-reverse;
2024-07-27 14:32:57 +08:00
div.header {
display: none;
}
2024-07-14 16:42:38 +08:00
}
2024-07-27 14:32:57 +08:00
.app-layout div.header-mobile {
display: flex;
2024-07-14 16:42:38 +08:00
flex-direction: row;
width: 100%;
padding: 0 20px;
2024-07-27 14:32:57 +08:00
justify-content: space-around;
2024-07-14 16:42:38 +08:00
align-items: center;
2024-07-16 18:14:27 +08:00
flex: 0 0 60px;
border-right: none;
2024-07-14 16:42:38 +08:00
.nav-item {
text-decoration: none;
2024-07-27 14:32:57 +08:00
width: 40px;
color: var(--c-text-light-2);
font-size: 1rem;
font-weight: bold;
2024-07-27 14:32:57 +08:00
transition: color 0.1s ease-in-out, font-size 0.1s ease-in-out;
2024-07-27 14:32:57 +08:00
&.active {
color: black;
font-size: 1.1rem;
}
2024-07-14 16:42:38 +08:00
}
}
2024-07-16 18:14:27 +08:00
.app-layout .chat-box::webkit-scrollbar {
width: 0;
}
2024-07-14 16:42:38 +08:00
}
</style>