用户:「是的去吧」(批准上一封列出的下一步)。
- CalendarApi:createEvent / updateEvent / deleteEvent(POST /calendar/events、
PUT/DELETE /calendar/events/{id});新建与编辑发**同一份** CalendarEventInput
—— 服务端两个端点同形(CreateCalendarEvent 里那个 Status 字段的注释就写着这句),
拆两份会在严格解码下 400
- CalendarPage:写侧表单(新建与编辑共用一份)、二次确认删除、暂停/恢复走 update
(调度器只触发 active;没有暂停就只能删掉重加,而那会丢 event_id 与历史)
- 服务端 400 文案原样显示(收件地址无法解析:…)—— 建事件时就校验地址,
吞成保存失败等于让人猜,而猜的代价是以为设好了、实际永远发不出去
- 空标题/空收件人在本地就挡住,不发注定 400 的请求
- 提交的是**时间戳**(isoTimestampOfLocal),不是日期键;编辑回填走 localDateOf
- ★ 表单形状:日期/时间选择器合起来 ~1400px,展开着放会把标题与收件人挤出屏幕 ——
改成一行摘要 + 点开展开(默认收起)。这不是美观问题:展开态下保存在屏幕外,
要跨过一整面滚轮才够得着
- 判据 +7(端点/载荷/前置校验/文案/二次确认/时间戳往返/变异自检),23 条全绿
- 真机实测(hvigorw + hdc + uitest 逐字段输入 + 逐键点击,每一步都回库核对):
建 → 库里 event_time 是 2026-09-28T01:00Z(= 本地 09:00 整,默认值正确)、
暂停 → status=paused、删除第一下只变确认删除(库里还在)、第二下才真删(库里 0 条)
54 lines
2.3 KiB
Plaintext
54 lines
2.3 KiB
Plaintext
/*
|
||
* AgentMail 鸿蒙客户端 — 日历 API
|
||
* GET /calendar/events?from=&to=
|
||
*
|
||
* 与 WebUI 同源同参(`client/electron/src/api/client.ts` 的 listCalendarEvents):
|
||
* from/to 是 **RFC3339 区间**,服务端按 `event_time` 落在区间内筛。
|
||
*
|
||
* 区间必须按**网格**算,不是按月首月末算 —— 月视图首尾会显示上/下月的格子,
|
||
* 只查当月会让那几个格子永远空着(看着像"那天没事件",其实是没查)。
|
||
*/
|
||
import { ApiClient } from './ApiClient';
|
||
import { CalendarListResponse, CalendarEvent, CalendarEventInput, CalendarDeleteResponse } from '../model/Models';
|
||
|
||
export class CalendarApi {
|
||
private client: ApiClient;
|
||
|
||
constructor(client: ApiClient) {
|
||
this.client = client;
|
||
}
|
||
|
||
/**
|
||
* 列区间内的事件。
|
||
*
|
||
* `from`/`to` 走 `encodeURIComponent`:RFC3339 里的 `+08:00` 若不编码,
|
||
* 查询串里的 `+` 会被服务端解成空格,`time.Parse` 直接失败 ⇒ 静默返回空列表
|
||
* (界面表现为"这个月没有日程",而实际是参数被吃掉了)。
|
||
*/
|
||
async listEvents(from: string, to: string): Promise<CalendarListResponse> {
|
||
const query: string = 'from=' + encodeURIComponent(from) + '&to=' + encodeURIComponent(to);
|
||
return this.client.get<CalendarListResponse>('/calendar/events', query);
|
||
}
|
||
|
||
/**
|
||
* 新建日程。
|
||
*
|
||
* 服务端在**建事件时**就校验收件地址("地址在这里就校验而不是等到触发时:建事件时报错
|
||
* 人能立刻改,而触发时报错只会进 journalctl")。所以这里的 400 必须**显示给用户**,
|
||
* 不许吞成"保存失败"——错误文案("收件地址无法解析:…")是唯一能让人立刻改的东西。
|
||
*/
|
||
async createEvent(input: CalendarEventInput): Promise<CalendarEvent> {
|
||
return this.client.post<CalendarEvent>('/calendar/events', input);
|
||
}
|
||
|
||
/** 编辑日程(PUT 与 POST 同形,见 `CalendarEventInput` 的说明)。 */
|
||
async updateEvent(id: string, input: CalendarEventInput): Promise<CalendarEvent> {
|
||
return this.client.put<CalendarEvent>('/calendar/events/' + encodeURIComponent(id), input);
|
||
}
|
||
|
||
/** 删除日程。 */
|
||
async deleteEvent(id: string): Promise<CalendarDeleteResponse> {
|
||
return this.client.del<CalendarDeleteResponse>('/calendar/events/' + encodeURIComponent(id));
|
||
}
|
||
}
|