Skip to content

Commit

Permalink
✨ feat(commands): 其他的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeAL committed Jun 21, 2024
1 parent 83e8862 commit 497854d
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ anyhow = "1.0.86"
regex = "1.10.4"
scraper = "0.19.0"
chrono = "0.4.38"
mac_address = "1.1.7"
# 下面这两个不要更新版本
windows = "0.39.0"
webview2-com = "0.19.1"
Expand Down
82 changes: 81 additions & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use chrono::DateTime;
use regex::Regex;
use tauri::Manager;

use crate::{
entities::AppState,
requests::{get_load_user_flow, get_month_pay, get_refresh_account},
requests::{
get_load_user_flow, get_mac_address, get_month_pay, get_refresh_account,
get_user_login_log, unbind_macs,
},
utils::get_webview2_cookie,
};

Expand Down Expand Up @@ -145,3 +149,79 @@ pub async fn load_month_pay(
)),
}
}

#[tauri::command(async)]
pub async fn load_user_login_log(
app_state: tauri::State<'_, AppState>,
start_date: i64,
end_date: i64,
) -> Result<String, String> {
if start_date >= end_date {
return Err("起始日期比结束日期更大。。。".to_string());
}
let session_id = match app_state.jsessionid.read().unwrap().clone() {
Some(s) => s,
None => return Err("SessionID为空,是否已经登录并单击获取Cookie按钮?".to_string()),
};
let start_date = DateTime::from_timestamp(start_date, 0)
.unwrap()
.format("%Y-%m-%d")
.to_string();
let end_date = DateTime::from_timestamp(end_date, 0)
.unwrap()
.format("%Y-%m-%d")
.to_string();
match get_user_login_log(&session_id, &start_date, &end_date).await {
Ok(Some(value)) => Ok(value.to_string()),
Ok(None) => Err("请确认是否已经登录".to_string()),
Err(e) => Err(format!(
"Request Error,检查是否在校园网内: {}",
e.to_string()
)),
}
}

#[tauri::command(async)]
pub async fn load_mac_address(app_state: tauri::State<'_, AppState>) -> Result<String, String> {
let session_id = match app_state.jsessionid.read().unwrap().clone() {
Some(s) => s,
None => return Err("SessionID为空,是否已经登录并单击获取Cookie按钮?".to_string()),
};

match get_mac_address(&session_id).await {
Ok(Some(value)) => Ok(value.to_string()),
Ok(None) => Err("请确认是否已经登录".to_string()),
Err(e) => Err(format!(
"Request Error,检查是否在校园网内: {}",
e.to_string()
)),
}
}

#[tauri::command]
pub fn get_current_device_mac() -> Result<String, String> {
mac_address::get_mac_address()
.map_err(|e| format!("获取MAC地址错误: {}", e.to_string()))
.map(|mac_address| mac_address.unwrap_or_default().to_string())
}

// 传进来的应该是不需要解绑的,提醒。
#[tauri::command(async)]
pub async fn do_unbind_macs(
app_state: tauri::State<'_, AppState>,
macs: Vec<String>,
) -> Result<(), String> {
let session_id = match app_state.jsessionid.read().unwrap().clone() {
Some(s) => s,
None => return Err("SessionID为空,是否已经登录并单击获取Cookie按钮?".to_string()),
};

match unbind_macs(&session_id, &macs).await {
Ok(Some(())) => Ok(()),
Ok(None) => Err("请确认是否已经登录".to_string()),
Err(e) => Err(format!(
"Request Error,检查是否在校园网内: {}",
e.to_string()
)),
}
}
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn main() {
open_nav_login,
load_user_flow_by_state,
load_month_pay,
load_user_login_log,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub async fn get_user_login_log(
.header("Cookie", format!("JSESSIONID={}", session_id))
.form(&[
("type", "4"),
("month", "CHECKER.TBLUSERLOGIN202304"),
("month", "CHECKER.TBLUSERLOGIN202304"), // 按月已经没用了,这里是固定写法,传过去也没用
("startDate", start_date),
("endDate", end_date),
])
Expand Down

0 comments on commit 497854d

Please sign in to comment.