mali-applet-ui 0.0.10 → 0.0.11
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.
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ml-table" :style="{height}">
|
|
3
|
+
<view class="table-header">
|
|
4
|
+
<view class="table-column-header">
|
|
5
|
+
<view class="table-tr">
|
|
6
|
+
<view v-for="(column, columnIndex) in tableColumn" :key="columnIndex" class="table-th" :style="{width: column.width || '30vw'}" @click="chickThEvent({ column, columnIndex })">
|
|
7
|
+
<view class="th-title">{{column.title}}</view>
|
|
8
|
+
<view class="th-sort" v-if="column.sortable">
|
|
9
|
+
<view class="asc-btn" :class="{active: column.order === 'asc'}" @click.stop="sortEvent({column, columnIndex}, 'asc')">
|
|
10
|
+
<ml-icon name="arrow-up-filling"></ml-icon>
|
|
11
|
+
</view>
|
|
12
|
+
<view class="desc-btn" :class="{active: column.order === 'desc'}" @click.stop="sortEvent({column, columnIndex}, 'desc')">
|
|
13
|
+
<ml-icon name="arrow-down-filling"></ml-icon>
|
|
14
|
+
</view>
|
|
15
|
+
</view>
|
|
16
|
+
</view>
|
|
17
|
+
</view>
|
|
18
|
+
</view>
|
|
19
|
+
<view v-if="headerData && headerData.length" class="table-body-top">
|
|
20
|
+
<view class="table-tr" v-for="(row, rowIndex) in headerData" :key="rowIndex">
|
|
21
|
+
<view class="table-td" v-for="(column, columnIndex) in tableColumn" :key="columnIndex" :style="{width: column.width || '30vw'}" @click="cellHeaderTdClick({ type: 'header', row, rowIndex, column, columnIndex })">
|
|
22
|
+
<view :class="['table-cell', column.align ? `align-${column.align}` : '', getHeaderCellClass({ type: 'header', row, rowIndex, column, columnIndex })]">
|
|
23
|
+
<ml-amount-text v-if="column.cellRender && column.cellRender.name === 'MlAmountText'" :value="row[column.field]" :simplify="column.cellRender.props ? column.cellRender.props.simplify : false"></ml-amount-text>
|
|
24
|
+
<text v-else>{{ getHeaderCellValue({ type: 'header', row, rowIndex, column, columnIndex }) }}</text>
|
|
25
|
+
</view>
|
|
26
|
+
</view>
|
|
27
|
+
</view>
|
|
28
|
+
</view>
|
|
29
|
+
</view>
|
|
30
|
+
<view class="table-body-contnet">
|
|
31
|
+
<view class="table-tr" v-for="(row, rowIndex) in tableData" :key="rowIndex">
|
|
32
|
+
<view class="table-td" v-for="(column, columnIndex) in tableColumn" :key="columnIndex" :style="{width: column.width || '30vw'}" @click="cellTdClick({ type: 'body', row, rowIndex, column, columnIndex })">
|
|
33
|
+
<view :class="['table-cell', column.align ? `align-${column.align}` : '', getCellClass({ type: 'body', row, rowIndex, column, columnIndex })]">
|
|
34
|
+
<text v-if="column.type === 'seq'">{{ rowIndex + 1 }}</text>
|
|
35
|
+
<text v-else-if="column.cellRender && column.cellRender.name === 'Underline'" class="underline">{{ getCellValue({ type: 'body', row, rowIndex, column, columnIndex }) }}</text>
|
|
36
|
+
<ml-amount-text v-else-if="column.cellRender && column.cellRender.name === 'MlAmountText'" :value="row[column.field]" :simplify="column.cellRender.props ? column.cellRender.props.simplify : false"></ml-amount-text>
|
|
37
|
+
<ml-progress-bar
|
|
38
|
+
v-else-if="column.cellRender && column.cellRender.name === 'MlProgressBar'"
|
|
39
|
+
:value="row[column.cellRender.field || column.field]"
|
|
40
|
+
:title="row[column.cellRender.titleField] || ''"
|
|
41
|
+
:titleUnderline="column.cellRender.props ? column.cellRender.props.titleUnderline : false"
|
|
42
|
+
:showNum="column.cellRender.props ? column.cellRender.props.showNum : false"
|
|
43
|
+
:activeColor="barActiveColor ? barActiveColor({ type: 'body', row, rowIndex, column, columnIndex }) : column.cellRender.props ? column.cellRender.props.activeColor : ''"
|
|
44
|
+
:backgroundColor="column.cellRender.props ? column.cellRender.props.backgroundColor : ''">
|
|
45
|
+
</ml-progress-bar>
|
|
46
|
+
<ml-progress-bar
|
|
47
|
+
v-else-if="column.cellRender && column.cellRender.name === 'MlProgressDiffBar'"
|
|
48
|
+
:value="row[column.cellRender.field || column.field]"
|
|
49
|
+
:title="row[column.cellRender.titleField] || ''"
|
|
50
|
+
:max="row[column.cellRender.maxField] || ''"
|
|
51
|
+
:titleUnderline="column.cellRender.props ? column.cellRender.props.titleUnderline : false"
|
|
52
|
+
:showNum="column.cellRender.props ? column.cellRender.props.showNum : false"
|
|
53
|
+
:activeColor="barActiveColor ? barActiveColor({ type: 'body', row, rowIndex, column, columnIndex }) : column.cellRender.props ? column.cellRender.props.activeColor : ''"
|
|
54
|
+
:backgroundColor="column.cellRender.props ? column.cellRender.props.backgroundColor : ''">
|
|
55
|
+
</ml-progress-bar>
|
|
56
|
+
<text v-else>{{ getCellValue({ type: 'body', row, rowIndex, column, columnIndex }) }}</text>
|
|
57
|
+
</view>
|
|
58
|
+
</view>
|
|
59
|
+
</view>
|
|
60
|
+
</view>
|
|
61
|
+
</view>
|
|
62
|
+
</template>
|
|
63
|
+
|
|
64
|
+
<script>
|
|
65
|
+
import XEUtils from 'xe-utils'
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* columns: [{ title, field, width: '20%' }]
|
|
69
|
+
*/
|
|
70
|
+
export default {
|
|
71
|
+
name: 'ml-table',
|
|
72
|
+
props: {
|
|
73
|
+
loading: Boolean,
|
|
74
|
+
height: String,
|
|
75
|
+
headerData: Array,
|
|
76
|
+
data: Array,
|
|
77
|
+
columns: Array,
|
|
78
|
+
showMore: Boolean,
|
|
79
|
+
loadStatus: String,
|
|
80
|
+
sortConfig: Object,
|
|
81
|
+
headerCellClass: [String, Function],
|
|
82
|
+
headerCellFormat: Function,
|
|
83
|
+
cellClass: [String, Function],
|
|
84
|
+
cellFormat: Function,
|
|
85
|
+
// 仅用于MlProgressBar参数
|
|
86
|
+
barActiveColor: Function
|
|
87
|
+
},
|
|
88
|
+
data () {
|
|
89
|
+
return {
|
|
90
|
+
tableColumn: [],
|
|
91
|
+
tableData: []
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
computed: {
|
|
95
|
+
sortOpts () {
|
|
96
|
+
return this.sortConfig ? { ...this.sortConfig } : {}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
watch: {
|
|
100
|
+
columns () {
|
|
101
|
+
this.updateColumn()
|
|
102
|
+
},
|
|
103
|
+
data () {
|
|
104
|
+
this.updateData()
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
created () {
|
|
108
|
+
this.updateColumn()
|
|
109
|
+
this.updateData()
|
|
110
|
+
},
|
|
111
|
+
methods: {
|
|
112
|
+
updateData () {
|
|
113
|
+
this.tableData = this.data ? this.data.slice(0) : []
|
|
114
|
+
},
|
|
115
|
+
updateColumn () {
|
|
116
|
+
this.tableColumn = this.columns.map(column => {
|
|
117
|
+
let order = null
|
|
118
|
+
if (this.sortOpts.defaultSort && this.sortOpts.defaultSort.field === column.field) {
|
|
119
|
+
order = this.sortOpts.defaultSort.order
|
|
120
|
+
}
|
|
121
|
+
return { ...column, order, colid: XEUtils.uniqueId('col_') }
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
getHeaderCellClass(params) {
|
|
125
|
+
if (this.headerCellClass) {
|
|
126
|
+
if (XEUtils.isFunction(this.headerCellClass)) {
|
|
127
|
+
return this.headerCellClass(params)
|
|
128
|
+
}
|
|
129
|
+
return `${this.headerCellClass}`
|
|
130
|
+
}
|
|
131
|
+
return ''
|
|
132
|
+
},
|
|
133
|
+
getHeaderCellValue (params) {
|
|
134
|
+
const { row, column } = params
|
|
135
|
+
const cellValue = row[column.field]
|
|
136
|
+
if (this.headerCellFormat) {
|
|
137
|
+
return this.headerCellFormat({ ...params, cellValue })
|
|
138
|
+
}
|
|
139
|
+
return XEUtils.eqNull(cellValue) ? '' : cellValue
|
|
140
|
+
},
|
|
141
|
+
getCellClass(params) {
|
|
142
|
+
if (this.cellClass) {
|
|
143
|
+
if (XEUtils.isFunction(this.cellClass)) {
|
|
144
|
+
return this.cellClass(params)
|
|
145
|
+
}
|
|
146
|
+
return `${this.cellClass}`
|
|
147
|
+
}
|
|
148
|
+
return ''
|
|
149
|
+
},
|
|
150
|
+
getCellValue (params) {
|
|
151
|
+
const { row, column } = params
|
|
152
|
+
const cellValue = row[column.field]
|
|
153
|
+
if (this.cellFormat) {
|
|
154
|
+
return this.cellFormat({ ...params, cellValue })
|
|
155
|
+
}
|
|
156
|
+
return XEUtils.eqNull(cellValue) ? '' : cellValue
|
|
157
|
+
},
|
|
158
|
+
sort (fieldOrColumn, order) {
|
|
159
|
+
const column = fieldOrColumn ? this.tableColumn.find(item => item.colid === fieldOrColumn.colid || item.field === fieldOrColumn) : null
|
|
160
|
+
if (column) {
|
|
161
|
+
const targetOrder = column.order === order ? null : order
|
|
162
|
+
this.tableColumn.forEach(item => {
|
|
163
|
+
item.order = null
|
|
164
|
+
})
|
|
165
|
+
column.order = targetOrder
|
|
166
|
+
if (column.order) {
|
|
167
|
+
this.tableData = XEUtils.orderBy(this.tableData, { field: column.field, order: column.order })
|
|
168
|
+
} else {
|
|
169
|
+
this.tableData = this.data ? this.data.slice(0) : []
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
sortEvent (params, order) {
|
|
174
|
+
const { column } = params
|
|
175
|
+
if (!this.sortOpts.remote) {
|
|
176
|
+
this.sort(column, order)
|
|
177
|
+
}
|
|
178
|
+
this.$emit('sort-change', params)
|
|
179
|
+
},
|
|
180
|
+
chickThEvent (params) {
|
|
181
|
+
const { column } = params
|
|
182
|
+
if (column.sortable) {
|
|
183
|
+
let order
|
|
184
|
+
if (column.order === 'asc') {
|
|
185
|
+
order = 'desc'
|
|
186
|
+
} else if (column.order === 'desc') {
|
|
187
|
+
order = null
|
|
188
|
+
} else {
|
|
189
|
+
order = 'asc'
|
|
190
|
+
}
|
|
191
|
+
this.sort(column, order)
|
|
192
|
+
}
|
|
193
|
+
this.$emit('header-th-click', params)
|
|
194
|
+
},
|
|
195
|
+
cellHeaderTdClick(params) {
|
|
196
|
+
this.$emit('header-cell-click', params)
|
|
197
|
+
},
|
|
198
|
+
cellTdClick(params) {
|
|
199
|
+
this.$emit('cell-click', params)
|
|
200
|
+
},
|
|
201
|
+
cellTdClick(params) {
|
|
202
|
+
this.$emit('cell-click', params)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
</script>
|
|
207
|
+
|
|
208
|
+
<style lang="scss">
|
|
209
|
+
.ml-table {
|
|
210
|
+
margin-top: 20rpx;
|
|
211
|
+
overflow: auto;
|
|
212
|
+
width: 100%;
|
|
213
|
+
font-size: 26rpx;
|
|
214
|
+
box-shadow: 0rpx 0rpx 10rpx -3rpx rgba(0, 0, 0, 0.2);
|
|
215
|
+
|
|
216
|
+
// height: 90vh;
|
|
217
|
+
.table-header {
|
|
218
|
+
position: sticky;
|
|
219
|
+
top: 0;
|
|
220
|
+
z-index: 10;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.table-body-top {
|
|
224
|
+
background: #ffffff;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.table-th {
|
|
228
|
+
display: inline-block;
|
|
229
|
+
height: 80rpx;
|
|
230
|
+
line-height: 80rpx;
|
|
231
|
+
color: #000000;
|
|
232
|
+
text-align: center;
|
|
233
|
+
overflow: hidden;
|
|
234
|
+
text-overflow: ellipsis;
|
|
235
|
+
white-space: nowrap;
|
|
236
|
+
border-radius: 8rpx 8rpx 0 0;
|
|
237
|
+
background: rgba(240, 249, 255, 1);
|
|
238
|
+
border-bottom: 1rpx solid rgba(39, 42, 48, 0.05);
|
|
239
|
+
.th-title {
|
|
240
|
+
overflow: hidden;
|
|
241
|
+
text-overflow: ellipsis;
|
|
242
|
+
white-space: nowrap;
|
|
243
|
+
padding-right: 26rpx;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.table-body {
|
|
248
|
+
// .table-tr:nth-child(even) {
|
|
249
|
+
// background-color: #364775;
|
|
250
|
+
// display: inline-block;
|
|
251
|
+
// color: #FFFFFF;
|
|
252
|
+
// text-align: center;
|
|
253
|
+
// overflow: hidden;
|
|
254
|
+
// text-overflow: ellipsis;
|
|
255
|
+
// white-space: nowrap;
|
|
256
|
+
// }
|
|
257
|
+
// background-color: #999999;
|
|
258
|
+
// box-shadow: 0rpx 0rpx 10rpx -3rpx rgba(0, 0, 0, 0.2);
|
|
259
|
+
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.table-tr {
|
|
263
|
+
display: block;
|
|
264
|
+
white-space: nowrap;
|
|
265
|
+
width: 100%;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.table-th {
|
|
269
|
+
position: relative;
|
|
270
|
+
.th-sort {
|
|
271
|
+
position: absolute;
|
|
272
|
+
top: 50%;
|
|
273
|
+
right: 0;
|
|
274
|
+
transform: translateY(-50%);
|
|
275
|
+
}
|
|
276
|
+
.asc-btn,
|
|
277
|
+
.desc-btn {
|
|
278
|
+
height: 18rpx;
|
|
279
|
+
line-height: 18rpx;
|
|
280
|
+
color: #ddeffe;
|
|
281
|
+
&.active {
|
|
282
|
+
color: #2982ea;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.table-td {
|
|
288
|
+
display: inline-block;
|
|
289
|
+
padding: 22rpx 10rpx;
|
|
290
|
+
text-align: center;
|
|
291
|
+
color: rgba(39, 42, 48, 0.65);
|
|
292
|
+
border-bottom: 1rpx solid rgba(39, 42, 48, 0.05);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.table-cell {
|
|
296
|
+
overflow: hidden;
|
|
297
|
+
text-overflow: ellipsis;
|
|
298
|
+
white-space: nowrap;
|
|
299
|
+
&.align-left {
|
|
300
|
+
text-align: left;
|
|
301
|
+
}
|
|
302
|
+
&.align-right {
|
|
303
|
+
text-align: right;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
.underline {
|
|
307
|
+
text-decoration: underline;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
</style>
|