fuliqi
2024-11-22 2765d6b25f13fb00d4c80a0057e4f1f3d0176c95
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
<template>
  <div class="top-right-btn" :style="style">
    <el-row>
      <el-tooltip v-if="search" class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
        <el-button size="small" circle icon="el-icon-search" @click="toggleSearch"></el-button>
      </el-tooltip>
      <el-tooltip class="item" effect="dark" content="刷新" placement="top">
        <el-button size="small" circle icon="el-icon-refresh" @click="refresh"></el-button>
      </el-tooltip>
      <el-tooltip v-if="columns" class="item" effect="dark" content="显示/隐藏列" placement="top">
        <el-button size="small" circle icon="el-icon-menu" @click="openDrawer"></el-button>
      </el-tooltip>
    </el-row>
 
    <el-drawer v-model="table" title="信息显隐筛选" size="30%" append-to-body>
      <div slot="header">
        <span>信息显隐筛选</span>
      </div>
      <div slot="default">
        <el-table :data="pagedColumns" style="width: 100%; height: 80%">
          <el-table-column prop="index" label="序号" width="80"></el-table-column>
          <el-table-column prop="label" label="数据名称"></el-table-column>
          <el-table-column prop="visible" label="是否显示">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.visible"
                class="ml-2"
                style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
                @change="switchChange(scope.row)"
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="排序">
            <template slot-scope="scope">
              <el-input-number v-model="scope.row.serialNumber" :min="0" style="width: 120px" @change="sortChange(scope.row, $event)"></el-input-number>
            </template>
          </el-table-column>
        </el-table>
 
        <el-pagination
          v-if="total > pageSize"
          :page-size="pageSize"
          :current-page="currentPage"
          :total="total"
          layout="total, prev, pager, next"
          @current-change="handlePageChange"
        ></el-pagination>
      </div>
      <div slot="footer">
        <el-button @click="table = false">取 消</el-button>
        <el-button type="primary" @click="resetSort">重 置</el-button>
      </div>
    </el-drawer>
  </div>
</template>
 
<script>
 
export default {
  data() {
    return {
      table: false,
      currentPage: 1,
      columnRef: null,
    };
  },
  props: {
    showSearch: {
      type: Boolean,
      default: true,
    },
    columns: {
      type: Array,
      default: () => [],
    },
    search: {
      type: Boolean,
      default: false,
    },
    gutter: {
      type: Number,
      default: 10,
    },
  },
  computed: {
    style() {
      return {
        marginRight: this.gutter ? `${this.gutter / 2}px` : '',
      };
    },
    pageSize() {
      return 10;
    },
    total() {
      return this.columns.length;
    },
    pagedColumns() {
      const start = (this.currentPage - 1) * this.pageSize;
      const end = start + this.pageSize;
      return this.columns.slice(start, end);
    },
  },
  methods: {
    toggleSearch() {
      this.$emit('update:showSearch', !this.showSearch);
    },
    refresh() {
      this.$emit('queryTable');
    },
    openDrawer() {
      this.table = true;
    },
    switchChange(row) {
      this.$emit('update:columns', row);
    },
    handlePageChange(page) {
      this.currentPage = page;
    },
    sortChange(row, val) {
      this.$emit('update:sort', { key: row.key, serialNumber: val });
    },
    resetSort() {
      this.$emit('update:resetSort');
    },
  },
  mounted() {
    this.columns.forEach((item, index) => {
      if (item.visible) {
        // 注意:这里假设columnRef应该是一个checkbox组件的引用,
        // 但在Vue 2中,我们可能需要另一种方式来管理checked状态,
        // 因为Vue 2没有ref的自动实例绑定,且这里的columnRef逻辑似乎不完整或错误。
        // 可能需要移除或重写这部分逻辑。
      }
    });
  },
};
</script>
 
<style lang="scss" scoped>
:deep(.el-transfer__button) {
  border-radius: 50%;
  display: block;
  margin-left: 0px;
}
:deep(.el-transfer__button:first-child) {
  margin-bottom: 10px;
}
 
.my-el-transfer {
  text-align: center;
}
.tree-header {
  width: 100%;
  line-height: 24px;
  text-align: center;
}
.show-btn {
  margin-left: 12px;
}
</style>