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