cortico-world-fun 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/webui.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { mountStories } from './stories.js';
1
2
  /**
2
3
  * 娱乐时间面板的浏览器端(Coo WebUI 扩展面板)。
3
4
  *
@@ -18,6 +19,8 @@
18
19
  * shelf —— 纪念品架:长期收藏与探索进度
19
20
  */
20
21
 
22
+ import { venueArtwork, souvenirArtwork, souvenirCategory } from './artwork.js';
23
+
21
24
  const CSS = `
22
25
  .fun{--f-line:var(--border,#e3e4e3);--f-ink:var(--foreground,#1b1a1e);--f-dim:var(--muted-foreground,#5c5c60);--f-card:var(--surface,#fbfbfb);--f-soft:color-mix(in srgb,var(--surface,#fbfbfb) 92%,var(--foreground,#1b1a1e));--f-accent:var(--accent,#00a870);--f-warm:#e0862f;--f-mint:#00a870;font:13px/1.6 var(--sans,-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif);color:var(--f-ink);padding:4px 2px 24px}
23
26
  .fun *{box-sizing:border-box}
@@ -35,6 +38,15 @@ const CSS = `
35
38
  .fun-sec:first-child{margin-top:2px}
36
39
 
37
40
  /* 正在逛的那一趟 */
41
+ .fun-draft{border:1px solid var(--f-line);border-left:3px solid var(--f-warm);border-radius:var(--radius-sm,6px);padding:12px 14px;margin-bottom:12px;background:var(--f-card)}
42
+ .fun-draft h3{margin:0 0 4px;font-size:15px;font-weight:600}
43
+ .fun-draft-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}
44
+ .fun-choice{border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);padding:9px 11px;margin-top:9px;background:var(--f-soft)}
45
+ .fun-choice-title{font-size:12px;font-weight:600}
46
+ .fun-choice .fun-list{margin-top:4px}
47
+ .fun-choice-note{font-size:11.5px;color:var(--f-dim);margin:7px 0 0;line-height:1.5}
48
+ .fun-upcoming-wish{margin:-6px 0 12px;padding:8px 11px;border-radius:var(--radius-sm,6px);background:var(--f-soft);color:var(--f-dim);font-size:12px}
49
+
38
50
  .fun-live{border:1px solid var(--f-line);border-left:3px solid var(--f-accent);border-radius:var(--radius-sm,6px);padding:9px 12px;margin-bottom:12px;background:var(--f-card)}
39
51
  .fun-live-idle{border-left-color:var(--f-line)}
40
52
  .fun-live h3{margin:0 0 3px;font-size:14px;font-weight:600}
@@ -157,7 +169,7 @@ const CSS = `
157
169
  .fun-feedback:empty{display:none}.fun-feedback{margin:10px 0}.fun-feedback .fun-err{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
158
170
  .fun-loading{padding:18px;color:var(--f-dim);font-size:13px}.fun-empty{border:1px dashed var(--f-line);border-radius:var(--f-round);margin:10px 0;background:var(--f-soft)}
159
171
  @media(max-width:420px){.fun{padding-inline:0}.fun-live,.fun-trip,.fun-form{padding:12px}.fun-stats{gap:12px}.fun-detail-cols,.fun-form-grid{grid-template-columns:1fr}.fun-detail-top{flex-wrap:wrap}.fun-trip-actions{flex-wrap:wrap}}
160
- @media(prefers-reduced-motion:reduce){.fun *{transition:none!important;scroll-behavior:auto!important}}
172
+ .fun-art{display:block;color:color-mix(in srgb,var(--f-ink) 64%,var(--f-card));background:color-mix(in srgb,var(--f-accent) 5%,var(--f-card));border-radius:8px;margin-bottom:10px;overflow:hidden;pointer-events:none}.fun-art svg{display:block;width:100%;height:116px}.fun-art-detail svg{height:160px}.fun-icon{display:inline-flex;vertical-align:middle;flex:none;width:22px;height:22px;color:var(--f-dim);margin-right:5px}.fun-icon svg{width:100%;height:100%}.fun-keepsake>summary .fun-icon{width:32px;height:32px;margin-bottom:5px}.fun-recommendations{margin:18px 0 20px}.fun-recommendations h3{font-size:16px;margin:0 0 3px}.fun-recommend-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(218px,100%),1fr));gap:12px;margin-top:10px}.fun-recommend-card{padding:13px;border:1px solid var(--f-line);border-radius:var(--f-round);background:var(--f-card);cursor:pointer;transition:border-color .15s,background .15s}.fun-recommend-card:hover{border-color:var(--f-accent)}.fun-recommend-card:focus-visible{outline:2px solid var(--f-accent);outline-offset:3px}.fun-recommend-name{font-weight:650;font-size:15px}.fun-recommend-reason{margin-top:7px;color:var(--f-dim);font-size:12px}.fun-management{margin:16px 0;color:var(--f-dim);font-size:12px}.fun-management>summary{cursor:pointer;padding:6px 0}.fun-management .fun-bar{margin-top:8px}.fun-detail-actions{flex-wrap:wrap}.fun-detail-edit{border-color:var(--f-line);color:var(--f-dim)}.fun-album-filters{display:grid;grid-template-columns:minmax(160px,2fr) minmax(130px,1fr) minmax(130px,1fr);gap:8px;margin:14px 0}.fun-route{padding:10px 13px;border:1px dashed var(--f-line);border-radius:10px;margin:10px 0;font-size:12px}.fun-route-stops{display:flex;gap:6px;align-items:center;flex-wrap:wrap;margin-top:5px}.fun-link{background:transparent!important;color:var(--f-accent)!important;font-size:12px!important;min-height:30px!important}.fun-inspector{margin-top:10px;padding:12px;border:1px solid var(--f-line);border-radius:10px;background:var(--f-soft)}.fun-inspector h4{margin:0 0 4px}.fun-inline-status{font-size:12px;color:var(--f-dim);padding:8px 0}.fun-timeline{list-style:none;padding:0;margin:8px 0}.fun-timeline-block{border-left:2px solid var(--f-line);padding:0 0 12px 13px;margin-left:4px}.fun-timeline-block:last-child{padding-bottom:2px}.fun-timeline-area{font-size:13px;font-weight:600;margin-bottom:5px}.fun-timeline-row{display:grid;grid-template-columns:minmax(78px,auto) 1fr;gap:10px;font-size:12.5px;margin:5px 0;overflow-wrap:anywhere}.fun-timeline-time{color:var(--f-dim);font-size:11px;font-variant-numeric:tabular-nums}.fun-timeline-choice{border-left:2px solid color-mix(in srgb,var(--f-accent) 40%,var(--f-line));margin:5px 0 5px 10px;padding-left:8px}.fun-timeline-event{margin:6px 0}.fun-timeline-source{font-size:11px;color:var(--f-dim)}.fun-recommend-card,.fun-inspector,.fun-feedback,.fun-outing-result{animation:fun-appear .16s ease-out}@keyframes fun-appear{from{opacity:.4;transform:translateY(3px)}to{opacity:1;transform:translateY(0)}}.fun-trip-detail,.fun-detail,.fun-inspector{overflow-wrap:anywhere}.fun{--f-art-warm:color-mix(in srgb,#e9b97e 63%,var(--f-card));--f-art-mint:color-mix(in srgb,#79b7a6 62%,var(--f-card));--f-art-blue:color-mix(in srgb,#7cacc2 62%,var(--f-card));--f-art-pink:color-mix(in srgb,#ce91af 56%,var(--f-card))}@media(max-width:560px){.fun-album-filters{grid-template-columns:1fr}.fun-timeline-row{grid-template-columns:78px 1fr}.fun-art-detail svg{height:128px}}@media(prefers-reduced-motion:reduce){.fun *{transition:none!important;animation:none!important;scroll-behavior:auto!important}}
161
173
 
162
174
  `;
