From da3ce4c955387489bbd55b97a754b695b88dc7bb Mon Sep 17 00:00:00 2001 From: CakeAL <1742507190@qq.com> Date: Fri, 21 Jun 2024 19:50:04 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(UnbindMacs,=20SpeedTest):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=B5=8B=E9=80=9F=EF=BC=8Cmac?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E5=B1=95=E7=A4=BA=E3=80=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/commands.rs | 24 ++++++++++++- src-tauri/src/main.rs | 4 +++ src-tauri/tauri.conf.json | 3 +- src/App.vue | 6 +++- src/components/Menu.vue | 26 ++++++++++++++ src/pages/SpeedTest.vue | 21 ++++++++++++ src/pages/UnbindMacs.vue | 71 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 src/pages/SpeedTest.vue create mode 100644 src/pages/UnbindMacs.vue diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 8f72deb..fedaa05 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -200,7 +200,7 @@ pub async fn load_mac_address(app_state: tauri::State<'_, AppState>) -> Result Result { - mac_address::get_mac_address() + mac_address::mac_address_by_name("WLAN") .map_err(|e| format!("获取MAC地址错误: {}", e.to_string())) .map(|mac_address| mac_address.unwrap_or_default().to_string()) } @@ -225,3 +225,25 @@ pub async fn do_unbind_macs( )), } } + +#[tauri::command(async)] +pub fn open_speed_test(app_handle: tauri::AppHandle) -> Result<(), String> { + // 判断该窗口是否已存在 + if let Some(_) = app_handle.get_window("speed_test") { + return Err("已经打开一个测速窗口了".to_string()); + } + + tauri::WindowBuilder::new( + &app_handle, + "speed_test", + tauri::WindowUrl::App("http://speed.ustb.edu.cn/".into()), + ) + .build() + .map_err(|e| { + format!( + "Error when building the speed_test window: {}", + e.to_string() + ) + }) + .map(|_| ()) +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e6f33c6..ab8f7bc 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -20,6 +20,10 @@ fn main() { load_user_flow_by_state, load_month_pay, load_user_login_log, + load_mac_address, + get_current_device_mac, + do_unbind_macs, + open_speed_test ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 9da78de..b290f7e 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -20,7 +20,8 @@ "all":true, "request": true, "scope": [ - "http://202.204.60.7:8080/*" + "http://202.204.60.7:8080/*", + "http://speed.ustb.edu.cn/*" ] } }, diff --git a/src/App.vue b/src/App.vue index 0b11674..3f315c6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,6 +8,8 @@ import NotFound from "./pages/NotFound.vue"; import UserInfo from "./pages/UserInfo.vue"; import MonthPay from "./pages/MonthPay.vue"; import UserLoginLog from "./pages/UserLoginLog.vue" +import UnbindMacs from "./pages/UnbindMacs.vue"; +import SpeedTest from "./pages/SpeedTest.vue" type RouteComponent = DefineComponent<{}, {}, any>; interface Routes { @@ -19,7 +21,9 @@ const routes: Routes = { "/about": About, "/userinfo": UserInfo, "/monthpay": MonthPay, - "/userloginlog": UserLoginLog + "/userloginlog": UserLoginLog, + "/unbindmacs": UnbindMacs, + "/speedtest": SpeedTest, }; // Ref for current path diff --git a/src/components/Menu.vue b/src/components/Menu.vue index 6f62825..c11860a 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -15,6 +15,8 @@ import { ListOutline, CashOutline, BookOutline, + BrowsersOutline, + SpeedometerOutline, } from "@vicons/ionicons5"; function renderIcon(icon: Component) { @@ -70,6 +72,30 @@ const menuOptions: MenuOption[] = [ key: "userloginlog", icon: renderIcon(BookOutline), }, + { + label: () => + h( + "a", + { + href: "#/unbindmacs", + }, + "解绑MAC地址" + ), + key: "unbindmacs", + icon: renderIcon(BrowsersOutline), + }, + { + label: () => + h( + "a", + { + href: "#/speedtest", + }, + "测个速" + ), + key: "speedtest", + icon: renderIcon(SpeedometerOutline), + }, { label: () => h( diff --git a/src/pages/SpeedTest.vue b/src/pages/SpeedTest.vue new file mode 100644 index 0000000..e364d22 --- /dev/null +++ b/src/pages/SpeedTest.vue @@ -0,0 +1,21 @@ + + + + + diff --git a/src/pages/UnbindMacs.vue b/src/pages/UnbindMacs.vue new file mode 100644 index 0000000..0021ecb --- /dev/null +++ b/src/pages/UnbindMacs.vue @@ -0,0 +1,71 @@ + + + + +