sadais-piui 1.2.7-beta58 → 1.2.7-beta59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/pi-table/index.vue +251 -0
- package/config/table.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="table-wrap">
|
|
3
|
+
<view class="table">
|
|
4
|
+
<view class="row">
|
|
5
|
+
<view v-for="(col, idx) in cols" :key="idx" class="head"
|
|
6
|
+
:class="{fixed: !!col.fixed}"
|
|
7
|
+
:style="[col.style, cellStyle, leftMap[idx], rightMap[idx]]">
|
|
8
|
+
{{ col.name }}
|
|
9
|
+
</view>
|
|
10
|
+
</view>
|
|
11
|
+
<view class="table-body" :data-empty-text="emptyText">
|
|
12
|
+
<block v-if="data.length > 0">
|
|
13
|
+
<view v-for="(row, idx) in data" :key="idx" class="row" :class="{ odd: stripe && idx % 2 > 0 }">
|
|
14
|
+
<view
|
|
15
|
+
v-for="(col, colIdx) in cols"
|
|
16
|
+
:key="colIdx"
|
|
17
|
+
class="cell"
|
|
18
|
+
:class="{fixed: !!col.fixed}"
|
|
19
|
+
:style="[leftMap[colIdx], rightMap[colIdx]]"
|
|
20
|
+
>
|
|
21
|
+
<div class="cell-content-wrap-ph" :style="[{ width: col.style.width, whiteSpace: col.whiteSpace || 'normal' }]">
|
|
22
|
+
<image v-if="col.slot && col.slot.type === 'img'" :src="row[col.prop]" :style="[col.slot.style]" />
|
|
23
|
+
<image v-else-if="col.slot && col.slot.type === 'rank' && idx < col.slot.condition" :src="row[col.prop]" :style="[col.slot.style]" />
|
|
24
|
+
<block v-else>{{ row[col.prop] }}</block>
|
|
25
|
+
</div>
|
|
26
|
+
<div class="cell-content-wrap" :style="[cellContentWrapStyle]">
|
|
27
|
+
<image v-if="col.slot && col.slot.type === 'img'" :src="row[col.prop]" :style="[col.slot.style]" />
|
|
28
|
+
<image v-else-if="col.slot && col.slot.type === 'rank' && idx < col.slot.condition" :src="row[col.prop]" :style="[col.slot.style]" />
|
|
29
|
+
<block v-else>{{ row[col.prop] }}</block>
|
|
30
|
+
</div>
|
|
31
|
+
</view>
|
|
32
|
+
</view>
|
|
33
|
+
</block>
|
|
34
|
+
</view>
|
|
35
|
+
</view>
|
|
36
|
+
</view>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<script>
|
|
40
|
+
import { getConfig } from '../../config'
|
|
41
|
+
const { table: tableConfig } = getConfig()
|
|
42
|
+
export default {
|
|
43
|
+
name: 'PiTable',
|
|
44
|
+
props: {
|
|
45
|
+
// 列配置项
|
|
46
|
+
columns: {
|
|
47
|
+
type: Array,
|
|
48
|
+
// `[]`
|
|
49
|
+
default: () => tableConfig.columns
|
|
50
|
+
},
|
|
51
|
+
// 表格数据源
|
|
52
|
+
data: {
|
|
53
|
+
type: Array,
|
|
54
|
+
// `[]`
|
|
55
|
+
default: () => tableConfig.data
|
|
56
|
+
},
|
|
57
|
+
// 无数据提示语
|
|
58
|
+
emptyText: {
|
|
59
|
+
// `'暂无数据'`
|
|
60
|
+
default: tableConfig.emptyText
|
|
61
|
+
},
|
|
62
|
+
// 是否条纹显示
|
|
63
|
+
stripe: {
|
|
64
|
+
// `true`
|
|
65
|
+
default: tableConfig.stripe
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
data() {
|
|
69
|
+
return {
|
|
70
|
+
cellPadding: 16,
|
|
71
|
+
leftMap: {},
|
|
72
|
+
rightMap: {}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
computed: {
|
|
76
|
+
cellStyle() {
|
|
77
|
+
return {
|
|
78
|
+
padding: `${this.cellPadding}rpx`
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
cellContentWrapStyle() {
|
|
82
|
+
return {
|
|
83
|
+
left: `${this.cellPadding}rpx`,
|
|
84
|
+
width: `calc(100% - ${this.cellPadding * 2}rpx)`
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
cols() {
|
|
88
|
+
const list = (this.columns || []).map(i => {
|
|
89
|
+
const t = { ...i }
|
|
90
|
+
const w = (t.width && `${t.width}rpx`) || 'auto'
|
|
91
|
+
t.style = { width: w }
|
|
92
|
+
return t
|
|
93
|
+
})
|
|
94
|
+
return list
|
|
95
|
+
},
|
|
96
|
+
reCompute() {
|
|
97
|
+
return this.cols.length + this.data.length
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
watch: {
|
|
101
|
+
reCompute: {
|
|
102
|
+
immediate: true,
|
|
103
|
+
handler() {
|
|
104
|
+
this.$nextTick(() => {
|
|
105
|
+
this.computeColumnWidth()
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
methods: {
|
|
111
|
+
computeColumnWidth() {
|
|
112
|
+
const query = uni.createSelectorQuery().in(this)
|
|
113
|
+
query
|
|
114
|
+
.selectAll('.head')
|
|
115
|
+
.boundingClientRect()
|
|
116
|
+
.exec(res => {
|
|
117
|
+
const list = res[0] || []
|
|
118
|
+
let left = 0
|
|
119
|
+
const isLeft = i => i.fixed === true || i.fixed === 'left'
|
|
120
|
+
const isRight = i => i.fixed === 'right'
|
|
121
|
+
const leftMap = {}
|
|
122
|
+
for (let i = 0; i < list.length; i++) {
|
|
123
|
+
const col = this.cols[i]
|
|
124
|
+
leftMap[i] = { left: isLeft(col) ? `${left}px` : 'auto' }
|
|
125
|
+
left += isLeft(col) ? list[i].width : 0
|
|
126
|
+
}
|
|
127
|
+
const rightMap = {}
|
|
128
|
+
let right = 0
|
|
129
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
130
|
+
const col = this.cols[i]
|
|
131
|
+
rightMap[i] = { right: isRight(col) ? `${right}px` : 'auto' }
|
|
132
|
+
right += isRight(col) ? list[i].width : 0
|
|
133
|
+
}
|
|
134
|
+
this.leftMap = leftMap
|
|
135
|
+
this.rightMap = rightMap
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
</script>
|
|
141
|
+
|
|
142
|
+
<style lang="scss" scoped>
|
|
143
|
+
.table-wrap {
|
|
144
|
+
position: relative;
|
|
145
|
+
width: 100%;
|
|
146
|
+
overflow: auto hidden;
|
|
147
|
+
}
|
|
148
|
+
.table {
|
|
149
|
+
display: table;
|
|
150
|
+
min-width: 100%;
|
|
151
|
+
background: #ffffff;
|
|
152
|
+
border: none;
|
|
153
|
+
box-sizing: border-box;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
$even-row-color: #f4f8fd;
|
|
157
|
+
.row {
|
|
158
|
+
display: table-row;
|
|
159
|
+
border: none;
|
|
160
|
+
background: #ffffff;
|
|
161
|
+
&.odd {
|
|
162
|
+
background: $even-row-color;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
.head {
|
|
166
|
+
display: table-cell;
|
|
167
|
+
padding: 16rpx;
|
|
168
|
+
background: $even-row-color;
|
|
169
|
+
white-space: nowrap;
|
|
170
|
+
text-align: center;
|
|
171
|
+
font-size: 28rpx;
|
|
172
|
+
color: #333333;
|
|
173
|
+
font-weight: bold;
|
|
174
|
+
border: none;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
$fixed-shadow: 0 0 40rpx rgba(11, 101, 209, 0.2);
|
|
178
|
+
.head.fixed {
|
|
179
|
+
position: sticky;
|
|
180
|
+
left: 0;
|
|
181
|
+
z-index: 1;
|
|
182
|
+
box-shadow: $fixed-shadow;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.cell {
|
|
186
|
+
position: relative;
|
|
187
|
+
display: table-cell;
|
|
188
|
+
padding: 16rpx;
|
|
189
|
+
background: inherit;
|
|
190
|
+
overflow: hidden;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.cell.fixed {
|
|
194
|
+
position: sticky;
|
|
195
|
+
left: 0;
|
|
196
|
+
z-index: 1;
|
|
197
|
+
box-shadow: $fixed-shadow;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.cell-content-wrap-ph {
|
|
201
|
+
opacity: 0;
|
|
202
|
+
white-space: normal;
|
|
203
|
+
word-wrap: break-word;
|
|
204
|
+
overflow: hidden;
|
|
205
|
+
text-align: center;
|
|
206
|
+
font-size: 28rpx;
|
|
207
|
+
line-height: 1.5;
|
|
208
|
+
}
|
|
209
|
+
.cell-content-wrap {
|
|
210
|
+
position: absolute;
|
|
211
|
+
top: 0;
|
|
212
|
+
left: 16rpx;
|
|
213
|
+
width: 100%;
|
|
214
|
+
height: 100%;
|
|
215
|
+
display: flex;
|
|
216
|
+
align-items: center;
|
|
217
|
+
justify-content: center;
|
|
218
|
+
white-space: normal;
|
|
219
|
+
word-wrap: break-word;
|
|
220
|
+
overflow: hidden;
|
|
221
|
+
font-size: 28rpx;
|
|
222
|
+
color: #333333;
|
|
223
|
+
line-height: 1.5;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.table-body {
|
|
227
|
+
position: relative;
|
|
228
|
+
display: table-row-group;
|
|
229
|
+
&:empty {
|
|
230
|
+
&::before {
|
|
231
|
+
display: table-row;
|
|
232
|
+
content: '';
|
|
233
|
+
height: 200rpx;
|
|
234
|
+
width: 100%;
|
|
235
|
+
}
|
|
236
|
+
&::after {
|
|
237
|
+
display: block;
|
|
238
|
+
text-align: center;
|
|
239
|
+
content: attr(data-empty-text);
|
|
240
|
+
font-size: 36rpx;
|
|
241
|
+
color: #888888;
|
|
242
|
+
position: absolute;
|
|
243
|
+
white-space: nowrap;
|
|
244
|
+
top: 50%;
|
|
245
|
+
left: 50%;
|
|
246
|
+
transform: translate(-50%, -50%);
|
|
247
|
+
margin-top: 20rpx;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
</style>
|
package/config/table.js
ADDED