Files
lingji-work-fe/src/components/_base/navbar/index.vue

195 lines
5.4 KiB
Vue
Raw Normal View History

2025-06-16 14:42:26 +08:00
<script lang="ts" setup>
import { useAppStore } from '@/stores';
import { IconExport, IconFile, IconCaretDown } from '@arco-design/web-vue/es/icon';
import { fetchMenusTree } from '@/api/all';
2025-06-20 06:10:15 -04:00
import { handleUserLogout } from '@/utils/user';
2025-06-23 03:16:55 -04:00
import { fetchLogOut } from '@/api/all/login';
2025-06-23 23:59:08 -04:00
import { useSidebarStore } from '@/stores/modules/side-bar';
import { MENU_GROUP_IDS } from '@/router/constants';
import router from '@/router';
import { useRoute } from 'vue-router';
interface MenuItem {
name: string;
id: number;
children: Array<{
name: string;
}>;
}
const lists = ref<MenuItem[]>([]);
const sidebarStore = useSidebarStore();
const route = useRoute();
const selectedKey = computed(() => {
// 判断是否为工作台页面(假设路由名为 'Home' 或 path 为 '/'
if (route.name === 'Home' || route.path === '/') {
return [`${MENU_GROUP_IDS.WORK_BENCH_ID}`];
}
// 其他页面activeMenuId 作为 key
return [String(sidebarStore.activeMenuId)];
});
2025-06-23 03:16:55 -04:00
const clickExit = async () => {
const { code } = await fetchLogOut();
if (code === 200) {
handleUserLogout();
}
2025-06-17 11:18:39 +08:00
};
2025-06-16 14:42:26 +08:00
const getMenus = async () => {
const res = await fetchMenusTree();
2025-06-23 03:16:55 -04:00
if (res.code === 200) {
lists.value = res.data;
}
2025-06-16 14:42:26 +08:00
};
onMounted(() => {
getMenus();
});
const appStore = useAppStore();
const setServerMenu = () => {
router.push('/management/person');
};
2025-06-16 14:42:26 +08:00
const handleSelect = (index: any) => {
2025-06-23 03:16:55 -04:00
if (index === 0) {
2025-06-23 23:59:08 -04:00
router.push('/');
2025-06-17 11:18:39 +08:00
} else {
router.push('/dataEngine/hotTranslation');
2025-06-17 11:18:39 +08:00
}
};
const handleDopdownClick = (index: any, ind: any) => {
2025-06-23 23:59:08 -04:00
const { children } = lists.value[index];
const indPath = children[ind] as any;
if (indPath.name === '行业热门话题洞察') {
router.push('/dataEngine/hotTranslation');
2025-06-23 23:59:08 -04:00
} else if (indPath.name === '行业词云') {
router.push('/dataEngine/hotCloud');
2025-06-23 23:59:08 -04:00
} else if (indPath.name === '行业关键词动向') {
router.push('/dataEngine/keyWord');
2025-06-23 23:59:08 -04:00
} else if (indPath.name === '用户痛点观察') {
router.push('/dataEngine/userPainPoints');
2025-06-23 23:59:08 -04:00
} else if (indPath.name === '重点品牌动向') {
router.push('/dataEngine/keyBrandMovement');
2025-06-23 23:59:08 -04:00
} else if (indPath.name === '用户画像') {
router.push('/dataEngine/userPersona');
2025-06-17 11:18:39 +08:00
}
2025-06-16 14:42:26 +08:00
};
</script>
<template>
<div class="navbar">
<div class="left-side">
<a-space>
2025-06-17 11:18:39 +08:00
<img src="@/assets/logo.svg" alt="" />
2025-06-16 14:42:26 +08:00
</a-space>
</div>
<div class="center-side">
<div class="menu-demo">
2025-06-23 23:59:08 -04:00
<a-menu
mode="horizontal"
:selected-keys="selectedKey"
:default-selected-keys="[`${MENU_GROUP_IDS.WORK_BENCH_ID}`]"
>
<a-menu-item :key="`${MENU_GROUP_IDS.WORK_BENCH_ID}`" @click="handleSelect(0)">
2025-06-16 14:42:26 +08:00
<view>工作台</view>
</a-menu-item>
2025-06-23 23:59:08 -04:00
<a-menu-item v-for="(item, index) in lists" :key="String(item.id)">
2025-06-17 11:18:39 +08:00
<a-dropdown :popup-max-height="false">
2025-06-16 14:42:26 +08:00
<a-button>{{ item.name }}<icon-caret-down /></a-button>
<template #content>
2025-06-17 11:18:39 +08:00
<a-doption v-for="(child, ind) in item.children" :key="ind" @click="handleDopdownClick(index, ind)">{{
child.name
}}</a-doption>
2025-06-16 14:42:26 +08:00
</template>
</a-dropdown>
</a-menu-item>
</a-menu>
</div>
</div>
<ul class="right-side">
<li>
<a-dropdown trigger="click">
<a-avatar class="cursor-pointer" :size="32">
2025-06-17 11:18:39 +08:00
<img alt="avatar" src="@/assets/avatar.svg" />
2025-06-16 14:42:26 +08:00
</a-avatar>
2025-06-17 11:18:39 +08:00
<template #content>
<div style="padding: 14px">
<a-doption>
<a-space @click="setServerMenu">
<img src="@/assets/option.svg" style="width: 16px; height: 16px" />
<span style="width: 140px; font-size: 12px">管理中心</span>
<icon-right />
</a-space>
</a-doption>
<a-doption>
<a-space>
<img src="@/assets/change.svg" style="width: 16px; height: 16px" />
<span style="width: 140px; font-size: 12px">切换企业账号</span>
<icon-right />
</a-space>
</a-doption>
<a-doption>
<a-space @click="clickExit">
<img src="@/assets/exit.svg" style="width: 16px; height: 16px" />
<span style="width: 140px; font-size: 12px">退出登录</span>
<icon-right />
</a-space>
</a-doption>
</div>
</template>
2025-06-16 14:42:26 +08:00
</a-dropdown>
</li>
</ul>
</div>
</template>
<style scoped lang="less">
.navbar {
display: flex;
justify-content: space-between;
height: 100%;
background-color: var(--color-bg-2);
border-bottom: 1px solid var(--color-border);
}
.left-side {
display: flex;
align-items: center;
padding-left: 20px;
}
.center-side {
flex: 1;
display: flex;
align-items: center;
margin-left: 40px;
}
.cneter-tip {
font-size: 16px;
font-weight: 400;
color: var(--color-text-1);
}
.menu-demo {
flex: 1;
}
.right-side {
display: flex;
padding-right: 20px;
list-style: none;
li {
display: flex;
align-items: center;
padding: 0 10px;
}
a {
color: var(--color-text-1);
text-decoration: none;
}
.nav-btn {
border-color: rgb(var(--gray-2));
color: rgb(var(--gray-8));
font-size: 16px;
}
}
</style>