hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<template>
  <div>
    <el-table
      ref="multipleTable"
      v-loading="loading"
      class="customTable"
      :data="tableData"
      border
      :stripe="false"
      fit
      highlight-current-row
 
      element-loading-text="拼命加载中"
      element-loading-background="rgba(0, 0, 0, 0.3)"
      @selection-change="handleSelectionChange"
    >
      <!-- 是否需要全选, isshow控制-->
      <el-table-column v-if="checkbox" type="selection" align="center" fixed></el-table-column>
      <!-- prop: 字段名name, label: 展示的名称, fixed: 是否需要固定(left, right), minWidth: 设置列的最小宽度(不传默认值),
        oper: 是否有操作列, oper.name: 操作列字段名称, oper.clickFun: 操作列点击事件, formatData: 格式化内容 -->
      <el-table-column
        type="index"
        label="序号"
        width="50px"
      >
      </el-table-column>
      <el-table-column
        v-for="(th, key) in tableHeader"
        :key="key"
        :prop="th.prop"
        :label="th.label"
        :fixed="th.fixed"
        :width="th.width"
        :min-width="th.minWidth"
        align="left"
      >
        <!-- 加入template主要是有操作一栏, 操作一栏的内容是相同的, 数据不是动态获取的,这里操作一栏的名字定死(oper表示是操作这一列,否则就不是) -->
        <template slot-scope="scope">
          <!-- <div v-if="th.prop === 'custom'"> -->
          <!-- <el-button
            v-for="(o, key2) in th.oper"
            :key="key2"
            :type="o.style"
            :icon="o.icon"
            size="mini"
            @click="o.clickFun(scope.row)"
          >
            {{ o.name }}
          </el-button> -->
          <!-- </div> -->
          <slot v-if="th.slot" :name="th.slot" :scope="scope.row"></slot>
          <span>{{ scope.row[th.prop] }}</span>
        </template>
      </el-table-column>
    </el-table>
 
    <div v-if="paginationDataSource && paginationDataSource.records && paginationDataSource.records.length" class="page">
      <el-pagination
        :current-page="paginationDataSource.current"
        :page-size="paginationDataSource.size"
        :page-sizes="[5, 10, 20, 50, 100]"
        background
        layout="total,prev,pager,next,sizes,jumper"
        :total="paginationDataSource.total"
        @size-change="onPageSizeChange"
        @current-change="onPaginationChange"
      >
      </el-pagination>
    </div>
  </div>
</template>
 
<script>
  export default {
    name: 'Index',
    // 传入的数据
    props: {
      /** 未分页数据 */
      dataSource: { // 表格数据
        type: Array,
        default: function () {
          return []
        }
      },
      /** 带分页控件的数据 */
      paginationDataSource: {
        default: {
          records: []
        }
      },
      tableHeader: { // 表格头部
        type: Array,
        default: function () {
          return []
        }
      },
      tabheight: {
        type: String,
        default: '100%'
      },
      loading: { // 加载等待
        type: Boolean,
        default: false
      },
      checkbox: {
        type: Boolean,
        default: false
      }
    },
    computed: {
      tableData () {
        if (this.paginationDataSource.records) {
          return this.paginationDataSource.records || [];
        }
        return this.dataSource;
      }
    },
    watch: {
      tableData (val) {
        console.log(val)
      }
    },
    methods: {
      // 获取选择行数信息
      getmydata() {
        const data = this.$refs.multipleTable.selection
        const IDS = []
        for (let i = 0; i < data.length; i++) {
          IDS.push(data[i].ID)
        }
        this.$emit('func', IDS)
      },
      handleSelectionChange (list) {
        this.$emit('onSelectionChange', list);
      },
      onPageSizeChange (pageSize) {
        this.$emit('onPageSizeChange', pageSize)
      },
      onPaginationChange (page) {
        this.$emit('onPaginationChange', page);
      }
    }
  }
</script>
 
<style lang="less" >
  /*@import '../../styles/table.less';*/
  .title {
    font-size: 20px;
    height: 40px;
    line-height: 40px;
    color: #333;
    font-weight: 600;
  }
  .brand {
    color: #409EFF;
  }
  .custom-box {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 100%;
    background-color: #fff;
    border-radius: 5px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    padding: 5px;
    z-index: 25;
    overflow: auto;
    .addBtn {
      padding-bottom: 10px;
    }
  }
  .tableBox {
    // width: 100%;
    // height: calc(100vh - 178px);
    // overflow: hidden
  }
  /deep/.el-range-editor--small.el-input__inner {
    // height: 40px;
  }
  /deep/.el-table {
    th {
      padding: 0 !important;
      height: 50px !important;
      text-align: center;
      background-color: rgba(231, 231, 231, 0.2) !important;
      color: #222;
    }
    td{
      padding: 0 !important;
      max-height: 70px !important;
      height: 70px;
      text-align: center;
    }
  }
  /deep/.el-table td.el-table__cell div {
    // text-overflow: -o-ellipsis-lastline;
    // overflow: hidden;
    // text-overflow: ellipsis;
    // display: -webkit-box;
    // -webkit-line-clamp: 2;
    // line-clamp: 2;
    // -webkit-box-orient: vertical;
  }
  /deep/.el-table--scrollable-y {
    .el-table__body-wrapper {
      overflow-y: hidden !important;
    }
  }
  /deep/.el-table__fixed-right {
    right: 0 !important;
  }
  .page {
    text-align: center;
    padding: 20px 0;
  }
</style>