| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749 |
- <template>
- <div
- class="layout-wrapper"
- :class="{ 'full-screen': isFullScreen }"
- :style="isSpecialBg ? backgroundStyle : {}"
- >
- <!-- 背景层 -->
- <div v-if="isSpecialBg" class="background-layer"></div>
- <!-- Header -->
- <el-header
- class="layout-header"
- v-if="!isFullScreen"
- :class="{ 'transparent-header': isSpecialBg }"
- >
- <div class="logo-title-row">
- <!-- 左侧:Logo和标题 -->
- <div class="left-section">
- <img src="@/assets/logo.png" alt="Logo" class="logo" />
- <span class="project-name" :class="{ 'light-text': isSpecialBg }">
- 土壤酸化智能预测专家系统
- </span>
- </div>
- <!-- 右侧:用户信息 -->
- <div class="right-section" v-if="!isSelectCity">
- <div class="user-info-row">
- <span class="welcome-text" :class="{ 'light-text': isSpecialBg }">
- 欢迎 {{ userInfo.name }} 登录成功
- </span>
- <el-dropdown>
- <span class="el-dropdown-link">
- <el-avatar
- :size="40"
- :class="{ 'light-avatar-border': isSpecialBg }"
- src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
- />
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item disabled
- >用户名:{{ userInfo.name }}</el-dropdown-item
- >
- <el-dropdown-item divided @click="handleLogout"
- >退出登录</el-dropdown-item
- >
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- </div>
- </div>
- </div>
- </el-header>
- <div class="tabs-row" v-if="!isFullScreen">
- <el-tabs
- v-if="showTabs"
- v-model="activeName"
- class="demo-tabs"
- :style="tabStyle"
- @tab-click="handleClick"
- >
- <el-tab-pane v-for="tab in tabs" :key="tab.name" :name="tab.name">
- <template #label>
- <i :class="['tab-icon', tab.icon]"></i>
- <span class="tab-label-text">{{ tab.label }}</span>
- </template>
- </el-tab-pane>
- </el-tabs>
- <div v-else class="single-tab" @click="handleClick(tabs[0], $event)">
- <i :class="['tab-icon', tabs[0].icon]"></i>
- <span class="tab-label-text">{{ tabs[0].label }}</span>
- </div>
- </div>
- <!-- Main Content -->
- <el-container class="layout-main-container">
- <el-aside v-if="showAside && showTabs" class="layout-aside">
- <component
- :is="AsideComponent"
- :activeTab="activeName"
- :showTabs="showTabs"
- />
- </el-aside>
- <el-main class="layout-content-wrapper" :style="mainStyle">
- <div
- class="scrollable-content"
- :class="{ 'transparent-scroll': isSpecialBg }"
- >
- <div :class="{ 'select-city-container': isSelectCity }">
- <RouterView />
- </div>
- </div>
- </el-main>
- </el-container>
-
- <!-- 全局消息提示组件 -->
- <div v-if="showGlobalMessage" class="global-message">
- <div class="message-content" :class="messageType">
- {{ globalMessage }}
- </div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { ref, reactive, computed, watch, defineAsyncComponent } from "vue";
- import { useRouter, useRoute } from "vue-router";
- import { useTokenStore } from "@/stores/mytoken";
- import { ElMessageBox, ElMessage } from "element-plus"; // 确保导入ElMessage
- import { logout } from "@/API/users";
- const router = useRouter();
- const route = useRoute();
- const tokenStore = useTokenStore();
- const currentBgImage = ref("");
- // ============ 新增状态 ============
- const showGlobalMessage = ref(false);
- const globalMessage = ref("");
- const messageType = ref("success"); // 消息类型: success/error
- currentBgImage.value = `url(${new URL('../../assets/bg/background.jpg', import.meta.url).href})`;
- // 是否特殊背景(始终返回true → 所有页面应用特殊背景样式)
- const isSpecialBg = computed(() => true);
- const backgroundStyle = computed(() => ({
- backgroundImage: currentBgImage.value,
- backgroundSize: "cover",
- backgroundPosition: "center",
- backgroundRepeat: "no-repeat",
- backgroundAttachment: "fixed",
- }));
- const isFullScreen = computed(() => route.meta.fullScreen === true);
- const isSelectCity = computed(() => route.path === "/select-city");
- // 当前用户信息
- const userInfo = reactive({
- name: tokenStore.userName,
- type: tokenStore.userType,
- });
- const tabs = computed(() => {
- if (userInfo.type === "admin") {
- return [
- {
- name: "dataManagement",
- label: "数据管理",
- icon: "el-icon-folder",
- routes: [
- "/soilAcidReductionData",
- "/soilAcidificationData",
- "/crossSectionSampleData",
- "/irrigationWaterInputFluxData",
- "/heavyMetalEnterpriseData",
- "/atmosphericSampleData",
- ],
- },
- {
- name: "infoManagement",
- label: "信息管理",
- icon: "el-icon-document",
- routes: ["/IntroductionUpdate"],
- },
- {
- name: "modelManagement",
- label: "模型管理及配置",
- icon: "el-icon-cpu",
- routes: ["/ModelSelection", "/thres", "/ModelTrain"],
- },
- {
- name: "userManagement",
- label: "用户管理",
- icon: "el-icon-user",
- routes: ["/UserManagement"],
- },
- ];
- } else {
- return [
- {
- name: "introduction",
- label: "软件简介",
- icon: "el-icon-info-filled",
- routes: ["/SoilPro", "/Overview", "/ResearchFindings", "/Unit"],
- },
- {
- name: "acidmodelmap",
- label: "土壤酸化地块级计算",
- icon: "el-icon-data-analysis",
- routes: ["/shaoguan_acidmodelmap","nanxiong_acidmodelmap"],
- },
- {
- name: "Calculation",
- label: "土壤反酸模型",
- icon: "el-icon-data-analysis",
- routes: ["/Calculation", "/SoilAcidReductionIterativeEvolution"],
- },
- {
- name: "AcidNeutralizationModel",
- label: "土壤降酸模型",
- icon: "el-icon-data-analysis",
- routes: ["/AcidNeutralizationModel", "/SoilAcidificationIterativeEvolution"],
- },
- {
- name: "dataStatistics",
- label: "数据统计",
- icon: "el-icon-pie-chart",
- routes: [
- "/DetectionStatistics",
- "/FarmlandPollutionStatistics",
- "/LandClutivatesStatistics",
- "/SoilacidificationStatistics",
- ],
- },
- ];
- }
- });
- const activeName = ref(tabs.value[0]?.name || "");
- const showTabs = computed(() => tabs.value.length > 1);
- const tabStyle = computed(() =>
- tabs.value.length === 1 ? { width: "100%", justifyContent: "center" } : {}
- );
- let hasNavigated = false;
- watch(
- () => activeName.value,
- (newTab) => {
- const tab = tabs.value.find((t) => t.name === newTab);
- const targetPath = tab?.routes?.[0];
- if (!hasNavigated) {
- hasNavigated = true;
- return;
- }
- if (tab && targetPath && router.currentRoute.value.path !== targetPath)
- router.push({ path: targetPath });
- },
- { immediate: true }
- );
- // 点击 tab
- const activeAsideTab = ref(activeName.value || "");
- const handleClick = (tab: any, _event?: Event) => {
- activeAsideTab.value = tab.name || tab.props?.name;
- };
- // 动态加载侧边栏
- const AsideComponent = computed(() => {
- return [
- "dataManagement",
- "infoManagement",
- "modelManagement",
- "userManagement",
- ].includes(activeName.value)
- ? defineAsyncComponent(() => import("./AppAsideForTab2.vue"))
- : defineAsyncComponent(() => import("./AppAside.vue"));
- });
- // 是否显示侧边栏
- const showAside = computed(
- () =>
- !isFullScreen.value && !["cropRiskAssessment"].includes(activeName.value)
- );
- // ============ 显示全局消息 ============
- // 登出逻辑
- const handleLogout = async () => {
- try {
- await ElMessageBox.confirm("确定要退出登录吗?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- });
- await logout();
- tokenStore.clearToken();
-
- // 使用ElMessage而不是全局消息提示
- ElMessage.success("退出登录成功");
-
- // 延迟跳转,让用户看到提示消息
- setTimeout(() => {
- router.push("/login");
- }, 1000);
- } catch (error) {
- // 区分用户取消操作和真正的错误
- if (error === 'cancel' || error?.toString().includes('cancel')) {
- console.log("用户取消退出登录");
- } else {
- ElMessage.error("退出失败,请重试");
- console.error("退出登录错误:", error);
- }
- }
- };
- // 内容区样式
- const mainStyle = computed(() => ({
- padding: ["mapView", "infoManagement"].includes(activeName.value)
- ? "0"
- : "20px",
- overflow: "hidden",
- }));
- </script>
- <style>
- /* 隐藏所有滚动条 */
- *::-webkit-scrollbar {
- display: none;
- /* Chrome, Safari, Opera */
- }
- * {
- -ms-overflow-style: none;
- /* IE and Edge */
- scrollbar-width: none;
- /* Firefox */
- }
- /* 整体布局容器 */
- .layout-wrapper {
- display: flex;
- flex-direction: column;
- height: 100vh;
- overflow: hidden;
- position: relative; /* 创建层叠上下文 */
- background-color: #f5f7fa; /* 默认背景色 */
- /* 确保 layout-wrapper 自身的 z-index 不干扰子元素,或根据需要设置 */
- /* z-index: 0; */ /* 通常不需要显式设置,除非有特殊需求 */
- }
- /* 背景层 - 关键修改 */
- .background-layer {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- /* 将背景层的 z-index 设为一个较低的负值或非常小的正值,确保它在最底层 */
- z-index: -1; /* 修改点:使用负值确保其在最底层,避免任何可能的遮挡 */
- background-size: cover;
- background-position: center;
- background-repeat: no-repeat;
- filter: brightness(0.8);
- }
- /* 全屏页面特殊处理 */
- .layout-wrapper.full-screen {
- background: none;
- min-height: 100vh;
- }
- /* 特殊背景页面的Header样式 */
- .transparent-header {
- background: transparent !important;
- backdrop-filter: blur(2px); /* 添加轻微模糊效果增强可读性 */
- }
- /* 特殊背景页面的文字颜色 */
- .light-text {
- color: #ffffff !important; /* 白色文字 */
- text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); /* 文字阴影增强可读性 */
- }
- /* 特殊背景页面的头像边框 */
- .light-avatar-border {
- border: 2px solid #ffffff !important; /* 白色边框 */
- }
- /* 内容区域在特殊背景页面透明 */
- .transparent-scroll {
- background-color: transparent !important;
- }
- /* Header 样式 */
- .layout-header {
- height: 80px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- color: #333; /* 深色文字 */
- flex-shrink: 0;
- /* 确保在背景层上方 */
- position: relative;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10; /* 增大 z-index */
- background-color: white; /* 默认背景色 */
- }
- /* 修改Header布局样式 */
- .logo-title-row {
- display: flex;
- align-items: center;
- justify-content: space-between; /* 左右两侧分布 */
- width: 100%;
- gap: 24px;
- }
- .title-and-user {
- display: flex;
- flex-direction: row;
- flex: 1;
- }
- /* 用户信息区域样式调整 */
- .user-info-row {
- display: flex;
- align-items: center;
- gap: 16px;
- color: #333;
- }
- .welcome-text {
- font-size: 28px;
- font-weight: 500;
- color: #ffffff;
- white-space: nowrap; /* 防止文字换行 */
- }
- /* Tab 区域 - 不透明 */
- .tabs-row {
- height: 48px;
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 0 24px;
- background: linear-gradient(to right, #1092d8, #02c3ad);
- border-bottom: none !important;
- flex-shrink: 0;
- /* 确保在背景层上方 */
- position: relative;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10; /* 增大 z-index */
- }
- /* el-tabs 外层容器 */
- .demo-tabs {
- height: 48px !important;
- display: flex;
- align-items: center;
- width: 100%;
- padding: 0 !important;
- margin: 0 !important;
- border-bottom: none !important;
- }
- /* 清除滑块条和底部线条 */
- .el-tabs__nav-wrap::after,
- .el-tabs__active-bar {
- display: none !important;
- height: 0 !important;
- border: none !important;
- }
- .el-tabs__nav-scroll {
- padding: 0 !important;
- margin: 0 !important;
- }
- /* Tabs 单项样式 */
- .el-tabs__item {
- height: 48px !important;
- line-height: 48px !important;
- display: flex !important;
- align-items: center;
- justify-content: center;
- padding: 0 20px !important;
- font-size: 20px;
- font-weight: 600;
- border-radius: 10px;
- transition: all 0.2s ease-in-out;
- background-color: transparent;
- position: relative;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10; /* 增大 z-index */
- }
- /* 激活 Tab */
- .el-tabs__item.is-active {
- background-color: #2a53ba;
- color: #ffffff;
- font-weight: 700;
- box-shadow: 0 4px 16px rgba(26, 188, 156, 0.4);
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 11; /* 激活项可以更高一点 */
- }
- /* 鼠标悬停 */
- .el-tabs__item:hover {
- background-color: #455a64;
- color: #ffffff;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 11; /* 悬停时也可以更高 */
- }
- /* 图标样式 */
- .tab-icon {
- font-size: 24px;
- margin-right: 4px;
- color: inherit;
- }
- /* 文字样式 */
- .tab-label-text {
- font-size: 20px;
- color: inherit;
- line-height: 1;
- display: inline-block;
- }
- .logo {
- height: 60px;
- }
- .project-name {
- font-size: 32px; /* 适当调整字体大小 */
- font-weight: bold;
- color: #333;
- white-space: nowrap; /* 防止标题换行 */
- }
- /* 响应式设计:在小屏幕上调整布局 */
- @media (max-width: 1200px) {
- .project-name {
- font-size: 20px;
- }
-
- .welcome-text {
- font-size: 14px;
- }
- }
- @media (max-width: 768px) {
- .logo-title-row {
- flex-wrap: wrap;
- gap: 12px;
- }
-
- .left-section {
- order: 1;
- width: 100%;
- justify-content: center;
- }
-
- .right-section {
- order: 2;
- width: 100%;
- justify-content: center;
- }
-
- .project-name {
- font-size: 18px;
- text-align: center;
- }
- }
- .layout-main-container {
- flex: 1;
- display: flex;
- overflow: hidden;
- min-height: 0;
- /* 确保在背景层上方 */
- position: relative;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10; /* 增大 z-index */
- }
- /* 侧边栏 - 白色背景 */
- .layout-aside {
- width: 280px;
- background: linear-gradient(to bottom, #b7f1fc, #fff8f0);
- border-right: 1px solid;
- overflow-y: auto;
- color: #000000;
- padding-top: 8px;
- height: 100%;
- position: relative;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10; /* 增大 z-index */
- }
- /* 隐藏侧边栏滚动条 */
- .layout-aside::-webkit-scrollbar {
- display: none;
- }
- .layout-aside .el-menu-item,
- .layout-aside .el-sub-menu__title {
- font-size: 18px;
- font-weight: 500;
- color: #000000;
- background-color: transparent;
- transition: all 0.2s ease;
- border-radius: 6px;
- padding: 12px 16px !important;
- }
- .layout-aside .el-menu-item:hover,
- .layout-aside .el-sub-menu__title:hover {
- background-color: rgba(16, 146, 216, 0.1);
- color: #1092d8;
- }
- .layout-aside .el-menu-item.is-active,
- .layout-aside .el-sub-menu__title.is-active {
- background: linear-gradient(to right, #1092d8, #02c3ad);
- color: #000000 !important;
- border-radius: 8px;
- font-weight: 600;
- box-shadow: 0 2px 8px rgba(16, 146, 216, 0.25);
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 11; /* 激活项可以更高一点 */
- }
- .layout-content-wrapper {
- flex: 1;
- overflow: hidden;
- display: flex;
- flex-direction: column;
- position: relative;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10; /* 增大 z-index */
- }
- /* 强制重置 el-tabs header 高度/边距/背景/阴影,避免背景层穿透错位 */
- .el-tabs__header.is-top {
- height: 48px !important;
- margin: 0 !important;
- padding: 0 !important;
- border: none !important;
- background: transparent !important;
- box-shadow: none !important;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10 !important; /* 增大 z-index */
- }
- /* 全屏页面特殊处理 */
- .layout-wrapper.full-screen .layout-main-container {
- height: 100vh;
- }
- .scrollable-content {
- flex: 1;
- overflow: auto;
- padding: 0 20px;
- box-sizing: border-box;
- background-color: white; /* 默认背景色 */
- position: relative; /* 确保它可以参与 z-index 计算 */
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10; /* 增大 z-index */
- }
- .scrollable-content.transparent-scroll {
- background-color: transparent;
- /* 修改点:增大 z-index 确保在背景层之上 */
- z-index: 10; /* 即使透明也应保持在上层 */
- }
- /* 左侧区域 */
- .left-section {
- display: flex;
- align-items: center;
- gap: 24px;
- flex-shrink: 0; /* 防止缩小 */
- }
- /* 右侧区域 */
- .right-section {
- display: flex;
- align-items: center;
- justify-content: flex-end;
- flex-shrink: 0; /* 防止缩小 */
- }
- </style>
|