Commit 866c1b33 authored by tyn's avatar tyn

element ui table 固定列 行错位 自带bug修复 => 重新计算dom元素高度 通过css变量重新插入赋值

parent b91b4446
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"author": "若依", "author": "若依",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"dev": "set NODE_OPTIONS=--openssl-legacy-provider & vue-cli-service serve", "dev": "vue-cli-service serve",
"devmac": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve", "devmac": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
"build:prod": "vue-cli-service build", "build:prod": "vue-cli-service build",
"build:test": "vue-cli-service build --mode test", "build:test": "vue-cli-service build --mode test",
......
<template> <template>
<div class="table-list-com-ins" :class="{'is-empty-table' : !tableDataTotal,'no-pagination' : !hasQueryParams,'auto-max-height' : maxHeight}"> <div class="table-list-com-ins" :class="{'is-empty-table' : !tableDataTotal,'no-pagination' : !hasQueryParams,'auto-max-height' : maxHeight}"
:style="maxBodyFixedStyle">
<div class="table-item"> <div class="table-item">
<el-table v-if="tableDataTotal>0" class="fixed-table" v-loading="tableLoading" :data="tableData" element-loading-text="Loading" ref="tableRef" <el-table v-if="tableDataTotal>0" class="fixed-table" v-loading="tableLoading" :data="tableData" element-loading-text="Loading"
border fit highlight-current-row :default-sort="defaultSort?defaultSort:{}" @sort-change="sortChange" @selection-change="selectionChange" ref="customTableRef" border fit highlight-current-row :default-sort="defaultSort?defaultSort:{}" @sort-change="sortChange"
:cell-class-name="cellClassName" :cell-style="cellStyle" :row-class-name="rowClassName" :row-style="rowStyle" :height="height" @selection-change="selectionChange" :cell-class-name="cellClassName" :cell-style="cellStyle" :row-class-name="rowClassName"
:maxHeight="comMaxHeight" v-sticky-header="stickyHeader"> :row-style="rowStyle" :height="height" :maxHeight="comMaxHeight" v-sticky-header="stickyHeader">
<el-table-column type="selection" :width="needSelection.width ? needSelection.width : '38px'" v-if="needSelection.flag" <el-table-column type="selection" :width="needSelection.width ? needSelection.width : '38px'" v-if="needSelection.flag"
:fixed="needSelection.fixed" :align="needSelection.align" :show-overflow-tooltip="needSelection.showOverflowTooltip"> :fixed="needSelection.fixed" :align="needSelection.align" :show-overflow-tooltip="needSelection.showOverflowTooltip">
</el-table-column> </el-table-column>
...@@ -138,7 +139,8 @@ export default { ...@@ -138,7 +139,8 @@ export default {
current_page: this.queryParams.pageNum, current_page: this.queryParams.pageNum,
show_page: this.paging, show_page: this.paging,
comMaxHeight: null, comMaxHeight: null,
hasQueryParams: false hasQueryParams: false,
comMaxBodyHeight: 0
}; };
}, },
watch: { watch: {
...@@ -159,6 +161,13 @@ export default { ...@@ -159,6 +161,13 @@ export default {
deep: true deep: true
} }
}, },
computed: {
maxBodyFixedStyle() {
return {
"--body-max-height": `${this.comMaxBodyHeight}px`
};
}
},
created() { created() {
this.maxHeight ? this.maxHeightInit() : null; this.maxHeight ? this.maxHeightInit() : null;
}, },
...@@ -167,19 +176,38 @@ export default { ...@@ -167,19 +176,38 @@ export default {
async maxHeightInit() { async maxHeightInit() {
try { try {
await this.$nextTick(); await this.$nextTick();
if (typeof this.maxHeight == "number") { // 固定数值
this.comMaxHeight = `${this.maxHeight}px`; const isFixedNumber = typeof this.maxHeight == "number";
return; // 最大高度
let containerMaxHeight = null;
if (isFixedNumber) {
containerMaxHeight = this.maxHeight;
} else {
/**
* @type {HTMLDivElement}
*/
const container = this.$el.querySelector(".table-item");
if (container) {
containerMaxHeight = container.offsetHeight;
}
} }
/** // 列表自适应高度
* @type {HTMLDivElement} this.comMaxHeight = containerMaxHeight ? `${containerMaxHeight}px` : null;
*/ // 重新计算表格高度 减去滚动条高度差 16 - 6
const container = this.$el.querySelector(".table-item"); if (containerMaxHeight) {
if (container) { /**
this.comMaxHeight = `${container.offsetHeight}px`; * @type {HTMLDivElement}
*/
const tableRightHeader = this.$el.querySelector(".el-table__fixed-header-wrapper");
if (tableRightHeader) {
const headerHeight = parseInt(window.getComputedStyle(tableRightHeader).height);
//原滚动条高度为6px 差 10px
const bodyMaxHeight = containerMaxHeight - headerHeight - 16;
this.comMaxBodyHeight = bodyMaxHeight;
}
} }
} catch (error) { } catch (error) {
console.log(error);
} }
}, },
pagingHandler(hasQueryParams, queryParams, scope) { pagingHandler(hasQueryParams, queryParams, scope) {
...@@ -235,6 +263,7 @@ export default { ...@@ -235,6 +263,7 @@ export default {
/* maxHeight自适应样式 */ /* maxHeight自适应样式 */
&.auto-max-height { &.auto-max-height {
::v-deep .table-item { ::v-deep .table-item {
// 原滚动条为6px 现在多10px
.el-table { .el-table {
/* 右侧fixed列 */ /* 右侧fixed列 */
.el-table__fixed-right { .el-table__fixed-right {
...@@ -253,6 +282,18 @@ export default { ...@@ -253,6 +282,18 @@ export default {
border-left: unset; border-left: unset;
border-bottom: unset; border-bottom: unset;
} }
// 自动适配下 减去滚动条高度
.el-table__fixed {
height: calc(100% - 15px) !important;
}
.el-table__fixed-right {
height: calc(100% - 15px) !important;
}
// 重新计算隐藏列表高度 减去滚动条16px高度
.el-table__fixed-body-wrapper {
max-height: var(--body-max-height) !important;
}
} }
} }
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<!-- 数据列表部分 --> <!-- 数据列表部分 -->
<div class="project-feedsummary-list-container"> <div class="project-feedsummary-list-container">
<dsk-skeleton v-if="tableLoading"></dsk-skeleton> <dsk-skeleton v-if="tableLoading"></dsk-skeleton>
<custom-table :tableData="tableDataList" :formColum="formColum" v-else-if="!tableLoading" :tableDataTotal="total" <custom-table :tableData="tableDataList" :formColum="formColum" v-else-if="!tableLoading" :max-height="true" :tableDataTotal="total"
:paging="false"> :paging="false">
<template slot="action-field-bar" slot-scope="scope"> <template slot="action-field-bar" slot-scope="scope">
<div class="project-action-field-bar" v-if="scope.row.id != '0'"> <div class="project-action-field-bar" v-if="scope.row.id != '0'">
......
...@@ -193,8 +193,8 @@ export default { ...@@ -193,8 +193,8 @@ export default {
const detail = await getProjectDetailApi(projectId); const detail = await getProjectDetailApi(projectId);
if (detail.code == 200 && detail.data) { if (detail.code == 200 && detail.data) {
if (detail.data.id) detail.data["projectId"] = detail.data.id; if (detail.data.id) detail.data["projectId"] = detail.data.id;
detail.data["projectId"] = "1754425038355890177"; // detail.data["projectId"] = "1754425038355890177";
detail.data["cbStage"] = 0; // detail.data["cbStage"] = 0;
this.detailInfo = detail.data; this.detailInfo = detail.data;
} }
} catch (error) { } catch (error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment