Skip to content

Commit

Permalink
✨ feat(UserLoginLog): 简单展示每日使用详情
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeAL committed Jun 21, 2024
1 parent 497854d commit d76d140
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 2 deletions.
2 changes: 2 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ declare module 'vue' {
Menu: typeof import('./src/components/Menu.vue')['default']
NButton: typeof import('naive-ui')['NButton']
NDataTable: typeof import('naive-ui')['NDataTable']
NDatePicker: typeof import('naive-ui')['NDatePicker']
NIcon: typeof import('naive-ui')['NIcon']
NMenu: typeof import('naive-ui')['NMenu']
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NResult: typeof import('naive-ui')['NResult']
NSelect: typeof import('naive-ui')['NSelect']
NSplit: typeof import('naive-ui')['NSplit']
NTable: typeof import('naive-ui')['NTable']
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@tauri-apps/api": "^1",
"dayjs": "^1.11.11",
"vue": "^3.3.4"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub async fn load_user_login_log(
start_date: i64,
end_date: i64,
) -> Result<String, String> {
if start_date >= end_date {
if start_date > end_date {
return Err("起始日期比结束日期更大。。。".to_string());
}
let session_id = match app_state.jsessionid.read().unwrap().clone() {
Expand Down
2 changes: 2 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import About from "./pages/About.vue";
import NotFound from "./pages/NotFound.vue";
import UserInfo from "./pages/UserInfo.vue";
import MonthPay from "./pages/MonthPay.vue";
import UserLoginLog from "./pages/UserLoginLog.vue"
type RouteComponent = DefineComponent<{}, {}, any>;
interface Routes {
Expand All @@ -18,6 +19,7 @@ const routes: Routes = {
"/about": About,
"/userinfo": UserInfo,
"/monthpay": MonthPay,
"/userloginlog": UserLoginLog
};
// Ref for current path
Expand Down
13 changes: 13 additions & 0 deletions src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
InformationCircleOutline,
ListOutline,
CashOutline,
BookOutline,
} from "@vicons/ionicons5";
function renderIcon(icon: Component) {
Expand Down Expand Up @@ -57,6 +58,18 @@ const menuOptions: MenuOption[] = [
key: "monthpay",
icon: renderIcon(CashOutline),
},
{
label: () =>
h(
"a",
{
href: "#/userloginlog",
},
"每日使用详情"
),
key: "userloginlog",
icon: renderIcon(BookOutline),
},
{
label: () =>
h(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/MonthPay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const mb2gb = (mb: number | undefined) => {
@update:value="load_month_pay"
/>
<div v-if="month_pay !== undefined" class="show-data">
<p>这一年移一共花费 {{ month_pay?.year_cost }} 元。</p>
<p>这一年一共花费 {{ month_pay?.year_cost }} 元。</p>
<p>
总共使用时长 {{ month_pay?.year_used_duration }} 分钟,约合
{{ min2hour(month_pay?.year_used_duration) }} 小时。
Expand Down
124 changes: 124 additions & 0 deletions src/pages/UserLoginLog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<script setup lang="ts">
import { ref } from "vue";
import { invoke } from "@tauri-apps/api/tauri";
import { useMessage } from "naive-ui";
import dayjs from "dayjs";
interface UserLoginLog {
ipv4_up: number;
ipv4_down: number;
ipv6_up: number;
ipv6_down: number;
used_flow: number; // 实际上就是 ipv4 下行
cost: number;
used_duration: number;
every_login_data: EveryLoginData[];
}
interface EveryLoginData {
online_time: number; // 时间戳,UTC
offline_time: number;
used_duration: number;
used_flow: number; // 实际上就是 ipv4 下行
cost: number;
ipv4_up: number;
ipv4_down: number;
ipv6_up: number;
ipv6_down: number;
ipv4_addr: string;
ipv6_addr: string;
}
const pop_message = useMessage();
const date_range = ref<[number, number]>([Date.now(), Date.now()]);
const user_login_log = ref<UserLoginLog | null>(null);
const get_user_login_log = async () => {
let res = await invoke("load_user_login_log", {
startDate: Math.floor(date_range.value[0] / 1000),
endDate: Math.floor(date_range.value[1] / 1000),
}).catch((err) => pop_message.error(err));
// console.log(res as string);
user_login_log.value = JSON.parse(res as string);
if (user_login_log.value !== null) {
}
};
const unix_format = (unix: number) => {
return dayjs.unix(unix - 8 * 3600).format("YYYY-MM-DD HH:mm:ss");
};
</script>

<template>
<div class="container">
<h2>每日使用详情</h2>
<p>选择一个时间段:</p>
<n-date-picker
v-model:value="date_range"
type="daterange"
clearable
@update:value="get_user_login_log"
/>
<div v-if="user_login_log !== null" class="show-data">
<p>该段时间:</p>
<p>
ipv4 上行:{{ user_login_log?.ipv4_up }} MB;下行:{{
user_login_log?.ipv4_down
}}
MB。
</p>
<p>
ipv6 上行:{{ user_login_log?.ipv6_up }} MB;下行:{{
user_login_log?.ipv6_down
}}
MB。
</p>
<p>消耗校园网流量:{{ user_login_log?.used_flow }} MB。</p>
<p>花费金额:{{ user_login_log?.cost }} 元。</p>
<p>使用时长: {{ user_login_log?.used_duration }} 分钟。</p>

<n-table :bordered="false" :single-line="false">
<thead>
<tr>
<th>上线时间</th>
<th>下线时间</th>
<th>在线时长(分钟)</th>
<th>消耗流量(MB)</th>
<th>花费(元)</th>
<th>ipv4 上行(MB)</th>
<th>ipv4 下行(MB)</th>
<th>ipv6 上行(MB)</th>
<th>ipv6 下行(MB)</th>
<th>ipv4 地址</th>
<th>ipv6 地址</th>
</tr>
</thead>
<tbody>
<tr
v-for="(log_info, index) in user_login_log?.every_login_data"
:key="index"
>
<th>{{ unix_format(log_info.online_time) }}</th>
<th>{{ unix_format(log_info.offline_time) }}</th>
<th>{{ log_info.used_duration }}</th>
<th>{{ log_info.used_flow }}</th>
<th>{{ log_info.cost }}</th>
<th>{{ log_info.ipv4_up }}</th>
<th>{{ log_info.ipv4_down }}</th>
<th>{{ log_info.ipv6_up }}</th>
<th>{{ log_info.ipv6_down }}</th>
<th>{{ log_info.ipv4_addr }}</th>
<th>{{ log_info.ipv6_addr }}</th>
</tr>
</tbody>
</n-table>
</div>
</div>
</template>

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

0 comments on commit d76d140

Please sign in to comment.