lu-lowcode-package-form 0.9.2 → 0.9.3
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/index.cjs.js +64 -64
- package/dist/index.es.js +5146 -5135
- package/package.json +1 -1
- package/src/components/field/upload/upload-image.jsx +40 -14
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { Upload as OriginalUpload, Button, Image, Spin } from "antd";
|
|
|
2
2
|
|
|
3
3
|
import { BaseWrapper } from "../base.jsx"
|
|
4
4
|
import { DeleteOutlined, EyeOutlined, PlusOutlined } from "@ant-design/icons";
|
|
5
|
-
import React, { useEffect, useState } from "react";
|
|
5
|
+
import React, { useEffect, useRef, useState, version } from "react";
|
|
6
6
|
|
|
7
7
|
const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
|
8
8
|
useEffect(() => {
|
|
@@ -17,8 +17,19 @@ const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
let _fileList = []
|
|
21
|
+
if (Array.isArray(value))
|
|
22
|
+
for (let i = 0; i < value.length; i++) {
|
|
23
|
+
let file = value[i]
|
|
24
|
+
var oldfile = fileMap.current.find((item) => item.uid === file.uid)
|
|
25
|
+
console.log("set file", file)
|
|
26
|
+
console.log("set oldfile", oldfile)
|
|
27
|
+
if (!oldfile ||( (oldfile.version||0) < (file.version||0 )))
|
|
28
|
+
_fileList.push(file)
|
|
29
|
+
else _fileList.push(oldfile)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setFileList(_fileList)
|
|
22
33
|
}
|
|
23
34
|
}, [value]);
|
|
24
35
|
maxCount = maxCount || 9;
|
|
@@ -26,6 +37,7 @@ const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
|
|
26
37
|
const [previewImage, setPreviewImage] = useState('');
|
|
27
38
|
const [previewImageIndex, setPreviewImageIndex] = useState(0);
|
|
28
39
|
const [previewOpen, setPreviewOpen] = useState(false);
|
|
40
|
+
const fileMap = useRef([]);
|
|
29
41
|
|
|
30
42
|
const getBase64 = (file) =>
|
|
31
43
|
new Promise((resolve, reject) => {
|
|
@@ -59,26 +71,40 @@ const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
|
|
59
71
|
|
|
60
72
|
);
|
|
61
73
|
const handleChange = async ({ fileList: newFileList }) => {
|
|
74
|
+
|
|
75
|
+
let handleFileList = []
|
|
76
|
+
|
|
62
77
|
for (let i = 0; i < newFileList.length; i++) {
|
|
63
78
|
var file = newFileList[i];
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
file.version = new Date().getTime()
|
|
80
|
+
var oldfile = fileMap.current.find((item) => item.uid === file.uid)
|
|
81
|
+
if (oldfile && oldfile.status != "uploading") {
|
|
82
|
+
handleFileList.push(oldfile)
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (file.status == "done" && file.response) {
|
|
86
|
+
file.url = file.response;
|
|
87
|
+
}
|
|
88
|
+
if (!file.url && file.originFileObj)
|
|
89
|
+
file.base64 = await getBase64(file.originFileObj)
|
|
90
|
+
newFileList[i] = file
|
|
91
|
+
handleFileList.push(file)
|
|
66
92
|
}
|
|
67
|
-
if (!file.url && file.originFileObj)
|
|
68
|
-
file.base64 = await getBase64(file.originFileObj)
|
|
69
|
-
newFileList[i] = file
|
|
70
93
|
}
|
|
71
94
|
console.log("newFileList", JSON.parse(JSON.stringify(newFileList)))
|
|
72
|
-
|
|
95
|
+
console.log("handleFileList", JSON.parse(JSON.stringify(handleFileList)))
|
|
96
|
+
fileMap.current = handleFileList
|
|
97
|
+
setFileList(handleFileList);
|
|
98
|
+
onChange(handleFileList.map((file) => {
|
|
73
99
|
return {
|
|
74
100
|
uid: file.uid,
|
|
75
101
|
name: file.name,
|
|
76
102
|
status: file.status,
|
|
77
103
|
url: file.url || file.response || "",
|
|
78
104
|
error: file.error,
|
|
105
|
+
version: file.version || 0
|
|
79
106
|
}
|
|
80
107
|
}))
|
|
81
|
-
setFileList(newFileList);
|
|
82
108
|
}
|
|
83
109
|
return (
|
|
84
110
|
<BaseWrapper {...props}>
|
|
@@ -105,13 +131,13 @@ const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
|
|
105
131
|
let index = fileList.findIndex((item) => item.uid === file.uid)
|
|
106
132
|
return (
|
|
107
133
|
<>
|
|
108
|
-
<div key={`file-${file.uid}`} className={"fgroup fw-full fh-full fbg-transparent fborder frounded fflex fitems-center fjustify-center foverflow-hidden fcursor-pointer frelative" + (file.status == "error" ?" fborder-red-500":"")}>
|
|
134
|
+
<div key={`file-${file.uid}`} className={"fgroup fw-full fh-full fbg-transparent fborder frounded fflex fitems-center fjustify-center foverflow-hidden fcursor-pointer frelative" + (file.status == "error" ? " fborder-red-500" : "")}>
|
|
109
135
|
<div className=" fhidden fabsolute fw-full fh-full fbg-gray-900 fbg-opacity-50 fitems-center fjustify-center fz-10 group-hover:fflex ftext-white ftext-lg fgap-2">
|
|
110
|
-
|
|
136
|
+
{file.status == "done" && <EyeOutlined onClick={() => { handlePreview(file, index) }} className="hover:ftext-gray-200" />}
|
|
111
137
|
<DeleteOutlined onClick={() => { handleDelete(file, index) }} className="hover:ftext-gray-200" />
|
|
112
|
-
|
|
138
|
+
|
|
113
139
|
</div>
|
|
114
|
-
{file.status == "uploading" &&
|
|
140
|
+
{file.status == "uploading" && <div className=" fw-full fh-full fflex fitems-center fjustify-center fabsolute ftop-0 fleft-0 "><Spin></Spin></div>}
|
|
115
141
|
<img src={file.url || file.base64} alt="Example Image" class="fmax-w-full fmax-h-full fobject-contain " />
|
|
116
142
|
</div>
|
|
117
143
|
</>
|