diff --git a/components.d.ts b/components.d.ts index b367c8e..fc94db5 100644 --- a/components.d.ts +++ b/components.d.ts @@ -12,6 +12,8 @@ declare module 'vue' { NButton: typeof import('naive-ui')['NButton'] NCard: typeof import('naive-ui')['NCard'] NCheckbox: typeof import('naive-ui')['NCheckbox'] + NCollapse: typeof import('naive-ui')['NCollapse'] + NCollapseItem: typeof import('naive-ui')['NCollapseItem'] NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] NDataTable: typeof import('naive-ui')['NDataTable'] diff --git a/public/7a35cda1e5187cf409a1677bf0c58fa3.png b/public/7a35cda1e5187cf409a1677bf0c58fa3.png new file mode 100644 index 0000000..2fe823d Binary files /dev/null and b/public/7a35cda1e5187cf409a1677bf0c58fa3.png differ diff --git a/public/QQ_1731405540124.png b/public/QQ_1731405540124.png new file mode 100644 index 0000000..ecc9267 Binary files /dev/null and b/public/QQ_1731405540124.png differ diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index e32b684..44255d9 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -246,14 +246,35 @@ pub async fn load_mac_address(app_state: tauri::State<'_, AppState>) -> Result return Err("SessionID为空,是否已经登录并单击获取Cookie按钮?".to_string()), }; let via_vpn = *app_state.login_via_vpn.read().unwrap(); + let mac_custom_address = app_state.setting.read().unwrap().mac_custom_name.clone(); - match get_mac_address(&session_id, via_vpn).await { + match get_mac_address(&session_id, via_vpn, &mac_custom_address).await { Ok(Some(value)) => Ok(value.to_string()), Ok(None) => Err("请确认是否已经登录".to_string()), Err(e) => Err(format!("Request Error,检查是否在校园网内: {}", e)), } } +#[tauri::command(async)] +pub async fn set_mac_custom_name( + app_state: tauri::State<'_, AppState>, + app_handle: tauri::AppHandle, + mac: &str, + name: &str, +) -> Result<(), String> { + app_state + .setting + .write() + .unwrap() + .set_mac_custom_name(mac, name); + app_state + .setting + .write() + .unwrap() + .write_setting(&app_handle) + .map_err(|e| e.to_string()) +} + #[tauri::command] pub fn get_current_device_mac() -> Result { match std::env::consts::OS { diff --git a/src-tauri/src/entities.rs b/src-tauri/src/entities.rs index 09af042..3b6b9a7 100644 --- a/src-tauri/src/entities.rs +++ b/src-tauri/src/entities.rs @@ -76,6 +76,7 @@ pub struct EveryLoginData { pub struct MacAddress { pub device_name: String, pub mac_address: String, + pub custom_name: String, } pub struct AppState { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index e0e8610..673165a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -52,7 +52,8 @@ pub fn run() { set_background_image, reset_background_image, set_background_transparence, - set_background_blur + set_background_blur, + set_mac_custom_name ]) .setup(|app| { #[cfg(not(any(target_os = "android", target_os = "linux")))] diff --git a/src-tauri/src/requests.rs b/src-tauri/src/requests.rs index 953ea78..daef400 100644 --- a/src-tauri/src/requests.rs +++ b/src-tauri/src/requests.rs @@ -1,4 +1,4 @@ -use std::{f64, time::Duration}; +use std::{collections::HashMap, f64, time::Duration}; use anyhow::{anyhow, Result}; use chrono::NaiveDateTime; @@ -451,7 +451,11 @@ pub async fn get_user_login_log( })) } -pub async fn get_mac_address(session_id: &str, via_vpn: bool) -> Result> { +pub async fn get_mac_address( + session_id: &str, + via_vpn: bool, + mac_custom_name: &HashMap, +) -> Result> { let url = if !via_vpn { "http://202.204.60.7:8080/nav_unBandMacJsp" } else { @@ -495,12 +499,15 @@ pub async fn get_mac_address(session_id: &str, via_vpn: bool) -> Result>(); - Ok(Some(serde_json::json!(mac_address))) } @@ -658,7 +665,7 @@ mod tests { #[tokio::test] async fn test_get_mac_address() { let session_id = "session_id"; - let res = get_mac_address(session_id, false).await; + let res = get_mac_address(session_id, false, &mut HashMap::new()).await; dbg!(res.unwrap()); } diff --git a/src-tauri/src/setting.rs b/src-tauri/src/setting.rs index b08ba2d..0bca2ff 100644 --- a/src-tauri/src/setting.rs +++ b/src-tauri/src/setting.rs @@ -1,4 +1,5 @@ use std::{ + collections::HashMap, fs::{self, create_dir, File, OpenOptions}, io::{Read, Write}, path::PathBuf, @@ -13,9 +14,10 @@ pub struct Setting { pub username: Option, pub password: Option, pub ammeter_number: Option, + pub mac_custom_name: HashMap, pub background_image_path: Option, pub background_transparence: Option, - pub background_blur: Option + pub background_blur: Option, } impl Setting { @@ -92,6 +94,15 @@ impl Setting { pub fn set_background_blur(&mut self, background_blur: u32) { self.background_blur = Some(background_blur); } + + pub fn set_mac_custom_name(&mut self, mac: &str, name: &str) { + self.mac_custom_name + .entry(mac.to_owned()) + .and_modify(|n| { + *n = name.to_owned(); + }) + .or_insert(name.to_string()); + } } fn get_config_path(app: &tauri::AppHandle) -> Result { diff --git a/src/pages/UnbindMacs.vue b/src/pages/UnbindMacs.vue index 6a3abbb..bf5648b 100644 --- a/src/pages/UnbindMacs.vue +++ b/src/pages/UnbindMacs.vue @@ -7,12 +7,14 @@ import { open } from "@tauri-apps/plugin-shell"; interface MacAddress { device_name: string; mac_address: string; + custom_name: string; } const pop_message = useMessage(); const this_mac = ref(""); const mac_addrs = ref(null); const unbind_macs = ref>([]); +const custom_names = ref>([]); onMounted(() => { get_current_device_mac(); @@ -33,6 +35,7 @@ const load_mac_address = async () => { if (mac_addrs.value !== null) { for (let i = 0; i < mac_addrs.value.length; i += 1) { unbind_macs.value.push(false); + custom_names.value.push(mac_addrs.value[i].custom_name); } } }; @@ -52,50 +55,102 @@ const unbind = async () => { }).catch((err) => pop_message.error(err)); setTimeout(load_mac_address, 100); }; + +const set_mac_custom_name = async (mac: string, index: number) => { + if (custom_names.value[index] === "") { + return; + } + await invoke("set_mac_custom_name", { + mac, + name: custom_names.value[index], + }).catch((err) => pop_message.error(err)); +};