From 5552639fd1bc592c3a64de374bbfa2eaa90d9bca Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Mon, 13 Aug 2018 00:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=B7=B3=E8=BD=AC=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E9=93=BE=E6=8E=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: f3efcfeef6aa80e71d58a283c7a012daf7e9b8f3 [formerly f3efcfeef6aa80e71d58a283c7a012daf7e9b8f3 [formerly f3efcfeef6aa80e71d58a283c7a012daf7e9b8f3 [formerly f3efcfeef6aa80e71d58a283c7a012daf7e9b8f3 [formerly 1992b24b60b05040dc05d5560346e588d67e6177 [formerly e739f55c37f694cb22cde32fee3d66745ef80906]]]]] Former-commit-id: 5a431444072fcd4a43866a458173da85d7380a6c Former-commit-id: 51c7bc03498d69ffe207436c0a470e2fd41407a0 Former-commit-id: 6fe58189034659f8c767ddb97fd3d6397f24d7bf [formerly 0b495976f82bf0633b3ded3e28dd1568c14be1ca] Former-commit-id: e6ddea0e2a683272a5a757271442ab62fdfeb5ce Former-commit-id: 07d0fad901b750296655a22fbe2fa29893d33f7c Former-commit-id: 9f718c52da8302b33f3d0c0c80628e6a6a92c4df Former-commit-id: 7b5db07e1542a42a3d0d3af1bca0606db47b5dbb Former-commit-id: 204199da27a137c4d4edde0fc88680810743e771 --- src/layout/header-aside/components/mixin/menu.js | 4 ++++ src/libs/util.js | 14 ++++++++++++++ src/main.js | 4 ++-- src/menu/index.js | 12 ++++++++++++ src/plugin/open/index.js | 8 -------- 5 files changed, 32 insertions(+), 10 deletions(-) delete mode 100644 src/plugin/open/index.js diff --git a/src/layout/header-aside/components/mixin/menu.js b/src/layout/header-aside/components/mixin/menu.js index 3cf2c84d..78316f3a 100644 --- a/src/layout/header-aside/components/mixin/menu.js +++ b/src/layout/header-aside/components/mixin/menu.js @@ -1,8 +1,12 @@ +import util from '@/libs/util.js' + export default { methods: { handleMenuSelect (index, indexPath) { if (/^d2-menu-empty-\d+$/.test(index)) { this.$message.warning('临时菜单') + } else if (/^https:\/\/|http:\/\//.test(index)) { + util.open(index) } else { this.$router.push({ path: index diff --git a/src/libs/util.js b/src/libs/util.js index 4fc81800..6d36dc1b 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -17,6 +17,20 @@ util.title = function (titleText) { window.document.title = `${process.env.VUE_APP_TITLE}${titleText ? ` | ${titleText}` : ''}` } +/** + * @description 打开新页面 + * @param {String} url 地址 + */ +util.open = function (url) { + var a = document.createElement('a') + a.setAttribute('href', url) + a.setAttribute('target', '_blank') + a.setAttribute('id', 'd2admin-menu-link') + document.body.appendChild(a) + a.click() + document.body.removeChild(document.getElementById('d2admin-menu-link')) +} + /** * @description 判断是否在其内 * @param {*} ele element diff --git a/src/main.js b/src/main.js index df4e164c..f7f09724 100644 --- a/src/main.js +++ b/src/main.js @@ -20,7 +20,6 @@ import pluginLog from '@/plugin/log' import pluginError from '@/plugin/error' import pluginImport from '@/plugin/import' import pluginExport from '@/plugin/export' -import pluginOpen from '@/plugin/open' // 菜单和路由设置 import router from './router' @@ -34,7 +33,6 @@ Vue.use(pluginLog) Vue.use(pluginError) Vue.use(pluginImport) Vue.use(pluginExport) -Vue.use(pluginOpen) Vue.use(vueJsonTreeView) Vue.config.productionTip = false @@ -42,6 +40,8 @@ Vue.config.productionTip = false Vue.prototype.$env = process.env.NODE_ENV Vue.prototype.$baseUrl = process.env.BASE_URL +Vue.prototype.$open = util.open + new Vue({ router, store, diff --git a/src/menu/index.js b/src/menu/index.js index 75ae0482..b21b7ef2 100644 --- a/src/menu/index.js +++ b/src/menu/index.js @@ -37,6 +37,18 @@ export const menuHeader = [ demoCharts, demoPlugins, demoPlayground, + { + title: '跳转外部链接', + icon: 'link', + children: [ + { path: 'https://github.com/d2-projects/d2-admin', title: 'D2Admin Github', icon: 'github' }, + { path: 'https://juejin.im/user/57a48b632e958a006691b946/posts', title: '掘金', icon: 'globe' }, + { path: 'https://my.oschina.net/u/3871516', title: '开源中国', icon: 'globe' }, + { path: 'https://www.zhihu.com/people/fairy-ever/activities', title: '知乎', icon: 'globe' }, + { path: 'https://segmentfault.com/blog/liyang-note-book', title: 'segmentfault 专栏', icon: 'globe' }, + { path: 'http://www.fairyever.com/', title: 'www.fairyever.com', icon: 'globe' } + ] + }, { title: '空菜单演示', icon: 'folder-o', diff --git a/src/plugin/open/index.js b/src/plugin/open/index.js deleted file mode 100644 index c5b6a96b..00000000 --- a/src/plugin/open/index.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - install (Vue, options) { - // 打开一个url - Vue.prototype.$open = (url = 'https://github.com/d2-projects') => { - window.open(url) - } - } -}