From a8a334b3c326610be70dd762978e8bf1a8766adc Mon Sep 17 00:00:00 2001 From: 三个三 <2029364173@qq.com> Date: 星期四, 02 十一月 2023 12:36:31 +0800 Subject: [PATCH] !50 add 新增 前端接入websocket接收消息 * add 新增 前端接入websocket接收消息 --- src/layout/components/Navbar.vue | 100 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 70 insertions(+), 30 deletions(-) diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index 44250ca..7818fd4 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -20,8 +20,28 @@ <template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template> </el-select> - <header-search id="header-search" class="right-menu-item" /> - + <!-- <header-search id="header-search" class="right-menu-item" /> --> + <search-menu ref="searchMenuRef" /> + <el-tooltip content="鎼滅储" effect="dark" placement="bottom"> + <div class="right-menu-item hover-effect" @click="openSearchMenu"> + <svg-icon class-name="search-icon" icon-class="search" /> + </div> + </el-tooltip> + <!-- 娑堟伅 --> + <el-tooltip :content="$t('navbar.message')" effect="dark" placement="bottom"> + <div> + <el-popover placement="bottom" trigger="click" transition="el-zoom-in-top" :width="300" :persistent="false"> + <template #reference> + <el-badge :value="newNotice > 0 ? newNotice : ''" :max="99"> + <svg-icon icon-class="message" /> + </el-badge> + </template> + <template #default> + <notice></notice> + </template> + </el-popover> + </div> + </el-tooltip> <el-tooltip content="Github" effect="dark" placement="bottom"> <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" /> </el-tooltip> @@ -53,7 +73,7 @@ <router-link to="/user/profile" v-if="!dynamic"> <el-dropdown-item>{{ $t('navbar.personalCenter') }}</el-dropdown-item> </router-link> - <el-dropdown-item command="setLayout"> + <el-dropdown-item command="setLayout" v-if="settingsStore.showSettings"> <span>{{ $t('navbar.layoutSetting') }}</span> </el-dropdown-item> <el-dropdown-item divided command="logout"> @@ -68,17 +88,22 @@ </template> <script setup lang="ts"> -import useAppStore from '@/store/modules/app' -import useUserStore from '@/store/modules/user' -import useSettingsStore from '@/store/modules/settings' +import SearchMenu from './TopBar/search.vue'; +import useAppStore from '@/store/modules/app'; +import useUserStore from '@/store/modules/user'; +import useSettingsStore from '@/store/modules/settings'; import { getTenantList } from "@/api/login"; import { dynamicClear, dynamicTenant } from "@/api/system/tenant"; import { ComponentInternalInstance } from "vue"; import { TenantVO } from "@/api/types"; +import notice from './notice/index.vue'; +import useNoticeStore from '@/store/modules/notice'; -const appStore = useAppStore() -const userStore = useUserStore() -const settingsStore = useSettingsStore() +const appStore = useAppStore(); +const userStore = useUserStore(); +const settingsStore = useSettingsStore(); +const noticeStore = storeToRefs(useNoticeStore()); +const newNotice = ref(<number>0); const { proxy } = getCurrentInstance() as ComponentInternalInstance; @@ -89,46 +114,52 @@ const dynamic = ref(false); // 绉熸埛寮�鍏� const tenantEnabled = ref(true); +// 鎼滅储鑿滃崟 +const searchMenuRef = ref<InstanceType<typeof SearchMenu>>(); + +const openSearchMenu = () => { + searchMenuRef.value?.openSearch(); +} // 鍔ㄦ�佸垏鎹� const dynamicTenantEvent = async (tenantId: string) => { - if (companyName.value != null && companyName.value !== '') { - await dynamicTenant(tenantId); - dynamic.value = true; - proxy?.$tab.closeAllPage(); - proxy?.$router.push('/'); - } + if (companyName.value != null && companyName.value !== '') { + await dynamicTenant(tenantId); + dynamic.value = true; + proxy?.$tab.closeAllPage(); + proxy?.$router.push('/'); + } } const dynamicClearEvent = async () => { - await dynamicClear(); - dynamic.value = false; - proxy?.$tab.closeAllPage(); - proxy?.$router.push('/') + await dynamicClear(); + dynamic.value = false; + proxy?.$tab.closeAllPage(); + proxy?.$router.push('/'); } /** 绉熸埛鍒楄〃 */ const initTenantList = async () => { - const { data } = await getTenantList(); - tenantEnabled.value = data.tenantEnabled === undefined ? true : data.tenantEnabled; - if (tenantEnabled.value) { - tenantList.value = data.voList; - } + const { data } = await getTenantList(); + tenantEnabled.value = data.tenantEnabled === undefined ? true : data.tenantEnabled; + if (tenantEnabled.value) { + tenantList.value = data.voList; + } } defineExpose({ - initTenantList, + initTenantList, }) const toggleSideBar = () => { - appStore.toggleSideBar() + appStore.toggleSideBar(false); } const logout = async () => { await ElMessageBox.confirm('纭畾娉ㄩ攢骞堕��鍑虹郴缁熷悧锛�', '鎻愮ず', { - confirmButtonText: '纭畾', - cancelButtonText: '鍙栨秷', - type: 'warning' + confirmButtonText: '纭畾', + cancelButtonText: '鍙栨秷', + type: 'warning' }) await userStore.logout() location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index'; @@ -149,12 +180,21 @@ commandMap[command](); } } + +//鐢ㄦ繁搴︾洃鍚� 娑堟伅 +watch(() => noticeStore.state.value.notices, (newVal, oldVal) => { + newNotice.value = newVal.filter((item: any) => !item.read).length; +}, { deep: true }); </script> <style lang="scss" scoped> :deep(.el-select .el-input__wrapper) { height:30px; +} + +:deep(.el-badge__content.is-fixed){ + top: 12px; } .flex { @@ -169,7 +209,7 @@ height: 50px; overflow: hidden; position: relative; - background: #fff; + //background: #fff; box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08); .hamburger-container { -- Gitblit v1.9.3