From e2660fdb13b6b7ee2226e2d818d40e01b4e8d313 Mon Sep 17 00:00:00 2001 From: iczer <1126263215@qq.com> Date: Sun, 18 Oct 2020 19:27:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20function=20of=20link=20for=20out?= =?UTF-8?q?=20website=20in=20menu;=20:star:=20#135=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=EF=BC=9A=E8=8F=9C=E5=8D=95=E5=A2=9E=E5=8A=A0=E5=A4=96=E9=93=BE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/menu/menu.js | 8 ++++++- src/utils/routerUtil.js | 42 +++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/components/menu/menu.js b/src/components/menu/menu.js index 315d0c3..e560e97 100644 --- a/src/components/menu/menu.js +++ b/src/components/menu/menu.js @@ -131,10 +131,16 @@ export default { return !icon || icon == 'none' ? null : h(Icon, {props: {type: icon}}) }, renderMenuItem: function (h, menu) { + let tag = 'router-link' + let config = {props: {to: menu.fullPath}, attrs: {style: 'overflow:hidden;white-space:normal;text-overflow:clip;'}} + if (menu.meta && menu.meta.link) { + tag = 'a' + config = {attrs: {style: 'overflow:hidden;white-space:normal;text-overflow:clip;', href: menu.meta.link, target: '_blank'}} + } return h( Item, {key: menu.fullPath}, [ - h('router-link', {props: {to: menu.fullPath}, attrs: {style: 'overflow:hidden;white-space:normal;text-overflow:clip;'}}, + h(tag, config, [ this.renderIcon(h, menu.meta ? menu.meta.icon : 'none', menu.fullPath), this.$t(getI18nKey(menu.fullPath)) diff --git a/src/utils/routerUtil.js b/src/utils/routerUtil.js index 8cd719a..5886958 100644 --- a/src/utils/routerUtil.js +++ b/src/utils/routerUtil.js @@ -39,29 +39,30 @@ function parseRoutes(routesConfig, routerMap) { router = routerMap[item.router] routeCfg = item } - // 从 router 和 routeCfg 解析路由 if (!router) { console.warn(`can't find register for router ${routeCfg.router}, please register it in advance.`) - } else { - const route = { - path: routeCfg.path || router.path || routeCfg.router, - name: routeCfg.name || router.name, - component: router.component, - redirect: routeCfg.redirect || router.redirect, - meta: { - authority: routeCfg.authority || router.authority || '*', - icon: routeCfg.icon || router.icon, - page: routeCfg.page || router.page - } - } - if (routeCfg.invisible || router.invisible) { - route.meta.invisible = true - } - if (routeCfg.children && routeCfg.children.length > 0) { - route.children = parseRoutes(routeCfg.children, routerMap) - } - routes.push(route) + router = typeof item === 'string' ? {path: item, name: item} : item } + // 从 router 和 routeCfg 解析路由 + const route = { + path: routeCfg.path || router.path || routeCfg.router, + name: routeCfg.name || router.name, + component: router.component, + redirect: routeCfg.redirect || router.redirect, + meta: { + authority: routeCfg.authority || router.authority || '*', + icon: routeCfg.icon || router.icon, + page: routeCfg.page || router.page, + link: routeCfg.link || router.link + } + } + if (routeCfg.invisible || router.invisible) { + route.meta.invisible = true + } + if (routeCfg.children && routeCfg.children.length > 0) { + route.children = parseRoutes(routeCfg.children, routerMap) + } + routes.push(route) }) return routes } @@ -71,6 +72,7 @@ function parseRoutes(routesConfig, routerMap) { * @param routesConfig {RouteConfig[]} 路由配置 */ function loadRoutes(routesConfig) { + console.log('hahah') //兼容 0.6.1 以下版本 /*************** 兼容 version < v0.6.1 *****************/ if (arguments.length > 0) {