From 8e51e2713e358aade30db570b0cb8a4877022cf9 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期三, 15 六月 2022 13:40:46 +0800
Subject: [PATCH] 1.递交

---
 src/views/zzmx/chda.vue                 |   11 +
 src/permission.js                       |    1 
 vue.config.js                           |   13 +
 src/api/user.js                         |    5 
 src/views/sbgl/sbqd.vue                 |   11 +
 src/utils/auth.js                       |   26 +++
 src/router/index.js                     |   79 +++++++++++--
 src/utils/request.js                    |   23 ++-
 .env.development                        |    1 
 src/views/wlgl/ckdy.vue                 |   11 +
 package.json                            |    3 
 .env.production                         |    3 
 src/layout/components/Sidebar/index.vue |   97 ++++++++++++++-
 src/views/wlgl/kwdy.vue                 |   11 +
 src/views/zzmx/wllx.vue                 |   11 +
 15 files changed, 264 insertions(+), 42 deletions(-)

diff --git a/.env.development b/.env.development
index 5fd6935..849e0a2 100644
--- a/.env.development
+++ b/.env.development
@@ -3,3 +3,4 @@
 
 # base api
 VUE_APP_BASE_API = 'http://121.196.36.24:8001/api/'
+
diff --git a/.env.production b/.env.production
index 80c8103..93546cd 100644
--- a/.env.production
+++ b/.env.production
@@ -2,5 +2,6 @@
 ENV = 'production'
 
 # base api
-VUE_APP_BASE_API = '/prod-api'
+#VUE_APP_BASE_API = './'
+VUE_APP_BASE_API = 'http://121.196.36.24:8001/api/'
 
diff --git a/package.json b/package.json
index bf839ce..e0d6fd1 100644
--- a/package.json
+++ b/package.json
@@ -49,7 +49,8 @@
     "serve-static": "1.13.2",
     "svg-sprite-loader": "4.1.3",
     "svgo": "1.2.2",
-    "vue-template-compiler": "2.6.10"
+    "vue-template-compiler": "2.6.10",
+    "webpack-dev-server": "^3.0.0"
   },
   "browserslist": [
     "> 1%",
diff --git a/src/api/user.js b/src/api/user.js
index 2edbe7a..48a69de 100644
--- a/src/api/user.js
+++ b/src/api/user.js
@@ -7,11 +7,10 @@
     params: data
   })
 }
-export function LoginMenu(data) {
+export function LoginMenu() {
   return request({
     url: 'Login/LoginMenu',
-    method: 'get',
-    params: data
+    method: 'get'
   })
 }
 
diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue
index ec50cdc..8e366d8 100644
--- a/src/layout/components/Sidebar/index.vue
+++ b/src/layout/components/Sidebar/index.vue
@@ -13,14 +13,14 @@
         :collapse-transition="false"
         mode="vertical"
       >
-        <!--        <sidebar-item-->
-        <!--          v-for="route in routes"-->
-        <!--          :key="route.path"-->
-        <!--          class="el-scrollbar-menu"-->
-        <!--          :item="route"-->
-        <!--          :base-path="route.path"-->
-        <!--        />-->
-        <sidebar-item v-for="route in permission_routes" :key="route.path" :item="route" :base-path="route.path" />
+        <sidebar-item
+          v-for="route in routes"
+          :key="route.path"
+          class="el-scrollbar-menu"
+          :item="route"
+          :base-path="route.path"
+        />
+        <!--        <sidebar-item v-for="route in permission_routes" :key="route.path" :item="route" :base-path="route.path" />-->
 
       </el-menu>
     </el-scrollbar>
@@ -36,16 +36,95 @@
 import Logo from './Logo'
 import SidebarItem from './SidebarItem'
 import variables from '@/styles/variables.scss'
+import { LoginMenu } from '@/api/user'
 
 export default {
   components: { SidebarItem, Logo },
+  data() {
+    return {
+      routers: []
+    }
+  },
+  async created() {
+    // const arr = [
+    //   {
+    //     name: '绯荤粺棣栭〉'
+    //   },
+    //   {
+    //     name: '鍩虹璁剧疆',
+    //     children: [
+    //       { name: '缁勭粐鏋舵瀯' },
+    //       { name: '瑙掕壊娓呭崟' },
+    //       { name: '鐢ㄦ埛娓呭崟' }
+    //     ]
+    //   },
+    //   {
+    //     name: '鍒堕�犳ā鍨�',
+    //     children: [
+    //       { name: '鍏泭璺嚎' },
+    //       { name: '鑺傛媿宸ヤ环' },
+    //       { name: '瀛樿揣妗f' }
+    //     ]
+    //   }
+    // ]
+    // this.routers = arr
+    const res = await LoginMenu()
+    console.log(res, 999)
+  },
   computed: {
     ...mapGetters([
       'permission_routes',
       'sidebar'
     ]),
     routes() {
-      return this.$router.options.routes
+      // console.log(this.$router.options.routes, 111)
+      // this.$router.options.routes.forEach((item, index) => {
+      //   if (item.name === 'jcsz') {
+      //     this.$router.options.routes.slice(index, 1)
+      //   }
+      // })
+
+      // return this.$router.options.routes.filter(item => {
+      //   console.log(item)
+      //   return item.name === 'jcsz'
+      // })
+      console.log(this.routers, 99)
+      console.log(this.$router.options.routes, 11)
+
+      const newArr = []
+      this.routers.forEach(item => {
+        if (item.name) {
+          newArr.push(item.name)
+          if (item.children) {
+            item.children.forEach(it => {
+              if (it.name) {
+                newArr.push(it.name)
+              }
+            })
+          }
+        }
+      })
+      console.log(newArr, 333)
+      const arr = this.$router.options.routes
+      const arr2 = []
+      arr.forEach((item, index) => {
+        console.log(newArr.includes(item.name), 222)
+
+        if (newArr.includes(item.name) && item.children.length === 1) {
+          arr2.push(item)
+        } else if (newArr.includes(item.name) && item.children.length > 1) {
+          const a = []
+          item.children.forEach((it, ind) => {
+            if (newArr.includes(it.name)) {
+              a.push(it)
+            }
+          })
+          item.children = a
+
+          arr2.push(item)
+        }
+      })
+      return arr2
     },
     activeMenu() {
       const route = this.$route
diff --git a/src/permission.js b/src/permission.js
index 89024f9..ac6b2fe 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -52,6 +52,7 @@
           // if (s) {
           //   console.log(s)
           // }
+
           next()
           // next({ ...to, replace: true })
         } catch (error) {
diff --git a/src/router/index.js b/src/router/index.js
index 66962f9..fed8437 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -57,6 +57,7 @@
     path: '/',
     component: Layout,
     redirect: '/index',
+    name: '绯荤粺棣栭〉',
     children: [{
       path: 'index',
       name: 'index',
@@ -68,29 +69,69 @@
     path: '/jcsz',
     component: Layout,
     redirect: '/jcsz/zzjg',
-    name: 'jcsz',
+    name: '鍩虹璁剧疆',
     meta: { title: '鍩虹璁剧疆', icon: 'el-icon-setting' },
     children: [
       {
         path: 'zzjg',
-        name: 'Table',
+        name: '缁勭粐鏋舵瀯',
         component: () => import('@/views/jcsz/zzjg'),
         meta: { title: '缁勭粐鏋舵瀯', icon: '' }
       }, {
         path: 'jsqd',
-        name: 'jsqd',
+        name: '瑙掕壊娓呭崟',
         component: () => import('@/views/jcsz/jsqd'),
         meta: { title: '瑙掕壊娓呭崟', icon: '' }
       }, {
         path: 'yhqd',
-        name: 'yhqd',
+        name: '鐢ㄦ埛娓呭崟',
         component: () => import('@/views/jcsz/yhqd'),
         meta: { title: '鐢ㄦ埛娓呭崟', icon: '' }
       }, {
         path: 'wldw',
-        name: 'wldw',
+        name: '寰�鏉ュ崟浣�',
         component: () => import('@/views/jcsz/wldw'),
         meta: { title: '寰�鏉ュ崟浣�', icon: '' }
+      }
+    ]
+  }, {
+    path: '/sbgl',
+    component: Layout,
+    redirect: '/sbgl/sbqd',
+    name: '璁惧绠$悊',
+    meta: { title: '璁惧绠$悊', icon: 'el-icon-setting' },
+    children: [
+      {
+        path: 'sbqd',
+        name: '璁惧娓呭崟',
+        component: () => import('@/views/sbgl/sbqd'),
+        meta: { title: '璁惧娓呭崟', icon: '' }
+      }
+      // {
+      //   path: 'sblxsz',
+      //   name: '瑙掕壊娓呭崟',
+      //   component: () => import('@/views/jcsz/jsqd'),
+      //   meta: { title: '瑙掕壊娓呭崟', icon: '' }
+      // },
+    ]
+  }, {
+    path: '/wlgl',
+    component: Layout,
+    redirect: '/wlgl/ckdy',
+    name: '鐗╂枡绠$悊',
+    meta: { title: '鐗╂枡绠$悊', icon: 'el-icon-setting' },
+    children: [
+      {
+        path: 'ckdy',
+        name: '浠撳簱瀹氫箟',
+        component: () => import('@/views/wlgl/ckdy'),
+        meta: { title: '浠撳簱瀹氫箟', icon: '' }
+      },
+      {
+        path: 'kwdy',
+        name: '搴撲綅瀹氫箟',
+        component: () => import('@/views/wlgl/kwdy'),
+        meta: { title: '搴撲綅瀹氫箟', icon: '' }
       }
     ]
   },
@@ -98,23 +139,35 @@
     path: '/zzmx',
     component: Layout,
     redirect: '/zzmx/gylx',
-    name: 'zzmx',
+    name: '鍒堕�犳ā鍨�',
     meta: { title: '鍒堕�犳ā鍨�', icon: 'el-icon-s-help' },
     children: [
       {
         path: 'gylx',
-        name: 'gylx',
+        name: '鍏泭璺嚎',
         component: () => import('@/views/zzmx/gylx'),
-        meta: { title: '鍏泭璺嚎', icon: 'table' }
+        meta: { title: '鍏泭璺嚎', icon: '' }
       },
       {
         path: 'jpgj',
-        name: 'jpgj',
+        name: '鑺傛媿宸ヤ环',
         component: () => import('@/views/zzmx/jpgj'),
-        meta: { title: '鑺傛媿宸ヤ环', icon: 'tree' }
+        meta: { title: '鑺傛媿宸ヤ环', icon: '' }
+      }, {
+        path: 'wllx',
+        name: '鐗╂枡绫诲瀷',
+        component: () => import('@/views/zzmx/wllx'),
+        meta: { title: '鐗╂枡绫诲瀷', icon: '' }
+      },
+      {
+        path: 'chda',
+        name: '瀛樿揣妗f',
+        component: () => import('@/views/zzmx/chda'),
+        meta: { title: '瀛樿揣妗f', icon: '' }
       }
     ]
-  }
+  },
+  { path: '*', redirect: '/404', hidden: true }
 ]
 
 // export const constantRoutesxxxxxx = [
@@ -207,8 +260,8 @@
 //     ]
 //   },
 //
-//   // 404 page must be placed at the end !!!
-//   { path: '*', redirect: '/404', hidden: true }
+// 404 page must be placed at the end !!!
+// , {path: '*', redirect: '/404', hidden: true}
 // ]
 
 const createRouter = () => new Router({
diff --git a/src/utils/auth.js b/src/utils/auth.js
index a137df1..e9bdf27 100644
--- a/src/utils/auth.js
+++ b/src/utils/auth.js
@@ -14,14 +14,32 @@
   return Cookies.remove(TokenKey)
 }
 
-export function getCookie(key) {
-  return Cookies.get(key)
+export function getCookie(c_name) {
+  // document.cookie = escape(key) + ';path=/'
+  if (document.cookie.length > 0) {
+    let c_start = document.cookie.indexOf(c_name + '=')
+    if (c_start != -1) {
+      c_start = c_start + c_name.length + 1
+      let c_end = document.cookie.indexOf(';', c_start)
+      if (c_end == -1) {
+        c_end = document.cookie.length
+      }
+      return unescape(document.cookie.substring(c_start, c_end))
+    }
+  }
+  return ''
+  // return Cookies.get(key)
 }
 
 export function setCookie(key, value) {
-  return Cookies.set(key, value)
+  var date = new Date()
+  date.setSeconds(date.getSeconds() + 10000)
+  document.cookie = key + '=' + escape(value) + '; expires=' + date.toGMTString() + ';path=/'
+
+  // return Cookies.set(key, value)
 }
 
 export function removeCookie(key) {
-  return Cookies.remove(key)
+  setCookie(key, '', -1)
+  // return Cookies.remove(key)
 }
diff --git a/src/utils/request.js b/src/utils/request.js
index eeb81b4..aa096f6 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -1,13 +1,13 @@
 import axios from 'axios'
 import { MessageBox, Message } from 'element-ui'
 import store from '@/store'
-import { getToken } from '@/utils/auth'
-
+import { getCookie, getToken } from '@/utils/auth'
 // create an axios instance
 const service = axios.create({
   baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
-  // withCredentials: true, // send cookies when cross-domain requests
+  withCredentials: true, // send cookies when cross-domain requests
   timeout: 5000 // request timeout
+
 })
 
 // request interceptor
@@ -15,12 +15,17 @@
   config => {
     // do something before request is sent
 
-    if (store.getters.token) {
-      // let each request carry token
-      // ['X-Token'] is a custom headers key
-      // please modify it according to the actual situation
-      config.headers['X-Token'] = getToken()
+    if (getCookie('admin')) {
+    // let each request carry token
+    // ['X-Token'] is a custom headers key
+    // please modify it according to the actual situation
+    // config.headers['X-Token'] = getToken()
+    //   config.headers['Authorization'] = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId')
+      config.headers['Cookie'] = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId')
+    //   document.cookie = 'admin=' + getCookie('admin') + ';navTabId=' + getCookie('navTabId')
+    //   document.cookie = 'admin'
     }
+    console.log(config, 1)
     return config
   },
   error => {
@@ -35,7 +40,7 @@
   /**
    * If you want to get http information such as headers or status
    * Please return  response => response
-  */
+   */
 
   /**
    * Determine the request status by custom code
diff --git a/src/views/sbgl/sbqd.vue b/src/views/sbgl/sbqd.vue
new file mode 100644
index 0000000..cb05b35
--- /dev/null
+++ b/src/views/sbgl/sbqd.vue
@@ -0,0 +1,11 @@
+<template />
+
+<script>
+export default {
+  name: 'Sbqd'
+}
+</script>
+
+<style scoped>
+
+</style>
diff --git a/src/views/wlgl/ckdy.vue b/src/views/wlgl/ckdy.vue
new file mode 100644
index 0000000..33de60d
--- /dev/null
+++ b/src/views/wlgl/ckdy.vue
@@ -0,0 +1,11 @@
+<template />
+
+<script>
+export default {
+  name: 'Ckdy'
+}
+</script>
+
+<style scoped>
+
+</style>
diff --git a/src/views/wlgl/kwdy.vue b/src/views/wlgl/kwdy.vue
new file mode 100644
index 0000000..b0bc913
--- /dev/null
+++ b/src/views/wlgl/kwdy.vue
@@ -0,0 +1,11 @@
+<template />
+
+<script>
+export default {
+  name: 'Wldy'
+}
+</script>
+
+<style scoped>
+
+</style>
diff --git a/src/views/zzmx/chda.vue b/src/views/zzmx/chda.vue
new file mode 100644
index 0000000..206b836
--- /dev/null
+++ b/src/views/zzmx/chda.vue
@@ -0,0 +1,11 @@
+<template />
+
+<script>
+export default {
+  name: 'Chda'
+}
+</script>
+
+<style scoped>
+
+</style>
diff --git a/src/views/zzmx/wllx.vue b/src/views/zzmx/wllx.vue
new file mode 100644
index 0000000..ef72891
--- /dev/null
+++ b/src/views/zzmx/wllx.vue
@@ -0,0 +1,11 @@
+<template />
+
+<script>
+export default {
+  name: 'Wllx'
+}
+</script>
+
+<style scoped>
+
+</style>
diff --git a/vue.config.js b/vue.config.js
index 9f32fb0..f0c725d 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -24,7 +24,7 @@
    * In most cases please use '/' !!!
    * Detail: https://cli.vuejs.org/config/#publicpath
    */
-  publicPath: '/',
+  publicPath: './',
   outputDir: 'dist',
   assetsDir: 'static',
   lintOnSave: process.env.NODE_ENV === 'development',
@@ -36,7 +36,16 @@
       warnings: false,
       errors: true
     },
-    before: require('./mock/mock-server.js')
+    proxy: {
+      [process.env.VUE_APP_BASE_API]: {
+        target: process.env.VUE_APP_BASE_API, // 璇锋眰鐨勭涓夆絽鎺モ紳鍦板潃
+        changeOrigin: true, // 璇锋眰璺ㄥ煙鏃讹紝闇�閰嶇疆姝ら」
+        pathRewrite: { // 璺緞閲嶅啓,鏇挎崲target涓殑璇锋眰鍦板潃
+          ['^' + process.env.VUE_APP_BASE_API]: ''
+        }
+      }
+    }
+    // before: require('./mock/mock-server.js')
   },
   configureWebpack: {
     // provide the app's title in webpack's name field, so that

--
Gitblit v1.9.3