Skip to content

Commit

Permalink
正常显示
Browse files Browse the repository at this point in the history
  • Loading branch information
testuser01 committed Dec 17, 2024
1 parent 1d0a989 commit 2aa08d7
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 74 deletions.
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"devDependencies": {
"@tauri-apps/cli": "^2",
"@vitejs/plugin-vue": "^5.0.5",
"typescript": "^5.2.2",
"typescript": "5.6.2",
"vite": "^5.3.1",
"vue-tsc": "^2.0.22"
"vue-tsc": "2.0.29"
}
}
6 changes: 4 additions & 2 deletions src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"windows": ["main","screenshot"],
"permissions": [
"core:default",
"shell:allow-open",
Expand All @@ -16,7 +16,9 @@
"core:webview:allow-create-webview-window",
"core:webview:allow-webview-close",
"core:webview:allow-set-webview-size",
"core:window:allow-set-decorations"
"core:window:allow-set-decorations",
"core:window:allow-get-all-windows",
"core:webview:allow-get-all-webviews"


]
Expand Down
19 changes: 2 additions & 17 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,10 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

mod scan;
use std::option;

use scan::{scan_colors, scan_loop, scan_once, stop_scan};
use tauri::{menu::{MenuBuilder, MenuItemBuilder}};

fn main() {
tauri::Builder::default().setup(|app| {
let option = MenuItemBuilder::new("option").build(app)?;
let quite = MenuItemBuilder::new("quit").build(app)?;
let menu = MenuBuilder::new(app).items(&[&option, &quite]).build()?;
app.set_menu(menu)?;
app.on_menu_event(move |app, event| {
if event.id() == "option" {
app.exit(0);
} else if event.id() == "quit" {
app.exit(0);
}
});
Ok(())
})
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![scan_once, scan_loop, scan_colors, stop_scan])
.run(tauri::generate_context!())
.expect("error running tauri application");
Expand Down
1 change: 1 addition & 0 deletions src/components/createScreenshot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function handleScreenshot() {
resizable: true,
skipTaskbar: false,
transparent: true,
maximized: true,
});
await getCurrentWindow().hide();
Expand Down
8 changes: 4 additions & 4 deletions src/views/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:header="`任务${index} X: ${
startX[index - 1] + endX[index - 1] / 2
} Y: ${y[index - 1]}`"
v-for="(index, item) in startX.length"
v-for="(index) in startX.length"
:key="index"
>
<a-space direction="vertical">
Expand All @@ -59,7 +59,7 @@
</a-space>
<template #extra>
<a-space>
<CreateScreenshot size="small" :index="index" />
<CreateScreenshot size="small" :index="index-1" />
<a-button
size="small"
:icon="h(CloseOutlined)"
Expand Down Expand Up @@ -110,7 +110,7 @@ async function handleScanLoop() {
y: y.value[index],
interval: scanInterval.value * startX.value.length,
};
//invoke('scan', data);
invoke("scan_loop", data);
}, index * scanInterval.value);
});
}
Expand Down Expand Up @@ -138,7 +138,7 @@ function addProject() {
}
function handleStop() {
//invoke("stop_scan");
invoke("stop_scan");
console.log("stop");
}
Expand Down
66 changes: 41 additions & 25 deletions src/views/screenshot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
</template>

<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
import { computed, ref } from "vue";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { useRoute } from "vue-router";
import { Webview } from '@tauri-apps/api/webview';
import { getAllWebviewWindows } from "@tauri-apps/api/webviewWindow";
import { emit } from "@tauri-apps/api/event";
const index = Number(useRoute().query.index as string);
Expand All @@ -38,16 +39,20 @@ const pickerButtonStyle = computed(() => {
return {
top: `${top.value + height.value + 30}px`,
left: `${left.value + width.value - 80}px`,
visibility: isMouseDown.value ? "visible" : "hidden",
visibility: isShowButton.value ? "visible" : "hidden",
};
});
// 鼠标左键是否按下
let isMouseDown = ref(false);
// 是否显示button
let isShowButton = ref(false);
// 监听鼠标按下事件
window.addEventListener("mousedown", (e) => {
// 判断当前按下的位置不是 picker-check 的位置
// 获取 picker-check 的包围盒
const pickerCheck = document.querySelector(".picker-check");
const pickerCheckRect = pickerCheck?.getBoundingClientRect();
Expand All @@ -61,6 +66,8 @@ window.addEventListener("mousedown", (e) => {
return;
} else {
isMouseDown.value = true;
isShowButton.value = true;
pickerButtonStyle.value.visibility = "visible";
// 获取鼠标位置
const { clientX, clientY } = e;
left.value = clientX;
Expand All @@ -84,31 +91,39 @@ window.addEventListener("mousemove", (e) => {
// 监听鼠标抬起事件
window.addEventListener("mouseup", () => {
isMouseDown.value = false;
isShowButton.value = true;
});
async function handleClick() {
const curentwindow = getCurrentWindow();
const allwindows = Webview.getAll();
const mainWindow = (await allwindows).find(item=>item.label === "main");
console.log("1111111111");
const allwindows = await getAllWebviewWindows();
console.log("222222");
const mainWindow = (await allwindows).find((item) => item.label === "main");
console.log("3333");
const scaleFactor = await curentwindow.scaleFactor();
console.log("444");
const position = await curentwindow.innerPosition();
console.log("5555");
//窗口高度
const payload = {
startX: left.value,
endX: left.value + width.value,
y:top.value + height.value/2+Math.round(position.y/scaleFactor),
y: top.value + height.value / 2 + Math.round(position.y / scaleFactor),
index: index,
}
};
console.log("6666");
await emit("location", payload);
if(mainWindow){
console.log("7777");
if (mainWindow) {
await mainWindow.show();
}
console.log("8888");
await curentwindow.close();
}
</script>
<style scoped>
.screen-wrap{
<style scoped>
.screen-wrap {
width: 100vw;
height: 100vh;
position: absolute;
Expand All @@ -117,18 +132,19 @@ async function handleClick() {
z-index: 999;
box-sizing: border-box;
position: relative;
.screen-picker{
position: absolute;
z-index: 999;
border: solid 2px #0a7baf;
box-sizing: content-box;
transform: translate(-2px, -2px);
}
.picker-check{
width: 80px;
position: absolute;
right: 0;
bottom: -50px;
}
background-color: rgba(0, 0, 0, 0.2);
}
.picker-check {
width: 80px;
position: absolute;
right: 0;
bottom: -50px;
}
.screen-picker {
position: absolute;
z-index: 999;
border: solid 2px #0a7baf;
box-sizing: content-box;
transform: translate(-2px, -2px);
}
</style>
</style>

0 comments on commit 2aa08d7

Please sign in to comment.