vue2-components-plus 1.0.70 → 1.0.80
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/dist/ComponentDemo/CaptchaTableDemo.vue +281 -0
- package/dist/ComponentDemo/TableDemo.md +60 -41
- package/dist/ComponentDemo/TableDemo.vue +127 -409
- package/dist/vue2-components-plus.css +1 -1
- package/dist/vue2-components-plus.js +300 -271
- package/dist/vue2-components-plus.umd.cjs +1 -1
- package/package.json +1 -1
- package/dist/vue2-components-plus.es5.js +0 -3742
|
@@ -121,19 +121,11 @@
|
|
|
121
121
|
:columns="columns"
|
|
122
122
|
:action-buttons="actionButtons"
|
|
123
123
|
:total="total"
|
|
124
|
-
:current-page.sync="paginationState.currentPage"
|
|
125
|
-
:page-size.sync="paginationState.pageSize"
|
|
126
124
|
:table-props="mergedTableProps"
|
|
127
|
-
|
|
128
|
-
@search="handleSearch"
|
|
125
|
+
@search="loadData"
|
|
129
126
|
@reset="handleReset"
|
|
130
127
|
@add="handleAdd"
|
|
131
128
|
@selection-change="handleSelectionChange"
|
|
132
|
-
@sort-change="handleSortChange"
|
|
133
|
-
@row-click="handleRowClick"
|
|
134
|
-
@size-change="handleSizeChange"
|
|
135
|
-
@current-change="handleCurrentChange"
|
|
136
|
-
@page-change="handlePageChange"
|
|
137
129
|
@link-click="handleLinkClick"
|
|
138
130
|
>
|
|
139
131
|
<!-- 容器扩展插槽示例:extend(位于搜索区与表格之间) -->
|
|
@@ -151,9 +143,9 @@
|
|
|
151
143
|
<!-- 搜索项插槽示例:slot=item.slot -->
|
|
152
144
|
<template v-slot:emailKeywordSlot="{ formData }">
|
|
153
145
|
<el-input
|
|
154
|
-
v-model="formData.
|
|
146
|
+
v-model="formData.body"
|
|
155
147
|
clearable
|
|
156
|
-
placeholder="
|
|
148
|
+
placeholder="请输入正文关键字(自定义插槽)"
|
|
157
149
|
@keyup.enter.native="triggerSearchByEnter"
|
|
158
150
|
/>
|
|
159
151
|
</template>
|
|
@@ -180,26 +172,13 @@
|
|
|
180
172
|
<template v-slot:usernameHeader>
|
|
181
173
|
<span>
|
|
182
174
|
<i class="el-icon-link" />
|
|
183
|
-
|
|
175
|
+
标题(link)
|
|
184
176
|
</span>
|
|
185
177
|
</template>
|
|
186
178
|
|
|
187
|
-
<!-- 单元格插槽示例:column.slot -->
|
|
188
|
-
<template v-slot:status="{ row }">
|
|
189
|
-
<el-tag size="small" :type="getStatusType(row.status)">{{ getStatusText(row.status) }}</el-tag>
|
|
190
|
-
</template>
|
|
191
|
-
<template v-slot:gender="{ row }">
|
|
192
|
-
<el-tag size="small" :type="row.gender === 1 ? 'primary' : 'danger'">
|
|
193
|
-
{{ row.gender === 1 ? '男' : '女' }}
|
|
194
|
-
</el-tag>
|
|
195
|
-
</template>
|
|
196
|
-
<template v-slot:department="{ row }">
|
|
197
|
-
<el-tag size="small" effect="plain">{{ getDepartmentText(row.department) }}</el-tag>
|
|
198
|
-
</template>
|
|
199
|
-
|
|
200
179
|
<!-- action 按钮插槽示例:button.slot -->
|
|
201
180
|
<template v-slot:deleteAction="{ row }">
|
|
202
|
-
<el-button type="text" style="color: #f56c6c"
|
|
181
|
+
<el-button type="text" style="color: #f56c6c" @click="handleDelete(row)">
|
|
203
182
|
删除
|
|
204
183
|
</el-button>
|
|
205
184
|
</template>
|
|
@@ -243,50 +222,53 @@
|
|
|
243
222
|
|
|
244
223
|
<script setup>
|
|
245
224
|
import { computed, getCurrentInstance, nextTick, onMounted, ref, watch } from 'vue'
|
|
246
|
-
|
|
225
|
+
|
|
226
|
+
const POSTS_API = 'https://jsonplaceholder.typicode.com/posts'
|
|
247
227
|
|
|
248
228
|
function createSearchItems() {
|
|
249
229
|
return [
|
|
250
230
|
{
|
|
251
|
-
prop: '
|
|
252
|
-
label: '
|
|
231
|
+
prop: 'id',
|
|
232
|
+
label: '帖子 ID',
|
|
253
233
|
span: 6,
|
|
254
|
-
component: '
|
|
234
|
+
component: 'ElInputNumber',
|
|
255
235
|
attrs: {
|
|
256
|
-
placeholder: '
|
|
257
|
-
|
|
236
|
+
placeholder: '精确匹配(?id=)',
|
|
237
|
+
controlsPosition: 'right',
|
|
238
|
+
min: 1,
|
|
239
|
+
max: 100,
|
|
258
240
|
},
|
|
259
|
-
children: Array.from({ length: 12 }, function (_, index) {
|
|
260
|
-
return {
|
|
261
|
-
label: index + 1 + '月',
|
|
262
|
-
value: String(index + 1),
|
|
263
|
-
}
|
|
264
|
-
}),
|
|
265
241
|
},
|
|
266
242
|
{
|
|
267
|
-
prop: '
|
|
268
|
-
label: '
|
|
243
|
+
prop: 'userId',
|
|
244
|
+
label: '用户 ID',
|
|
269
245
|
span: 6,
|
|
270
|
-
component: '
|
|
246
|
+
component: 'ElSelect',
|
|
271
247
|
attrs: {
|
|
272
|
-
placeholder: '
|
|
248
|
+
placeholder: '精确匹配(?userId=)',
|
|
273
249
|
clearable: true,
|
|
274
250
|
},
|
|
251
|
+
children: Array.from({ length: 10 }, function (_, index) {
|
|
252
|
+
return {
|
|
253
|
+
label: '用户 ' + (index + 1),
|
|
254
|
+
value: index + 1,
|
|
255
|
+
}
|
|
256
|
+
}),
|
|
275
257
|
events: {},
|
|
276
258
|
},
|
|
277
259
|
{
|
|
278
|
-
prop: '
|
|
279
|
-
label: '
|
|
260
|
+
prop: 'q',
|
|
261
|
+
label: '关键字',
|
|
280
262
|
span: 6,
|
|
281
263
|
component: 'ElInput',
|
|
282
264
|
attrs: {
|
|
283
|
-
placeholder: '
|
|
265
|
+
placeholder: '在 title / body 中模糊匹配(?q=)',
|
|
284
266
|
clearable: true,
|
|
285
267
|
},
|
|
286
268
|
},
|
|
287
269
|
{
|
|
288
|
-
prop: '
|
|
289
|
-
label: '
|
|
270
|
+
prop: 'body',
|
|
271
|
+
label: '正文关键字',
|
|
290
272
|
span: 6,
|
|
291
273
|
type: 'slot',
|
|
292
274
|
slot: 'emailKeywordSlot',
|
|
@@ -294,79 +276,6 @@ function createSearchItems() {
|
|
|
294
276
|
required: false,
|
|
295
277
|
},
|
|
296
278
|
},
|
|
297
|
-
{
|
|
298
|
-
prop: 'status',
|
|
299
|
-
label: '状态',
|
|
300
|
-
span: 6,
|
|
301
|
-
component: 'ElSelect',
|
|
302
|
-
attrs: {
|
|
303
|
-
placeholder: '请选择状态',
|
|
304
|
-
clearable: true,
|
|
305
|
-
},
|
|
306
|
-
children: [],
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
prop: 'department',
|
|
310
|
-
label: '部门',
|
|
311
|
-
span: 6,
|
|
312
|
-
component: 'ElSelect',
|
|
313
|
-
attrs: {
|
|
314
|
-
placeholder: '请选择部门',
|
|
315
|
-
clearable: true,
|
|
316
|
-
filterable: true,
|
|
317
|
-
},
|
|
318
|
-
children: [],
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
prop: 'gender',
|
|
322
|
-
label: '性别',
|
|
323
|
-
span: 6,
|
|
324
|
-
component: 'ElSelect',
|
|
325
|
-
attrs: {
|
|
326
|
-
placeholder: '请选择性别',
|
|
327
|
-
clearable: true,
|
|
328
|
-
},
|
|
329
|
-
children: [
|
|
330
|
-
{ label: '全部', value: '' },
|
|
331
|
-
{ label: '男', value: 1 },
|
|
332
|
-
{ label: '女', value: 2 },
|
|
333
|
-
],
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
prop: 'createTime',
|
|
337
|
-
label: '创建时间',
|
|
338
|
-
span: 6,
|
|
339
|
-
component: 'ElDatePicker',
|
|
340
|
-
attrs: {
|
|
341
|
-
type: 'daterange',
|
|
342
|
-
clearable: true,
|
|
343
|
-
rangeSeparator: '至',
|
|
344
|
-
startPlaceholder: '开始日期',
|
|
345
|
-
endPlaceholder: '结束日期',
|
|
346
|
-
valueFormat: 'yyyy-MM-dd',
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
prop: 'phone',
|
|
351
|
-
label: '手机号',
|
|
352
|
-
span: 6,
|
|
353
|
-
component: 'ElInput',
|
|
354
|
-
attrs: {
|
|
355
|
-
placeholder: '请输入手机号',
|
|
356
|
-
clearable: true,
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
prop: 'active',
|
|
361
|
-
label: '是否激活',
|
|
362
|
-
span: 6,
|
|
363
|
-
component: 'ElSwitch',
|
|
364
|
-
attrs: {
|
|
365
|
-
activeText: '是',
|
|
366
|
-
inactiveText: '否',
|
|
367
|
-
},
|
|
368
|
-
defaultValue: true,
|
|
369
|
-
},
|
|
370
279
|
]
|
|
371
280
|
}
|
|
372
281
|
|
|
@@ -375,94 +284,38 @@ function createColumns(context) {
|
|
|
375
284
|
{
|
|
376
285
|
prop: 'id',
|
|
377
286
|
label: 'ID',
|
|
378
|
-
width:
|
|
379
|
-
sortable:
|
|
287
|
+
width: 80,
|
|
288
|
+
sortable: 'custom',
|
|
380
289
|
fixed: 'left',
|
|
290
|
+
align: 'center',
|
|
381
291
|
},
|
|
382
292
|
{
|
|
383
|
-
prop: '
|
|
384
|
-
label: '
|
|
385
|
-
width:
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
imageHeight: '34px',
|
|
389
|
-
},
|
|
390
|
-
{
|
|
391
|
-
label: '基本信息',
|
|
392
|
-
children: [
|
|
393
|
-
{
|
|
394
|
-
prop: 'username',
|
|
395
|
-
label: '用户名',
|
|
396
|
-
minWidth: 150,
|
|
397
|
-
type: 'link',
|
|
398
|
-
headerSlot: 'usernameHeader',
|
|
399
|
-
linkText: '查看用户',
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
prop: 'realName',
|
|
403
|
-
label: '真实姓名',
|
|
404
|
-
width: 120,
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
prop: 'gender',
|
|
408
|
-
label: '性别',
|
|
409
|
-
width: 90,
|
|
410
|
-
slot: 'gender',
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
prop: 'level',
|
|
414
|
-
label: '级别(enum)',
|
|
415
|
-
width: 120,
|
|
416
|
-
enum: [
|
|
417
|
-
{ label: '初级', value: 1 },
|
|
418
|
-
{ label: '中级', value: 2 },
|
|
419
|
-
{ label: '高级', value: 3 },
|
|
420
|
-
],
|
|
421
|
-
},
|
|
422
|
-
],
|
|
423
|
-
},
|
|
424
|
-
{
|
|
425
|
-
label: '组织信息',
|
|
426
|
-
children: [
|
|
427
|
-
{
|
|
428
|
-
prop: 'department',
|
|
429
|
-
label: '部门',
|
|
430
|
-
width: 130,
|
|
431
|
-
slot: 'department',
|
|
432
|
-
},
|
|
433
|
-
{
|
|
434
|
-
prop: 'status',
|
|
435
|
-
label: '状态(slot)',
|
|
436
|
-
width: 110,
|
|
437
|
-
slot: 'status',
|
|
438
|
-
},
|
|
439
|
-
],
|
|
293
|
+
prop: 'userId',
|
|
294
|
+
label: '用户 ID',
|
|
295
|
+
width: 100,
|
|
296
|
+
sortable: 'custom',
|
|
297
|
+
align: 'center',
|
|
440
298
|
},
|
|
441
299
|
{
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
prop: 'email',
|
|
451
|
-
label: '邮箱',
|
|
452
|
-
minWidth: 220,
|
|
453
|
-
},
|
|
454
|
-
],
|
|
300
|
+
prop: 'title',
|
|
301
|
+
label: '标题(link)',
|
|
302
|
+
minWidth: 260,
|
|
303
|
+
type: 'link',
|
|
304
|
+
headerSlot: 'usernameHeader',
|
|
305
|
+
linkText: function (row) {
|
|
306
|
+
return row.title
|
|
307
|
+
},
|
|
455
308
|
},
|
|
456
309
|
{
|
|
457
|
-
prop: '
|
|
458
|
-
label: '
|
|
459
|
-
|
|
460
|
-
|
|
310
|
+
prop: 'body',
|
|
311
|
+
label: '正文',
|
|
312
|
+
minWidth: 320,
|
|
313
|
+
showOverflowTooltip: true,
|
|
461
314
|
},
|
|
462
315
|
{
|
|
463
316
|
type: 'action',
|
|
464
317
|
label: '操作(action)',
|
|
465
|
-
width:
|
|
318
|
+
width: 220,
|
|
466
319
|
fixed: 'right',
|
|
467
320
|
buttons: [
|
|
468
321
|
{
|
|
@@ -481,19 +334,6 @@ function createColumns(context) {
|
|
|
481
334
|
context.handleEdit(row)
|
|
482
335
|
},
|
|
483
336
|
},
|
|
484
|
-
{
|
|
485
|
-
label: '禁用',
|
|
486
|
-
type: 'text',
|
|
487
|
-
show: function (row) {
|
|
488
|
-
return row.status === 1
|
|
489
|
-
},
|
|
490
|
-
disabled: function (row) {
|
|
491
|
-
return row.id % 2 === 0
|
|
492
|
-
},
|
|
493
|
-
handler: function (row) {
|
|
494
|
-
context.handleDisable(row)
|
|
495
|
-
},
|
|
496
|
-
},
|
|
497
337
|
{
|
|
498
338
|
label: '删除',
|
|
499
339
|
type: 'text',
|
|
@@ -509,26 +349,12 @@ const containerRef = ref()
|
|
|
509
349
|
const loading = ref(false)
|
|
510
350
|
const total = ref(0)
|
|
511
351
|
const tableData = ref([])
|
|
512
|
-
const searchParams = ref({})
|
|
513
|
-
const sortState = ref({
|
|
514
|
-
prop: '',
|
|
515
|
-
order: '',
|
|
516
|
-
})
|
|
517
352
|
const selectedKeys = ref([])
|
|
518
353
|
const eventLogs = ref([])
|
|
519
|
-
const
|
|
520
|
-
const mockUserCount = mockUsers.length
|
|
521
|
-
const externalSearchParams = {
|
|
522
|
-
source: 'vue2-demo',
|
|
523
|
-
active: true,
|
|
524
|
-
}
|
|
354
|
+
const externalSearchParams = {}
|
|
525
355
|
const actionButtons = [{ label: '导出', key: 'export' }]
|
|
526
356
|
const searchItems = ref(createSearchItems())
|
|
527
357
|
const columns = ref([])
|
|
528
|
-
const paginationState = ref({
|
|
529
|
-
currentPage: 1,
|
|
530
|
-
pageSize: 10,
|
|
531
|
-
})
|
|
532
358
|
const featureState = ref({
|
|
533
359
|
showSearch: true,
|
|
534
360
|
showSearchCollapse: true,
|
|
@@ -561,7 +387,7 @@ const mergedSearchProps = computed(function () {
|
|
|
561
387
|
actionsWidth: featureState.value.searchActionsWidth,
|
|
562
388
|
collapseToggleText: [featureState.value.searchCollapseExpandText, featureState.value.searchCollapseFoldText],
|
|
563
389
|
showCollapse: featureState.value.showSearchCollapse,
|
|
564
|
-
collapseLimit:
|
|
390
|
+
collapseLimit: 3,
|
|
565
391
|
actionsAlign: featureState.value.searchActionsAlign,
|
|
566
392
|
}
|
|
567
393
|
})
|
|
@@ -611,164 +437,89 @@ function logEvent(name, payload) {
|
|
|
611
437
|
eventLogs.value = eventLogs.value.slice(0, 20)
|
|
612
438
|
}
|
|
613
439
|
|
|
614
|
-
function enrichRows(list) {
|
|
615
|
-
return (list || []).map(function (item) {
|
|
616
|
-
return {
|
|
617
|
-
...item,
|
|
618
|
-
level: (item.id % 3) + 1,
|
|
619
|
-
}
|
|
620
|
-
})
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function normalizeSearchParams(params) {
|
|
624
|
-
const next = Object.assign({}, params)
|
|
625
|
-
if (typeof next.emailKeyword === 'string') {
|
|
626
|
-
next.emailKeyword = next.emailKeyword.trim()
|
|
627
|
-
}
|
|
628
|
-
if (typeof next.username === 'string') {
|
|
629
|
-
next.username = next.username.trim()
|
|
630
|
-
}
|
|
631
|
-
return next
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
function applyExtraFilters(list) {
|
|
635
|
-
if (!searchParams.value.emailKeyword) return list
|
|
636
|
-
return list.filter(function (item) {
|
|
637
|
-
return String(item.email || '').toLowerCase().indexOf(String(searchParams.value.emailKeyword).toLowerCase()) > -1
|
|
638
|
-
})
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
function compareValue(a, b) {
|
|
642
|
-
if (a === b) return 0
|
|
643
|
-
if (a === undefined || a === null) return -1
|
|
644
|
-
if (b === undefined || b === null) return 1
|
|
645
|
-
const maybeDateA = new Date(a).getTime()
|
|
646
|
-
const maybeDateB = new Date(b).getTime()
|
|
647
|
-
if (!Number.isNaN(maybeDateA) && !Number.isNaN(maybeDateB)) {
|
|
648
|
-
return maybeDateA - maybeDateB
|
|
649
|
-
}
|
|
650
|
-
if (typeof a === 'number' && typeof b === 'number') {
|
|
651
|
-
return a - b
|
|
652
|
-
}
|
|
653
|
-
return String(a).localeCompare(String(b))
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
function applySort(list) {
|
|
657
|
-
if (!sortState.value.prop || !sortState.value.order) {
|
|
658
|
-
return list
|
|
659
|
-
}
|
|
660
|
-
const direction = sortState.value.order === 'ascending' ? 1 : -1
|
|
661
|
-
return (list || []).slice().sort(function (left, right) {
|
|
662
|
-
return compareValue(left[sortState.value.prop], right[sortState.value.prop]) * direction
|
|
663
|
-
})
|
|
664
|
-
}
|
|
665
|
-
|
|
666
440
|
function triggerSearchByEnter() {
|
|
667
|
-
|
|
441
|
+
if (containerRef.value && containerRef.value.reload) {
|
|
442
|
+
containerRef.value.reload()
|
|
443
|
+
}
|
|
668
444
|
}
|
|
669
445
|
|
|
670
446
|
function applyEnabledQuickFilter(formData, doSearch) {
|
|
671
447
|
if (!formData) return
|
|
672
|
-
formData.
|
|
448
|
+
formData.userId = 1
|
|
673
449
|
if (typeof doSearch === 'function') {
|
|
674
450
|
doSearch()
|
|
675
451
|
}
|
|
676
452
|
}
|
|
677
453
|
|
|
678
|
-
function
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
function getDepartmentText(value) {
|
|
687
|
-
const matched = departmentOptions.find(function (item) {
|
|
688
|
-
return item.value === value
|
|
454
|
+
function buildQuery(params) {
|
|
455
|
+
const usp = new URLSearchParams()
|
|
456
|
+
Object.keys(params).forEach(function (key) {
|
|
457
|
+
const value = params[key]
|
|
458
|
+
if (value === undefined || value === null || value === '') return
|
|
459
|
+
usp.append(key, String(value))
|
|
689
460
|
})
|
|
690
|
-
return
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
function getCurrentPagination() {
|
|
694
|
-
return containerRef.value && containerRef.value.getPagination
|
|
695
|
-
? containerRef.value.getPagination()
|
|
696
|
-
: { currentPage1: 1, pageSize1: paginationState.value.pageSize }
|
|
461
|
+
return usp.toString()
|
|
697
462
|
}
|
|
698
463
|
|
|
699
|
-
function
|
|
700
|
-
const
|
|
701
|
-
const
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
if (
|
|
709
|
-
|
|
464
|
+
async function fetchPosts(query) {
|
|
465
|
+
const params = query || {}
|
|
466
|
+
const requestParams = {
|
|
467
|
+
_page: params.currentPage1 || 1,
|
|
468
|
+
_limit: params.pageSize1 || 10,
|
|
469
|
+
}
|
|
470
|
+
const keyword = String(params.q || '').trim()
|
|
471
|
+
if (keyword) requestParams.q = keyword
|
|
472
|
+
if (params.id) requestParams.id = params.id
|
|
473
|
+
if (params.userId) requestParams.userId = params.userId
|
|
474
|
+
const body = String(params.body || '').trim()
|
|
475
|
+
if (body) requestParams.body_like = body
|
|
476
|
+
const sort = params.sort || {}
|
|
477
|
+
if (sort.prop && sort.order) {
|
|
478
|
+
requestParams._sort = sort.prop
|
|
479
|
+
requestParams._order = sort.order === 'ascending' ? 'asc' : 'desc'
|
|
710
480
|
}
|
|
711
|
-
}
|
|
712
481
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
482
|
+
const response = await fetch(POSTS_API + '?' + buildQuery(requestParams), {
|
|
483
|
+
method: 'GET',
|
|
484
|
+
headers: { Accept: 'application/json' },
|
|
485
|
+
})
|
|
486
|
+
if (!response.ok) {
|
|
487
|
+
throw new Error('HTTP ' + response.status)
|
|
716
488
|
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
loadData()
|
|
721
|
-
proxy.$message.success('已切换为' + (paginationMode.value === 'frontend' ? '前端分页' : '后端分页'))
|
|
489
|
+
const list = await response.json()
|
|
490
|
+
const totalHeader = Number(response.headers.get('x-total-count')) || (Array.isArray(list) ? list.length : 0)
|
|
491
|
+
return { list: Array.isArray(list) ? list : [], total: totalHeader }
|
|
722
492
|
}
|
|
723
493
|
|
|
724
|
-
async function loadData() {
|
|
494
|
+
async function loadData(query) {
|
|
725
495
|
loading.value = true
|
|
726
496
|
try {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
497
|
+
logEvent('search', query)
|
|
498
|
+
const result = await fetchPosts(query)
|
|
499
|
+
let list = result.list
|
|
500
|
+
if (query && query.body) {
|
|
501
|
+
const keyword = String(query.body).trim().toLowerCase()
|
|
502
|
+
if (keyword) {
|
|
503
|
+
list = list.filter(function (item) {
|
|
504
|
+
return String(item.body || '').toLowerCase().indexOf(keyword) !== -1
|
|
505
|
+
})
|
|
506
|
+
}
|
|
734
507
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
mockUsers,
|
|
738
|
-
searchParams.value,
|
|
739
|
-
{ currentPage1: 1, pageSize1: mockUserCount || 10 },
|
|
740
|
-
pageConfig,
|
|
741
|
-
)
|
|
742
|
-
const enrichedList = enrichRows(filtered.list)
|
|
743
|
-
const extraFilteredList = applyExtraFilters(enrichedList)
|
|
744
|
-
const sortedList = applySort(extraFilteredList)
|
|
745
|
-
|
|
746
|
-
if (paginationMode.value === 'frontend') {
|
|
747
|
-
const pagination = getCurrentPagination()
|
|
748
|
-
tableData.value = paginateList(sortedList, pagination)
|
|
749
|
-
total.value = sortedList.length
|
|
750
|
-
return
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
const pagination = getCurrentPagination()
|
|
754
|
-
tableData.value = paginateList(sortedList, pagination)
|
|
755
|
-
total.value = sortedList.length
|
|
508
|
+
tableData.value = list
|
|
509
|
+
total.value = result.total
|
|
756
510
|
} catch (error) {
|
|
757
|
-
proxy.$message
|
|
511
|
+
if (proxy && proxy.$message) {
|
|
512
|
+
proxy.$message.error('加载表格数据失败:' + (error && error.message ? error.message : ''))
|
|
513
|
+
}
|
|
514
|
+
tableData.value = []
|
|
515
|
+
total.value = 0
|
|
758
516
|
} finally {
|
|
759
517
|
loading.value = false
|
|
760
518
|
}
|
|
761
519
|
}
|
|
762
520
|
|
|
763
|
-
function handleSearch(params) {
|
|
764
|
-
const normalized = normalizeSearchParams(params)
|
|
765
|
-
searchParams.value = normalized
|
|
766
|
-
logEvent('search', normalized)
|
|
767
|
-
loadData()
|
|
768
|
-
}
|
|
769
|
-
|
|
770
521
|
function handleReset() {
|
|
771
|
-
logEvent('reset',
|
|
522
|
+
logEvent('reset', {})
|
|
772
523
|
proxy.$message.info('搜索条件已重置')
|
|
773
524
|
}
|
|
774
525
|
|
|
@@ -780,37 +531,12 @@ function handleSelectionChange(selection) {
|
|
|
780
531
|
logEvent('selection-change', keys)
|
|
781
532
|
}
|
|
782
533
|
|
|
783
|
-
function handleSortChange(sort) {
|
|
784
|
-
sortState.value = sort || { prop: '', order: '' }
|
|
785
|
-
logEvent('sort-change', sortState.value)
|
|
786
|
-
loadData()
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
function handleRowClick(row, column) {
|
|
790
|
-
logEvent('row-click', {
|
|
791
|
-
id: row.id,
|
|
792
|
-
column: column && column.property,
|
|
793
|
-
})
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
function handleSizeChange(size) {
|
|
797
|
-
logEvent('size-change', size)
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
function handleCurrentChange(page) {
|
|
801
|
-
logEvent('current-change', page)
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
function handlePageChange(payload) {
|
|
805
|
-
logEvent('page-change', payload)
|
|
806
|
-
}
|
|
807
|
-
|
|
808
534
|
function handleLinkClick(row, column) {
|
|
809
535
|
logEvent('link-click', {
|
|
810
536
|
id: row.id,
|
|
811
537
|
prop: column && column.prop,
|
|
812
538
|
})
|
|
813
|
-
proxy.$message.info('
|
|
539
|
+
proxy.$message.info('点击了标题链接:#' + row.id)
|
|
814
540
|
}
|
|
815
541
|
|
|
816
542
|
function getSelectedRows() {
|
|
@@ -854,9 +580,9 @@ function checkSelection() {
|
|
|
854
580
|
function setSearchForm() {
|
|
855
581
|
if (!containerRef.value) return
|
|
856
582
|
containerRef.value.setSearchFormData({
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
583
|
+
userId: 1,
|
|
584
|
+
q: 'qui',
|
|
585
|
+
body: 'rerum',
|
|
860
586
|
})
|
|
861
587
|
proxy.$message.success('已回填搜索条件,可点击“查询”查看效果')
|
|
862
588
|
}
|
|
@@ -868,16 +594,19 @@ function resetSearchForm() {
|
|
|
868
594
|
}
|
|
869
595
|
|
|
870
596
|
function reloadWithMessage() {
|
|
871
|
-
|
|
597
|
+
if (containerRef.value && containerRef.value.reload) {
|
|
598
|
+
containerRef.value.reload()
|
|
599
|
+
}
|
|
872
600
|
proxy.$message.success('已刷新数据')
|
|
873
601
|
}
|
|
874
602
|
|
|
875
603
|
function clearSortState() {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
604
|
+
if (containerRef.value && containerRef.value.$refs && containerRef.value.$refs.tableRef && containerRef.value.$refs.tableRef.clearSort) {
|
|
605
|
+
containerRef.value.$refs.tableRef.clearSort()
|
|
606
|
+
}
|
|
607
|
+
if (containerRef.value && containerRef.value.reload) {
|
|
608
|
+
containerRef.value.reload()
|
|
879
609
|
}
|
|
880
|
-
loadData()
|
|
881
610
|
proxy.$message.success('已重置排序')
|
|
882
611
|
}
|
|
883
612
|
|
|
@@ -887,28 +616,22 @@ function handleAdd() {
|
|
|
887
616
|
}
|
|
888
617
|
|
|
889
618
|
function handleView(row) {
|
|
890
|
-
proxy.$message.info('
|
|
619
|
+
proxy.$message.info('查看:#' + row.id + ' ' + row.title)
|
|
891
620
|
}
|
|
892
621
|
|
|
893
622
|
function handleEdit(row) {
|
|
894
|
-
proxy.$message.success('
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
function handleDisable(row) {
|
|
898
|
-
proxy.$message.warning('已模拟禁用:' + row.username)
|
|
623
|
+
proxy.$message.success('编辑:#' + row.id + ' ' + row.title)
|
|
899
624
|
}
|
|
900
625
|
|
|
901
626
|
function handleDelete(row) {
|
|
902
|
-
|
|
903
|
-
proxy.$message.warning('禁用状态用户不可删除')
|
|
904
|
-
return
|
|
905
|
-
}
|
|
906
|
-
proxy.$confirm('确认删除用户“' + row.username + '”吗?', '提示', {
|
|
627
|
+
proxy.$confirm('确认删除帖子“' + row.title + '”吗?', '提示', {
|
|
907
628
|
type: 'warning',
|
|
908
629
|
})
|
|
909
630
|
.then(() => {
|
|
910
|
-
proxy.$message.success('
|
|
911
|
-
|
|
631
|
+
proxy.$message.success('已模拟删除:#' + row.id)
|
|
632
|
+
if (containerRef.value && containerRef.value.reload) {
|
|
633
|
+
containerRef.value.reload()
|
|
634
|
+
}
|
|
912
635
|
})
|
|
913
636
|
.catch(function () {})
|
|
914
637
|
}
|
|
@@ -925,7 +648,6 @@ watch(
|
|
|
925
648
|
columns.value = createColumns({
|
|
926
649
|
handleView,
|
|
927
650
|
handleEdit,
|
|
928
|
-
handleDisable,
|
|
929
651
|
handleDelete,
|
|
930
652
|
})
|
|
931
653
|
searchItems.value[1].events.keyup = function (event) {
|
|
@@ -935,12 +657,8 @@ searchItems.value[1].events.keyup = function (event) {
|
|
|
935
657
|
}
|
|
936
658
|
|
|
937
659
|
onMounted(async () => {
|
|
938
|
-
const statusOptions = await fetchStatusOptions()
|
|
939
|
-
const departmentList = await fetchDepartmentOptions()
|
|
940
|
-
searchItems.value[4].children = statusOptions
|
|
941
|
-
searchItems.value[5].children = departmentList
|
|
942
660
|
await nextTick()
|
|
943
|
-
if (containerRef.value) {
|
|
661
|
+
if (containerRef.value && containerRef.value.initSearchAndLoad) {
|
|
944
662
|
containerRef.value.initSearchAndLoad()
|
|
945
663
|
}
|
|
946
664
|
})
|