|
|
@@ -1,146 +1,119 @@
|
|
|
<template>
|
|
|
- <div id="menu" class="menu-container">
|
|
|
- <div class="menu-logo">
|
|
|
+ <ElMenu class="menu" mode="horizontal" @select="handleSelect">
|
|
|
+ <ElMenuItem class="menu-logo" index="logo" disabled>
|
|
|
LOGO
|
|
|
- </div>
|
|
|
- <div class="project-switcher" v-show="projectList.length>0" ref="switcher">
|
|
|
- <div class="selected-project-name">{{selectedProject.name}}</div>
|
|
|
- <div class="icon" @click="handleSwitcherClick"></div>
|
|
|
- <transition name="expand">
|
|
|
- <div class="dropdown" v-show="isDropDownExpand">
|
|
|
- <div
|
|
|
- v-for="item in projectList"
|
|
|
- :key="item.id"
|
|
|
- class="item"
|
|
|
- @click="handleProjectChange(item)">{{item.name}}</div>
|
|
|
- </div>
|
|
|
- </transition>
|
|
|
- </div>
|
|
|
- <div class="notify"></div>
|
|
|
- <div class="user"></div>
|
|
|
- </div>
|
|
|
+ </ElMenuItem>
|
|
|
+ <ElSubmenu index="group">
|
|
|
+ <template #title>{{selectedGroup.name}}</template>
|
|
|
+ <template v-if="groupList.length > 0">
|
|
|
+ <ElMenuItem v-for="group in groupList" :key="group.id" :index="`group-${group.id}`">{{group.name}}</ElMenuItem>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <ElMenuItem disabled>暂未加入任何小组</ElMenuItem>
|
|
|
+ </template>
|
|
|
+ </ElSubmenu>
|
|
|
+ <ElSubmenu index="project">
|
|
|
+ <template #title>{{selectedProject.name}}</template>
|
|
|
+ <template v-if="projectList.length > 0">
|
|
|
+ <ElMenuItem v-for="project in projectList" :key="project.id" :index="`project-${project.id}`">{{project.name}}</ElMenuItem>
|
|
|
+ </template>
|
|
|
+ <template v-else-if="selectedGroup.id === -1">
|
|
|
+ <ElMenuItem disabled>请先选择小组</ElMenuItem>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <ElMenuItem disabled>该小组暂无项目</ElMenuItem>
|
|
|
+ </template>
|
|
|
+ </ElSubmenu>
|
|
|
+ <template v-if="userLoggedIn">
|
|
|
+ <ElSubmenu index="user" class="user">
|
|
|
+ <template #title>{{userInfo.username}}</template>
|
|
|
+ <ElMenuItem index="user-create">创建小组</ElMenuItem>
|
|
|
+ <ElMenuItem index="user-join">加入小组</ElMenuItem>
|
|
|
+ <ElMenuItem index="user-logout">登出</ElMenuItem>
|
|
|
+ </ElSubmenu>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <ElLink type="primary" href="/login" class="user">登录</ElLink>
|
|
|
+ </template>
|
|
|
+ </ElMenu>
|
|
|
</template>
|
|
|
|
|
|
-<script>
|
|
|
-export default {
|
|
|
+<script lang="ts">
|
|
|
+import { useProjectList } from '@/composable/useProject';
|
|
|
+import { useGroupList } from '@/composable/useGroup';
|
|
|
+import { useUser } from '@/composable/useUser';
|
|
|
+import { defineComponent } from 'vue';
|
|
|
+
|
|
|
+export default defineComponent({
|
|
|
name: 'Menu',
|
|
|
- props: {
|
|
|
- projectList: Array,
|
|
|
- selectedProject: Object,
|
|
|
- },
|
|
|
- data() {
|
|
|
+ setup(_, { emit }) {
|
|
|
+ const { projectListOfCurrentGroup: projectList, selectedProject, handleProjectChange } = useProjectList();
|
|
|
+ const { groupList, selectedGroup, handleGroupChange } = useGroupList();
|
|
|
+ const { userInfo, userLoggedIn, userLogOut } = useUser();
|
|
|
+
|
|
|
+ const handleSelect = (index: string) => {
|
|
|
+ const [type, id] = index.split('-');
|
|
|
+ switch (type) {
|
|
|
+ case 'logo': {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'project': {
|
|
|
+ handleProjectChange(parseInt(id, 10));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'group': {
|
|
|
+ handleGroupChange(parseInt(id, 10));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'user': {
|
|
|
+ if (id === 'create') {
|
|
|
+ emit('show-create-group-drawer');
|
|
|
+ } else if (id === 'join') {
|
|
|
+ emit('show-join-group-drawer');
|
|
|
+ } else if (id === 'logout') {
|
|
|
+ userLogOut();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ console.warn('unknown type of sub-menu');
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
return {
|
|
|
- isDropDownExpand: false,
|
|
|
+ projectList,
|
|
|
+ selectedProject,
|
|
|
+ groupList,
|
|
|
+ selectedGroup,
|
|
|
+ handleSelect,
|
|
|
+ userInfo,
|
|
|
+ userLoggedIn,
|
|
|
+ userLogOut,
|
|
|
};
|
|
|
},
|
|
|
- mounted() {
|
|
|
- document.addEventListener('click', (e) => {
|
|
|
- if (!this.$refs.switcher.contains(e.target)) {
|
|
|
- this.isDropDownExpand = false;
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- methods: {
|
|
|
- handleSwitcherClick() {
|
|
|
- this.isDropDownExpand = !this.isDropDownExpand;
|
|
|
- },
|
|
|
- handleProjectChange(item) {
|
|
|
- this.$emit('project-change', item.id);
|
|
|
- this.isDropDownExpand = !this.isDropDownExpand;
|
|
|
- },
|
|
|
- },
|
|
|
-};
|
|
|
+});
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
-.menu-container{
|
|
|
- height: 58px;
|
|
|
+.menu {
|
|
|
width: 100%;
|
|
|
- position: fixed;
|
|
|
- top:0px;
|
|
|
- background-color: #34495E;
|
|
|
- display: flex;
|
|
|
- flex-direction: row;
|
|
|
- align-items: center;
|
|
|
- justify-content: flex-start;
|
|
|
- z-index: 100;
|
|
|
}
|
|
|
-.menu-logo{
|
|
|
- color: #FFFFFF;
|
|
|
+.menu-logo {
|
|
|
+ color: #000000;
|
|
|
font-size: 24px;
|
|
|
font-weight: bolder;
|
|
|
line-height: 58px;
|
|
|
margin-left: 30px;
|
|
|
transition: all .2s linear;
|
|
|
}
|
|
|
-.menu-logo:hover{
|
|
|
- color: #BDC3C7;
|
|
|
-}
|
|
|
-.project-switcher{
|
|
|
- margin-left: 20px;
|
|
|
- background-color: #2C3E50;
|
|
|
- height: 30px;
|
|
|
- padding: 5px;
|
|
|
- width: 240px;
|
|
|
- display: flex;
|
|
|
- flex-direction: row;
|
|
|
- justify-content: flex-start;
|
|
|
- align-items: center;
|
|
|
- border-radius: 5px;
|
|
|
- position: relative;
|
|
|
-}
|
|
|
-.project-switcher .icon{
|
|
|
- width: 24px;
|
|
|
- height: 24px;
|
|
|
- cursor: pointer;
|
|
|
- margin-left: auto;
|
|
|
- background-position: center;
|
|
|
- background-repeat: no-repeat;
|
|
|
- background-size: 100% 100%;
|
|
|
- transition: all .2s linear;
|
|
|
- background-image: url("../assets/icon/menu.svg");
|
|
|
-}
|
|
|
-.project-switcher .icon:hover{
|
|
|
- background-image: url("../assets/icon/menu-hover.svg");
|
|
|
-}
|
|
|
-.project-switcher .dropdown{
|
|
|
- width: 240px;
|
|
|
- position: absolute;
|
|
|
- background-color: #2C3E50;
|
|
|
- color: #FFFFFF;
|
|
|
- top: 39px;
|
|
|
- left: 0px;
|
|
|
- padding: 5px;
|
|
|
- border-radius: 0 0 5px 5px;
|
|
|
- flex-direction: column;
|
|
|
- justify-content: center;
|
|
|
- align-items: start;
|
|
|
- transform-origin: 0px 0px;
|
|
|
-}
|
|
|
-.expand-enter-active,.expand-leave-active{
|
|
|
- transition: all .3s ease-in-out;
|
|
|
-}
|
|
|
-.expand-enter-from,.expand-leave-to{
|
|
|
- opacity: 0;
|
|
|
- transform: scaleY(0);
|
|
|
-}
|
|
|
-.project-switcher .selected-project-name{
|
|
|
- width: 220px;
|
|
|
- line-height: 30px;
|
|
|
- color: #FFFFFF;
|
|
|
- text-align: start;
|
|
|
- text-overflow: ellipsis;
|
|
|
- white-space:nowrap; overflow:hidden
|
|
|
-}
|
|
|
-.project-switcher .dropdown .item{
|
|
|
- line-height: 24px;
|
|
|
- width: 240px;
|
|
|
- text-align: start;
|
|
|
- text-overflow: ellipsis;
|
|
|
- white-space:nowrap; overflow:hidden;
|
|
|
- cursor: pointer;
|
|
|
+.menu-logo.is-disabled {
|
|
|
+ opacity: 1;
|
|
|
+ cursor: default;
|
|
|
}
|
|
|
-.project-switcher .dropdown .item:hover{
|
|
|
- background-color: #34495E;
|
|
|
+.user {
|
|
|
+ float: right;
|
|
|
+ height: 60px;
|
|
|
+ margin: 0 20px;
|
|
|
}
|
|
|
</style>
|