ke_junjie
2025-06-04 2462b97ab51eb872b1a873cfd6de0b750123123a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!--  -->
<template>
  <div class="app-wrapper" :class="{ hidcontainer: isCollapse }">
    <sidebar class="sidebar-container" />
    <div class="main-container">
      <nav-tab />
      <!-- <right-panel v-if="showSettings">
        <settings />
      </right-panel> -->
      <div class="main">
        <transition name="fade-transform" mode="out-in">
          <router-view />
        </transition>
      </div>
    </div>
  </div>
</template>
 
<script>
//这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
//例如:import 《组件名称》 from '《组件路径》';
import { NavTab, sidebar } from './components';
import { mapGetters } from 'vuex';
import { getStorage, setStorage } from '@/utils/sessionStorage';
// import sidebar from './components/Sidebar/index'
// import ResizeMixin from './mixin/ResizeHandler';
export default {
  //name放入模板名,方便在其他地方引用
  name: '',
  //import引入的组件需要注入到对象中才能使用
  components: { sidebar, NavTab },
  data() {
    //这里存放数据
    return {};
  },
  //监听属性 类似于data概念
  computed: {
    ...mapGetters(['sidebar']),
    isCollapse() {
      return this.sidebar;
    },
    visitedViews() {
      return this.$store.state.tagsView.visitedViews;
    }
  },
  //生命周期 - 创建完成(可以访问当前this实例)
  created() {},
  //生命周期 - 挂载完成(可以访问DOM元素)
  mounted() {},
  //方法集合
  methods: {},
  //监控data中的数据变化
  watch: {},
  //如果页面有keep-alive缓存功能,这个函数会触发
  activated() {},
  beforeRouteLeave: function (to, from, next) {
    console.log(this.$vnode);
    if (to.name == 'Login' || to.name == 'login') {
      if (this.$vnode && this.$vnode.data.keepAlive) {
        if (this.$vnode.parent && this.$vnode.parent.componentInstance && this.$vnode.parent.componentInstance.cache) {
          if (this.$vnode.componentOptions) {
            var key =
              this.$vnode.key == null
                ? this.$vnode.componentOptions.Ctor.cid +
                  (this.$vnode.componentOptions.tag ? `::${this.$vnode.componentOptions.tag}` : '')
                : this.$vnode.key;
            var cache = this.$vnode.parent.componentInstance.cache;
            var keys = this.$vnode.parent.componentInstance.keys;
            if (cache[key]) {
              if (keys.length) {
                var index = keys.indexOf(key);
                if (index > -1) {
                  keys.splice(index, 1);
                }
              }
              delete cache[key];
            }
          }
        }
      }
      this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => {});
    }
 
    next();
  }
};
</script>
<style lang="scss" scoped>
.app-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  .is-open {
    width: calc(100% - 45px);
  }
  .main {
    width: 98%;
    height: calc(100% - 100px);
    padding: 1%;
    overflow: hidden;
  }
}
</style>