屏幕找图去掉从剪贴板获取图片按钮,添加直接截图获取按钮

This commit is contained in:
fofolee 2025-02-17 15:59:22 +08:00
parent daef39b02a
commit 89a2e07b13
2 changed files with 14 additions and 19 deletions

View File

@ -115,15 +115,15 @@ async function captureScreen(range = "fullscreen") {
}
async function captureScreenToFile(range = "fullscreen", path = null) {
if (!path) return null;
if (!path) return;
const result = await captureScreen(range);
if (!result) return null;
if (!result) return;
fs.writeFileSync(
path,
result.replace("data:image/png;base64,", ""),
"base64"
);
return result;
return;
}
async function captureScreenToClipboard(range = "fullscreen") {

View File

@ -26,9 +26,7 @@
<template v-else>
<div class="upload-placeholder">
<q-icon name="add_photo_alternate" size="48px" color="grey-6" />
<div class="text-grey-6 q-mt-sm">
点击上传或粘贴图片<br />支持从剪贴板读取
</div>
<div class="text-grey-6 q-mt-sm">点击上传或粘贴图片</div>
</div>
</template>
</div>
@ -37,16 +35,16 @@
<!-- 配置区域 -->
<div class="col-12 col-sm-4">
<div class="row">
<!-- 从剪贴板读取按钮 -->
<!-- 截图按钮 -->
<div class="col-12">
<q-btn
outline
color="primary"
class="full-width"
@click="pasteFromClipboard"
@click="getImgByCaptureScreen"
>
<q-icon name="content_paste" class="q-mr-sm" />
从剪贴板读取
<q-icon name="crop" class="q-mr-sm" />
截图查找
</q-btn>
</div>
@ -157,7 +155,6 @@ export default defineComponent({
try {
const reader = new FileReader();
reader.onload = (e) => {
this.argvs.imagePreview = e.target.result;
this.updateArgvs("imagePreview", e.target.result);
};
reader.readAsDataURL(file);
@ -176,7 +173,6 @@ export default defineComponent({
const blob = item.getAsFile();
const reader = new FileReader();
reader.onload = (e) => {
this.argvs.imagePreview = e.target.result;
this.updateArgvs("imagePreview", e.target.result);
};
reader.readAsDataURL(blob);
@ -186,17 +182,16 @@ export default defineComponent({
},
//
async pasteFromClipboard() {
const clipboardImage = quickcommand.readClipboardImage();
if (!clipboardImage)
return quickcommand.showMessageBox("剪贴板中没有图片", "warning");
this.argvs.imagePreview = clipboardImage;
this.updateArgvs("imagePreview", clipboardImage);
async getImgByCaptureScreen() {
const img = await quickcomposer.simulate.captureScreenToClipboard({
type: "area",
});
if (!img) return;
this.updateArgvs("imagePreview", img);
},
//
clearImage() {
this.argvs.imagePreview = "";
this.updateArgvs("imagePreview", "");
},