From 51636e9cd814bddba7a9b4ff21b5bc94e95fb6cb Mon Sep 17 00:00:00 2001 From: wangting <675591594@qq.com> Date: 星期二, 14 五月 2024 09:21:36 +0800 Subject: [PATCH] 配置文档 --- Source/ProjectWeb/src/router/avue-router.js | 70 ++++++++++++++++++++++++----------- 1 files changed, 48 insertions(+), 22 deletions(-) diff --git a/Source/ProjectWeb/src/router/avue-router.js b/Source/ProjectWeb/src/router/avue-router.js index 1f5f0a7..52c14c9 100644 --- a/Source/ProjectWeb/src/router/avue-router.js +++ b/Source/ProjectWeb/src/router/avue-router.js @@ -1,3 +1,5 @@ +import {validatenull} from "@/util/validate"; + let RouterPlugin = function () { this.$router = null; this.$store = null; @@ -6,7 +8,7 @@ RouterPlugin.install = function (vue, option = {}) { this.$router = option.router; this.$store = option.store; - this.$vue = new vue({ i18n: option.i18n }); + this.$vue = new vue({i18n: option.i18n}); // 杩欎釜鐨勪綔鐢ㄦ槸 涓轰簡妫�鏌ュ嚭缃戦〉閾炬帴锛屽洜涓烘湰椤圭洰鐢ㄥ埌浜� iframe function isURL(s) { @@ -85,19 +87,20 @@ }, //鍔ㄦ�佽矾鐢� // 璺敱鏄笓闂ㄧ殑涓�涓帴鍙h幏鍙� - /** - * aMenu: 鎺ュ彈鍒扮殑鍔ㄦ�佽矾鐢辨暟鎹� menu鐨勭粨鏋勫灞傛湁鐖剁骇path 閲岄潰鏈変竴涓猚hilden 璁板綍椤甸潰鐨勮矾鐢� - * first: 涓轰簡鍖哄垎澶栫晫 璋冪敤formatRoutes 鍜� 褰撳墠鏂囦欢璋冪敤 formatRoutes - */ + /** + * aMenu: 鎺ュ彈鍒扮殑鍔ㄦ�佽矾鐢辨暟鎹� menu鐨勭粨鏋勫灞傛湁鐖剁骇path 閲岄潰鏈変竴涓猚hilden 璁板綍椤甸潰鐨勮矾鐢� + * first: 涓轰簡鍖哄垎澶栫晫 璋冪敤formatRoutes 鍜� 褰撳墠鏂囦欢璋冪敤 formatRoutes + */ formatRoutes: function (aMenu = [], first) { - debugger; const aRouter = [] // 鑾峰彇鍒板叏灞�閰嶇疆涓殑 props const propsConfig = this.$website.menu.props; // 璁剧疆 props榛樿鍊� 浣滅敤灏辨槸灏嗗瓧娈佃缃垚閰嶇疆鐨� const propsDefault = { label: propsConfig.label || 'name', - path: propsConfig.path || 'path', + path: 'code', + code: 'code', + pathValue: 'pathValue', icon: propsConfig.icon || 'icon', children: propsConfig.children || 'children', meta: propsConfig.meta || 'meta', @@ -110,21 +113,44 @@ const oMenu = aMenu[i]; // 杩欎竴鍧楃殑璧嬪�� 涔熷氨鏄彇鍒拌繑鍥炵殑鍊� let path = (() => { - if (first) { - // 灏� '/index' 鏇挎崲涓� '' - return oMenu[propsDefault.path].replace('/index', '') - } else { - return oMenu[propsDefault.path] - } - })(), - //鐗规畩澶勭悊缁勪欢 鎵ц瀹岃繖涓� component 涔熷氨鏄簿纭埌鍏蜂綋鐨勬枃浠朵簡 views鏂囦欢澶逛笅闈㈠氨鏄叿浣撶殑椤甸潰浠g爜 - //component = 'views' + oMenu.path, - component = oMenu.path, - name = oMenu[propsDefault.label], + if (first) { + // 灏� '/index' 鏇挎崲涓� '' + return oMenu[propsDefault.pathValue].replace('/index', '') + } else { + return oMenu[propsDefault.pathValue] + } + })(); + let code = (() => { + return oMenu[propsDefault.code] + })(); + + let component = ''; + let parts = ''; + + // 濡傛灉璺緞涓瓨鍦� '?'锛屽垯鍙栭棶鍙峰墠闈㈤儴鍒嗙粰 parts + if (path.includes('?')) { + parts = path.split("?")[0]; + } else { + parts = path; // 涓嶅瓨鍦� '?' 鏁存潯璺緞灏辨槸 parts + } + if(validatenull(parts)){ + parts='UI'; + } + // 濡傛灉闂彿鍓嶉潰閮ㄥ垎涓嶅湪 ['ui', 'UI', 'base'] 涓紝鍒欐槸鑷畾涔夌粍浠� + if (!['ui', 'UI', 'base','bs'].includes(parts) && parts.indexOf('views/')==-1) { + component = `views/custom-ui/${parts}`; + }else if (['UI', 'ui', 'base','bs'].includes(parts)) { + // 濡傛灉闂彿鍓嶉潰绛変簬 UI銆乽i 鍒欎负UI寮曟搸 + component = 'views/base/UIContentViewer'; + }else{ + component = `${parts}`; + } + + let name = oMenu[propsDefault.label], icon = oMenu[propsDefault.icon], children = oMenu[propsDefault.children], meta = oMenu[propsDefault.meta] || {}; - // meta涓� keepalive 鐨勫鐞� + // meta涓� keepalive 鐨勫鐞� meta = Object.assign(meta, (function () { if (option.keepAlive === true) { return { @@ -135,7 +161,7 @@ //鏄惁鏈夊瓙璺敱 const isChild = children.length !== 0; const oRouter = { - path: path, + path: '/' + code, component(resolve) { // 鍒ゆ柇鏄惁涓洪璺敱 if (first) { @@ -163,7 +189,7 @@ children: !isChild ? (() => { if (first) { // 杩欓噷鐨刬sURL鍒ゆ柇锛屽洜涓鸿繖涓綉绔欐湁浣跨敤 iframe銆傛墍浠ラ渶瑕佸垽鏂槸鍚︿负缃戦〉閾炬帴 - if (!isURL(path)) oMenu[propsDefault.path] = `${path}/index`; + if (!isURL(path)) oMenu[propsDefault.pathValue] = `${path}/index`; return [{ component(resolve) { require([`../${component}.vue`], resolve) @@ -179,7 +205,7 @@ /** * 杩欓噷鏄噸鐐癸紝褰撴湁瀛愯矾鐢辩殑鏃跺�� 浼氬啀鍘绘墽琛� formatRoutes 鏂规硶锛岀劧鍚庡張浼氭湁涓�涓柊鐨� aMenu for寰幆銆� * 鏈�鍚庤繑鍥炵殑鏄竴涓暟缁� aRouter 杩欎釜鏁扮粍灏变細浣滀负 childen鐨勫�艰 return - */ + */ return this.formatRoutes(children, false) })() } -- Gitblit v1.9.3