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

320 lines
7.9 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">
2024-05-23 23:40:55 +08:00
<el-menu :default-active="activeIndex" mode="horizontal" :ellipsis="false" @select="handleSelect">
2023-12-14 16:25:38 +08:00
<el-menu-item index="1" @click="enterIndex">主页</el-menu-item>
2024-06-02 23:11:42 +08:00
<el-menu-item index="2" @click="enterStart"
style="color: red;font-weight: bolder;font-size: large;"
>开始</el-menu-item>
2023-12-14 16:25:38 +08:00
<el-sub-menu index="3">
2024-06-02 23:11:42 +08:00
<template #title>学习</template>
2024-05-23 23:40:55 +08:00
<el-menu-item index="3-1">前端</el-menu-item>
<el-menu-item index="3-2">后端</el-menu-item>
<el-menu-item index="3-3">运维</el-menu-item>
2023-12-14 16:25:38 +08:00
</el-sub-menu>
2024-06-02 23:11:42 +08:00
2023-12-14 16:25:38 +08:00
<el-sub-menu index="4">
<template #title>问答</template>
2024-05-23 23:40:55 +08:00
<el-menu-item index="4-1">前端</el-menu-item>
<el-menu-item index="4-2">后端</el-menu-item>
<el-menu-item index="4-3">运维</el-menu-item>
2023-12-14 16:25:38 +08:00
</el-sub-menu>
</el-menu>
</div>
<div class="search-bar">
2024-05-23 23:40:55 +08:00
<el-input style="width: 300px" v-model="searchText" placeholder="全站搜索" clearable prefix-icon="Search">
2023-12-14 16:25:38 +08:00
<template #append>
<el-button type="primary" plain @click="search">搜索</el-button>
</template>
</el-input>
</div>
<div class="user">
2024-03-14 18:32:58 +08:00
2024-05-23 23:40:55 +08:00
<div class="money" v-if="isLogin">钱钱<span>{{ money }}</span></div>
2023-12-14 16:25:38 +08:00
<el-dropdown trigger="click">
<AvatarInfo :size="30" :isSelf="true" />
2024-03-14 18:32:58 +08:00
2023-12-14 16:25:38 +08:00
<template #dropdown>
2024-03-14 18:32:58 +08:00
2024-05-23 23:40:55 +08:00
<el-dropdown-menu v-if="isLogin">
2024-05-23 23:40:55 +08:00
<el-dropdown-item>你的钱钱{{ money }}</el-dropdown-item>
<el-dropdown-item @click="enterProfile">进入个人中心</el-dropdown-item>
<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>
2024-03-14 18:32:58 +08:00
<el-dropdown-menu v-else>
<el-dropdown-item @click="toLogin">去登录</el-dropdown-item>
</el-dropdown-menu>
2023-12-14 16:25:38 +08:00
</template>
</el-dropdown>
2024-03-14 18:32:58 +08:00
2024-05-23 23:40:55 +08:00
<div class="notice">
<el-dropdown trigger="click" :max-height="500">
2024-06-08 21:51:45 +08:00
<el-badge v-if="noticeStore.noticeForNoReadCount>0" :value="noticeStore.noticeForNoReadCount">
2024-05-23 23:40:55 +08:00
<el-button type="primary">
<el-icon :size="15">
<Bell />
</el-icon>
</el-button>
</el-badge>
2024-06-08 21:51:45 +08:00
<el-button v-else="noticeStore.noticeForNoReadCount" type="primary">
<el-icon :size="15">
<Bell />
</el-icon>
</el-button>
2024-05-23 23:40:55 +08:00
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item class="notice-oper" style="justify-content: space-between;">
<el-button type="primary" @click="fetchNoticeData">刷新</el-button>
<el-button type="warning" @click="hanldeReadClick">一键已读</el-button>
</el-dropdown-item>
<el-dropdown-item v-for="(item, index) in noticeList" :key="index">
<div v-if="item.isRead" class="notice-msg" v-html="item.message"></div>
<el-badge is-dot v-else >
<div class="notice-msg" v-html="item.message"></div>
</el-badge>
</el-dropdown-item>
2024-03-14 18:32:58 +08:00
2024-05-23 23:40:55 +08:00
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
<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>
2024-05-23 23:40:55 +08:00
import { Bell } from '@element-plus/icons-vue'
2023-12-14 16:25:38 +08:00
import AvatarInfo from "@/components/AvatarInfo.vue";
2024-05-23 23:40:55 +08:00
import { computed, onMounted, 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-03-14 18:32:58 +08:00
import { storeToRefs } from 'pinia'
2024-05-23 23:40:55 +08:00
import useNoticeStore from "@/stores/notice";
import { ElMessage } from "element-plus";
import { getList as getNoticeList, read as noticeRead } from "@/apis/bbsNoticeApi"
2024-01-15 15:28:32 +08:00
const { isLogin, clearStorage } = useAuths();
2024-05-23 23:40:55 +08:00
//消息通知存储
const noticeStore = useNoticeStore();
const { noticeList } = storeToRefs(noticeStore);
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();
2024-03-14 18:32:58 +08:00
const { money } = storeToRefs(userStore)
2023-12-14 16:25:38 +08:00
const activeIndex = ref("1");
const searchText = ref("");
2024-05-23 23:40:55 +08:00
const noticeForNoReadCount=computed(()=>{
return noticeList.value.filter(x => x.isRead ==false).length;
})
//加载初始化离线消息
onMounted(async () => {
await fetchNoticeData();
})
const fetchNoticeData = async () => {
const { data } = await getNoticeList({maxResultCount:20});
noticeStore.setNotices(data.items);
}
2023-12-14 10:15:23 +08:00
const handleSelect = (key, keyPath) => {
2024-07-21 13:37:56 +08:00
//console.log(key, keyPath);
2023-12-14 16:25:38 +08:00
};
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-05-23 23:40:55 +08:00
const enterActivity = () => {
2024-01-30 18:30:26 +08:00
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");
};
2024-05-23 23:40:55 +08:00
///一键已读
const hanldeReadClick=async ()=>{
await noticeRead();
await fetchNoticeData();
ElMessage({
message: `全部已读`,
type: "success",
});
}
2024-06-02 23:11:42 +08:00
const enterStart=()=>{
2024-06-09 00:29:53 +08:00
router.push("/start");
2024-06-02 23:11:42 +08:00
}
2023-12-14 10:15:23 +08:00
</script>
2024-05-23 23:40:55 +08:00
2023-12-14 16:25:38 +08:00
<style scoped lang="scss">
2024-05-23 23:40:55 +08:00
.money {
2024-03-14 18:32:58 +08:00
font-size: small;
color: #FED055;
margin: 0 5px;
2024-05-23 23:40:55 +08:00
span {
2024-03-14 18:32:58 +08:00
font-weight: 600;
}
}
2024-05-23 23:40:55 +08:00
2023-12-14 16:25:38 +08:00
.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;
}
2024-05-23 23:40:55 +08:00
.gitee,
.github {
cursor: pointer;
width: 25px;
height: 25px;
margin-left: 15px;
2024-05-23 23:40:55 +08:00
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;
2024-05-23 23:40:55 +08:00
2023-12-14 16:25:38 +08:00
.image {
2023-12-16 11:28:04 +08:00
width: 25px;
height: 25px;
2024-05-23 23:40:55 +08:00
2023-12-14 16:25:38 +08:00
img {
width: 100%;
height: 100%;
}
}
2024-05-23 23:40:55 +08:00
2023-12-14 16:25:38 +08:00
.text {
font-weight: bold;
margin-left: 10px;
}
}
2024-05-23 23:40:55 +08:00
2023-12-14 16:25:38 +08:00
.tab {
.el-menu {
height: 90%;
}
2024-05-23 23:40:55 +08:00
2023-12-14 16:25:38 +08:00
:deep(.el-menu--horizontal) {
border-bottom: none;
}
2023-12-14 10:15:23 +08:00
}
2024-05-23 23:40:55 +08:00
2023-12-14 10:15:23 +08:00
.flex-grow {
flex-grow: 1;
}
2024-05-23 23:40:55 +08:00
2023-12-14 16:25:38 +08:00
.img-icon {
2023-12-14 10:15:23 +08:00
margin-right: 0.5rem;
}
2024-05-23 23:40:55 +08:00
.notice {
margin: 0 5px;
&-oper {
display: flex;
justify-content: space-between;
width: 100%;
}
&-msg {
white-space: wrap !important;
width: 400px;
padding: 6px;
font-size: 14px;
line-height: 24px;
border-bottom: 1px solid #f0e9e9;
}
}
2023-12-14 16:25:38 +08:00
</style>