| | |
| | | <template> |
| | | <div class="navbar"> |
| | | <hamburger id="hamburger-container" :is-active="appStore.sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> |
| | | <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!settingsStore.topNav" /> |
| | | <top-nav id="topmenu-container" class="topmenu-container" v-if="settingsStore.topNav" /> |
| | | <hamburger id="hamburger-container" :is-active="appStore.sidebar.opened" class="hamburger-container" @toggle-click="toggleSideBar" /> |
| | | <breadcrumb v-if="!settingsStore.topNav" id="breadcrumb-container" class="breadcrumb-container" /> |
| | | <top-nav v-if="settingsStore.topNav" id="topmenu-container" class="topmenu-container" /> |
| | | |
| | | <div class="right-menu flex align-center"> |
| | | <template v-if="appStore.device !== 'mobile'"> |
| | | <el-select v-model="companyName" |
| | | clearable |
| | | filterable |
| | | reserve-keyword |
| | | placeholder="请选择租户" |
| | | v-if="userId === 1" |
| | | @change="dynamicTenantEvent" |
| | | @clear="dynamicClearEvent"> |
| | | <el-option |
| | | v-for="item in tenantList" |
| | | :key="item.tenantId" |
| | | :label="item.companyName" |
| | | :value="item.tenantId"> |
| | | </el-option> |
| | | <el-select |
| | | v-if="userId === 1 && tenantEnabled" |
| | | v-model="companyName" |
| | | class="min-w-244px" |
| | | clearable |
| | | filterable |
| | | reserve-keyword |
| | | :placeholder="proxy.$t('navbar.selectTenant')" |
| | | @change="dynamicTenantEvent" |
| | | @clear="dynamicClearEvent" |
| | | > |
| | | <el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"> </el-option> |
| | | <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" /> |
| | | |
| | | <el-tooltip content="源码地址" effect="dark" placement="bottom"> |
| | | <!-- <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="proxy.$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> |
| | | |
| | | <el-tooltip content="文档地址" effect="dark" placement="bottom"> |
| | | <el-tooltip :content="proxy.$t('navbar.document')" effect="dark" placement="bottom"> |
| | | <ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" /> |
| | | </el-tooltip> |
| | | |
| | | <screenfull id="screenfull" class="right-menu-item hover-effect" /> |
| | | <el-tooltip :content="proxy.$t('navbar.full')" effect="dark" placement="bottom"> |
| | | <screenfull id="screenfull" class="right-menu-item hover-effect" /> |
| | | </el-tooltip> |
| | | |
| | | <el-tooltip content="布局大小" effect="dark" placement="bottom"> |
| | | <el-tooltip :content="proxy.$t('navbar.language')" effect="dark" placement="bottom"> |
| | | <lang-select id="lang-select" class="right-menu-item hover-effect" /> |
| | | </el-tooltip> |
| | | |
| | | <el-tooltip :content="proxy.$t('navbar.layoutSize')" effect="dark" placement="bottom"> |
| | | <size-select id="size-select" class="right-menu-item hover-effect" /> |
| | | </el-tooltip> |
| | | </template> |
| | | <div class="avatar-container"> |
| | | <el-dropdown @command="handleCommand" class="right-menu-item hover-effect" trigger="click"> |
| | | <el-dropdown class="right-menu-item hover-effect" trigger="click" @command="handleCommand"> |
| | | <div class="avatar-wrapper"> |
| | | <img :src="userStore.avatar" class="user-avatar" /> |
| | | <el-icon><caret-bottom /></el-icon> |
| | | </div> |
| | | <template #dropdown> |
| | | <el-dropdown-menu> |
| | | <router-link to="/user/profile" v-if="!dynamic"> |
| | | <el-dropdown-item>个人中心</el-dropdown-item> |
| | | <router-link v-if="!dynamic" to="/user/profile"> |
| | | <el-dropdown-item>{{ proxy.$t('navbar.personalCenter') }}</el-dropdown-item> |
| | | </router-link> |
| | | <el-dropdown-item command="setLayout"> |
| | | <span>布局设置</span> |
| | | <el-dropdown-item v-if="settingsStore.showSettings" command="setLayout"> |
| | | <span>{{ proxy.$t('navbar.layoutSetting') }}</span> |
| | | </el-dropdown-item> |
| | | <el-dropdown-item divided command="logout"> |
| | | <span>退出登录</span> |
| | | <span>{{ proxy.$t('navbar.logout') }}</span> |
| | | </el-dropdown-item> |
| | | </el-dropdown-menu> |
| | | </template> |
| | |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ElMessageBox } from 'element-plus' |
| | | import Breadcrumb from '@/components/Breadcrumb' |
| | | import TopNav from '@/components/TopNav' |
| | | import Hamburger from '@/components/Hamburger' |
| | | import Screenfull from '@/components/Screenfull' |
| | | import SizeSelect from '@/components/SizeSelect' |
| | | import HeaderSearch from '@/components/HeaderSearch' |
| | | import RuoYiGit from '@/components/RuoYi/Git' |
| | | import RuoYiDoc from '@/components/RuoYi/Doc' |
| | | 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"; |
| | | <script setup lang="ts"> |
| | | 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 useNoticeStore from '@/store/modules/notice'; |
| | | import { getTenantList } from '@/api/login'; |
| | | import { dynamicClear, dynamicTenant } from '@/api/system/tenant'; |
| | | import { TenantVO } from '@/api/types'; |
| | | import notice from './notice/index.vue'; |
| | | import router from '@/router'; |
| | | |
| | | 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(); |
| | | const { proxy } = getCurrentInstance() as ComponentInternalInstance; |
| | | |
| | | const userId = ref(userStore.userId); |
| | | const companyName = ref(undefined); |
| | | const tenantList = ref([]); |
| | | const tenantList = ref<TenantVO[]>([]); |
| | | // 是否切换了租户 |
| | | const dynamic = ref(false); |
| | | // 租户开关 |
| | | const tenantEnabled = ref(true); |
| | | // 搜索菜单 |
| | | const searchMenuRef = ref<InstanceType<typeof SearchMenu>>(); |
| | | |
| | | const openSearchMenu = () => { |
| | | searchMenuRef.value?.openSearch(); |
| | | }; |
| | | |
| | | // 动态切换 |
| | | function dynamicTenantEvent(tenantId) { |
| | | const dynamicTenantEvent = async (tenantId: string) => { |
| | | if (companyName.value != null && companyName.value !== '') { |
| | | dynamicTenant(tenantId).then(res => { |
| | | dynamic.value = true; |
| | | proxy.$tab.closeAllPage() |
| | | proxy.$router.push('/') |
| | | }); |
| | | await dynamicTenant(tenantId); |
| | | dynamic.value = true; |
| | | await proxy?.$router.push('/'); |
| | | await proxy?.proxy.$tab.closeAllPage(); |
| | | await proxy?.proxy.$tab.refreshPage(); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | function dynamicClearEvent() { |
| | | dynamicClear().then(res => { |
| | | dynamic.value = false; |
| | | proxy.$tab.closeAllPage() |
| | | proxy.$router.push('/') |
| | | }); |
| | | } |
| | | const dynamicClearEvent = async () => { |
| | | await dynamicClear(); |
| | | dynamic.value = false; |
| | | await proxy?.$router.push('/'); |
| | | await proxy?.proxy.$tab.closeAllPage(); |
| | | await proxy?.proxy.$tab.refreshPage(); |
| | | }; |
| | | |
| | | // 租户列表 |
| | | function initTenantList() { |
| | | getTenantList().then(res => { |
| | | tenantList.value = res.data; |
| | | }); |
| | | } |
| | | /** 租户列表 */ |
| | | const initTenantList = async () => { |
| | | const { data } = await getTenantList(true); |
| | | tenantEnabled.value = data.tenantEnabled === undefined ? true : data.tenantEnabled; |
| | | if (tenantEnabled.value) { |
| | | tenantList.value = data.voList; |
| | | } |
| | | }; |
| | | |
| | | defineExpose({ |
| | | initTenantList, |
| | | }) |
| | | initTenantList |
| | | }); |
| | | |
| | | function toggleSideBar() { |
| | | appStore.toggleSideBar() |
| | | } |
| | | const toggleSideBar = () => { |
| | | appStore.toggleSideBar(false); |
| | | }; |
| | | |
| | | function handleCommand(command) { |
| | | switch (command) { |
| | | case "setLayout": |
| | | setLayout(); |
| | | break; |
| | | case "logout": |
| | | logout(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | function logout() { |
| | | ElMessageBox.confirm('确定注销并退出系统吗?', '提示', { |
| | | const logout = async () => { |
| | | await ElMessageBox.confirm('确定注销并退出系统吗?', '提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }).then(() => { |
| | | userStore.logOut().then(() => { |
| | | location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index'; |
| | | }) |
| | | }).catch(() => { }); |
| | | } |
| | | }); |
| | | userStore.logout().then(() => { |
| | | router.replace({ |
| | | path: '/login', |
| | | query: { |
| | | redirect: encodeURIComponent(router.currentRoute.value.fullPath || '/') |
| | | } |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | const emits = defineEmits(['setLayout']) |
| | | function setLayout() { |
| | | const emits = defineEmits(['setLayout']); |
| | | const setLayout = () => { |
| | | emits('setLayout'); |
| | | } |
| | | }; |
| | | // 定义Command方法对象 通过key直接调用方法 |
| | | const commandMap: { [key: string]: any } = { |
| | | setLayout, |
| | | logout |
| | | }; |
| | | const handleCommand = (command: string) => { |
| | | // 判断是否存在该方法 |
| | | if (commandMap[command]) { |
| | | commandMap[command](); |
| | | } |
| | | }; |
| | | //用深度监听 消息 |
| | | watch( |
| | | () => noticeStore.state.value.notices, |
| | | (newVal) => { |
| | | newNotice.value = newVal.filter((item: any) => !item.read).length; |
| | | }, |
| | | { deep: true } |
| | | ); |
| | | </script> |
| | | |
| | | <style lang='scss' scoped> |
| | | <style lang="scss" scoped> |
| | | :deep(.el-select .el-input__wrapper) { |
| | | height: 30px; |
| | | } |
| | | |
| | | :deep .el-select .el-input__wrapper { |
| | | height:30px; |
| | | :deep(.el-badge__content.is-fixed) { |
| | | top: 12px; |
| | | } |
| | | |
| | | .flex { |
| | |
| | | height: 50px; |
| | | overflow: hidden; |
| | | position: relative; |
| | | background: #fff; |
| | | //background: #fff; |
| | | box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08); |
| | | |
| | | .hamburger-container { |
| | |
| | | width: 40px; |
| | | height: 40px; |
| | | border-radius: 10px; |
| | | margin-top: 10px; |
| | | } |
| | | |
| | | i { |