feat: preview image with pre-cache

This commit is contained in:
zerosoul
2022-06-12 12:13:09 +08:00
parent cf5fdcdbba
commit 86ea895b13
4 changed files with 63 additions and 32 deletions
+5 -4
View File
@@ -20,7 +20,7 @@ export default function Layout({
to = null,
}) {
const { addStageFile } = useUploadFile({ context, id: to });
const messagesContainer = useRef(null);
const messagesContainer = useRef(undefined);
const [previewImage, setPreviewImage] = useState(null);
const { selects, channelsData, contactsData } = useSelector((store) => {
return {
@@ -64,8 +64,8 @@ export default function Layout({
setPreviewImage(null);
};
useEffect(() => {
if (messagesContainer) {
const container = messagesContainer.current;
const container = messagesContainer?.current;
if (container) {
// 点击查看大图
container.addEventListener(
"click",
@@ -76,10 +76,11 @@ export default function Layout({
target.nodeName == "IMG" &&
target.classList.contains("preview")
) {
const thumbnail = target.src;
const originUrl = target.dataset.origin || target.src;
const downloadLink = target.dataset.download || target.src;
const meta = JSON.parse(target.dataset.meta || "{}");
setPreviewImage({ originUrl, downloadLink, ...meta });
setPreviewImage({ thumbnail, originUrl, downloadLink, ...meta });
}
},
true