From b187b6cf678f0e6b17e3612c5681ecd35434f15a Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 25 六月 2025 10:36:11 +0800
Subject: [PATCH] 任务管理界面新增巡查单据下载功能
---
src/views/fysp/check/components/ArbitraryPhoto.vue | 36 +++++++++++++++++++++++++++++++++++-
1 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/src/views/fysp/check/components/ArbitraryPhoto.vue b/src/views/fysp/check/components/ArbitraryPhoto.vue
index 55b11a5..703ceda 100644
--- a/src/views/fysp/check/components/ArbitraryPhoto.vue
+++ b/src/views/fysp/check/components/ArbitraryPhoto.vue
@@ -74,6 +74,7 @@
// ],
closeContextMenuListenr: undefined,
// 鍙抽敭閫変腑鐨勫浘鐗�
+ selectedFileElement: undefined,
selectedFile: undefined,
selectedIndex: undefined,
selectedTypeId: undefined
@@ -94,7 +95,7 @@
};
});
return [
- // { label: '澶嶅埗鍥剧墖', action: 'copy' },
+ // { label: '澶嶅埗鍒板壀璐存澘', action: 'copy' },
{ label: '绉诲姩鍒�', children: items }
];
}
@@ -158,6 +159,7 @@
left: `${event.clientX}px`,
top: `${event.clientY}px`
};
+ this.selectedFileElement = event.target;
this.selectedTypeId = typeId;
this.selectedIndex = index;
this.selectedFile = this.typesMap.get(typeId)[index];
@@ -168,6 +170,7 @@
handleMenuItem(item) {
switch (item.action) {
case 'copy':
+ this.drawImageToCanvas();
break;
case 'move':
this.selectedFile.data.businesstypeid = item.value;
@@ -217,6 +220,37 @@
// }
// this.selectedFile.loading = false;
// }, 2000);
+ },
+ drawImageToCanvas() {
+ const canvas = document.createElement('canvas');
+ const ctx = canvas.getContext('2d');
+ const img = this.selectedFileElement; // 鑾峰彇DOM寮曠敤
+ // img.crossOrigin = 'Anonymous';
+ canvas.width = img.naturalWidth;
+ canvas.height = img.naturalHeight;
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
+ // this.copyCanvasToClipboard(canvas);
+ const dataUrl = canvas.toDataURL('image/png'); // 鍙互閫夋嫨鍏朵粬鏍煎紡濡�'image/jpeg'
+ // 鍒涘缓涓�涓复鏃剁殑textarea鍏冪礌鏉ュ鍒舵枃鏈�
+ const tempTextArea = document.createElement('textarea');
+ document.body.appendChild(tempTextArea);
+ tempTextArea.value = dataUrl;
+ tempTextArea.select();
+ document.execCommand('copy');
+ document.body.removeChild(tempTextArea);
+ },
+ copyCanvasToClipboard(canvas) {
+ canvas.toBlob((blob) => {
+ const item = new ClipboardItem({ 'image/png': blob }); // 浣犲彲浠ユ牴鎹渶瑕佹敼鍙樻牸寮忥紝濡� "image/jpeg"
+ navigator.clipboard.write([item]).then(
+ () => {
+ console.log('Image copied to clipboard');
+ },
+ (err) => {
+ console.error('Could not copy image: ', err);
+ }
+ );
+ }, 'image/png'); // 鍚屾牱锛岃繖閲屼篃鍙互鎸囧畾鍏朵粬鏍煎紡锛屽 'image/jpeg'
}
}
};
--
Gitblit v1.9.3