163
175
 
@@ -213,6 +225,162 @@ function feedback(box) {
213
225
  return node;
214
226
  }
215
227
 
228
+ function sceneArt(place, detail = false) {
229
+ return el('div', { class: `fun-art${detail ? ' fun-art-detail' : ''}`, 'aria-hidden': 'true', 'data-artwork': place.userVenue ? 'custom' : place.id,
230
+ html: venueArtwork(place.userVenue ? '' : place.id) });
231
+ }
232
+ function itemIcon(name) {
233
+ return el('span', { class: 'fun-icon', 'aria-hidden': 'true', 'data-category': souvenirCategory(name), html: souvenirArtwork(name) });
234
+ }
235
+
236
+ // Refreshes and explicit view changes can repaint; typing only repaints results.
237
+ function rememberFocus(container) {
238
+ const active = document.activeElement;
239
+ let parent = active;
240
+ while (parent && parent !== container) parent = parent.parentNode;
241
+ const key = parent ? active?.getAttribute?.('data-focus-key') : null;
242
+ const start = active?.selectionStart;
243
+ const end = active?.selectionEnd;
244
+ return () => {
245
+ if (!key) return;
246
+ const target = [...container.querySelectorAll('input'), ...container.querySelectorAll('select')]
247
+ .find((node) => node.getAttribute('data-focus-key') === key);
248
+ target?.focus?.();
249
+ if (typeof start === 'number' && typeof target?.setSelectionRange === 'function' && target.type !== 'date') {
250
+ try { target.setSelectionRange(start, end); } catch { /* Some input types do not support a caret. */ }
251
+ }
252
+ };
253
+ }
254
+
255
+ const routeStatus = { planned: '待出发', active: '行程中', between: '站间歇脚', completed: '已完成', cancelled: '已取消' };
256
+ function routeSummary(route, trips = [], selectTrip) {
257
+ const node = el('section', { class: 'fun-route', 'data-route-id': route.id, 'aria-label': '联程记录' },
258
+ el('strong', { text: `联程 · ${routeStatus[route.status] ?? '状态未知'}` }),
259
+ el('div', { class: 'fun-route-stops', text: (route.stops ?? []).map((stop) => stop.placeName || stop.placeId).join(' → ') }));
260
+ const retained = (route.tripIds ?? []).map((id) => trips.find((trip) => trip.id === id)).filter(Boolean);
261
+ if (selectTrip && retained.length) node.appendChild(el('div', { class: 'fun-route-stops' }, retained.map((trip) => el('button', {
262
+ type: 'button', class: 'fun-link', 'data-trip-id': trip.id, onclick: () => selectTrip(trip),
263
+ }, `${trip.routeOrder ? `第 ${trip.routeOrder} 站 · ` : ''}${trip.placeName} · ${trip.day || '日期不详'}`))));
264
+ if (selectTrip && (route.tripIds ?? []).length > retained.length) node.appendChild(el('div', { class: 'fun-note', text: '较早行程仅保留联程归属,详细记录已归档。' }));
265
+ return node;
266
+ }
267
+
268
+ function tripDetails(trip) {
269
+ const detail = el('section', { class: 'fun-trip-detail', 'aria-label': `${trip.placeName}行程详情` });
270
+ if (trip.company) detail.appendChild(el('p', { text: `同行 · ${trip.company}` }));
271
+ if (trip.timelineTruncated) detail.appendChild(el('p', { class: 'fun-note', text: '这趟记录较长,时间线保留进门与最近的活动;较早的逐项细节已省略。' }));
272
+ if (trip.routeId) detail.appendChild(el('p', { class: 'fun-note', text: `联程${trip.routeOrder ? ` · 第 ${trip.routeOrder} 站` : ''}`, 'data-route-id': trip.routeId }));
273
+ const supplied = Array.isArray(trip.timeline) && trip.timeline.length > 0;
274
+ // Old arrays have no per-action clock. Preserve their text, explicitly unknown.
275
+ const timeline = supplied ? trip.timeline : [
276
+ ...(trip.visited ?? []).map((area) => ({ kind: 'area', text: typeof area === 'string' ? area : area.area, area: typeof area === 'string' ? area : area.area, at: null })),
277
+ ...(trip.events ?? []).map((text) => ({ kind: 'event', text, event: text, at: null })),
278
+ ...(trip.choices ?? []).map((choice) => ({ kind: 'choice', text: choice.result, event: choice.event, at: null })),
279
+ ...(trip.souvenirs ?? []).map((text) => ({ kind: 'buy', text, at: null })),
280
+ ...(trip.photos ?? []).map((text) => ({ kind: 'photo', text, at: null })),
281
+ ...(trip.ate ?? []).map((item) => ({ kind: 'consume', text: `${item.verb}了 ${item.item}`, at: null })),
282
+ ];
283
+ if (timeline.length) {
284
+ detail.appendChild(el('div', { class: 'fun-sec', text: '沿途时间线' }));
285
+ if (!supplied) detail.appendChild(el('p', { class: 'fun-note', text: '这趟旧记录没有保存逐项时间,以下均标为时间不详。' }));
286
+ const list = el('ol', { class: 'fun-timeline' });
287
+ const blocks = [];
288
+ let current = null;
289
+ const block = (area) => {
290
+ const node = el('li', { class: 'fun-timeline-block', 'data-area': area || '' }, el('div', { class: 'fun-timeline-area', text: area || '途中记录(区域未记)' }));
291
+ const value = { area, node, events: [] };
292
+ blocks.push(value); list.appendChild(node); return value;
293
+ };
294
+ const labels = { enter: '进门', area: '逛到', event: '小事', choice: '选择', buy: '带回', photo: '拍照', consume: '吃喝', close: '收摊' };
295
+ for (const entry of timeline) {
296
+ const known = typeof entry.at === 'number' && Number.isFinite(entry.at);
297
+ const clock = known ? [entry.day, entry.hm].filter(Boolean).join(' ') || '时间未标注' : '时间不详';
298
+ const row = el('div', { class: 'fun-timeline-row', 'data-kind': entry.kind, 'data-at': known ? String(entry.at) : 'unknown' },
299
+ el('span', { class: 'fun-timeline-time', text: clock }),
300
+ el('span', null, entry.kind === 'buy' ? itemIcon(entry.text) : null, `${labels[entry.kind] ?? '记录'} · ${entry.text || (entry.kind === 'area' ? entry.area : '') || '未记内容'}`));
301
+ if (entry.kind === 'enter' || entry.kind === 'close') {
302
+ current = block(entry.kind === 'enter' ? '出发与进门' : '收摊');
303
+ current.node.appendChild(row); current = null; continue;
304
+ }
305
+ const source = entry.kind === 'choice' ? [...blocks].reverse().flatMap((group) => [...group.events].reverse())
306
+ .find((event) => entry.event && event.name === entry.event && (!entry.area || event.area === entry.area)) : null;
307
+ if (source && current === source.group && current.lastNode === source.node) {
308
+ source.node.appendChild(el('div', { class: 'fun-timeline-choice', 'data-event': entry.event }, row));
309
+ continue;
310
+ }
311
+ // Never move a late choice ahead of an intervening saved action just to
312
+ // nest it. Its source label links it while chronological order stays put.
313
+ const area = entry.area || '';
314
+ if (!current || area !== current.area) current = block(area);
315
+ if (entry.kind === 'event') {
316
+ const event = el('div', { class: 'fun-timeline-event', 'data-event': entry.event || entry.text }, row);
317
+ current.events.push({ name: entry.event || entry.text, area: current.area, group: current, node: event });
318
+ current.node.appendChild(event); current.lastNode = event;
319
+ } else {
320
+ if (entry.kind === 'choice' && entry.event) {
321
+ row.appendChild(el('span', { class: 'fun-timeline-source', text: `对应小事:${entry.event}` }));
322
+ const choice = el('div', { class: 'fun-timeline-choice', 'data-event': entry.event }, row);
323
+ current.node.appendChild(choice); current.lastNode = choice;
324
+ } else { current.node.appendChild(row); current.lastNode = row; }
325
+ }
326
+ }
327
+ detail.appendChild(list);
328
+ }
329
+ if (trip.note) detail.appendChild(el('p', { text: `收摊备注 · ${trip.note}` }));
330
+ if (trip.scene) detail.appendChild(el('p', { class: 'fun-dim', text: `生图 scene:${trip.scene}${trip.outfit ? ` · outfits:${trip.outfit}` : ''}` }));
331
+ return detail;
332
+ }
333
+
334
+ /** Read-only inline lookup; its own pending/error repaint leaves search controls intact. */
335
+ function tripLookup(ctx, method, parameter, label) {
336
+ const states = new Map();
337
+ const views = new Map();
338
+ const redraw = (id) => {
339
+ for (const view of views.get(id) ?? []) {
340
+ if (view.host.isConnected === false) views.get(id).delete(view);
341
+ else view.paint();
342
+ }
343
+ };
344
+ return (id) => {
345
+ const state = states.get(id) ?? { opened: false, pending: false, trips: null, error: '' };
346
+ states.set(id, state);
347
+ const host = el('section', { class: 'fun-history', 'data-lookup-id': id });
348
+ const paint = () => {
349
+ let focused = document.activeElement;
350
+ while (focused && focused !== host) focused = focused.parentNode;
351
+ host.replaceChildren(el('button', { type: 'button', class: 'fun-link fun-history-toggle', 'aria-expanded': String(state.opened), disabled: state.pending ? 'disabled' : null,
352
+ onclick: () => { if (state.pending) return; state.opened = !state.opened; if (state.opened && state.trips === null) void load(); else redraw(id); } },
353
+ state.pending ? '读取中…' : state.opened ? '收起回看' : label));
354
+ const restore = () => {
355
+ if (!focused) return;
356
+ if (state.pending) { host.setAttribute('tabindex', '-1'); host.focus?.(); }
357
+ else host.querySelector('.fun-history-toggle')?.focus?.();
358
+ };
359
+ if (!state.opened) { restore(); return; }
360
+ const content = el('div', { class: 'fun-history-content', 'aria-live': 'polite' }); host.appendChild(content);
361
+ if (state.pending) content.appendChild(el('div', { class: 'fun-inline-status', role: 'status', text: '正在找这段回忆…' }));
362
+ if (state.error) content.appendChild(el('div', { class: 'fun-err', role: 'alert' }, el('span', { text: state.error }), el('button', { type: 'button', onclick: () => { void load(); } }, '重试')));
363
+ if (state.trips?.length === 0) content.appendChild(el('div', { class: 'fun-note', text: '没有可回看的详细行程;较早记录可能已经归档。' }));
364
+ for (const trip of state.trips ?? []) content.appendChild(el('details', { class: 'fun-inspector', open: state.trips.length === 1 ? 'open' : null, 'data-trip-id': trip.id },
365
+ el('summary', { text: `${trip.placeName} · ${trip.day || '日期不详'} · ${trip.summary || '行程记录'}` }), tripDetails(trip)));
366
+ restore();
367
+ };
368
+ const load = async () => {
369
+ if (state.pending) return;
370
+ state.pending = true; state.error = ''; redraw(id);
371
+ try {
372
+ const result = await ctx.invoke(method, [{ [parameter]: id }]);
373
+ if (!result?.ok) throw new Error(result?.error ?? '详细行程暂时读不到');
374
+ if (!Array.isArray(result.trips)) throw new Error('详细行程格式不正确');
375
+ state.trips = result.trips;
376
+ } catch (error) { state.error = error?.message ?? String(error); }
377
+ finally { state.pending = false; if (!ctx.signal?.aborted) redraw(id); }
378
+ };
379
+ if (!views.has(id)) views.set(id, new Set());
380
+ views.get(id).add({ host, paint }); paint(); return host;
381
+ };
382
+ }
383
+
216
384
  // ---------------------------------------------------------------------------
