hookehuyr

✨ feat(文件和图片上传组件): 表单数据默认值,因为是自定义绑定数据,需要手动同步到提交结构上。

1 <!-- 1 <!--
2 * @Date: 2022-08-31 16:16:49 2 * @Date: 2022-08-31 16:16:49
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-08-12 18:12:00 4 + * @LastEditTime: 2024-11-14 13:05:31
5 * @FilePath: /data-table/src/components/FileUploaderField/index.vue 5 * @FilePath: /data-table/src/components/FileUploaderField/index.vue
6 * @Description: 文件上传控件 6 * @Description: 文件上传控件
7 --> 7 -->
...@@ -118,6 +118,18 @@ onMounted(() => { ...@@ -118,6 +118,18 @@ onMounted(() => {
118 // 非只读模式并且有默认值时 118 // 非只读模式并且有默认值时
119 if (!props.item.component_props.readonly && props.item.component_props.default) { 119 if (!props.item.component_props.readonly && props.item.component_props.default) {
120 fileList.value = default_file.value; 120 fileList.value = default_file.value;
121 + // TAG:把存在的默认值同步到表单数据列表里
122 + // 过滤非包含URL的文件
123 + fileList.value = fileList.value.filter((item) => {
124 + if (item.url) return item;
125 + });
126 + props.item.value = {
127 + key: "file_uploader",
128 + filed_name: props.item.key,
129 + value: fileList.value,
130 + };
131 + // 完整数据回调到表单上
132 + emit("active", props.item.value);
121 } 133 }
122 }) 134 })
123 135
......
1 <!-- 1 <!--
2 * @Date: 2022-08-31 16:16:49 2 * @Date: 2022-08-31 16:16:49
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-08-07 18:14:21 4 + * @LastEditTime: 2024-11-14 13:06:43
5 * @FilePath: /data-table/src/components/ImageUploaderField/index.vue 5 * @FilePath: /data-table/src/components/ImageUploaderField/index.vue
6 * @Description: 图片上传控件 6 * @Description: 图片上传控件
7 --> 7 -->
...@@ -102,7 +102,19 @@ onMounted(() => { ...@@ -102,7 +102,19 @@ onMounted(() => {
102 if (!props.item.component_props.readonly) { 102 if (!props.item.component_props.readonly) {
103 // 默认图片显示 103 // 默认图片显示
104 if (default_tmp.value && default_tmp.value.length) { 104 if (default_tmp.value && default_tmp.value.length) {
105 - fileList.value = default_tmp.value 105 + fileList.value = default_tmp.value;
106 + // TAG:把存在的默认值同步到表单数据列表里
107 + // 过滤非包含URL的文件
108 + fileList.value = fileList.value.filter((item) => {
109 + if (item.url) return item;
110 + });
111 + props.item.value = {
112 + key: "image_uploader",
113 + filed_name: props.item.key,
114 + value: fileList.value,
115 + };
116 + // 完整数据回调到表单上
117 + emit("active", props.item.value);
106 } 118 }
107 } else { 119 } else {
108 // 默认图片显示 120 // 默认图片显示
......