- 重构运营总览、侧栏和内容运营工作台\n- 增加大喇叭、成果审核与运营统计链路\n- 补齐租户、知识空间、分类和知识维护闭环\n- 加固标签页租户上下文、停用租户写保护与迁移预检
438 lines
13 KiB
Vue
438 lines
13 KiB
Vue
<template>
|
|
<div class="navbar" :class="'nav' + navType">
|
|
<hamburger
|
|
v-if="navType !== NavTypeEnum.TOP"
|
|
id="hamburger-container"
|
|
:is-active="appStore.sidebar.opened"
|
|
class="hamburger-container"
|
|
@toggle-click="toggleSideBar"
|
|
/>
|
|
|
|
<breadcrumb v-if="navType == NavTypeEnum.LEFT" id="breadcrumb-container" class="breadcrumb-container" />
|
|
<top-nav v-if="navType == NavTypeEnum.MIX" id="topmenu-container" class="topmenu-container" />
|
|
|
|
<template v-if="navType == NavTypeEnum.TOP">
|
|
<logo v-show="showLogo" :collapse="false"></logo>
|
|
<top-bar id="topbar-container" class="topbar-container" />
|
|
</template>
|
|
<div class="right-menu flex align-center">
|
|
<template v-if="appStore.device !== 'mobile'">
|
|
<el-tag v-if="isSuperAdmin && tenantEnabled && !tenantContextVerified" class="mr-2" type="warning" effect="plain"> 租户上下文未确认 </el-tag>
|
|
<el-select
|
|
v-if="isSuperAdmin && tenantEnabled"
|
|
v-model="selectedTenantId"
|
|
class="min-w-244px mr-2"
|
|
clearable
|
|
filterable
|
|
:disabled="tenantContextSwitching"
|
|
:loading="tenantContextSwitching"
|
|
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>
|
|
|
|
<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 style="display: flex; align-items: center">
|
|
<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">
|
|
<div class="right-menu-item hover-effect"><svg-icon icon-class="message" /></div>
|
|
</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="proxy.$t('navbar.document')" effect="dark" placement="bottom">
|
|
<ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />
|
|
</el-tooltip>
|
|
|
|
<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="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 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 v-if="!dynamic" to="/user/profile">
|
|
<el-dropdown-item>{{ proxy.$t('navbar.personalCenter') }}</el-dropdown-item>
|
|
</router-link>
|
|
<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>{{ proxy.$t('navbar.logout') }}</span>
|
|
</el-dropdown-item>
|
|
</el-dropdown-menu>
|
|
</template>
|
|
</el-dropdown>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<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 { getDynamicTenant } from '@/api/system/tenant';
|
|
import { TenantVO } from '@/api/types';
|
|
import notice from './notice/index.vue';
|
|
import router from '@/router';
|
|
import {
|
|
clearDynamicTenantContext,
|
|
clearDynamicTenantContextState,
|
|
dynamicTenantContextVersion,
|
|
dynamicTenantId,
|
|
hasDynamicTenant,
|
|
isTenantContextVersionCurrent,
|
|
markTenantContextUnverified,
|
|
restoreDynamicTenantContext,
|
|
switchDynamicTenantContext,
|
|
tenantContextVerified,
|
|
tenantContextSwitching,
|
|
waitForTenantRequestContextOwnership
|
|
} from '@/utils/tenant-context';
|
|
import { ElMessageBoxOptions } from 'element-plus/es/components/message-box/src/message-box.type';
|
|
import { NavTypeEnum } from '@/enums/NavTypeEnum';
|
|
import Logo from '@/layout/components/Sidebar/Logo.vue';
|
|
import TopBar from './TopBar';
|
|
|
|
const appStore = useAppStore();
|
|
const userStore = useUserStore();
|
|
const settingsStore = useSettingsStore();
|
|
const noticeStore = storeToRefs(useNoticeStore());
|
|
const newNotice = ref(<number>0);
|
|
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
|
|
const navType = computed(() => settingsStore.navType);
|
|
const showLogo = computed(() => settingsStore.sidebarLogo);
|
|
const isSuperAdmin = computed(() => userStore.roles.includes('superadmin'));
|
|
|
|
const selectedTenantId = ref<string | number>();
|
|
const tenantList = ref<TenantVO[]>([]);
|
|
// 是否切换了租户
|
|
const dynamic = hasDynamicTenant;
|
|
// 租户开关
|
|
const tenantEnabled = ref(true);
|
|
// 搜索菜单
|
|
const searchMenuRef = ref<InstanceType<typeof SearchMenu>>();
|
|
|
|
const openSearchMenu = () => {
|
|
searchMenuRef.value?.openSearch();
|
|
};
|
|
|
|
// 动态切换
|
|
const dynamicTenantEvent = async (tenantId?: string | number) => {
|
|
if (tenantId === undefined || tenantId === null || tenantId === '' || tenantContextSwitching.value) return;
|
|
const tenant = tenantList.value.find((item) => String(item.tenantId) === String(tenantId));
|
|
if (!tenant) {
|
|
selectedTenantId.value = dynamicTenantId.value;
|
|
return;
|
|
}
|
|
try {
|
|
await switchDynamicTenantContext({ tenantId, companyName: tenant.companyName }, '/');
|
|
} catch {
|
|
selectedTenantId.value = dynamicTenantId.value;
|
|
}
|
|
};
|
|
|
|
const dynamicClearEvent = async () => {
|
|
if (tenantContextSwitching.value) return;
|
|
try {
|
|
await clearDynamicTenantContext('/');
|
|
} catch {
|
|
selectedTenantId.value = dynamicTenantId.value;
|
|
}
|
|
};
|
|
|
|
/** 租户列表 */
|
|
const initTenantList = async () => {
|
|
await waitForTenantRequestContextOwnership();
|
|
let contextVersion = dynamicTenantContextVersion.value;
|
|
const isCurrentInit = () => isTenantContextVersionCurrent(contextVersion);
|
|
let currentTenantId: string | number | null | undefined;
|
|
let dynamicContextLoaded = false;
|
|
|
|
// Read the page-scoped server context first. Without this echo, a restored
|
|
// dynamic tenant deliberately rejects the tenant list request as stale.
|
|
if (isSuperAdmin.value) {
|
|
try {
|
|
currentTenantId = (await getDynamicTenant()).data;
|
|
if (!isCurrentInit()) return;
|
|
restoreDynamicTenantContext(
|
|
currentTenantId !== undefined && currentTenantId !== null && currentTenantId !== '' ? { tenantId: currentTenantId } : undefined
|
|
);
|
|
contextVersion = dynamicTenantContextVersion.value;
|
|
dynamicContextLoaded = true;
|
|
} catch {
|
|
if (!isCurrentInit()) return;
|
|
}
|
|
}
|
|
|
|
try {
|
|
const { data } = await getTenantList(true);
|
|
if (!isCurrentInit()) return;
|
|
|
|
tenantEnabled.value = data.tenantEnabled === undefined ? true : data.tenantEnabled;
|
|
if (!tenantEnabled.value || !isSuperAdmin.value) {
|
|
tenantList.value = [];
|
|
clearDynamicTenantContextState();
|
|
return;
|
|
}
|
|
|
|
tenantList.value = data.voList.filter((tenant) => tenant.status === undefined || tenant.status === '0');
|
|
} catch {
|
|
if (!isCurrentInit()) return;
|
|
tenantList.value = [];
|
|
markTenantContextUnverified();
|
|
return;
|
|
}
|
|
|
|
if (!dynamicContextLoaded) {
|
|
markTenantContextUnverified();
|
|
return;
|
|
}
|
|
|
|
const tenant = tenantList.value.find((item) => String(item.tenantId) === String(currentTenantId));
|
|
if (currentTenantId !== undefined && currentTenantId !== null && currentTenantId !== '' && !tenant) {
|
|
markTenantContextUnverified();
|
|
return;
|
|
}
|
|
restoreDynamicTenantContext(
|
|
currentTenantId !== undefined && currentTenantId !== null && currentTenantId !== ''
|
|
? { tenantId: currentTenantId, companyName: tenant?.companyName }
|
|
: undefined
|
|
);
|
|
};
|
|
|
|
watch(
|
|
dynamicTenantId,
|
|
(tenantId) => {
|
|
selectedTenantId.value = tenantId;
|
|
},
|
|
{ immediate: true }
|
|
);
|
|
|
|
defineExpose({
|
|
initTenantList
|
|
});
|
|
|
|
const toggleSideBar = () => {
|
|
appStore.toggleSideBar(false);
|
|
};
|
|
|
|
const logout = async () => {
|
|
await ElMessageBox.confirm('确定注销并退出系统吗?', '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
} as ElMessageBoxOptions);
|
|
userStore.logout().then(() => {
|
|
router.replace({
|
|
path: '/login',
|
|
query: {
|
|
redirect: encodeURIComponent(router.currentRoute.value.fullPath || '/')
|
|
}
|
|
});
|
|
proxy?.$tab.closeAllPage();
|
|
});
|
|
};
|
|
|
|
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>
|
|
.navbar.navtop {
|
|
.hamburger-container {
|
|
display: none !important;
|
|
}
|
|
}
|
|
|
|
:deep(.el-select .el-input__wrapper) {
|
|
height: 30px;
|
|
}
|
|
|
|
:deep(.el-badge__content.is-fixed) {
|
|
top: 12px;
|
|
}
|
|
|
|
.flex {
|
|
display: flex;
|
|
}
|
|
|
|
.align-center {
|
|
align-items: center;
|
|
}
|
|
|
|
.navbar {
|
|
height: 50px;
|
|
overflow: hidden;
|
|
position: relative;
|
|
background: var(--el-bg-color);
|
|
border-bottom: 1px solid var(--el-border-color-lighter);
|
|
box-shadow: none;
|
|
display: flex;
|
|
align-items: center;
|
|
// padding: 0 8px;
|
|
box-sizing: border-box;
|
|
|
|
.hamburger-container {
|
|
line-height: 46px;
|
|
height: 100%;
|
|
//float: left;
|
|
cursor: pointer;
|
|
transition: background 0.3s;
|
|
-webkit-tap-highlight-color: transparent;
|
|
display: flex;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
margin-right: 8px;
|
|
|
|
&:hover {
|
|
background: var(--el-fill-color-lighter);
|
|
}
|
|
}
|
|
|
|
.breadcrumb-container {
|
|
//float: left;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.topmenu-container {
|
|
position: absolute;
|
|
left: 50px;
|
|
}
|
|
|
|
.topbar-container {
|
|
flex: 1;
|
|
min-width: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
overflow: hidden;
|
|
margin-left: 8px;
|
|
}
|
|
|
|
.errLog-container {
|
|
display: inline-block;
|
|
vertical-align: top;
|
|
}
|
|
|
|
.right-menu {
|
|
height: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
margin-left: auto;
|
|
|
|
&:focus {
|
|
outline: none;
|
|
}
|
|
|
|
.right-menu-item {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 0 8px;
|
|
height: 32px;
|
|
font-size: 18px;
|
|
color: var(--el-text-color-regular);
|
|
border-radius: var(--app-radius-md);
|
|
|
|
&.hover-effect {
|
|
cursor: pointer;
|
|
transition:
|
|
background 0.2s ease,
|
|
color 0.2s ease;
|
|
|
|
&:hover {
|
|
background: var(--el-fill-color-light);
|
|
color: var(--el-color-primary);
|
|
}
|
|
}
|
|
}
|
|
|
|
.avatar-container {
|
|
margin-right: 40px;
|
|
|
|
.avatar-wrapper {
|
|
margin-top: 0;
|
|
position: relative;
|
|
|
|
.user-avatar {
|
|
cursor: pointer;
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: var(--app-radius-md);
|
|
margin-top: 0;
|
|
display: block;
|
|
}
|
|
|
|
i {
|
|
cursor: pointer;
|
|
position: absolute;
|
|
right: -20px;
|
|
top: 25px;
|
|
font-size: 12px;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|