Browse Source

feat: 修改页面布局结构

aXin-0810 2 years ago
parent
commit
8524188b17

+ 47 - 198
src/permission.js

@@ -1,30 +1,35 @@
 import router from './router'
 import router from './router'
-import { resetRouter } from './router'
 import store from './store'
 import store from './store'
 import { Message } from 'element-ui'
 import { Message } from 'element-ui'
+import { getToken } from '@/utils/auth' // get token from cookie
 import NProgress from 'nprogress' // progress bar
 import NProgress from 'nprogress' // progress bar
 import 'nprogress/nprogress.css' // progress bar style
 import 'nprogress/nprogress.css' // progress bar style
-import { getToken } from '@/utils/auth' // get token from cookie
 import getPageTitle from '@/utils/get-page-title'
 import getPageTitle from '@/utils/get-page-title'
 import Layout from '@/layout'
 import Layout from '@/layout'
-const _import = require('./router/_import_' + process.env.NODE_ENV) // 获取组件的方法
-
+import RouterView from '@/views/routerView.vue'
+import IframeView from '@/views/iframeView.vue'
 NProgress.configure({ showSpinner: false }) // NProgress Configuration
 NProgress.configure({ showSpinner: false }) // NProgress Configuration
-
+const _import = require('./router/_import_' + process.env.NODE_ENV) // 获取组件的方法
 const whiteList = ['/login'] // no redirect whitelist
 const whiteList = ['/login'] // no redirect whitelist
