hookehuyr

group组件删除和提交逻辑调整

...@@ -77,8 +77,10 @@ declare module '@vue/runtime-core' { ...@@ -77,8 +77,10 @@ declare module '@vue/runtime-core' {
77 VanSearch: typeof import('vant/es')['Search'] 77 VanSearch: typeof import('vant/es')['Search']
78 VanSwipe: typeof import('vant/es')['Swipe'] 78 VanSwipe: typeof import('vant/es')['Swipe']
79 VanSwipeItem: typeof import('vant/es')['SwipeItem'] 79 VanSwipeItem: typeof import('vant/es')['SwipeItem']
80 + VanTa: typeof import('vant/es')['Ta']
80 VanTab: typeof import('vant/es')['Tab'] 81 VanTab: typeof import('vant/es')['Tab']
81 VanTabs: typeof import('vant/es')['Tabs'] 82 VanTabs: typeof import('vant/es')['Tabs']
83 + VanTag: typeof import('vant/es')['Tag']
82 VanTimePicker: typeof import('vant/es')['TimePicker'] 84 VanTimePicker: typeof import('vant/es')['TimePicker']
83 VanUploader: typeof import('vant/es')['Uploader'] 85 VanUploader: typeof import('vant/es')['Uploader']
84 VideoField: typeof import('./src/components/VideoField/index.vue')['default'] 86 VideoField: typeof import('./src/components/VideoField/index.vue')['default']
......
This diff is collapsed. Click to expand it.
1 <!-- 1 <!--
2 * @Date: 2022-07-18 10:22:22 2 * @Date: 2022-07-18 10:22:22
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-05-29 14:28:37 4 + * @LastEditTime: 2024-06-03 17:06:34
5 * @FilePath: /data-table/src/views/index.vue 5 * @FilePath: /data-table/src/views/index.vue
6 * @Description: 首页 6 * @Description: 首页
7 --> 7 -->
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
25 <van-form @submit="onSubmit" :scroll-to-error="true"> 25 <van-form @submit="onSubmit" :scroll-to-error="true">
26 <van-cell-group :border="false"> 26 <van-cell-group :border="false">
27 <component v-for="(item, index) in formData" :id="item.key" :ref="(el) => setRefMap(el, item)" :key="index" 27 <component v-for="(item, index) in formData" :id="item.key" :ref="(el) => setRefMap(el, item)" :key="index"
28 - :is="item.component" :item="item" @active="onActive" /> 28 + :is="item.component" :item="item" @active="onActive" @remove="onRemove" />
29 </van-cell-group> 29 </van-cell-group>
30 <div v-if="formData.length && PCommit.visible" style="margin: 16px"> 30 <div v-if="formData.length && PCommit.visible" style="margin: 16px">
31 <van-button round block type="primary" native-type="submit" :disabled="submitStatus"> 31 <van-button round block type="primary" native-type="submit" :disabled="submitStatus">
...@@ -253,63 +253,129 @@ onMounted(async () => { ...@@ -253,63 +253,129 @@ onMounted(async () => {
253 // name : "name_41", 253 // name : "name_41",
254 // placeholder : "请输入", 254 // placeholder : "请输入",
255 // readonly : false, 255 // readonly : false,
256 - // required : false, 256 + // required : true,
257 // tag : "tree", 257 // tag : "tree",
258 // unique : false, 258 // unique : false,
259 // }); 259 // });
260 260
261 - // page_form.unshift({ 261 + page_form.unshift({
262 - // data_type : "text", 262 + data_type : "text",
263 - // default : "", 263 + default : "",
264 - // disabled : false, 264 + disabled : false,
265 - // field_id : 1414832, 265 + field_id : 1414832,
266 - // field_name : "field_4", 266 + field_name : "field_4",
267 - // index : 41, 267 + index : 41,
268 - // interaction_type : "h5edit", 268 + interaction_type : "h5edit",
269 - // label : "物品详情", 269 + label : "物品详情",
270 - // name : "name_41", 270 + name : "name_41",
271 - // placeholder : "请输入", 271 + placeholder : "请输入",
272 - // readonly : false, 272 + readonly : false,
273 - // required : false, 273 + required : false,
274 - // tag : "group", 274 + tag : "group",
275 - // unique : false, 275 + unique : false,
276 - // field_groups: [{ 276 + field_groups: [{
277 - // "tag": "input", 277 + "tag": "input",
278 - // "name": "input_21", 278 + "name": "input_21",
279 - // "index": 2, 279 + "index": 2,
280 - // "label": "物品描述", 280 + "label": "物品描述",
281 - // "unique": false, 281 + "unique": false,
282 - // "default": "", 282 + "default": "",
283 - // "disabled": false, 283 + "disabled": false,
284 - // "field_id": 7985071, 284 + "field_id": 7985071,
285 - // "readonly": false, 285 + "readonly": false,
286 - // "required": false, 286 + "required": false,
287 - // "data_type": "text", 287 + "data_type": "text",
288 - // "field_name": "field_21", 288 + "field_name": "field_10",
289 - // "placeholder": "请输入", 289 + "placeholder": "请输入",
290 - // "is_camera_scan": false, 290 + "is_camera_scan": false,
291 - // "camera_scan_type": "", 291 + "camera_scan_type": "",
292 - // "interaction_type": "h5edit", 292 + "interaction_type": "h5edit",
293 - // "is_edit_camera_scan_result": false, 293 + "is_edit_camera_scan_result": false,
294 - // "group_field_name" : "field_4", 294 + "group_field_name" : "field_4",
295 - // },{ 295 + },{
296 - // "tag": "name", 296 + "tag": "gender",
297 - // "name": "name_71", 297 + "name": "gender_3",
298 - // "index": 7, 298 + "note": "",
299 - // "label": "序列号", 299 + "index": 3,
300 - // "unique": false, 300 + "label": "性别",
301 - // "default": "", 301 + "options": [
302 - // "disabled": false, 302 + {
303 - // "field_id": 7995031, 303 + "title": "男",
304 - // "readonly": false, 304 + "value": "男",
305 - // "required": true, 305 + "checked": false,
306 - // "data_type": "text", 306 + "desc_url": "",
307 - // "field_name": "field_91", 307 + "is_input": false,
308 - // "placeholder": "请输入", 308 + "desc_text": "",
309 - // "interaction_type": "h5edit", 309 + "desc_type": "",
310 - // "group_field_name" : "field_4", 310 + "desc_btn_name": "",
311 - // },] 311 + "input_required": false,
312 - // }); 312 + "input_placeholder": "请输入补充信息"
313 + },
314 + {
315 + "title": "女",
316 + "value": "女",
317 + "checked": false,
318 + "desc_url": "",
319 + "is_input": false,
320 + "desc_text": "",
321 + "desc_type": "",
322 + "desc_btn_name": "",
323 + "input_required": false,
324 + "input_placeholder": "请输入补充信息"
325 + }
326 + ],
327 + "disabled": false,
328 + "field_id": 799603,
329 + "required": false,
330 + "data_type": "text",
331 + "direction": "vertical",
332 + "field_name": "field_4",
333 + "option_map": {
334 + "女": {
335 + "title": "女",
336 + "value": "女",
337 + "checked": false,
338 + "desc_url": "",
339 + "is_input": false,
340 + "desc_text": "",
341 + "desc_type": "",
342 + "desc_btn_name": "",
343 + "input_required": false,
344 + "input_placeholder": "请输入补充信息"
345 + },
346 + "男": {
347 + "title": "男",
348 + "value": "男",
349 + "checked": false,
350 + "desc_url": "",
351 + "is_input": false,
352 + "desc_text": "",
353 + "desc_type": "",
354 + "desc_btn_name": "",
355 + "input_required": false,
356 + "input_placeholder": "请输入补充信息"
357 + }
358 + },
359 + "interaction_type": "h5edit"
360 + },]
361 + });
362 +
363 + page_form.push({
364 + "tag": "name",
365 + "name": "name_2",
366 + "index": 2,
367 + "label": "姓名",
368 + "unique": false,
369 + "default": "",
370 + "disabled": false,
371 + "field_id": 799599,
372 + "readonly": false,
373 + "required": true,
374 + "data_type": "text",
375 + "field_name": "field_2",
376 + "placeholder": "请输入",
377 + "interaction_type": "h5edit"
378 + })
313 formData.value = formatData(page_form); 379 formData.value = formatData(page_form);
314 // TODO:再次提交测试, 需要获取原来表单数据 380 // TODO:再次提交测试, 需要获取原来表单数据
315 // formData.value.forEach((item) => { 381 // formData.value.forEach((item) => {
...@@ -645,6 +711,33 @@ const preValidData = (values) => { ...@@ -645,6 +711,33 @@ const preValidData = (values) => {
645 return _.assign(postData.value, rest_data); 711 return _.assign(postData.value, rest_data);
646 } 712 }
647 713
714 +const onRemove = (value) => { // 处理组件删除事件回调, 数据结构是二维数组,删除时返回被删除的一组数据
715 + value[0].forEach(item => {
716 + for (const key in postData.value) {
717 + if (item.key === key) {
718 + delete postData.value[key]; // 删除对应的键值对
719 + }
720 + }
721 + });
722 +}
723 +
724 +const adjGroupData = (values) => { // 调整group组件的数据结构
725 + // let obj = {
726 + // "field_10_group[0]_7653" : "1",
727 + // "field_10_group[1]_4154" : "11",
728 + // "field_11_group[0]_3440" : "2",
729 + // "field_11_group[1]_4282" : "22"
730 + // }
731 +
732 + // let arr = [{
733 + // "field_10": "1",
734 + // "field_11": "2",
735 + // }, {
736 + // "field_10": "11",
737 + // "field_11": "22",
738 + // }]
739 +}
740 +
648 const submitStatus = ref(false); 741 const submitStatus = ref(false);
649 742
650 const onSubmit = async (values) => { 743 const onSubmit = async (values) => {
......