Skip to content

Commit

Permalink
✨ feat(UnbindMacs, SpeedTest): 添加了测速,mac地址展示。。
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeAL committed Jun 21, 2024
1 parent d76d140 commit da3ce4c
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub async fn load_mac_address(app_state: tauri::State<'_, AppState>) -> Result<S

#[tauri::command]
pub fn get_current_device_mac() -> Result<String, String> {
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())
}
Expand All @@ -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(|_| ())
}
4 changes: 4 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
]
}
},
Expand Down
6 changes: 5 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
ListOutline,
CashOutline,
BookOutline,
BrowsersOutline,
SpeedometerOutline,
} from "@vicons/ionicons5";
function renderIcon(icon: Component) {
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions src/pages/SpeedTest.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script setup lang="ts">
import { invoke } from "@tauri-apps/api";
import { useMessage } from "naive-ui";
const pop_message = useMessage();
const open_speed_test = async () => {
await invoke("open_speed_test").catch((err) => pop_message.error(err));
};
</script>

<template>
<div class="container">
<h2>测个速,不费校园网流量的</h2>
<n-button strong secondary type="primary" @click="open_speed_test">
点我
</n-button>
</div>
</template>

<style scoped></style>
71 changes: 71 additions & 0 deletions src/pages/UnbindMacs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script setup lang="ts">
import { invoke } from "@tauri-apps/api";
import { onMounted, ref } from "vue";
import { useMessage } from "naive-ui";
interface MacAddress {
device_name: string;
mac_address: string;
}
const pop_message = useMessage();
const this_mac = ref<string>("");
const mac_addrs = ref<MacAddress[] | null>(null);
onMounted(() => {
get_current_device_mac();
load_mac_address();
});
const get_current_device_mac = async () => {
this_mac.value = (await invoke("get_current_device_mac").catch((err) =>
pop_message.error(err)
)) as string;
};
const load_mac_address = async () => {
let res = await invoke("load_mac_address").catch((err) =>
pop_message.error(err)
);
mac_addrs.value = JSON.parse(res as string);
};
</script>

<template>
<div class="container">
<h2>解绑MAC地址</h2>
<p>MAC Address是什么?简单来说校园网靠这个来识别是否是你的设备。</p>
<p>
所以随机MAC地址开启的话,就会导致你之前的设备被顶掉,详情可看B站视频:BV1JC4y1S7WS
</p>
<p>当前机器的无线MAC地址是(仅供参考):{{ this_mac }}</p>
<p>如果把该地址解绑会导致立刻断网。</p>
<div v-if="mac_addrs !== null" class="show-data">
<n-table :bordered="false" :single-line="false">
<thead>
<tr>
<th>序号</th>
<th>设备名(校园网后台可能获取不到)</th>
<th>MAC Address</th>
<th>是否解绑</th>
</tr>
</thead>
<tbody>
<tr v-for="(mac_addr, index) in mac_addrs" :key="index">
<th>{{ index + 1 }}</th>
<th>{{ mac_addr.device_name }}</th>
<th>{{ mac_addr.mac_address }}</th>
<th>1</th>
</tr>
</tbody>
</n-table>
</div>
</div>
</template>

<style scoped>
.container {
height: 100vh;
overflow: auto;
}
</style>

0 comments on commit da3ce4c

Please sign in to comment.