AppLayout.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <template>
  2. <div
  3. class="layout-wrapper"
  4. :class="{ 'full-screen': isFullScreen }"
  5. :style="isSpecialBg ? backgroundStyle : {}"
  6. >
  7. <!-- 背景层 -->
  8. <div v-if="isSpecialBg" class="background-layer"></div>
  9. <!-- Header -->
  10. <el-header
  11. class="layout-header"
  12. v-if="!isFullScreen"
  13. :class="{ 'transparent-header': isSpecialBg }"
  14. >
  15. <div class="logo-title-row">
  16. <!-- 左侧:Logo和标题 -->
  17. <div class="left-section">
  18. <img src="@/assets/logo.png" alt="Logo" class="logo" />
  19. <span class="project-name" :class="{ 'light-text': isSpecialBg }">
  20. 土壤酸化智能预测专家系统
  21. </span>
  22. </div>
  23. <!-- 右侧:用户信息 -->
  24. <div class="right-section" v-if="!isSelectCity">
  25. <div class="user-info-row">
  26. <span class="welcome-text" :class="{ 'light-text': isSpecialBg }">
  27. 欢迎 {{ userInfo.name }} 登录成功
  28. </span>
  29. <el-dropdown>
  30. <span class="el-dropdown-link">
  31. <el-avatar
  32. :size="40"
  33. :class="{ 'light-avatar-border': isSpecialBg }"
  34. src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
  35. />
  36. </span>
  37. <template #dropdown>
  38. <el-dropdown-menu>
  39. <el-dropdown-item disabled
  40. >用户名:{{ userInfo.name }}</el-dropdown-item
  41. >
  42. <el-dropdown-item divided @click="handleLogout"
  43. >退出登录</el-dropdown-item
  44. >
  45. </el-dropdown-menu>
  46. </template>
  47. </el-dropdown>
  48. </div>
  49. </div>
  50. </div>
  51. </el-header>
  52. <div class="tabs-row" v-if="!isFullScreen">
  53. <el-tabs
  54. v-if="showTabs"
  55. v-model="activeName"
  56. class="demo-tabs"
  57. :style="tabStyle"
  58. @tab-click="handleClick"
  59. >
  60. <el-tab-pane v-for="tab in tabs" :key="tab.name" :name="tab.name">
  61. <template #label>
  62. <i :class="['tab-icon', tab.icon]"></i>
  63. <span class="tab-label-text">{{ tab.label }}</span>
  64. </template>
  65. </el-tab-pane>
  66. </el-tabs>
  67. <div v-else class="single-tab" @click="handleClick(tabs[0], $event)">
  68. <i :class="['tab-icon', tabs[0].icon]"></i>
  69. <span class="tab-label-text">{{ tabs[0].label }}</span>
  70. </div>
  71. </div>
  72. <!-- Main Content -->
  73. <el-container class="layout-main-container">
  74. <el-aside v-if="showAside && showTabs" class="layout-aside">
  75. <component
  76. :is="AsideComponent"
  77. :activeTab="activeName"
  78. :showTabs="showTabs"
  79. />
  80. </el-aside>
  81. <el-main class="layout-content-wrapper" :style="mainStyle">
  82. <div
  83. class="scrollable-content"
  84. :class="{ 'transparent-scroll': isSpecialBg }"
  85. >
  86. <div :class="{ 'select-city-container': isSelectCity }">
  87. <RouterView />
  88. </div>
  89. </div>
  90. </el-main>
  91. </el-container>
  92. <!-- 全局消息提示组件 -->
  93. <div v-if="showGlobalMessage" class="global-message">
  94. <div class="message-content" :class="messageType">
  95. {{ globalMessage }}
  96. </div>
  97. </div>
  98. </div>
  99. </template>
  100. <script setup lang="ts">
  101. import { ref, reactive, computed, watch, defineAsyncComponent } from "vue";
  102. import { useRouter, useRoute } from "vue-router";
  103. import { useTokenStore } from "@/stores/mytoken";
  104. import { ElMessageBox, ElMessage } from "element-plus"; // 确保导入ElMessage
  105. import { logout } from "@/API/users";
  106. const router = useRouter();
  107. const route = useRoute();
  108. const tokenStore = useTokenStore();
  109. const currentBgImage = ref("");
  110. // ============ 新增状态 ============
  111. const showGlobalMessage = ref(false);
  112. const globalMessage = ref("");
  113. const messageType = ref("success"); // 消息类型: success/error
  114. currentBgImage.value = `url(${new URL('../../assets/bg/background.jpg', import.meta.url).href})`;
  115. // 是否特殊背景(始终返回true → 所有页面应用特殊背景样式)
  116. const isSpecialBg = computed(() => true);
  117. const backgroundStyle = computed(() => ({
  118. backgroundImage: currentBgImage.value,
  119. backgroundSize: "cover",
  120. backgroundPosition: "center",
  121. backgroundRepeat: "no-repeat",
  122. backgroundAttachment: "fixed",
  123. }));
  124. const isFullScreen = computed(() => route.meta.fullScreen === true);
  125. const isSelectCity = computed(() => route.path === "/select-city");
  126. // 当前用户信息
  127. const userInfo = reactive({
  128. name: tokenStore.userName,
  129. type: tokenStore.userType,
  130. });
  131. const tabs = computed(() => {
  132. if (userInfo.type === "admin") {
  133. return [
  134. {
  135. name: "dataManagement",
  136. label: "数据管理",
  137. icon: "el-icon-folder",
  138. routes: [
  139. "/soilAcidReductionData",
  140. "/soilAcidificationData",
  141. "/crossSectionSampleData",
  142. "/irrigationWaterInputFluxData",
  143. "/heavyMetalEnterpriseData",
  144. "/atmosphericSampleData",
  145. ],
  146. },
  147. {
  148. name: "infoManagement",
  149. label: "信息管理",
  150. icon: "el-icon-document",
  151. routes: ["/IntroductionUpdate"],
  152. },
  153. {
  154. name: "modelManagement",
  155. label: "模型管理及配置",
  156. icon: "el-icon-cpu",
  157. routes: ["/ModelSelection", "/thres", "/ModelTrain"],
  158. },
  159. {
  160. name: "userManagement",
  161. label: "用户管理",
  162. icon: "el-icon-user",
  163. routes: ["/UserManagement"],
  164. },
  165. ];
  166. } else {
  167. return [
  168. {
  169. name: "introduction",
  170. label: "软件简介",
  171. icon: "el-icon-info-filled",
  172. routes: ["/SoilPro", "/Overview", "/ResearchFindings", "/Unit"],
  173. },
  174. {
  175. name: "acidmodelmap",
  176. label: "土壤酸化地块级计算",
  177. icon: "el-icon-data-analysis",
  178. routes: ["/shaoguan_acidmodelmap","nanxiong_acidmodelmap"],
  179. },
  180. {
  181. name: "Calculation",
  182. label: "土壤反酸模型",
  183. icon: "el-icon-data-analysis",
  184. routes: ["/Calculation", "/SoilAcidReductionIterativeEvolution"],
  185. },
  186. {
  187. name: "AcidNeutralizationModel",
  188. label: "土壤降酸模型",
  189. icon: "el-icon-data-analysis",
  190. routes: ["/AcidNeutralizationModel", "/SoilAcidificationIterativeEvolution"],
  191. },
  192. {
  193. name: "dataStatistics",
  194. label: "数据统计",
  195. icon: "el-icon-pie-chart",
  196. routes: [
  197. "/DetectionStatistics",
  198. "/FarmlandPollutionStatistics",
  199. "/LandClutivatesStatistics",
  200. "/SoilacidificationStatistics",
  201. ],
  202. },
  203. ];
  204. }
  205. });
  206. const activeName = ref(tabs.value[0]?.name || "");
  207. const showTabs = computed(() => tabs.value.length > 1);
  208. const tabStyle = computed(() =>
  209. tabs.value.length === 1 ? { width: "100%", justifyContent: "center" } : {}
  210. );
  211. let hasNavigated = false;
  212. watch(
  213. () => activeName.value,
  214. (newTab) => {
  215. const tab = tabs.value.find((t) => t.name === newTab);
  216. const targetPath = tab?.routes?.[0];
  217. if (!hasNavigated) {
  218. hasNavigated = true;
  219. return;
  220. }
  221. if (tab && targetPath && router.currentRoute.value.path !== targetPath)
  222. router.push({ path: targetPath });
  223. },
  224. { immediate: true }
  225. );
  226. // 点击 tab
  227. const activeAsideTab = ref(activeName.value || "");
  228. const handleClick = (tab: any, _event?: Event) => {
  229. activeAsideTab.value = tab.name || tab.props?.name;
  230. };
  231. // 动态加载侧边栏
  232. const AsideComponent = computed(() => {
  233. return [
  234. "dataManagement",
  235. "infoManagement",
  236. "modelManagement",
  237. "userManagement",
  238. ].includes(activeName.value)
  239. ? defineAsyncComponent(() => import("./AppAsideForTab2.vue"))
  240. : defineAsyncComponent(() => import("./AppAside.vue"));
  241. });
  242. // 是否显示侧边栏
  243. const showAside = computed(
  244. () =>
  245. !isFullScreen.value && !["cropRiskAssessment"].includes(activeName.value)
  246. );
  247. // ============ 显示全局消息 ============
  248. // 登出逻辑
  249. const handleLogout = async () => {
  250. try {
  251. await ElMessageBox.confirm("确定要退出登录吗?", "提示", {
  252. confirmButtonText: "确定",
  253. cancelButtonText: "取消",
  254. type: "warning",
  255. });
  256. await logout();
  257. tokenStore.clearToken();
  258. // 使用ElMessage而不是全局消息提示
  259. ElMessage.success("退出登录成功");
  260. // 延迟跳转,让用户看到提示消息
  261. setTimeout(() => {
  262. router.push("/login");
  263. }, 1000);
  264. } catch (error) {
  265. // 区分用户取消操作和真正的错误
  266. if (error === 'cancel' || error?.toString().includes('cancel')) {
  267. console.log("用户取消退出登录");
  268. } else {
  269. ElMessage.error("退出失败,请重试");
  270. console.error("退出登录错误:", error);
  271. }
  272. }
  273. };
  274. // 内容区样式
  275. const mainStyle = computed(() => ({
  276. padding: ["mapView", "infoManagement"].includes(activeName.value)
  277. ? "0"
  278. : "20px",
  279. overflow: "hidden",
  280. }));
  281. </script>
  282. <style>
  283. /* 隐藏所有滚动条 */
  284. *::-webkit-scrollbar {
  285. display: none;
  286. /* Chrome, Safari, Opera */
  287. }
  288. * {
  289. -ms-overflow-style: none;
  290. /* IE and Edge */
  291. scrollbar-width: none;
  292. /* Firefox */
  293. }
  294. /* 整体布局容器 */
  295. .layout-wrapper {
  296. display: flex;
  297. flex-direction: column;
  298. height: 100vh;
  299. overflow: hidden;
  300. position: relative; /* 创建层叠上下文 */
  301. background-color: #f5f7fa; /* 默认背景色 */
  302. /* 确保 layout-wrapper 自身的 z-index 不干扰子元素,或根据需要设置 */
  303. /* z-index: 0; */ /* 通常不需要显式设置,除非有特殊需求 */
  304. }
  305. /* 背景层 - 关键修改 */
  306. .background-layer {
  307. position: absolute;
  308. top: 0;
  309. left: 0;
  310. width: 100%;
  311. height: 100%;
  312. /* 将背景层的 z-index 设为一个较低的负值或非常小的正值,确保它在最底层 */
  313. z-index: -1; /* 修改点:使用负值确保其在最底层,避免任何可能的遮挡 */
  314. background-size: cover;
  315. background-position: center;
  316. background-repeat: no-repeat;
  317. filter: brightness(0.8);
  318. }
  319. /* 全屏页面特殊处理 */
  320. .layout-wrapper.full-screen {
  321. background: none;
  322. min-height: 100vh;
  323. }
  324. /* 特殊背景页面的Header样式 */
  325. .transparent-header {
  326. background: transparent !important;
  327. backdrop-filter: blur(2px); /* 添加轻微模糊效果增强可读性 */
  328. }
  329. /* 特殊背景页面的文字颜色 */
  330. .light-text {
  331. color: #ffffff !important; /* 白色文字 */
  332. text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); /* 文字阴影增强可读性 */
  333. }
  334. /* 特殊背景页面的头像边框 */
  335. .light-avatar-border {
  336. border: 2px solid #ffffff !important; /* 白色边框 */
  337. }
  338. /* 内容区域在特殊背景页面透明 */
  339. .transparent-scroll {
  340. background-color: transparent !important;
  341. }
  342. /* Header 样式 */
  343. .layout-header {
  344. height: 80px;
  345. display: flex;
  346. align-items: center;
  347. justify-content: space-between;
  348. color: #333; /* 深色文字 */
  349. flex-shrink: 0;
  350. /* 确保在背景层上方 */
  351. position: relative;
  352. /* 修改点:增大 z-index 确保在背景层之上 */
  353. z-index: 10; /* 增大 z-index */
  354. background-color: white; /* 默认背景色 */
  355. }
  356. /* 修改Header布局样式 */
  357. .logo-title-row {
  358. display: flex;
  359. align-items: center;
  360. justify-content: space-between; /* 左右两侧分布 */
  361. width: 100%;
  362. gap: 24px;
  363. }
  364. .title-and-user {
  365. display: flex;
  366. flex-direction: row;
  367. flex: 1;
  368. }
  369. /* 用户信息区域样式调整 */
  370. .user-info-row {
  371. display: flex;
  372. align-items: center;
  373. gap: 16px;
  374. color: #333;
  375. }
  376. .welcome-text {
  377. font-size: 28px;
  378. font-weight: 500;
  379. color: #ffffff;
  380. white-space: nowrap; /* 防止文字换行 */
  381. }
  382. /* Tab 区域 - 不透明 */
  383. .tabs-row {
  384. height: 48px;
  385. display: flex;
  386. justify-content: center;
  387. align-items: center;
  388. padding: 0 24px;
  389. background: linear-gradient(to right, #1092d8, #02c3ad);
  390. border-bottom: none !important;
  391. flex-shrink: 0;
  392. /* 确保在背景层上方 */
  393. position: relative;
  394. /* 修改点:增大 z-index 确保在背景层之上 */
  395. z-index: 10; /* 增大 z-index */
  396. }
  397. /* el-tabs 外层容器 */
  398. .demo-tabs {
  399. height: 48px !important;
  400. display: flex;
  401. align-items: center;
  402. width: 100%;
  403. padding: 0 !important;
  404. margin: 0 !important;
  405. border-bottom: none !important;
  406. }
  407. /* 清除滑块条和底部线条 */
  408. .el-tabs__nav-wrap::after,
  409. .el-tabs__active-bar {
  410. display: none !important;
  411. height: 0 !important;
  412. border: none !important;
  413. }
  414. .el-tabs__nav-scroll {
  415. padding: 0 !important;
  416. margin: 0 !important;
  417. }
  418. /* Tabs 单项样式 */
  419. .el-tabs__item {
  420. height: 48px !important;
  421. line-height: 48px !important;
  422. display: flex !important;
  423. align-items: center;
  424. justify-content: center;
  425. padding: 0 20px !important;
  426. font-size: 20px;
  427. font-weight: 600;
  428. border-radius: 10px;
  429. transition: all 0.2s ease-in-out;
  430. background-color: transparent;
  431. position: relative;
  432. /* 修改点:增大 z-index 确保在背景层之上 */
  433. z-index: 10; /* 增大 z-index */
  434. }
  435. /* 激活 Tab */
  436. .el-tabs__item.is-active {
  437. background-color: #2a53ba;
  438. color: #ffffff;
  439. font-weight: 700;
  440. box-shadow: 0 4px 16px rgba(26, 188, 156, 0.4);
  441. /* 修改点:增大 z-index 确保在背景层之上 */
  442. z-index: 11; /* 激活项可以更高一点 */
  443. }
  444. /* 鼠标悬停 */
  445. .el-tabs__item:hover {
  446. background-color: #455a64;
  447. color: #ffffff;
  448. /* 修改点:增大 z-index 确保在背景层之上 */
  449. z-index: 11; /* 悬停时也可以更高 */
  450. }
  451. /* 图标样式 */
  452. .tab-icon {
  453. font-size: 24px;
  454. margin-right: 4px;
  455. color: inherit;
  456. }
  457. /* 文字样式 */
  458. .tab-label-text {
  459. font-size: 20px;
  460. color: inherit;
  461. line-height: 1;
  462. display: inline-block;
  463. }
  464. .logo {
  465. height: 60px;
  466. }
  467. .project-name {
  468. font-size: 32px; /* 适当调整字体大小 */
  469. font-weight: bold;
  470. color: #333;
  471. white-space: nowrap; /* 防止标题换行 */
  472. }
  473. /* 响应式设计:在小屏幕上调整布局 */
  474. @media (max-width: 1200px) {
  475. .project-name {
  476. font-size: 20px;
  477. }
  478. .welcome-text {
  479. font-size: 14px;
  480. }
  481. }
  482. @media (max-width: 768px) {
  483. .logo-title-row {
  484. flex-wrap: wrap;
  485. gap: 12px;
  486. }
  487. .left-section {
  488. order: 1;
  489. width: 100%;
  490. justify-content: center;
  491. }
  492. .right-section {
  493. order: 2;
  494. width: 100%;
  495. justify-content: center;
  496. }
  497. .project-name {
  498. font-size: 18px;
  499. text-align: center;
  500. }
  501. }
  502. .layout-main-container {
  503. flex: 1;
  504. display: flex;
  505. overflow: hidden;
  506. min-height: 0;
  507. /* 确保在背景层上方 */
  508. position: relative;
  509. /* 修改点:增大 z-index 确保在背景层之上 */
  510. z-index: 10; /* 增大 z-index */
  511. }
  512. /* 侧边栏 - 白色背景 */
  513. .layout-aside {
  514. width: 280px;
  515. background: linear-gradient(to bottom, #b7f1fc, #fff8f0);
  516. border-right: 1px solid;
  517. overflow-y: auto;
  518. color: #000000;
  519. padding-top: 8px;
  520. height: 100%;
  521. position: relative;
  522. /* 修改点:增大 z-index 确保在背景层之上 */
  523. z-index: 10; /* 增大 z-index */
  524. }
  525. /* 隐藏侧边栏滚动条 */
  526. .layout-aside::-webkit-scrollbar {
  527. display: none;
  528. }
  529. .layout-aside .el-menu-item,
  530. .layout-aside .el-sub-menu__title {
  531. font-size: 18px;
  532. font-weight: 500;
  533. color: #000000;
  534. background-color: transparent;
  535. transition: all 0.2s ease;
  536. border-radius: 6px;
  537. padding: 12px 16px !important;
  538. }
  539. .layout-aside .el-menu-item:hover,
  540. .layout-aside .el-sub-menu__title:hover {
  541. background-color: rgba(16, 146, 216, 0.1);
  542. color: #1092d8;
  543. }
  544. .layout-aside .el-menu-item.is-active,
  545. .layout-aside .el-sub-menu__title.is-active {
  546. background: linear-gradient(to right, #1092d8, #02c3ad);
  547. color: #000000 !important;
  548. border-radius: 8px;
  549. font-weight: 600;
  550. box-shadow: 0 2px 8px rgba(16, 146, 216, 0.25);
  551. /* 修改点:增大 z-index 确保在背景层之上 */
  552. z-index: 11; /* 激活项可以更高一点 */
  553. }
  554. .layout-content-wrapper {
  555. flex: 1;
  556. overflow: hidden;
  557. display: flex;
  558. flex-direction: column;
  559. position: relative;
  560. /* 修改点:增大 z-index 确保在背景层之上 */
  561. z-index: 10; /* 增大 z-index */
  562. }
  563. /* 强制重置 el-tabs header 高度/边距/背景/阴影,避免背景层穿透错位 */
  564. .el-tabs__header.is-top {
  565. height: 48px !important;
  566. margin: 0 !important;
  567. padding: 0 !important;
  568. border: none !important;
  569. background: transparent !important;
  570. box-shadow: none !important;
  571. /* 修改点:增大 z-index 确保在背景层之上 */
  572. z-index: 10 !important; /* 增大 z-index */
  573. }
  574. /* 全屏页面特殊处理 */
  575. .layout-wrapper.full-screen .layout-main-container {
  576. height: 100vh;
  577. }
  578. .scrollable-content {
  579. flex: 1;
  580. overflow: auto;
  581. padding: 0 20px;
  582. box-sizing: border-box;
  583. background-color: white; /* 默认背景色 */
  584. position: relative; /* 确保它可以参与 z-index 计算 */
  585. /* 修改点:增大 z-index 确保在背景层之上 */
  586. z-index: 10; /* 增大 z-index */
  587. }
  588. .scrollable-content.transparent-scroll {
  589. background-color: transparent;
  590. /* 修改点:增大 z-index 确保在背景层之上 */
  591. z-index: 10; /* 即使透明也应保持在上层 */
  592. }
  593. /* 左侧区域 */
  594. .left-section {
  595. display: flex;
  596. align-items: center;
  597. gap: 24px;
  598. flex-shrink: 0; /* 防止缩小 */
  599. }
  600. /* 右侧区域 */
  601. .right-section {
  602. display: flex;
  603. align-items: center;
  604. justify-content: flex-end;
  605. flex-shrink: 0; /* 防止缩小 */
  606. }
  607. </style>