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 2aa08d7 commit 94a408d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src-tauri/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lazy_static! {
#[tauri::command]
pub fn scan_once(colors: Vec<[u8; 3]>, start_x: f64, end_x: f64, y: f64) -> bool {
// 调用 scan_colors 获取屏幕上的颜色
println!("scan_once start_x: {}, end_x: {}, y: {}", start_x, end_x, y);
let screen_colors = scan_colors(start_x, end_x, y);
// 计算颜色差异
let mut is_match = true;
Expand All @@ -25,8 +26,10 @@ pub fn scan_once(colors: Vec<[u8; 3]>, start_x: f64, end_x: f64, y: f64) -> bool
}
// 如果颜色匹配,则点击鼠标左键
if is_match {
println!("match!");
let x_point = (start_x + end_x) / 2.0;
//鼠标移动
let _ = mouse::move_to(Point::new(start_x + end_x / 2.0, y));
let _ = mouse::move_to(Point::new(x_point, y));
//鼠标左键点击
thread::sleep(Duration::from_millis(100));
let _ = mouse::click(mouse::Button::Left, None);
Expand Down
3 changes: 2 additions & 1 deletion src/components/screenImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ watch(
</script>
<style scoped>
.image {
transform: scale(5);
transform: scaleY(20);
transform-origin: bottom center;
}
</style>
76 changes: 56 additions & 20 deletions src/views/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,58 @@
:header="`任务${index} X: ${
startX[index - 1] + endX[index - 1] / 2
} Y: ${y[index - 1]}`"
v-for="(index) in startX.length"
v-for="index in startX.length"
:key="index"
>
<a-space direction="vertical">
<a-input-number
size="small"
v-model:value="startX[index - 1]"
addon-before="起始X"
/>
<a-input-number
size="small"
v-model:value="endX[index - 1]"
addon-before="终止X"
/>
<a-input-number
size="small"
v-model:value="y[index - 1]"
addon-before="高度 Y"
/>
</a-space>
<a-row :gutter="10">
<!-- Radio buttons for type selection -->
<a-col :span="4">
<a-radio-group
v-model:value="type[index - 1]"
default-value="button"
button-style="solid"
>
<a-radio value="button">按键</a-radio>
<a-radio value="text">文本</a-radio>
</a-radio-group>
</a-col>

<!-- Image and textarea -->
<a-col :span="8">
<ScreenImage :colors="colors[index - 1]" width="60%" />
<a-textarea
v-if="type[index - 1] === 'text'"
v-model:value="text_detail[index - 1]"
:rows="4"
placeholder="输入文本内容"
/>
</a-col>

<!-- Input numbers for start X, end X, and Y -->
<a-col :span="8">
<a-space direction="vertical" align="start">
<a-input-number
size="small"
v-model:value="startX[index - 1]"
addon-before="起始X"
/>
<a-input-number
size="small"
v-model:value="endX[index - 1]"
addon-before="终止X"
/>
<a-input-number
size="small"
v-model:value="y[index - 1]"
addon-before="高度 Y"
/>
</a-space>
</a-col>
</a-row>

<template #extra>
<a-space>
<CreateScreenshot size="small" :index="index-1" />
<CreateScreenshot size="small" :index="index - 1" />
<a-button
size="small"
:icon="h(CloseOutlined)"
Expand Down Expand Up @@ -93,12 +122,18 @@ import {
} from "@tauri-apps/plugin-global-shortcut";
import { getCurrentWindow } from "@tauri-apps/api/window";
import CreateScreenshot from "../components/createScreenshot.vue";
import ScreenImage from "../components/screenImage.vue";
const activeKey = ref("1");
const startX = useStorage<number[]>("startX", [0]);
const endX = useStorage<number[]>("endX", [0]);
const y = useStorage<number[]>("y", [0]);
const colors = useStorage<[][][]>("colors", [[]]);
const scanInterval = useStorage<number>("scanInterval", 1000);
const type = useStorage<string[]>(
"type",
new Array(startX.value.length).fill("button")
);
const text_detail = useStorage<string[]>("text_detail", [""]);
async function handleScanLoop() {
startX.value.forEach((_item, index) => {
Expand All @@ -110,6 +145,7 @@ async function handleScanLoop() {
y: y.value[index],
interval: scanInterval.value * startX.value.length,
};
console.log("data-->", data);
invoke("scan_loop", data);
}, index * scanInterval.value);
});
Expand Down Expand Up @@ -138,7 +174,7 @@ function addProject() {
}
function handleStop() {
invoke("stop_scan");
invoke("stop_scan");
console.log("stop");
}
Expand Down

0 comments on commit 94a408d

Please sign in to comment.