小程序和uni-app 通用的表格样式库

在 小程序和uni-app 中是没有表格组件的。虽然表格并不是移动端设计的推荐布局,但是有些数据表格使用表格会拥有更好的阅读性。
本模板只提供最基础的表格样式,不支持表头固定等其它数据表格的操作(可自行扩展)。
一、源码下载
源码下载地址:https://ext.dcloud.net.cn/plugin?id=3713
在线预览:https://mydarling.gitee.io/uniapp-extend/#/pages/template/table
源码gitee仓库:https://gitee.com/myDarling/uniapp-extend
二、预览图

三、源码
<view class="h-table">
<view class="h-tr h-tr-3 h-thead">
<view class="h-td">主题</view>
<view class="h-td">类名</view>
<view class="h-td">备注</view>
</view>
<view class="h-tr h-tr-3">
<view class="h-td">默认</view>
<view class="h-td">无</view>
<view class="h-td">默认样式</view>
</view>
<view class="h-tr h-tr-3">
<view class="h-td">-</view>
<view class="h-td">-</view>
<view class="h-td">作者河浪</view>
</view>
</view>
.h-table{
/* 行 */
.h-tr{
box-sizing: border-box;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
align-content: center;
border-color: #ccc;
border-style: solid;
border-width: 0;
border-top-width: 1px;
border-left-width: 1px;
border-bottom-width: 1px;
color: #333;
/* 等比分列,1-6列 */
@for $i from 1 through 6
{
&-#{$i}{
>.h-td{
width:(100% / $i);
}
}
}
+ .h-tr{
border-top-style: none;
}
}
/* 单元格 */
.h-td{
box-sizing: border-box;
padding: 3px;
word-break:break-all;
border-color: #ccc;
border-style: solid;
border-width: 0;
border-right-width: 1px;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
align-content: center;
min-height: 64rpx;
/* 跨列 */
&-colspan{
flex-grow: 1;
width:0;
}
/* 内容顶部对齐 */
&-top{
align-items: flex-start;
align-content:flex-start;
}
/* 内容底部对齐 */
&-bottom{
align-items: flex-end;
align-content:flex-end;
}
/* 内容左边对齐 */
&-left{
justify-content: flex-start;
}
/* 内容右边对齐 */
&-right{
justify-content: flex-end;
}
}
/* 表头 */
.h-thead{
background-color: #e6e6e6;
}
/* 表格虚线 */
&-dashed{
.h-tr{
border-top-style: dashed;
border-left-style: dashed;
border-bottom-style: dashed;
}
.h-td{
border-right-style: dashed;
}
}
/* 表格主题 Map,颜色摘自 Bootstrap */
$theme-table:(
primary:(
color:#fff,
bgColor:#337ab7,
border:#2e6da4
),
success:(
color:#fff,
bgColor:#5cb85c,
border:#4cae4c
),
info:(
color:#fff,
bgColor:#5bc0de,
border:#46b8da
),
warning:(
color:#fff,
bgColor:#f0ad4e,
border:#eea236
),
danger:(
color:#fff,
bgColor:#d9534f,
border:#d43f3a
)
);
/* 生成主题代码 */
$theme-table-keys:map-keys($theme-table);
@each $k in $theme-table-keys {
$item:map-get($theme-table,$k);
&-#{$k}{
.h-tr{
border-top-color: map-get($item,border);
border-left-color: map-get($item,border);
border-bottom-color: map-get($item,border);
color: map-get($item,bgColor);
}
.h-td{
border-right-color: map-get($item,border);
}
.h-thead{
background-color: map-get($item,bgColor);
color: map-get($item,color);
}
}
}
}