riku
2024-10-24 3d3e7f45086799fdd7a412e2079710a6cdf8dc2b
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
<template>
  <div class="monitor-obj-wrapper">
    <el-affix v-if="affix" :offset="60" target=".monitor-obj-wrapper">
      <div>
        <el-segmented
          :model-value="activeName"
          :options="activeTabs"
          @change="tabChange"
        />
      </div>
    </el-affix>
    <div v-else>
      <el-segmented
        :model-value="activeName"
        :options="activeTabs"
        @change="tabChange"
      />
    </div>
    <el-scrollbar :height="height">
      <el-space wrap>
        <ItemMonitorObj v-for="obj in activeData" :key="obj.movid" :item="obj">
          <template #default="{ item }">
            <slot :item="item">
              <el-button
                v-if="showBtn"
                size="small"
                plain
                :type="btnType"
                @click="itemClick(item)"
                >{{ btnName }}</el-button
              >
            </slot>
          </template>
        </ItemMonitorObj>
      </el-space>
    </el-scrollbar>
  </div>
</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: '移除'
    },
    btnType: {
      type: String,
      default: 'danger'
    },
    // 头部选项是否吸顶
    affix: Boolean,
    height: String
  },
  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>