明树Git Lab

Commit f89eef28 authored by zhanghan's avatar zhanghan

1

parent 6c6712a9
Pipeline #108703 passed with stage
in 20 seconds
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
<img src="@/assets/images/logo.png" alt="" /> <img src="@/assets/images/logo.png" alt="" />
<div class="Split"></div> <div class="Split"></div>
<div class="header_subtitle">投资决策分析系统</div> <div class="header_subtitle">投资决策分析系统</div>
<!-- <span class="city-name">123123</span> -->
</div> </div>
<div class="header-right"> <div class="header-right">
<div class="message-wrap" @click="toMessagePage"> <div class="message-wrap" @click="toMessagePage">
...@@ -22,8 +21,8 @@ ...@@ -22,8 +21,8 @@
</div> </div>
<div class="Split"></div> <div class="Split"></div>
<span class="avatar"> <span class="avatar">
<el-icon size="20"><Avatar /></el-icon <el-icon size="20"><Avatar /></el-icon>
></span> </span>
<el-dropdown @visible-change="changeVisible"> <el-dropdown @visible-change="changeVisible">
<span class="username"> <span class="username">
{{ userInfo.name }} {{ userInfo.name }}
...@@ -85,7 +84,9 @@ import { useRouter, useRoute } from "vue-router"; ...@@ -85,7 +84,9 @@ import { useRouter, useRoute } from "vue-router";
import { useUserStore } from "@/stores/user.js"; import { useUserStore } from "@/stores/user.js";
import windowConfig from "@/window"; import windowConfig from "@/window";
import LeftMenu from "./leftMenu.vue"; import LeftMenu from "./leftMenu.vue";
import axios from "axios"; // watch中使用proxy会有warning import axios from "axios";
import { Bell, Avatar, ArrowUp, ArrowDown } from "@element-plus/icons-vue"; // 补充导入图标
const userStore = useUserStore(); const userStore = useUserStore();
const proxyRef = ref(null); const proxyRef = ref(null);
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
...@@ -95,7 +96,8 @@ const isIcon = ref(false); ...@@ -95,7 +96,8 @@ const isIcon = ref(false);
const changeVisible = (bool) => { const changeVisible = (bool) => {
isIcon.value = Boolean(bool); isIcon.value = Boolean(bool);
}; };
// 2. 判断是否包含目标路由的核心方法
// 判断是否包含目标路由的核心方法
const isExcludeRoute = (path) => { const isExcludeRoute = (path) => {
return !excludeTabs.includes(path); return !excludeTabs.includes(path);
}; };
...@@ -105,11 +107,13 @@ const instance = getCurrentInstance(); ...@@ -105,11 +107,13 @@ const instance = getCurrentInstance();
if (instance) { if (instance) {
proxyRef.value = instance.proxy; proxyRef.value = instance.proxy;
} }
let userInfo = ref( let userInfo = ref(
sessionStorage.getItem("userInfo") sessionStorage.getItem("userInfo")
? JSON.parse(sessionStorage.getItem("userInfo")) ? JSON.parse(sessionStorage.getItem("userInfo"))
: [], : {}, // 修改为空对象更合理,用户信息不是数组
); );
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
...@@ -168,28 +172,42 @@ const handleTabClick = (tab) => { ...@@ -168,28 +172,42 @@ const handleTabClick = (tab) => {
} }
}; };
// 关闭标签(逻辑调整:删除同路径的所有记录) // 修复后的关闭标签方法
const handleTabRemove = (targetFullPath) => { const handleTabRemove = (targetFullPath) => {
const targetView = visitedViews.value.find( // 1. 找到要删除的标签索引
const index = visitedViews.value.findIndex(
(v) => v.fullPath === targetFullPath, (v) => v.fullPath === targetFullPath,
); );
if (!targetView) return;
// 根据基础路径删除(确保同路径的标签只删一次) // 如果没找到,直接返回
const index = visitedViews.value.findIndex((v) => v.path === targetView.path); if (index === -1) return;
if (index !== -1) {
// 跳转逻辑保持不变 // 2. 获取要删除的视图
const targetView = visitedViews.value[index];
// 3. 删除该标签
visitedViews.value.splice(index, 1);
// 4. 如果删除的是当前激活的标签,需要跳转到其他标签
if (targetFullPath === route.fullPath) { if (targetFullPath === route.fullPath) {
if (visitedViews.value.length > 0) { // 优先跳转到下一个标签,如果没有则跳转到上一个
const nextView = const nextIndex = index < visitedViews.value.length ? index : index - 1;
visitedViews.value[index] || visitedViews.value[index - 1];
if (nextView) { if (nextIndex >= 0 && visitedViews.value[nextIndex]) {
router.push(nextView.fullPath); // 跳转到下一个/上一个标签
} router.push(visitedViews.value[nextIndex].fullPath);
} else { } else {
// 如果没有剩余标签,跳转到首页
router.push("/"); router.push("/");
} }
} }
// 5. 更新激活的标签路径
if (visitedViews.value.length > 0) {
activePath.value =
visitedViews.value[visitedViews.value.length - 1].fullPath;
} else {
activePath.value = "";
} }
}; };
// ========== 路由标签页相关结束 ========== // ========== 路由标签页相关结束 ==========
...@@ -200,45 +218,66 @@ const getResourceData = () => { ...@@ -200,45 +218,66 @@ const getResourceData = () => {
.post(windowConfig.baseUrl + "/api/resource/listResourceAll", {}) .post(windowConfig.baseUrl + "/api/resource/listResourceAll", {})
.then((res) => { .then((res) => {
sessionStorage.setItem("resourceData", JSON.stringify(res.data)); sessionStorage.setItem("resourceData", JSON.stringify(res.data));
}); })
.catch((err) => console.error("获取资源库数据失败:", err)); // 增加错误处理
}; };
// 获取未读消息数量 // 获取未读消息数量
let messageCount = ref(0); let messageCount = ref(0);
const getMessageCount = () => { const getMessageCount = () => {
axios axios
.post(windowConfig.baseUrl + "/api/message/getMesCount", {}) .post(windowConfig.baseUrl + "/api/message/getMesCount", {})
.then((res) => { .then((res) => {
messageCount.value = res.data.count; messageCount.value = res.data.count || 0; // 增加默认值
}); })
.catch((err) => console.error("获取消息数量失败:", err)); // 增加错误处理
}; };
// 跳转消息列表页 // 跳转消息列表页
const toMessagePage = () => { const toMessagePage = () => {
router.push("/message"); router.push("/message");
}; };
onMounted(() => { onMounted(() => {
getResourceData(); getResourceData();
getMessageCount(); getMessageCount();
addView(route); // 初始化时添加当前路由 addView(route); // 初始化时添加当前路由
}); });
// 优化watch:监听完整的route变化,而不只是path
watch( watch(
() => route.path, () => route,
() => { (newRoute) => {
getMessageCount(); getMessageCount();
addView(route); // 路由变化时添加到标签页 addView(newRoute); // 路由变化时添加到标签页
}, },
{ immediate: false, deep: true }, // 深度监听路由对象
); );
// 处理退出登录 // 处理退出登录
const handleLogout = () => { const handleLogout = () => {
// 清除登录状态 // 优先使用axios,避免依赖proxy
proxy.$post({ axios
url: "/api/user/logout", .post(windowConfig.baseUrl + "/api/user/logout", {})
data: {}, .then(() => {
callback: (data) => {
userStore.clearUserInfo(); userStore.clearUserInfo();
sessionStorage.removeItem("userInfo"); // 清除本地存储
router.replace("/login"); router.replace("/login");
}, })
}); .catch((err) => console.error("退出登录失败:", err));
// // 如果需要保留proxy方式,使用下面的代码
// if (proxy) {
// proxy.$post({
// url: "/api/user/logout",
// data: {},
// callback: (data) => {
// userStore.clearUserInfo();
// sessionStorage.removeItem("userInfo");
// router.replace("/login");
// },
// });
// }
}; };
</script> </script>
...@@ -282,7 +321,6 @@ const handleLogout = () => { ...@@ -282,7 +321,6 @@ const handleLogout = () => {
/* 子菜单被激活时,父菜单也高亮 */ /* 子菜单被激活时,父菜单也高亮 */
:deep(.el-sub-menu.is-active > .el-sub-menu__title) { :deep(.el-sub-menu.is-active > .el-sub-menu__title) {
color: #0084ff !important; color: #0084ff !important;
// background-color: #b3d7ff !important;
} }
/* 完全去掉系统管理子菜单的背景色 */ /* 完全去掉系统管理子菜单的背景色 */
...@@ -306,7 +344,6 @@ const handleLogout = () => { ...@@ -306,7 +344,6 @@ const handleLogout = () => {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 0 24px; padding: 0 24px;
.Split { .Split {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment