Browse Source

动态路由处理

zweizhao 7 years ago
parent
commit
98e25ab96a
3 changed files with 26 additions and 11 deletions
  1. 1 1
      components/menu/index.vue
  2. 22 7
      pages/main/index/dev_check.vue
  3. 3 3
      plugins/http.js

+ 1 - 1
components/menu/index.vue

@@ -16,7 +16,7 @@
 
 <script>
 import data from './data'
-console.log(data)
+// console.log(data)
 let menus = data.map(menu => ({
   ...menu,
   subs: menu.subs.filter(sub => !sub.hidden)

+ 22 - 7
pages/main/index/dev_check.vue

@@ -90,20 +90,31 @@ export default {
       tableData: []
     }
   },
+  watch: {
+    '$route'(to, from) {
+      this.handleRouteParams()
+    }
+  },
   mounted() {
-    console.log(this.currentPage)
+    // console.log(this.currentPage)
     this.getFilters()
   },
   methods: {
     // 页码变动
     changePagination(page) {
-      this.getTableData()
+      // console.log(this.certID, page)
+      this.$router.replace({
+        // path: `/main/dev_check`,
+        query: { page, cert_id: this.certID }
+      })
     },
     // 筛选框变动
     changeSelect(id) {
-      this.currentPage = 1
       this.certID = id
-      this.getTableData()
+      this.$router.replace({
+        // path: `/main/dev_check`,
+        query: { page: this.currentPage, cert_id: id }
+      })
     },
     // 获取筛选
     async getFilters() {
@@ -115,7 +126,12 @@ export default {
       })
       this.statuses = data.cert_type_list || []
       this.selected = this.statuses[0].name
-
+      this.handleRouteParams()
+    },
+    /**
+     * 路由钩子触发获取路由携带query, 首次进入也算一次
+     */
+    handleRouteParams() {
       this.currentPage = Number(this.$route.query.page)
       this.certID = this.$route.query.cert_id
       this.getTableData()
@@ -153,11 +169,10 @@ export default {
     async getTableData() {
       this.tableData = []
       let page = this.currentPage
-      console.log(this.currentPage)
       let cert_id = this.certID
       let body = { page, cert_id }
       let res = await this.$post("/api/admin/audit/getList", body)
-      console.log(body)
+      // console.log(body)
       let data = res.data
       env = data.current_env
       this.tableData = this.formatTableData(res.data.list)

+ 3 - 3
plugins/http.js

@@ -59,7 +59,7 @@ const request = async (method, path, data, payload = {}) => {
   }
   if(payload.config) Object.assign(body, payload.config, { params: '' })
 
-  console.log(`url: ${url}`)
+  // console.log(`url: ${url}`)
   consoleFormat({ body })
 
   const res = await axios.request(body)
@@ -79,8 +79,8 @@ const request = async (method, path, data, payload = {}) => {
 
 const consoleFormat = obj => {
   const key = Object.keys(obj)[0]
-  console.log(key + ':')
-  console.dir(obj[key])
+  // console.log(key + ':')
+  // console.dir(obj[key])
   // console.log()
 }