-
+const lay = {
+  path: '/',
+  component: Layout,
+  children: []
+}
+// 递归找最后一级页面
+function getc(obj) {
+  if (!obj.children || !obj.children.length) {
+    return obj
+  } else {
+    return getc(obj.children[0])
+  }
+}
 router.beforeEach(async (to, from, next) => {
 router.beforeEach(async (to, from, next) => {
-  // start progress bar
   NProgress.start()
   NProgress.start()
-
-  // set page title
   document.title = getPageTitle(to.meta.title)
   document.title = getPageTitle(to.meta.title)
-
-  // determine whether the user has logged in
   const hasToken = getToken()
   const hasToken = getToken()
   if (hasToken) {
   if (hasToken) {
     if (to.path === '/login') {
     if (to.path === '/login') {
-      // if is logged in, redirect to the home page
       next({ path: '/' })
       next({ path: '/' })
       NProgress.done()
       NProgress.done()
     } else {
     } else {
@@ -33,75 +38,36 @@ router.beforeEach(async (to, from, next) => {
         next()
         next()
       } else {
       } else {
         try {
         try {
-          // get user info
           await store.dispatch('user/getInfo')
           await store.dispatch('user/getInfo')
-
-          // 请求获取路由表
           await store.dispatch('user/getRouter')
           await store.dispatch('user/getRouter')
           if (store.getters.menus.length < 1) {
           if (store.getters.menus.length < 1) {
             global.antRouter = []
             global.antRouter = []
             next()
             next()
           }
           }
-
           // 设置路由
           // 设置路由
-          var newRoutes = []
-
+          lay.children = []
           for (var route of store.getters.menus) {
           for (var route of store.getters.menus) {
-            const item = buildRootRoute(route)
-            newRoutes.push(item)
-          }
-          console.log(newRoutes, '8589')
-          // newRoutes.shift();
-          // 添加一项根目录重定向页面
-          if (newRoutes[0].path !== '/') {
-            let path = newRoutes[0].path
-            if (newRoutes[0].children.length > 0) {
-              path = `${path}/${newRoutes[0].children[0].path}`
-            }
-            if (newRoutes[0].children[0].children.length > 0) {
-              path = `${path}/${newRoutes[0].children[0].children[0].path}`
-            }
-            newRoutes.unshift({
-              path: '/',
-              component: Layout,
-              redirect: path
-            })
-          } else {
-            newRoutes[0].redirect = '/dashboard'
+            lay.children.push(buildRoute(route))
           }
           }
-
-          console.log(newRoutes)
-          router.addRoutes(newRoutes) // 2.动态添加路由
-          global.antRouter = newRoutes // 3.将路由数据传递给全局变量,做侧边栏菜单渲染工作
-
-          // const menus = filterAsyncRouter(store.getters.menus) // 1.过滤路由
-          // console.log(menus);
-          // router.addRoutes(menus) // 2.动态添加路由
-          // global.antRouter = menus // 3.将路由数据传递给全局变量,做侧边栏菜单渲染工作
+          lay.redirect = getc(lay).name
+          router.addRoutes([lay])
+          global.antRouter = lay.children
           next({
           next({
             ...to,
             ...to,
             replace: true
             replace: true
           })
           })
-          // next()
         } catch (error) {
         } catch (error) {
-          // remove token and go to login page to re-login
           await store.dispatch('user/resetToken')
           await store.dispatch('user/resetToken')
           Message.error(error || 'Has Error')
           Message.error(error || 'Has Error')
           next('/login')
           next('/login')
-          // next(`/login?redirect=${to.path}`);
           NProgress.done()
           NProgress.done()
         }
         }
       }
       }
     }
     }
   } else {
   } else {
-    /* has no token*/
-
     if (whiteList.indexOf(to.path) !== -1) {
     if (whiteList.indexOf(to.path) !== -1) {
-      // in the free login whitelist, go directly
       next()
       next()
     } else {
     } else {
-      // other pages that do not have permission to access are redirected to the login page.
-      // next(`/login?redirect=${to.path}`);
       next('/login')
       next('/login')
       NProgress.done()
       NProgress.done()
     }
     }
@@ -109,164 +75,47 @@ router.beforeEach(async (to, from, next) => {
 })
 })
 
 
 router.afterEach(() => {
 router.afterEach(() => {
-  // finish progress bar
   NProgress.done()
   NProgress.done()
 })
 })
 
 
-// 遍历后台传来的路由字符串,转换为组件对象
-// function filterAsyncRouter(asyncRouterMap) {
-//   const accessedRouters = asyncRouterMap.filter((route) => {
-//     console.log(route);
-//     if (route.component) {
-//       if (route.component === "Layout") {
-//         route.component = Layout;
-//       } else {
-//         route.component = _import(route.component); // 导入组件
-//       }
-//     }
-//     if (route.children && route.children.length) {
-//       route.children = filterAsyncRouter(route.children);
-//     }
-//     return true;
-//   });
-//   return accessedRouters;
-// }
-
-function buildRootRoute(route) {
-  const { url, icon, moduleName, moduleId, code, type, fullUrl } = route
-  var item = {}
-  item.path = url
-  item.component = Layout
-  item.name = fullUrl || code
-  item.meta = {
-    title: moduleName,
-    icon: icon,
-    moduleId
-  }
-  if (code == 'index') {
-    item.path = '/'
-    item.alwaysShow = false
-    const children = route.children
-    route.children = []
-    route.children.push({
-      code: 'dashboard',
-      moduleName: '首页',
-      type: 2,
-      url: '/dashboard',
-      children: children
-    })
-  }
-  if (code == 'issue') {
-    const children = route.children
-    route.children = []
-    route.children.push({
-      code: 'issue_index',
-      moduleName: '文件下发',
-      type: 2,
-      url: '/index',
-      children: children
-    })
-    item.alwaysShow = false
-  }
-  if (code === 'notice') {
-    const children = route.children
-    route.children = []
-    route.children.push({
-      code: 'notice_index',
-      moduleName: '系统通知',
-      type: 2,
-      url: '/index',
-      children: children
-    })
-    item.alwaysShow = false
-  }
-  item.children = []
-  if ((route.hasOwnProperty('children') && type === 1) || code == 'issue' || code == 'notice' || code == 'index') {
-    for (var child of route.children) {
-      item.children.push(buildRoute(child, fullUrl))
-    }
-  }
-  return item
-}
-
-function buildRoute(route, p_url) {
+function buildRoute(route) {
   const { url, moduleName, icon, moduleId, code, type, hidden, fullUrl } = route
   const { url, moduleName, icon, moduleId, code, type, hidden, fullUrl } = route
   var item = {}
   var item = {}
-  if (url.substr(0, 1) === '/') {
-    item.path = url.substr(1)
-  } else {
-    item.path = url
-  }
-  try {
-    if (code == 'dashboard') {
-      // item.component = _import(`${url}/index`)
-      item.component = resolve => require(['@/views' + `${url}/index`], resolve)
-    } else {
-      if (fullUrl) {
-        item.component = _import(`${fullUrl}`)
-      } else {
-        item.component = _import(`${p_url}${url}`)
-      }
-    }
-  } catch (e) {
-    console.log(e)
-  }
+  item.path = fullUrl || code
   item.name = fullUrl || code
   item.name = fullUrl || code
   item.meta = {
   item.meta = {
+    url,
     title: moduleName,
     title: moduleName,
     icon: icon,
     icon: icon,
     moduleId
     moduleId
   }
   }
-  if (route.children && type == 2) {
-    const roles = []
-    for (var role of route.children) {
-      roles.push(role.code)
-    }
-    item.meta.roles = roles
-  }
   item.hidden = hidden
   item.hidden = hidden
-  item.children = []
-  // eslint-disable-next-line no-prototype-builtins
-  if (route.hasOwnProperty('children') && type === 1) {
-    for (var child of route.children) {
-      item.children.push(buildThirdRoute(child, `${p_url}${url}`))
+  if (route.children && route.children.length) {
+    if (type == 2) {
+      try {
+        item.component = _import(`${fullUrl}`)
+      } catch (e) {
+        console.log(e)
+      }
+      const roles = []
+      for (var role of route.children) {
+        roles.push(role.code)
+      }
+      item.meta.roles = roles
+    } else {
+      item.component = RouterView
+      item.children = route.children.map(child => buildRoute(child))
     }
     }
-  }
-  return item
-}
-
-function buildThirdRoute(route, p_url) {
-  const { url, moduleName, icon, moduleId, code, hidden, type, fullUrl } = route
-  var item = {}
-  if (url.substr(0, 1) == '/') {
-    item.path = url.substr(1)
   } else {
   } else {
-    tem.path = url
-  }
-  try {
-    if (fullUrl) {
-      item.component = _import(`${fullUrl}`)
+    if (type == 4) {
+      item.component = IframeView
     } else {
     } else {
-      item.component = _import(`${p_url}${url}`)
-    }
-  } catch (e) {
-    console.log(e)
-  }
-  item.name = fullUrl || code
-
-  item.meta = {
-    title: moduleName,
-    icon: icon,
-    moduleId
-  }
-  if (route.children && type == 2) {
-    const roles = []
-    for (var role of route.children) {
-      roles.push(role.code)
+      try {
+        item.component = _import(`${fullUrl}`)
+      } catch (e) {
+        console.log(e)
+      }
     }
     }
-    item.meta.roles = roles
   }
   }
-  item.hidden = hidden
-  item.children = []
   return item
   return item
 }
 }

+ 19 - 0
src/views/iframeView.vue

@@ -0,0 +1,19 @@
+<template>
+  <iframe :src="url" height="99.5%" width="100%" frameBorder="0" />
+</template>
+<script>
+import { getFanruanToken } from '@/utils/auth'
+export default {
+  data() {
+    return {
+      fanruanToken: getFanruanToken()
+    }
+  },
+  computed: {
+    url() {
+      return this.$route.meta.url && this.fanruanToken ? `${this.$route.meta.url}&ssoToken=${this.fanruanToken}` : ''
+    }
+  }
+}
+</script>
+<style></style>

+ 15 - 0
src/views/routerView.vue

@@ -0,0 +1,15 @@
+<template>
+  <div class="app-main-view-div">
+    <router-view />
+  </div>
+</template>
+
+<style scoped>
+.app-main-view-div {
+  width: 100%;
+  height: 100%;
+  position: relative;
+  overflow-x: hidden;
+  overflow-y: auto;
+}
+</style>

+ 23 - 33
src/views/sales_control/preposition_stock_list.vue

@@ -1,23 +1,19 @@
 <template>
 <template>
-  <div>
-    <template-page
-      style="width: 100%;
-      height: 100%;"
-      ref="pageRef"
-      :getList="getList"
-      :exportList="exportList"
-      :columnParsing="columnParsing"
-      :optionsEvensGroup="optionsEvensGroup"
-    >
-    </template-page>
-  </div>
+  <template-page
+    ref="pageRef"
+    :getList="getList"
+    :exportList="exportList"
+    :columnParsing="columnParsing"
+    :optionsEvensGroup="optionsEvensGroup"
+  >
+  </template-page>
 </template>
 </template>
 
 
 <script>
 <script>
 import TemplatePage from '@/components/template/template-page-1.vue'
 import TemplatePage from '@/components/template/template-page-1.vue'
 import import_mixin from '@/components/template/import_mixin.js'
 import import_mixin from '@/components/template/import_mixin.js'
 
 
-import { getcustomerFrontList, partsNewInExport,partsNewInImport, workerTemplateExcel } from '@/api/stock'
+import { getcustomerFrontList, partsNewInExport, partsNewInImport, workerTemplateExcel } from '@/api/stock'
 export default {
 export default {
   components: { TemplatePage },
   components: { TemplatePage },
   mixins: [import_mixin],
   mixins: [import_mixin],
@@ -25,24 +21,24 @@ export default {
     return {
     return {
       // 事件组合
       // 事件组合
       optionsEvensGroup: [
       optionsEvensGroup: [
-      [
+        [
           [
           [
-          {
-              name: "下载模板",
+            {
+              name: '下载模板',
               click: () => {
               click: () => {
                 workerTemplateExcel({}, `${this.$route.meta.title}`)
                 workerTemplateExcel({}, `${this.$route.meta.title}`)
                   .then(res => {
                   .then(res => {
-                    console.log('chengg');
+                    console.log('chengg')
                     this.$message({
                     this.$message({
-                      message: "下载成功",
-                      type: "success"
-                    });
+                      message: '下载成功',
+                      type: 'success'
+                    })
                   })
                   })
                   .catch(err => {
                   .catch(err => {
-                    this.$message.error("下载失败");
-                  });
+                    this.$message.error('下载失败')
+                  })
               },
               },
-              isRole: this.$checkBtnRole("import", this.$route.meta.roles)
+              isRole: this.$checkBtnRole('import', this.$route.meta.roles)
             }
             }
           ]
           ]
         ],
         ],
@@ -50,12 +46,11 @@ export default {
           [
           [
             {
             {
               name: '',
               name: '',
-              render:this.importButton(partsNewInImport),
-              isRole: this.$checkBtnRole("import", this.$route.meta.roles)
+              render: this.importButton(partsNewInImport),
+              isRole: this.$checkBtnRole('import', this.$route.meta.roles)
             }
             }
           ]
           ]
         ]
         ]
-       
       ],
       ],
       // 表格属性
       // 表格属性
       tableAttributes: {
       tableAttributes: {
@@ -69,8 +64,7 @@ export default {
       recordSelected: []
       recordSelected: []
     }
     }
   },
   },
-  created () {
-  },
+  created() {},
   methods: {
   methods: {
     // 列表请求函数
     // 列表请求函数
     getList(...p) {
     getList(...p) {
@@ -130,8 +124,4 @@ export default {
 }
 }
 </script>
 </script>
 
 
-<style lang="scss" scoped>
-::v-deep .el-table__body-wrapper {
-  height: 100% !important;
-}
-</style>
+<style lang="scss" scoped></style>

+ 2 - 11
src/views/stock_control/preposition_stock_list.vue

@@ -1,15 +1,6 @@
 <template>
 <template>
-  <div>
-    <template-page
-      style="width: 100%;
-      height: 100%;"
-      ref="pageRef"
-      :getList="getList"
-      :exportList="exportList"
-      :columnParsing="columnParsing"
-    >
-    </template-page>
-  </div>
+  <template-page ref="pageRef" :getList="getList" :exportList="exportList" :columnParsing="columnParsing">
+  </template-page>
 </template>
 </template>
 
 
 <script>
 <script>