@@ -60,6 +60,7 @@ export class CardData {
|
||||
// ===== 卡片翻页(上一天 / 下一天 / 回到今天)=====
|
||||
dayOffset: number = 0; // 相对今天的天数偏移(0=今天)
|
||||
isToday: boolean = true; // 当前显示的是否为今天(非今天不画红线)
|
||||
selectedDate: number = 0; // 当前卡片显示的那一天 0 点毫秒(点卡片进入日历时定位到这一天)
|
||||
dayCount: number = 0; // 当前显示日的日程条数(含全天)
|
||||
}
|
||||
|
||||
@@ -190,6 +191,7 @@ export class CardDataService {
|
||||
data.weekday = fullWeekCn[base.getDay()];
|
||||
data.dayOffset = dayOffset;
|
||||
data.isToday = dayOffset === 0;
|
||||
data.selectedDate = baseStart; // 卡片当前显示日 0 点毫秒(点卡片进入日历时定位用)
|
||||
const start: number = baseStart < todayStart ? baseStart : todayStart;
|
||||
const end: number = (baseStart > todayStart ? baseStart : todayStart) + 60 * 86400000;
|
||||
const sources = await CalendarDataService.loadSources(context);
|
||||
|
||||
@@ -49,7 +49,7 @@ export default class EntryAbility extends UIAbility {
|
||||
this.handleWidgetParam(want);
|
||||
}
|
||||
|
||||
/** 读取卡片深链参数:widgetAction=add 时写入 AppStorage,供 Index 页面拉起新建日程页 */
|
||||
/** 读取卡片深链参数:widgetAction=add 拉起新建日程;openDate 定位到卡片当前显示日 */
|
||||
private handleWidgetParam(want: Want): void {
|
||||
const params = want.parameters;
|
||||
if (params !== undefined) {
|
||||
@@ -58,6 +58,21 @@ export default class EntryAbility extends UIAbility {
|
||||
AppStorage.setOrCreate<string>('widgetAction', 'add');
|
||||
LogUtil.write('卡片添加入口:已设置 widgetAction=add');
|
||||
}
|
||||
// 卡片点击进入日历时,定位到卡片当前显示的那一天(用户可能已翻到其他日期)
|
||||
const od = params['openDate'];
|
||||
let odMs: number = 0;
|
||||
if (typeof od === 'number') {
|
||||
odMs = od;
|
||||
} else if (typeof od === 'string' && od.length > 0) {
|
||||
const parsed = parseInt(od, 10);
|
||||
if (!isNaN(parsed)) {
|
||||
odMs = parsed;
|
||||
}
|
||||
}
|
||||
if (odMs > 0) {
|
||||
AppStorage.setOrCreate<number>('widgetOpenDate', odMs);
|
||||
LogUtil.write(`卡片进入日历:定位到显示日 ${odMs}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,8 @@ struct Index {
|
||||
@State detailEvent: DisplayEvent | null = null;
|
||||
// 服务卡片"添加"按钮深链:EntryAbility 写入,本页读取后拉起新建日程页
|
||||
@Watch('onWidgetActionChange') @StorageLink('widgetAction') widgetAction: string = '';
|
||||
// 服务卡片点击进入日历时携带的"显示日"毫秒(用户可能已翻到其他日期):消费后定位 selectedDate
|
||||
@Watch('onWidgetOpenDateChange') @StorageLink('widgetOpenDate') widgetOpenDate: number = 0;
|
||||
@State nowMs: number = Date.now(); // 当前时刻毫秒(驱动红线"播放"位置,每 30s 更新)
|
||||
// 时间轴视图(月/周/列表共用):按天预计算好色块布局,避免 build 中重算
|
||||
@State dayTimeline: DayTimeline = new DayTimeline(); // 选中日(月/周视图用)
|
||||
@@ -99,6 +101,13 @@ struct Index {
|
||||
this.displayYear = now.getFullYear();
|
||||
this.displayMonth = now.getMonth();
|
||||
this.selectedDate = this.startOfDay(now.getTime());
|
||||
// 卡片点击:若携带显示日(用户可能已翻到其他日期),进入日历时定位到那一天
|
||||
const openFromCard: number = AppStorage.get<number>('widgetOpenDate') ?? 0;
|
||||
if (openFromCard > 0) {
|
||||
this.selectedDate = this.startOfDay(openFromCard);
|
||||
AppStorage.setOrCreate<number>('widgetOpenDate', 0);
|
||||
LogUtil.write(`从卡片进入:定位到显示日 ${this.selectedDate}`);
|
||||
}
|
||||
this.rebuildPages();
|
||||
this.initLandscapeListener();
|
||||
// 首启同意门禁:未同意《隐私政策》与《用户协议》前,不申请任何系统权限、不加载/同步数据(AGC 硬性要求)
|
||||
@@ -169,6 +178,16 @@ struct Index {
|
||||
this.consumeWidgetAction();
|
||||
}
|
||||
|
||||
/** 卡片点击携带的"显示日":App 已在后台运行时由 onNewWant 改写,定位到那一天后清除 */
|
||||
private onWidgetOpenDateChange(): void {
|
||||
const d: number = this.widgetOpenDate;
|
||||
if (d > 0) {
|
||||
this.selectedDate = this.startOfDay(d);
|
||||
AppStorage.setOrCreate<number>('widgetOpenDate', 0);
|
||||
LogUtil.write(`卡片切入(运行中):定位到显示日 ${this.selectedDate}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** 消费卡片"添加"深链:拉起新建日程页并立即清除标记,避免重复触发 */
|
||||
private consumeWidgetAction(): void {
|
||||
const action: string = AppStorage.get<string>('widgetAction') ?? '';
|
||||
|
||||
@@ -91,6 +91,7 @@ struct Widget4x4Card {
|
||||
@LocalStorageProp('dayCount') dayCount: number = 0;
|
||||
@LocalStorageProp('listJson') listJson: string = '[]';
|
||||
@LocalStorageProp('displayStyle') displayStyle: string = 'timeline';
|
||||
@LocalStorageProp('selectedDate') selectedDate: number = 0; // 卡片当前显示日 0 点毫秒
|
||||
|
||||
private parseBlocks(): TBlock[] {
|
||||
try {
|
||||
@@ -421,7 +422,8 @@ struct Widget4x4Card {
|
||||
postCardAction(this, {
|
||||
action: 'router',
|
||||
abilityName: 'EntryAbility',
|
||||
params: {}
|
||||
// 携带卡片当前显示日(用户可能已翻到其他日期),进入日历时定位到这一天
|
||||
params: { openDate: this.selectedDate }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ struct Widget6x4Card {
|
||||
@LocalStorageProp('dayCount') dayCount: number = 0;
|
||||
@LocalStorageProp('listJson') listJson: string = '[]';
|
||||
@LocalStorageProp('displayStyle') displayStyle: string = 'timeline';
|
||||
@LocalStorageProp('selectedDate') selectedDate: number = 0; // 卡片当前显示日 0 点毫秒
|
||||
|
||||
private parseBlocks(): TBlock6[] {
|
||||
try {
|
||||
@@ -418,7 +419,8 @@ struct Widget6x4Card {
|
||||
postCardAction(this, {
|
||||
action: 'router',
|
||||
abilityName: 'EntryAbility',
|
||||
params: {}
|
||||
// 携带卡片当前显示日(用户可能已翻到其他日期),进入日历时定位到这一天
|
||||
params: { openDate: this.selectedDate }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user