| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <template>
- <div class="tabroll-wrap cockpit-tabroll-table">
- <el-table
- :show-header="false"
- v-loading="shujuloading"
- :data="tableData"
- :max-height="maxHeight"
- ref="shujuscroll_Table"
- strip
- style="width: 100%"
- @mouseenter.native="shujuautoScroll(true)"
- @mouseleave.native="shujuautoScroll(false)"
- id="Tabtab"
- >
- <el-table-column
- v-for="(column, index) in columns"
- :key="index"
- :prop="column.prop"
- :label="column.label"
- show-overflow-tooltip
- :width="getColumnWidth(column.prop)"
- :min-width="getColumnMinWidth(column.prop)"
- />
- </el-table>
- </div>
- </template>
- <script>
- import { COCKPIT_TABLE_BODY_HEIGHT } from "./cockpitTableMetrics";
- export default {
- props: {
- tableData: {
- type: Array,
- default: () => [],
- },
- shujuloading: {
- type: Boolean,
- default: false,
- },
- tableTitle: {
- type: String,
- default: "",
- },
- columns: {
- type: Array,
- default: () => [],
- },
- maxHeight: {
- type: Number,
- default: COCKPIT_TABLE_BODY_HEIGHT,
- },
- columnWidths: {
- type: Object,
- default: () => ({}),
- },
- YCcolumnWidths: {
- type: Object,
- default: () => ({}),
- },
- },
- mounted() {
- this.$nextTick(() => this.shujuautoScroll());
- },
- watch: {
- tableData() {
- this.$nextTick(() => {
- this.shujuautoScroll(true);
- this.shujuautoScroll();
- });
- },
- },
- beforeDestroy() {
- this.shujuautoScroll(true);
- },
- methods: {
- shujuautoScroll(stop) {
- if (stop) {
- window.clearInterval(this.scrolltimer);
- this.scrolltimer = null;
- return;
- }
- const table = this.$refs.shujuscroll_Table;
- const divData = table && table.$refs.bodyWrapper;
- if (!divData || !this.tableData || this.tableData.length === 0) {
- return;
- }
- if (divData.scrollHeight <= divData.clientHeight) {
- return;
- }
- window.clearInterval(this.scrolltimer);
- this.scrolltimer = window.setInterval(() => {
- divData.scrollTop += 1;
- if (
- divData.clientHeight + divData.scrollTop >=
- divData.scrollHeight
- ) {
- divData.scrollTop = 0;
- }
- }, 150);
- },
- getColumnWidth(prop) {
- const w =
- this.columnWidths[prop] ?? this.YCcolumnWidths[prop];
- if (w == null || w === "auto") return undefined;
- if (typeof w === "string" && w.endsWith("%")) return undefined;
- if (typeof w === "string") return w;
- return `${w}px`;
- },
- getColumnMinWidth(prop) {
- const w =
- this.columnWidths[prop] ?? this.YCcolumnWidths[prop];
- if (typeof w === "string" && w.endsWith("%")) {
- return w;
- }
- return undefined;
- },
- tableRowClassName({ row, rowIndex }) {
- if (rowIndex % 2 === 1) {
- return "warning-row";
- } else {
- return "success-row";
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .tabroll-wrap {
- width: 100%;
- }
- #Tabtab {
- width: 100% !important;
- font-size: 12px;
- }
- ::v-deep #Tabtab .el-table__body,
- ::v-deep #Tabtab .el-table__body-wrapper table {
- width: 100% !important;
- table-layout: fixed;
- }
- ::v-deep .cockpit-tabroll-table .el-table__body .el-table__cell {
- padding: 0 !important;
- }
- ::v-deep .cockpit-tabroll-table .el-table__body .el-table__cell .cell {
- padding-top: 0 !important;
- padding-bottom: 0 !important;
- padding-left: var(--cockpit-td-padding-x, 8px) !important;
- padding-right: var(--cockpit-td-padding-x, 8px) !important;
- }
- /* 去掉最下面的那一条线 */
- .el-table::before {
- height: 0px;
- }
- /* 自动滚动:隐藏滚动条 */
- ::v-deep .cockpit-tabroll-table .el-table__body-wrapper {
- scrollbar-width: none;
- -ms-overflow-style: none;
- }
- ::v-deep .cockpit-tabroll-table .el-table__body-wrapper::-webkit-scrollbar {
- width: 0 !important;
- height: 0 !important;
- display: none !important;
- }
- </style>
|