fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
<!--
 * @Author: 张嘉彬
 * @Date: 2021-10-13 15:15:36
 * @Description:
-->
<template>
  <div class="menuTabs" :class="$route.path == '/dash/home' ? 'homeCardStyle' : 'cardCurrentStyle2'">
    <el-tabs v-model="editableTabsValue" type="border-card"
             :closable="routerHistory && routerHistory.length > 1" @tab-remove="removeTab"
             @tab-click="clickTab">
      <el-tab-pane v-for="(item) in routerHistory"  :key="item.url" :name="item.url">
          <span slot="label">
            <i v-if="item.url === editableTabsValue" :class="['el-icon-refresh', {'loading': featching}]" @click="refreshList(item)"></i>
            {{item.name || '-'}}
          </span>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
  name: 'MenuTabs',
  props: ['featching'],
  data() {
    return {
      editableTabsValue: ''
    }
  },
  computed: {
    ...mapState(['routerHistory'])
  },
  methods: {
    // 刷新列表
    refreshList(item) {
      this.$emit('refresh-list', item);
    },
    removeTab(val) {
      this.$store.dispatch('removeRoute', val)
      if (this.routerHistory.length === 1) {
        this.$router.push({ path: this.routerHistory[0].url })
      } else if (val === this.$route.path) {
        this.$router.push({ path: this.routerHistory[this.routerHistory.length - 1].url })
      }
    },
    clickTab(val) {
      if (val.name === this.$route.path) return
      this.$router.push({ path: val.name })
    }
  },
  watch: {
    $route: {
      handler: function() {
        this.editableTabsValue = this.$route.path
      },
      immediate: true
    }
  }
}
</script>
<style scoped lang="scss">
.menuTabs {
  margin: 20px 20px 0;
  /deep/ .el-tabs__content {
    display: none;
  }
  .el-tabs__nav-next,
  .el-tabs__nav-prev {
    font-size: 16px !important;
  }
// 刷新旋转动画
@keyframes rotation{
    from {transform: rotate(0deg);}
    to {transform: rotate(360deg);}
}
.el-icon-refresh {
    &:hover {
      color: rgb(221, 46, 46);
      font-weight: bolder;
    }
    &.loading {
     animation: rotation 1s linear infinite;
    }
  }
}
</style>