feat: 用 Slint 显示最近一周打卡列表
This commit is contained in:
Generated
+4370
-9
File diff suppressed because it is too large
Load Diff
@@ -16,3 +16,7 @@ serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1", features = ["preserve_order"] }
|
||||
sha2 = "0.10"
|
||||
thiserror = "2"
|
||||
slint = { version = "1", default-features = false, features = ["std", "compat-1-18", "backend-winit", "renderer-software"] }
|
||||
|
||||
[build-dependencies]
|
||||
slint-build = "1"
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
|
||||
```powershell
|
||||
cargo run
|
||||
cargo run --bin punchlog-ui
|
||||
cargo run --bin extract-device -- --write
|
||||
```
|
||||
|
||||
`punchlog-ui` 打开最近一周的列表窗口。
|
||||
|
||||
第二条需要手机打开 USB 调试并具有 root,用来把当前 iCenter 的版本和设备身份写回 `.env`。
|
||||
|
||||
账号、密码、token、项目和设备身份放在项目根目录的 `.env`,参考 `.env.example`。token 失效时会用账号密码重新登录。
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
use std::process::ExitCode;
|
||||
use std::rc::Rc;
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let ui = match MainWindow::new() {
|
||||
Ok(ui) => ui,
|
||||
Err(err) => {
|
||||
eprintln!("{err}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
let ui_weak = ui.as_weak();
|
||||
show(&ui, load());
|
||||
ui.on_refresh(move || {
|
||||
let Some(ui) = ui_weak.upgrade() else {
|
||||
return;
|
||||
};
|
||||
show(&ui, load());
|
||||
});
|
||||
if let Err(err) = ui.run() {
|
||||
eprintln!("{err}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
|
||||
fn load() -> punchlog::Result<punchlog::WeekReport> {
|
||||
let mut config = punchlog::AppConfig::load()?;
|
||||
punchlog::load_last_week(&mut config)
|
||||
}
|
||||
|
||||
fn show(ui: &MainWindow, loaded: punchlog::Result<punchlog::WeekReport>) {
|
||||
match loaded {
|
||||
Ok(report) => {
|
||||
ui.set_error(String::new().into());
|
||||
ui.set_range(format!("{} — {}", report.start, report.end).into());
|
||||
let rows: Vec<DayRow> = report
|
||||
.days
|
||||
.iter()
|
||||
.map(|day| {
|
||||
let (site, memo) = day.content();
|
||||
DayRow {
|
||||
date: day.day.format("%m-%d").to_string().into(),
|
||||
mark: if day.has_supplement { "补" } else { "" }.into(),
|
||||
time: format!("{} – {}", day.first.format("%H:%M"), day.last.format("%H:%M")).into(),
|
||||
hours: format!("{:.1}h", day.hours).into(),
|
||||
status: day.status.label().into(),
|
||||
site: site.into(),
|
||||
memo: memo.into(),
|
||||
problem: day.status.is_problem(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
ui.set_days(Rc::new(slint::VecModel::from(rows)).into());
|
||||
}
|
||||
Err(err) => {
|
||||
ui.set_error(err.to_string().into());
|
||||
ui.set_days(Rc::new(slint::VecModel::<DayRow>::default()).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
import { AboutSlint } from "std-widgets.slint";
|
||||
|
||||
export struct DayRow {
|
||||
date: string,
|
||||
mark: string,
|
||||
time: string,
|
||||
hours: string,
|
||||
status: string,
|
||||
site: string,
|
||||
memo: string,
|
||||
problem: bool,
|
||||
}
|
||||
|
||||
component Hairline inherits Rectangle {
|
||||
height: 1px;
|
||||
background: #e4e4e1;
|
||||
}
|
||||
|
||||
component DayBlock inherits HorizontalLayout {
|
||||
in property <DayRow> day;
|
||||
spacing: 0;
|
||||
|
||||
Rectangle {
|
||||
width: 2px;
|
||||
background: day.problem ? #161616 : transparent;
|
||||
}
|
||||
|
||||
VerticalLayout {
|
||||
padding-left: 18px;
|
||||
padding-right: 20px;
|
||||
padding-top: 16px;
|
||||
padding-bottom: 16px;
|
||||
spacing: 6px;
|
||||
alignment: start;
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: 10px;
|
||||
alignment: center;
|
||||
Text {
|
||||
text: day.date;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #161616;
|
||||
}
|
||||
if day.mark != "": Text {
|
||||
text: day.mark;
|
||||
font-size: 12px;
|
||||
color: #8a8a8a;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
Text {
|
||||
text: day.time;
|
||||
font-size: 12px;
|
||||
color: #6e6e6e;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Text {
|
||||
text: day.hours;
|
||||
font-size: 12px;
|
||||
color: #6e6e6e;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Text {
|
||||
text: day.status;
|
||||
font-size: 12px;
|
||||
color: #161616;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
|
||||
if day.site != "": Text {
|
||||
text: day.site;
|
||||
wrap: word-wrap;
|
||||
font-size: 12px;
|
||||
color: #8a8a8a;
|
||||
}
|
||||
|
||||
if day.memo != "": Text {
|
||||
text: day.memo;
|
||||
wrap: word-wrap;
|
||||
font-size: 14px;
|
||||
color: #161616;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component MainWindow inherits Window {
|
||||
in property <[DayRow]> days;
|
||||
in property <string> range;
|
||||
in property <string> error;
|
||||
in-out property <bool> about: false;
|
||||
callback refresh();
|
||||
|
||||
title: "打卡";
|
||||
preferred-width: 920px;
|
||||
preferred-height: 680px;
|
||||
background: #f7f7f5;
|
||||
default-font-family: "Segoe UI";
|
||||
|
||||
VerticalLayout {
|
||||
spacing: 0;
|
||||
|
||||
Rectangle {
|
||||
height: 52px;
|
||||
HorizontalLayout {
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
spacing: 16px;
|
||||
alignment: center;
|
||||
Text {
|
||||
text: "打卡";
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #161616;
|
||||
}
|
||||
Text {
|
||||
text: root.range;
|
||||
font-size: 12px;
|
||||
color: #8a8a8a;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
Text {
|
||||
text: "刷新";
|
||||
font-size: 12px;
|
||||
color: #161616;
|
||||
vertical-alignment: center;
|
||||
TouchArea { clicked => { root.refresh(); } }
|
||||
}
|
||||
Text {
|
||||
text: "关于";
|
||||
font-size: 12px;
|
||||
color: #161616;
|
||||
vertical-alignment: center;
|
||||
TouchArea { clicked => { root.about = !root.about; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Hairline {}
|
||||
|
||||
if root.error != "": VerticalLayout {
|
||||
padding: 20px;
|
||||
Text {
|
||||
text: root.error;
|
||||
wrap: word-wrap;
|
||||
font-size: 13px;
|
||||
color: #161616;
|
||||
}
|
||||
}
|
||||
|
||||
if root.about: VerticalLayout {
|
||||
padding: 24px;
|
||||
spacing: 16px;
|
||||
alignment: start;
|
||||
Text {
|
||||
text: "关于";
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #161616;
|
||||
}
|
||||
AboutSlint {}
|
||||
Text {
|
||||
text: "返回";
|
||||
font-size: 12px;
|
||||
color: #161616;
|
||||
TouchArea { clicked => { root.about = false; } }
|
||||
}
|
||||
}
|
||||
|
||||
if !root.about && root.error == "" && root.days.length == 0: VerticalLayout {
|
||||
padding: 20px;
|
||||
Text {
|
||||
text: "这一周没有打卡记录。";
|
||||
font-size: 13px;
|
||||
color: #8a8a8a;
|
||||
}
|
||||
}
|
||||
|
||||
if !root.about && root.error == "" && root.days.length > 0: Flickable {
|
||||
vertical-stretch: 1;
|
||||
content-height: list.preferred-height;
|
||||
list := VerticalLayout {
|
||||
width: parent.width;
|
||||
for day in root.days: VerticalLayout {
|
||||
DayBlock { day: day; }
|
||||
Hairline {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user