Skip to content

Commit

Permalink
🐞 fix(req): 登录使用错误密码会登录的问题和钱数保留整数问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeAL committed Oct 28, 2024
1 parent 9b2aff7 commit f9901f4
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 165 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [x] 解绑 MAC 地址:可以显示当前设备无线网卡的 MAC 地址进行参考,以及解绑功能
- [x] 测速功能:可以选择不同测速点,贝壳内网,以及其他教育网 ipv6 测速点进行测速(不消耗校园网流量),同时显示当前公网 IP 地址
- [x] 关于页面:一些作者的废话以及我的捐赠打钱二维码,还有一些小 Tips
- [x] 查别人流量,和查电表

## TODO

Expand All @@ -26,7 +27,7 @@
- [ ] 前端页面美化
- [ ] 前端加入图表展示,更加直观
- [ ] 密码输入错误超过 3 次之后显示验证码(困难)
- [ ] 给应用签名
- [ ] 给应用签名(苹果要钱,不签了)
- [ ] 设计应用图标,现在的图标是 Tauri 默认的

## 下载链接
Expand Down
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare module 'vue' {
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NProgress: typeof import('naive-ui')['NProgress']
NResult: typeof import('naive-ui')['NResult']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSelect: typeof import('naive-ui')['NSelect']
NSpace: typeof import('naive-ui')['NSpace']
NSplit: typeof import('naive-ui')['NSplit']
Expand Down
9 changes: 7 additions & 2 deletions src-tauri/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub async fn simulate_login(account: &str, password: &str) -> Result<Option<Stri
.text()
.await?;
// dbg!(&response);
if response.contains("账号或密码出现错误!") {
if response.contains("账号或密码出现错误!") || response.contains("登录密码不正确") {
return Ok(None); // 账号或密码出现错误!
}
Ok(Some(jsessionid.to_string()))
Expand Down Expand Up @@ -125,7 +125,7 @@ pub async fn simulate_login_via_vpn(account: &str, password: &str) -> Result<Opt
.as_str();
dbg!(captcha_id);
// 发送登录请求
let _res = client
let res = client
.post("https://elib.ustb.edu.cn/do-login")
.header(
"Cookie",
Expand All @@ -147,6 +147,10 @@ pub async fn simulate_login_via_vpn(account: &str, password: &str) -> Result<Opt
])
.send()
.await?;
// dbg!(res.text().await?);
if res.text().await?.contains("用户名或密码错误") {
return Ok(None); // 账号或密码出现错误!
}
// 访问校园网后台登录页
let res = client.get("https://elib.ustb.edu.cn/http-8080/77726476706e69737468656265737421a2a713d275603c1e2858c7fb/nav_login")
.header("Cookie", format!("wengine_vpn_ticketelib_ustb_edu_cn={}", wengine_vpn_ticketelib_ustb_edu_cn))
Expand Down Expand Up @@ -431,6 +435,7 @@ pub async fn get_user_login_log(
}
// dbg!(every_login_datas);
Ok(Some(UserLoginLog {
// 获取数据如果没有数据会在 unwrap 崩掉该 task,但是 WHO CARES?
#[allow(clippy::get_first)]
ipv4_up: redtexts.get(0).unwrap().trim().parse()?,
ipv4_down: redtexts.get(1).unwrap().trim().parse()?,
Expand Down
54 changes: 27 additions & 27 deletions src/pages/MonthPay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,33 @@ const mb2gb = (mb: number | undefined) => {

<template>
<div class="container">
<n-h2 prefix="bar" type="success" style="margin-top: 15px">
<n-text type="success"> 年度扣费账单 </n-text>
</n-h2>
<p>选择一个年份:</p>
<n-select
v-model:value="year"
:options="year_options"
@update:value="load_month_pay"
/>
<div v-if="month_pay !== undefined" class="show-data">
<p>这一年一共花费 {{ month_pay?.year_cost }} 元。</p>
<p>
总共使用时长 {{ month_pay?.year_used_duration }} 分钟,约合
{{ min2hour(month_pay?.year_used_duration) }} 小时,{{
min2day(month_pay?.year_used_duration)
}}
天(不同设备使用时长会叠加)。
</p>
<p>
总共使用流量 {{ month_pay?.year_used_flow }} MB,约合
{{ mb2gb(month_pay?.year_used_flow) }} GB。
</p>
<n-data-table
:columns="monthly_columns"
:data="month_pay?.monthly_data"
/>
</div>
<n-scrollbar style="max-height: 100vh">
<n-h2 prefix="bar" type="success" style="margin-top: 15px">
<n-text type="success"> 年度扣费账单 </n-text>
</n-h2>
<p>选择一个年份:</p>
<n-select
v-model:value="year"
:options="year_options"
@update:value="load_month_pay" />
<div v-if="month_pay !== undefined" class="show-data">
<p>这一年一共花费 {{ month_pay?.year_cost }} 元。</p>
<p>
总共使用时长 {{ month_pay?.year_used_duration }} 分钟,约合
{{ min2hour(month_pay?.year_used_duration) }} 小时,{{
min2day(month_pay?.year_used_duration)
}}
天(不同设备使用时长会叠加)。
</p>
<p>
总共使用流量 {{ month_pay?.year_used_flow }} MB,约合
{{ mb2gb(month_pay?.year_used_flow) }} GB。
</p>
<n-data-table
:columns="monthly_columns"
:data="month_pay?.monthly_data"
/></div
></n-scrollbar>
</div>
</template>

Expand Down
111 changes: 59 additions & 52 deletions src/pages/MonthlyUserLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ const get_monthly_user_log = async () => {
refresh.value = !refresh.value;
};
const getBackgroundColor = (data: number) => {
const getBackgroundColor = (data_string: string) => {
// const max = flow_max;
// const min = 0;
// const value = data / max * (max - min) + min;
// const green = Math.round(255 * (1 - value / max));
// const red = Math.round(255 * (value / max));
// return `rgba(${red}, ${green}, 100, 0.2)`;
let data = parseFloat(data_string);
if (data < 1000) {
return "rgba(55, 80, 147, 0.5)";
} else if (data < 2000) {
Expand All @@ -105,7 +106,7 @@ const getBackgroundColor = (data: number) => {
}
};
const select_to_data = (item: EveryLoginData): number => {
const select_to_data = (item: EveryLoginData): string => {
const fieldMap: { [key: string]: number } = {
ipv4_down: item.ipv4_down,
ipv4_up: item.ipv4_up,
Expand All @@ -117,7 +118,11 @@ const select_to_data = (item: EveryLoginData): number => {
cost: item.cost,
used_duration: item.used_duration,
};
return fieldMap[select_show_value.value] || 0;
return (
fieldMap[select_show_value.value].toFixed(
select_show_value.value == "cost" ? 2 : 0
) || "0"
);
};
const data_type = (): string => {
Expand All @@ -133,55 +138,57 @@ const data_type = (): string => {

<template>
<div class="container">
<n-h2 prefix="bar" type="success" style="margin-top: 15px">
<n-text type="success"> 月度使用概览 </n-text>
</n-h2>
<n-date-picker
v-model:value="start_date"
type="month"
clearable
@update:value="get_monthly_user_log"
/>
<br />
<n-grid :x-gap="12" :y-gap="8" :cols="7" :key="refresh">
<n-grid-item class="gray"><p>日</p></n-grid-item>
<n-grid-item class="gray"><p>一</p></n-grid-item>
<n-grid-item class="gray"><p>二</p></n-grid-item>
<n-grid-item class="gray"><p>三</p></n-grid-item>
<n-grid-item class="gray"><p>四</p></n-grid-item>
<n-grid-item class="gray"><p>五</p></n-grid-item>
<n-grid-item class="gray"><p>六</p></n-grid-item>
<n-grid-item
v-for="(, index) in the_week_of_first_day"
:key="index"
class="gray"
>
</n-grid-item>
<n-grid-item
v-for="(item, index) in monthly_user_log"
:key="index"
class="day"
:style="{ backgroundColor: getBackgroundColor(select_to_data(item)) }"
>
<p style="margin: 3px; line-height: 1.5em; white-space: nowrap">
<b>{{ index + 1 }}日</b><br />
{{ select_to_data(item).toFixed(0) }} {{ data_type() }}
</p>
</n-grid-item>
</n-grid>
<p>在使用概览上的东西选择:</p>
<n-select
v-model:value="select_show_value"
:options="select_show_options"
/>
<p>关于统计信息:</p>
<p>这里统计的每日情况与校园网后台一致,以下线时间为准。</p>
<p>
例如:你的手机连接了Wi-Fi,没断过,从第一天晚上8点用到了第二天凌晨4点,一共用了流量2GB,才断网,那么校园网后台才会统计一次信息,此时这2GB流量是算在第二天的。
</p>
<p>
所以,这里的使用情况仅供参考,如果你每天都能在24点前断网,那么它也可能是准确的。
</p>
<n-scrollbar style="max-height: 100vh">
<n-h2 prefix="bar" type="success" style="margin-top: 15px">
<n-text type="success"> 月度使用概览 </n-text>
</n-h2>
<n-date-picker
v-model:value="start_date"
type="month"
clearable
@update:value="get_monthly_user_log"
/>
<br />
<n-grid :x-gap="12" :y-gap="8" :cols="7" :key="refresh">
<n-grid-item class="gray"><p>日</p></n-grid-item>
<n-grid-item class="gray"><p>一</p></n-grid-item>
<n-grid-item class="gray"><p>二</p></n-grid-item>
<n-grid-item class="gray"><p>三</p></n-grid-item>
<n-grid-item class="gray"><p>四</p></n-grid-item>
<n-grid-item class="gray"><p>五</p></n-grid-item>
<n-grid-item class="gray"><p>六</p></n-grid-item>
<n-grid-item
v-for="(, index) in the_week_of_first_day"
:key="index"
class="gray"
>
</n-grid-item>
<n-grid-item
v-for="(item, index) in monthly_user_log"
:key="index"
class="day"
:style="{ backgroundColor: getBackgroundColor(select_to_data(item)) }"
>
<p style="margin: 3px; line-height: 1.5em; white-space: nowrap">
<b>{{ index + 1 }}日</b><br />
{{ select_to_data(item) }} {{ data_type() }}
</p>
</n-grid-item>
</n-grid>
<p>在使用概览上的东西选择:</p>
<n-select
v-model:value="select_show_value"
:options="select_show_options"
/>
<p>关于统计信息:</p>
<p>这里统计的每日情况与校园网后台一致,以下线时间为准。</p>
<p>
例如:你的手机连接了Wi-Fi,没断过,从第一天晚上8点用到了第二天凌晨4点,一共用了流量2GB,才断网,那么校园网后台才会统计一次信息,此时这2GB流量是算在第二天的。
</p>
<p>
所以,这里的使用情况仅供参考,如果你每天都能在24点前断网,那么它也可能是准确的。
</p>
</n-scrollbar>
</div>
</template>

Expand Down
Loading

0 comments on commit f9901f4

Please sign in to comment.