1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| <template> <view class="table relative"> <view class="tr"> <view wx:for="{{computedColumns}}" wx:key="index" class="th" wx:style="{{{textAlign:item.align,width:item.width}}}"> {{item.title}} </view> </view> <view wx:if="{{!data.length}}" class="tr placeholder"> <view wx:for="{{computedColumns}}" wx:key="index" class="td"> </view> <view class="placeholder-text">{{placeholder}}</view> </view> <view wx:for="{{data}}" wx:for-index="rowIndex" wx:for-item="row" wx:key="rowIndex" class="tr"> <view wx:for="{{computedColumns}}" wx:key="index" class="td" wx:style="{{{textAlign:item.align,width:item.width}}}"> <slot wx:if="{{item.slot}}" name="col_{{rowIndex}}" /> <block wx:else>{{ data[rowIndex][item.key]}}</block> </view> </view> </view> </template>
<script> import { createComponent } from '@mpxjs/core'
export default createComponent({ options: { styleIsolation: 'apply-shared', multipleSlots: true }, properties: {
columns: { type: Array, value: [] }, data: { type: Array, value: [] }, placeholder: { type: String, value: '暂无数据' } }, computed: { computedColumns() { return this.columns.map(col => { return { ...col, width: typeof col.width === 'number' ? `${col.width}rpx` : col.width } }) } } }) </script>
<script type="application/json" lang="json"> { "component": true } </script>
<style lang="stylus"> @import '~@/assets/styles/variables.styl' .table { display table width 100% border-collapse: collapse; .tr { width: 100%; display table-row } .th, .td { display table-cell padding 20rpx 8rpx width auto vertical-align middle font-size 24rpx color $darkTextColor } .th { color $greyTextColor } .td { border-top 1px solid $dividerColor } .placeholder { .td { height: 72rpx; } } .placeholder-text { position absolute left 50% top 92rpx font-size 24rpx color $placeholderColor transform translateX(-50%) } } </style>
|