fix(新建日程): 非今天默认 09:00,今天仍用当前时刻 #4
应用市场反馈:「新建非今天的日程时,默认时间固定在当天 9 点更好」。 根因:原来日期取所选日,但**时分固定取 now.getHours()**, 与所选日期无关。所以下午三点建明天的日程会得到「明天 15:00」。 改为按日期分支: · 今天 → 当前时刻(今天 09:00 往往已过,「现在就记一笔」才是常态) · 非今天 → 09:00(现在几点对别的日子没有参考价值) 顺带统一:toggleAllDay 关闭全天时原来硬编码 9 点,改为引用 DEFAULT_START_HOUR 常量,两处口径一致。
This commit is contained in:
@@ -112,6 +112,8 @@ struct EventEditPage {
|
|||||||
@State sheetMode: string = 'picker';
|
@State sheetMode: string = 'picker';
|
||||||
@State pickerIsEnd: boolean = false;
|
@State pickerIsEnd: boolean = false;
|
||||||
@State pickDate: Date = new Date();
|
@State pickDate: Date = new Date();
|
||||||
|
/** 新建"非今天"日程时的默认开始小时(24 小时制) */
|
||||||
|
private static readonly DEFAULT_START_HOUR: number = 9;
|
||||||
@State pickHour: number = 9;
|
@State pickHour: number = 9;
|
||||||
@State pickMin: number = 0;
|
@State pickMin: number = 0;
|
||||||
/** ⭐ 重复日程编辑范围:'one' 仅此次 / 'future' 此次及以后 / 'all' 全部 */
|
/** ⭐ 重复日程编辑范围:'one' 仅此次 / 'future' 此次及以后 / 'all' 全部 */
|
||||||
@@ -271,12 +273,23 @@ struct EventEditPage {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 新建:日期取所选日(未选则今天),时间取当前时刻;结束 = 开始 + 1 小时
|
// 新建:日期取所选日(未选则今天)。默认开始时刻分两种情况:
|
||||||
|
// ① 今天 → 取当前时刻("现在就记一笔"最自然;而且今天的 09:00 往往已经过了)
|
||||||
|
// ② 非今天 → 固定 09:00("现在几点"对别的日子毫无参考价值,09:00 才是通用默认)
|
||||||
|
// 结束时间统一 = 开始 + 1 小时。
|
||||||
const base: number = AppStorage.get<number>('pendingEventDate') ?? Date.now();
|
const base: number = AppStorage.get<number>('pendingEventDate') ?? Date.now();
|
||||||
const dayStart = new Date(new Date(base).getFullYear(), new Date(base).getMonth(),
|
const pickedDay = new Date(base);
|
||||||
new Date(base).getDate()).getTime();
|
const dayStart = new Date(pickedDay.getFullYear(), pickedDay.getMonth(),
|
||||||
|
pickedDay.getDate()).getTime();
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
|
||||||
|
if (dayStart === todayStart) {
|
||||||
|
// ① 今天:当前时刻
|
||||||
this.startMs = dayStart + now.getHours() * 3600000 + now.getMinutes() * 60000;
|
this.startMs = dayStart + now.getHours() * 3600000 + now.getMinutes() * 60000;
|
||||||
|
} else {
|
||||||
|
// ② 非今天:09:00
|
||||||
|
this.startMs = dayStart + EventEditPage.DEFAULT_START_HOUR * 3600000;
|
||||||
|
}
|
||||||
this.endMs = this.startMs + 3600000;
|
this.endMs = this.startMs + 3600000;
|
||||||
if (choices.length > 0) {
|
if (choices.length > 0) {
|
||||||
this.chosenKey = choices[0].calKey;
|
this.chosenKey = choices[0].calKey;
|
||||||
@@ -686,7 +699,8 @@ struct EventEditPage {
|
|||||||
this.endMs = dayStart + 86399999;
|
this.endMs = dayStart + 86399999;
|
||||||
} else {
|
} else {
|
||||||
const s = new Date(this.startMs);
|
const s = new Date(this.startMs);
|
||||||
this.startMs = s.getTime() + 9 * 3600000;
|
this.startMs = new Date(s.getFullYear(), s.getMonth(), s.getDate()).getTime()
|
||||||
|
+ EventEditPage.DEFAULT_START_HOUR * 3600000;
|
||||||
this.endMs = this.startMs + 3600000;
|
this.endMs = this.startMs + 3600000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user