riku
2024-10-15 e38ea524ec4107ed7f8b1d7491a4177632dd3402
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
<template>
  <div>
    <el-segmented :model-value="activeName" :options="activeTabs" @change="tabChange" />
  </div>
  <el-space wrap>
    <ItemMonitorObj v-for="obj in activeData" :key="obj.movid" :item="obj">
      <template #default="{ item }">
        <!-- <slot :item="item"></slot> -->
        <el-button v-if="showBtn" size="small" type="danger" @click="itemClick(item)">{{
          btnName
        }}</el-button>
      </template>
    </ItemMonitorObj>
  </el-space>
</template>
 
<script>
const defaultTabName = '全部';
export default {
  props: {
    data: {
      type: Array,
      default: () => []
    },
    tabName: {
      type: String,
      default: defaultTabName
    },
    tabOptions: Array,
    showData: Array,
    // 是否添加默认的全部选项
    allOption: Boolean,
    showBtn: Boolean,
    btnName: {
      type: String,
      default: '移除'
    }
  },
  emits: ['update:tabName', 'update:showData', 'itemClick'],
  data() {
    return {
      activeName: defaultTabName,
      tabs: []
    };
  },
  computed: {
    activeData() {
      const list = this.data.filter((v) => {
        return this.activeName == defaultTabName || v.sceneType == this.activeName;
        // return this.tabName == defaultTabName || v.sceneType == this.tabName;
      });
      this.$emit('update:showData', list);
      return list;
    },
    activeTabs() {
      if (this.tabOptions) {
        return this.tabOptions;
      } else {
        return this.tabs;
      }
    }
  },
  watch: {
    data: {
      handler(nV, oV) {
        if (nV != oV && nV.length > 0) {
          this.getTabs(nV);
        }
      },
      immediate: true
    },
    tabs: {
      handler(nV, oV) {
        if (nV != oV && nV.length > 0) {
          this.activeName = nV[0];
          this.tabChange(nV[0]);
        }
      },
      immediate: true
    },
    tabName(nV, oV) {
      if (nV != oV) {
        this.activeName = nV;
      }
    }
  },
  methods: {
    getTabs(dataList) {
      const list = [];
      dataList.forEach((d) => {
        if (list.indexOf(d.sceneType) == -1) list.push(d.sceneType);
      });
      this.tabs = list.sort();
    },
    tabChange(tabName) {
      this.activeName = tabName;
      this.$emit('update:tabName', tabName);
    },
    itemClick(item) {
      this.$emit('itemClick', item);
    }
  }
};
</script>
 
<style scoped></style>