z-table-mini
v1.2.0
Published
vue2.0 table 自适应宽度,自适应高度、固定高度、左右列可固定、多级头部、合并表格、Loading、滚动加载、表尾统计、无内置样式、精简高效;
Downloads
18
Readme
VUE2.0 Table组件
自适应宽度 自适应高度、固定高度 左右列可固定 多级头部 合并表格 三个大小(medium / small / mini 样式由外部定义) 无内置样式,精简高效;
全局引入
1、安装 yarn add z-table-mini 或 npm install [email protected] --save
2、引入 import ZTable from 'z-table-mini'; Vue.use(ZTable);
3、使用
<z-table :data="tableData" border stripe>
<z-column type="selection" fixed width="55"></z-column>
<z-column prop="date" label="日期" min-width="150" align="right"></z-column>
<z-column></z-column>
<z-column align="center"><template slot-scope="scope">{{ scope.$index }} - {{ scope.row.name }}</template></z-column>
<z-column prop="name" label="姓名" min-width="180"></z-column>
<z-column prop="address" label="地址" min-width="280" show-overflow-tooltip></z-column>
<z-column label="操作" width="180" fixed="right">
<template slot-scope="scope"><a>编辑</a></template>
</z-column>
</z-table>
<script>
export default {
name: "demo",
data() {
return {
tableData: [
{
id: 8,
date: "2023-03-03",
name: "小明",
num: 12,
p: 1.21,
address: "深圳",
tag: "g",
},
{
id: 9,
date: "2023-03-06",
name: "小张",
num: 12,
p: 1.21,
address: "xxx",
tag: "a",
},
],
};
}
};
</script>
<style>
body {
font: 14px/1.5 Microsoft YaHei, Helvetica Neue, Helvetica, Arial, sans-serif;
}
.z--container {
height: calc(100vh - 20px);
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.z--head {
display: flex;
flex-direction: column;
margin-bottom: 20px;
}
.z--main {
flex: 1;
display: flex;
flex-direction: column;
align-items: baseline;
overflow-y: auto;
}
.z--footer {
margin-top: 20px;
display: flex;
flex-direction: column;
}
.z--table {
position: relative;
overflow: hidden;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
width: 100%;
max-width: 100%;
height: 100%;
font-size: 14px;
color: #606266;
}
.z--table thead {
color: #909399;
font-weight: 500;
}
/* 居中对齐 */
.z--table th.is-center,
.z--table td.is-center,
.z--table .is-center .cell {
text-align: center;
}
/* 右对齐 */
.z--table th.is-right,
.z--table td.is-right,
.z--table .is-right .cell {
text-align: right;
}
.z--table td,
.z--table th {
text-align: left;
vertical-align: middle;
padding: 10px;
box-sizing: border-box;
border-bottom: 1px solid #ebeef5;
background-color: #fff;
}
.z--table th {
overflow: hidden;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
color: #909399;
font-weight: 700;
white-space: nowrap;
}
.z--table td div {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.z--table .cell {
position: relative;
white-space: initial;
word-break: break-all;
display: inline-block;
line-height: 1.4;
}
/* 多级表头背景 */
.z--table thead.is-group th {
background: #f5f7fa;
}
.z--table thead.is-group *,
.z--table tbody.is-group * {
white-space: initial;
word-break: break-all;
}
/* 设置 size 尺寸 */
.z--table-medium td,
.z--table-medium th {
padding: 10px;
}
.z--table-small,
.z--table-mini {
font-size: 12px;
}
.z--table-small td,
.z--table-small th {
padding: 8px;
}
.z--table-mini td,
.z--table-mini th {
padding: 3px;
}
/* 设置 size 尺寸 End*/
/* 无数据 */
.z--table-empty-block {
min-height: 60px;
text-align: center;
width: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.z--table-empty-text {
line-height: 60px;
width: 50%;
color: #909399;
}
/* 加上底边线 */
.z--table-border::after,
.z--table::before {
content: "";
position: absolute;
background-color: #ebeef5;
z-index: 11;
}
.z--table-border::after {
top: 0;
right: 0;
width: 1px;
height: 100%;
}
.z--table::before {
left: 0;
bottom: 0;
width: 100%;
height: 1px;
}
/* 为空时加上边线 End*/
/* 无数据 End*/
/* 设置边线border 样式 */
.z--table-border {
border: 1px solid #ebeef5;
border-right: none;
border-bottom: none;
}
.z--table-border td,
.z--table-border th {
border-right: 1px solid #ebeef5;
}
.z--table-border th {
border-bottom: 1px solid #ebeef5;
background-color: #f5f7fa;
}
.z--table-hidden {
visibility: hidden;
}
/* 头 主体 尾 默认100% */
.z--table-body-wrapper {
overflow: auto;
width: 100%;
max-height: 100%;
}
/* fixed */
.z--table-body {
table-layout: fixed;
border-collapse: separate;
width: 100%;
}
.z--table-body thead {
background-color: #fff;
position: sticky;
top: 0;
z-index: 999;
}
.z--table .hidden-columns {
visibility: hidden;
position: absolute;
z-index: -1;
}
/* 设置斑马纹 stripe */
.z--table tr td {
background: #fff;
}
.z--table-striped tr.z--table-row-striped td {
background: #fafafa;
}
/* 固定栏目样式 */
.z--table .z--table-body-wrapper .is-sticky-left {
position: sticky;
left: 0;
z-index: 10;
}
.z--table .z--table-body-wrapper .is-sticky-right {
position: sticky;
right: 0;
z-index: 10;
}
.z--table .z--table-body-wrapper .is-sticky-left{
left: 0;
box-shadow: 2px 0 2px 0 #00000010;
right: initial;
}
.z--table .z--table-body-wrapper .is-sticky-right.is-fixed-right {
left: initial;
right: 0;
box-shadow:-2px 0 2px 0 #00000010;
}
.z--table .z--table-body-wrapper th.is-sticky-left,.z--table .z--table-body-wrapper th.is-sticky-right {
z-index: 9999;
}
.z--table-body-wrapper.is-scrolling-left .is-sticky-left,
.z--table-body-wrapper.is-scrolling-right .is-sticky-right.is-fixed-right {
-webkit-box-shadow: none;
box-shadow: none;
}
/* 固定栏目样式 End*/
/* hover */
.z--table-body tr:hover > td {
background-color: #f5f7fa !important;
}
/* 排序 */
.z--table th.is-sortable {
cursor: pointer;
}
.z--table .caret-wrapper {
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
height: 16px;
width: 24px;
vertical-align: middle;
cursor: pointer;
overflow: initial;
position: relative;
}
.z--table .sort-caret {
width: 0;
height: 0;
border: 5px solid transparent;
position: absolute;
left: 7px;
}
.z--table .sort-caret.ascending {
border-bottom-color: #c0c4cc;
top: -4px;
}
.z--table .sort-caret.descending {
border-top-color: #c0c4cc;
bottom: -2px;
}
.z--table .ascending .sort-caret.ascending {
border-bottom-color: #409eff;
}
.z--table .descending .sort-caret.descending {
border-top-color: #409eff;
}
/* 排序 end */
/* 单选 */
.z--table tr.current-row > td {
background-color: #ecf5ff;
}
/* 拖动宽度时,显示线条 */
.z--table-resize-proxy {
position: absolute;
left: 200px;
top: 0;
bottom: 0;
width: 0;
border-left: 1px solid #ebeef5;
z-index: 10;
}
/* 展开行 */
.z--table .z--icon-right {
width: 0;
height: 0;
border: 5px solid transparent;
position: absolute;
bottom: 0;
}
.z--table .z--icon-right {
border-left-color: #c0c4cc;
}
.z--table td.z--table-expand-column,
.z--table th.z--table-expand-column {
padding: 0;
text-align: center;
}
.z--table-expand-icon {
position: relative;
cursor: pointer;
color: #666;
font-size: 12px;
-webkit-transition: -webkit-transform 0.2s ease-in-out;
transition: -webkit-transform 0.2s ease-in-out;
transition: transform 0.2s ease-in-out;
transition: transform 0.2s ease-in-out, -webkit-transform 0.2s ease-in-out;
height: 20px;
}
.z--table-expand-icon-expanded {
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
.z--table-expand-icon > .z--icon-right {
position: absolute;
left: 50%;
top: 50%;
margin-left: -5px;
margin-top: -5px;
}
.z--table,
.z--table-expanded-cell {
background-color: #fff;
}
.z--table-expanded-cell[class*="cell"] {
padding: 20px 60px;
}
.z--table-expanded-cell:hover {
background-color: transparent !important;
}
/* 展开行 End*/
/* 设置多选时需要 */
.z--table .z-check-box-span {
cursor: pointer;
width: 20px;
height: 20px;
display: flex;
margin: auto;
}
.z--table .z-check-box-span::before {
position: absolute;
width: 18px;
height: 18px;
border: 1px solid #dcdfe6;
border-radius: 2px;
content: "";
top: 2px;
}
.z--table .z-check-box-span.active::after {
position: absolute;
width: 12px;
height: 12px;
content: "";
margin: auto;
left: 4px;
top: 6px;
}
.z--table .z-check-box-span.active::after {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAICAYAAADA+m62AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAAsSAAALEgHS3X78AAAAqUlEQVQY033PoUrDUQCF8d/VobhyQbkPsGdYGZhUGIhlQQxG4dalJYN7kLuyJmi2aV/2DcQwuBiuwSRo+QuGsVPPB+c7wZbEUvtY4ra3BdrDI85xGGKpA9zgruX000G7uMcl3nDcwwOGOMAslhqw6KA1zlpO7yGWOsIz+pjjCFN84KTl9AqhmzrFE/Y7xU+MW06rP+cdaDm94Arf+MLkP7Tp6XUs9WJT9ws1kC07ActjIgAAAABJRU5ErkJggg==)
no-repeat center;
}
/* 多选 End*/
/* 设置:row-class-name="tableRowClassName"时需要;可将表格内容 highlight 显示,方便区分「成功、信息、警告、危险」等内容。 */
.z--table .warning-row td {
background: oldlace !important;
}
.z--table .success-row td {
background: #f0f9eb !important;
}
/* 有 table solt append 时 插入至表格最后一行之后的内容,如果需要对表格的内容进行无限滚动操作,可能需要用到这个 slot。若表格有合计行,该 slot 会位于合计行之上。 */
.z--table-append-wrapper {
overflow: hidden;
padding: 12px;
text-align: center;
}
.z--table-append-gutter {
padding: 12px;
}
/* v-z-loading 需要 */
.z--loading-fade-enter,
.z--loading-fade-leave-active {
opacity: 0;
}
.z--loading-parent--relative {
position: relative !important;
}
/* 全屏显示 v-z-loading.fullscreen="loading" */
.z--loading-mask.is-fullscreen {
position: fixed;
}
/* 锁定屏幕的滚动 v-z-loading.fullscreen.lock="loading" */
.z--loading-parent--hidden {
overflow: hidden !important;
}
.z--loading-mask {
position: absolute;
z-index: 2000;
background-color: rgba(0, 0, 0, 0.1);
margin: 0;
top: 0;
right: 0;
bottom: 0;
left: 0;
-webkit-transition: opacity 0.3s;
transition: opacity 0.3s;
}
.z--loading-wrapper {
position: absolute;
top: 50%;
left: 50%;
text-align: center;
transform: translate(-50%, -100%);
}
.z--loading-text {
color: #0272bd;
margin: 3px 0;
font-size: 14px;
}
.z--loading-dot {
animation: antRotate 1.2s infinite linear;
transform: rotate(45deg);
position: relative;
display: inline-block;
font-size: 50px;
width: 50px;
height: 50px;
box-sizing: border-box;
}
.z--loading-dot i {
width: 26px;
height: 26px;
position: absolute;
display: block;
background-color: #0272bd;
border-radius: 100%;
transform: scale(0.75);
transform-origin: 50% 50%;
opacity: 0.2;
animation: antSpinMove 1s infinite linear alternate;
}
.z--loading-dot i:nth-child(1) {
top: 0;
left: 0;
}
.z--loading-dot i:nth-child(2) {
top: 0;
right: 0;
-webkit-animation-delay: 0.4s;
animation-delay: 0.4s;
}
.z--loading-dot i:nth-child(3) {
right: 0;
bottom: 0;
-webkit-animation-delay: 0.8s;
animation-delay: 0.8s;
}
.z--loading-dot i:nth-child(4) {
bottom: 0;
left: 0;
-webkit-animation-delay: 1.2s;
animation-delay: 1.2s;
}
@keyframes antRotate {
to {
-webkit-transform: rotate(405deg);
transform: rotate(405deg);
}
}
@-webkit-keyframes antRotate {
to {
-webkit-transform: rotate(405deg);
transform: rotate(405deg);
}
}
@keyframes antSpinMove {
to {
opacity: 1;
}
}
@-webkit-keyframes antSpinMove {
to {
opacity: 1;
}
}
</style>