张卓
2022-09-20 5aead44ba1be31db948dfd8362c2bfcbedbbce29
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<template>
<a-layout class="wrapper">
  <admin-header></admin-header>
  <a-layout>
    <admin-sidebar></admin-sidebar>
    <a-layout>
      <a-layout-content class="content">
        <reuse-tab :list="tabList"
            :pos="$route.name"
            @changePath="handleChangePath"
            @closeTab="handleCloseTab">
        </reuse-tab>
        <!---->
        <router-view></router-view>
 
      </a-layout-content>
      <a-layout-footer style="padding:0px">
        <admin-footer :link-list="linkList" :copyright="copyright" />
      </a-layout-footer>
    </a-layout>
  </a-layout>
</a-layout>
</template>
 
<script  lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
import { State, Mutation, namespace } from 'vuex-class';
// app 模块
const appModule = namespace('app');
// 复用tab模块
const reuseTabModule = namespace('reuseTab');
 
import ReuseTab from '@/components/reusetab/Index.vue';
 
import AdminHeader from './components/AdminHeader.vue';
import AdminSidebar from './components/AdminSidebar.vue';
import AdminFooter from './components/AdminFooter.vue';
 
import * as _ from 'lodash';
 
@Component({
  components: {
    ReuseTab,
    AdminHeader,
    AdminSidebar,
    AdminFooter,
  },
})
export default class MainLayout extends Vue {
 
  // 是否折叠
  @appModule.State('isCollapse')
  private isCollapse!: boolean;
 
  // 复用tab数据源
  @reuseTabModule.State('source')
  private reuseTabSource!: any[];
 
  // 复用tab跳转
  @reuseTabModule.State('to')
  private reuseTabTo!: string;
 
  private copyright: string = '七星瓢虫环境科技(苏州)有限公司 苏ICP备2021045039号';
 
  private linkList: any = [
      // {link: 'https://www.7drlb.com', name: '七星瓢虫首页'},
      // {link: 'https://github.com/vue-alain/vue-alain', icon: 'github'},
      // {link: 'https://ant.design', name: 'Ant Design'},
      // {link: 'https://vuecomponent.github.io/ant-design-vue/docs/vue/introduce-cn/', name: 'Vue Ant Design'},
    ];
 
  // 复用tab列表
  get tabList() {
    _.forEach(this.reuseTabSource, (item: any,index: any) => {
      if ( item.i18n ) {
        item.title = this.$t(item.i18n);
      }
      return item;
    });
    return this.reuseTabSource;
  }
 
  constructor() {
    super();
  }
 
  private mounted() {
  }
 
  /**
   * 点击复用tab标签跳转路由
   */
  private handleChangePath(e: any, route: any) {
    this.$router.push(route.path);
  }
 
  /**
   * 处理关闭路由tab
   */
  private handleCloseTab(e: any, route: any, close: boolean) {
    const activeName = this.$route.name;
    this.reuseTabClose({
      ...route,
      activeName,
    });
  }
 
  /**
   * 关于路由tab
   */
  @reuseTabModule.Action('remove')
  private reuseTabClose(param: any) {
 
  }
 
  /**
   * 监控 路由tab to属性,以便正确调整路由
   */
  @Watch('reuseTabTo')
  private watchReuseTabTo(newVal: string, oldVal: string) {
    if (newVal !== undefined || newVal !== '') {
      this.$router.push(newVal);
    }
  }
 
}
</script>
 
<style lang="less">
.has-ad-rt .content {
    margin-top: 116px;
}
</style>