Files
Yi.Admin/Yi.Bbs.Vue3/src/layout/AppHeader.vue

206 lines
5.3 KiB
Vue
Raw Normal View History

2023-12-14 10:15:23 +08:00
<template>
2023-12-14 16:25:38 +08:00
<div class="header">
<div class="logo" @click="enterIndex">
<div class="image">
2023-12-16 11:28:04 +08:00
<img class="img-icon" src="@/assets/common/icons/logo.ico" />
2023-12-14 16:25:38 +08:00
</div>
<div class="text">{{ configStore.name }}</div>
2023-12-14 10:15:23 +08:00
</div>
2023-12-14 16:25:38 +08:00
<div class="tab">
<el-menu
:default-active="activeIndex"
mode="horizontal"
:ellipsis="false"
@select="handleSelect"
>
<el-menu-item index="1" @click="enterIndex">主页</el-menu-item>
<el-sub-menu index="2">
<template #title>学习</template>
<el-menu-item index="2-1">学习 one</el-menu-item>
<el-menu-item index="2-2">学习 two</el-menu-item>
<el-menu-item index="2-3">学习 three</el-menu-item>
</el-sub-menu>
<el-sub-menu index="3">
<template #title>资源</template>
<el-menu-item index="3-1">资源 one</el-menu-item>
<el-menu-item index="3-2">资源 two</el-menu-item>
<el-menu-item index="3-3">资源 three</el-menu-item>
</el-sub-menu>
<el-sub-menu index="4">
<template #title>问答</template>
<el-menu-item index="4-1">问答 one</el-menu-item>
<el-menu-item index="4-2">问答 two</el-menu-item>
<el-menu-item index="4-3">问答 three</el-menu-item>
</el-sub-menu>
</el-menu>
</div>
<div class="search-bar">
<el-input
style="width: 300px"
v-model="searchText"
placeholder="全站搜索"
clearable
prefix-icon="Search"
>
<template #append>
<el-button type="primary" plain @click="search">搜索</el-button>
</template>
</el-input>
</div>
<div class="user">
<el-dropdown trigger="click">
<AvatarInfo :size="30" :isSelf="true" />
<template #dropdown>
<el-dropdown-menu v-if="isLogin">
2023-12-14 16:25:38 +08:00
<el-dropdown-item @click="enterProfile"
>进入个人中心</el-dropdown-item
>
2024-01-30 18:30:26 +08:00
<el-dropdown-item @click="enterActivity"
>进入活动页面</el-dropdown-item
>
2023-12-14 16:25:38 +08:00
<el-dropdown-item @click="logout">登出</el-dropdown-item>
</el-dropdown-menu>
<el-dropdown-menu v-else="isLogin">
<el-dropdown-item @click="toLogin">去登录</el-dropdown-item>
</el-dropdown-menu>
2023-12-14 16:25:38 +08:00
</template>
</el-dropdown>
<div class="gitee" @click="handleGitClick">
<el-tooltip effect="dark" content="在gitee找到我们" placement="bottom">
<img src="@/assets/common/icons/gitee.png" alt="" />
</el-tooltip>
</div>
<div class="github" @click="handleGithubClick">
<el-tooltip effect="dark" content="在github找到我们" placement="bottom">
<img src="@/assets/common/icons/github.png" alt="" />
</el-tooltip>
</div>
2023-12-14 16:25:38 +08:00
</div>
</div>
2023-12-14 10:15:23 +08:00
</template>
<script setup>
2023-12-14 16:25:38 +08:00
import AvatarInfo from "@/components/AvatarInfo.vue";
import { ref } from "vue";
import { useRoute, useRouter } from "vue-router";
2023-12-14 16:25:38 +08:00
import useUserStore from "@/stores/user.js";
2023-12-14 10:15:23 +08:00
import useConfigStore from "@/stores/config";
import useAuths from "@/hooks/useAuths";
import { Session } from "@/utils/storage";
2024-01-15 15:28:32 +08:00
const { isLogin, clearStorage } = useAuths();
2023-12-14 16:25:38 +08:00
const configStore = useConfigStore();
const router = useRouter();
const route = useRoute();
2023-12-14 16:25:38 +08:00
const userStore = useUserStore();
const activeIndex = ref("1");
const searchText = ref("");
2023-12-14 10:15:23 +08:00
const handleSelect = (key, keyPath) => {
2023-12-14 16:25:38 +08:00
console.log(key, keyPath);
};
const logout = async () => {
2023-12-14 10:15:23 +08:00
ElMessageBox.confirm(`确定登出系统吗?`, "警告", {
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "warning",
2023-12-14 16:25:38 +08:00
}).then(async () => {
2023-12-14 10:15:23 +08:00
//异步
await userStore.logOut();
//删除成功后,跳转到主页
router.push("/login");
ElMessage({
type: "success",
message: "登出成功",
});
});
2023-12-14 16:25:38 +08:00
};
const enterIndex = () => {
2023-12-14 10:15:23 +08:00
router.push("/index");
};
2023-12-14 16:25:38 +08:00
const enterProfile = () => {
2024-01-17 16:31:01 +08:00
router.push(`/profile/${userStore.userName}`);
2023-12-14 16:25:38 +08:00
};
2024-01-30 18:30:26 +08:00
const enterActivity=()=>{
router.push(`/activity`);
}
const toLogin = () => {
2023-12-21 23:37:42 +08:00
clearStorage();
Session.set("currentPath", route.path);
router.push("/login");
};
2023-12-14 16:25:38 +08:00
const search = () => {
var routerPer = { path: `/discuss`, query: { q: searchText.value } };
searchText.value = "";
router.push(routerPer);
};
2024-01-02 20:40:14 +08:00
const handleGitClick = () => {
window.open("https://gitee.com/ccnetcore/Yi");
};
2024-01-03 23:39:36 +08:00
const handleGithubClick = () => {
window.open("https://github.com/ccnetcore/Yi.Abp.Admin");
};
2023-12-14 10:15:23 +08:00
</script>
2023-12-14 16:25:38 +08:00
<style scoped lang="scss">
.header {
2023-12-20 21:52:42 +08:00
width: 1300px;
2023-12-14 16:25:38 +08:00
display: flex;
align-items: center;
justify-content: space-between;
}
2024-01-02 20:40:14 +08:00
2023-12-14 16:25:38 +08:00
.user {
display: flex;
align-items: center;
2024-01-03 23:39:36 +08:00
2023-12-14 16:25:38 +08:00
.el-dropdown-link {
cursor: pointer;
display: flex;
align-items: center;
}
.gitee,
.github {
cursor: pointer;
width: 25px;
height: 25px;
margin-left: 15px;
img {
width: 100%;
height: 100%;
}
2024-01-03 23:39:36 +08:00
}
}
2023-12-14 16:25:38 +08:00
.logo {
cursor: pointer;
display: flex;
align-items: center;
.image {
2023-12-16 11:28:04 +08:00
width: 25px;
height: 25px;
2023-12-14 16:25:38 +08:00
img {
width: 100%;
height: 100%;
}
}
.text {
font-weight: bold;
margin-left: 10px;
}
}
.tab {
.el-menu {
height: 90%;
}
:deep(.el-menu--horizontal) {
border-bottom: none;
}
2023-12-14 10:15:23 +08:00
}
.flex-grow {
flex-grow: 1;
}
2023-12-14 16:25:38 +08:00
.img-icon {
2023-12-14 10:15:23 +08:00
margin-right: 0.5rem;
}
2023-12-14 16:25:38 +08:00
</style>