Kaynağa Gözat

Merge branch 'http_mock' of git.xiaojukeji.com:jacklijiajia/thoth-frontend into http_mock

qinzhipeng_v 5 yıl önce
ebeveyn
işleme
ac3352a8c0

+ 53 - 0
src/App.vue

@@ -5,6 +5,7 @@
 </template>
 
 <script>
+import { getGlobalInterface } from '@/api/data.js'
 import { getUserInfo } from '@/api/user.js'
 // omega埋点工具包
 import OmegaTracker from '@didi/omega-tracker/lib/index.esm'
@@ -21,11 +22,63 @@ export default {
   },
   created() {
     this.initOmegaTracker()
+    this.initRoutes()
   },
   methods: {
     initOmegaTracker() {
       const omega = OmegaTracker.getTracker(config)
       return omega
+    },
+    initRoutes() {
+      this.$store.dispatch('data/setRoutes', this.$router.options.routes)
+      // 数据中心动态路由获取
+      getGlobalInterface().then(res => {
+        this.$store.dispatch('data/setMenu', res.data)
+        const dataCenterRoutes = []
+        const route = {
+          path: '/data',
+          component: () => import('@/layout'),
+          redirect: '/data/upload-file',
+          name: '数据中心',
+          meta: { title: '数据中心' },
+          children: [
+            {
+              path: 'upload-file',
+              name: 'jar包管理',
+              component: () => import('@/views/data/upload.vue'),
+              meta: { title: 'jar包管理' }
+            }
+          ]
+        }
+        for (const i in res.data) {
+          const routeItem = {
+            path: res.data[i].subMenus[0].path + '/' + i,
+            redirect: res.data[i].subMenus[0].path,
+            name: res.data[i].menuName + '/' + i,
+            component: () => import('@/views/data/index.vue'),
+            meta: { title: res.data[i].menuName },
+            children: []
+          }
+          for (const j in res.data[i].subMenus) {
+            const routeChildrenItem = {
+              path: res.data[i].subMenus[j].path + '/' + i + '/' + j,
+              name: res.data[i].subMenus[j].subMenuName + '/' + i + '/' + j,
+              component: () => import('@/views/data/index.vue'),
+              meta: { title: res.data[i].subMenus[j].subMenuName }
+            }
+            routeItem.children.push(routeChildrenItem)
+          }
+          route.children.push(routeItem)
+        }
+        dataCenterRoutes.push(route)
+        this.$router.addRoutes(dataCenterRoutes)
+        for (const i in this.$router.options.routes) {
+          if (this.$router.options.routes[i].name === '工具集合') {
+            this.$router.options.routes[i].children.push(route)
+          }
+        }
+        this.$store.dispatch('data/setRoutes', this.$router.options.routes)
+      })
     }
   }
 }

+ 4 - 44
src/layout/components/Sidebar/index.vue

@@ -12,20 +12,8 @@
           :active-text-color="variables.menuActiveText"
           :collapse-transition="false"
           mode="vertical"
-          @select="handleSelect"
         >
           <sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
-          <el-submenu index="100">
-            <template slot="title">
-              <svg-icon icon-class="data" />
-              <span slot="title" @mouseover="getGlobalInterface">数据中心</span>
-            </template>
-            <el-menu-item index="/data/upload-file">jar包管理</el-menu-item>
-            <el-submenu v-for="(myMenu,index) in menu" :key="myMenu.menuName" :index="'100-' + index">
-              <template slot="title">{{ myMenu.menuName }}</template>
-              <el-menu-item v-for="(subMenu,index2) in myMenu.subMenus" :key="'1000-' + index2" :index="getIndex(index,index2)" @click="handleClick(subMenu)">{{ subMenu.subMenuName }}</el-menu-item>
-            </el-submenu>
-          </el-submenu>
         </el-menu>
       </el-scrollbar>
     </el-main>
@@ -41,7 +29,6 @@ import { mapGetters } from 'vuex'
 import Logo from './Logo'
 import SidebarItem from './SidebarItem'
 import variables from '@/styles/variables.scss'
-import { getGlobalInterface } from '@/api/data.js'
 import { logoutUrl } from '@/apiConfig/requestIP.js'
 import Hamburger from '@/components/Hamburger'
 
