mkl_power_box/components/screen-table.js

100 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

2024-11-19 00:17:04 +08:00
/**
* 顶部header
*/
Vue.component("screen-table", {
template: `
<div class="quality-table">
<el-table ref="pxjy"
:data="data.data"
style="width: 100%"
:height="height+'px'"
@cell-mouse-enter="MouseEnter"
@cell-mouse-leave="MouseLeave"
class="elTable"
:cell-class-name="tableRowClassName"
@row-click="onRowData">
<el-table-column :label="item.label" :width="item.width" v-for="item in data.label" show-overflow-tooltip>
<template slot-scope="scope">
<div v-if="item.type==''" :style="{'color':item.color}">{{scope.row[item.data]}}</div>
<div v-if="item.type=='img'" style="padding-top: 3px;">
<el-image style="width: 40px; height: 40px" :src="scope.row[item.data]" fit="cover"
:preview-src-list="srcList" @click="onSrcList(scope.row[item.data])"></el-image>
</div>
<div v-if="item.type=='state'">
<div :style="{'color':scope.row[item.type_color]}">{{scope.row[item.data]}}</div>
</div>
</template>
</el-table-column>
</el-table>
</div>
`,
props: {
height:{
type:Number
},
data: {
type: Object,
}
},
data() {
return {
interval: '',
srcList:[]
}
},
mounted() {
this.init()
},
methods: {
init() {
//表格定时器
this.interval = setInterval(this.scroll, 50);
},
onRowData(row){
this.$emit('item',row);
},
onSrcList(src,row){
this.srcList = [src]
},
// 表格隔行变色
tableRowClassName({row, rowIndex}) {
if (rowIndex % 2 === 0) {
return 'warning-row' //这是类名
} else {
return ''
}
},
//左边信息表
scroll() {
let maxHeight = this.$refs.pxjy.$el.querySelectorAll('.el-table__body')[0].offsetHeight;
let clientHeight = this.$refs.pxjy.bodyWrapper.clientHeight;
if (Math.abs(this.$refs.pxjy.bodyWrapper.scrollTop - (maxHeight - clientHeight)) < 5) { //预留5像素误差
this.$refs.pxjy.bodyWrapper.scrollTop = 0;
} else {
this.$refs.pxjy.bodyWrapper.scrollTop += 1;//32是每一行表格的高度每秒滚一行
}
}
,
MouseEnter() {//鼠标移入停止滚动
clearInterval(this.interval);
}
,
MouseLeave() {//鼠标离开继续滚动
this.interval = setInterval(this.scroll, 50);
},
onClickPoint(n) {
this.btnNav = n;
},
},
watch:{
data:function () {
clearInterval(this.interval);
this.init()
},
},
})