cortico-world-fun 0.2.0 → 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/CHANGELOG.md +29 -0
- package/PUBLISHING.md +59 -195
- package/README.md +66 -4
- package/describe.json +171 -10
- package/dist/artwork.js +64 -0
- package/dist/stories.js +395 -0
- package/dist/webui.js +523 -116
- package/package.json +5 -5
- package/src/ENV_PROMPT.md +2 -1
- package/src/branches.js +62 -0
- package/src/definition.js +16 -4
- package/src/exploration.js +268 -0
- package/src/journeys.js +65 -0
- package/src/keepsakes.js +28 -6
- package/src/recommendations.js +109 -0
- package/src/state.js +71 -39
- package/src/story-examples.js +111 -0
- package/src/story-library.js +149 -0
- package/src/story-packs.js +428 -0
- package/src/world.js +425 -124
package/dist/webui.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mountStories } from './stories.js';
|
|
1
2
|
/**
|
|
2
3
|
* 娱乐时间面板的浏览器端(Coo WebUI 扩展面板)。
|
|
3
4
|
*
|
|
@@ -12,11 +13,14 @@
|
|
|
12
13
|
* 颜色走宿主主题的自定义属性(--surface/--foreground/--border/--accent…),
|
|
13
14
|
* 自定义属性会继承进 shadow root,所以明暗两套主题都不用自己写。
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
+
* 三个面板:
|
|
16
17
|
* places —— 二十处地方(以及自己加的、改过的)此刻的状态,以及她正在逛的这一趟
|
|
17
|
-
* book ——
|
|
18
|
+
* book —— 纪念册:去过的每一趟与出游心愿
|
|
19
|
+
* shelf —— 纪念品架:长期收藏与探索进度
|
|
18
20
|
*/
|
|
19
21
|
|
|
22
|
+
import { venueArtwork, souvenirArtwork, souvenirCategory } from './artwork.js';
|
|
23
|
+
|
|
20
24
|
const CSS = `
|
|
21
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}
|
|
22
26
|
.fun *{box-sizing:border-box}
|
|
@@ -34,6 +38,15 @@ const CSS = `
|
|
|
34
38
|
.fun-sec:first-child{margin-top:2px}
|
|
35
39
|
|
|
36
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
|
+
|
|
37
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)}
|
|
38
51
|
.fun-live-idle{border-left-color:var(--f-line)}
|
|
39
52
|
.fun-live h3{margin:0 0 3px;font-size:14px;font-weight:600}
|
|
@@ -119,6 +132,45 @@ const CSS = `
|
|
|
119
132
|
.fun-stat span{font-size:11.5px;color:var(--f-dim)}
|
|
120
133
|
.fun-empty{padding:22px 12px;text-align:center;color:var(--f-dim);font-size:12.5px}
|
|
121
134
|
.fun-err{border:1px solid #d9534f;border-radius:var(--radius-sm,6px);padding:10px 12px;color:#d9534f;background:color-mix(in srgb,#d9534f 10%,transparent);font-size:12.5px}
|
|
135
|
+
/* 轻手账:跟随宿主主题,只用少量色彩区分内容层次。 */
|
|
136
|
+
.fun{font-size:14px;line-height:1.65;padding:8px 4px 24px;--f-round:12px}
|
|
137
|
+
.fun button,.fun input,.fun select{min-height:34px}
|
|
138
|
+
.fun button:focus-visible,.fun input:focus-visible,.fun select:focus-visible,.fun textarea:focus-visible,.fun summary:focus-visible{outline:2px solid var(--f-accent);outline-offset:3px}
|
|
139
|
+
.fun button:disabled{cursor:default;opacity:.6}
|
|
140
|
+
.fun .fun-btn-primary{background:var(--f-accent);border-color:var(--f-accent);color:var(--accent-foreground,#fff)}
|
|
141
|
+
.fun-heading{margin-bottom:16px;padding:4px 0 12px;border-bottom:1px solid var(--f-line)}
|
|
142
|
+
.fun-heading h2{font-size:20px;line-height:1.4;margin:0 0 4px;letter-spacing:.03em}
|
|
143
|
+
.fun-heading p{margin:0;color:var(--f-dim);font-size:12.5px}
|
|
144
|
+
.fun-live,.fun-trip,.fun-stats,.fun-form{border-radius:var(--f-round);padding:14px 16px}
|
|
145
|
+
.fun-live{background:linear-gradient(120deg,color-mix(in srgb,var(--f-accent) 8%,var(--f-card)),var(--f-card));margin-bottom:16px}
|
|
146
|
+
.fun-live h3{font-size:16px}
|
|
147
|
+
.fun-grid{grid-template-columns:repeat(auto-fill,minmax(min(232px,100%),1fr));gap:12px}
|
|
148
|
+
.fun-card{padding:14px;border-radius:var(--f-round);min-height:136px;background:linear-gradient(180deg,color-mix(in srgb,var(--f-accent) 4%,var(--f-card)),var(--f-card) 65%)}
|
|
149
|
+
.fun-card-name{font-size:15px}.fun-card-head{flex-wrap:wrap}.fun-card-desc{line-height:1.7;margin-top:8px}
|
|
150
|
+
.fun-detail{padding:16px;border-radius:0 0 var(--f-round) var(--f-round)}
|
|
151
|
+
.fun-card-active{border-bottom-left-radius:0;border-bottom-right-radius:0;background:color-mix(in srgb,var(--f-accent) 7%,var(--f-card))}
|
|
152
|
+
.fun-tabs,.fun-filters{display:flex;gap:7px;flex-wrap:wrap;margin:12px 0 16px}
|
|
153
|
+
.fun-tabs button,.fun-filters button{border-radius:999px;padding:5px 13px;background:transparent}
|
|
154
|
+
.fun-tabs button[aria-pressed="true"],.fun-filters button[aria-pressed="true"]{border-color:var(--f-accent);color:var(--f-ink);background:color-mix(in srgb,var(--f-accent) 12%,var(--f-card));font-weight:600}
|
|
155
|
+
.fun-stats{gap:18px;background:var(--f-soft);border:none}.fun-stat b{font-size:21px}.fun-stat span{font-size:12px}
|
|
156
|
+
.fun-trip-head{flex-wrap:wrap}.fun-trip-name{font-size:14px}.fun-trip-when{white-space:normal}
|
|
157
|
+
.fun-date{margin:20px 0 10px;font-size:12px;color:var(--f-dim);font-weight:600;display:flex;align-items:center;gap:10px}
|
|
158
|
+
.fun-date:after{content:'';height:1px;background:var(--f-line);flex:1}
|
|
159
|
+
.fun-ticket{position:relative;border-left:3px solid color-mix(in srgb,var(--f-accent) 55%,var(--f-line));margin-bottom:12px}
|
|
160
|
+
.fun-trip-detail{border-top:1px dashed var(--f-line);margin-top:12px;padding-top:4px}
|
|
161
|
+
.fun-trip-detail .fun-sec{margin-top:10px}.fun-trip-detail p{margin:4px 0;font-size:13px;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
162
|
+
.fun-wish-history{margin-top:14px}.fun-wish-history>summary{cursor:pointer;padding:8px 0;color:var(--f-dim)}
|
|
163
|
+
.fun-shelf-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(180px,100%),1fr));gap:10px;margin-top:12px}
|
|
164
|
+
.fun-keepsake{border:1px solid var(--f-line);border-radius:10px;padding:12px;background:var(--f-soft);min-width:0}
|
|
165
|
+
.fun-keepsake>summary{cursor:pointer;line-height:1.7;overflow-wrap:anywhere}.fun-keepsake>summary strong{display:block;color:var(--f-ink);font-weight:600}
|
|
166
|
+
.fun-keepsake .fun-trip-sum{border-top:1px dashed var(--f-line);margin-top:9px;padding-top:9px}
|
|
167
|
+
.fun-progress{display:block;width:100%;height:7px;margin:10px 0;accent-color:var(--f-accent);border:0;border-radius:8px;overflow:hidden;background:var(--f-line)}
|
|
168
|
+
.fun-progress::-webkit-progress-bar{background:var(--f-line);border-radius:8px}.fun-progress::-webkit-progress-value{background:var(--f-accent);border-radius:8px}.fun-progress::-moz-progress-bar{background:var(--f-accent);border-radius:8px}
|
|
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}
|
|
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)}
|
|
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}}
|
|
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}}
|
|
173
|
+
|
|
122
174
|
`;
|
|
123
175
|
|
|
124
176
|
/** 小工具:建元素 + 设属性,省掉一屏 createElement。 */
|
|
@@ -157,8 +209,176 @@ function shell(root) {
|
|
|
157
209
|
return box;
|
|
158
210
|
}
|
|
159
211
|
|
|
160
|
-
function errorCard(err) {
|
|
161
|
-
return el('div', { class: 'fun-err',
|
|
212
|
+
function errorCard(err, retry, retained = false) {
|
|
213
|
+
return el('div', { class: 'fun-err', role: 'alert' },
|
|
214
|
+
el('span', { text: retained ? `刷新失败,保留上次内容:${err?.message ?? String(err)}` : `面板加载失败:${err?.message ?? String(err)}` }),
|
|
215
|
+
retry ? el('button', { type: 'button', onclick: () => { void retry(); } }, '重试') : null);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function heading(title, subtitle) {
|
|
219
|
+
return el('header', { class: 'fun-heading' }, el('h2', { text: title }), el('p', { text: subtitle }));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function feedback(box) {
|
|
223
|
+
const node = el('div', { class: 'fun-feedback' });
|
|
224
|
+
box.appendChild(node);
|
|
225
|
+
return node;
|
|
226
|
+
}
|
|
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
|
+
};
|
|
162
382
|
}
|
|
163
383
|
|
|
164
384
|
// ---------------------------------------------------------------------------
|
|
@@ -173,14 +393,23 @@ function mountPlaces(ctx) {
|
|
|
173
393
|
box.appendChild(body);
|
|
174
394
|
|
|
175
395
|
let keyword = '';
|
|
396
|
+
let quickFilter = '全部';
|
|
176
397
|
let expanded = null;
|
|
398
|
+
let expandedOrigin = 'list';
|
|
399
|
+
const historyView = tripLookup(ctx, 'history', 'placeId', '回看这里的行程');
|
|
177
400
|
/** null = 没在编辑;{ mode: 'new' | 'edit', venue } = 打开表单。 */
|
|
178
401
|
let editing = null;
|
|
179
402
|
let formError = '';
|
|
403
|
+
let outingAction = '';
|
|
404
|
+
let notice = null;
|
|
405
|
+
let loadSequence = 0;
|
|
180
406
|
/** 表单打开期间收到的最新数据,等关掉表单再补画,免得把用户填的内容冲掉。 */
|
|
181
407
|
let currentData = null;
|
|
408
|
+
const status = feedback(box);
|
|
409
|
+
body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在看看有哪些地方开着…' }));
|
|
182
410
|
|
|
183
411
|
const render = (data) => {
|
|
412
|
+
const restoreFocus = rememberFocus(body);
|
|
184
413
|
// 表单相关声明要放在最前:点「添加地点」时 render 会重跑,
|
|
185
414
|
// 而那一轮里 `venueForm()` 在 `if (editing)` 处就会用到 `fields`。
|
|
186
415
|
// 放在后面会撞上 TDZ(`Cannot access 'fields' before initialization`)。
|
|
@@ -188,7 +417,29 @@ function mountPlaces(ctx) {
|
|
|
188
417
|
const fields = {};
|
|
189
418
|
const lines = (v) => (Array.isArray(v) ? v.join('\n') : '');
|
|
190
419
|
const parseLines = (s) => String(s ?? '').split(/[\n,,、]/).map((x) => x.trim()).filter(Boolean);
|
|
191
|
-
|
|
420
|
+
currentData = data;
|
|
421
|
+
body.replaceChildren(heading('去哪儿', '挑一处喜欢的地方,慢慢逛。'));
|
|
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
|
+
}
|
|
192
443
|
|
|
193
444
|
// ---- 正在逛的那一趟 ----
|
|
194
445
|
if (data.session) {
|
|
@@ -197,7 +448,8 @@ function mountPlaces(ctx) {
|
|
|
197
448
|
const leftAreas = venue
|
|
198
449
|
? venue.areas.filter((a) => !s.visited.some((v) => v.area === a))
|
|
199
450
|
: [];
|
|
200
|
-
const leftText =
|
|
451
|
+
const leftText = venue?.state === 'closed' ? '这处已经打烊'
|
|
452
|
+
: leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join('、')}` : '这会儿开放的都逛过了';
|
|
201
453
|
const progress = s.venueAreaCount ? `${s.visited.length}/${s.venueAreaCount}` : String(s.visited.length);
|
|
202
454
|
body.appendChild(el('div', { class: 'fun-live' },
|
|
203
455
|
el('h3', { text: `正在${s.placeName}逛` }),
|
|
@@ -212,8 +464,9 @@ function mountPlaces(ctx) {
|
|
|
212
464
|
: null,
|
|
213
465
|
s.events.length ? el('ul', { class: 'fun-list' }, s.events.slice(-3).map((e) => el('li', { text: e }))) : null,
|
|
214
466
|
venue ? el('div', { class: 'fun-meta', text: leftText }) : null,
|
|
467
|
+
pendingChoice(s.pendingChoice),
|
|
215
468
|
));
|
|
216
|
-
} else {
|
|
469
|
+
} else if (!draft) {
|
|
217
470
|
body.appendChild(el('div', { class: 'fun-live fun-live-idle' },
|
|
218
471
|
el('h3', { text: '这会儿没在逛' }),
|
|
219
472
|
el('div', { class: 'fun-meta', text: `现在 ${data.nowHm} · ${data.total} 处地方里 ${data.openCount} 处开着` }),
|
|
@@ -221,11 +474,23 @@ function mountPlaces(ctx) {
|
|
|
221
474
|
));
|
|
222
475
|
}
|
|
223
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
|
+
|
|
224
488
|
// ---- 搜索条 + 自填地点 ----
|
|
225
489
|
const input = el('input', {
|
|
226
490
|
class: 'fun-search',
|
|
227
491
|
type: 'search',
|
|
228
492
|
placeholder: '搜地方名、别名或标签(庙会 / 室内 / 夜…)',
|
|
493
|
+
'aria-label': '搜索全部地方', 'data-focus-key': 'places-search',
|
|
229
494
|
value: keyword,
|
|
230
495
|
});
|
|
231
496
|
input.addEventListener('input', () => {
|
|
@@ -234,7 +499,6 @@ function mountPlaces(ctx) {
|
|
|
234
499
|
renderList();
|
|
235
500
|
});
|
|
236
501
|
const addBtn = el('button', {
|
|
237
|
-
class: 'fun-btn-primary',
|
|
238
502
|
type: 'button',
|
|
239
503
|
onclick: () => {
|
|
240
504
|
editing = { mode: 'new', venue: null };
|
|
@@ -242,10 +506,11 @@ function mountPlaces(ctx) {
|
|
|
242
506
|
renderAll();
|
|
243
507
|
},
|
|
244
508
|
}, '+ 添加地点');
|
|
245
|
-
body.appendChild(el('div', { class: 'fun-bar' }, input
|
|
509
|
+
body.appendChild(el('div', { class: 'fun-bar' }, input));
|
|
510
|
+
management.appendChild(el('div', { class: 'fun-bar' }, addBtn));
|
|
246
511
|
|
|
247
512
|
// B 阶段:预设也能编辑(改的是覆盖层,预设本身不动);删只对自己的地方。
|
|
248
|
-
|
|
513
|
+
management.appendChild(el('div', { class: 'fun-hint' },
|
|
249
514
|
`预设的 ${data.total - data.userVenueCount} 处插件自带,现在也能改——改过的会标「已改」,`
|
|
250
515
|
+ `随时能恢复;你自己加了 ${data.userVenueCount} 处,随时能改能删。`
|
|
251
516
|
+ (data.overriddenCount
|
|
@@ -257,28 +522,44 @@ function mountPlaces(ctx) {
|
|
|
257
522
|
|
|
258
523
|
// 一键恢复全部预设:只在真有覆盖层时给,免得平时多一个没用的按钮。
|
|
259
524
|
if (data.overriddenCount) {
|
|
260
|
-
|
|
261
|
-
|
|
525
|
+
const resetError = el('div', { class: 'fun-form-error', role: 'alert' });
|
|
526
|
+
const resetButton = el('button', {
|
|
262
527
|
type: 'button',
|
|
263
528
|
style: { marginBottom: '10px' },
|
|
264
529
|
onclick: async () => {
|
|
530
|
+
if (resetButton.disabled) return;
|
|
531
|
+
resetButton.disabled = true; resetError.textContent = ''; resetButton.textContent = '恢复中…';
|
|
265
532
|
try {
|
|
266
533
|
const r = await ctx.invoke('resetAll', []);
|
|
267
|
-
if (!r?.ok)
|
|
534
|
+
if (!r?.ok) throw new Error(r?.error ?? '恢复不了');
|
|
268
535
|
formError = '';
|
|
269
536
|
await load();
|
|
270
537
|
} catch (err) {
|
|
271
|
-
|
|
272
|
-
}
|
|
538
|
+
resetError.textContent = err?.message ?? String(err);
|
|
539
|
+
} finally { resetButton.disabled = false; resetButton.textContent = `恢复全部预设(${data.overriddenCount} 处)`; }
|
|
273
540
|
},
|
|
274
|
-
}, `恢复全部预设(${data.overriddenCount} 处)`)
|
|
541
|
+
}, `恢复全部预设(${data.overriddenCount} 处)`);
|
|
542
|
+
management.appendChild(resetButton); management.appendChild(resetError);
|
|
275
543
|
}
|
|
276
544
|
|
|
277
545
|
// ---- 编辑表单(打开时在最上面) ----
|
|
278
546
|
if (editing) body.appendChild(venueForm());
|
|
279
547
|
|
|
548
|
+
const filterBar = el('div', { class: 'fun-filters', role: 'group', 'aria-label': '地点快捷筛选' });
|
|
549
|
+
const filterButtons = [];
|
|
550
|
+
for (const label of ['全部', '现在开着', '室内', '户外', '夜游', '我的地点']) {
|
|
551
|
+
const button = el('button', { type: 'button', 'aria-pressed': String(quickFilter === label), onclick: () => {
|
|
552
|
+
quickFilter = label;
|
|
553
|
+
for (const item of filterButtons) item.button.setAttribute('aria-pressed', String(item.label === label));
|
|
554
|
+
renderList();
|
|
555
|
+
} }, label);
|
|
556
|
+
filterButtons.push({ label, button });
|
|
557
|
+
filterBar.appendChild(button);
|
|
558
|
+
}
|
|
559
|
+
body.appendChild(filterBar);
|
|
280
560
|
const listBox = el('div');
|
|
281
561
|
body.appendChild(listBox);
|
|
562
|
+
body.appendChild(management);
|
|
282
563
|
|
|
283
564
|
/**
|
|
284
565
|
* 重画列表。
|
|
@@ -289,18 +570,39 @@ function mountPlaces(ctx) {
|
|
|
289
570
|
function renderList() {
|
|
290
571
|
listBox.replaceChildren();
|
|
291
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
|
+
}
|
|
585
|
+
const filtered = data.places.filter((p) => {
|
|
586
|
+
const tags = p.tags ?? [];
|
|
587
|
+
if (quickFilter === '现在开着') return p.state !== 'closed';
|
|
588
|
+
if (quickFilter === '我的地点') return p.userVenue;
|
|
589
|
+
if (quickFilter === '室内') return tags.some((tag) => tag.includes('室内'));
|
|
590
|
+
if (quickFilter === '户外') return tags.some((tag) => /户外|室外/.test(tag));
|
|
591
|
+
if (quickFilter === '夜游') return tags.some((tag) => /夜/.test(tag));
|
|
592
|
+
return true;
|
|
593
|
+
});
|
|
292
594
|
const matched = kw
|
|
293
|
-
?
|
|
595
|
+
? filtered.filter((p) => p.name.toLowerCase().includes(kw)
|
|
294
596
|
|| p.aliases.some((a) => a.toLowerCase().includes(kw))
|
|
295
597
|
|| p.tags.some((t) => t.toLowerCase().includes(kw)))
|
|
296
|
-
:
|
|
598
|
+
: filtered;
|
|
297
599
|
|
|
298
600
|
const open = matched.filter((p) => p.state !== 'closed');
|
|
299
601
|
const closed = matched.filter((p) => p.state === 'closed');
|
|
300
602
|
|
|
301
603
|
/** 一格里画卡;展开时它后面紧跟一条详情,并且这一格跨满整行。 */
|
|
302
604
|
const cell = (p) => {
|
|
303
|
-
const isOpen = expanded === p.id;
|
|
605
|
+
const isOpen = expanded === p.id && expandedOrigin === 'list';
|
|
304
606
|
const wrap = el('div', { class: isOpen ? 'fun-cell fun-cell-open' : 'fun-cell' });
|
|
305
607
|
wrap.appendChild(card(p));
|
|
306
608
|
if (isOpen) wrap.appendChild(detail(p));
|
|
@@ -312,41 +614,47 @@ function mountPlaces(ctx) {
|
|
|
312
614
|
listBox.appendChild(el('div', { class: 'fun-sec', text: title }));
|
|
313
615
|
listBox.appendChild(el('div', { class: 'fun-grid' }, items.map(cell)));
|
|
314
616
|
};
|
|
315
|
-
section(kw ?
|
|
617
|
+
section(kw || quickFilter !== '全部' ? `筛选结果 · 开着的(${open.length})` : `开着的(${open.length})`, open);
|
|
316
618
|
section('已经关了', closed);
|
|
317
619
|
if (!matched.length) {
|
|
318
|
-
listBox.appendChild(el('div', { class: 'fun-empty', text: `没有匹配「${keyword}
|
|
620
|
+
listBox.appendChild(el('div', { class: 'fun-empty', text: kw ? `没有匹配「${keyword}」的地方,试试其他筛选。` : '这个筛选下还没有地方,换一项看看。' }));
|
|
319
621
|
}
|
|
320
622
|
}
|
|
321
623
|
|
|
322
|
-
const card = (p) => {
|
|
323
|
-
const
|
|
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'];
|
|
324
627
|
if (p.state === 'closed') cls.push('fun-card-closed');
|
|
325
628
|
else if (p.state === 'closingSoon') cls.push('fun-card-soon');
|
|
326
629
|
else cls.push('fun-card-open');
|
|
327
|
-
if (
|
|
630
|
+
if (selected) cls.push('fun-card-active');
|
|
328
631
|
const stateCls = p.state === 'open' ? 'fun-card-state-open'
|
|
329
632
|
: (p.state === 'closingSoon' ? 'fun-card-state-soon' : '');
|
|
330
633
|
const node = el('div', {
|
|
331
634
|
class: cls.join(' '),
|
|
332
635
|
role: 'button',
|
|
333
636
|
tabindex: '0',
|
|
334
|
-
'aria-expanded':
|
|
335
|
-
|
|
637
|
+
'aria-expanded': selected ? 'true' : 'false',
|
|
638
|
+
'aria-label': `${p.name},${p.stateLabel},查看详情`, 'data-place-id': p.id,
|
|
639
|
+
onclick: () => toggle(p.id, recommended),
|
|
336
640
|
onkeydown: (ev) => {
|
|
337
641
|
// 键盘也能开合:卡片是 role=button,不能只认鼠标。
|
|
338
642
|
if (ev.key === 'Enter' || ev.key === ' ' || ev.key === 'Spacebar') {
|
|
339
643
|
ev.preventDefault?.();
|
|
340
|
-
toggle(p.id);
|
|
644
|
+
toggle(p.id, recommended, true);
|
|
341
645
|
}
|
|
342
646
|
},
|
|
343
647
|
},
|
|
648
|
+
sceneArt(p),
|
|
344
649
|
el('div', { class: 'fun-card-head' },
|
|
345
|
-
el('span', { class: 'fun-card-name', text: p.name }),
|
|
650
|
+
el('span', { class: recommended ? 'fun-recommend-name' : 'fun-card-name', text: p.name }),
|
|
346
651
|
p.phase ? el('span', { class: 'fun-chip fun-chip-phase', text: p.phase }) : null,
|
|
347
652
|
el('span', { class: `fun-card-state ${stateCls}`, text: p.stateLabel }),
|
|
348
|
-
el('span', { class: 'fun-card-arrow', text:
|
|
349
|
-
el('div', { class: 'fun-
|
|
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,
|
|
350
658
|
el('div', { class: 'fun-card-foot' },
|
|
351
659
|
el('span', { text: `${p.hours.open}–${p.hours.close}` }),
|
|
352
660
|
el('span', { text: p.crowdLabel }),
|
|
@@ -364,18 +672,22 @@ function mountPlaces(ctx) {
|
|
|
364
672
|
* 用户会以为自己点错了。`block: 'nearest'` 保证「已经看得见就不动」,
|
|
365
673
|
* 不会因为点一张本来就在屏幕里的卡而把页面跳一下。
|
|
366
674
|
*/
|
|
367
|
-
function toggle(id) {
|
|
368
|
-
const
|
|
675
|
+
function toggle(id, recommended = false, keyboard = false) {
|
|
676
|
+
const origin = recommended ? 'recommend' : 'list';
|
|
677
|
+
const wasOpen = expanded === id && expandedOrigin === origin;
|
|
369
678
|
expanded = wasOpen ? null : id;
|
|
679
|
+
expandedOrigin = origin;
|
|
370
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?.();
|
|
371
683
|
if (!wasOpen) {
|
|
372
684
|
// 滚的是**整格**(卡 + 详情),不是只滚卡片:
|
|
373
685
|
// 卡片恰好贴在视口底部时,只保证卡片可见等于详情还在屏幕外。
|
|
374
|
-
const active = listBox.querySelector('.fun-card-active');
|
|
686
|
+
const active = (recommended ? recommendBox : listBox).querySelector('.fun-card-active');
|
|
375
687
|
const target = active?.parentNode ?? active;
|
|
376
688
|
// 真 DOM 有 scrollIntoView;测试桩没有,判一下再用。
|
|
377
689
|
if (target && typeof target.scrollIntoView === 'function') {
|
|
378
|
-
target.scrollIntoView({ block: 'nearest', behavior: '
|
|
690
|
+
target.scrollIntoView({ block: 'nearest', behavior: 'auto' });
|
|
379
691
|
}
|
|
380
692
|
}
|
|
381
693
|
}
|
|
@@ -408,6 +720,7 @@ function mountPlaces(ctx) {
|
|
|
408
720
|
renderList();
|
|
409
721
|
},
|
|
410
722
|
}, '收起'))),
|
|
723
|
+
sceneArt(p, true),
|
|
411
724
|
el('p', { class: 'fun-dim', text: `${p.kindLabel} · ${p.crowdLabel} · ${p.hours.open}–${p.hours.close} · ${p.stateLabel}` }),
|
|
412
725
|
// 此刻的那段描写:有阶段的场所显示的是「这会儿的样子」,不是通用那段。
|
|
413
726
|
el('p', { class: 'fun-detail-desc', text: p.desc }),
|
|
@@ -428,7 +741,7 @@ function mountPlaces(ctx) {
|
|
|
428
741
|
el('ul', { class: 'fun-list' }, p.areas.map((a) => el('li', { text: a })))),
|
|
429
742
|
el('div', { class: 'fun-detail-col' },
|
|
430
743
|
el('div', { class: 'fun-sec', text: '纪念品' }),
|
|
431
|
-
el('div', { class: 'fun-chips' }, p.souvenirs.map((s) => el('span', { class: 'fun-chip',
|
|
744
|
+
el('div', { class: 'fun-chips' }, p.souvenirs.map((s) => el('span', { class: 'fun-chip' }, itemIcon(s), s))),
|
|
432
745
|
el('div', { class: 'fun-sec', text: '拍照点' }),
|
|
433
746
|
el('div', { class: 'fun-chips' }, p.photoSpots.map((s) => el('span', { class: 'fun-chip', text: s }))),
|
|
434
747
|
p.food
|
|
@@ -442,6 +755,7 @@ function mountPlaces(ctx) {
|
|
|
442
755
|
? el('span', {}, '生图时 ', el('b', { text: `scene 填「${p.scene}」` }), `,outfits 建议「${p.outfit}」`)
|
|
443
756
|
: el('span', {}, '素材库里没有这处的场景,生图时 ', el('b', { text: 'scene 不用填' }), ',把地方写进 prompt 就行')));
|
|
444
757
|
|
|
758
|
+
d.appendChild(historyView(p.id));
|
|
445
759
|
return d;
|
|
446
760
|
};
|
|
447
761
|
|
|
@@ -595,23 +909,48 @@ function mountPlaces(ctx) {
|
|
|
595
909
|
}
|
|
596
910
|
|
|
597
911
|
renderList();
|
|
912
|
+
restoreFocus();
|
|
598
913
|
};
|
|
599
914
|
|
|
600
915
|
const load = async () => {
|
|
916
|
+
const sequence = ++loadSequence;
|
|
601
917
|
try {
|
|
602
918
|
const data = await ctx.invoke('list');
|
|
919
|
+
if (sequence !== loadSequence || ctx.signal?.aborted) return;
|
|
603
920
|
if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
|
|
604
921
|
// 正在填表单时别重画——一分钟的自动刷新会把用户刚填的一整页冲掉。
|
|
605
922
|
if (editing) { currentData = data; return; }
|
|
923
|
+
status.replaceChildren();
|
|
606
924
|
render(data);
|
|
607
925
|
} catch (err) {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
box2.appendChild(errorCard(err));
|
|
926
|
+
if (sequence !== loadSequence || ctx.signal?.aborted) return;
|
|
927
|
+
if (!currentData) body.replaceChildren();
|
|
928
|
+
status.replaceChildren(errorCard(err, load, Boolean(currentData)));
|
|
612
929
|
}
|
|
613
930
|
};
|
|
614
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
|
+
|
|
615
954
|
void load();
|
|
616
955
|
// 状态会随时间变(几点、开没开):一分钟刷一次就够,不打断操作。
|
|
617
956
|
ctx.interval(() => { void load(); }, 60000);
|
|
@@ -628,7 +967,14 @@ function mountBook(ctx) {
|
|
|
628
967
|
const box = shell(root);
|
|
629
968
|
const body = el('div');
|
|
630
969
|
box.appendChild(body);
|
|
631
|
-
let
|
|
970
|
+
let bookTab = 'all';
|
|
971
|
+
let bookKeyword = '';
|
|
972
|
+
let bookPlace = '';
|
|
973
|
+
let bookDate = '';
|
|
974
|
+
let wishFormOpen = false;
|
|
975
|
+
const expandedTrips = new Set();
|
|
976
|
+
const status = feedback(box);
|
|
977
|
+
body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在翻开纪念册…' }));
|
|
632
978
|
const pending = new Set();
|
|
633
979
|
const errors = new Map();
|
|
634
980
|
let currentData = null;
|
|
@@ -642,7 +988,9 @@ function mountBook(ctx) {
|
|
|
642
988
|
const wishes = data.wishes ?? [];
|
|
643
989
|
const adding = wishPending.has('add');
|
|
644
990
|
const section = el('section', { class: 'fun-wishes', 'aria-label': '出游心愿' });
|
|
645
|
-
section.appendChild(el('div', { class: 'fun-
|
|
991
|
+
section.appendChild(el('div', { class: 'fun-bar' },
|
|
992
|
+
el('span', { class: 'fun-sec', text: '出游心愿' }),
|
|
993
|
+
el('button', { type: 'button', 'aria-expanded': String(wishFormOpen), disabled: adding ? 'disabled' : null, onclick: () => { wishFormOpen = !wishFormOpen; render(currentData); } }, wishFormOpen ? '收起表单' : '记个心愿')));
|
|
646
994
|
const field = (label, input) => el('label', { class: 'fun-field' },
|
|
647
995
|
el('span', { class: 'fun-field-label', text: label }), input);
|
|
648
996
|
const select = (className, placeholder, options, value) => {
|
|
@@ -697,13 +1045,16 @@ function mountBook(ctx) {
|
|
|
697
1045
|
wishDraft = { placeId: payload.placeId, type: payload.type, target: payload.target, reason: reasonInput.value };
|
|
698
1046
|
await changeWish('add', payload, data);
|
|
699
1047
|
};
|
|
700
|
-
section.appendChild(el('div', { class: 'fun-form fun-wish-form' },
|
|
1048
|
+
if (wishFormOpen) section.appendChild(el('div', { class: 'fun-form fun-wish-form' },
|
|
701
1049
|
el('div', { class: 'fun-form-note', text: '由你选择想去的地方,按保存才记下心愿;心愿不保证立即出发。' }),
|
|
702
1050
|
el('div', { class: 'fun-form-grid' }, field('地点', placeInput), field('心愿类型', typeInput), field('目标', targetInput)),
|
|
703
1051
|
field('缘由(可选)', reasonInput), errorNode,
|
|
704
1052
|
el('button', { class: 'fun-btn-primary', type: 'button', disabled: adding ? 'disabled' : null, onclick: save }, adding ? '保存中…' : '保存心愿')));
|
|
705
1053
|
if (!wishes.length) section.appendChild(el('div', { class: 'fun-note', text: '还没有出游心愿,想好了再记下。' }));
|
|
706
1054
|
const statusNames = { active: '待实现', paused: '已暂缓', completed: '已实现', cancelled: '已取消' };
|
|
1055
|
+
const history = el('details', { class: 'fun-wish-history',
|
|
1056
|
+
open: wishes.some((w) => w.status !== 'active' && (wishErrors.has(`wish:${w.id}`) || wishPending.has(`wish:${w.id}`))) ? 'open' : null,
|
|
1057
|
+
}, el('summary', { text: `已实现、暂缓与取消(${wishes.filter((w) => w.status !== 'active').length})` }));
|
|
707
1058
|
for (const wish of wishes) {
|
|
708
1059
|
const key = `wish:${wish.id}`;
|
|
709
1060
|
const busy = wishPending.has(key);
|
|
@@ -717,13 +1068,14 @@ function mountBook(ctx) {
|
|
|
717
1068
|
}
|
|
718
1069
|
if (busy) actions.appendChild(el('span', { class: 'fun-dim', text: '保存中…' }));
|
|
719
1070
|
if (wishErrors.has(key)) actions.appendChild(el('span', { class: 'fun-trip-error', role: 'alert', text: wishErrors.get(key) }));
|
|
720
|
-
section.appendChild(el('div', { class: 'fun-wish fun-trip' },
|
|
1071
|
+
(state === 'active' ? section : history).appendChild(el('div', { class: 'fun-wish fun-trip' },
|
|
721
1072
|
el('div', { class: 'fun-trip-head' },
|
|
722
1073
|
el('span', { class: 'fun-trip-name', text: wish.placeName ?? places.find((p) => p.id === wish.placeId)?.name ?? wish.placeId }),
|
|
723
1074
|
el('span', { class: 'fun-wish-status fun-dim', text: statusNames[state] ?? state ?? '状态未知' })),
|
|
724
1075
|
el('div', { class: 'fun-trip-sum', text: `${wishTypes[wish.type] ?? wish.type}${wish.target ? ` · ${wish.target}` : ''}` }),
|
|
725
1076
|
wish.reason ? el('div', { class: 'fun-wish-note fun-note', text: `缘由:${wish.reason}` }) : null, actions));
|
|
726
1077
|
}
|
|
1078
|
+
if (wishes.some((w) => w.status !== 'active')) section.appendChild(history);
|
|
727
1079
|
body.appendChild(section);
|
|
728
1080
|
};
|
|
729
1081
|
|
|
@@ -737,10 +1089,11 @@ function mountBook(ctx) {
|
|
|
737
1089
|
const result = await ctx.invoke('wish', [payload]);
|
|
738
1090
|
if (!result?.ok) throw new Error(result?.error ?? '心愿保存失败');
|
|
739
1091
|
saved = true;
|
|
740
|
-
if (key === 'add') wishDraft = { placeId: '', type: '', target: '', reason: '' };
|
|
1092
|
+
if (key === 'add') { wishDraft = { placeId: '', type: '', target: '', reason: '' }; wishFormOpen = false; }
|
|
741
1093
|
await load(true);
|
|
742
1094
|
} catch (error) {
|
|
743
1095
|
wishErrors.set(key, `${saved ? '已保存,但列表刷新失败:' : ''}${error?.message ?? String(error)}`);
|
|
1096
|
+
if (key === 'add') wishFormOpen = true;
|
|
744
1097
|
} finally {
|
|
745
1098
|
wishPending.delete(key);
|
|
746
1099
|
render(currentData ?? data);
|
|
@@ -748,71 +1101,116 @@ function mountBook(ctx) {
|
|
|
748
1101
|
};
|
|
749
1102
|
|
|
750
1103
|
const render = (data) => {
|
|
1104
|
+
const restoreFocus = rememberFocus(body);
|
|
751
1105
|
currentData = data;
|
|
752
|
-
body.replaceChildren();
|
|
753
|
-
|
|
754
|
-
|
|
1106
|
+
body.replaceChildren(heading('纪念册', '把走过的地方,收成可以回看的小回忆。'));
|
|
1107
|
+
if (data.session) body.appendChild(el('div', { class: 'fun-live' },
|
|
1108
|
+
el('h3', { text: '正在逛 · ' + data.session.placeName }), el('div', { class: 'fun-trip-sum', text: data.session.summary })));
|
|
1109
|
+
else if (data.trips?.length) body.appendChild(el('div', { class: 'fun-live' },
|
|
1110
|
+
el('div', { class: 'fun-meta', text: '最近一趟 · ' + data.trips[0].day }),
|
|
1111
|
+
el('h3', { text: data.trips[0].placeName }), el('div', { class: 'fun-trip-sum', text: data.trips[0].summary })));
|
|
1112
|
+
|
|
1113
|
+
const tabs = el('nav', { class: 'fun-tabs', 'aria-label': '纪念册分类' });
|
|
1114
|
+
for (const [id, label] of [['all', '全部行程'], ['kept', '珍藏'], ['wishes', '心愿']]) tabs.appendChild(el('button', {
|
|
1115
|
+
type: 'button', 'aria-pressed': String(bookTab === id), onclick: () => { bookTab = id; render(currentData); },
|
|
1116
|
+
}, label));
|
|
1117
|
+
body.appendChild(tabs);
|
|
1118
|
+
if (bookTab === 'wishes') { renderWishes(data); restoreFocus(); return; }
|
|
1119
|
+
if (!data.total && !(data.keepsakeCount > 0)) {
|
|
755
1120
|
body.appendChild(el('div', { class: 'fun-empty', text: '纪念册还是空的——她收一次摊,这里就有一趟。' }));
|
|
756
1121
|
return;
|
|
757
1122
|
}
|
|
758
|
-
|
|
759
1123
|
body.appendChild(el('div', { class: 'fun-stats' },
|
|
760
|
-
stat(data.totalRecent ?? data.total, '近期行程'),
|
|
761
|
-
stat(data.
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
const
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
const
|
|
784
|
-
|
|
785
|
-
if (
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
pending.
|
|
798
|
-
|
|
799
|
-
|
|
1124
|
+
stat(data.totalRecent ?? data.total, '近期行程'), stat(data.keepsakeCount ?? 0, '珍藏'),
|
|
1125
|
+
stat(data.visitedAreaCount, '处逛过'), stat(data.souvenirCount, '件纪念品'), stat(data.photoCount, '张照片')));
|
|
1126
|
+
if (data.mostVisited?.length) body.appendChild(el('details', { class: 'fun-wish-history' },
|
|
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}` })))));
|
|
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);
|
|
800
1185
|
};
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
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';
|
|
1196
|
+
render(currentData);
|
|
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
|
+
}
|
|
1206
|
+
}
|
|
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();
|
|
816
1214
|
};
|
|
817
1215
|
|
|
818
1216
|
const stat = (n, label) => el('div', { class: 'fun-stat' },
|
|
@@ -822,10 +1220,12 @@ function mountBook(ctx) {
|
|
|
822
1220
|
try {
|
|
823
1221
|
const data = await ctx.invoke('list');
|
|
824
1222
|
if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
|
|
1223
|
+
status.replaceChildren();
|
|
825
1224
|
render(data);
|
|
826
1225
|
} catch (err) {
|
|
827
1226
|
if (propagate) throw err;
|
|
828
|
-
body.replaceChildren(
|
|
1227
|
+
if (!currentData) body.replaceChildren();
|
|
1228
|
+
status.replaceChildren(errorCard(err, load, Boolean(currentData)));
|
|
829
1229
|
}
|
|
830
1230
|
};
|
|
831
1231
|
|
|
@@ -845,17 +1245,21 @@ function mountShelf(ctx) {
|
|
|
845
1245
|
const box = shell(root);
|
|
846
1246
|
const body = el('div');
|
|
847
1247
|
box.appendChild(body);
|
|
1248
|
+
const status = feedback(box);
|
|
1249
|
+
let currentData = null;
|
|
1250
|
+
body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在整理纪念品架…' }));
|
|
848
1251
|
|
|
849
1252
|
const stat = (n, label) => el('div', { class: 'fun-stat' },
|
|
850
1253
|
el('b', { text: String(n) }), el('span', { text: label }));
|
|
851
1254
|
|
|
852
1255
|
const pct = (part) => `${part.done}/${part.total}`;
|
|
1256
|
+
const memoryTrip = tripLookup(ctx, 'trip', 'id', '回看这趟行程');
|
|
853
1257
|
|
|
854
1258
|
const render = (data) => {
|
|
855
|
-
|
|
1259
|
+
currentData = data;
|
|
1260
|
+
body.replaceChildren(heading('纪念品架', '每一件小东西,都有带它回来的那一天。'));
|
|
856
1261
|
if (!data.total) {
|
|
857
1262
|
body.appendChild(el('div', { class: 'fun-empty', text: '架子上还什么都没有——她买过纪念品,这里就有了。' }));
|
|
858
|
-
return;
|
|
859
1263
|
}
|
|
860
1264
|
|
|
861
1265
|
body.appendChild(el('div', { class: 'fun-stats' },
|
|
@@ -866,20 +1270,21 @@ function mountShelf(ctx) {
|
|
|
866
1270
|
|
|
867
1271
|
body.appendChild(el('div', { class: 'fun-meta', text: '收藏账本长期保留;详细行程可查看最近 40 趟与珍藏行程。进度按当前场所清单统计,移除或改名不删除旧回忆。' }));
|
|
868
1272
|
|
|
869
|
-
body.appendChild(el('div', { class: 'fun-meta', text: '收藏账本长期保留;详细行程可查看最近 40 趟与珍藏行程。进度按当前场所清单统计,移除或改名不删除旧回忆。' }));
|
|
870
|
-
|
|
871
1273
|
// 每一处的架子:只列真有东西的,空的不用占版面。
|
|
872
|
-
body.appendChild(el('div', { class: 'fun-sec', text: '按地方归着' }));
|
|
1274
|
+
if (data.byPlace.length) body.appendChild(el('div', { class: 'fun-sec', text: '按地方归着' }));
|
|
873
1275
|
for (const g of data.byPlace) {
|
|
874
1276
|
body.appendChild(el('div', { class: 'fun-trip' },
|
|
875
1277
|
el('div', { class: 'fun-trip-head' },
|
|
876
1278
|
el('span', { class: 'fun-trip-name', text: g.placeName }),
|
|
877
1279
|
el('span', { class: 'fun-trip-when', text: `${g.items.length} 样 · 最早 ${g.firstDay || '—'}` })),
|
|
878
|
-
|
|
879
|
-
el('summary', { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ''}
|
|
1280
|
+
el('div', { class: 'fun-shelf-grid' }, g.items.map((it) => el('details', { class: 'fun-keepsake' },
|
|
1281
|
+
el('summary', null, itemIcon(it.name), el('strong', { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ''}` }),
|
|
1282
|
+
el('span', { class: 'fun-dim', text: `记录中最早 ${it.firstDay || '日期不详'}` })),
|
|
1283
|
+
it.archivedCount ? el('div', { class: 'fun-note', text: `${it.archivedCount} 次收藏仅保留账本,详细行程已不在近期记录中。` }) : null,
|
|
880
1284
|
...(it.memories ?? []).map((m) => el('div', { class: 'fun-trip-sum' },
|
|
881
1285
|
el('div', { text: `${m.day || '日期不详'} · ${m.summary}` }),
|
|
882
|
-
m.note ? el('div', { text: `你记的:${m.note}` }) : null
|
|
1286
|
+
m.note ? el('div', { text: `你记的:${m.note}` }) : null,
|
|
1287
|
+
m.id ? memoryTrip(m.id) : null)))))));
|
|
883
1288
|
}
|
|
884
1289
|
|
|
885
1290
|
// 进度:只列去过的。服务端已按「快逛遍的」排好,这里照顺序画。
|
|
@@ -892,7 +1297,9 @@ function mountShelf(ctx) {
|
|
|
892
1297
|
el('div', { class: 'fun-trip-head' },
|
|
893
1298
|
el('span', { class: 'fun-trip-name', text: p.placeName }),
|
|
894
1299
|
el('span', { class: 'fun-trip-when', text: `去过 ${p.visits} 次 · ${p.percent}%` })),
|
|
1300
|
+
el('progress', { class: 'fun-progress', max: '100', value: String(p.percent), 'aria-label': `${p.placeName}探索进度 ${p.percent}%` }),
|
|
895
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,
|
|
896
1303
|
left
|
|
897
1304
|
? el('div', { class: 'fun-trip-sum', text: `还差:${p.areas.left.slice(0, 6).join('、')}${left > 6 ? ` 等 ${left} 处` : ''}` })
|
|
898
1305
|
: el('div', { class: 'fun-trip-sum', text: '这一处已经逛遍了。' })));
|
|
@@ -904,12 +1311,11 @@ function mountShelf(ctx) {
|
|
|
904
1311
|
try {
|
|
905
1312
|
const data = await ctx.invoke('list');
|
|
906
1313
|
if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
|
|
1314
|
+
status.replaceChildren();
|
|
907
1315
|
render(data);
|
|
908
1316
|
} catch (err) {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
const box2 = shell(root);
|
|
912
|
-
box2.appendChild(errorCard(err));
|
|
1317
|
+
if (!currentData) body.replaceChildren();
|
|
1318
|
+
status.replaceChildren(errorCard(err, load, Boolean(currentData)));
|
|
913
1319
|
}
|
|
914
1320
|
};
|
|
915
1321
|
|
|
@@ -922,5 +1328,6 @@ export default {
|
|
|
922
1328
|
places: { mount: mountPlaces },
|
|
923
1329
|
book: { mount: mountBook },
|
|
924
1330
|
shelf: { mount: mountShelf },
|
|
1331
|
+
stories: { mount: mountStories },
|
|
925
1332
|
},
|
|
926
1333
|
};
|