在 vue-antd-jeecg 或就jeccg-boot 前端管理系统中,通过低代码生成的在线表格,表格的高度是不固定,这就会造成,表头会随着全局滚动条滚动上移。
再说说antd中a-table表格组件,它是通过定义scroll属性来控制横纵向滚动条的,但是低代码生成的表格,它通过@jeecg/antd-online-mini这个插件来根据配置项来构建表格,但是没有指定scroll固定值。
所以,我这边是通过修改OnlineForm.umd.min.js源码里的scroll值,给他一个固定的值,如下
scroll: {x: 1700, y: 600}
为什么给x设置1700呢,因为如果只设置y值,或将x设置为true,会出现错行的现象,这里将x设置成尽可能大的值,防止出现错行现象,这个问题antd官网也有说明。
用法:将OnlineForm.umd.min.js放到src中的一个文件中。在main.js替换掉原来的引用。
require('@/tool/OnlineForm.umd.min')
全局搜索 antd-online-mini,将所有的引用antd-online-mini都替换成上述代码,我的项目只有在src/utils/util.js中动态生成菜单路由的时候有使用。
补充通过css样式,在App.vue中加入以下样式,但是有时候在Chrome浏览器会失效,其他浏览器未曾发现。
.ant-table-scroll > .ant-table-header {
overflow: hidden !important;
margin-bottom: 0px !important;
padding-bottom: 0px !important;
}
body.cgformList {
> div > section.ant-layout {
height: 150%;
}
main.ant-layout-content > div.tab-layout-tabs + div {
height: calc(100% - 76px);
margin: 12px !important;
> div.main {
height: 100%;
> div.ant-card {
> div.ant-card-body {
height: 100%;
display: flex;
flex-direction: column;
> div.table-operator + div {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
> div.ant-table-wrapper {
flex: 1;
.ant-spin-nested-loading > div > .ant-spin {
max-height: initial;
}
> .ant-spin-nested-loading {
height: 100%;
> .ant-spin-container {
height: 100%;
> .ant-table {
max-height: calc(100% - 40px);
border: 1px solid #e8e8e8;
border-radius: 3px;
display: flex;
flex-direction: column;
& .ant-table-content {
height: 100%;
border: 1px solid #e8e8e8;
& .ant-table-body {
min-height: 0;
flex: 1;
> table {
height: 100%;
border: none;
> thead.ant-table-thead {
position: sticky;
top: 0px;
z-index: 2;
border-radius: 0px;
> tr:first-child > th:first-child {
border-top-left-radius: 0px;
}
> tr:first-child > th:last-child {
border-top-right-radius: 0px;
}
}
}
.ant-table-placeholder {
border: none;
td {
border: none;
}
}
}
}
& .ant-table-body {
min-height: 0;
flex: 1;
.ant-table-placeholder {
border: none;
td {
border: none;
}
}
}
}
}
}
}
}
}
}
}
}
}