Add support for collapse navigator and global config (#33)

This commit is contained in:
AceDataCloud committed 2024-01-07 19:05:16 +08:00
1 parent 9a18b417f6
commit 439be1797d
20 files changed
+305 -50

No files matched your search

+9 -1
View File
@@ -27,7 +27,15 @@ export default defineComponent({
return `${getBaseUrlAuth()}/auth/login?inviter_id=${this.inviterId}`;
},
inviterId() {
const result = this.$route.query.inviter_id?.toString() || getCookie('INVITER_ID');
// if forceInviterId is set, then use forceInviterId
if (this.$config?.distribution?.forceInviterId) {
return this.$config?.distribution?.defaultInviterId;
}
// Otherwise, use the inviter_id in the url, then use the inviter_id in the cookie, and finally use the default inviter_id
const result =
this.$route.query.inviter_id?.toString() ||
getCookie('INVITER_ID') ||
this.$config?.distribution?.defaultInviterId;
return result;
},
authenticated() {
+38
View File
@@ -0,0 +1,38 @@
<template>
<font-awesome-icon :icon="icon" class="icon" />
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
export default defineComponent({
name: 'Chevron',
components: {
FontAwesomeIcon
},
props: {
direction: {
type: String,
default: 'right'
}
},
computed: {
icon(): string {
return `fa-solid fa-chevron-${this.direction}`;
}
}
});
</script>
<style lang="scss" scoped>
.icon {
font-size: 12px;
border: 1px solid var(--el-border-color);
border-radius: 50%;
padding: 5px 6px;
cursor: pointer;
color: var(--el-color-black);
background: var(--el-color-white);
}
</style>
+114 -32
View File
@@ -1,13 +1,26 @@
<template>
<div class="navigator">
<chevron v-if="collapsed" class="chevron" direction="right" @click="onOpenMenu"></chevron>
<chevron v-else class="chevron" direction="left" @click="onCollapseMenu"></chevron>
<div class="top">
<div v-for="(link, linkIndex) in links" :key="linkIndex" class="link">
<el-tooltip effect="dark" :content="link.displayName" placement="right">
<div v-if="!collapsed">
<img src="@/assets/images/logo.svg" class="logo" @click="onHome" />
</div>
<el-menu v-if="!collapsed" :default-active="activeIndex">
<el-menu-item
v-for="(link, linkIndex) in links"
:key="linkIndex"
:index="link.route.name"
@click="$router.push(link.route)"
>
<font-awesome-icon :icon="link.icon" class="mr-2" />
<template #title>{{ link.displayName }}</template>
</el-menu-item>
</el-menu>
<div v-for="(link, linkIndex) in links" v-else :key="linkIndex" class="link">
<el-tooltip v-if="collapsed" effect="dark" :content="link.displayName" placement="right">
<el-button
:class="{
button: true,
active: link.routes.includes($route.name as string)
}"
:class="{button: true, active: link.routes.includes($route.name as string)}"
@click="$router.push(link.route)"
>
<font-awesome-icon :icon="link.icon" />
@@ -16,15 +29,27 @@
</div>
</div>
<div class="middle" />
<div class="bottom">
<div class="link">
<div v-if="!collapsed" class="bottom">
<el-menu :default-active="activeIndex">
<el-menu-item @click="onConsole">
<font-awesome-icon icon="fa-solid fa-compass" class="mr-2" />
<template #title>{{ $t('common.nav.console') }}</template>
</el-menu-item>
<el-menu-item @click="onLogout">
<font-awesome-icon icon="fa-solid fa-arrow-right-from-bracket" class="mr-2" />
<template #title>{{ $t('common.nav.logOut') }}</template>
</el-menu-item>
</el-menu>
</div>
<div v-else class="bottom">
<div v-if="$config.navigation?.console" class="link">
<el-tooltip effect="dark" :content="$t('common.nav.console')" placement="right">
<el-button class="button" @click="onConsole">
<font-awesome-icon icon="fa-solid fa-compass" />
</el-button>
</el-tooltip>
</div>
<div class="link">
<div v-if="$config.navigation?.help" class="link">
<help-entry />
</div>
<div v-if="authenticated" class="link">
@@ -40,16 +65,18 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { ElButton, ElTooltip } from 'element-plus';
import { ElButton, ElTooltip, ElMenu, ElMenuItem } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import {
ROUTE_CHAT_CONVERSATION,
ROUTE_CHAT_CONVERSATION_NEW,
ROUTE_CONSOLE_ROOT,
ROUTE_INDEX,
ROUTE_MIDJOURNEY_HISTORY,
ROUTE_MIDJOURNEY_INDEX
} from '@/router/constants';
import HelpEntry from './HelpEntry2.vue';
import Chevron from './Chevron.vue';
export default defineComponent({
name: 'Navigator',
@@ -57,38 +84,68 @@ export default defineComponent({
ElButton,
HelpEntry,
ElTooltip,
FontAwesomeIcon
FontAwesomeIcon,
ElMenu,
ElMenuItem,
Chevron
},
data() {
return {
links: [
{
route: {
name: ROUTE_CHAT_CONVERSATION_NEW
},
displayName: this.$t('common.nav.chat'),
icon: 'fa-regular fa-comment',
image: 'https://cdn.zhishuyun.com/9ad12c99b2.png/thumb_100x100',
routes: [ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW]
const links = [];
if (this.$config?.navigation?.chat) {
links.push({
route: {
name: ROUTE_CHAT_CONVERSATION_NEW
},
{
route: {
name: ROUTE_MIDJOURNEY_INDEX
},
displayName: this.$t('common.nav.midjourney'),
icon: 'fa-solid fa-palette',
image: 'https://cdn.zhishuyun.com/83ee211091.png/thumb_100x100',
routes: [ROUTE_MIDJOURNEY_INDEX, ROUTE_MIDJOURNEY_HISTORY]
}
]
displayName: this.$t('common.nav.chat'),
icon: 'fa-regular fa-comment',
image: 'https://cdn.zhishuyun.com/9ad12c99b2.png/thumb_100x100',
routes: [ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW]
});
}
if (this.$config.navigation?.midjourney) {
links.push({
route: {
name: ROUTE_MIDJOURNEY_INDEX
},
displayName: this.$t('common.nav.midjourney'),
icon: 'fa-solid fa-palette',
image: 'https://cdn.zhishuyun.com/83ee211091.png/thumb_100x100',
routes: [ROUTE_MIDJOURNEY_INDEX, ROUTE_MIDJOURNEY_HISTORY]
});
}
return {
links,
activeIndex: this.$route.name as string
};
},
computed: {
authenticated() {
return !!this.$store.state.token.access;
},
collapsed: {
get() {
return this.$store.state.setting?.navigationCollapsed;
},
set(val: boolean) {
this.$store.commit('setSetting', {
navigationCollapsed: val
});
}
}
},
methods: {
onHome() {
this.$router.push({
name: ROUTE_INDEX
});
},
async onOpenMenu() {
this.collapsed = false;
},
async onCollapseMenu() {
this.collapsed = true;
},
async onLogout() {
await this.$store.dispatch('resetAll');
await this.$store.dispatch('chat/resetAll');
@@ -106,6 +163,31 @@ export default defineComponent({
display: flex;
flex-direction: column;
align-items: center;
position: relative;
.el-menu {
width: 150px;
border-right: none;
.el-menu-item {
height: 50px;
}
}
.chevron {
position: absolute;
right: -12px;
top: 50%;
transform: translateY(-50%) scale(0.8);
z-index: 10;
}
.logo {
width: 80%;
max-height: 40px;
cursor: pointer;
margin: 10px auto 20px auto;
display: block;
}
.top,
.bottom {
@@ -115,7 +197,7 @@ export default defineComponent({
.link {
width: 40px;
height: 40px;
margin-bottom: 10px;
margin: 0 10px 10px 10px;
.button {
width: 40px;
height: 40px;