表单低代码自定义列表页
# 例子
在后台配置完成前端列表页展示内容后,前端根据返回的配置项生成对应的列表页
<template>
<div class="container">
<div class="contain">
<div class="pager-pagination">
<el-pagination background :total="total" @current-change="handleCurrentChange" />
</div>
<div class="searchForm">
<el-form :inline="true" class="form-inline">
<div class="left">
<el-row>
<el-col :span="8" v-for="(item, index) in headList" :key="index">
<el-form-item :label="item.title" label-width="100px">
<el-input v-if="item.type == 'TEXT'" v-model="params[item.code]" :placeholder="item.tips" />
<el-input
type="number"
v-if="item.type == 'NUMBER'"
v-model="params[item.code]"
:placeholder="item.tips"
/>
<el-date-picker
:format="item.format"
:value-format="item.format"
v-if="item.type == 'DATE'"
v-model="params[item.code]"
:placeholder="item.tips"
/>
<el-date-picker
v-model="params[item.code]"
style="width: 250px"
type="datetimerange"
:format="item.format"
:value-format="item.format"
v-if="item.type == 'DATE_RANGE'"
:placeholder="item.tips"
/>
<el-select style="width: 210px" v-model="params[item.code]" v-if="item.type == 'RADIO'">
<el-option v-for="(op, i) in item.optionList" :key="i" :label="op.text" :value="op.value" />
</el-select>
<el-select
style="width: 210px"
v-if="item.type == 'CHECKBOX'"
v-model="params[item.code]"
:placeholder="item.tips"
>
<el-option v-for="(op, i) in item.optionList" :key="i" :label="op.text" :value="op.value" />
</el-select>
<el-select
style="width: 210px"
v-if="item.type == 'SELECT'"
v-model="params[item.code]"
:placeholder="item.tips"
>
<el-option
v-for="(op, i) in item.optionList"
:key="i"
:label="op.text"
:value="op.value"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
</div>
<el-form-item class="btn-all">
<el-button @click="resetSearch"><img src="@/assets/btn/reset-btn.png" /> <span>重置</span></el-button>
<el-button type="primary" @click="getTableData"
><img src="@/assets/btn/search-btn.png" /> <span>搜索</span></el-button
>
</el-form-item>
</el-form>
</div>
<div class="add">
<div class="addBox" @click="goAdd" v-if="buttonList.includes('form:data:create')">
<img src="@/assets/formicon/add.png" alt="" />
<span>新增</span>
</div>
</div>
<el-table
:data="tableData"
show-overflow-tooltip
header-cell-class-name="table-header-cell-class-name"
class="table-list-class"
virtual-scroll
stripe
>
<template #empty>
<div class="noData">
<div>
<img src="@/assets/form/nodataTable.png" alt="" />
<div class="tips">暂无数据</div>
</div>
</div>
</template>
<el-table-column v-if="isNumber" type="index" label="序号" width="70" />
<el-table-column v-for="(item, index) in tableList" :key="index" :prop="item.code" :label="item.title">
<template v-if="item.code === 'status'" #default="scope">
<span class="listing-status" :class="scope.row.status == '已上架' ? 'active' : ''">
<img src="@/assets/authentication/adopt.png" v-if="scope.row.status == '已上架'" />
<img src="@/assets/authentication/yqx.png" v-else />
{{ scope.row.status }}
</span>
</template>
</el-table-column>
<el-table-column fixed="right" label="操作" width="300">
<template #default="scope">
<el-button
v-if="buttonList.includes('form:data:updateStatus')"
type="primary"
class="table-fixed-btn-text"
link
@click="handleSj(scope.row)"
>{{ scope.row.status == "已上架" ? "下架" : "上架" }}</el-button
>
<el-button
v-if="buttonList.includes('form:data:detail')"
type="primary"
class="table-fixed-btn-text"
link
@click="handleDetail(scope.row)"
>详情</el-button
>
<el-button
v-if="buttonList.includes('form:data:update')"
type="primary"
class="table-fixed-btn-text"
link
@click="goEdit(scope.row)"
>编辑</el-button
>
<el-button
v-if="buttonList.includes('form:data:delete')"
type="primary"
class="table-fixed-btn-text"
link
@click="deleteRow(scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<script setup>
import { detailTableByCategoryId, selectPage, deleteItem, updateStatus, getButton } from "@/api/form.js"
import { ref, reactive, onMounted } from "vue"
import { useRoute, useRouter } from "vue-router"
import { ElMessage, ElMessageBox } from "element-plus"
const route = useRoute()
const router = useRouter()
//筛选列表
const headList = ref([])
//表格列表
const tableList = ref([])
//表格数据
const tableData = ref([])
//条数
const total = ref(0)
//数据处理方法
function generateObject(arr) {
const result = {}
arr.forEach((item) => {
if (item.code) {
result[item.code] = "" // 将 code 作为键,值设置为空字符串
}
})
return result
}
//参数
const params = reactive({
pageNo: 1,
pageSize: 10,
formCode: ""
})
const resetSearch = () => {
console.log(params)
for (let key in params) {
if (key === "pageNo") {
params[key] = 1
} else if (key === "pageSize") {
params[key] = 10
} else if (key === "formCode") {
console.log(1)
} else {
params[key] = ""
}
}
getTableData()
}
//分页方法
const handleCurrentChange = () => {
getTableData()
}
//数据处理方法
function transformData(input) {
// 初始化一个新的对象
let result = {
pageNo: input.pageNo,
pageSize: input.pageSize,
formCode: input.formCode,
tableScreenList: []
}
// 遍历输入对象的其他属性
for (let key in input) {
// 排除 pageNo, pageSize, formCode 这几个属性
if (key !== "pageNo" && key !== "pageSize" && key !== "formCode") {
// 将其他属性转换成指定格式,并添加到 tableScreenList 数组中
result.tableScreenList.push({
code: key,
value: input[key]
})
}
}
return result
}
const isNumber = ref(false)
//数据处理方法
function transformDatas(inputData) {
return inputData.map((item) => {
// 构建一个新的对象,包含外层数据
let newItem = {
id: item.id,
userId: item.userId,
formId: item.formId,
category: item.category,
siteCode: item.siteCode,
version: item.version,
userName: item.userName
}
// 处理dataList中的数据,提取key和value并存入新对象
item.dataList.forEach((data) => {
const key = data.code // 使用code作为key
const value = data.valueString || data.valueInt || data.valueDecimal // 使用valueString或valueInt作为value
newItem[key] = value // 将数据存入新对象
})
return newItem
})
}
//获取表格数据
const getTableData = async () => {
const res = await selectPage(transformData(params))
tableData.value = transformDatas(res.data.list)
const arr = []
res.data.list.forEach((item) => {
const obj = {
userName: item.userName,
createTime: item.createTime,
updateTime: item.updateTime,
status: item.status,
reviewStatus: item.reviewStatus
}
arr.push(obj)
})
tableData.value.forEach((item) => {
for (let key in item) {
tableList.value.forEach((item2) => {
if (item2.code == key) {
if (item2.type === "SELECT" || item2.type === "CHECKBOX" || item2.type === "RADIO") {
item2.optionList.forEach((item3) => {
if (item3.value === item[key]) {
item[key] = item3.text
}
})
}
}
})
}
})
tableData.value.forEach((item, index) => {
arr.forEach((item2, index2) => {
if (index == index2) {
;(item.userName = item2.userName),
(item.createTime = timestampToDateTime(item2.createTime)),
(item.updateTime = timestampToDateTime(item2.updateTime)),
(item.status = handleStatus(item2.status)),
(item.reviewStatus = item2.reviewStatus)
}
})
})
total.value = res.data.total
}
function handleStatus(status) {
if (status == 1) {
return "已上架"
}
if (status == 0) {
return "已下架"
}
}
function timestampToDateTime(timestamp) {
var date = new Date(timestamp) // 转换为Date对象
var year = date.getFullYear() // 获取年份
var month = ("0" + (date.getMonth() + 1)).slice(-2) // 获取月份,转为两位数
var day = ("0" + date.getDate()).slice(-2) // 获取日,转为两位数
var hours = ("0" + date.getHours()).slice(-2) // 获取小时,转为两位数
var minutes = ("0" + date.getMinutes()).slice(-2) // 获取分钟,转为两位数
var seconds = ("0" + date.getSeconds()).slice(-2) // 获取秒钟,转为两位数
// 拼接字符串
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
//获取页面表单
const getForm = async () => {
const res = await detailTableByCategoryId({ categoryId: route.query.id, siteCode: "DALIAN" })
isNumber.value = res.data.isNumber
headList.value = res.data.tableScreenList
formId.value = res.data.formId
params.formCode = res.data.formCode
res.data.tableScreenList.forEach((item) => {
params[item.code] = ""
})
tableList.value = res.data.tableHeaderList
// tableData.value = [generateObject(res.data.tableHeaderList)]
}
//去新增
const formId = ref("")
const goAdd = () => {
router.push(`/operateManage/formAdd?id=${formId.value}&type=add`)
}
const goEdit = (item) => {
console.log(item)
router.push(`/operateManage/formAdd?id=${item.id}&type=edit`)
}
const handleSj = async (item) => {
console.log(item)
if (item.status === "已下架") {
const res = await updateStatus({ dataId: item.id, status: 1 })
ElMessage.success("操作成功")
getTableData()
}
if (item.status === "已上架") {
const res = await updateStatus({ dataId: item.id, status: 0 })
ElMessage.success("操作成功")
getTableData()
}
}
const handleDetail = (item) => {
router.push(`/operateManage/formDetail?id=${item.id}&type=edit`)
}
const deleteRow = async (row) => {
ElMessageBox.confirm("确认删除吗?", "", {
cancelButtonText: "取消",
confirmButtonText: "确认",
customClass: "delete-message-box",
center: true
})
.then(async () => {
await deleteItem({ id: row.id })
getTableData()
ElMessage({
type: "success",
message: "删除成功"
})
})
.catch(() => {})
}
const buttonList = ref([])
const getPermission = async () => {
const res = await getButton({ menuIdList: route.query.buttonId })
console.log(res)
buttonList.value = res.data
}
onMounted(async () => {
getPermission()
await getForm()
await getTableData()
})
</script>
<style lang="scss" scoped>
.noData {
display: flex;
align-items: center;
justify-content: center;
height: 500px;
img {
width: 157px;
height: 150px;
}
.tips {
font-family: SourceHanSansCN, SourceHanSansCN;
font-weight: 500;
font-size: 14px;
color: #005fd0;
line-height: 20px;
text-align: center;
font-style: normal;
}
}
.container {
width: 100%;
height: calc(100vh - var(--v3-navigationbar-height));
display: flex;
.contain {
margin: 24px;
margin-top: 0;
border-radius: 8px;
background: #fff;
overflow: hidden;
flex: 1;
display: flex;
flex-direction: column;
position: relative;
.pager-pagination {
z-index: 9999;
position: absolute;
bottom: 10px;
right: 20px;
background-color: #fff;
}
.searchForm {
padding-left: 24px;
padding-right: 24px;
box-sizing: border-box;
border-bottom: 1px solid #e4e7ed;
// height: 84px;
display: flex;
align-items: center;
.form-inline {
width: 100%;
display: flex;
align-items: center;
.left {
flex: 1;
padding-bottom: 20px;
}
:deep(.el-row) {
padding-bottom: 20px;
}
:deep(.el-col) {
margin-top: 20px;
}
:deep(.el-form-item) {
margin-bottom: 0px;
margin-right: 40px;
.el-form-item__label {
font-size: 14px;
color: #1d2129;
padding-right: 8px;
height: 36px;
line-height: 36px;
}
.el-input,
.el-select {
// width: 240px;
height: 36px;
line-height: 36px;
> div {
height: 36px;
}
}
}
.btn-all {
margin-right: 0;
:deep(.el-button) {
width: 80px;
height: 36px;
> span {
> img {
width: 14px;
margin-right: 4px;
margin-top: -1px;
}
> span {
font-weight: 400;
font-size: 14px;
}
}
}
}
}
.searchItem {
display: flex;
.reset {
cursor: pointer;
margin-right: 24px;
width: 80px;
height: 36px;
background: #ffffff;
border-radius: 2px;
border: 1px solid #c9cdd4;
display: flex;
align-items: center;
justify-content: center;
img {
width: 14px;
height: 14px;
margin-right: 4px;
}
span {
font-family: SourceHanSansCN, SourceHanSansCN;
font-weight: 400;
font-size: 14px;
color: #1d2129;
line-height: 20px;
text-align: center;
font-style: normal;
}
}
.search {
cursor: pointer;
width: 80px;
height: 36px;
background: #005fd0;
border-radius: 2px;
display: flex;
align-items: center;
justify-content: center;
img {
width: 14px;
height: 14px;
margin-right: 4px;
}
span {
font-family: SourceHanSansCN, SourceHanSansCN;
font-weight: 500;
font-size: 14px;
color: #ffffff;
line-height: 20px;
text-align: center;
font-style: normal;
}
}
}
}
.add {
padding-top: 24px;
height: 84px;
padding-left: 24px;
.addBox {
cursor: pointer;
width: 80px;
height: 36px;
background: #ffffff;
border-radius: 2px;
border: 2px solid #005fd0;
display: flex;
align-items: center;
justify-content: center;
span {
font-family: SourceHanSansCN, SourceHanSansCN;
font-weight: 400;
font-size: 14px;
color: #005fd0;
line-height: 20px;
text-align: left;
font-style: normal;
}
img {
width: 14px;
height: 14px;
margin-right: 4px;
}
}
}
}
}
</style>
1
2
3
4
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
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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
2
3
4
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
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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
上次更新: 2024/11/22, 15:42:10