feat: 日期可手选,刷新显示加载并自动关闭提示
This commit is contained in:
+174
-63
@@ -1,4 +1,4 @@
|
||||
import { ScrollView } from "std-widgets.slint";
|
||||
import { ScrollView, DatePickerPopup, Date } from "std-widgets.slint";
|
||||
|
||||
export struct DayRow {
|
||||
date: string,
|
||||
@@ -11,54 +11,115 @@ export struct DayRow {
|
||||
problem: bool,
|
||||
}
|
||||
|
||||
component DayBlock inherits Rectangle {
|
||||
in property <DayRow> day;
|
||||
height: 132px;
|
||||
component DateField inherits Rectangle {
|
||||
in-out property <Date> date;
|
||||
in property <string> title;
|
||||
callback accepted();
|
||||
|
||||
height: 28px;
|
||||
border-width: 1px;
|
||||
border-color: #d5d5d0;
|
||||
background: #f7f7f5;
|
||||
|
||||
function two(n: int) -> string {
|
||||
if (n < 10) {
|
||||
return "0" + n;
|
||||
}
|
||||
return "" + n;
|
||||
}
|
||||
|
||||
Text {
|
||||
x: 24px;
|
||||
y: 14px;
|
||||
width: 56px;
|
||||
text: day.date;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
x: 8px;
|
||||
width: parent.width - 16px;
|
||||
height: parent.height;
|
||||
text: root.date.year + "-" + root.two(root.date.month) + "-" + root.two(root.date.day);
|
||||
font-size: 13px;
|
||||
color: #1a1a1a;
|
||||
horizontal-alignment: left;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
Text {
|
||||
x: 88px;
|
||||
y: 16px;
|
||||
width: 120px;
|
||||
text: day.time;
|
||||
font-size: 13px;
|
||||
color: #6a6a6a;
|
||||
horizontal-alignment: left;
|
||||
picker := DatePickerPopup {
|
||||
title: root.title;
|
||||
date: root.date;
|
||||
accepted(date) => {
|
||||
root.date = date;
|
||||
root.accepted();
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
x: 216px;
|
||||
y: 16px;
|
||||
width: 52px;
|
||||
text: day.hours;
|
||||
font-size: 13px;
|
||||
color: #6a6a6a;
|
||||
horizontal-alignment: left;
|
||||
TouchArea {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
clicked => {
|
||||
picker.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component DayBlock inherits Rectangle {
|
||||
in property <DayRow> day;
|
||||
height: 112px;
|
||||
background: #f7f7f5;
|
||||
|
||||
HorizontalLayout {
|
||||
x: 24px;
|
||||
y: 12px;
|
||||
width: parent.width - 48px;
|
||||
height: 22px;
|
||||
spacing: 8px;
|
||||
alignment: start;
|
||||
|
||||
Text {
|
||||
text: day.date;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #1a1a1a;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
Text {
|
||||
text: day.time;
|
||||
font-size: 13px;
|
||||
color: #6a6a6a;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
Text {
|
||||
text: day.hours;
|
||||
font-size: 13px;
|
||||
color: #6a6a6a;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
if day.mark != "": Text {
|
||||
text: day.mark;
|
||||
font-size: 13px;
|
||||
color: #6a6a6a;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
min-width: 24px;
|
||||
clip: true;
|
||||
|
||||
Text {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
text: day.site;
|
||||
font-size: 12px;
|
||||
color: #8a8a8a;
|
||||
horizontal-alignment: right;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if day.mark != "": Text {
|
||||
x: 276px;
|
||||
y: 16px;
|
||||
text: day.mark;
|
||||
font-size: 13px;
|
||||
color: #6a6a6a;
|
||||
horizontal-alignment: left;
|
||||
}
|
||||
|
||||
Text {
|
||||
status-text := Text {
|
||||
x: parent.width - 24px - self.width;
|
||||
y: 16px;
|
||||
y: parent.height - 16px - self.height;
|
||||
text: day.status;
|
||||
font-size: 13px;
|
||||
color: day.problem ? #1a1a1a : #6a6a6a;
|
||||
@@ -68,20 +129,8 @@ component DayBlock inherits Rectangle {
|
||||
Text {
|
||||
x: 24px;
|
||||
y: 42px;
|
||||
width: parent.width - 48px;
|
||||
height: 18px;
|
||||
text: day.site;
|
||||
font-size: 12px;
|
||||
color: #8a8a8a;
|
||||
horizontal-alignment: left;
|
||||
overflow: elide;
|
||||
}
|
||||
|
||||
Text {
|
||||
x: 24px;
|
||||
y: 64px;
|
||||
width: parent.width - 48px;
|
||||
height: 52px;
|
||||
width: max(0px, status-text.x - 24px - 16px);
|
||||
height: parent.height - 42px - 14px;
|
||||
text: day.memo;
|
||||
font-size: 14px;
|
||||
color: #1a1a1a;
|
||||
@@ -101,9 +150,13 @@ component DayBlock inherits Rectangle {
|
||||
|
||||
export component MainWindow inherits Window {
|
||||
in property <[DayRow]> days;
|
||||
in property <string> range;
|
||||
in-out property <Date> start-date;
|
||||
in-out property <Date> end-date;
|
||||
in property <bool> loading;
|
||||
in-out property <string> toast;
|
||||
in property <string> error;
|
||||
callback refresh();
|
||||
callback range-changed();
|
||||
|
||||
title: "打卡";
|
||||
preferred-width: 880px;
|
||||
@@ -121,27 +174,45 @@ export component MainWindow inherits Window {
|
||||
horizontal-alignment: left;
|
||||
}
|
||||
|
||||
DateField {
|
||||
x: 76px;
|
||||
y: 12px;
|
||||
width: 108px;
|
||||
date <=> root.start-date;
|
||||
title: "开始日期";
|
||||
accepted => { root.range-changed(); }
|
||||
}
|
||||
|
||||
Text {
|
||||
x: 72px;
|
||||
y: 18px;
|
||||
text: root.range;
|
||||
x: 190px;
|
||||
y: 16px;
|
||||
text: "—";
|
||||
font-size: 13px;
|
||||
color: #8a8a8a;
|
||||
horizontal-alignment: left;
|
||||
}
|
||||
|
||||
DateField {
|
||||
x: 210px;
|
||||
y: 12px;
|
||||
width: 108px;
|
||||
date <=> root.end-date;
|
||||
title: "结束日期";
|
||||
accepted => { root.range-changed(); }
|
||||
}
|
||||
|
||||
TouchArea {
|
||||
x: parent.width - 72px;
|
||||
x: parent.width - 28px - 80px;
|
||||
y: 0px;
|
||||
width: 72px;
|
||||
width: 80px;
|
||||
height: 52px;
|
||||
enabled: !root.loading;
|
||||
Text {
|
||||
x: 0px;
|
||||
y: 18px;
|
||||
width: parent.width;
|
||||
text: "刷新";
|
||||
text: root.loading ? "正在刷新" : "刷新";
|
||||
font-size: 13px;
|
||||
color: #1a1a1a;
|
||||
color: root.loading ? #8a8a8a : #1a1a1a;
|
||||
horizontal-alignment: right;
|
||||
}
|
||||
clicked => { root.refresh(); }
|
||||
@@ -166,10 +237,10 @@ export component MainWindow inherits Window {
|
||||
horizontal-alignment: left;
|
||||
}
|
||||
|
||||
if root.error == "" && root.days.length == 0: Text {
|
||||
if !root.loading && root.error == "" && root.days.length == 0: Text {
|
||||
x: 24px;
|
||||
y: 68px;
|
||||
text: "这一周没有打卡记录。";
|
||||
text: "这个范围没有打卡记录。";
|
||||
font-size: 14px;
|
||||
color: #8a8a8a;
|
||||
horizontal-alignment: left;
|
||||
@@ -188,4 +259,44 @@ export component MainWindow inherits Window {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if root.toast != "": island := Rectangle {
|
||||
property <length> capsule-width: min(parent.width - 80px, notice.preferred-width + close-mark.preferred-width + 32px);
|
||||
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: 0px;
|
||||
width: capsule-width;
|
||||
height: 30px;
|
||||
border-top-left-radius: 0px;
|
||||
border-top-right-radius: 0px;
|
||||
border-bottom-left-radius: 15px;
|
||||
border-bottom-right-radius: 15px;
|
||||
background: #1a1a1a;
|
||||
|
||||
notice := Text {
|
||||
x: 16px;
|
||||
height: parent.height;
|
||||
text: root.toast;
|
||||
font-size: 13px;
|
||||
color: #f7f7f5;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
|
||||
close-mark := Text {
|
||||
x: parent.width - 8px - self.width;
|
||||
height: parent.height;
|
||||
text: "×";
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: #ff2430;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
TouchArea {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
clicked => { root.toast = ""; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user