123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <template>
- <el-table class="custom-table" :show-summary="summary" :class="customClass" stripe :data="data.data" :height="height" style="width: 100%" @cell-click="onClick" @header-click="onHeaderClick" ref="groupTable">
- <template v-for="(col, cIndex) in data.column" :key="col">
- <el-table-column v-if="col.child && col.child.length > 0" :label="col.name" :key="col">
- <el-table-column
- v-for="(sub, sindex) in col.child"
- :key="sub"
- :index="cIndex"
- :class-name="getClassName(cIndex, sindex)"
- :label="sub.name"
- :prop="sub.field"
- :width="sub.width"
- :sortable="sub.sortable"
- :show-overflow-tooltip="!sub.slot"
- :fixed="sub.fixed"
- :align="sub.align ? sub.align : 'center'"
- :resizable="sub.resizable"
- :header-align="'center'"
- >
- <template v-if="sub.slot == true" #default="item">
- <slot :name="sub.field" :column="sub" :row="item.row" :all="item" :data="item.row[item.field]"></slot>
- </template>
- </el-table-column>
- </el-table-column>
- <el-table-column
- v-if="!col.child"
- :label="col.name"
- :prop="col.field"
- :width="col.width"
- :sortable="col.sortable"
- :show-overflow-tooltip="!col.slot"
- :fixed="col.fixed"
- :align="col.align ? col.align : 'center'"
- :resizable="col.resizable"
- :header-align="'center'"
- >
- <template v-if="col.slot == true" #default="item">
- <slot :name="col.field" :column="col" :row="item.row" :all="item" :data="item.row[col.field]"></slot>
- </template>
- </el-table-column>
- </template>
- </el-table>
- <el-pagination class="mg-t-8"
- v-if="pageable" @current-change="handleCurrentChange"
- :current-page="currentPage" :page-size="pageSize" :total="data.total" v-bind="elPaggingProps">
- </el-pagination>
- </template>
- <script>
- export default {
- // 名称
- name: "ComTable",
- // 使用组件
- components: {},
- // 传入参数
- props: {
- /**
- * {
- column: [{
- name: "风机名称",
- child:[{
- field: "name",
- width:'', // 宽度
- click:function(){} // 点击事件
- sortable:fasle,
- slot:false,
- fixed:false,
- align:'center',
- resizable :false,
- }]
- }],
- total:200
- }
- */
- data: Object,
- height: {
- type: String,
- default: "",
- },
- pageSize: {
- type: Number,
- default: 0,
- },
- customClass: {
- type: String,
- default: "",
- },
- elPaggingProps: {
- type: Object,
- default: () => {
- return {
- layout: "total, sizes, prev, pager, next, jumper",
- // "page-sizes": [100, 200, 300, 400],
- };
- },
- },
- isColumnLight: {
- type: Boolean,
- default: true,
- },
- summary: {
- type: Boolean,
- default: false,
- },
- },
- emits: {
- onPagging: null,
- headerClick: null,
- },
- // 数据
- data() {
- return {
- currentPage: 1,
- headerIndex: -1,
- subIndex: -1,
- };
- },
- computed: {
- tableData() {
- let that = this;
- if (this.sortCol == "") {
- return this.data.data;
- } else {
- let data = this.data.data;
- data.sort((a, b) => {
- let rev = 1;
- if (that.sortType == "ASC") rev = 1;
- else if (that.sortType == "DESC") rev = -1;
- if (a[that.sortCol] > b[that.sortCol]) return rev * 1;
- if (a[that.sortCol] < b[that.sortCol]) return rev * -1;
- return 0;
- });
- return data;
- }
- },
- pageable() {
- return this.pageSize != 0;
- },
- pages() {
- if (this.pageable) return parseInt(this.data.total / this.pageSize) + 1;
- else return 0;
- },
- startRow() {
- if (this.pageable) return (this.currentPage - 1) * this.pageSize;
- else return 0;
- },
- endRow() {
- if (this.pageable) return this.currentPage * this.pageSize;
- else return this.data.data.length;
- },
- },
- // 函数
- methods: {
- onClick(row, column, cell, event) {
- if (column.rawColumnKey.click) column.rawColumnKey.click(event, row);
- },
- onHeaderClick(column, event) {
- if (column.level == 2) {
- this.headerIndex = column.index;
- this.subIndex = column.no;
- }
- this.$emit("headerClick", { level: column.level, event: event, col: column.rawColumnKey, data: this.data.data });
- },
- handleCurrentChange(val) {
- this.currentPage = val;
- this.$emit("onPagging", {
- pageIndex: this.currentPage,
- pageSize: this.pageSize,
- start: this.startRow,
- end: this.endRow,
- });
- },
- getClassName(cindex, sindex) {
- if (this.isColumnLight == true && cindex == this.headerIndex && sindex == this.subIndex) return "light";
- return "";
- },
- },
- // 生命周期钩子
- beforeCreate() {
- // 创建前
- },
- created() {
- // 创建后
- },
- beforeMount() {
- // 渲染前
- },
- mounted() {
- // 渲染后
- },
- beforeUpdate() {},
- updated() {},
- };
- </script>
- <style lang="less">
- @titleGray: #9ca5a8;
- @rowGray: #606769;
- @darkBack: #536268;
- .com-table {
- width: 100%;
- border-collapse: collapse;
- thead {
- tr {
- display: table;
- table-layout: fixed;
- width: 100%;
- th {
- background-color: fade(@darkBack, 20%);
- height: 30px;
- line-height: 30px;
- color: @titleGray;
- font-weight: 400;
- font-size: @fontsize-s;
- position: sticky;
- top: 0;
- cursor: pointer;
- &.light,
- &.always-light {
- color: @green;
- }
- }
- }
- }
- tbody {
- display: block;
- tr {
- display: table;
- table-layout: fixed;
- width: 100%;
- &:nth-child(2n) {
- background-color: fade(@rowGray, 20%);
- }
- td {
- padding: 0.556vh 0;
- color: @rowGray;
- text-align: center;
- font-size: @fontsize-s;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- &.light,
- &.always-light {
- color: @green !important;
- }
- &.num {
- font-family: "Bicubik";
- font-weight: 400;
- }
- }
- }
- }
- .el-pagination {
- color: @gray;
- .el-pagination__total {
- color: @gray;
- }
- button {
- &.btn-next,
- &.btn-prev {
- background: center center no-repeat fade(@gray, 20);
- color: @gray-l;
- }
- &:disabled {
- color: @gray-l;
- background-color: fade(@gray, 20);
- cursor: not-allowed;
- }
- }
- .el-pager li {
- color: @gray-l;
- background: fade(@gray, 20);
- &.active {
- color: @green;
- }
- }
- .el-input__inner {
- color: @gray-l;
- background: fade(@gray, 20);
- border: 1px solid fade(@gray, 20);
- }
- }
- }
- </style>
|