hookehuyr

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

<!--
* @Date: 2022-08-31 16:16:49
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-12 18:12:00
* @LastEditTime: 2024-11-14 13:05:31
* @FilePath: /data-table/src/components/FileUploaderField/index.vue
* @Description: 文件上传控件
-->
......@@ -118,6 +118,18 @@ onMounted(() => {
// 非只读模式并且有默认值时
if (!props.item.component_props.readonly && props.item.component_props.default) {
fileList.value = default_file.value;
// TAG:把存在的默认值同步到表单数据列表里
// 过滤非包含URL的文件
fileList.value = fileList.value.filter((item) => {
if (item.url) return item;
});
props.item.value = {
key: "file_uploader",
filed_name: props.item.key,
value: fileList.value,
};
// 完整数据回调到表单上
emit("active", props.item.value);
}
})
......
<!--
* @Date: 2022-08-31 16:16:49
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-07 18:14:21
* @LastEditTime: 2024-11-14 13:06:43
* @FilePath: /data-table/src/components/ImageUploaderField/index.vue
* @Description: 图片上传控件
-->
......@@ -102,7 +102,19 @@ onMounted(() => {
if (!props.item.component_props.readonly) {
// 默认图片显示
if (default_tmp.value && default_tmp.value.length) {
fileList.value = default_tmp.value
fileList.value = default_tmp.value;
// TAG:把存在的默认值同步到表单数据列表里
// 过滤非包含URL的文件
fileList.value = fileList.value.filter((item) => {
if (item.url) return item;
});
props.item.value = {
key: "image_uploader",
filed_name: props.item.key,
value: fileList.value,
};
// 完整数据回调到表单上
emit("active", props.item.value);
}
} else {
// 默认图片显示
......