直播功能菜单调整

This commit is contained in:
chc
2026-07-06 14:48:40 +08:00
parent 2e5be29a43
commit fc5fb3832d
6 changed files with 128 additions and 59 deletions

View File

@@ -1,9 +1,7 @@
const viewContext = require.context("@/views", true, /\.vue$/);
/** 后端菜单 frontRoute 与前端实际路径不一致时的映射 */
const VIEW_ALIASES = {
"live/list": "promotions/live/live",
};
const VIEW_ALIASES = {};
function resolveViewPath(url) {
return VIEW_ALIASES[url] || url;

View File

@@ -7,6 +7,30 @@ let util = {};
/** 动态菜单路由 name用于登出或重新注册时清理 */
util.dynamicRouteNames = [];
util.normalizeRoutePath = function (path) {
return String(path || "")
.replace(/^\/+/, "")
.replace(/\/+$/, "");
};
util.isSameRoutePage = function (a, b) {
if (!a || !b) return false;
if (a.name && b.name && a.name === b.name) return true;
const pathA = util.normalizeRoutePath(a.path);
const pathB = util.normalizeRoutePath(b.path);
return !!(pathA && pathB && pathA === pathB);
};
util.findOpenedPageIndex = function (pageOpenedList, name, path) {
const normalizedPath = util.normalizeRoutePath(path);
return pageOpenedList.findIndex(
(item) =>
item.name === name ||
(normalizedPath &&
util.normalizeRoutePath(item.path) === normalizedPath)
);
};
util.clearDynamicRoutes = function () {
const router = getRouter();
if (!router) return;
@@ -75,8 +99,10 @@ util.registerDynamicRoutes = function (menuData, options = {}) {
});
leaves.forEach((leaf) => {
const path = (leaf.path || leaf.name || "").replace(/^\//, "");
if (!router.hasRoute(leaf.name)) {
const path = util.normalizeRoutePath(leaf.path || leaf.name);
if (router.hasRoute(leaf.name)) {
return;
}
router.addRoute("otherRouter", {
path,
name: leaf.name,
@@ -84,7 +110,6 @@ util.registerDynamicRoutes = function (menuData, options = {}) {
meta: leaf.meta,
});
util.dynamicRouteNames.push(leaf.name);
}
});
if (!router.hasRoute("error-404")) {
@@ -147,23 +172,16 @@ util.openNewPage = function(vm, name, argu, query) {
return;
}
let pageOpenedList = vm.$store.state.app.pageOpenedList;
let openedPageLen = pageOpenedList.length;
let i = 0;
let tagHasOpened = false;
while (i < openedPageLen) {
if (name == pageOpenedList[i].name) {
// 页面已经打开
const currentPath = vm.$route ? vm.$route.path : "";
const openedIndex = util.findOpenedPageIndex(pageOpenedList, name, currentPath);
if (openedIndex >= 0) {
vm.$store.commit("pageOpenedList", {
index: i,
index: openedIndex,
argu: argu,
query: query
});
tagHasOpened = true;
break;
return;
}
i++;
}
if (!tagHasOpened) {
let tag = vm.$store.state.app.tagsList.filter(item => {
if (item.children) {
return name == item.children[0].name;
@@ -172,16 +190,25 @@ util.openNewPage = function(vm, name, argu, query) {
}
});
tag = tag[0];
if (!tag) {
tag = vm.$store.state.app.tagsList.find((item) => {
const candidate = item.children ? item.children[0] : item;
return util.isSameRoutePage(candidate, { name, path: currentPath });
});
if (tag && tag.children) {
tag = tag.children[0];
}
}
if (tag) {
tag = tag.children ? tag.children[0] : tag;
const tagObj = { ...tag, name: name || tag.name };
if (argu) {
tag.argu = argu;
tagObj.argu = argu;
}
if (query) {
tag.query = query;
}
vm.$store.commit("increateTag", tag);
tagObj.query = query;
}
vm.$store.commit("increateTag", tagObj);
}
};

View File

@@ -355,12 +355,6 @@ export const otherRouter = {
name: "add-sms-sign",
component: () => import("@/views/sys/message/smsSign.vue")
},
{
path: "live-list",
title: "直播管理",
name: "live-list",
component: () => import("@/views/live/list.vue")
},
{
path: "live-add",
title: "创建直播",

View File

@@ -159,7 +159,11 @@ export default {
}
},
checkTag(name) {
const openpageHasTag = this.pageTagsList.some((item) => item.name == name);
const openpageHasTag = util.findOpenedPageIndex(
this.pageTagsList,
name,
this.$route.path
) >= 0;
if (!openpageHasTag) {
util.openNewPage(
this,

View File

@@ -10,9 +10,9 @@
</el-menu-item>
</el-menu>
<el-menu
:key="currNav"
:key="`${currNav}-${activeMenuName}`"
class="sub-menu"
:default-active="$route.name"
:default-active="activeMenuName"
@select="changeMenu"
>
<template v-for="item in menuList" :key="item.id">
@@ -45,6 +45,19 @@ export default {
currNav() {
return this.$store.state.app.currNav;
},
activeMenuName() {
const route = this.$route;
const routePath = util.normalizeRoutePath(route.path);
for (const item of this.menuList) {
for (const menu of item.children || []) {
const menuPath = util.normalizeRoutePath(menu.path);
if (menu.name === route.name || (menuPath && menuPath === routePath)) {
return menu.name;
}
}
}
return route.name;
},
},
watch: {
$route(val) {
@@ -63,6 +76,12 @@ export default {
this.$router.push({ name });
return;
}
const menu = this.findMenuByName(name);
if (menu?.path) {
const path = menu.path.startsWith("/") ? menu.path : `/${menu.path}`;
this.$router.push({ path });
return;
}
util.initRouter(this);
this.$nextTick(() => {
if (this.$router.hasRoute(name)) {
@@ -72,6 +91,16 @@ export default {
}
});
},
findMenuByName(name) {
for (const item of this.menuList) {
for (const menu of item.children || []) {
if (menu.name === name) {
return menu;
}
}
}
return null;
},
selectNav(name) {
this.$store.commit("setCurrNav", name);
this.setStore("currNav", name);

View File

@@ -42,6 +42,8 @@
</template>
<script>
import util from "@/libs/util.js";
export default {
name: "tagsPageOpened",
props: {
@@ -66,9 +68,11 @@ export default {
},
methods: {
isActive(item) {
return item.children
? item.children[0].name === this.currentPageName
: item.name === this.currentPageName;
const target = item.children ? item.children[0] : item;
return util.isSameRoutePage(target, {
name: this.currentPageName,
path: this.$route.path,
});
},
tagType(item) {
return this.isActive(item) ? "primary" : "info";
@@ -104,12 +108,25 @@ export default {
}
},
linkTo(item) {
if (this.$route.name === item.name) return;
const target = item.children ? item.children[0] : item;
if (util.isSameRoutePage(target, this.$route)) return;
if (!this.beforePush(item)) return;
const routerObj = { name: item.name };
if (item.argu) routerObj.params = item.argu;
if (item.query) routerObj.query = item.query;
if (this.beforePush(item)) {
if (item.name && this.$router.hasRoute(item.name)) {
this.$router.push(routerObj);
return;
}
const path = target.path || item.path;
if (path) {
this.$router.push({
path: path.startsWith("/") ? path : `/${path}`,
query: item.query,
});
}
},
handlescroll(e) {