matrix_components 2.0.365 → 2.0.367
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/FormDemo copy 2.vue +557 -0
- package/dist/ComponentDemo/FormDemo copy.vue +454 -0
- package/dist/ComponentDemo/FormDemo.vue +515 -378
- package/dist/matrix_components.css +1 -1
- package/dist/matrix_components.js +12 -12
- package/dist/matrix_components.umd.cjs +1 -1
- package/package.json +1 -1
|
@@ -1,423 +1,560 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
<div class="demo-container">
|
|
3
|
+
<div class="control-panel">
|
|
4
|
+
<h3>动态表单组件演示</h3>
|
|
5
|
+
<!-- 配置文件选择 -->
|
|
6
|
+
<el-form :model="state" ref="formRef" label-position="left">
|
|
7
7
|
<el-button type="primary" @click="getFormData">获取表单数据</el-button>
|
|
8
|
-
<
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<br
|
|
13
|
-
<br>
|
|
8
|
+
<el-button type="default" @click="resetFormData">重置表单</el-button>
|
|
9
|
+
<br />
|
|
10
|
+
<span style="color: red"> 结果:{{ state.formData }} </span>
|
|
11
|
+
<br />
|
|
12
|
+
<br />
|
|
14
13
|
<NsFormTitle title="模型参数">
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
<NsForm
|
|
15
|
+
ref="row1Ref"
|
|
16
|
+
:readOnly="state.readOnly"
|
|
17
|
+
backgroundColor="#fff"
|
|
18
|
+
:model="state.model"
|
|
19
|
+
:rows="state.rows"
|
|
20
|
+
formPropKey="rows"
|
|
21
|
+
labelColor="#606266"
|
|
22
|
+
labelWidth="150"
|
|
23
|
+
gapH="20px"
|
|
24
|
+
gapV="10px"
|
|
25
|
+
></NsForm>
|
|
27
26
|
</NsFormTitle>
|
|
28
27
|
<NsFormTitle title="视频配置">
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
<NsForm
|
|
29
|
+
ref="row2Ref"
|
|
30
|
+
:readOnly="state.readOnly"
|
|
31
|
+
backgroundColor="#fff"
|
|
32
|
+
:model="state.model"
|
|
33
|
+
:rows="state.rows2"
|
|
34
|
+
formPropKey="rows2"
|
|
35
|
+
labelColor="#606266"
|
|
36
|
+
labelWidth="150"
|
|
37
|
+
gapH="20px"
|
|
38
|
+
gapV="10px"
|
|
39
|
+
></NsForm>
|
|
41
40
|
</NsFormTitle>
|
|
42
41
|
<NsFormTitle title="结果保存">
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
<NsForm
|
|
43
|
+
ref="row3Ref"
|
|
44
|
+
:readOnly="state.readOnly"
|
|
45
|
+
backgroundColor="#fff"
|
|
46
|
+
:model="state.model"
|
|
47
|
+
:rows="state.rows3"
|
|
48
|
+
formPropKey="rows3"
|
|
49
|
+
labelColor="#606266"
|
|
50
|
+
labelWidth="150"
|
|
51
|
+
gapH="20px"
|
|
52
|
+
gapV="10px"
|
|
53
|
+
></NsForm>
|
|
55
54
|
</NsFormTitle>
|
|
56
|
-
|
|
55
|
+
</el-form>
|
|
56
|
+
</div>
|
|
57
57
|
</div>
|
|
58
|
-
</
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
</template>
|
|
59
|
+
|
|
60
|
+
<script setup lang="ts">
|
|
61
|
+
import { ElInput, ElMessage, ElRadioGroup } from 'element-plus'
|
|
62
|
+
import { reactive, ref } from 'vue'
|
|
63
|
+
import { cloneDeep } from 'lodash-es'
|
|
64
|
+
import { nextTick } from 'vue'
|
|
65
|
+
|
|
66
|
+
const props = defineProps({
|
|
66
67
|
readOnly: {
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
type: Boolean,
|
|
69
|
+
default: false,
|
|
69
70
|
},
|
|
70
71
|
row: {
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
type: Object,
|
|
73
|
+
default: () => ({}),
|
|
73
74
|
},
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
const formRef = ref()
|
|
77
|
-
const row1Ref = ref()
|
|
78
|
-
const row2Ref = ref()
|
|
79
|
-
const row3Ref = ref()
|
|
80
|
-
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const formRef = ref()
|
|
78
|
+
const row1Ref = ref()
|
|
79
|
+
const row2Ref = ref()
|
|
80
|
+
const row3Ref = ref()
|
|
81
|
+
|
|
82
|
+
const state = reactive({
|
|
81
83
|
formData: {},
|
|
82
84
|
readOnly: props.readOnly,
|
|
83
|
-
model: props.readOnly ?
|
|
84
|
-
//
|
|
85
|
+
model: props.readOnly ? '' : 'vertical',
|
|
86
|
+
// 使用 cloneDeep 进行深拷贝,保留函数
|
|
85
87
|
rows: [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
88
|
+
[
|
|
89
|
+
{
|
|
90
|
+
key: 'confidence',
|
|
91
|
+
label: '置信度',
|
|
92
|
+
value: 'aaa',
|
|
93
|
+
component: ElInput,
|
|
94
|
+
params: {
|
|
95
|
+
rules: [
|
|
96
|
+
{
|
|
97
|
+
required: true,
|
|
98
|
+
message: '请输入',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
key: 'iou',
|
|
105
|
+
label: '交并比',
|
|
106
|
+
value: '',
|
|
107
|
+
component: ElInput,
|
|
108
|
+
params: {
|
|
109
|
+
'v-length.range': {
|
|
110
|
+
min: 0,
|
|
111
|
+
max: 1,
|
|
112
|
+
maxLength: 3,
|
|
104
113
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
maxLength: 3 },
|
|
115
|
-
rules: [
|
|
116
|
-
{
|
|
117
|
-
required: true,
|
|
118
|
-
message: "请输入",
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
],
|
|
114
|
+
rules: [
|
|
115
|
+
{
|
|
116
|
+
required: true,
|
|
117
|
+
message: '请输入',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
124
123
|
],
|
|
125
124
|
rows2: [
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
rules: [
|
|
139
|
-
{
|
|
140
|
-
required: true,
|
|
141
|
-
message: "请输入",
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
},
|
|
125
|
+
[
|
|
126
|
+
{
|
|
127
|
+
key: 'timeInterval',
|
|
128
|
+
label: '时间间隔(秒)',
|
|
129
|
+
value: '',
|
|
130
|
+
component: ElInput,
|
|
131
|
+
params: {
|
|
132
|
+
'v-length.range': {
|
|
133
|
+
min: 0,
|
|
134
|
+
max: 6000,
|
|
135
|
+
int: true,
|
|
145
136
|
},
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
137
|
+
rules: [
|
|
138
|
+
{
|
|
139
|
+
required: true,
|
|
140
|
+
message: '请输入',
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
key: 'stuck_threshold',
|
|
147
|
+
label: '视频帧卡顿(秒)',
|
|
148
|
+
value: '',
|
|
149
|
+
component: ElInput,
|
|
150
|
+
params: {
|
|
151
|
+
'v-length.range': {
|
|
152
|
+
min: 0,
|
|
153
|
+
max: 1000,
|
|
154
|
+
int: true,
|
|
164
155
|
},
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
156
|
+
rules: [
|
|
157
|
+
{
|
|
158
|
+
required: true,
|
|
159
|
+
message: '请输入',
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
[
|
|
166
|
+
{
|
|
167
|
+
key: 'max_retries',
|
|
168
|
+
label: '最大重连次数',
|
|
169
|
+
value: '',
|
|
170
|
+
component: ElInput,
|
|
171
|
+
params: {
|
|
172
|
+
'v-length.range': {
|
|
173
|
+
min: 0,
|
|
174
|
+
max: 100,
|
|
175
|
+
int: true,
|
|
185
176
|
},
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
177
|
+
rules: [
|
|
178
|
+
{
|
|
179
|
+
required: true,
|
|
180
|
+
message: '请输入',
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
value: ' ',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
190
189
|
],
|
|
191
190
|
rows3: [
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
191
|
+
[
|
|
192
|
+
{
|
|
193
|
+
key: 'save_video',
|
|
194
|
+
label: '是否保存视频',
|
|
195
|
+
value: '1',
|
|
196
|
+
component: ElRadioGroup,
|
|
197
|
+
params: {
|
|
198
|
+
rules: [
|
|
199
|
+
{
|
|
200
|
+
required: true,
|
|
201
|
+
message: '请选择',
|
|
202
|
+
trigger: 'change',
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
options: [
|
|
206
|
+
{
|
|
196
207
|
value: '1',
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
},
|
|
208
|
+
label: '是',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
value: '0',
|
|
212
|
+
label: '否',
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
key: 'pre_buffer_second',
|
|
219
|
+
label: '帧前缓存(秒)',
|
|
220
|
+
value: '',
|
|
221
|
+
component: ElInput,
|
|
222
|
+
params: {
|
|
223
|
+
'v-length.range': {
|
|
224
|
+
min: 0,
|
|
225
|
+
max: 1000,
|
|
226
|
+
int: true,
|
|
217
227
|
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
228
|
+
rules: [
|
|
229
|
+
{
|
|
230
|
+
required: true,
|
|
231
|
+
message: '请输入',
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
[
|
|
238
|
+
{
|
|
239
|
+
key: 'det_area_mode',
|
|
240
|
+
label: '检测区域工作模式',
|
|
241
|
+
value: 'normal',
|
|
242
|
+
component: ElRadioGroup,
|
|
243
|
+
events: {
|
|
244
|
+
change: detAreaModeChange,
|
|
245
|
+
},
|
|
246
|
+
params: {
|
|
247
|
+
rules: [
|
|
248
|
+
{
|
|
249
|
+
required: true,
|
|
250
|
+
message: '请选择',
|
|
251
|
+
trigger: 'change',
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
options: [
|
|
255
|
+
{
|
|
242
256
|
value: 'normal',
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
},
|
|
254
|
-
],
|
|
255
|
-
options: [
|
|
256
|
-
{
|
|
257
|
-
value: 'normal',
|
|
258
|
-
label: '常规检测(normal)',
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
value: 'abnormal',
|
|
262
|
-
label: '非常规检测(abnormal)',
|
|
263
|
-
},
|
|
264
|
-
]
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
],
|
|
257
|
+
label: '常规检测(normal)',
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
value: 'abnormal',
|
|
261
|
+
label: '非常规检测(abnormal)',
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
],
|
|
268
267
|
],
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
function detAreaModeChange(value: any) {
|
|
272
|
-
if(value === 'abnormal') {
|
|
273
|
-
|
|
274
|
-
state.rows3.pop()
|
|
275
|
-
}
|
|
276
|
-
state.rows3.push([{
|
|
277
|
-
key: "det_area_json",
|
|
278
|
-
label: "感兴趣区域",
|
|
279
|
-
value: '',
|
|
280
|
-
component: ElInput,
|
|
281
|
-
span: 6,
|
|
282
|
-
events: {
|
|
283
|
-
change: (value) => getAreasHandler(value),
|
|
284
|
-
},
|
|
285
|
-
params: {
|
|
286
|
-
rules: [
|
|
287
|
-
{
|
|
288
|
-
required: true,
|
|
289
|
-
message: "请输入",
|
|
290
|
-
trigger: 'change'
|
|
291
|
-
},
|
|
292
|
-
],
|
|
293
|
-
},
|
|
294
|
-
}, {value: ' '}])
|
|
295
|
-
}else {
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
function detAreaModeChange(value: any) {
|
|
271
|
+
if (value === 'abnormal') {
|
|
272
|
+
if (state.rows3?.length && state.rows3[state.rows3.length - 1]?.[0]?.key === 'det_area_json') {
|
|
296
273
|
state.rows3.pop()
|
|
274
|
+
}
|
|
275
|
+
state.rows3.push([
|
|
276
|
+
{
|
|
277
|
+
key: 'det_area_json',
|
|
278
|
+
label: '感兴趣区域',
|
|
279
|
+
value: '',
|
|
280
|
+
component: ElInput,
|
|
281
|
+
span: 6,
|
|
282
|
+
events: {
|
|
283
|
+
change: (value) => getAreasHandler(value),
|
|
284
|
+
},
|
|
285
|
+
params: {
|
|
286
|
+
rules: [
|
|
287
|
+
{
|
|
288
|
+
required: true,
|
|
289
|
+
message: '请输入',
|
|
290
|
+
trigger: 'change',
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
{ value: ' ' },
|
|
296
|
+
])
|
|
297
|
+
} else {
|
|
298
|
+
state.rows3.pop()
|
|
297
299
|
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function getAreasHandler(value: any) {
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function getAreasHandler(value: any) {
|
|
301
303
|
state.rows3[state.rows3.length - 1][0].value = value
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
async function getFormData() {
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* 保存
|
|
308
|
+
*/
|
|
309
|
+
async function getFormData() {
|
|
308
310
|
try {
|
|
309
|
-
|
|
311
|
+
await formRef.value.validate()
|
|
310
312
|
} catch (error: any) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
console.log(error)
|
|
314
|
+
ElMessage.error('表单校验失败')
|
|
315
|
+
state.formData = {}
|
|
316
|
+
return false
|
|
315
317
|
}
|
|
316
|
-
const data1 = row1Ref.value?.getKeyValuePairs?.(state.rows)
|
|
317
|
-
const data2 = row2Ref.value?.getKeyValuePairs?.(state.rows2)
|
|
318
|
-
const data3 = row3Ref.value?.getKeyValuePairs?.(state.rows3)
|
|
318
|
+
const data1 = row1Ref.value?.getKeyValuePairs?.(state.rows)
|
|
319
|
+
const data2 = row2Ref.value?.getKeyValuePairs?.(state.rows2)
|
|
320
|
+
const data3 = row3Ref.value?.getKeyValuePairs?.(state.rows3)
|
|
319
321
|
const data = { ...data1, ...data2, ...data3 }
|
|
320
|
-
state.formData = data
|
|
321
|
-
ElMessage.success('表单校验成功')
|
|
322
|
-
return data
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
h3 {
|
|
341
|
-
margin: 0 0 20px 0;
|
|
342
|
-
color: #333;
|
|
322
|
+
state.formData = data
|
|
323
|
+
ElMessage.success('表单校验成功')
|
|
324
|
+
return data
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 重置表单
|
|
329
|
+
*/
|
|
330
|
+
async function resetFormData() {
|
|
331
|
+
// 使用组件内置的 resetForm 方法
|
|
332
|
+
row1Ref.value?.resetForm?.()
|
|
333
|
+
row2Ref.value?.resetForm?.()
|
|
334
|
+
row3Ref.value?.resetForm?.()
|
|
335
|
+
setTimeout(()=>{
|
|
336
|
+
// 重置表单验证状态
|
|
337
|
+
formRef.value?.clearValidate?.()
|
|
338
|
+
// 清空结果显示
|
|
339
|
+
state.formData = {}
|
|
340
|
+
ElMessage.success('表单重置成功')
|
|
341
|
+
}, 0)
|
|
343
342
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* 重置表单数据到指定值或默认值
|
|
346
|
+
* @param targetRows 要重置的rows数据
|
|
347
|
+
* @param defaultValues 默认值对象,key为字段key,value为默认值
|
|
348
|
+
*/
|
|
349
|
+
function resetFormToDefaults(targetRows: any[], defaultValues: Record<string, any> = {}) {
|
|
350
|
+
for (let rowIndex = 0; rowIndex < targetRows.length; rowIndex++) {
|
|
351
|
+
const row = targetRows[rowIndex]
|
|
352
|
+
for (let colIndex = 0; colIndex < row.length; colIndex++) {
|
|
353
|
+
const item = row[colIndex]
|
|
354
|
+
if (item.key) {
|
|
355
|
+
// 如果提供了默认值,使用默认值,否则根据组件类型重置
|
|
356
|
+
if (defaultValues.hasOwnProperty(item.key)) {
|
|
357
|
+
item.value = cloneDeep(defaultValues[item.key])
|
|
358
|
+
} else {
|
|
359
|
+
// 根据组件类型或当前值类型设置默认值
|
|
360
|
+
if (Array.isArray(item.value)) {
|
|
361
|
+
item.value = []
|
|
362
|
+
} else if (typeof item.value === 'number') {
|
|
363
|
+
item.value = 0
|
|
364
|
+
} else if (typeof item.value === 'boolean') {
|
|
365
|
+
item.value = false
|
|
366
|
+
} else {
|
|
367
|
+
item.value = ''
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// 重置删除的文件列表
|
|
372
|
+
if (item.delValue !== undefined) {
|
|
373
|
+
item.delValue = defaultValues[`${item.key}_delValue`]
|
|
374
|
+
? cloneDeep(defaultValues[`${item.key}_delValue`])
|
|
375
|
+
: []
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// 检查子项
|
|
380
|
+
if (item.children && Array.isArray(item.children)) {
|
|
381
|
+
for (let childIndex = 0; childIndex < item.children.length; childIndex++) {
|
|
382
|
+
const child = item.children[childIndex]
|
|
383
|
+
if (child.key) {
|
|
384
|
+
// 重置子项
|
|
385
|
+
if (defaultValues.hasOwnProperty(child.key)) {
|
|
386
|
+
child.value = cloneDeep(defaultValues[child.key])
|
|
387
|
+
} else {
|
|
388
|
+
if (Array.isArray(child.value)) {
|
|
389
|
+
child.value = []
|
|
390
|
+
} else if (typeof child.value === 'number') {
|
|
391
|
+
child.value = 0
|
|
392
|
+
} else if (typeof child.value === 'boolean') {
|
|
393
|
+
child.value = false
|
|
394
|
+
} else {
|
|
395
|
+
child.value = ''
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// 重置子项删除的文件列表
|
|
400
|
+
if (child.delValue !== undefined) {
|
|
401
|
+
child.delValue = defaultValues[`${child.key}_delValue`]
|
|
402
|
+
? cloneDeep(defaultValues[`${child.key}_delValue`])
|
|
403
|
+
: []
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
349
410
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* 批量设置表单值
|
|
414
|
+
* @param targetRows 要设置的rows数据
|
|
415
|
+
* @param values 值对象,key为字段key,value为要设置的值
|
|
416
|
+
*/
|
|
417
|
+
function setFormValues(targetRows: any[], values: Record<string, any> = {}) {
|
|
418
|
+
for (let rowIndex = 0; rowIndex < targetRows.length; rowIndex++) {
|
|
419
|
+
const row = targetRows[rowIndex]
|
|
420
|
+
for (let colIndex = 0; colIndex < row.length; colIndex++) {
|
|
421
|
+
const item = row[colIndex]
|
|
422
|
+
if (item.key && values.hasOwnProperty(item.key)) {
|
|
423
|
+
item.value = cloneDeep(values[item.key])
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// 检查子项
|
|
427
|
+
if (item.children && Array.isArray(item.children)) {
|
|
428
|
+
for (let childIndex = 0; childIndex < item.children.length; childIndex++) {
|
|
429
|
+
const child = item.children[childIndex]
|
|
430
|
+
if (child.key && values.hasOwnProperty(child.key)) {
|
|
431
|
+
child.value = cloneDeep(values[child.key])
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
364
437
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* 重置所有表单到默认值(新的重置方法)
|
|
441
|
+
* @param customDefaults 自定义默认值
|
|
442
|
+
*/
|
|
443
|
+
function resetAllFormsToDefaults(customDefaults: Record<string, any> = {}) {
|
|
444
|
+
// 重置第一个表单
|
|
445
|
+
resetFormToDefaults(state.rows, customDefaults)
|
|
446
|
+
|
|
447
|
+
// 重置第二个表单
|
|
448
|
+
resetFormToDefaults(state.rows2, customDefaults)
|
|
449
|
+
|
|
450
|
+
// 重置第三个表单
|
|
451
|
+
resetFormToDefaults(state.rows3, customDefaults)
|
|
452
|
+
|
|
453
|
+
// 重置表单验证状态
|
|
454
|
+
formRef.value?.clearValidate?.()
|
|
455
|
+
|
|
456
|
+
// 清空结果显示
|
|
457
|
+
state.formData = {}
|
|
458
|
+
|
|
459
|
+
ElMessage.success('表单重置到默认值成功')
|
|
368
460
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
461
|
+
</script>
|
|
462
|
+
|
|
463
|
+
<style lang="scss" scoped>
|
|
464
|
+
.demo-container {
|
|
465
|
+
padding: 20px;
|
|
466
|
+
max-width: 1400px;
|
|
467
|
+
margin: 0 auto;
|
|
373
468
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
.data-card {
|
|
393
|
-
margin-top: 20px;
|
|
394
|
-
|
|
395
|
-
.card-header {
|
|
396
|
-
display: flex;
|
|
397
|
-
justify-content: space-between;
|
|
398
|
-
align-items: center;
|
|
469
|
+
|
|
470
|
+
.control-panel {
|
|
471
|
+
background: #f5f5f5;
|
|
472
|
+
padding: 20px;
|
|
473
|
+
border-radius: 8px;
|
|
474
|
+
margin-bottom: 20px;
|
|
475
|
+
|
|
476
|
+
h3 {
|
|
477
|
+
margin: 0 0 20px 0;
|
|
478
|
+
color: #333;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
h4 {
|
|
482
|
+
margin: 15px 0 10px 0;
|
|
483
|
+
color: #666;
|
|
484
|
+
font-size: 14px;
|
|
485
|
+
}
|
|
399
486
|
}
|
|
400
|
-
|
|
401
|
-
.
|
|
402
|
-
|
|
487
|
+
|
|
488
|
+
.config-section,
|
|
489
|
+
.upload-section,
|
|
490
|
+
.action-section {
|
|
491
|
+
margin-bottom: 20px;
|
|
403
492
|
padding: 15px;
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
493
|
+
background: white;
|
|
494
|
+
border-radius: 6px;
|
|
495
|
+
border: 1px solid #e0e0e0;
|
|
496
|
+
|
|
497
|
+
.config-select {
|
|
498
|
+
width: 300px;
|
|
499
|
+
margin-right: 10px;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
input[type='file'] {
|
|
503
|
+
margin-right: 10px;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
.el-button {
|
|
507
|
+
margin-right: 10px;
|
|
508
|
+
margin-bottom: 5px;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
.form-container {
|
|
513
|
+
background: white;
|
|
514
|
+
padding: 20px;
|
|
515
|
+
border-radius: 8px;
|
|
516
|
+
border: 1px solid #e0e0e0;
|
|
517
|
+
margin-bottom: 20px;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
.empty-state {
|
|
521
|
+
text-align: center;
|
|
522
|
+
padding: 60px 20px;
|
|
523
|
+
background: white;
|
|
524
|
+
border-radius: 8px;
|
|
525
|
+
border: 1px solid #e0e0e0;
|
|
409
526
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
527
|
+
|
|
528
|
+
.data-card {
|
|
529
|
+
margin-top: 20px;
|
|
530
|
+
|
|
531
|
+
.card-header {
|
|
532
|
+
display: flex;
|
|
533
|
+
justify-content: space-between;
|
|
534
|
+
align-items: center;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
.form-data-display {
|
|
538
|
+
background-color: #f5f7fa;
|
|
539
|
+
padding: 15px;
|
|
540
|
+
border-radius: 4px;
|
|
541
|
+
font-size: 12px;
|
|
542
|
+
line-height: 1.5;
|
|
543
|
+
max-height: 400px;
|
|
544
|
+
overflow-y: auto;
|
|
545
|
+
}
|
|
416
546
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
547
|
+
|
|
548
|
+
@media (max-width: 768px) {
|
|
549
|
+
.config-select {
|
|
550
|
+
width: 100% !important;
|
|
551
|
+
margin-bottom: 10px;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
.el-button {
|
|
555
|
+
width: 100%;
|
|
556
|
+
margin-bottom: 10px;
|
|
557
|
+
}
|
|
421
558
|
}
|
|
422
|
-
|
|
423
|
-
|
|
559
|
+
</style>
|
|
560
|
+
|