Quellcode durchsuchen

avue-router update

smallwei vor 6 Jahren
Ursprung
Commit
29b99b8147
3 geänderte Dateien mit 27 neuen und 29 gelöschten Zeilen
  1. 10 5
      src/router/avue-router.js
  2. 12 11
      src/store/modules/user.js
  3. 5 13
      src/views/admin/menu/index.vue

+ 10 - 5
src/router/avue-router.js

@@ -5,7 +5,9 @@ const RouterPlugin = function() {
 RouterPlugin.install = function(router, store) {
   this.$router = router
   this.$store = store
-
+  function isURL(s) {
+    return /^http[s]?:\/\/.*/.test(s)
+  }
   function objToform(obj) {
     const result = []
     Object.keys(obj).forEach(ele => {
@@ -74,14 +76,17 @@ RouterPlugin.install = function(router, store) {
         const oMenu = aMenu[i]
         if (this.routerList.includes(oMenu[propsDefault.path])) return
         const path = (() => {
-          if (first) {
+          if (!oMenu[propsDefault.path]) {
+            return
+          } else if (first) {
             return oMenu[propsDefault.path].replace('/index', '')
           } else {
             return oMenu[propsDefault.path]
           }
         })()
 
-        const component = oMenu.component
+        //特殊处理组件
+        const component = 'views' + oMenu.path
 
         const name = oMenu[propsDefault.label]
 
@@ -113,13 +118,13 @@ RouterPlugin.install = function(router, store) {
           icon: icon,
           meta: meta,
           redirect: (() => {
-            if (!isChild && first) return `${path}/index`
+            if (!isChild && first && !isURL(path)) return `${path}/index`
             else return ''
           })(),
           // 处理是否为一级路由
           children: !isChild ? (() => {
             if (first) {
-              oMenu[propsDefault.path] = `${path}/index`
+              if (!isURL(path)) oMenu[propsDefault.path] = `${path}/index`
               return [{
                 component(resolve) { require([`../${component}.vue`], resolve) },
                 icon: icon,

+ 12 - 11
src/store/modules/user.js

@@ -1,29 +1,30 @@
 import { getStore, setStore } from '@/util/store'
-import { isURL } from '@/util/validate'
+import { isURL, validatenull } from '@/util/validate'
 import { getUserInfo, loginByMobile, loginBySocial, loginByUsername, logout, refreshToken } from '@/api/login'
 import { deepClone, encryption } from '@/util/util'
 import webiste from '@/const/website'
 import { GetMenu } from '@/api/admin/menu'
 
 function addPath(ele, first) {
-  const propsConfig = webiste.menu.props
+  const menu = webiste.menu
+  const propsConfig = menu.props
   const propsDefault = {
-    label: propsConfig.label || 'label',
+    label: propsConfig.label || 'name',
     path: propsConfig.path || 'path',
     icon: propsConfig.icon || 'icon',
     children: propsConfig.children || 'children'
   }
+  const icon = ele[propsDefault.icon]
+  ele[propsDefault.icon] = validatenull(icon) ? menu.iconDefault : icon
   const isChild = ele[propsDefault.children] && ele[propsDefault.children].length !== 0
-  if (!isChild && first) {
+  if (!isChild) ele[propsDefault.children] = []
+  if (!isChild && first && !isURL(ele[propsDefault.path])) {
     ele[propsDefault.path] = ele[propsDefault.path] + '/index'
-    return
+  } else {
+    ele[propsDefault.children].forEach(child => {
+      addPath(child)
+    })
   }
-  ele[propsDefault.children].forEach(child => {
-    if (!isURL(child[propsDefault.path])) {
-      child[propsDefault.path] = `${ele[propsDefault.path]}/${child[propsDefault.path] ? child[propsDefault.path] : 'index'}`
-    }
-    addPath(child)
-  })
 }
 
 const user = {

+ 5 - 13
src/views/admin/menu/index.vue

@@ -139,16 +139,7 @@
               </el-form-item>
               <el-form-item
                 v-if="form.type === '0'"
-                label="前端组件"
-                prop="component">
-                <el-input
-                  v-model="form.component"
-                  :disabled="formEdit"
-                  placeholder="请输入描述"/>
-              </el-form-item>
-              <el-form-item
-                v-if="form.type === '0'"
-                label="前端地址"
+                label="地址"
                 prop="component">
                 <el-input
                   v-model="form.path"
@@ -254,15 +245,16 @@ export default {
       }
     }
   },
+
+  computed: {
+    ...mapGetters(['elements', 'permissions'])
+  },
   created() {
     this.getList()
     this.menuManager_btn_add = this.permissions['sys_menu_add']
     this.menuManager_btn_edit = this.permissions['sys_menu_edit']
     this.menuManager_btn_del = this.permissions['sys_menu_del']
   },
-  computed: {
-    ...mapGetters(['elements', 'permissions'])
-  },
   methods: {
     getList() {
       fetchMenuTree(this.listQuery).then(response => {