uview-plus 3.4.28 → 3.4.30
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/changelog.md +24 -0
- package/components/u-cate-tab/u-cate-tab.vue +20 -14
- package/components/u-image/u-image.vue +7 -4
- package/components/u-index-list/u-index-list.vue +1 -1
- package/components/u-number-box/u-number-box.vue +4 -3
- package/components/u-pagination/u-pagination.vue +283 -0
- package/components/u-popup/u-popup.vue +1 -0
- package/components/u-table2/u-table2.vue +431 -408
- package/components/u-tag/props.js +5 -0
- package/index.js +3 -1
- package/package.json +1 -1
|
@@ -1,451 +1,474 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{{ col.title }}
|
|
20
|
-
<view v-if="col.sortable">
|
|
21
|
-
{{ getSortIcon(col.key) }}
|
|
22
|
-
</view>
|
|
2
|
+
<view scroll-x class="u-table2" :style="{ height: height ? height + 'px' : 'auto' }">
|
|
3
|
+
<!-- 表头 -->
|
|
4
|
+
<view v-if="showHeader" class="u-table-header" :class="{ 'u-table-sticky': fixedHeader }" :style="{minWidth: scrollWidth}">
|
|
5
|
+
<view class="u-table-row">
|
|
6
|
+
<view v-for="(col, colIndex) in columns" :key="col.key" class="u-table-cell"
|
|
7
|
+
:style="{ width: col.width ? addUnit(col.width) : 'auto', flex: col.width ? 'none' : 1 }" :class="[
|
|
8
|
+
col.align ? 'u-text-' + col.align : '',
|
|
9
|
+
headerCellClassName ? headerCellClassName(col) : '',
|
|
10
|
+
col.fixed === 'left' ? 'u-table-fixed-left' : '',
|
|
11
|
+
col.fixed === 'right' ? 'u-table-fixed-right' : ''
|
|
12
|
+
]" @click="handleHeaderClick(col)">
|
|
13
|
+
{{ col.title }}
|
|
14
|
+
<view v-if="col.sortable">
|
|
15
|
+
{{ getSortIcon(col.key) }}
|
|
16
|
+
</view>
|
|
17
|
+
</view>
|
|
18
|
+
</view>
|
|
23
19
|
</view>
|
|
24
|
-
</view>
|
|
25
|
-
</view>
|
|
26
20
|
|
|
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
|
-
v-for="col in columns"
|
|
81
|
-
:key="col.key"
|
|
82
|
-
class="u-table-cell"
|
|
83
|
-
:style="{ width: col.width ? addUnit(col.width) : 'auto', paddingLeft: '24px', flex: col.width ? 'none' : 1 }"
|
|
84
|
-
>
|
|
85
|
-
<slot :name="col.key" :row="child">
|
|
86
|
-
{{ child[col.key] }}
|
|
21
|
+
<!-- 表体 -->
|
|
22
|
+
<view class="u-table-body" :style="{ minWidth: scrollWidth, maxHeight: maxHeight ? maxHeight + 'px' : 'none' }">
|
|
23
|
+
<template v-if="data && data.length > 0">
|
|
24
|
+
<template v-for="(row, index) in sortedData" :key="row[rowKey] || index">
|
|
25
|
+
<view class="u-table-row" :class="[
|
|
26
|
+
highlightCurrentRow && currentRow === row ? 'u-table-row-highlight' : '',
|
|
27
|
+
rowClassName ? rowClassName(row, index) : '',
|
|
28
|
+
stripe && index % 2 === 1 ? 'u-table-row-zebra' : ''
|
|
29
|
+
]" @click="handleRowClick(row)">
|
|
30
|
+
<view v-for="(col, colIndex) in columns" :key="col.key" class="u-table-cell" :class="[
|
|
31
|
+
col.align ? 'u-text-' + col.align : '',
|
|
32
|
+
cellClassName ? cellClassName(row, col) : '',
|
|
33
|
+
col.fixed === 'left' ? 'u-table-fixed-left' : '',
|
|
34
|
+
col.fixed === 'right' ? 'u-table-fixed-right' : ''
|
|
35
|
+
]" :style="{ width: col.width ? addUnit(col.width) : 'auto', flex: col.width ? 'none' : 1 }">
|
|
36
|
+
<!-- 复选框列 -->
|
|
37
|
+
<view v-if="col.type === 'selection'">
|
|
38
|
+
<checkbox :checked="isSelected(row)" @click.stop="toggleSelect(row)" />
|
|
39
|
+
</view>
|
|
40
|
+
|
|
41
|
+
<!-- 树形结构展开图标 -->
|
|
42
|
+
<view v-else-if="col.type === 'expand'" @click.stop="toggleExpand(row)">
|
|
43
|
+
{{ isExpanded(row) ? '▼' : '▶' }}
|
|
44
|
+
</view>
|
|
45
|
+
|
|
46
|
+
<!-- 默认插槽或文本 -->
|
|
47
|
+
<slot name="cell" :row="row" :col="col">
|
|
48
|
+
<view class="u-table-cell_content">
|
|
49
|
+
{{ row[col.key] }}
|
|
50
|
+
</view>
|
|
51
|
+
</slot>
|
|
52
|
+
</view>
|
|
53
|
+
</view>
|
|
54
|
+
|
|
55
|
+
<!-- 子级渲染 -->
|
|
56
|
+
<template v-if="isExpanded(row) && row[treeProps.children] && row[treeProps.children].length">
|
|
57
|
+
<view v-for="child in row[treeProps.children]" :key="child[rowKey]"
|
|
58
|
+
class="u-table-row u-table-row-child">
|
|
59
|
+
<view v-for="col in columns" :key="col.key" class="u-table-cell"
|
|
60
|
+
:style="{ width: col.width ? addUnit(col.width) : 'auto', paddingLeft: '24px', flex: col.width ? 'none' : 1 }">
|
|
61
|
+
<slot name="cell" :row="child" :col="col">
|
|
62
|
+
<view class="u-table-cell_content">
|
|
63
|
+
{{ child[col.key] }}
|
|
64
|
+
</view>
|
|
65
|
+
</slot>
|
|
66
|
+
</view>
|
|
67
|
+
</view>
|
|
68
|
+
</template>
|
|
69
|
+
</template>
|
|
70
|
+
</template>
|
|
71
|
+
<template v-else>
|
|
72
|
+
<slot name="empty">
|
|
73
|
+
<view class="u-table-empty">{{ emptyText }}</view>
|
|
87
74
|
</slot>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
</template>
|
|
91
|
-
</template>
|
|
92
|
-
</block>
|
|
93
|
-
<block v-else>
|
|
94
|
-
<slot name="empty">
|
|
95
|
-
<view class="u-table-empty">暂无数据</view>
|
|
96
|
-
</slot>
|
|
97
|
-
</block>
|
|
75
|
+
</template>
|
|
76
|
+
</view>
|
|
98
77
|
</view>
|
|
99
|
-
</view>
|
|
100
78
|
</template>
|
|
101
79
|
|
|
102
80
|
<script>
|
|
103
81
|
import { ref, watch, computed } from 'vue'
|
|
104
|
-
import { addUnit } from '../../libs/function/index';
|
|
82
|
+
import { addUnit, sleep } from '../../libs/function/index';
|
|
105
83
|
|
|
106
84
|
export default {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
85
|
+
name: 'u-table2',
|
|
86
|
+
props: {
|
|
87
|
+
data: {
|
|
88
|
+
type: Array,
|
|
89
|
+
required: true,
|
|
90
|
+
default: () => {
|
|
91
|
+
return []
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
columns: {
|
|
95
|
+
type: Array,
|
|
96
|
+
required: true,
|
|
97
|
+
default: () => {
|
|
98
|
+
return []
|
|
99
|
+
},
|
|
100
|
+
validator: cols =>
|
|
101
|
+
cols.every(col =>
|
|
102
|
+
['default', 'selection', 'expand'].includes(col.type || 'default')
|
|
103
|
+
)
|
|
104
|
+
},
|
|
105
|
+
stripe: {
|
|
106
|
+
type: Boolean,
|
|
107
|
+
default: false
|
|
108
|
+
},
|
|
109
|
+
border: {
|
|
110
|
+
type: Boolean,
|
|
111
|
+
default: false
|
|
112
|
+
},
|
|
113
|
+
height: {
|
|
114
|
+
type: [String, Number],
|
|
115
|
+
default: null
|
|
116
|
+
},
|
|
117
|
+
maxHeight: {
|
|
118
|
+
type: [String, Number],
|
|
119
|
+
default: null
|
|
120
|
+
},
|
|
121
|
+
showHeader: {
|
|
122
|
+
type: Boolean,
|
|
123
|
+
default: true
|
|
124
|
+
},
|
|
125
|
+
highlightCurrentRow: {
|
|
126
|
+
type: Boolean,
|
|
127
|
+
default: false
|
|
128
|
+
},
|
|
129
|
+
rowKey: {
|
|
130
|
+
type: String,
|
|
131
|
+
default: 'id'
|
|
132
|
+
},
|
|
133
|
+
currentRowKey: {
|
|
134
|
+
type: [String, Number],
|
|
135
|
+
default: null
|
|
136
|
+
},
|
|
137
|
+
rowStyle: {
|
|
138
|
+
type: Object,
|
|
139
|
+
default: () => ({})
|
|
140
|
+
},
|
|
141
|
+
cellClassName: {
|
|
142
|
+
type: Function,
|
|
143
|
+
default: null
|
|
144
|
+
},
|
|
145
|
+
headerCellClassName: {
|
|
146
|
+
type: Function,
|
|
147
|
+
default: null
|
|
148
|
+
},
|
|
149
|
+
rowClassName: {
|
|
150
|
+
type: Function,
|
|
151
|
+
default: null
|
|
152
|
+
},
|
|
153
|
+
context: {
|
|
154
|
+
type: Object,
|
|
155
|
+
default: null
|
|
156
|
+
},
|
|
157
|
+
showOverflowTooltip: {
|
|
158
|
+
type: Boolean,
|
|
159
|
+
default: false
|
|
160
|
+
},
|
|
161
|
+
lazy: {
|
|
162
|
+
type: Boolean,
|
|
163
|
+
default: false
|
|
164
|
+
},
|
|
165
|
+
load: {
|
|
166
|
+
type: Function,
|
|
167
|
+
default: null
|
|
168
|
+
},
|
|
169
|
+
treeProps: {
|
|
170
|
+
type: Object,
|
|
171
|
+
default: () => ({
|
|
172
|
+
children: 'children',
|
|
173
|
+
hasChildren: 'hasChildren'
|
|
174
|
+
})
|
|
175
|
+
},
|
|
176
|
+
defaultExpandAll: {
|
|
177
|
+
type: Boolean,
|
|
178
|
+
default: false
|
|
179
|
+
},
|
|
180
|
+
expandRowKeys: {
|
|
181
|
+
type: Array,
|
|
182
|
+
default: () => []
|
|
183
|
+
},
|
|
184
|
+
sortOrders: {
|
|
185
|
+
type: Array,
|
|
186
|
+
default: () => ['ascending', 'descending']
|
|
187
|
+
},
|
|
188
|
+
sortable: {
|
|
189
|
+
type: [Boolean, String],
|
|
190
|
+
default: false
|
|
191
|
+
},
|
|
192
|
+
multiSort: {
|
|
193
|
+
type: Boolean,
|
|
194
|
+
default: false
|
|
195
|
+
},
|
|
196
|
+
sortBy: {
|
|
197
|
+
type: String,
|
|
198
|
+
default: null
|
|
199
|
+
},
|
|
200
|
+
sortMethod: {
|
|
201
|
+
type: Function,
|
|
202
|
+
default: null
|
|
203
|
+
},
|
|
204
|
+
filters: {
|
|
205
|
+
type: Object,
|
|
206
|
+
default: () => ({})
|
|
207
|
+
},
|
|
208
|
+
fixedHeader: {
|
|
209
|
+
type: Boolean,
|
|
210
|
+
default: true
|
|
211
|
+
},
|
|
212
|
+
emptyText: {
|
|
213
|
+
type: String,
|
|
214
|
+
default: '暂无数据'
|
|
215
|
+
},
|
|
174
216
|
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
default: null
|
|
186
|
-
},
|
|
187
|
-
treeProps: {
|
|
188
|
-
type: Object,
|
|
189
|
-
default: () => ({
|
|
190
|
-
children: 'children',
|
|
191
|
-
hasChildren: 'hasChildren'
|
|
192
|
-
})
|
|
193
|
-
},
|
|
194
|
-
defaultExpandAll: {
|
|
195
|
-
type: Boolean,
|
|
196
|
-
default: false
|
|
197
|
-
},
|
|
198
|
-
expandRowKeys: {
|
|
199
|
-
type: Array,
|
|
200
|
-
default: () => []
|
|
201
|
-
},
|
|
202
|
-
sortOrders: {
|
|
203
|
-
type: Array,
|
|
204
|
-
default: () => ['ascending', 'descending']
|
|
205
|
-
},
|
|
206
|
-
sortable: {
|
|
207
|
-
type: [Boolean, String],
|
|
208
|
-
default: false
|
|
209
|
-
},
|
|
210
|
-
multiSort: {
|
|
211
|
-
type: Boolean,
|
|
212
|
-
default: false
|
|
213
|
-
},
|
|
214
|
-
sortBy: {
|
|
215
|
-
type: String,
|
|
216
|
-
default: null
|
|
217
|
+
emits: [
|
|
218
|
+
'select', 'select-all', 'selection-change',
|
|
219
|
+
'cell-click', 'row-click', 'row-dblclick',
|
|
220
|
+
'header-click', 'sort-change', 'filter-change',
|
|
221
|
+
'current-change', 'expand-change'
|
|
222
|
+
],
|
|
223
|
+
data() {
|
|
224
|
+
return {
|
|
225
|
+
scrollWidth: 'auto'
|
|
226
|
+
}
|
|
217
227
|
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
default: null
|
|
228
|
+
mounted() {
|
|
229
|
+
this.getComponentWidth()
|
|
221
230
|
},
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
231
|
+
methods: {
|
|
232
|
+
addUnit,
|
|
233
|
+
// 获取组件的宽度
|
|
234
|
+
async getComponentWidth() {
|
|
235
|
+
// 延时一定时间,以获取dom尺寸
|
|
236
|
+
await sleep(30)
|
|
237
|
+
this.$uGetRect('.u-table-row').then(size => {
|
|
238
|
+
this.scrollWidth = size.width + 'px'
|
|
239
|
+
})
|
|
240
|
+
},
|
|
225
241
|
},
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
currentRow.value = found;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
// 过滤后的数据
|
|
266
|
-
const filteredData = computed(() => {
|
|
267
|
-
return props.data.filter(row => {
|
|
268
|
-
return Object.keys(props.filters).every(key => {
|
|
269
|
-
const filter = props.filters[key];
|
|
270
|
-
if (!filter) return true;
|
|
271
|
-
return row[key]?.toString().includes(filter.toString());
|
|
242
|
+
setup(props, { emit }) {
|
|
243
|
+
const expandedKeys = ref([...props.expandRowKeys]);
|
|
244
|
+
const selectedRows = ref([]);
|
|
245
|
+
const sortConditions = ref([]);
|
|
246
|
+
|
|
247
|
+
// 当前高亮行
|
|
248
|
+
const currentRow = ref(null);
|
|
249
|
+
|
|
250
|
+
watch(
|
|
251
|
+
() => props.expandRowKeys,
|
|
252
|
+
newVal => {
|
|
253
|
+
expandedKeys.value = [...newVal];
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
watch(
|
|
258
|
+
() => props.currentRowKey,
|
|
259
|
+
newVal => {
|
|
260
|
+
const found = props.data.find(item => item[props.rowKey] === newVal);
|
|
261
|
+
if (found) {
|
|
262
|
+
currentRow.value = found;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
// 过滤后的数据
|
|
268
|
+
const filteredData = computed(() => {
|
|
269
|
+
return props.data.filter(row => {
|
|
270
|
+
return Object.keys(props.filters).every(key => {
|
|
271
|
+
const filter = props.filters[key];
|
|
272
|
+
if (!filter) return true;
|
|
273
|
+
return row[key]?.toString().includes(filter.toString());
|
|
274
|
+
});
|
|
275
|
+
});
|
|
272
276
|
});
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
277
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
278
|
+
// 排序后的数据
|
|
279
|
+
const sortedData = computed(() => {
|
|
280
|
+
if (!sortConditions.value.length) return filteredData.value;
|
|
279
281
|
|
|
280
|
-
|
|
282
|
+
const data = [...filteredData.value];
|
|
281
283
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
284
|
+
return data.sort((a, b) => {
|
|
285
|
+
for (const condition of sortConditions.value) {
|
|
286
|
+
const { field, order } = condition;
|
|
287
|
+
let valA = a[field];
|
|
288
|
+
let valB = b[field];
|
|
287
289
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
290
|
+
if (props.sortMethod) {
|
|
291
|
+
const result = props.sortMethod(a, b, field);
|
|
292
|
+
if (result !== 0) return result * (order === 'ascending' ? 1 : -1);
|
|
293
|
+
}
|
|
292
294
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
if (valA < valB) return order === 'ascending' ? -1 : 1;
|
|
296
|
+
if (valA > valB) return order === 'ascending' ? 1 : -1;
|
|
297
|
+
}
|
|
298
|
+
return 0;
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
function handleRowClick(row) {
|
|
303
|
+
if (props.highlightCurrentRow) {
|
|
304
|
+
const oldRow = currentRow.value;
|
|
305
|
+
currentRow.value = row;
|
|
306
|
+
emit('current-change', row, oldRow);
|
|
307
|
+
}
|
|
308
|
+
emit('row-click', row);
|
|
295
309
|
}
|
|
296
|
-
return 0;
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
function handleRowClick(row) {
|
|
301
|
-
if (props.highlightCurrentRow) {
|
|
302
|
-
const oldRow = currentRow.value;
|
|
303
|
-
currentRow.value = row;
|
|
304
|
-
emit('current-change', row, oldRow);
|
|
305
|
-
}
|
|
306
|
-
emit('row-click', row);
|
|
307
|
-
}
|
|
308
310
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
+
function handleHeaderClick(column) {
|
|
312
|
+
if (!column.sortable) return;
|
|
313
|
+
|
|
314
|
+
const index = sortConditions.value.findIndex(c => c.field === column.key);
|
|
315
|
+
let newOrder = 'ascending';
|
|
316
|
+
|
|
317
|
+
if (index >= 0) {
|
|
318
|
+
if (sortConditions.value[index].order === 'ascending') {
|
|
319
|
+
newOrder = 'descending';
|
|
320
|
+
} else {
|
|
321
|
+
sortConditions.value.splice(index, 1);
|
|
322
|
+
emit('sort-change', sortConditions.value);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
311
326
|
|
|
312
|
-
|
|
313
|
-
|
|
327
|
+
if (!props.multiSort) {
|
|
328
|
+
sortConditions.value = [{ field: column.key, order: newOrder }];
|
|
329
|
+
} else {
|
|
330
|
+
if (index >= 0) {
|
|
331
|
+
sortConditions.value[index].order = newOrder;
|
|
332
|
+
} else {
|
|
333
|
+
sortConditions.value.push({ field: column.key, order: newOrder });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
314
336
|
|
|
315
|
-
|
|
316
|
-
if (sortConditions.value[index].order === 'ascending') {
|
|
317
|
-
newOrder = 'descending';
|
|
318
|
-
} else {
|
|
319
|
-
sortConditions.value.splice(index, 1);
|
|
320
|
-
emit('sort-change', sortConditions.value);
|
|
321
|
-
return;
|
|
337
|
+
emit('sort-change', sortConditions.value);
|
|
322
338
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
339
|
+
|
|
340
|
+
function getSortIcon(field) {
|
|
341
|
+
const cond = sortConditions.value.find(c => c.field === field);
|
|
342
|
+
if (!cond) return '';
|
|
343
|
+
return cond.order === 'ascending' ? '↑' : '↓';
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function toggleSelect(row) {
|
|
347
|
+
const index = selectedRows.value.findIndex(r => r[props.rowKey] === row[props.rowKey]);
|
|
348
|
+
if (index >= 0) {
|
|
349
|
+
selectedRows.value.splice(index, 1);
|
|
350
|
+
} else {
|
|
351
|
+
selectedRows.value.push(row);
|
|
352
|
+
}
|
|
353
|
+
emit('selection-change', selectedRows.value);
|
|
354
|
+
emit('select', row);
|
|
332
355
|
}
|
|
333
|
-
}
|
|
334
356
|
|
|
335
|
-
|
|
357
|
+
function isSelected(row) {
|
|
358
|
+
return selectedRows.value.some(r => r[props.rowKey] === row[props.rowKey]);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function toggleExpand(row) {
|
|
362
|
+
const key = row[props.rowKey];
|
|
363
|
+
const index = expandedKeys.value.indexOf(key);
|
|
364
|
+
if (index === -1) {
|
|
365
|
+
expandedKeys.value.push(key);
|
|
366
|
+
} else {
|
|
367
|
+
expandedKeys.value.splice(index, 1);
|
|
368
|
+
}
|
|
369
|
+
emit('expand-change', expandedKeys.value);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function isExpanded(row) {
|
|
373
|
+
return expandedKeys.value.includes(row[props.rowKey]);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return {
|
|
377
|
+
currentRow,
|
|
378
|
+
sortedData,
|
|
379
|
+
expandedKeys,
|
|
380
|
+
selectedRows,
|
|
381
|
+
sortConditions,
|
|
382
|
+
handleRowClick,
|
|
383
|
+
handleHeaderClick,
|
|
384
|
+
getSortIcon,
|
|
385
|
+
toggleSelect,
|
|
386
|
+
isSelected,
|
|
387
|
+
toggleExpand,
|
|
388
|
+
isExpanded
|
|
389
|
+
};
|
|
336
390
|
}
|
|
391
|
+
};
|
|
392
|
+
</script>
|
|
337
393
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
394
|
+
<style lang="scss" scoped>
|
|
395
|
+
.u-table2 {
|
|
396
|
+
width: auto;
|
|
397
|
+
overflow: auto;
|
|
398
|
+
white-space: nowrap;
|
|
399
|
+
|
|
400
|
+
.u-table-header {
|
|
401
|
+
min-width: 100% !important;
|
|
402
|
+
width: fit-content;
|
|
403
|
+
background-color: #f5f7fa;
|
|
342
404
|
}
|
|
343
405
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
selectedRows.value.splice(index, 1);
|
|
348
|
-
} else {
|
|
349
|
-
selectedRows.value.push(row);
|
|
350
|
-
}
|
|
351
|
-
emit('selection-change', selectedRows.value);
|
|
352
|
-
emit('select', row);
|
|
406
|
+
.u-table-body {
|
|
407
|
+
min-width: 100% !important;
|
|
408
|
+
width: fit-content;
|
|
353
409
|
}
|
|
354
410
|
|
|
355
|
-
|
|
356
|
-
|
|
411
|
+
.u-table-sticky {
|
|
412
|
+
position: sticky;
|
|
413
|
+
top: 0;
|
|
414
|
+
z-index: 10;
|
|
357
415
|
}
|
|
358
416
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
expandedKeys.value.splice(index, 1);
|
|
366
|
-
}
|
|
367
|
-
emit('expand-change', expandedKeys.value);
|
|
417
|
+
.u-table-row {
|
|
418
|
+
display: flex;
|
|
419
|
+
flex-direction: row;
|
|
420
|
+
align-items: center;
|
|
421
|
+
border-bottom: 1rpx solid #ebeef5;
|
|
422
|
+
overflow: hidden;
|
|
368
423
|
}
|
|
369
424
|
|
|
370
|
-
|
|
371
|
-
|
|
425
|
+
.u-table-cell {
|
|
426
|
+
flex: 1;
|
|
427
|
+
display: flex;
|
|
428
|
+
flex-direction: row;
|
|
429
|
+
padding: 5px 4px;
|
|
430
|
+
font-size: 14px;
|
|
431
|
+
white-space: nowrap;
|
|
432
|
+
overflow: hidden;
|
|
433
|
+
text-overflow: ellipsis;
|
|
372
434
|
}
|
|
373
435
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
sortConditions,
|
|
380
|
-
handleRowClick,
|
|
381
|
-
handleHeaderClick,
|
|
382
|
-
getSortIcon,
|
|
383
|
-
toggleSelect,
|
|
384
|
-
isSelected,
|
|
385
|
-
toggleExpand,
|
|
386
|
-
isExpanded
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
</script>
|
|
436
|
+
.u-table-fixed-left {
|
|
437
|
+
position: sticky;
|
|
438
|
+
left: 0;
|
|
439
|
+
z-index: 9;
|
|
440
|
+
}
|
|
391
441
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
left: 0;
|
|
424
|
-
z-index: 9;
|
|
425
|
-
}
|
|
426
|
-
.u-table-fixed-right {
|
|
427
|
-
position: sticky;
|
|
428
|
-
right: 0;
|
|
429
|
-
z-index: 9;
|
|
430
|
-
}
|
|
431
|
-
.u-table-row-zebra {
|
|
432
|
-
background-color: #fafafa;
|
|
433
|
-
}
|
|
434
|
-
.u-table-row-highlight {
|
|
435
|
-
background-color: #f5f7fa;
|
|
436
|
-
}
|
|
437
|
-
.u-table-empty {
|
|
438
|
-
text-align: center;
|
|
439
|
-
padding: 20px;
|
|
440
|
-
color: #999;
|
|
441
|
-
}
|
|
442
|
-
.u-text-left {
|
|
443
|
-
text-align: left;
|
|
444
|
-
}
|
|
445
|
-
.u-text-center {
|
|
446
|
-
text-align: center;
|
|
447
|
-
}
|
|
448
|
-
.u-text-right {
|
|
449
|
-
text-align: right;
|
|
442
|
+
.u-table-fixed-right {
|
|
443
|
+
position: sticky;
|
|
444
|
+
right: 0;
|
|
445
|
+
z-index: 9;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.u-table-row-zebra {
|
|
449
|
+
background-color: #fafafa;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
.u-table-row-highlight {
|
|
453
|
+
background-color: #f5f7fa;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
.u-table-empty {
|
|
457
|
+
text-align: center;
|
|
458
|
+
padding: 20px;
|
|
459
|
+
color: #999;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
.u-text-left {
|
|
463
|
+
text-align: left;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
.u-text-center {
|
|
467
|
+
text-align: center;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
.u-text-right {
|
|
471
|
+
text-align: right;
|
|
472
|
+
}
|
|
450
473
|
}
|
|
451
474
|
</style>
|