jinlin
2023-12-18 29fc8705dff6992e8f7278ec05fe2a327ce9e71b
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<template>
  <main  style="display: flex;flex-direction: column;position: relative" >
    <!-- tab展示内容 -->
    <template v-if="$route.meta.isTab">
      <!--<el-dropdown class="aui-content&#45;&#45;tabs-tools">-->
        <!--<i class="el-icon-arrow-down"></i>-->
        <!--<el-dropdown-menu slot="dropdown" :show-timeout="0">-->
          <!--<el-dropdown-item @click.native="tabRemoveHandle($store.state.contentTabsActiveName)">{{-->
            <!--$t('contentTabs.closeCurrent') }}-->
          <!--</el-dropdown-item>-->
          <!--<el-dropdown-item @click.native="tabsCloseOtherHandle()">{{ $t('contentTabs.closeOther') }}</el-dropdown-item>-->
          <!--<el-dropdown-item @click.native="tabsCloseAllHandle()">{{ $t('contentTabs.closeAll') }}</el-dropdown-item>-->
        <!--</el-dropdown-menu>-->
      <!--</el-dropdown>-->
      <el-form :inline="true" style="position:absolute;right:10px; margin-top:3px;z-index:9;overflow: hidden;white-space: nowrap">
        <zt-button class="CloseHandle" type="primary" @click.native="tabsCloseOtherHandle()">{{ $t('contentTabs.closeOther') }}</zt-button>
        <zt-button class="CloseHandle" type="primary" @click.native="tabsCloseAllHandle()">{{ $t('contentTabs.closeAll') }}</zt-button>
      </el-form>
      <el-tabs class="tabNext" v-model="$store.state.contentTabsActiveName" @tab-click="tabSelectedHandle"
               @tab-remove="tabRemoveHandle"
      >
        <el-tab-pane
          v-if="isRouterAlive"
          :lazy="true"
          v-for="item in $store.state.contentTabs.filter(item => item.title!='首页')"
          :key="item.name"
          :name="item.name"
          :label="item.remark || item.title"
          :closable="item.name !== 'home'"
          :class="{ 'is-iframe': tabIsIframe(item.iframeURL) }">
          <template v-if="item.name === 'home'">
            <svg slot="label" class="icon-svg aui-content--tabs-icon-nav" aria-hidden="true">
              <use xlink:href="#icon-home"></use>
            </svg>
          </template>
          <iframe v-if="tabIsIframe(item.iframeURL)" :src="item.iframeURL" width="100%" height="100%" frameborder="0"
                  scrolling="yes"></iframe>
          <keep-alive v-else>
            <router-view :key="key" v-if="item.name === $store.state.contentTabsActiveName"/>
          </keep-alive>
        </el-tab-pane>
      </el-tabs>
    </template>
    <!-- 其他方式, 展示内容 -->
    <template v-else>
      <keep-alive>
        <router-view/>
      </keep-alive>
    </template>
  </main>
</template>
 
<script>
  import {isURL} from '../../../packages/utils/validate'
 
  export default {
    data() {
      return {
        menuConfigs: [],
        products: [],
        isRouterAlive: true
      }
    },
    created() {
      let that = this
      Promise.all([
        this.getConfig(),
        this.getProducts()
      ]).then(() => {
        that.$store.registerModule('product', {
          state: {
            menuConfigs: that.menuConfigs || [],
            products: that.products || []
          },
          getters: {},
          mutations: {},
          actions: {}
        })
      })
 
      console.log(this.$store.state.contentTabs, 'this.$store.state.contentTabs')
    },
    computed: {
      key() {
        return this.$route.name !== undefined? this.$route.name + +new Date(): this.$route + +new Date()
      }
    },
    methods: {
      // tabs, 是否通过iframe展示
      tabIsIframe(url) {
        return isURL(url)
      },
      reload() {
        this.isRouterAlive = false
        this.$nextTick(() => {
          this.isRouterAlive = true
        })
      },
      // tabs, 选中tab
      tabSelectedHandle(tab) {
        tab = this.$store.state.contentTabs.filter(item => item.name === tab.name)[0]
        if (tab && (tab.name === 'miantainHome-home' || 'replaceProblemHome-home')) {
          this.$nextTick(() => {
            this.$router.push({
              'name': tab.name,
              'remark': tab.remark,
              'params': {...tab.params},
              'query': {...tab.query}
            })
          })
          // this.reload()
        } else if (tab && tab.name !== this.$router.history.current.name) {
          this.$nextTick(() => {
            this.$router.push({
              'name': tab.name,
              'remark': tab.remark,
              'params': {...tab.params},
              'query': {...tab.query}
            })
          })
        }
      },
      tabRemoveCurrentHandle(){
        let tabName = this.$route.name
        tabRemoveHandle(tabName)
      },
      // tabs, 删除tab
      tabRemoveHandle(tabName) {
        if (tabName === 'home') {
          return false
        }
        this.$store.state.contentTabs = this.$store.state.contentTabs.filter(item => item.name !== tabName)
        if (this.$store.state.contentTabs.length <= 0) {
          this.$store.state.sidebarMenuActiveName = this.$store.state.contentTabsActiveName = 'home'
          return false
        }
        // 当前选中tab被删除
        if (tabName === this.$store.state.contentTabsActiveName) {
          let tab = this.$store.state.contentTabs[this.$store.state.contentTabs.length - 1]
          this.$router.push({
            name: tab.name,
            params: {...tab.params},
            query: {...tab.query}
          })
        }
      },
      // tabs, 关闭其它
      tabsCloseOtherHandle() {
        this.$store.state.contentTabs = this.$store.state.contentTabs.filter(item => {
          return item.name === 'home' || item.name === this.$store.state.contentTabsActiveName
        })
      },
      // tabs, 关闭全部
      tabsCloseAllHandle() {
        this.$store.state.contentTabs = this.$store.state.contentTabs.filter(item => item.name === 'home')
        this.$router.push({name: 'home'})
      },
      // 获取所有菜单配置
      getConfig() {
        let that = this
        return this.$http.get('/sys/menuConfig/list').then(({data: res}) => {
          that.menuConfigs = res
        }).catch(() => {
        })
      },
      // 获取产品树
      getProducts() {
        return
        let that = this
        return this.$http.get('/product/treeSelect').then(({data: res}) => {
          that.products = res
        }).catch(() => {
        })
      }
    }
  }
</script>
<style>
  /*.hide-tabs.aui-wrapper,*/
  /*.hide-tabs .aui-content {*/
  /*  padding-top: 0;*/
  /*}*/
  /*.hide-tabs .aui-content > .el-tabs > .el-tabs__header,*/
  /*.hide-tabs .aui-content > .aui-content--tabs-tools {*/
  /*  display: none;*/
  /*}*/
  /*.el-tabs__nav.is-top{*/
  /*  transform:translateX(50px) !important;*/
  /*}*/
  /* #tabNext .el-tabs__nav-next{*/
  /*  right: 21% !important;*/
  /*}*/
  .zt .tabNext>.el-tabs__header>.el-tabs__nav-wrap{
    width:80% ;
  }
  .zt .tabNext .el-tabs__nav-wrap.is-scrollable{
    width:80% ;
  }
  #tab-home{
    padding-left: 10px;
  }
</style>