mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-08-06 10:57:26 +08:00
直播功能菜单调整
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,16 +99,17 @@ util.registerDynamicRoutes = function (menuData, options = {}) {
|
||||
});
|
||||
|
||||
leaves.forEach((leaf) => {
|
||||
const path = (leaf.path || leaf.name || "").replace(/^\//, "");
|
||||
if (!router.hasRoute(leaf.name)) {
|
||||
router.addRoute("otherRouter", {
|
||||
path,
|
||||
name: leaf.name,
|
||||
component: leaf.component,
|
||||
meta: leaf.meta,
|
||||
});
|
||||
util.dynamicRouteNames.push(leaf.name);
|
||||
const path = util.normalizeRoutePath(leaf.path || leaf.name);
|
||||
if (router.hasRoute(leaf.name)) {
|
||||
return;
|
||||
}
|
||||
router.addRoute("otherRouter", {
|
||||
path,
|
||||
name: leaf.name,
|
||||
component: leaf.component,
|
||||
meta: leaf.meta,
|
||||
});
|
||||
util.dynamicRouteNames.push(leaf.name);
|
||||
});
|
||||
|
||||
if (!router.hasRoute("error-404")) {
|
||||
@@ -147,41 +172,43 @@ 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) {
|
||||
// 页面已经打开
|
||||
vm.$store.commit("pageOpenedList", {
|
||||
index: i,
|
||||
argu: argu,
|
||||
query: query
|
||||
});
|
||||
tagHasOpened = true;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (!tagHasOpened) {
|
||||
let tag = vm.$store.state.app.tagsList.filter(item => {
|
||||
if (item.children) {
|
||||
return name == item.children[0].name;
|
||||
} else {
|
||||
return name == item.name;
|
||||
}
|
||||
const currentPath = vm.$route ? vm.$route.path : "";
|
||||
const openedIndex = util.findOpenedPageIndex(pageOpenedList, name, currentPath);
|
||||
if (openedIndex >= 0) {
|
||||
vm.$store.commit("pageOpenedList", {
|
||||
index: openedIndex,
|
||||
argu: argu,
|
||||
query: query
|
||||
});
|
||||
tag = tag[0];
|
||||
if (tag) {
|
||||
tag = tag.children ? tag.children[0] : tag;
|
||||
if (argu) {
|
||||
tag.argu = argu;
|
||||
}
|
||||
if (query) {
|
||||
tag.query = query;
|
||||
}
|
||||
vm.$store.commit("increateTag", tag);
|
||||
return;
|
||||
}
|
||||
let tag = vm.$store.state.app.tagsList.filter(item => {
|
||||
if (item.children) {
|
||||
return name == item.children[0].name;
|
||||
} else {
|
||||
return name == item.name;
|
||||
}
|
||||
});
|
||||
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) {
|
||||
tagObj.argu = argu;
|
||||
}
|
||||
if (query) {
|
||||
tagObj.query = query;
|
||||
}
|
||||
vm.$store.commit("increateTag", tagObj);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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: "创建直播",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user