@@ -50,11 +37,11 @@ export default {
   computed: {
     ...mapGetters([
       'sidebar',
-      'menu'
+      'routes'
     ]),
-    routes() {
-      return this.$router.options.routes
-    },
+    // routes() {
+    //   return this.$router.options.routes
+    // },
     activeMenu() {
       const route = this.$route
       const { meta, path } = route
@@ -74,37 +61,10 @@ export default {
       return !this.sidebar.opened
     }
   },
-  mounted() {
-    this.getGlobalInterface()
-  },
   methods: {
     toggleSideBar() {
       this.$store.dispatch('app/toggleSideBar')
     },
-    handleSelect(key, keypath) {
-      switch (key) {
-        case '/data/upload-file':
-          this.$router.push({ name: 'jar包管理' })
-          break
-      }
-    },
-    handleClick(subMenu) {
-      this.$store.dispatch('data/setSubMenu', subMenu)
-      this.$router.push({ name: '动态数据' })
-    },
-    getGlobalInterface() {
-      getGlobalInterface()
-        .then(res => {
-          this.$store.dispatch('data/setMenu', res.data)
-          this.$store.dispatch('data/setSubMenu', res.data[0].subMenus[0])
-        })
-    },
-    getIndex(index, index2) {
-      if (index + index2 === 0) {
-        return '/data/item'
-      }
-      return '100-' + index + '-' + index2
-    },
     Logout() {
       location.href = logoutUrl
     }

+ 1 - 80
src/router/index.js

@@ -1,4 +1,5 @@
 import Vue from 'vue'
+// import { getGlobalInterface } from '@/api/data.js'
 import Router from 'vue-router'
 
 Vue.use(Router)
@@ -596,88 +597,8 @@ export const constantRoutes = [{
           import('@/views/ToConfigure/configure'),
       meta: { title: '配置' }
     }
-    // {
-    //   path: 'systemSetup',
-    //   name: '系统设置',
-    //   component: () =>
-    //         import('@/views/Platform/setUp/systemSetup/testa'),
-    //   meta: { title: '系统设置' },
-    //   children: [{
-    //     path: 'bizPage',
-    //     name: '业务线',
-    //     component: () =>
-    //             import('@/views/Platform/setUp/systemSetup/bizPage'),
-    //     meta: { title: '业务线' }
-    //   },
-    //   {
-    //     path: 'platformPage',
-    //     name: '平台类型',
-    //     component: () =>
-    //             import('@/views/Platform/setUp/systemSetup/platformPage'),
-    //     meta: { title: '平台类型' }
-    //   },
-    //   {
-    //     path: 'modulePage',
-    //     name: '业务模块',
-    //     component: () =>
-    //             import('@/views/Platform/setUp/systemSetup/modulePage'),
-    //     meta: { title: '业务模块' }
-    //   },
-    //   {
-    //     path: 'projectPage',
-    //     name: '工程模块',
-    //     component: () =>
-    //             import('@/views/Platform/setUp/systemSetup/projectPage'),
-    //     meta: { title: '工程模块' }
-    //   },
-    //   {
-    //     path: 'confList',
-    //     name: '业务配置列表',
-    //     component: () =>
-    //             import('@/views/Platform/setUp/systemSetup/confList'),
-    //     meta: { title: '业务配置列表' }
-    //   },
-    //   {
-    //     path: 'addConf',
-    //     name: '新增配置',
-    //     component: () =>
-    //             import('@/views/Platform/setUp/systemSetup/addConf'),
-    //     meta: { title: '新增配置' }
-    //   }
-    //   ]
-    // },
-    // {
-    //   path: 'teamPage',
-    //   name: '团队设置',
-    //   component: () =>
-    //         import('@/views/Platform/setUp/teamPage'),
-    //   meta: { title: '团队设置' }
-    // }
-  ]
-},
-{
-  path: '/data',
-  component: Layout,
-  redirect: '/data/upload-file',
-  name: '数据中心',
-  hidden: true,
-  meta: { title: '数据中心', icon: '数据中心' },
-  children: [
-    {
-      path: 'upload-file',
-      name: 'jar包管理',
-      component: () => import('@/views/data/upload.vue'),
-      meta: { title: 'jar包管理' }
-    },
-    {
-      path: 'item',
-      name: '动态数据',
-      component: () => import('@/views/data/index.vue'),
-      meta: { title: '动态数据' }
-    }
   ]
 }
-
 ]
 
 const createRouter = () => new Router({

+ 2 - 1
src/store/getters.js

@@ -8,6 +8,7 @@ const getters = {
   menu: state => state.data.menu,
   subMenu: state => state.data.subMenu,
   project: state => state.project.project,
-  status: state => state.data.status
+  status: state => state.data.status,
+  routes: state => state.data.routes
 }
 export default getters

+ 7 - 0
src/store/modules/data.js

@@ -1,4 +1,5 @@
 const state = {
+  routes: [],
   menu: '',
   subMenu: '',
   status: false
@@ -13,6 +14,9 @@ const mutations = {
   },
   SETSTATUS: (state, value) => {
     state.status = value
+  },
+  SETROUTES(state, value) {
+    state.routes = value
   }
 }
 
@@ -25,6 +29,9 @@ const actions = {
   },
   setStatus({ commit }, value) {
     commit('SETSTATUS', value)
+  },
+  setRoutes({ commit }, value) {
+    commit('SETROUTES', value)
   }
 }
 

+ 7 - 1
src/views/data/index.vue

@@ -66,6 +66,7 @@ export default {
   name: 'DataCenter',
   data() {
     return {
+      subMenu: [],
       showWidgetsNumber: 0,
       rules: {},
       data: {},
@@ -76,7 +77,7 @@ export default {
   },
   computed: {
     ...mapGetters([
-      'subMenu'
+      'menu'
     ])
   },
   watch: {
@@ -92,9 +93,14 @@ export default {
       }
       this.data = {}
       this.result = ''
+    },
+    $route(to, from) {
+      const urlArr = to.path.split('/')
+      this.subMenu = this.menu[urlArr[urlArr.length - 2]].subMenus[urlArr[urlArr.length - 1]]
     }
   },
   created() {
+    this.subMenu = this.menu[0].subMenus[0]
     for (const i in this.subMenu.widgets) {
       if (this.subMenu.widgets[i].widgetId === 0) {
         this.widgets.push(this.subMenu.widgets[i])

+ 0 - 5
src/views/home/index.vue

@@ -273,7 +273,6 @@ img.img-arrow {
 
 <script>
 import FloatMenu from './floatMenu'
-import { getGlobalInterface } from '@/api/data.js'
 import { logoutUrl } from '@/apiConfig/requestIP.js'
 
 export default {
@@ -305,10 +304,6 @@ export default {
         }
       })()
     }
-    getGlobalInterface().then(res => {
-      this.$store.dispatch('data/setMenu', res.data)
-      this.$store.dispatch('data/setSubMenu', res.data[0].subMenus[0])
-    })
   },
   methods: {
     handleSelect(key, keyPath) {