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$/);
|
const viewContext = require.context("@/views", true, /\.vue$/);
|
||||||
|
|
||||||
/** 后端菜单 frontRoute 与前端实际路径不一致时的映射 */
|
/** 后端菜单 frontRoute 与前端实际路径不一致时的映射 */
|
||||||
const VIEW_ALIASES = {
|
const VIEW_ALIASES = {};
|
||||||
"live/list": "promotions/live/live",
|
|
||||||
};
|
|
||||||
|
|
||||||
function resolveViewPath(url) {
|
function resolveViewPath(url) {
|
||||||
return VIEW_ALIASES[url] || url;
|
return VIEW_ALIASES[url] || url;
|
||||||
|
|||||||
@@ -7,6 +7,30 @@ let util = {};
|
|||||||
/** 动态菜单路由 name,用于登出或重新注册时清理 */
|
/** 动态菜单路由 name,用于登出或重新注册时清理 */
|
||||||
util.dynamicRouteNames = [];
|
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 () {
|
util.clearDynamicRoutes = function () {
|
||||||
const router = getRouter();
|
const router = getRouter();
|
||||||
if (!router) return;
|
if (!router) return;
|
||||||
@@ -75,8 +99,10 @@ util.registerDynamicRoutes = function (menuData, options = {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
leaves.forEach((leaf) => {
|
leaves.forEach((leaf) => {
|
||||||
const path = (leaf.path || leaf.name || "").replace(/^\//, "");
|
const path = util.normalizeRoutePath(leaf.path || leaf.name);
|
||||||
if (!router.hasRoute(leaf.name)) {
|
if (router.hasRoute(leaf.name)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
router.addRoute("otherRouter", {
|
router.addRoute("otherRouter", {
|
||||||
path,
|
path,
|
||||||
name: leaf.name,
|
name: leaf.name,
|
||||||
@@ -84,7 +110,6 @@ util.registerDynamicRoutes = function (menuData, options = {}) {
|
|||||||
meta: leaf.meta,
|
meta: leaf.meta,
|
||||||
});
|
});
|
||||||
util.dynamicRouteNames.push(leaf.name);
|
util.dynamicRouteNames.push(leaf.name);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!router.hasRoute("error-404")) {
|
if (!router.hasRoute("error-404")) {
|
||||||
@@ -147,23 +172,16 @@ util.openNewPage = function(vm, name, argu, query) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let pageOpenedList = vm.$store.state.app.pageOpenedList;
|
let pageOpenedList = vm.$store.state.app.pageOpenedList;
|
||||||
let openedPageLen = pageOpenedList.length;
|
const currentPath = vm.$route ? vm.$route.path : "";
|
||||||
let i = 0;
|
const openedIndex = util.findOpenedPageIndex(pageOpenedList, name, currentPath);
|
||||||
let tagHasOpened = false;
|
if (openedIndex >= 0) {
|
||||||
while (i < openedPageLen) {
|
|
||||||
if (name == pageOpenedList[i].name) {
|
|
||||||
// 页面已经打开
|
|
||||||
vm.$store.commit("pageOpenedList", {
|
vm.$store.commit("pageOpenedList", {
|
||||||
index: i,
|
index: openedIndex,
|
||||||
argu: argu,
|
argu: argu,
|
||||||
query: query
|
query: query
|
||||||
});
|
});
|
||||||
tagHasOpened = true;
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (!tagHasOpened) {
|
|
||||||
let tag = vm.$store.state.app.tagsList.filter(item => {
|
let tag = vm.$store.state.app.tagsList.filter(item => {
|
||||||
if (item.children) {
|
if (item.children) {
|
||||||
return name == item.children[0].name;
|
return name == item.children[0].name;
|
||||||
@@ -172,16 +190,25 @@ util.openNewPage = function(vm, name, argu, query) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
tag = tag[0];
|
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) {
|
if (tag) {
|
||||||
tag = tag.children ? tag.children[0] : tag;
|
tag = tag.children ? tag.children[0] : tag;
|
||||||
|
const tagObj = { ...tag, name: name || tag.name };
|
||||||
if (argu) {
|
if (argu) {
|
||||||
tag.argu = argu;
|
tagObj.argu = argu;
|
||||||
}
|
}
|
||||||
if (query) {
|
if (query) {
|
||||||
tag.query = query;
|
tagObj.query = query;
|
||||||
}
|
|
||||||
vm.$store.commit("increateTag", tag);
|
|
||||||
}
|
}
|
||||||
|
vm.$store.commit("increateTag", tagObj);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -355,12 +355,6 @@ export const otherRouter = {
|
|||||||
name: "add-sms-sign",
|
name: "add-sms-sign",
|
||||||
component: () => import("@/views/sys/message/smsSign.vue")
|
component: () => import("@/views/sys/message/smsSign.vue")
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "live-list",
|
|
||||||
title: "直播管理",
|
|
||||||
name: "live-list",
|
|
||||||
component: () => import("@/views/live/list.vue")
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "live-add",
|
path: "live-add",
|
||||||
title: "创建直播",
|
title: "创建直播",
|
||||||
|
|||||||
@@ -159,7 +159,11 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
checkTag(name) {
|
checkTag(name) {
|
||||||
const openpageHasTag = this.pageTagsList.some((item) => item.name == name);
|
const openpageHasTag = util.findOpenedPageIndex(
|
||||||
|
this.pageTagsList,
|
||||||
|
name,
|
||||||
|
this.$route.path
|
||||||
|
) >= 0;
|
||||||
if (!openpageHasTag) {
|
if (!openpageHasTag) {
|
||||||
util.openNewPage(
|
util.openNewPage(
|
||||||
this,
|
this,
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
</el-menu-item>
|
</el-menu-item>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
<el-menu
|
<el-menu
|
||||||
:key="currNav"
|
:key="`${currNav}-${activeMenuName}`"
|
||||||
class="sub-menu"
|
class="sub-menu"
|
||||||
:default-active="$route.name"
|
:default-active="activeMenuName"
|
||||||
@select="changeMenu"
|
@select="changeMenu"
|
||||||
>
|
>
|
||||||
<template v-for="item in menuList" :key="item.id">
|
<template v-for="item in menuList" :key="item.id">
|
||||||
@@ -45,6 +45,19 @@ export default {
|
|||||||
currNav() {
|
currNav() {
|
||||||
return this.$store.state.app.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: {
|
watch: {
|
||||||
$route(val) {
|
$route(val) {
|
||||||
@@ -63,6 +76,12 @@ export default {
|
|||||||
this.$router.push({ name });
|
this.$router.push({ name });
|
||||||
return;
|
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);
|
util.initRouter(this);
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (this.$router.hasRoute(name)) {
|
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) {
|
selectNav(name) {
|
||||||
this.$store.commit("setCurrNav", name);
|
this.$store.commit("setCurrNav", name);
|
||||||
this.setStore("currNav", name);
|
this.setStore("currNav", name);
|
||||||
|
|||||||
@@ -42,6 +42,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import util from "@/libs/util.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "tagsPageOpened",
|
name: "tagsPageOpened",
|
||||||
props: {
|
props: {
|
||||||
@@ -66,9 +68,11 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
isActive(item) {
|
isActive(item) {
|
||||||
return item.children
|
const target = item.children ? item.children[0] : item;
|
||||||
? item.children[0].name === this.currentPageName
|
return util.isSameRoutePage(target, {
|
||||||
: item.name === this.currentPageName;
|
name: this.currentPageName,
|
||||||
|
path: this.$route.path,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
tagType(item) {
|
tagType(item) {
|
||||||
return this.isActive(item) ? "primary" : "info";
|
return this.isActive(item) ? "primary" : "info";
|
||||||
@@ -104,12 +108,25 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
linkTo(item) {
|
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 };
|
const routerObj = { name: item.name };
|
||||||
if (item.argu) routerObj.params = item.argu;
|
if (item.argu) routerObj.params = item.argu;
|
||||||
if (item.query) routerObj.query = item.query;
|
if (item.query) routerObj.query = item.query;
|
||||||
if (this.beforePush(item)) {
|
|
||||||
|
if (item.name && this.$router.hasRoute(item.name)) {
|
||||||
this.$router.push(routerObj);
|
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) {
|
handlescroll(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user