修复了进入日历没有日程卡片的bug。

Signed-off-by: Yang Yongquan <i@yangyq.net>
This commit is contained in:
2026-09-16 12:34:39 +08:00
parent cc7523a8ec
commit 76d82886e4
4 changed files with 25 additions and 13 deletions
@@ -69,9 +69,13 @@ export default class EntryAbility extends UIAbility {
odMs = parsed; odMs = parsed;
} }
} }
if (odMs > 0) { // 合法性校验:13 位毫秒时间戳若按 int32 传递会溢出成 2147483647 等小值 →
// 只接受 [2000-01-01, 2100-01-01] 区间,避免把日历定位到 1970
if (odMs >= 946684800000 && odMs <= 4102444800000) {
AppStorage.setOrCreate<number>('widgetOpenDate', odMs); AppStorage.setOrCreate<number>('widgetOpenDate', odMs);
LogUtil.write(`卡片进入日历:定位到显示日 ${odMs}`); LogUtil.write(`卡片进入日历:定位到显示日 ${odMs}`);
} else if (odMs > 0) {
LogUtil.write(`卡片 openDate 非法(疑似 int32 溢出):${odMs},忽略`);
} }
} }
} }
+14 -8
View File
@@ -103,10 +103,13 @@ struct Index {
this.selectedDate = this.startOfDay(now.getTime()); this.selectedDate = this.startOfDay(now.getTime());
// 卡片点击:若携带显示日(用户可能已翻到其他日期),进入日历时定位到那一天 // 卡片点击:若携带显示日(用户可能已翻到其他日期),进入日历时定位到那一天
const openFromCard: number = AppStorage.get<number>('widgetOpenDate') ?? 0; const openFromCard: number = AppStorage.get<number>('widgetOpenDate') ?? 0;
if (openFromCard > 0) { if (openFromCard !== 0) {
this.selectedDate = this.startOfDay(openFromCard); AppStorage.setOrCreate<number>('widgetOpenDate', 0); // 用后即清,避免残留
AppStorage.setOrCreate<number>('widgetOpenDate', 0); // 合法性校验(防 int32 溢出等脏值把日历定位到 1970)
LogUtil.write(`从卡片进入:定位到显示日 ${this.selectedDate}`); if (openFromCard >= 946684800000 && openFromCard <= 4102444800000) {
this.selectedDate = this.startOfDay(openFromCard);
LogUtil.write(`从卡片进入:定位到显示日 ${this.selectedDate}`);
}
} }
this.rebuildPages(); this.rebuildPages();
this.initLandscapeListener(); this.initLandscapeListener();
@@ -181,10 +184,13 @@ struct Index {
/** 卡片点击携带的"显示日":App 已在后台运行时由 onNewWant 改写,定位到那一天后清除 */ /** 卡片点击携带的"显示日":App 已在后台运行时由 onNewWant 改写,定位到那一天后清除 */
private onWidgetOpenDateChange(): void { private onWidgetOpenDateChange(): void {
const d: number = this.widgetOpenDate; const d: number = this.widgetOpenDate;
if (d > 0) { if (d !== 0) {
this.selectedDate = this.startOfDay(d); AppStorage.setOrCreate<number>('widgetOpenDate', 0); // 用后即清,避免残留
AppStorage.setOrCreate<number>('widgetOpenDate', 0); // 合法性校验(防 int32 溢出等脏值)
LogUtil.write(`卡片切入(运行中):定位到显示日 ${this.selectedDate}`); if (d >= 946684800000 && d <= 4102444800000) {
this.selectedDate = this.startOfDay(d);
LogUtil.write(`卡片切入(运行中):定位到显示日 ${this.selectedDate}`);
}
} }
} }
@@ -422,8 +422,9 @@ struct Widget4x4Card {
postCardAction(this, { postCardAction(this, {
action: 'router', action: 'router',
abilityName: 'EntryAbility', abilityName: 'EntryAbility',
// 携带卡片当前显示日(用户可能已翻到其他日期),进入日历时定位到这一天 // 携带卡片当前显示日(用户可能已翻到其他日期),进入日历时定位到这一天
params: { openDate: this.selectedDate } // 必须转成字符串:param 的数值按 int32 传递,13 位毫秒时间戳会溢出成 2147483647(曾导致定位到 1970
params: { openDate: `${this.selectedDate}` }
}); });
} }
@@ -419,8 +419,9 @@ struct Widget6x4Card {
postCardAction(this, { postCardAction(this, {
action: 'router', action: 'router',
abilityName: 'EntryAbility', abilityName: 'EntryAbility',
// 携带卡片当前显示日(用户可能已翻到其他日期),进入日历时定位到这一天 // 携带卡片当前显示日(用户可能已翻到其他日期),进入日历时定位到这一天
params: { openDate: this.selectedDate } // 必须转成字符串:param 的数值按 int32 传递,13 位毫秒时间戳会溢出成 2147483647(曾导致定位到 1970
params: { openDate: `${this.selectedDate}` }
}); });
} }