实现效果
实现表格: 我是直接使用了该插件的样式table表格 - DCloud 插件市场 此插件里有更多的用法
1.首先复制下面这些table的样式到一个文件里 并在app.vue里引入此scss 注意 文件的格式要为scss
page {
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
}
@for $i from 0 through 100 {
.w-#{$i} {
width: $i + '%';
}
.h-#{$i} {
height: $i + '%';
}
.padding-#{$i} {
padding: $i + rpx;
}
.padding-left-#{$i} {
padding-left: $i + rpx;
}
.padding-right-#{$i} {
padding-right: $i + rpx;
}
.padding-top-#{$i} {
padding-top: $i + rpx;
}
.padding-bottom-#{$i} {
padding-bottom: $i + rpx;
}
.margin-#{$i} {
margin: $i + rpx;
}
.margin-left-#{$i} {
margin-left: $i + rpx;
}
.margin-right-#{$i} {
margin-right: $i + rpx;
}
.margin-top-#{$i} {
margin-top: $i + rpx;
}
.margin-bottom-#{$i} {
margin-bottom: $i + rpx;
}
}
.d-table {
display: table;
width: 100%;
vertical-align: middle;
text-align: center;
table-layout: fixed;
font-size: 28rpx;
word-break: break-all;
background-color: white;
border-collapse: collapse;
&.primary {
&.dark {
.d-thead {
background-color: #2b85e4;
}
}
&.disabled {
.d-thead {
background-color: #a0cfff;
}
}
&.light {
.d-thead {
background-color: #ecf5ff;
}
}
.d-thead {
background-color: #2979ff;
color: #fff;
}
}
&.success {
&.dark {
.d-thead {
background-color: #18b566;
}
}
&.disabled {
.d-thead {
background-color: #71d5a1;
}
}
&.light {
.d-thead {
background-color: #dbf1e1;
}
}
.d-thead {
background-color: #19be6b;
color: #fff;
}
}
&.warning {
&.dark {
.d-thead {
background-color: #f29100;
}
}
&.disabled {
.d-thead {
background-color: #fcbd71;
}
}
&.light {
.d-thead {
background-color: #fdf6ec;
}
}
.d-thead {
background-color: #ff9900;
color: #fff;
}
}
&.danger {
&.dark {
.d-thead {
background-color: #dd6161;
}
}
&.disabled {
.d-thead {
background-color: #fab6b6;
}
}
&.light {
.d-thead {
background-color: #fef0f0;
}
}
.d-thead {
background-color: #fa3534;
color: #fff;
}
}
&.info {
&.dark {
.d-thead {
background-color: #82848a;
}
}
&.disabled {
.d-thead {
background-color: #c8c9cc;
}
}
&.light {
.d-thead {
background-color: #f4f4f5;
}
}
.d-thead {
background-color: #909399;
color: #fff;
}
}
&.gray {
.d-thead {
background-color: #aaa;
color: #fff;
}
}
&.border-under {
.d-td,
.d-th {
@extend .noBorder;
}
.d-tr {
@extend .border-bottom;
}
.d-table {
.d-tr {
@extend .noBorder;
}
}
}
&.large {
.d-td,
.d-th {
height: 80rpx;
}
}
&.middle {
.d-td,
.d-th {
height: 60rpx;
}
}
.d-td,
.d-th {
@extend .border;
}
.d-table {
height: 100%;
.d-td,
.d-th {
@extend .noBorder;
}
// .d-tr {
// &:first-child {
// .d-td{
// &.border-bottom {
// border-bottom: none;
// }
// &.border-top {
// border-top: none;
// }
// }
// }
// }
}
input.borderInput {
border: 1px solid #ccc;
border-radius: 6rpx;
width: 80%;
height: 80%;
display: inline-flex;
}
}
.d-caption {
display: table-caption;
background-color: inherit;
}
.d-thead {
display: table-header-group;
font-weight: 600;
}
.d-tbody {
display: table-row-group;
}
.d-tfoot {
display: table-footer-group;
}
.d-tr {
display: table-row;
width: 100%;
}
.d-td,
.d-th {
display: table-cell;
vertical-align: middle;
height: 50rpx;
font-size: 28rpx;
}
.d-th {
font-weight: 600;
}
.border-top {
border-top: 1px solid #efefef !important;
}
.border-left {
border-left: 1px solid #efefef !important;
}
.border-bottom {
border-bottom: 1px solid #efefef !important;
}
.border-right {
border-right: 1px solid #efefef !important;
}
.border {
border: 1px solid #efefef;
}
.noBorder {
border: 0;
}
.flex {
display: flex;
align-items: center;
&-wrap {
flex-wrap: wrap;
}
&-nowrap {
flex-wrap: nowrap;
}
&-direction {
flex-direction: column;
}
}
@each $type in center, space-between, space-around, flex-start, flex-end {
.row-#{$type} {
justify-content: $type;
}
}
@each $type in center, stretch, flex-start, flex-end {
.col-#{$type} {
align-items: $type;
}
}
@each $type in center, left, right {
.text-#{$type} {
text-align: $type!important;
}
}
2.引入之后可以选择直接需要的表格来进行编写
2.1普通表格
<template>
//普通的表格 devList数组是表格data数据 columns数组是表头名
//先循环表格data数组再循环表头名数组 如果data数组下标等于0 就使用表头
<view class="d-table scroll-x">
<!--表头-->
<view class="d-tr right" v-for="(item,i) in devList" :key="i">
<view class="d-th" v-for="(columnsObj,j) in columns" :key="j">
{{columnsObj.title}}
</view>
</view>
<!--表格-->
<view class="d-tr right" v-for="(item,i) in devList" :key="i">
<view class="'d-td'" v-for="(columnsObj,j) in columns" :key="j">
{{item[columnsObj.dataIndex]}}
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
//table表头
columns: [{
title: '进人', //表格标题
dataIndex: 'enterPeople' //当前列渲染的data名
}, {
title: '出人',
dataIndex: 'outPeople'
}, {
title: '入口异常',
dataIndex: 'entranceException'
}],
//表格Data数据
devList:[{
id:1,
enterPeople:'假数据',
outPeople:'假数据',
entranceException:'假数据'
},{
id:1,
enterPeople:'假数据',
outPeople:'假数据',
entranceException:'假数据'
}]
}
}
}
</script>
<style>
.d-table .right>view {
border: 0;
border-bottom: 1px solid #efefef;
}
.d-table .d-th,
.d-table .left>view {
border: 0 !important;
}
</style>
2.2 固定列表格
<template>
//带固定列的表格 devList数组是表格data数据 columns数组是表头名
<view style="display: flex;">
<!--左侧固定列-->
<view class="d-table" style="width: 30%;">
<!--固定列的表头-->
<view class="d-tr left">
<view class='d-th'>{{'设备序列号'}}</view>
</view>
<!--固定列的表格-->
<view class="d-tr left" v-for="(item,i) in devList" :key="i">
<view class="d-td">{{item.devSn}}</view>
</view>
</view>
<!--剩余未固定的列-->
<scroll-view scroll-x class="border-right" style="width: 70%;">
<view class="d-table scroll-x">
<!--表头-->
<view class="d-tr right">
<view style="width:150rpx" class="d-th"
v-for="(columnsObj,j) in columns" :key="j">
{{columnsObj.title}}
</view>
</view>
<!--表格-->
<view class="d-tr right"
v-for="(item,i) in devList" :key="i">
<view style="width:150rpx" class="d-td"
v-for="(columnsObj,j) in columns" :key="j">
{{item[columnsObj.dataIndex]}}
</view>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
export default {
data() {
return {
//table表头
columns: [{
title: '进人', //表格标题
dataIndex: 'enterPeople' //当前列渲染的data名
}, {
title: '出人',
dataIndex: 'outPeople'
}, {
title: '入口异常',
dataIndex: 'entranceException'
}],
//表格Data数据
devList:[{
id:1,
enterPeople:'假数据',
outPeople:'假数据',
entranceException:'假数据'
},{
id:1,
enterPeople:'假数据',
outPeople:'假数据',
entranceException:'假数据'
}]
}
}
}
</script>
<style>
.d-table .right>view {
border: 0;
border-bottom: 1px solid #efefef;
}
.d-table .d-th,
.d-table .left>view {
border: 0 !important;
}
</style>