明树Git Lab

Commit 38c3b1f8 authored by zhanghan's avatar zhanghan

解决一个路由的bug

parent 99ce2cfd
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
<!-- 主内容Main --> <!-- 主内容Main -->
<el-main class="city-main"> <el-main class="city-main">
<!-- 路由标签页 --> <template v-if="route?.path && isExcludeRoute(route.path)">
<div class="tabs-view"> <div class="tabs-view" v-if="visitedViews && visitedViews.length > 0">
<el-tabs <el-tabs
v-model="activePath" v-model="activePath"
type="card" type="card"
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
/> />
</el-tabs> </el-tabs>
</div> </div>
</template>
<!-- 路由视图 --> <!-- 路由视图 -->
<div class="view-content"> <div class="view-content">
<router-view /> <router-view />
...@@ -74,6 +75,12 @@ import axios from "axios"; // watch中使用proxy会有warning ...@@ -74,6 +75,12 @@ import axios from "axios"; // watch中使用proxy会有warning
const userStore = useUserStore(); const userStore = useUserStore();
const proxyRef = ref(null); const proxyRef = ref(null);
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
const excludeTabs = ["/homePage"];
// 2. 判断是否包含目标路由的核心方法
const isExcludeRoute = (path) => {
return !excludeTabs.includes(path);
};
// 在 setup 中设置 // 在 setup 中设置
const instance = getCurrentInstance(); const instance = getCurrentInstance();
...@@ -91,19 +98,17 @@ const route = useRoute(); ...@@ -91,19 +98,17 @@ const route = useRoute();
// ========== 路由标签页相关 ========== // ========== 路由标签页相关 ==========
const visitedViews = ref([]); // 已访问的路由列表 const visitedViews = ref([]); // 已访问的路由列表
const activePath = ref(""); // 当前激活的路由路径 const activePath = ref(""); // 当前激活的路由路径
// 添加路由到已访问列表 // 添加路由到已访问列表
const addView = (view) => { const addView = (view) => {
// 检查路由是否已存在 // 检查路由是否已存在
const index = visitedViews.value.findIndex((v) => v.path === view.path); const index = visitedViews.value.findIndex((v) => v.path === view.path);
if (index === -1) { if (index === -1) {
console.log(view, "viewview");
// 不存在则添加,优先使用 title,其次 meta.title,最后 name // 不存在则添加,优先使用 title,其次 meta.title,最后 name
visitedViews.value.push({ visitedViews.value.push({
path: view.path, path: view.path,
title: view.title || view.meta?.title || view.name || "未命名", title: view.title || view.meta?.title || view.name || "未命名",
}); });
console.log(visitedViews, "visitedViewsvisitedViews");
} }
// 设置当前激活的路由 // 设置当前激活的路由
activePath.value = view.path; activePath.value = view.path;
......
...@@ -12,7 +12,7 @@ const routes = [ ...@@ -12,7 +12,7 @@ const routes = [
name: "gzbPage", name: "gzbPage",
title: "数据大屏", title: "数据大屏",
component: () => import("@/views/homePage/index.vue"), component: () => import("@/views/homePage/index.vue"),
meta: { nopermission: true, title: "数据大屏" }, meta: { nopermission: true, title: "数据大屏", hideTabs: false },
}, },
{ {
path: "/", path: "/",
......
...@@ -197,6 +197,9 @@ const handleLogin = async () => { ...@@ -197,6 +197,9 @@ const handleLogin = async () => {
} }
.login-btn { .login-btn {
&:hover {
background-color: #40a9ff;
}
width: 100%; width: 100%;
height: 36px; height: 36px;
border-radius: 4px; border-radius: 4px;
......
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