From fa2959515e81b4224ced33863d1e3f9f93e23f57 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 16 Apr 2025 08:49:33 +0800 Subject: [PATCH] no message --- .../js/components/PreviewImage/state.vue | 11 ++++- resources/assets/js/store/actions.js | 43 +++++++++++++++++++ resources/assets/js/store/state.js | 1 + resources/mobile | 2 +- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/resources/assets/js/components/PreviewImage/state.vue b/resources/assets/js/components/PreviewImage/state.vue index 6292a53fb..8a1ded73d 100644 --- a/resources/assets/js/components/PreviewImage/state.vue +++ b/resources/assets/js/components/PreviewImage/state.vue @@ -14,6 +14,7 @@ export default { ...mapState([ 'previewImageIndex', 'previewImageList', + 'previewImageBase64', ]), }, data() { @@ -92,7 +93,15 @@ export default { $A.eeuiAppSendMessage({ action: 'picturePreview', position: index, - paths + paths: paths.map(item => { + if (!$A.isJson(item)) { + item = {path: item} + } + if (this.previewImageBase64.has(item.path)) { + item.preview = this.previewImageBase64.get(item.path); + } + return item + }) }); } else if ($A.isElectron) { this.$Electron.sendMessage('openMediaViewer', { diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index e5b38d602..4185b66a0 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -3979,6 +3979,49 @@ export default { state.previewImageList = data.list; }, + /** + * 预览图片缓存 base64 + * @param state + * @param imgElement + */ + previewCacheBase64({state}, imgElement) { + try { + const src = $A.thumbRestore(imgElement.currentSrc || imgElement.src); + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + + // 计算缩放比例,保持原有比例,确保最长边不超过 200 + const MAX_SIZE = 200; + const originalWidth = imgElement.naturalWidth; + const originalHeight = imgElement.naturalHeight; + let width = originalWidth; + let height = originalHeight; + if (originalWidth > originalHeight && originalWidth > MAX_SIZE) { + width = MAX_SIZE; + height = Math.floor(originalHeight * (MAX_SIZE / originalWidth)); + } else if (originalHeight > MAX_SIZE) { + height = MAX_SIZE; + width = Math.floor(originalWidth * (MAX_SIZE / originalHeight)); + } + + canvas.width = width; + canvas.height = height; + ctx.drawImage(imgElement, 0, 0); + const base64 = canvas.toDataURL('image/jpeg', 0.8); + state.previewImageBase64.set(src, base64); + // + if (state.previewImageBase64.size >= 10) { + const keys = Array.from(state.previewImageBase64.keys()); + const removeCount = keys.length - 10; + for (let i = 0; i < removeCount; i++) { + state.previewImageBase64.delete(keys[i]); + } + } + } catch (error) { + console.log(error); + } + }, + /** * 播放音频 * @param state diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index 527fd85bb..6f32d9374 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -225,6 +225,7 @@ export default { // 预览图片 previewImageIndex: 0, previewImageList: [], + previewImageBase64: new Map(), // 工作报告未读数量 reportUnreadNumber: 0, diff --git a/resources/mobile b/resources/mobile index ca3803c8f..80267d119 160000 --- a/resources/mobile +++ b/resources/mobile @@ -1 +1 @@ -Subproject commit ca3803c8f27b96a955585a042102621249e08392 +Subproject commit 80267d1193fc68dbd4966c4232e716a35ba51c0e