hy-app 0.5.11 → 0.5.12
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/hy-button/hy-button.vue +289 -275
- package/components/hy-button/index.scss +24 -1
- package/components/hy-button/props.ts +143 -135
- package/components/hy-button/typing.d.ts +35 -30
- package/components/hy-coupon/hy-coupon.vue +183 -172
- package/components/hy-coupon/index.scss +12 -16
- package/components/hy-coupon/props.ts +108 -103
- package/components/hy-form/hy-form.vue +220 -220
- package/components/hy-input/hy-input.vue +333 -333
- package/components/hy-input/index.scss +1 -2
- package/components/hy-input/props.ts +186 -186
- package/components/hy-notice-bar/hy-row-notice.vue +121 -121
- package/components/hy-parse/node/node.vue +619 -422
- package/components/hy-parse/parser.js +1253 -1060
- package/components/hy-table/hy-table.vue +579 -358
- package/components/hy-table/index.scss +134 -159
- package/components/hy-table/props.ts +62 -47
- package/components/hy-table/typing.d.ts +29 -34
- package/components/hy-tabs/hy-tabs.vue +335 -335
- package/components/hy-text/hy-text.vue +237 -237
- package/components/hy-text/props.ts +115 -115
- package/components/hy-textarea/hy-textarea.vue +198 -197
- package/components/hy-textarea/index.scss +2 -3
- package/components/hy-toast/hy-toast.vue +190 -190
- package/libs/css/theme.scss +1 -0
- package/libs/css/vars.scss +2 -2
- package/libs/typing/modules/common.d.ts +139 -139
- package/libs/utils/inside.ts +336 -350
- package/package.json +2 -2
- package/web-types.json +1 -1
|
@@ -1,358 +1,579 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="hy-table" :style="{ height: addUnit(
|
|
3
|
-
<!--
|
|
4
|
-
<view class="hy-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
v-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
class="hy-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<view class="hy-table" :style="{ height: addUnit(containerHeight) }">
|
|
3
|
+
<!-- 列头 -->
|
|
4
|
+
<view class="hy-table__header" v-if="showHeader">
|
|
5
|
+
<scroll-view
|
|
6
|
+
class="hy-table__header--scroll"
|
|
7
|
+
scroll-x
|
|
8
|
+
:scroll-left="scrollLeft"
|
|
9
|
+
:scroll-y="false"
|
|
10
|
+
@scroll="onHeaderScroll"
|
|
11
|
+
>
|
|
12
|
+
<view class="hy-table__header--wrapper" :style="{ width: addUnit(totalWidth) }">
|
|
13
|
+
<!-- 左侧固定列头 -->
|
|
14
|
+
<view
|
|
15
|
+
v-if="leftFixedColumns.length > 0"
|
|
16
|
+
:class="['hy-table__header--wrapper__left', scrollLeft && 'is-shadow']"
|
|
17
|
+
:style="{ width: addUnit(leftFixedWidth), zIndex: 3 }"
|
|
18
|
+
>
|
|
19
|
+
<view
|
|
20
|
+
v-for="(col, colIndex) in leftFixedColumns"
|
|
21
|
+
:key="colIndex"
|
|
22
|
+
class="hy-table__header--wrapper__cell"
|
|
23
|
+
:style="getHeaderCellStyle(col)"
|
|
24
|
+
@tap="handleSort(col)"
|
|
25
|
+
>
|
|
26
|
+
<slot v-if="$slots['left-head']" name="left-head" :col="col">
|
|
27
|
+
<text class="header-text">{{ col.title }}</text>
|
|
28
|
+
</slot>
|
|
29
|
+
<text v-else class="hy-table__header--wrapper__cell--text">{{
|
|
30
|
+
col.title
|
|
31
|
+
}}</text>
|
|
32
|
+
<view
|
|
33
|
+
v-if="col.sortable"
|
|
34
|
+
class="hy-table__header--wrapper__cell--sortable"
|
|
35
|
+
>
|
|
36
|
+
<hy-icon
|
|
37
|
+
:name="IconConfig.ARROW_UP_FILL"
|
|
38
|
+
size="12"
|
|
39
|
+
:custom-class="
|
|
40
|
+
sortField === col.key && sortOrder === 'asc'
|
|
41
|
+
? 'is-active'
|
|
42
|
+
: ''
|
|
43
|
+
"
|
|
44
|
+
@click.stop="handleSort(col, 'asc')"
|
|
45
|
+
></hy-icon>
|
|
46
|
+
|
|
47
|
+
<hy-icon
|
|
48
|
+
:name="IconConfig.ARROW_DOWN_FILL"
|
|
49
|
+
size="12"
|
|
50
|
+
:custom-class="
|
|
51
|
+
sortField === col.key && sortOrder === 'desc'
|
|
52
|
+
? 'is-active'
|
|
53
|
+
: ''
|
|
54
|
+
"
|
|
55
|
+
@click.stop="handleSort(col, 'desc')"
|
|
56
|
+
></hy-icon>
|
|
57
|
+
</view>
|
|
58
|
+
</view>
|
|
59
|
+
</view>
|
|
60
|
+
|
|
61
|
+
<!-- 中间滚动列头 -->
|
|
62
|
+
<view class="hy-table__header--wrapper__center">
|
|
63
|
+
<view
|
|
64
|
+
v-for="(col, colIndex) in scrollColumns"
|
|
65
|
+
:key="colIndex"
|
|
66
|
+
class="hy-table__header--wrapper__cell"
|
|
67
|
+
:style="getHeaderCellStyle(col)"
|
|
68
|
+
@tap="handleSort(col)"
|
|
69
|
+
>
|
|
70
|
+
<slot v-if="$slots.head" name="head" :col="col"></slot>
|
|
71
|
+
<text v-else class="hy-table__header--wrapper__cell--text">{{
|
|
72
|
+
col.title
|
|
73
|
+
}}</text>
|
|
74
|
+
<view
|
|
75
|
+
v-if="col.sortable"
|
|
76
|
+
class="hy-table__header--wrapper__cell--sortable"
|
|
77
|
+
>
|
|
78
|
+
<hy-icon
|
|
79
|
+
:name="IconConfig.ARROW_UP_FILL"
|
|
80
|
+
size="12"
|
|
81
|
+
:custom-class="
|
|
82
|
+
sortField === col.key && sortOrder === 'asc'
|
|
83
|
+
? 'is-active'
|
|
84
|
+
: ''
|
|
85
|
+
"
|
|
86
|
+
@click.stop="handleSort(col, 'asc')"
|
|
87
|
+
></hy-icon>
|
|
88
|
+
|
|
89
|
+
<hy-icon
|
|
90
|
+
:name="IconConfig.ARROW_DOWN_FILL"
|
|
91
|
+
size="12"
|
|
92
|
+
:custom-class="
|
|
93
|
+
sortField === col.key && sortOrder === 'desc'
|
|
94
|
+
? 'is-active'
|
|
95
|
+
: ''
|
|
96
|
+
"
|
|
97
|
+
@click.stop="handleSort(col, 'desc')"
|
|
98
|
+
></hy-icon>
|
|
99
|
+
</view>
|
|
100
|
+
</view>
|
|
101
|
+
</view>
|
|
102
|
+
|
|
103
|
+
<!-- 右侧固定列头 -->
|
|
104
|
+
<view
|
|
105
|
+
v-if="rightFixedColumns.length > 0"
|
|
106
|
+
class="hy-table__header--wrapper__right"
|
|
107
|
+
:style="{ width: addUnit(rightFixedWidth), zIndex: 3 }"
|
|
108
|
+
>
|
|
109
|
+
<view
|
|
110
|
+
v-for="(col, colIndex) in rightFixedColumns"
|
|
111
|
+
:key="colIndex"
|
|
112
|
+
class="hy-table__header--wrapper__cell"
|
|
113
|
+
:style="getHeaderCellStyle(col)"
|
|
114
|
+
@tap="handleSort(col)"
|
|
115
|
+
>
|
|
116
|
+
<slot v-if="$slots['right-head']" name="right-head" :col="col"></slot>
|
|
117
|
+
<text v-else class="hy-table__header--wrapper__cell--text">{{
|
|
118
|
+
col.title
|
|
119
|
+
}}</text>
|
|
120
|
+
<view
|
|
121
|
+
v-if="col.sortable"
|
|
122
|
+
class="hy-table__header--wrapper__cell--sortable"
|
|
123
|
+
>
|
|
124
|
+
<hy-icon
|
|
125
|
+
:name="IconConfig.ARROW_UP_FILL"
|
|
126
|
+
size="12"
|
|
127
|
+
:custom-class="
|
|
128
|
+
sortField === col.key && sortOrder === 'asc'
|
|
129
|
+
? 'is-active'
|
|
130
|
+
: ''
|
|
131
|
+
"
|
|
132
|
+
@click.stop="handleSort(col, 'asc')"
|
|
133
|
+
></hy-icon>
|
|
134
|
+
|
|
135
|
+
<hy-icon
|
|
136
|
+
:name="IconConfig.ARROW_DOWN_FILL"
|
|
137
|
+
size="12"
|
|
138
|
+
:custom-class="
|
|
139
|
+
sortField === col.key && sortOrder === 'desc'
|
|
140
|
+
? 'is-active'
|
|
141
|
+
: ''
|
|
142
|
+
"
|
|
143
|
+
@click.stop="handleSort(col, 'desc')"
|
|
144
|
+
></hy-icon>
|
|
145
|
+
</view>
|
|
146
|
+
</view>
|
|
147
|
+
</view>
|
|
148
|
+
</view>
|
|
149
|
+
</scroll-view>
|
|
150
|
+
</view>
|
|
151
|
+
|
|
152
|
+
<!-- 表格主体 -->
|
|
153
|
+
<view class="hy-table__body">
|
|
154
|
+
<view v-if="loading" class="hy-table__body--loading">
|
|
155
|
+
<hy-loading text="加载中..." mode="circle"></hy-loading>
|
|
156
|
+
</view>
|
|
157
|
+
<view v-if="!data.length" class="hy-table__body--empty">
|
|
158
|
+
<slot v-if="$slots.empty" name="empty"></slot>
|
|
159
|
+
<hy-empty v-else :image-url="emptyUrl" :description="emptyDes"></hy-empty>
|
|
160
|
+
</view>
|
|
161
|
+
<!-- 左侧固定列 -->
|
|
162
|
+
<scroll-view
|
|
163
|
+
v-if="processedData.length"
|
|
164
|
+
:class="['hy-table__body--left', scrollLeft && 'is-shadow']"
|
|
165
|
+
scroll-y
|
|
166
|
+
:scroll-top="scrollTop"
|
|
167
|
+
:style="{ width: addUnit(leftFixedWidth), height: addUnit(bodyHeight) }"
|
|
168
|
+
@scroll="onLeftScroll"
|
|
169
|
+
>
|
|
170
|
+
<view class="hy-table__body--content">
|
|
171
|
+
<view
|
|
172
|
+
v-for="(row, rowIndex) in processedData"
|
|
173
|
+
:key="rowIndex"
|
|
174
|
+
:class="rowClass(rowIndex)"
|
|
175
|
+
:style="getRowStyle(rowIndex)"
|
|
176
|
+
>
|
|
177
|
+
<view
|
|
178
|
+
v-for="(col, colIndex) in leftFixedColumns"
|
|
179
|
+
:key="colIndex"
|
|
180
|
+
class="hy-table__body--content__row--cell"
|
|
181
|
+
:style="getBodyCellStyle(col, rowIndex)"
|
|
182
|
+
@tap="onCellClick(row, rowIndex)"
|
|
183
|
+
>
|
|
184
|
+
<slot
|
|
185
|
+
v-if="$slots.left"
|
|
186
|
+
name="left"
|
|
187
|
+
:row="row"
|
|
188
|
+
:col="col"
|
|
189
|
+
:index="rowIndex"
|
|
190
|
+
></slot>
|
|
191
|
+
<text
|
|
192
|
+
v-else
|
|
193
|
+
class="hy-table__body--content__row--cell__text"
|
|
194
|
+
:class="{ 'is-ellipsis': col.ellipsis }"
|
|
195
|
+
>
|
|
196
|
+
{{ getCellValue(row, col) }}
|
|
197
|
+
</text>
|
|
198
|
+
</view>
|
|
199
|
+
</view>
|
|
200
|
+
</view>
|
|
201
|
+
</scroll-view>
|
|
202
|
+
|
|
203
|
+
<!-- 中间滚动区域 -->
|
|
204
|
+
<scroll-view
|
|
205
|
+
v-if="processedData.length"
|
|
206
|
+
class="hy-table__body--center"
|
|
207
|
+
scroll-y
|
|
208
|
+
:scroll-top="scrollTop"
|
|
209
|
+
@scroll="onScroll"
|
|
210
|
+
:style="{
|
|
211
|
+
width: `calc(100% - ${leftFixedWidth + rightFixedWidth}px)`,
|
|
212
|
+
height: addUnit(bodyHeight),
|
|
213
|
+
left: addUnit(leftFixedWidth),
|
|
214
|
+
right: addUnit(rightFixedWidth)
|
|
215
|
+
}"
|
|
216
|
+
>
|
|
217
|
+
<scroll-view
|
|
218
|
+
scroll-x
|
|
219
|
+
:scroll-left="scrollLeft"
|
|
220
|
+
class="hy-table__body--content"
|
|
221
|
+
@scroll="onCrosswiseScroll"
|
|
222
|
+
>
|
|
223
|
+
<view
|
|
224
|
+
v-for="(row, rowIndex) in processedData"
|
|
225
|
+
:key="rowIndex"
|
|
226
|
+
:class="rowClass(rowIndex)"
|
|
227
|
+
:style="getRowStyle(rowIndex)"
|
|
228
|
+
>
|
|
229
|
+
<view
|
|
230
|
+
v-for="(col, colIndex) in scrollColumns"
|
|
231
|
+
:key="colIndex"
|
|
232
|
+
class="hy-table__body--content__row--cell"
|
|
233
|
+
:class="{ ellipsis: col.ellipsis }"
|
|
234
|
+
:style="getBodyCellStyle(col, rowIndex)"
|
|
235
|
+
@tap="onCellClick(row, rowIndex)"
|
|
236
|
+
>
|
|
237
|
+
<slot
|
|
238
|
+
v-if="$slots.default"
|
|
239
|
+
name="default"
|
|
240
|
+
:row="row"
|
|
241
|
+
:col="col"
|
|
242
|
+
:index="rowIndex"
|
|
243
|
+
></slot>
|
|
244
|
+
<text
|
|
245
|
+
v-else
|
|
246
|
+
class="hy-table__body--content__row--cell__text"
|
|
247
|
+
:class="{ 'is-ellipsis': col.ellipsis }"
|
|
248
|
+
>
|
|
249
|
+
{{ getCellValue(row, col) }}
|
|
250
|
+
</text>
|
|
251
|
+
</view>
|
|
252
|
+
</view>
|
|
253
|
+
</scroll-view>
|
|
254
|
+
</scroll-view>
|
|
255
|
+
|
|
256
|
+
<!-- 右侧固定列 -->
|
|
257
|
+
<scroll-view
|
|
258
|
+
v-if="processedData.length"
|
|
259
|
+
class="hy-table__body--right"
|
|
260
|
+
scroll-y
|
|
261
|
+
:scroll-top="scrollTop"
|
|
262
|
+
:style="{
|
|
263
|
+
width: addUnit(rightFixedWidth),
|
|
264
|
+
height: addUnit(bodyHeight),
|
|
265
|
+
right: '0'
|
|
266
|
+
}"
|
|
267
|
+
@scroll="onRightScroll"
|
|
268
|
+
>
|
|
269
|
+
<view class="hy-table__body--content">
|
|
270
|
+
<view
|
|
271
|
+
v-for="(row, rowIndex) in processedData"
|
|
272
|
+
:key="rowIndex"
|
|
273
|
+
:class="rowClass(rowIndex)"
|
|
274
|
+
:style="getRowStyle(rowIndex)"
|
|
275
|
+
>
|
|
276
|
+
<view
|
|
277
|
+
v-for="(col, colIndex) in rightFixedColumns"
|
|
278
|
+
:key="colIndex"
|
|
279
|
+
class="hy-table__body--content__row--cell"
|
|
280
|
+
:style="getBodyCellStyle(col, rowIndex)"
|
|
281
|
+
@tap="onCellClick(row, rowIndex)"
|
|
282
|
+
>
|
|
283
|
+
<slot
|
|
284
|
+
v-if="$slots.right"
|
|
285
|
+
name="right"
|
|
286
|
+
:row="row"
|
|
287
|
+
:col="col"
|
|
288
|
+
:index="rowIndex"
|
|
289
|
+
></slot>
|
|
290
|
+
<text
|
|
291
|
+
v-else
|
|
292
|
+
class="hy-table__body--content__row--cell__text"
|
|
293
|
+
:class="{ 'is-ellipsis': col.ellipsis }"
|
|
294
|
+
>
|
|
295
|
+
{{ getCellValue(row, col) }}
|
|
296
|
+
</text>
|
|
297
|
+
</view>
|
|
298
|
+
</view>
|
|
299
|
+
</view>
|
|
300
|
+
</scroll-view>
|
|
301
|
+
</view>
|
|
302
|
+
</view>
|
|
303
|
+
</template>
|
|
304
|
+
|
|
305
|
+
<script setup lang="ts">
|
|
306
|
+
import { ref, computed, watch, onMounted } from 'vue'
|
|
307
|
+
import { addUnit, IconConfig, sleep, getPx } from '../../libs'
|
|
308
|
+
import type { ITableColumn, ITableEmits } from './typing'
|
|
309
|
+
import tableProps from './props'
|
|
310
|
+
// 组件
|
|
311
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
312
|
+
import HyEmpty from '../hy-empty/hy-empty.vue'
|
|
313
|
+
import HyLoading from '../hy-loading/hy-loading.vue'
|
|
314
|
+
|
|
315
|
+
const props = defineProps(tableProps)
|
|
316
|
+
const emit = defineEmits<ITableEmits>()
|
|
317
|
+
|
|
318
|
+
// 响应式数据
|
|
319
|
+
const scrollLeft = ref(0)
|
|
320
|
+
const scrollTop = ref(0)
|
|
321
|
+
const rowHeights = ref<number[]>([])
|
|
322
|
+
const sortField = ref<string>('')
|
|
323
|
+
const sortOrder = ref<'asc' | 'desc'>('asc')
|
|
324
|
+
|
|
325
|
+
// 防止滚动循环触发和抖动的标志位
|
|
326
|
+
const isUpdatingScroll = ref(false)
|
|
327
|
+
|
|
328
|
+
// 计算属性
|
|
329
|
+
const leftFixedColumns = computed(() => props.columns.filter((col) => col.fixed === 'left'))
|
|
330
|
+
|
|
331
|
+
const rightFixedColumns = computed(() => props.columns.filter((col) => col.fixed === 'right'))
|
|
332
|
+
|
|
333
|
+
const scrollColumns = computed(() => props.columns.filter((col) => !col?.fixed))
|
|
334
|
+
|
|
335
|
+
const leftFixedWidth = computed(() =>
|
|
336
|
+
leftFixedColumns.value.reduce((sum, col) => sum + col.width, 0)
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
const rightFixedWidth = computed(() =>
|
|
340
|
+
rightFixedColumns.value.reduce((sum, col) => sum + col.width, 0)
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
const scrollWidth = computed(() => scrollColumns.value.reduce((sum, col) => sum + col.width, 0))
|
|
344
|
+
|
|
345
|
+
const totalWidth = computed(() => leftFixedWidth.value + scrollWidth.value + rightFixedWidth.value)
|
|
346
|
+
|
|
347
|
+
const containerHeight = computed(() => props.height)
|
|
348
|
+
|
|
349
|
+
const bodyHeight = computed(() => {
|
|
350
|
+
// 减去表头高度
|
|
351
|
+
return props.showHeader ? getPx(props.height) - 50 : props.height
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
const processedData = computed(() => {
|
|
355
|
+
let data = [...props.data]
|
|
356
|
+
|
|
357
|
+
if (sortField.value) {
|
|
358
|
+
data.sort((a, b) => {
|
|
359
|
+
const aVal = a[sortField.value]
|
|
360
|
+
const bVal = b[sortField.value]
|
|
361
|
+
|
|
362
|
+
if (aVal === bVal) return 0
|
|
363
|
+
if (sortOrder.value === 'asc') {
|
|
364
|
+
return aVal > bVal ? 1 : -1
|
|
365
|
+
} else {
|
|
366
|
+
return aVal < bVal ? 1 : -1
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return data
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
// 方法
|
|
375
|
+
const getHeaderCellStyle = (col: ITableColumn) => {
|
|
376
|
+
return {
|
|
377
|
+
width: addUnit(col.width),
|
|
378
|
+
textAlign: col.align || 'left',
|
|
379
|
+
flexShrink: 0
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const getBodyCellStyle = (col: ITableColumn, rowIndex: number) => {
|
|
384
|
+
const rowHeight = rowHeights.value[rowIndex] || props.rowHeight
|
|
385
|
+
return {
|
|
386
|
+
width: addUnit(col.width),
|
|
387
|
+
textAlign: col.align || 'left',
|
|
388
|
+
flexShrink: 0,
|
|
389
|
+
height: addUnit(rowHeight),
|
|
390
|
+
lineHeight: addUnit(rowHeight)
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* 行类名
|
|
396
|
+
* */
|
|
397
|
+
const rowClass = computed(() => {
|
|
398
|
+
return (rowIndex: number) => {
|
|
399
|
+
const classes = ['hy-table__body--content__row']
|
|
400
|
+
|
|
401
|
+
if (props.stripe && rowIndex % 2 === 1) {
|
|
402
|
+
classes.push('is-stripe')
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return classes
|
|
406
|
+
}
|
|
407
|
+
})
|
|
408
|
+
/**
|
|
409
|
+
* 行样式
|
|
410
|
+
* */
|
|
411
|
+
const getRowStyle = computed(() => {
|
|
412
|
+
return (rowIndex: number) => {
|
|
413
|
+
const rowHeight = rowHeights.value[rowIndex] || props.rowHeight
|
|
414
|
+
const styles: any = {
|
|
415
|
+
width: addUnit(scrollWidth.value),
|
|
416
|
+
height: addUnit(rowHeight),
|
|
417
|
+
lineHeight: addUnit(rowHeight)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return styles
|
|
421
|
+
}
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
const getCellValue = (row: any, col: ITableColumn) => {
|
|
425
|
+
if (col.formatter) {
|
|
426
|
+
return col.formatter(row[col.key], row)
|
|
427
|
+
}
|
|
428
|
+
return row[col.key] || ''
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const onHeaderScroll = async (e: any) => {
|
|
432
|
+
if (isUpdatingScroll.value) return
|
|
433
|
+
|
|
434
|
+
const newScrollLeft = e.detail.scrollLeft
|
|
435
|
+
if (Math.abs(newScrollLeft - scrollLeft.value) > 1) {
|
|
436
|
+
isUpdatingScroll.value = true
|
|
437
|
+
scrollLeft.value = newScrollLeft
|
|
438
|
+
// 在下一个事件循环重置标志位
|
|
439
|
+
await sleep(0)
|
|
440
|
+
isUpdatingScroll.value = false
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* 中间内容竖直滚动
|
|
446
|
+
* */
|
|
447
|
+
const onScroll = async (e: any) => {
|
|
448
|
+
if (isUpdatingScroll.value) return
|
|
449
|
+
|
|
450
|
+
const newScrollTop = e.detail.scrollTop
|
|
451
|
+
isUpdatingScroll.value = true
|
|
452
|
+
if (Math.abs(newScrollTop - scrollTop.value) > 1) {
|
|
453
|
+
scrollTop.value = newScrollTop
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// 在下一个事件循环重置标志位
|
|
457
|
+
await sleep(0)
|
|
458
|
+
isUpdatingScroll.value = false
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 中间内容横向滚动
|
|
463
|
+
* */
|
|
464
|
+
const onCrosswiseScroll = async (e: any) => {
|
|
465
|
+
if (isUpdatingScroll.value) return
|
|
466
|
+
|
|
467
|
+
const newScrollLeft = e.detail.scrollLeft
|
|
468
|
+
isUpdatingScroll.value = true
|
|
469
|
+
// 使用阈值来减少频繁更新,避免抖动
|
|
470
|
+
if (Math.abs(newScrollLeft - scrollLeft.value) > 1) {
|
|
471
|
+
scrollLeft.value = newScrollLeft
|
|
472
|
+
}
|
|
473
|
+
// 在下一个事件循环重置标志位
|
|
474
|
+
await sleep(0)
|
|
475
|
+
isUpdatingScroll.value = false
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* 左侧列表滚动
|
|
480
|
+
* */
|
|
481
|
+
const onLeftScroll = async (e: any) => {
|
|
482
|
+
if (isUpdatingScroll.value) return
|
|
483
|
+
|
|
484
|
+
const newScrollTop = e.detail.scrollTop
|
|
485
|
+
if (Math.abs(newScrollTop - scrollTop.value) > 1) {
|
|
486
|
+
isUpdatingScroll.value = true
|
|
487
|
+
scrollTop.value = newScrollTop
|
|
488
|
+
// 在下一个事件循环重置标志位
|
|
489
|
+
await sleep(0)
|
|
490
|
+
isUpdatingScroll.value = false
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* 右侧列表滚动
|
|
496
|
+
* */
|
|
497
|
+
const onRightScroll = async (e: any) => {
|
|
498
|
+
if (isUpdatingScroll.value) return
|
|
499
|
+
|
|
500
|
+
const newScrollTop = e.detail.scrollTop
|
|
501
|
+
if (Math.abs(newScrollTop - scrollTop.value) > 1) {
|
|
502
|
+
isUpdatingScroll.value = true
|
|
503
|
+
scrollTop.value = newScrollTop
|
|
504
|
+
// 在下一个事件循环重置标志位
|
|
505
|
+
await sleep(0)
|
|
506
|
+
isUpdatingScroll.value = false
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* 点击排序
|
|
512
|
+
* @param col 列标题
|
|
513
|
+
* @param sort 排序
|
|
514
|
+
* */
|
|
515
|
+
const handleSort = (col: ITableColumn, sort?: 'asc' | 'desc') => {
|
|
516
|
+
if (!col.sortable) return
|
|
517
|
+
|
|
518
|
+
if (sort) {
|
|
519
|
+
sortOrder.value = sort
|
|
520
|
+
sortField.value = col.key
|
|
521
|
+
} else {
|
|
522
|
+
if (sortField.value === col.key) {
|
|
523
|
+
sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc'
|
|
524
|
+
} else {
|
|
525
|
+
sortField.value = col.key
|
|
526
|
+
sortOrder.value = 'asc'
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
emit('sort-change', sortField.value, sortOrder.value)
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* 点击单元格
|
|
535
|
+
* @param row 行数据
|
|
536
|
+
* @param index 第几列
|
|
537
|
+
* */
|
|
538
|
+
const onCellClick = (row: AnyObject, index: number) => {
|
|
539
|
+
emit('row-click', row, index)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// 初始化行高
|
|
543
|
+
onMounted(() => {
|
|
544
|
+
rowHeights.value = new Array(props.data.length).fill(props.rowHeight)
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
// 监听数据变化
|
|
548
|
+
watch(
|
|
549
|
+
() => props.data,
|
|
550
|
+
() => {
|
|
551
|
+
rowHeights.value = new Array(props.data.length).fill(props.rowHeight)
|
|
552
|
+
},
|
|
553
|
+
{ deep: true }
|
|
554
|
+
)
|
|
555
|
+
</script>
|
|
556
|
+
|
|
557
|
+
<style scoped lang="scss">
|
|
558
|
+
@import './index.scss';
|
|
559
|
+
|
|
560
|
+
.header-text {
|
|
561
|
+
white-space: nowrap;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.sort-icons {
|
|
565
|
+
display: flex;
|
|
566
|
+
flex-direction: column;
|
|
567
|
+
margin-left: 4px;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
.sort-icon {
|
|
571
|
+
font-size: 10px;
|
|
572
|
+
color: #ccc;
|
|
573
|
+
line-height: 0.8;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
.sort-icon.active {
|
|
577
|
+
color: #1890ff;
|
|
578
|
+
}
|
|
579
|
+
</style>
|