loulijun2021
2022-07-11 e7f22e51057aa90e19afee1628dc68a0d7a6c99e
1.优化tagviews
已修改4个文件
45 ■■■■ 文件已修改
src/layout/components/TagsView/index.vue 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/modules/user.js 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/jcsz/jsqd.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/jcsz/wldw.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/layout/components/TagsView/index.vue
@@ -28,6 +28,7 @@
<script>
import ScrollPane from './ScrollPane'
import path from 'path'
import { getCookie } from '@/utils/auth'
export default {
  components: { ScrollPane },
@@ -64,8 +65,35 @@
  mounted() {
    this.initTags()
    this.addTags()
    this.beforeUnload()
  },
  methods: {
    // 解决 vue-admin-template 刷新页面 TagsView 丢失问题
    beforeUnload() {
      // 监听页面刷新
      window.addEventListener('beforeunload', () => {
        // visitedViews数据结构太复杂无法直接JSON.stringify处理,先转换需要的数据
        const tabViews = this.visitedViews.map(item => {
          return {
            fullPath: item.fullPath,
            hash: item.hash,
            meta: { ...item.meta },
            name: item.name,
            params: { ...item.params },
            path: item.path,
            query: { ...item.query },
            title: item.title
          }
        })
        sessionStorage.setItem('tabViews', JSON.stringify(tabViews))
      })
      // 页面初始化加载判断缓存中是否有数据
      const oldViews = JSON.parse(sessionStorage.getItem('tabViews')) || []
      if (oldViews.length > 0) {
        this.$store.state.tagsView.visitedViews = oldViews
      }
    },
    isActive(route) {
      return route.path === this.$route.path
    },
src/store/modules/user.js
@@ -90,7 +90,7 @@
  },
  // user logout
  logout({ commit, state }) {
  logout({ commit, state, dispatch }) {
    return new Promise((resolve, reject) => {
      const usercode = getCookie('navTabId')
      const username = getCookie('admin')
@@ -112,10 +112,15 @@
          removeCookie('navTabId')
          removeCookie('usertype')
          removeCookie('userid')
        }
        commit('RESET_STATE')
        resolve()
          // reset visited views and cached views
          dispatch('tagsView/delAllViews', null, { root: true })
          sessionStorage.removeItem('tabViews')
          commit('RESET_STATE')
          resolve()
        }
      }).catch(error => {
        reject(error)
      })
src/views/jcsz/jsqd.vue
@@ -509,7 +509,7 @@
const SER_HZ = /^[\u4e00-\u9fa5]+$/
export default {
  name: 'Zzjg',
  name: 'JSQD',
  components: {
    Pagination
  },
src/views/jcsz/wldw.vue
@@ -210,7 +210,7 @@
const SER_HZ = /^[\u4e00-\u9fa5]+$/
export default {
  name: 'Zzjg',
  name: 'WLDW',
  components: {
    Pagination
  },