217
385
  // places —— 去哪儿
218
386
  // ---------------------------------------------------------------------------
@@ -227,15 +395,21 @@ function mountPlaces(ctx) {
227
395
  let keyword = '';
228
396
  let quickFilter = '全部';
229
397
  let expanded = null;
398
+ let expandedOrigin = 'list';
399
+ const historyView = tripLookup(ctx, 'history', 'placeId', '回看这里的行程');
230
400
  /** null = 没在编辑;{ mode: 'new' | 'edit', venue } = 打开表单。 */
231
401
  let editing = null;
232
402
  let formError = '';
403
+ let outingAction = '';
404
+ let notice = null;
405
+ let loadSequence = 0;
233
406
  /** 表单打开期间收到的最新数据,等关掉表单再补画,免得把用户填的内容冲掉。 */
234
407
  let currentData = null;
235
408
  const status = feedback(box);
236
409
  body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在看看有哪些地方开着…' }));
237
410
 
238
411
  const render = (data) => {
412
+ const restoreFocus = rememberFocus(body);
239
413
  // 表单相关声明要放在最前:点「添加地点」时 render 会重跑,
240
414
  // 而那一轮里 `venueForm()` 在 `if (editing)` 处就会用到 `fields`。
241
415
  // 放在后面会撞上 TDZ(`Cannot access 'fields' before initialization`)。
@@ -246,6 +420,27 @@ function mountPlaces(ctx) {
246
420
  currentData = data;
247
421
  body.replaceChildren(heading('去哪儿', '挑一处喜欢的地方,慢慢逛。'));
248
422
 
423
+ const pendingChoice = (choice) => choice ? el('div', { class: 'fun-choice' },
424
+ el('div', { class: 'fun-choice-title', text: choice.prompt || '待选择事件' }),
425
+ el('ul', { class: 'fun-list' }, choice.options.map((option) => el('li', { text: option.label }))),
426
+ el('p', { class: 'fun-choice-note', text: '她可以选一项,也可以略过。' })) : null;
427
+
428
+ const draft = data.draft;
429
+ if (draft) {
430
+ const draftAction = (method, label) => el('button', {
431
+ type: 'button',
432
+ disabled: outingAction || (method === 'resume' && draft.canResume === false) ? 'disabled' : null,
433
+ onclick: () => resolveDraft(method, draft.id),
434
+ }, outingAction === method ? '处理中…' : label);
435
+ body.appendChild(el('section', { class: 'fun-draft' },
436
+ el('h3', { text: `未逛完 · ${draft.placeName}` }),
437
+ el('div', { class: 'fun-meta', text: `最后活动 ${draft.lastDay ? `${draft.lastDay} ` : ''}${draft.lastHm} · 逛了 ${draft.visited.length} 处` }),
438
+ el('div', { class: 'fun-meta', text: draft.visited.length ? `逛过:${draft.visited.map((v) => v.area).join('、')}` : '还没逛到哪儿' }),
439
+ pendingChoice(draft.pendingChoice),
440
+ draft.canResume === false ? el('div', { class: 'fun-meta', text: '这处已不在地点清单中,可以按已有记录收摊。' }) : null,
441
+ el('div', { class: 'fun-draft-actions' }, draftAction('resume', '继续逛'), draftAction('closeDraft', '按已有记录收摊'))));
442
+ }
443
+
249
444
  // ---- 正在逛的那一趟 ----
250
445
  if (data.session) {
251
446
  const s = data.session;
@@ -253,7 +448,8 @@ function mountPlaces(ctx) {
253
448
  const leftAreas = venue
254
449
  ? venue.areas.filter((a) => !s.visited.some((v) => v.area === a))
255
450
  : [];
256
- const leftText = leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join('、')}` : '都逛过了';
451
+ const leftText = venue?.state === 'closed' ? '这处已经打烊'
452
+ : leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join('、')}` : '这会儿开放的都逛过了';
257
453
  const progress = s.venueAreaCount ? `${s.visited.length}/${s.venueAreaCount}` : String(s.visited.length);
258
454
  body.appendChild(el('div', { class: 'fun-live' },
259
455
  el('h3', { text: `正在${s.placeName}逛` }),
@@ -268,8 +464,9 @@ function mountPlaces(ctx) {
268
464
  : null,
269
465
  s.events.length ? el('ul', { class: 'fun-list' }, s.events.slice(-3).map((e) => el('li', { text: e }))) : null,
270
466
  venue ? el('div', { class: 'fun-meta', text: leftText }) : null,
467
+ pendingChoice(s.pendingChoice),
271
468
  ));
272
- } else {
469
+ } else if (!draft) {
273
470
  body.appendChild(el('div', { class: 'fun-live fun-live-idle' },
274
471
  el('h3', { text: '这会儿没在逛' }),
275
472
  el('div', { class: 'fun-meta', text: `现在 ${data.nowHm} · ${data.total} 处地方里 ${data.openCount} 处开着` }),
@@ -277,11 +474,23 @@ function mountPlaces(ctx) {
277
474
  ));
278
475
  }
279
476
 
477
+ if (notice) body.appendChild(el('div', {
478
+ class: 'fun-meta fun-outing-result', role: notice.error ? 'alert' : 'status', tabindex: '-1', text: notice.text,
479
+ }));
480
+ if (data.upcomingWish) body.appendChild(el('div', { class: 'fun-upcoming-wish', text: data.upcomingWish }));
481
+
482
+ if (data.route) body.appendChild(routeSummary(data.route));
483
+ const recommendBox = el('section', { class: 'fun-recommendations', 'aria-label': '此刻推荐' });
484
+ body.appendChild(recommendBox);
485
+ body.appendChild(el('div', { class: 'fun-sec', text: '全部地方 · 找一处看看' }));
486
+ const management = el('details', { class: 'fun-management', open: editing ? 'open' : null }, el('summary', { text: '地点管理与说明' }));
487
+
280
488
  // ---- 搜索条 + 自填地点 ----
281
489
  const input = el('input', {
282
490
  class: 'fun-search',
283
491
  type: 'search',
284
492
  placeholder: '搜地方名、别名或标签(庙会 / 室内 / 夜…)',
493
+ 'aria-label': '搜索全部地方', 'data-focus-key': 'places-search',
285
494
  value: keyword,
286
495
  });
287
496
  input.addEventListener('input', () => {
@@ -297,10 +506,11 @@ function mountPlaces(ctx) {
297
506
  renderAll();
298
507
  },
299
508
  }, '+ 添加地点');
300
- body.appendChild(el('div', { class: 'fun-bar' }, input, addBtn));
509
+ body.appendChild(el('div', { class: 'fun-bar' }, input));
510
+ management.appendChild(el('div', { class: 'fun-bar' }, addBtn));
301
511
 
302
512
  // B 阶段:预设也能编辑(改的是覆盖层,预设本身不动);删只对自己的地方。
303
- body.appendChild(el('div', { class: 'fun-hint' },
513
+ management.appendChild(el('div', { class: 'fun-hint' },
304
514
  `预设的 ${data.total - data.userVenueCount} 处插件自带,现在也能改——改过的会标「已改」,`
305
515
  + `随时能恢复;你自己加了 ${data.userVenueCount} 处,随时能改能删。`
306
516
  + (data.overriddenCount
@@ -312,20 +522,24 @@ function mountPlaces(ctx) {
312
522
 
313
523
  // 一键恢复全部预设:只在真有覆盖层时给,免得平时多一个没用的按钮。
314
524
  if (data.overriddenCount) {
315
- body.appendChild(el('button', {
525
+ const resetError = el('div', { class: 'fun-form-error', role: 'alert' });
526
+ const resetButton = el('button', {
316
527
  type: 'button',
317
528
  style: { marginBottom: '10px' },
318
529
  onclick: async () => {
530
+ if (resetButton.disabled) return;
531
+ resetButton.disabled = true; resetError.textContent = ''; resetButton.textContent = '恢复中…';
319
532
  try {
320
533
  const r = await ctx.invoke('resetAll', []);
321
- if (!r?.ok) { formError = r?.error ?? '恢复不了'; return; }
534
+ if (!r?.ok) throw new Error(r?.error ?? '恢复不了');
322
535
  formError = '';
323
536
  await load();
324
537
  } catch (err) {
325
- formError = err?.message ?? String(err);
326
- }
538
+ resetError.textContent = err?.message ?? String(err);
539
+ } finally { resetButton.disabled = false; resetButton.textContent = `恢复全部预设(${data.overriddenCount} 处)`; }
327
540
  },
328
- }, `恢复全部预设(${data.overriddenCount} 处)`));
541
+ }, `恢复全部预设(${data.overriddenCount} 处)`);
542
+ management.appendChild(resetButton); management.appendChild(resetError);
329
543
  }
330
544
 
331
545
  // ---- 编辑表单(打开时在最上面) ----
@@ -345,6 +559,7 @@ function mountPlaces(ctx) {
345
559
  body.appendChild(filterBar);
346
560
  const listBox = el('div');
347
561
  body.appendChild(listBox);
562
+ body.appendChild(management);
348
563
 
349
564
  /**
350
565
  * 重画列表。
@@ -355,6 +570,18 @@ function mountPlaces(ctx) {
355
570
  function renderList() {
356
571
  listBox.replaceChildren();
357
572
  const kw = keyword.trim().toLowerCase();
573
+ recommendBox.replaceChildren();
574
+ const recommendations = [...new Set(data.recommendationIds ?? [])].map((id) => data.places.find((p) => p.id === id && p.state !== 'closed')).filter(Boolean).slice(0, 3);
575
+ if (!kw && quickFilter === '全部' && recommendations.length) {
576
+ recommendBox.appendChild(el('h3', { text: '此刻可以看看' }));
577
+ recommendBox.appendChild(el('p', { class: 'fun-note', text: '几处开着的地方,点开只看细节;出发与选择仍由她自己决定。' }));
578
+ recommendBox.appendChild(el('div', { class: 'fun-recommend-grid' }, recommendations.map((p) => {
579
+ const selected = expanded === p.id && expandedOrigin === 'recommend';
580
+ const cell = el('div', { class: selected ? 'fun-cell fun-cell-open' : 'fun-cell' }, card(p, true));
581
+ if (selected) cell.appendChild(detail(p));
582
+ return cell;
583
+ })));
584
+ }
358
585
  const filtered = data.places.filter((p) => {
359
586
  const tags = p.tags ?? [];
360
587
  if (quickFilter === '现在开着') return p.state !== 'closed';
@@ -375,7 +602,7 @@ function mountPlaces(ctx) {
375
602
 
376
603
  /** 一格里画卡;展开时它后面紧跟一条详情,并且这一格跨满整行。 */
377
604
  const cell = (p) => {
378
- const isOpen = expanded === p.id;
605
+ const isOpen = expanded === p.id && expandedOrigin === 'list';
379
606
  const wrap = el('div', { class: isOpen ? 'fun-cell fun-cell-open' : 'fun-cell' });
380
607
  wrap.appendChild(card(p));
381
608
  if (isOpen) wrap.appendChild(detail(p));
@@ -394,34 +621,40 @@ function mountPlaces(ctx) {
394
621
  }
395
622
  }
396
623
 
397
- const card = (p) => {
398
- const cls = ['fun-card'];
624
+ const card = (p, recommended = false) => {
625
+ const selected = expanded === p.id && expandedOrigin === (recommended ? 'recommend' : 'list');
626
+ const cls = [recommended ? 'fun-recommend-card' : 'fun-card'];
399
627
  if (p.state === 'closed') cls.push('fun-card-closed');
400
628
  else if (p.state === 'closingSoon') cls.push('fun-card-soon');
401
629
  else cls.push('fun-card-open');
402
- if (expanded === p.id) cls.push('fun-card-active');
630
+ if (selected) cls.push('fun-card-active');
403
631
  const stateCls = p.state === 'open' ? 'fun-card-state-open'
404
632
  : (p.state === 'closingSoon' ? 'fun-card-state-soon' : '');
405
633
  const node = el('div', {
406
634
  class: cls.join(' '),
407
635
  role: 'button',
408
636
  tabindex: '0',
409
- 'aria-expanded': expanded === p.id ? 'true' : 'false',
410
- onclick: () => toggle(p.id),
637
+ 'aria-expanded': selected ? 'true' : 'false',
638
+ 'aria-label': `${p.name},${p.stateLabel},查看详情`, 'data-place-id': p.id,
639
+ onclick: () => toggle(p.id, recommended),
411
640
  onkeydown: (ev) => {
412
641
  // 键盘也能开合:卡片是 role=button,不能只认鼠标。
413
642
  if (ev.key === 'Enter' || ev.key === ' ' || ev.key === 'Spacebar') {
414
643
  ev.preventDefault?.();
415
- toggle(p.id);
644
+ toggle(p.id, recommended, true);
416
645
  }
417
646
  },
418
647
  },
648
+ sceneArt(p),
419
649
  el('div', { class: 'fun-card-head' },
420
- el('span', { class: 'fun-card-name', text: p.name }),
650
+ el('span', { class: recommended ? 'fun-recommend-name' : 'fun-card-name', text: p.name }),
421
651
  p.phase ? el('span', { class: 'fun-chip fun-chip-phase', text: p.phase }) : null,
422
652
  el('span', { class: `fun-card-state ${stateCls}`, text: p.stateLabel }),
423
- el('span', { class: 'fun-card-arrow', text: expanded === p.id ? '⌃' : '⌄' })),
424
- el('div', { class: 'fun-card-desc', text: p.desc }),
653
+ el('span', { class: 'fun-card-arrow', text: selected ? '⌃' : '⌄' })),
654
+ recommended ? el('div', { class: 'fun-recommend-reason', text: p.wishReason || p.revisitReason || `${p.hours.open}–${p.hours.close} · ${p.crowdLabel} · ${p.phase || p.tags?.slice(0, 2).join(' / ') || '现在开着'}` }) : null,
655
+ recommended ? null : el('div', { class: 'fun-card-desc', text: p.desc }),
656
+ !recommended && p.wishReason ? el('div', { class: 'fun-meta', text: p.wishReason }) : null,
657
+ !recommended && p.revisitReason ? el('div', { class: 'fun-meta', text: p.revisitReason }) : null,
425
658
  el('div', { class: 'fun-card-foot' },
426
659
  el('span', { text: `${p.hours.open}–${p.hours.close}` }),
427
660
  el('span', { text: p.crowdLabel }),
@@ -439,14 +672,18 @@ function mountPlaces(ctx) {
439
672
  * 用户会以为自己点错了。`block: 'nearest'` 保证「已经看得见就不动」,
440
673
  * 不会因为点一张本来就在屏幕里的卡而把页面跳一下。
441
674
  */
442
- function toggle(id) {
443
- const wasOpen = expanded === id;
675
+ function toggle(id, recommended = false, keyboard = false) {
676
+ const origin = recommended ? 'recommend' : 'list';
677
+ const wasOpen = expanded === id && expandedOrigin === origin;
444
678
  expanded = wasOpen ? null : id;
679
+ expandedOrigin = origin;
445
680
  renderList();
681
+ if (keyboard) [...(recommended ? recommendBox : listBox).querySelectorAll(recommended ? '.fun-recommend-card' : '.fun-card')]
682
+ .find((node) => node.getAttribute('data-place-id') === id)?.focus?.();
446
683
  if (!wasOpen) {
447
684
  // 滚的是**整格**(卡 + 详情),不是只滚卡片:
448
685
  // 卡片恰好贴在视口底部时,只保证卡片可见等于详情还在屏幕外。
449
- const active = listBox.querySelector('.fun-card-active');
686
+ const active = (recommended ? recommendBox : listBox).querySelector('.fun-card-active');
450
687
  const target = active?.parentNode ?? active;
451
688
  // 真 DOM 有 scrollIntoView;测试桩没有,判一下再用。
452
689
  if (target && typeof target.scrollIntoView === 'function') {
@@ -483,6 +720,7 @@ function mountPlaces(ctx) {
483
720
  renderList();
484
721
  },
485
722
  }, '收起'))),
723
+ sceneArt(p, true),
486
724
  el('p', { class: 'fun-dim', text: `${p.kindLabel} · ${p.crowdLabel} · ${p.hours.open}–${p.hours.close} · ${p.stateLabel}` }),
487
725
  // 此刻的那段描写:有阶段的场所显示的是「这会儿的样子」,不是通用那段。
488
726
  el('p', { class: 'fun-detail-desc', text: p.desc }),
@@ -503,7 +741,7 @@ function mountPlaces(ctx) {
503
741
  el('ul', { class: 'fun-list' }, p.areas.map((a) => el('li', { text: a })))),
504
742
  el('div', { class: 'fun-detail-col' },
505
743
  el('div', { class: 'fun-sec', text: '纪念品' }),
506
- el('div', { class: 'fun-chips' }, p.souvenirs.map((s) => el('span', { class: 'fun-chip', text: s }))),
744
+ el('div', { class: 'fun-chips' }, p.souvenirs.map((s) => el('span', { class: 'fun-chip' }, itemIcon(s), s))),
507
745
  el('div', { class: 'fun-sec', text: '拍照点' }),
508
746
  el('div', { class: 'fun-chips' }, p.photoSpots.map((s) => el('span', { class: 'fun-chip', text: s }))),
509
747
  p.food
@@ -517,6 +755,7 @@ function mountPlaces(ctx) {
517
755
  ? el('span', {}, '生图时 ', el('b', { text: `scene 填「${p.scene}」` }), `,outfits 建议「${p.outfit}」`)
518
756
  : el('span', {}, '素材库里没有这处的场景,生图时 ', el('b', { text: 'scene 不用填' }), ',把地方写进 prompt 就行')));
519
757
 
758
+ d.appendChild(historyView(p.id));
520
759
  return d;
521
760
  };
522
761
 
@@ -670,22 +909,48 @@ function mountPlaces(ctx) {
670
909
  }
671
910
 
672
911
  renderList();
912
+ restoreFocus();
673
913
  };
674
914
 
675
915
  const load = async () => {
916
+ const sequence = ++loadSequence;
676
917
  try {
677
918
  const data = await ctx.invoke('list');
919
+ if (sequence !== loadSequence || ctx.signal?.aborted) return;
678
920
  if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
679
921
  // 正在填表单时别重画——一分钟的自动刷新会把用户刚填的一整页冲掉。
680
922
  if (editing) { currentData = data; return; }
681
923
  status.replaceChildren();
682
924
  render(data);
683
925
  } catch (err) {
926
+ if (sequence !== loadSequence || ctx.signal?.aborted) return;
684
927
  if (!currentData) body.replaceChildren();
685
928
  status.replaceChildren(errorCard(err, load, Boolean(currentData)));
686
929
  }
687
930
  };
688
931
 
932
+ async function resolveDraft(method, id) {
933
+ if (outingAction) return;
934
+ outingAction = method;
935
+ notice = null;
936
+ render(currentData);
937
+ try {
938
+ const result = await ctx.invoke(method, [{ id }]);
939
+ if (!result?.ok) throw new Error(result?.error ?? '行程更新失败');
940
+ notice = { text: result.text || '行程已更新。' };
941
+ // 写操作已成功,刷新失败时也不重新启用这张旧草稿的按钮。
942
+ currentData = { ...currentData, draft: null };
943
+ } catch (err) {
944
+ notice = { text: err?.message ?? String(err), error: true };
945
+ } finally {
946
+ outingAction = '';
947
+ if (ctx.signal?.aborted) return;
948
+ render(currentData);
949
+ await load();
950
+ body.querySelector('.fun-outing-result')?.focus?.();
951
+ }
952
+ }
953
+
689
954
  void load();
690
955
  // 状态会随时间变(几点、开没开):一分钟刷一次就够,不打断操作。
691
956
  ctx.interval(() => { void load(); }, 60000);
@@ -703,6 +968,9 @@ function mountBook(ctx) {
703
968
  const body = el('div');
704
969
  box.appendChild(body);
705
970
  let bookTab = 'all';
971
+ let bookKeyword = '';
972
+ let bookPlace = '';
973
+ let bookDate = '';
706
974
  let wishFormOpen = false;
707
975
  const expandedTrips = new Set();
708
976
  const status = feedback(box);
@@ -833,6 +1101,7 @@ function mountBook(ctx) {
833
1101
  };
834
1102
 
835
1103
  const render = (data) => {
1104
+ const restoreFocus = rememberFocus(body);
836
1105
  currentData = data;
837
1106
  body.replaceChildren(heading('纪念册', '把走过的地方,收成可以回看的小回忆。'));
838
1107
  if (data.session) body.appendChild(el('div', { class: 'fun-live' },
@@ -846,7 +1115,7 @@ function mountBook(ctx) {
846
1115
  type: 'button', 'aria-pressed': String(bookTab === id), onclick: () => { bookTab = id; render(currentData); },
847
1116
  }, label));
848
1117
  body.appendChild(tabs);
849
- if (bookTab === 'wishes') { renderWishes(data); return; }
1118
+ if (bookTab === 'wishes') { renderWishes(data); restoreFocus(); return; }
850
1119
  if (!data.total && !(data.keepsakeCount > 0)) {
851
1120
  body.appendChild(el('div', { class: 'fun-empty', text: '纪念册还是空的——她收一次摊,这里就有一趟。' }));
852
1121
  return;
@@ -856,56 +1125,92 @@ function mountBook(ctx) {
856
1125
  stat(data.visitedAreaCount, '处逛过'), stat(data.souvenirCount, '件纪念品'), stat(data.photoCount, '张照片')));
857
1126
  if (data.mostVisited?.length) body.appendChild(el('details', { class: 'fun-wish-history' },
858
1127
  el('summary', { text: '常去的' }), el('div', { class: 'fun-chips' }, data.mostVisited.slice(0, 8).map((m) => el('span', { class: 'fun-chip', text: `${m.name} ×${m.times}` })))));
859
- const trips = bookTab === 'kept' ? data.trips.filter((t) => t.kept) : data.trips;
860
- let previousDay = null;
861
- for (const t of trips) {
862
- if (t.day !== previousDay) { body.appendChild(el('div', { class: 'fun-date', text: t.day || '日期不详' })); previousDay = t.day; }
863
- const err = errors.get(t.id);
864
- const open = expandedTrips.has(t.id);
865
- const toggleKeep = async () => {
866
- if (pending.has(t.id)) return;
867
- pending.add(t.id); errors.delete(t.id); render(data);
868
- try {
869
- const result = await ctx.invoke('favorite', [{ id: t.id, keep: !t.kept }]);
870
- if (!result?.ok) throw new Error(result?.error ?? '珍藏状态保存失败');
871
- await load(true);
872
- } catch (error) { errors.set(t.id, error?.message ?? String(error)); }
873
- finally { pending.delete(t.id); render(currentData ?? data); }
1128
+ const search = el('input', { class: 'fun-book-search', type: 'search', placeholder: '搜地点、同行人、日期、备注或沿途回忆', value: bookKeyword, 'aria-label': '搜索纪念册', 'data-focus-key': 'book-search' });
1129
+ const placeOptions = new Map((data.trips ?? []).map((trip) => [trip.placeId, trip.placeName]));
1130
+ const place = el('select', { class: 'fun-book-place', 'aria-label': '按地点筛选行程', 'data-focus-key': 'book-place' },
1131
+ el('option', { value: '', text: '所有地点' }), [...placeOptions].map(([id, name]) => el('option', { value: id, text: name })));
1132
+ place.value = bookPlace;
1133
+ const days = [...new Set((data.trips ?? []).map((trip) => trip.day || 'unknown'))];
1134
+ const date = el('select', { class: 'fun-book-date', 'aria-label': '按日期筛选行程', 'data-focus-key': 'book-date' },
1135
+ el('option', { value: '', text: '所有日期' }), days.map((day) => el('option', { value: day, text: day === 'unknown' ? '日期不详' : day })));
1136
+ date.value = bookDate;
1137
+ body.appendChild(el('div', { class: 'fun-album-filters' }, search, place, date));
1138
+ const results = el('div', { class: 'fun-book-results' }); body.appendChild(results);
1139
+ const allTrips = data.trips ?? [];
1140
+ const textFor = (trip) => [trip.placeName, trip.company, trip.day, trip.note, trip.summary,
1141
+ ...(trip.visited ?? []).map((area) => typeof area === 'string' ? area : area.area), ...(trip.events ?? []),
1142
+ ...(trip.souvenirs ?? []), ...(trip.photos ?? []), ...(trip.choices ?? []).map((choice) => choice.event + ' ' + choice.result),
1143
+ ...(trip.timeline ?? []).map((entry) => entry.text)].filter(Boolean).join(' ').toLowerCase();
1144
+ const renderResults = () => {
1145
+ results.replaceChildren();
1146
+ const keyword = bookKeyword.trim().toLowerCase();
1147
+ const trips = allTrips.filter((trip) => {
1148
+ if (bookTab === 'kept' && !trip.kept) return false;
1149
+ if (bookPlace && trip.placeId !== bookPlace) return false;
1150
+ if (bookDate && (trip.day || 'unknown') !== bookDate) return false;
1151
+ if (!keyword) return true;
1152
+ const route = (data.routes ?? []).find((group) => group.id === trip.routeId);
1153
+ const linked = route ? allTrips.filter((member) => (route.tripIds ?? []).includes(member.id)) : [];
1154
+ const linkedText = route ? [(route.stops ?? []).map((stop) => stop.placeName).join(' '), ...linked.map(textFor)].join(' ').toLowerCase() : '';
1155
+ return textFor(trip).includes(keyword) || linkedText.includes(keyword);
1156
+ });
1157
+ if (keyword || bookPlace || bookDate) results.appendChild(el('div', { class: 'fun-note', role: 'status', text: '找到 ' + trips.length + ' 趟行程;联程同时检索相连的地点与记录。' }));
1158
+ const appendTrip = (trip, parent) => {
1159
+ const open = expandedTrips.has(trip.id);
1160
+ const toggleKeep = async () => {
1161
+ if (pending.has(trip.id)) return;
1162
+ pending.add(trip.id); errors.delete(trip.id); renderResults();
1163
+ try {
1164
+ const result = await ctx.invoke('favorite', [{ id: trip.id, keep: !trip.kept }]);
1165
+ if (!result?.ok) throw new Error(result?.error ?? '珍藏状态保存失败');
1166
+ await load(true);
1167
+ } catch (error) { errors.set(trip.id, error?.message ?? String(error)); }
1168
+ finally { pending.delete(trip.id); render(currentData ?? data); }
1169
+ };
1170
+ const card = el('article', { class: 'fun-trip fun-ticket', 'data-trip-id': trip.id },
1171
+ el('div', { class: 'fun-trip-head' }, el('span', { class: 'fun-trip-name', text: trip.placeName }),
1172
+ el('span', { class: 'fun-trip-when', text: (trip.enteredHm || '时间不详') + '–' + (trip.leftHm || '时间不详') + (trip.stayedMin ? ' · ' + trip.stayedMin + ' 分钟' : '') })),
1173
+ el('div', { class: 'fun-trip-sum', text: trip.summary }),
1174
+ trip.routeOrder ? el('div', { class: 'fun-note', text: '联程 · 第 ' + trip.routeOrder + ' 站' }) : null,
1175
+ el('div', { class: 'fun-trip-actions' },
1176
+ el('button', { type: 'button', class: 'fun-detail-toggle', 'data-trip-id': trip.id, 'aria-expanded': String(open), onclick: () => {
1177
+ if (open) expandedTrips.delete(trip.id); else expandedTrips.add(trip.id);
1178
+ renderResults();
1179
+ [...results.querySelectorAll('.fun-detail-toggle')].find((button) => button.getAttribute('data-trip-id') === trip.id)?.focus?.();
1180
+ } }, open ? '收起详情' : '查看详情'),
1181
+ el('button', { type: 'button', disabled: pending.has(trip.id) ? 'disabled' : null, onclick: toggleKeep }, pending.has(trip.id) ? '保存中…' : trip.kept ? '取消珍藏' : '珍藏'),
1182
+ errors.has(trip.id) ? el('span', { class: 'fun-trip-error', role: 'alert', text: errors.get(trip.id) }) : null));
1183
+ if (open) card.appendChild(tripDetails(trip));
1184
+ parent.appendChild(card);
874
1185
  };
875
- const card = el('article', { class: 'fun-trip fun-ticket' },
876
- el('div', { class: 'fun-trip-head' }, el('span', { class: 'fun-trip-name', text: t.placeName }),
877
- el('span', { class: 'fun-trip-when', text: t.enteredHm + '–' + t.leftHm + (t.stayedMin ? ' · ' + t.stayedMin + ' 分钟' : '') })),
878
- el('div', { class: 'fun-trip-sum', text: t.summary }),
879
- el('div', { class: 'fun-trip-actions' },
880
- el('button', { type: 'button', 'aria-expanded': String(open), onclick: () => {
881
- if (open) expandedTrips.delete(t.id); else expandedTrips.add(t.id);
1186
+ const drawnRoutes = new Set();
1187
+ let previousDay = null;
1188
+ for (const trip of trips) {
1189
+ const route = trip.routeId && (data.routes ?? []).find((group) => group.id === trip.routeId);
1190
+ if (route) {
1191
+ if (drawnRoutes.has(route.id)) continue;
1192
+ drawnRoutes.add(route.id);
1193
+ const group = el('section', { class: 'fun-route-group', 'data-route-id': route.id });
1194
+ group.appendChild(routeSummary(route, allTrips, (selected) => {
1195
+ expandedTrips.add(selected.id); bookKeyword = ''; bookPlace = ''; bookDate = ''; bookTab = 'all';
882
1196
  render(currentData);
883
- const focus = body.querySelectorAll('.fun-detail-toggle');
884
- [...focus].find((node) => node.getAttribute('data-trip-id') === t.id)?.focus();
885
- }, class: 'fun-detail-toggle', 'data-trip-id': t.id }, open ? '收起详情' : '查看详情'),
886
- el('button', { type: 'button', disabled: pending.has(t.id) ? 'disabled' : null, onclick: toggleKeep }, pending.has(t.id) ? '保存中…' : (t.kept ? '取消珍藏' : '珍藏')),
887
- err ? el('span', { class: 'fun-trip-error', role: 'alert', text: err }) : null));
888
- if (open) {
889
- const detail = el('section', { class: 'fun-trip-detail', 'aria-label': t.placeName + '行程详情' });
890
- const part = (title, values) => {
891
- if (!values.length) return;
892
- detail.appendChild(el('div', { class: 'fun-sec', text: title }));
893
- detail.appendChild(el('ul', { class: 'fun-list' }, values.map((text) => el('li', { text }))));
894
- };
895
- if (t.company) detail.appendChild(el('p', { text: '同行 · ' + t.company }));
896
- part('沿途逛过', t.visited ?? []);
897
- part('遇见的小事', t.events ?? []);
898
- part('当时的选择', (t.choices ?? []).map((c) => c.event + ' · ' + c.result));
899
- part('带回的纪念品', t.souvenirs ?? []);
900
- part('拍照记录', t.photos ?? []);
901
- part('吃喝记录', (t.ate ?? []).map((x) => x.verb + '了 ' + x.item));
902
- if (t.note) detail.appendChild(el('p', { text: '收摊备注 · ' + t.note }));
903
- if (t.scene) detail.appendChild(el('p', { class: 'fun-dim', text: '生图 scene:' + t.scene + (t.outfit ? ' · outfits:' + t.outfit : '') }));
904
- card.appendChild(detail);
1197
+ [...body.querySelectorAll('.fun-detail-toggle')].find((button) => button.getAttribute('data-trip-id') === selected.id)?.focus?.();
1198
+ }));
1199
+ const members = (route.tripIds ?? []).map((id) => trips.find((member) => member.id === id)).filter(Boolean);
1200
+ for (const member of members) { group.appendChild(el('div', { class: 'fun-date', text: member.day || '日期不详' })); appendTrip(member, group); }
1201
+ results.appendChild(group); previousDay = null;
1202
+ } else {
1203
+ if (trip.day !== previousDay) { results.appendChild(el('div', { class: 'fun-date', text: trip.day || '日期不详' })); previousDay = trip.day; }
1204
+ appendTrip(trip, results);
1205
+ }
905
1206
  }
906
- body.appendChild(card);
907
- }
908
- if (bookTab === 'kept' && !trips.length) body.appendChild(el('div', { class: 'fun-empty', text: '还没有珍藏的行程。' }));
1207
+ if (!trips.length) results.appendChild(el('div', { class: 'fun-empty', text: bookKeyword || bookPlace || bookDate ? '没有匹配的行程,试试其他地点、日期或搜索词。' : bookTab === 'kept' ? '还没有珍藏的行程。' : '还没有可回看的行程。' }));
1208
+ };
1209
+ search.addEventListener('input', () => { bookKeyword = search.value; renderResults(); });
1210
+ place.addEventListener('change', () => { bookPlace = place.value; renderResults(); });
1211
+ date.addEventListener('change', () => { bookDate = date.value; renderResults(); });
1212
+ renderResults();
1213
+ restoreFocus();
909
1214
  };
910
1215
 
911
1216
  const stat = (n, label) => el('div', { class: 'fun-stat' },
@@ -948,6 +1253,7 @@ function mountShelf(ctx) {
948
1253
  el('b', { text: String(n) }), el('span', { text: label }));
949
1254
 
950
1255
  const pct = (part) => `${part.done}/${part.total}`;
1256
+ const memoryTrip = tripLookup(ctx, 'trip', 'id', '回看这趟行程');
951
1257
 
952
1258
  const render = (data) => {
953
1259
  currentData = data;
@@ -972,12 +1278,13 @@ function mountShelf(ctx) {
972
1278
  el('span', { class: 'fun-trip-name', text: g.placeName }),
973
1279
  el('span', { class: 'fun-trip-when', text: `${g.items.length} 样 · 最早 ${g.firstDay || '—'}` })),
974
1280
  el('div', { class: 'fun-shelf-grid' }, g.items.map((it) => el('details', { class: 'fun-keepsake' },
975
- el('summary', null, el('strong', { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ''}` }),
1281
+ el('summary', null, itemIcon(it.name), el('strong', { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ''}` }),
976
1282
  el('span', { class: 'fun-dim', text: `记录中最早 ${it.firstDay || '日期不详'}` })),
977
1283
  it.archivedCount ? el('div', { class: 'fun-note', text: `${it.archivedCount} 次收藏仅保留账本,详细行程已不在近期记录中。` }) : null,
978
1284
  ...(it.memories ?? []).map((m) => el('div', { class: 'fun-trip-sum' },
979
1285
  el('div', { text: `${m.day || '日期不详'} · ${m.summary}` }),
980
- m.note ? el('div', { text: `你记的:${m.note}` }) : null)))))));
1286
+ m.note ? el('div', { text: `你记的:${m.note}` }) : null,
1287
+ m.id ? memoryTrip(m.id) : null)))))));
981
1288
  }
982
1289
 
983
1290
  // 进度:只列去过的。服务端已按「快逛遍的」排好,这里照顺序画。
@@ -992,6 +1299,7 @@ function mountShelf(ctx) {
992
1299
  el('span', { class: 'fun-trip-when', text: `去过 ${p.visits} 次 · ${p.percent}%` })),
993
1300
  el('progress', { class: 'fun-progress', max: '100', value: String(p.percent), 'aria-label': `${p.placeName}探索进度 ${p.percent}%` }),
994
1301
  el('div', { class: 'fun-meta', text: `逛过 ${pct(p.areas)}${p.souvenirs.total ? ` · 纪念品 ${pct(p.souvenirs)}` : ''}${p.photos.total ? ` · 拍过 ${pct(p.photos)}` : ''}` }),
1302
+ p.phases?.length ? el('div', { class: 'fun-note fun-visited-phases', text: `去过的时段:${p.phases.join('、')}` }) : null,
995
1303
  left
996
1304
  ? el('div', { class: 'fun-trip-sum', text: `还差:${p.areas.left.slice(0, 6).join('、')}${left > 6 ? ` 等 ${left} 处` : ''}` })
997
1305
  : el('div', { class: 'fun-trip-sum', text: '这一处已经逛遍了。' })));
@@ -1020,5 +1328,6 @@ export default {
1020
1328
  places: { mount: mountPlaces },
1021
1329
  book: { mount: mountBook },
1022
1330
  shelf: { mount: mountShelf },
1331
+ stories: { mount: mountStories },
1023
1332
  },
1024
1333
  };