Przeglądaj źródła

优化专利详情界面返回上级专利清单界面

zhuliu 10 miesięcy temu
rodzic
commit
ce609e8763
2 zmienionych plików z 56 dodań i 19 usunięć
  1. 22 0
      src/router/index.js
  2. 34 19
      src/views/project/patentDetails/index.vue

+ 22 - 0
src/router/index.js

@@ -682,6 +682,8 @@ const router = new VueRouter({
   routes
 })
 
+
+
 function savePreviousRoute(to){
   if(to.meta.notReturn || to.path == '/login' || to.path == '/'){
     return
@@ -694,7 +696,26 @@ function savePreviousRoute(to){
   }
   localStorage.setItem('redirectUrl',JSON.stringify(redirectUrl))
 }
+
+let lastRoute = null
+
+function setLastRoute(to,from){
+  if(to.name == 'patentDetails'){
+    lastRoute = {
+      path:from.path,
+      query:from.query,
+      params:from.params
+    }
+  }
+}
+
+export function getLastRoute(){
+  return lastRoute
+}
+
+
 router.beforeEach((to, from, next) => {
+  setLastRoute(to,from)
   savePreviousRoute(to)
   if(to.path == '/login'){
     Cookies.remove("token")
@@ -765,6 +786,7 @@ router.beforeEach((to, from, next) => {
 })
 
 router.afterEach((to, from) => {
+
 });
 
 export default router

+ 34 - 19
src/views/project/patentDetails/index.vue

@@ -29,6 +29,7 @@ import tortContrast from '@/views/report/tort/components/tortContrast1.vue'
 import teamwork from '@/views/report/components/dialog/teamwork.vue'
 import notPatentDetails from './components/notPatentDetails.vue'
 import {mapGetters} from 'vuex'
+import {getLastRoute} from '@/router'
 export default {
   components: {
     articleMenu,
@@ -129,22 +130,28 @@ export default {
   created() { },
   mounted() {
     if(this.search && !this.search.fromPath){
-      this.search.fromPath = window.history.length
-      if(window.history.state){
-        this.currentState = window.history.state.key
+      var lastRoute = getLastRoute()
+      if(lastRoute){
+        this.search.fromPath = JSON.stringify(lastRoute)
+      }else{
+        this.search.fromPath = 'noLastRoute'
       }
-      var that = this
-      window.addEventListener('popstate', function(event) {
-        // console.log(event,that.currentState,event.state.key)
-        // 在这里处理历史记录变化时的逻辑
-        if(that.currentState<event.state.key){
-          that.search.fromPath += 1
-        }else{
-          that.search.fromPath -= 1
-        }
+      // this.search.fromPath = window.history.length
+      // if(window.history.state){
+      //   this.currentState = window.history.state.key
+      // }
+      // var that = this
+      // window.addEventListener('popstate', function(event) {
+      //   // console.log(event,that.currentState,event.state.key)
+      //   // 在这里处理历史记录变化时的逻辑
+      //   if(that.currentState<event.state.key){
+      //     that.search.fromPath += 1
+      //   }else{
+      //     that.search.fromPath -= 1
+      //   }
         
-        that.currentState = event.state.key
-      })
+      //   that.currentState = event.state.key
+      // })
       this.$s.setSession('search',this.search)
     }
     if(this.noveltySearch){
@@ -292,11 +299,19 @@ export default {
     },
     //返回
     goBack() {
-      if(this.search.fromPath){
-        var now = window.history.length
-        var history= this.search.fromPath
-        var len = Number(now) - Number(history) + 1
-        window.history.go(-len)
+      if(this.search.fromPath && this.search.fromPath != 'noLastRoute'){
+        // var now = window.history.length
+        // var history= this.search.fromPath
+        // var len = Number(now) - Number(history) + 1
+        // window.history.go(-len)
+        var redirectUrl = JSON.parse(this.search.fromPath)
+        this.$router.push({
+          path:redirectUrl.path,
+          query:redirectUrl.query,
+          params:redirectUrl.params
+        })
+      }else{
+        this.$message.warning('未找到上级页面')
       }
     },
     //协同