cortico-world-fun 0.3.0 → 0.3.1
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 +6 -0
- package/PUBLISHING.md +42 -62
- package/README.md +8 -0
- package/dist/webui.js +1386 -738
- package/package.json +9 -3
- package/dist/artwork.js +0 -64
- package/dist/stories.js +0 -395
package/dist/webui.js
CHANGED
|
@@ -1,27 +1,517 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
// webui/stories.js
|
|
2
|
+
var CSS = `
|
|
3
|
+
.fun-stories{--fs-line:var(--border,#e3e4e3);--fs-ink:var(--foreground,#1b1a1e);--fs-dim:var(--muted-foreground,#5c5c60);--fs-card:var(--surface,#fbfbfb);--fs-soft:color-mix(in srgb,var(--fs-card) 93%,var(--fs-ink));--fs-accent:var(--accent,#00a870);--fs-error:var(--destructive,#b23b35);font:14px/1.65 var(--sans,-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif);color:var(--fs-ink);padding:8px 4px 24px;overflow-wrap:anywhere}
|
|
4
|
+
.fun-stories *{box-sizing:border-box}
|
|
5
|
+
.fun-stories h2,.fun-stories h3,.fun-stories h4,.fun-stories p{margin:0}
|
|
6
|
+
.fun-stories h2{font-size:20px}.fun-stories h3{font-size:15px}.fun-stories h4{font-size:14px}
|
|
7
|
+
.fun-story-heading{margin-bottom:14px;padding:4px 0 12px;border-bottom:1px solid var(--fs-line)}
|
|
8
|
+
.fun-story-note,.fun-story-field,.fun-story-feedback{color:var(--fs-dim);font-size:12px}
|
|
9
|
+
.fun-story-editor,.fun-story-pack{border:1px solid var(--fs-line);border-radius:12px;background:var(--fs-card);padding:12px;margin-bottom:9px}
|
|
10
|
+
.fun-story-editor{background:var(--fs-soft);margin-bottom:16px}
|
|
11
|
+
.fun-story-editor>summary{cursor:pointer;font-weight:600}
|
|
12
|
+
.fun-story-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(160px,100%),1fr));gap:6px 10px;margin:8px 0}
|
|
13
|
+
.fun-story-grid :is(input,select){display:block;width:100%;min-width:0;margin-top:3px}
|
|
14
|
+
.fun-story-branches{grid-template-columns:repeat(auto-fit,minmax(min(235px,100%),1fr))}
|
|
15
|
+
.fun-story-branch{margin:0;padding:6px 9px;min-width:0;border:1px solid var(--fs-line);border-radius:var(--radius-sm,6px)}
|
|
16
|
+
.fun-story-branch>.fun-story-field{margin:5px 0}
|
|
17
|
+
.fun-story-row{display:flex;align-items:center;gap:6px 8px;flex-wrap:wrap;margin:6px 0}
|
|
18
|
+
.fun-story-row>h3,.fun-story-row>h4{margin-right:auto}
|
|
19
|
+
.fun-story-field{display:block;font-weight:600}
|
|
20
|
+
.fun-story-row label{display:inline-flex;align-items:center;gap:5px}
|
|
21
|
+
.fun-stories button,.fun-stories select,.fun-stories textarea,.fun-story-grid input{font:inherit;color:inherit;background:var(--fs-card);border:1px solid var(--fs-line);border-radius:var(--radius-sm,6px);padding:4px 9px}
|
|
22
|
+
.fun-stories button,.fun-stories select{min-height:31px;max-width:100%}
|
|
23
|
+
.fun-stories button{cursor:pointer}
|
|
24
|
+
.fun-stories button:hover{border-color:var(--fs-accent)}
|
|
25
|
+
.fun-stories button[aria-disabled=true]{opacity:.55;cursor:default}
|
|
26
|
+
.fun-stories :is(button,select,textarea,input):focus-visible{outline:2px solid var(--fs-accent);outline-offset:2px}
|
|
27
|
+
.fun-stories .fun-story-primary{border-color:var(--fs-accent);background:var(--fs-accent);color:var(--accent-foreground,#fff);font-weight:600}
|
|
28
|
+
.fun-stories .fun-story-danger,.fun-story-errors{color:var(--fs-error)}
|
|
29
|
+
.fun-stories textarea{display:block;width:100%;margin:4px 0;resize:vertical;font:12px/1.55 ui-monospace,Consolas,monospace}
|
|
30
|
+
.fun-story-badge{font-size:11.5px;color:var(--fs-dim);border:1px solid var(--fs-line);border-radius:999px;padding:0 7px;background:var(--fs-soft)}
|
|
31
|
+
.fun-story-unavailable{border-style:dashed}
|
|
32
|
+
.fun-stories ul,.fun-stories ol{margin:3px 0;padding-inline-start:19px}
|
|
33
|
+
.fun-story-feedback>:empty,.fun-story-result:empty,.fun-story-confirm:empty{display:none}
|
|
34
|
+
.fun-story-confirm,.fun-story-result{margin-top:8px}
|
|
35
|
+
.fun-story-node{padding:5px 0;border-bottom:1px solid var(--fs-line)}
|
|
36
|
+
.fun-story-node:last-child{border-bottom:0}
|
|
37
|
+
.fun-story-node p{white-space:pre-wrap}
|
|
38
|
+
@media(max-width:420px){.fun-stories{padding-inline:0}.fun-story-editor,.fun-story-pack{padding:10px}}
|
|
39
|
+
`;
|
|
40
|
+
function el(tag, attrs = {}, ...children) {
|
|
41
|
+
const node = document.createElement(tag);
|
|
42
|
+
for (const [key, value] of Object.entries(attrs)) node.setAttribute(key, value);
|
|
43
|
+
for (const child of children.flat()) {
|
|
44
|
+
if (child == null) continue;
|
|
45
|
+
node.appendChild(typeof child === "string" ? document.createTextNode(child) : child);
|
|
46
|
+
}
|
|
47
|
+
return node;
|
|
48
|
+
}
|
|
49
|
+
function messageList(messages) {
|
|
50
|
+
return messages?.length ? el("ul", {}, messages.map((message) => el("li", {}, String(message)))) : null;
|
|
51
|
+
}
|
|
52
|
+
function feedback() {
|
|
53
|
+
const status = el("div", { role: "status" });
|
|
54
|
+
const alert = el("div", { class: "fun-story-errors", role: "alert" });
|
|
55
|
+
return {
|
|
56
|
+
node: el("div", { class: "fun-story-feedback" }, status, alert),
|
|
57
|
+
set(text = "", result) {
|
|
58
|
+
const warnings = messageList(result?.warnings);
|
|
59
|
+
status.replaceChildren(...[text ? document.createTextNode(text) : null, warnings].filter(Boolean));
|
|
60
|
+
const errors = [...new Set([result?.error, ...result?.errors ?? []].filter(Boolean))];
|
|
61
|
+
if (result?.ok === false && !errors.length) errors.push("操作失败,请重试。");
|
|
62
|
+
alert.replaceChildren(...errors.length ? [messageList(errors)] : []);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function previewGraph(result) {
|
|
67
|
+
const nodes = (result.nodes ?? []).map((node) => {
|
|
68
|
+
const when = node.when && Object.keys(node.when).length ? `条件:${typeof node.when === "string" ? node.when : JSON.stringify(node.when)}` : "";
|
|
69
|
+
const choices = (node.choices ?? []).map((choice) => el("li", {}, `${choice.label || choice.id} → ${choice.next || "结束"}`));
|
|
70
|
+
return el(
|
|
71
|
+
"li",
|
|
72
|
+
{ class: "fun-story-node" },
|
|
73
|
+
el("strong", {}, `${node.id}${node.area ? ` · ${node.area}` : ""}`),
|
|
74
|
+
node.event ? el("p", {}, node.event) : null,
|
|
75
|
+
when ? el("p", { class: "fun-story-note" }, when) : null,
|
|
76
|
+
node.next ? el("p", { class: "fun-story-note" }, `下一节点 → ${node.next}`) : null,
|
|
77
|
+
choices.length ? el("ul", {}, choices) : null,
|
|
78
|
+
!node.next && !choices.length ? el("p", { class: "fun-story-note" }, "结束") : null
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
return el(
|
|
82
|
+
"section",
|
|
83
|
+
{ class: "fun-story-graph", "aria-label": "只读节点图" },
|
|
84
|
+
el("h4", {}, result.title || "节点图"),
|
|
85
|
+
el("p", { class: "fun-story-note" }, result.eligible ? "当前预览条件匹配" : "当前预览条件未匹配"),
|
|
86
|
+
el("ol", {}, nodes)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
function label(text, control) {
|
|
90
|
+
return el("label", { class: "fun-story-field" }, text, control);
|
|
91
|
+
}
|
|
92
|
+
function fillSelect(select, items, placeholder) {
|
|
93
|
+
const selected = select.value;
|
|
94
|
+
select.replaceChildren(
|
|
95
|
+
el("option", { value: "" }, placeholder),
|
|
96
|
+
...items.map(({ value, label: label2 }) => el("option", { value }, label2))
|
|
97
|
+
);
|
|
98
|
+
select.value = items.some((item) => item.value === selected) ? selected : "";
|
|
99
|
+
}
|
|
100
|
+
function simpleEditor(button, save) {
|
|
101
|
+
const select = (key) => el("select", { class: `fun-story-author-${key}`, "data-story-field": key });
|
|
102
|
+
const input = (key, max, type = "text") => el("input", { class: `fun-story-author-${key}`, type, "data-story-field": key, ...max ? { maxlength: String(max) } : {} });
|
|
103
|
+
const place = select("place");
|
|
104
|
+
const area = select("area");
|
|
105
|
+
const id = input("id", 24);
|
|
106
|
+
id.value = `user-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`;
|
|
107
|
+
const title = input("title", 80);
|
|
108
|
+
const event = input("event", 120);
|
|
109
|
+
const prompt = input("prompt", 160);
|
|
110
|
+
const from = input("from", null, "time");
|
|
111
|
+
const to = input("to", null, "time");
|
|
112
|
+
const branches = ["a", "b"].map((key, index) => {
|
|
113
|
+
const choice = input(`${key}-label`, 160);
|
|
114
|
+
const result = input(`${key}-result`, 160);
|
|
115
|
+
const event2 = input(`${key}-event`, 120);
|
|
116
|
+
const area2 = select(`${key}-area`);
|
|
117
|
+
const node2 = el(
|
|
118
|
+
"fieldset",
|
|
119
|
+
{ class: "fun-story-branch" },
|
|
120
|
+
el("legend", { class: "fun-story-field" }, `选项 ${index + 1}`),
|
|
121
|
+
label("选项文字", choice),
|
|
122
|
+
label("选择结果", result),
|
|
123
|
+
label("后续事件", event2),
|
|
124
|
+
label("后续区域", area2)
|
|
125
|
+
);
|
|
126
|
+
return { key, choice, result, event: event2, area: area2, node: node2 };
|
|
127
|
+
});
|
|
128
|
+
let places = [];
|
|
129
|
+
const report = feedback();
|
|
130
|
+
const updateAreas = () => {
|
|
131
|
+
const areas = (places.find((item) => item.id === place.value)?.areas ?? []).map((name) => ({ value: name, label: name }));
|
|
132
|
+
fillSelect(area, areas, "选择起始区域");
|
|
133
|
+
for (const branch of branches) fillSelect(branch.area, areas, "同起始区域");
|
|
134
|
+
};
|
|
135
|
+
place.addEventListener("change", () => {
|
|
136
|
+
area.value = "";
|
|
137
|
+
for (const branch of branches) branch.area.value = "";
|
|
138
|
+
updateAreas();
|
|
139
|
+
});
|
|
140
|
+
const saveButton = button("保存新故事包", () => {
|
|
141
|
+
const fields = [place, area, id, title, event, prompt, ...branches.flatMap((branch) => [branch.choice, branch.result, branch.event])];
|
|
142
|
+
const missing = fields.find((field) => !field.value.trim());
|
|
143
|
+
if (missing) {
|
|
144
|
+
report.set("", { ok: false, error: "请填写地点、起始区域和故事内容。" });
|
|
145
|
+
missing.focus();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (!/^user-[a-z0-9_-]{1,19}$/.test(id.value.trim())) {
|
|
149
|
+
report.set("", { ok: false, error: "标识须以 user- 开头,最多 24 字符,只能含小写字母、数字、短横线或下划线。" });
|
|
150
|
+
id.focus();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (Boolean(from.value) !== Boolean(to.value) || from.value && from.value === to.value) {
|
|
154
|
+
report.set("", { ok: false, error: "请填写不同的开始和结束时间,或将两项都留空。" });
|
|
155
|
+
(from.value && !to.value ? to : from).focus();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const start = {
|
|
159
|
+
id: "start",
|
|
160
|
+
area: area.value,
|
|
161
|
+
event: event.value.trim(),
|
|
162
|
+
prompt: prompt.value.trim(),
|
|
163
|
+
choices: branches.map((branch) => ({ id: branch.key, label: branch.choice.value.trim(), result: branch.result.value.trim(), next: `end-${branch.key}` }))
|
|
164
|
+
};
|
|
165
|
+
if (from.value) start.when = { from: from.value, to: to.value };
|
|
166
|
+
const nodes = [start, ...branches.map((branch) => ({ id: `end-${branch.key}`, area: branch.area.value || area.value, event: branch.event.value.trim() }))];
|
|
167
|
+
save(report, JSON.stringify({ version: 1, id: id.value.trim(), title: title.value.trim(), placeId: place.value, start: start.id, nodes }));
|
|
168
|
+
}, { class: "fun-story-action fun-story-primary" });
|
|
169
|
+
const node = el(
|
|
170
|
+
"section",
|
|
171
|
+
{ class: "fun-story-editor", "aria-label": "编写故事" },
|
|
172
|
+
el("h3", {}, "编写故事"),
|
|
173
|
+
el("div", { class: "fun-story-grid" }, label("地点", place), label("起始区域", area), label("故事标题", title), label("故事标识", id)),
|
|
174
|
+
el("div", { class: "fun-story-grid" }, label("起始事件", event), label("选择提问", prompt)),
|
|
175
|
+
el("div", { class: "fun-story-grid fun-story-branches" }, branches.map((branch) => branch.node)),
|
|
176
|
+
el(
|
|
177
|
+
"details",
|
|
178
|
+
{},
|
|
179
|
+
el("summary", {}, "触发时段(可选)"),
|
|
180
|
+
el("div", { class: "fun-story-grid" }, label("开始时间", from), label("结束时间", to))
|
|
181
|
+
),
|
|
182
|
+
el("div", { class: "fun-story-row" }, saveButton),
|
|
183
|
+
report.node
|
|
184
|
+
);
|
|
185
|
+
function update(items) {
|
|
186
|
+
places = items;
|
|
187
|
+
fillSelect(place, items.map((item) => ({ value: item.id, label: item.name || item.id })), "选择地点");
|
|
188
|
+
updateAreas();
|
|
189
|
+
}
|
|
190
|
+
update([]);
|
|
191
|
+
return { node, update };
|
|
192
|
+
}
|
|
193
|
+
function mountStories(ctx) {
|
|
194
|
+
const { root } = ctx;
|
|
195
|
+
const box = el("div", { class: "fun-stories" });
|
|
196
|
+
root.replaceChildren(el("style", {}, CSS), box);
|
|
197
|
+
let busy = false;
|
|
198
|
+
let listRequest = 0;
|
|
199
|
+
let lastPacks;
|
|
200
|
+
let draftEdits = 0;
|
|
201
|
+
function button(text, handler, attrs = {}) {
|
|
202
|
+
const node = el("button", { type: "button", ...attrs }, text);
|
|
203
|
+
node.addEventListener("click", () => {
|
|
204
|
+
if (node.getAttribute("aria-disabled") !== "true" && !ctx.signal?.aborted) handler();
|
|
205
|
+
});
|
|
206
|
+
return node;
|
|
207
|
+
}
|
|
208
|
+
const errorResult = (error) => ({ ok: false, error: error?.message ?? String(error) });
|
|
209
|
+
function setBusy(value) {
|
|
210
|
+
busy = value;
|
|
211
|
+
for (const node of box.querySelectorAll(".fun-story-action")) node.setAttribute("aria-disabled", String(value));
|
|
212
|
+
}
|
|
213
|
+
async function run(report, pending, method, args, render) {
|
|
214
|
+
if (busy) return;
|
|
215
|
+
setBusy(true);
|
|
216
|
+
report.set(pending);
|
|
217
|
+
try {
|
|
218
|
+
const result = await ctx.invoke(method, [args]);
|
|
219
|
+
if (!ctx.signal?.aborted) await render(result ?? { ok: false, error: "返回结果为空。" });
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (!ctx.signal?.aborted) report.set("", errorResult(error));
|
|
222
|
+
} finally {
|
|
223
|
+
if (!ctx.signal?.aborted) setBusy(false);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const place = el("select", { class: "fun-story-place" });
|
|
227
|
+
const defaultPlace = () => el("option", { value: "" }, "默认地点");
|
|
228
|
+
place.appendChild(defaultPlace());
|
|
229
|
+
const draft = el("textarea", { class: "fun-story-json", rows: "8", spellcheck: "false", placeholder: "粘贴故事包 JSON…" });
|
|
230
|
+
const overwrite = el("input", { type: "checkbox", class: "fun-story-overwrite" });
|
|
231
|
+
const editorReport = feedback();
|
|
232
|
+
const editorResult = el("div", { class: "fun-story-result" });
|
|
233
|
+
draft.addEventListener("input", () => {
|
|
234
|
+
draftEdits += 1;
|
|
235
|
+
if (!busy) editorReport.set();
|
|
236
|
+
editorResult.replaceChildren();
|
|
237
|
+
});
|
|
238
|
+
function editAction(text, method, pending) {
|
|
239
|
+
return button(text, () => {
|
|
240
|
+
const json = draft.value;
|
|
241
|
+
const edits = draftEdits;
|
|
242
|
+
const placeId = place.value;
|
|
243
|
+
const args = method === "template" ? placeId ? { placeId } : {} : { json };
|
|
244
|
+
if (method === "import" && overwrite.checked) args.replace = true;
|
|
245
|
+
editorResult.replaceChildren();
|
|
246
|
+
void run(editorReport, pending, method, args, async (result) => {
|
|
247
|
+
const changed = draftEdits !== edits || draft.value !== json;
|
|
248
|
+
const previous = changed ? "上次提交:" : "";
|
|
249
|
+
if (method === "template") {
|
|
250
|
+
if (result.ok && !changed) {
|
|
251
|
+
if (typeof result.json !== "string") throw new Error("模板没有返回 JSON。");
|
|
252
|
+
draft.value = result.json;
|
|
253
|
+
overwrite.checked = false;
|
|
254
|
+
}
|
|
255
|
+
editorReport.set(result.ok ? changed ? "草稿已修改,保留当前内容。" : "模板已填入。" : "", result);
|
|
256
|
+
} else if (method === "validate") {
|
|
257
|
+
editorReport.set(previous + (result.ok ? "校验通过。" : "校验未通过。"), result);
|
|
258
|
+
} else if (method === "preview") {
|
|
259
|
+
editorReport.set(previous + (result.ok ? "只读预览已生成。" : "预览失败。"), result);
|
|
260
|
+
if (result.ok) editorResult.appendChild(previewGraph(result));
|
|
261
|
+
} else {
|
|
262
|
+
editorReport.set(previous + (result.ok ? `已导入${result.id ? ` · ${result.id}` : ""}。` : "导入失败。"), result);
|
|
263
|
+
if (result.ok) {
|
|
264
|
+
overwrite.checked = false;
|
|
265
|
+
await load();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}, { class: `fun-story-action${method === "import" ? " fun-story-primary" : ""}` });
|
|
270
|
+
}
|
|
271
|
+
const loadReport = feedback();
|
|
272
|
+
const libraryReport = feedback();
|
|
273
|
+
const packList = el("div", { class: "fun-story-list" });
|
|
274
|
+
const refreshButton = button("刷新列表", () => {
|
|
275
|
+
void load();
|
|
276
|
+
});
|
|
277
|
+
const simple = simpleEditor(button, (report, json) => {
|
|
278
|
+
void run(report, "正在保存新故事包…", "import", { json }, async (result) => {
|
|
279
|
+
report.set(result.ok ? `已保存新故事包${result.id ? ` · ${result.id}` : ""}。` : "保存失败。", result);
|
|
280
|
+
if (result.ok) await load();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
box.replaceChildren(
|
|
284
|
+
el(
|
|
285
|
+
"header",
|
|
286
|
+
{ class: "fun-story-heading" },
|
|
287
|
+
el("h2", {}, "故事包"),
|
|
288
|
+
el("p", { class: "fun-story-note" }, "为地点编写事件节点与分支。草稿仅在导入时保存。")
|
|
289
|
+
),
|
|
290
|
+
simple.node,
|
|
291
|
+
el(
|
|
292
|
+
"details",
|
|
293
|
+
{ class: "fun-story-advanced" },
|
|
294
|
+
el("summary", {}, "高级编辑 · 查看或粘贴完整 JSON"),
|
|
295
|
+
el(
|
|
296
|
+
"section",
|
|
297
|
+
{ class: "fun-story-editor", "aria-label": "高级 JSON 编辑器" },
|
|
298
|
+
el("h3", {}, "完整 JSON"),
|
|
299
|
+
el(
|
|
300
|
+
"div",
|
|
301
|
+
{ class: "fun-story-row" },
|
|
302
|
+
el("label", { class: "fun-story-field" }, "模板地点", place),
|
|
303
|
+
editAction("填入模板", "template", "正在取模板…")
|
|
304
|
+
),
|
|
305
|
+
el("label", { class: "fun-story-field" }, "故事包 JSON", draft),
|
|
306
|
+
el(
|
|
307
|
+
"div",
|
|
308
|
+
{ class: "fun-story-row" },
|
|
309
|
+
editAction("校验 JSON", "validate", "正在校验…"),
|
|
310
|
+
editAction("预览草稿", "preview", "正在预览…"),
|
|
311
|
+
editAction("导入故事包", "import", "正在导入…"),
|
|
312
|
+
el("label", { class: "fun-story-field" }, overwrite, "覆盖同 ID 故事包")
|
|
313
|
+
),
|
|
314
|
+
editorReport.node,
|
|
315
|
+
editorResult
|
|
316
|
+
)
|
|
317
|
+
),
|
|
318
|
+
el(
|
|
319
|
+
"section",
|
|
320
|
+
{ "aria-label": "故事包列表" },
|
|
321
|
+
el("div", { class: "fun-story-row" }, el("h3", {}, "已收录故事包"), refreshButton),
|
|
322
|
+
loadReport.node,
|
|
323
|
+
libraryReport.node,
|
|
324
|
+
packList
|
|
325
|
+
)
|
|
326
|
+
);
|
|
327
|
+
function packCard(pack) {
|
|
328
|
+
const title = pack.title || pack.id;
|
|
329
|
+
const report = feedback();
|
|
330
|
+
const resultBox = el("div", { class: "fun-story-result" });
|
|
331
|
+
const confirm = el("div", { class: "fun-story-confirm" });
|
|
332
|
+
const packAction = (text, key, handler, css = "") => button(text, handler, {
|
|
333
|
+
class: `fun-story-action ${css}`,
|
|
334
|
+
"aria-disabled": String(busy),
|
|
335
|
+
"aria-label": `${text} ${title}`,
|
|
336
|
+
"data-story-focus": `${pack.id}:${key}`
|
|
337
|
+
});
|
|
338
|
+
const read = (method, label2) => {
|
|
339
|
+
const opener = packAction(label2, method, () => {
|
|
340
|
+
confirm.replaceChildren();
|
|
341
|
+
resultBox.replaceChildren();
|
|
342
|
+
void run(report, method === "preview" ? "正在预览…" : "正在导出…", method, { id: pack.id }, (result) => {
|
|
343
|
+
report.set(result.ok ? method === "preview" ? "只读预览已生成。" : "已导出,可复制 JSON。" : "", result);
|
|
344
|
+
if (!result.ok) return;
|
|
345
|
+
if (method === "preview") {
|
|
346
|
+
resultBox.appendChild(previewGraph(result));
|
|
347
|
+
} else {
|
|
348
|
+
if (typeof result.json !== "string") throw new Error("导出没有返回 JSON。");
|
|
349
|
+
const output = el("textarea", { class: "fun-story-export", rows: "6", readonly: "", spellcheck: "false" });
|
|
350
|
+
output.value = result.json;
|
|
351
|
+
resultBox.appendChild(el("label", { class: "fun-story-field" }, `导出的 JSON · ${title}`, output));
|
|
352
|
+
}
|
|
353
|
+
resultBox.appendChild(button("收起", () => {
|
|
354
|
+
resultBox.replaceChildren();
|
|
355
|
+
report.set();
|
|
356
|
+
opener.focus();
|
|
357
|
+
}));
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
return opener;
|
|
361
|
+
};
|
|
362
|
+
const mutate = (method, label2) => {
|
|
363
|
+
void run(report, `正在${label2}…`, method, { id: pack.id }, async (result) => {
|
|
364
|
+
libraryReport.set();
|
|
365
|
+
report.set("", result);
|
|
366
|
+
if (!result.ok) return;
|
|
367
|
+
libraryReport.set(`已${label2}「${title}」。`, result);
|
|
368
|
+
await load();
|
|
369
|
+
confirm.replaceChildren();
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
const toggle = pack.enabled ? ["disable", "停用"] : ["enable", "启用"];
|
|
373
|
+
const remove = pack.builtin ? null : packAction("移除", "remove", () => {
|
|
374
|
+
const cancel = button("取消", () => {
|
|
375
|
+
confirm.replaceChildren();
|
|
376
|
+
remove.focus();
|
|
377
|
+
});
|
|
378
|
+
confirm.replaceChildren(
|
|
379
|
+
el("span", {}, `移除「${title}」?`),
|
|
380
|
+
el("div", { class: "fun-story-row" }, cancel, packAction("确认移除", "confirm", () => mutate("remove", "移除"), "fun-story-danger"))
|
|
381
|
+
);
|
|
382
|
+
cancel.focus();
|
|
383
|
+
}, "fun-story-danger");
|
|
384
|
+
const warnings = pack.warnings?.length ? pack.warnings : pack.available === false ? ["绑定地点或区域当前不匹配。"] : [];
|
|
385
|
+
return el(
|
|
386
|
+
"article",
|
|
387
|
+
{ class: "fun-story-pack", "data-pack-id": pack.id },
|
|
388
|
+
el(
|
|
389
|
+
"div",
|
|
390
|
+
{ class: "fun-story-row" },
|
|
391
|
+
el("h4", {}, title),
|
|
392
|
+
el("span", { class: "fun-story-badge" }, pack.builtin ? "内置" : "自定义"),
|
|
393
|
+
el("span", { class: "fun-story-badge" }, pack.enabled ? "已启用" : "已停用"),
|
|
394
|
+
pack.available === false ? el("span", { class: "fun-story-badge fun-story-unavailable" }, "暂不可用") : null
|
|
395
|
+
),
|
|
396
|
+
el("p", { class: "fun-story-note" }, `${pack.placeName || pack.placeId || "未绑定地点"} · ${pack.nodeCount} 个节点 · 版本 ${pack.revision}`),
|
|
397
|
+
pack.description ? el("p", {}, pack.description) : null,
|
|
398
|
+
warnings.length ? el("div", { class: "fun-story-note" }, messageList(warnings)) : null,
|
|
399
|
+
el(
|
|
400
|
+
"div",
|
|
401
|
+
{ class: "fun-story-row" },
|
|
402
|
+
read("preview", "预览"),
|
|
403
|
+
read("export", "导出 JSON"),
|
|
404
|
+
packAction(toggle[1], "toggle", () => mutate(...toggle)),
|
|
405
|
+
remove
|
|
406
|
+
),
|
|
407
|
+
confirm,
|
|
408
|
+
report.node,
|
|
409
|
+
resultBox
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
function renderList(data) {
|
|
413
|
+
const selected = place.value;
|
|
414
|
+
place.replaceChildren(defaultPlace(), ...data.places.map((item) => el("option", { value: item.id }, item.name || item.id)));
|
|
415
|
+
place.value = data.places.some((item) => item.id === selected) ? selected : "";
|
|
416
|
+
simple.update(data.places);
|
|
417
|
+
const signature = JSON.stringify(data.packs);
|
|
418
|
+
if (signature === lastPacks) return;
|
|
419
|
+
const focused = root.activeElement ?? document.activeElement;
|
|
420
|
+
const buttonWasFocused = [...packList.querySelectorAll("button")].includes(focused);
|
|
421
|
+
const focusKey = focused?.getAttribute?.("data-story-focus");
|
|
422
|
+
const cards = data.packs.map(packCard);
|
|
423
|
+
packList.replaceChildren(...cards.length ? cards : [el("p", { class: "fun-story-note" }, "还没有故事包。")]);
|
|
424
|
+
lastPacks = signature;
|
|
425
|
+
if (buttonWasFocused) {
|
|
426
|
+
const replacement = [...packList.querySelectorAll("button")].find((node) => focusKey && node.getAttribute("data-story-focus") === focusKey);
|
|
427
|
+
(replacement || refreshButton).focus();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
async function load() {
|
|
431
|
+
if (ctx.signal?.aborted) return;
|
|
432
|
+
const sequence = ++listRequest;
|
|
433
|
+
refreshButton.setAttribute("aria-disabled", "true");
|
|
434
|
+
loadReport.set("正在读取故事包…");
|
|
435
|
+
try {
|
|
436
|
+
const data = await ctx.invoke("list", []);
|
|
437
|
+
if (sequence !== listRequest || ctx.signal?.aborted) return;
|
|
438
|
+
if (!data?.ok) {
|
|
439
|
+
loadReport.set("列表加载失败。", data ?? { ok: false });
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
renderList(data);
|
|
443
|
+
loadReport.set("", data);
|
|
444
|
+
} catch (error) {
|
|
445
|
+
if (sequence === listRequest && !ctx.signal?.aborted) loadReport.set("列表加载失败。", errorResult(error));
|
|
446
|
+
} finally {
|
|
447
|
+
if (sequence === listRequest && !ctx.signal?.aborted) {
|
|
448
|
+
refreshButton.setAttribute("aria-disabled", "false");
|
|
449
|
+
refreshButton.textContent = loadReport.node.querySelector(".fun-story-errors").textContent ? "重试" : "刷新列表";
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
void load();
|
|
454
|
+
return { refresh: load };
|
|
455
|
+
}
|
|
21
456
|
|
|
22
|
-
|
|
457
|
+
// webui/artwork.js
|
|
458
|
+
var line = (d, extra = "") => `<path d="${d}" ${extra}/>`;
|
|
459
|
+
var rect = (x, y, w, h, r = 3, extra = "") => `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="${r}" ${extra}/>`;
|
|
460
|
+
var circle = (x, y, r, extra = "") => `<circle cx="${x}" cy="${y}" r="${r}" ${extra}/>`;
|
|
461
|
+
var warm = 'fill="var(--f-art-warm,#e9b97e)"';
|
|
462
|
+
var mint = 'fill="var(--f-art-mint,#99c7b9)"';
|
|
463
|
+
var blue = 'fill="var(--f-art-blue,#9abfd0)"';
|
|
464
|
+
var pink = 'fill="var(--f-art-pink,#d9abc1)"';
|
|
465
|
+
var paper = 'fill="var(--f-card,#fbfbfb)"';
|
|
466
|
+
var scenes = {
|
|
467
|
+
amusement: circle(139, 48, 34, blue) + line("M139 14V82M105 48H173M115 24L163 72M115 72L163 24M139 48L113 108H165Z") + [[139, 14], [173, 48], [139, 82], [105, 48]].map(([x, y]) => rect(x - 6, y - 4, 12, 10, 3, warm)).join("") + line("M202 104V64H267V104M196 64L235 38L274 64Z", warm) + rect(220, 77, 25, 27, 5, pink) + line("M39 91V45M39 45L69 53L39 63Z", mint),
|
|
468
|
+
aquarium: line("M68 108V57C68 8 249 8 249 57V108", blue) + line("M88 108V58C88 31 229 31 229 58V108", paper) + line("M132 56C154 39 180 41 192 52L210 45V67L192 60C170 73 144 68 132 56Z", mint) + circle(181, 52, 1.5, 'fill="currentColor"') + line("M105 108L108 87L117 100L121 78L128 108M208 108L215 82L219 99L228 89L231 108") + circle(111, 57, 3) + circle(118, 43, 2),
|
|
469
|
+
templefair: line("M67 108V38M91 108V38M225 108V38M249 108V38M52 31Q157 47 264 31L260 44H56ZM58 56H258", warm) + line("M102 80H215M109 80V107M207 80V107M99 79L158 54L218 79Z", mint) + [111, 157, 203].map((x) => circle(x, 60, 9, pink) + line(`M${x} 47V51M${x} 69V74`)).join(""),
|
|
470
|
+
con: rect(77, 35, 164, 72, 5, paper) + rect(91, 48, 63, 47, 3, pink) + line("M107 83L116 65L124 76L137 57L146 83Z") + rect(169, 49, 56, 13, 2, warm) + line("M169 73H225M169 83H209M91 107V114M227 107V114") + line("M47 57L53 43L59 57L73 63L59 69L53 83L47 69L33 63Z", blue),
|
|
471
|
+
cinema: rect(75, 23, 174, 79, 5, blue) + rect(89, 35, 146, 53, 2, paper) + line("M149 46L149 76L175 61Z", warm) + [98, 131, 164, 197, 230].map((x) => rect(x - 9, 96, 21, 16, 4, pink)).join("") + line("M42 96L38 68H62L58 96Z", warm) + line("M40 68Q39 54 48 59Q58 48 62 62"),
|
|
472
|
+
zoo: rect(73, 36, 177, 71, 10, mint) + line("M82 42L100 22H224L243 42", warm) + line("M117 107V72Q117 46 142 46Q167 46 167 72V107", paper) + circle(137, 62, 3) + circle(153, 62, 3) + line("M140 78Q146 84 152 78M201 107V67M195 67Q177 42 193 43Q200 24 207 43Q226 38 219 57Z", blue) + circle(53, 61, 18, mint) + line("M53 79V107"),
|
|
473
|
+
park: line("M119 114Q125 89 154 78Q176 67 178 49", warm) + circle(76, 54, 27, mint) + circle(236, 49, 33, mint) + line("M76 65V109M236 62V109") + rect(104, 75, 63, 10, 3, paper) + line("M110 86V102M160 86V102M105 67H166M113 67V76M157 67V76") + circle(157, 25, 13, warm),
|
|
474
|
+
arcade: rect(105, 25, 85, 82, 7, pink) + rect(116, 35, 63, 39, 3, blue) + line("M129 58L139 45L150 60L159 49L169 65") + line("M105 81L94 94H199L190 81Z", warm) + circle(126, 88, 3) + circle(168, 88, 3) + line("M122 85V78") + rect(128, 98, 37, 4, 1, paper) + line("M224 45L235 34M233 62H251M215 32V19"),
|
|
475
|
+
ktv: rect(62, 29, 126, 69, 6, blue) + line("M78 47H161M78 62H134M78 77H151") + line("M220 53L190 95Q187 103 195 106Q201 108 205 103L234 64", warm) + circle(231, 48, 17, pink) + line("M220 35L242 60M214 43L235 65M206 106Q236 121 255 99M272 31V61Q258 55 257 65Q260 77 273 69V40L290 35V55"),
|
|
476
|
+
museum: line("M64 47L159 15L253 47Z", warm) + rect(65, 47, 188, 10, 1, paper) + [86, 125, 164, 203].map((x) => rect(x, 57, 16, 43, 2, blue)).join("") + rect(61, 101, 195, 10, 1, paper) + circle(159, 36, 8, mint) + line("M41 110H278"),
|
|
477
|
+
catcafe: rect(66, 30, 123, 71, 5, warm) + line("M76 43H178M128 43V101M76 77H178") + line("M201 97C177 89 185 72 199 73L198 58L211 67L225 59L228 78C242 102 217 110 201 97Z", pink) + circle(207, 81, 1.5, 'fill="currentColor"') + circle(220, 81, 1.5, 'fill="currentColor"') + line("M206 91Q215 96 221 88M237 98Q263 100 253 83") + rect(89, 87, 18, 15, 3, paper) + line("M107 90Q119 90 112 98"),
|
|
478
|
+
hiking: line("M45 108L128 21L197 108Z", mint) + line("M127 21L104 47L128 43L145 47Z", paper) + line("M143 108L219 42L278 108Z", blue) + line("M150 108L145 94L164 79L164 70M219 42L205 56H232", paper) + circle(241, 24, 12, warm) + line("M83 109V85M75 93L83 79L91 93ZM248 109V86M239 96L248 78L257 96Z"),
|
|
479
|
+
cafe: rect(77, 30, 159, 77, 4, warm) + line("M69 48H243L232 25H81Z", pink) + rect(89, 61, 61, 46, 3, blue) + rect(167, 61, 55, 34, 3, paper) + line("M177 73H204V85H177ZM204 75Q216 74 211 82M183 64Q178 59 184 55M195 64Q190 59 196 55M119 62V106M89 82H150"),
|
|
480
|
+
milktea: rect(77, 29, 164, 78, 5, pink) + rect(88, 38, 141, 15, 2, paper) + line("M107 64L113 105H145L151 64Z", warm) + line("M102 64H156M127 64L135 40", paper) + [119, 129, 139].map((x) => circle(x, 94, 2.5, 'fill="currentColor"')).join("") + rect(174, 67, 40, 40, 3, blue) + line("M179 80H209M179 89H201"),
|
|
481
|
+
diner: rect(67, 29, 183, 78, 6, warm) + rect(80, 40, 69, 48, 3, blue) + line("M114 41V87M80 64H149") + line("M171 80H225M177 81V105M220 81V105") + line("M184 69H216Q217 56 201 56Q184 56 184 69ZM201 56V51", paper) + line("M183 36V47M196 32V43M209 36V47") + rect(88, 95, 51, 11, 3, pink),
|
|
482
|
+
library: rect(71, 29, 177, 78, 4, warm) + line("M87 35V99M155 35V99M231 35V99M87 65H231M87 99H231") + [95, 110, 126, 164, 179, 211].map((x, i) => rect(x, i % 2 ? 45 : 41, 10, i % 2 ? 19 : 23, 1, i % 2 ? mint : blue)).join("") + line("M106 83Q133 75 159 85Q183 75 208 83V111Q183 102 159 111Q134 102 106 111ZM159 85V111", paper),
|
|
483
|
+
market: line("M51 31Q156 58 269 30") + [75, 116, 158, 200, 242].map((x) => circle(x, x === 158 ? 52 : 45, 7, warm)).join("") + line("M60 104V77H130V104M49 77L67 59H123L141 77Z", pink) + line("M180 104V77H250V104M169 77L187 59H243L261 77Z", blue) + line("M73 90H118M192 89H237M81 104V92M225 104V90") + rect(142, 93, 22, 14, 2, mint),
|
|
484
|
+
bathhouse: rect(69, 33, 181, 74, 5, warm) + line("M60 34L89 18H229L258 34Z", blue) + rect(89, 53, 142, 54, 2, paper) + line("M89 54H231V76Q211 66 195 76Q177 67 160 77Q141 67 124 76Q105 66 89 76ZM160 54V107", mint) + line("M112 44Q102 34 112 25M156 45Q145 34 156 25M200 44Q189 34 200 25"),
|
|
485
|
+
thrift: rect(67, 29, 179, 78, 4, mint) + line("M60 48H253L241 26H73Z", warm) + rect(84, 64, 56, 43, 3, paper) + circle(112, 81, 12, blue) + line("M112 72V81L119 84") + line("M163 80L180 65L197 80M180 65V59Q180 53 187 55M163 80H197", pink) + rect(205, 86, 26, 21, 2, pink) + line("M210 86V79H226V86M90 103L102 96H129"),
|
|
486
|
+
riverside: line("M36 90Q93 80 151 90T284 90M36 103Q93 93 151 103T284 103M52 115Q99 107 145 115M187 115Q224 107 269 115", blue) + line("M62 82V57M88 82V57M114 82V57M140 82V57M57 63H147M57 75H147") + line("M165 60Q202 8 262 60M173 60V78M253 60V78M170 60H259", warm) + circle(103, 26, 13, pink) + line("M218 105L230 96H253L247 105Z", mint)
|
|
487
|
+
};
|
|
488
|
+
function venueArtwork(id) {
|
|
489
|
+
const drawing = scenes[id] ?? line("M83 107V51L160 20L237 51V107Z", mint) + rect(108, 64, 32, 43, 3, paper) + rect(169, 62, 42, 27, 3, blue);
|
|
490
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 128" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M28 112H292" opacity=".2"/><g>${drawing}</g></svg>`;
|
|
491
|
+
}
|
|
492
|
+
var symbols = {
|
|
493
|
+
ticket: line("M4 6H20V10Q16 12 20 14V18H4V14Q8 12 4 10ZM14 7V9M14 11V13M14 15V17"),
|
|
494
|
+
keychain: circle(9, 7, 4) + line("M9 11V15M7 15H15L18 21H5Z"),
|
|
495
|
+
bookmark: line("M7 3H17V21L12 17L7 21ZM10 7H14M10 10H14"),
|
|
496
|
+
postcard: rect(3, 5, 18, 14, 2) + line("M14 8V16M17 9H19M6 14L9 10L12 14ZM6 16H12"),
|
|
497
|
+
sticker: line("M4 4H20V15L15 20H4ZM15 20V15H20") + circle(9, 9, 1) + circle(15, 9, 1) + line("M8 12Q12 16 16 12"),
|
|
498
|
+
coin: circle(12, 12, 9) + circle(12, 12, 6) + line("M12 7L14 10L17 12L14 14L12 17L10 14L7 12L10 10Z"),
|
|
499
|
+
cup: line("M5 8H16V17Q10 22 5 17ZM16 10H20V15H16M8 3V5M12 3V5"),
|
|
500
|
+
light: line("M8 15Q1 7 8 4Q16 0 19 8Q20 12 16 15V19H8ZM9 22H15M9 16H15"),
|
|
501
|
+
plush: circle(6, 6, 3) + circle(18, 6, 3) + circle(12, 10, 7) + line("M7 16Q4 23 12 22Q20 23 17 16") + circle(9, 9, 1) + circle(15, 9, 1) + line("M11 12H13"),
|
|
502
|
+
charm: line("M12 3V6M7 6H17L20 12L17 21H7L4 12ZM9 10H15M9 14H15M10 18H14"),
|
|
503
|
+
generic: rect(4, 8, 16, 13, 2) + rect(3, 5, 18, 4, 1) + line("M12 5V21M12 5Q4 4 7 1Q10 0 12 5Q14 0 17 1Q20 4 12 5")
|
|
504
|
+
};
|
|
505
|
+
function souvenirCategory(name) {
|
|
506
|
+
const value = String(name ?? "");
|
|
507
|
+
return /票|券|入场/.test(value) ? "ticket" : /钥匙|挂件|挂饰|吊坠/.test(value) ? "keychain" : /书签/.test(value) ? "bookmark" : /明信片|卡片|画片|海报/.test(value) ? "postcard" : /贴纸|贴画|徽章/.test(value) ? "sticker" : /币|章/.test(value) ? "coin" : /杯|茶|咖啡/.test(value) ? "cup" : /灯/.test(value) ? "light" : /玩偶|公仔|小熊|毛绒/.test(value) ? "plush" : /御守|护符|签/.test(value) ? "charm" : "generic";
|
|
508
|
+
}
|
|
509
|
+
function souvenirArtwork(name) {
|
|
510
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${symbols[souvenirCategory(name)]}</svg>`;
|
|
511
|
+
}
|
|
23
512
|
|
|
24
|
-
|
|
513
|
+
// webui/webui.js
|
|
514
|
+
var CSS2 = `
|
|
25
515
|
.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}
|
|
26
516
|
.fun *{box-sizing:border-box}
|
|
27
517
|
.fun-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:10px}
|
|
@@ -172,169 +662,177 @@ const CSS = `
|
|
|
172
662
|
.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
663
|
|
|
174
664
|
`;
|
|
175
|
-
|
|
176
|
-
/** 小工具:建元素 + 设属性,省掉一屏 createElement。 */
|
|
177
|
-
function el(tag, props, ...kids) {
|
|
665
|
+
function el2(tag, props, ...kids) {
|
|
178
666
|
const n = document.createElement(tag);
|
|
179
667
|
if (props) {
|
|
180
668
|
for (const [k, v] of Object.entries(props)) {
|
|
181
|
-
if (v === null || v ===
|
|
182
|
-
if (k ===
|
|
183
|
-
else if (k ===
|
|
184
|
-
else if (k ===
|
|
185
|
-
else if (k.startsWith(
|
|
186
|
-
else if (k ===
|
|
669
|
+
if (v === null || v === void 0 || v === false) continue;
|
|
670
|
+
if (k === "class") n.className = v;
|
|
671
|
+
else if (k === "text") n.textContent = v;
|
|
672
|
+
else if (k === "html") n.innerHTML = v;
|
|
673
|
+
else if (k.startsWith("on") && typeof v === "function") n.addEventListener(k.slice(2), v);
|
|
674
|
+
else if (k === "style") Object.assign(n.style, v);
|
|
187
675
|
else n.setAttribute(k, v);
|
|
188
676
|
}
|
|
189
677
|
}
|
|
190
678
|
for (const kid of kids.flat()) {
|
|
191
|
-
if (kid === null || kid ===
|
|
192
|
-
n.appendChild(typeof kid ===
|
|
193
|
-
? document.createTextNode(String(kid)) : kid);
|
|
679
|
+
if (kid === null || kid === void 0 || kid === false) continue;
|
|
680
|
+
n.appendChild(typeof kid === "string" || typeof kid === "number" ? document.createTextNode(String(kid)) : kid);
|
|
194
681
|
}
|
|
195
682
|
return n;
|
|
196
683
|
}
|
|
197
|
-
|
|
198
|
-
/** 只注入一次样式(同一 root 反复 mount 时别叠 <style>)。 */
|
|
199
684
|
function ensureStyle(root) {
|
|
200
|
-
if (root.querySelector(
|
|
201
|
-
root.appendChild(
|
|
685
|
+
if (root.querySelector("style.fun-style")) return;
|
|
686
|
+
root.appendChild(el2("style", { class: "fun-style", text: CSS2 }));
|
|
202
687
|
}
|
|
203
|
-
|
|
204
|
-
/** 顶层容器。 */
|
|
205
688
|
function shell(root) {
|
|
206
689
|
ensureStyle(root);
|
|
207
|
-
const box =
|
|
690
|
+
const box = el2("div", { class: "fun" });
|
|
208
691
|
root.appendChild(box);
|
|
209
692
|
return box;
|
|
210
693
|
}
|
|
211
|
-
|
|
212
694
|
function errorCard(err, retry, retained = false) {
|
|
213
|
-
return
|
|
214
|
-
|
|
215
|
-
|
|
695
|
+
return el2(
|
|
696
|
+
"div",
|
|
697
|
+
{ class: "fun-err", role: "alert" },
|
|
698
|
+
el2("span", { text: retained ? `刷新失败,保留上次内容:${err?.message ?? String(err)}` : `面板加载失败:${err?.message ?? String(err)}` }),
|
|
699
|
+
retry ? el2("button", { type: "button", onclick: () => {
|
|
700
|
+
void retry();
|
|
701
|
+
} }, "重试") : null
|
|
702
|
+
);
|
|
216
703
|
}
|
|
217
|
-
|
|
218
704
|
function heading(title, subtitle) {
|
|
219
|
-
return
|
|
705
|
+
return el2("header", { class: "fun-heading" }, el2("h2", { text: title }), el2("p", { text: subtitle }));
|
|
220
706
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const node = el('div', { class: 'fun-feedback' });
|
|
707
|
+
function feedback2(box) {
|
|
708
|
+
const node = el2("div", { class: "fun-feedback" });
|
|
224
709
|
box.appendChild(node);
|
|
225
710
|
return node;
|
|
226
711
|
}
|
|
227
|
-
|
|
228
712
|
function sceneArt(place, detail = false) {
|
|
229
|
-
return
|
|
230
|
-
|
|
713
|
+
return el2("div", {
|
|
714
|
+
class: `fun-art${detail ? " fun-art-detail" : ""}`,
|
|
715
|
+
"aria-hidden": "true",
|
|
716
|
+
"data-artwork": place.userVenue ? "custom" : place.id,
|
|
717
|
+
html: venueArtwork(place.userVenue ? "" : place.id)
|
|
718
|
+
});
|
|
231
719
|
}
|
|
232
720
|
function itemIcon(name) {
|
|
233
|
-
return
|
|
721
|
+
return el2("span", { class: "fun-icon", "aria-hidden": "true", "data-category": souvenirCategory(name), html: souvenirArtwork(name) });
|
|
234
722
|
}
|
|
235
|
-
|
|
236
|
-
// Refreshes and explicit view changes can repaint; typing only repaints results.
|
|
237
723
|
function rememberFocus(container) {
|
|
238
724
|
const active = document.activeElement;
|
|
239
725
|
let parent = active;
|
|
240
726
|
while (parent && parent !== container) parent = parent.parentNode;
|
|
241
|
-
const key = parent ? active?.getAttribute?.(
|
|
727
|
+
const key = parent ? active?.getAttribute?.("data-focus-key") : null;
|
|
242
728
|
const start = active?.selectionStart;
|
|
243
729
|
const end = active?.selectionEnd;
|
|
244
730
|
return () => {
|
|
245
731
|
if (!key) return;
|
|
246
|
-
const target = [...container.querySelectorAll(
|
|
247
|
-
.find((node) => node.getAttribute('data-focus-key') === key);
|
|
732
|
+
const target = [...container.querySelectorAll("input"), ...container.querySelectorAll("select")].find((node) => node.getAttribute("data-focus-key") === key);
|
|
248
733
|
target?.focus?.();
|
|
249
|
-
if (typeof start ===
|
|
250
|
-
try {
|
|
734
|
+
if (typeof start === "number" && typeof target?.setSelectionRange === "function" && target.type !== "date") {
|
|
735
|
+
try {
|
|
736
|
+
target.setSelectionRange(start, end);
|
|
737
|
+
} catch {
|
|
738
|
+
}
|
|
251
739
|
}
|
|
252
740
|
};
|
|
253
741
|
}
|
|
254
|
-
|
|
255
|
-
const routeStatus = { planned: '待出发', active: '行程中', between: '站间歇脚', completed: '已完成', cancelled: '已取消' };
|
|
742
|
+
var routeStatus = { planned: "待出发", active: "行程中", between: "站间歇脚", completed: "已完成", cancelled: "已取消" };
|
|
256
743
|
function routeSummary(route, trips = [], selectTrip) {
|
|
257
|
-
const node =
|
|
258
|
-
|
|
259
|
-
|
|
744
|
+
const node = el2(
|
|
745
|
+
"section",
|
|
746
|
+
{ class: "fun-route", "data-route-id": route.id, "aria-label": "联程记录" },
|
|
747
|
+
el2("strong", { text: `联程 · ${routeStatus[route.status] ?? "状态未知"}` }),
|
|
748
|
+
el2("div", { class: "fun-route-stops", text: (route.stops ?? []).map((stop) => stop.placeName || stop.placeId).join(" → ") })
|
|
749
|
+
);
|
|
260
750
|
const retained = (route.tripIds ?? []).map((id) => trips.find((trip) => trip.id === id)).filter(Boolean);
|
|
261
|
-
if (selectTrip && retained.length) node.appendChild(
|
|
262
|
-
type:
|
|
263
|
-
|
|
264
|
-
|
|
751
|
+
if (selectTrip && retained.length) node.appendChild(el2("div", { class: "fun-route-stops" }, retained.map((trip) => el2("button", {
|
|
752
|
+
type: "button",
|
|
753
|
+
class: "fun-link",
|
|
754
|
+
"data-trip-id": trip.id,
|
|
755
|
+
onclick: () => selectTrip(trip)
|
|
756
|
+
}, `${trip.routeOrder ? `第 ${trip.routeOrder} 站 · ` : ""}${trip.placeName} · ${trip.day || "日期不详"}`))));
|
|
757
|
+
if (selectTrip && (route.tripIds ?? []).length > retained.length) node.appendChild(el2("div", { class: "fun-note", text: "较早行程仅保留联程归属,详细记录已归档。" }));
|
|
265
758
|
return node;
|
|
266
759
|
}
|
|
267
|
-
|
|
268
760
|
function tripDetails(trip) {
|
|
269
|
-
const detail =
|
|
270
|
-
if (trip.company) detail.appendChild(
|
|
271
|
-
if (trip.timelineTruncated) detail.appendChild(
|
|
272
|
-
if (trip.routeId) detail.appendChild(
|
|
761
|
+
const detail = el2("section", { class: "fun-trip-detail", "aria-label": `${trip.placeName}行程详情` });
|
|
762
|
+
if (trip.company) detail.appendChild(el2("p", { text: `同行 · ${trip.company}` }));
|
|
763
|
+
if (trip.timelineTruncated) detail.appendChild(el2("p", { class: "fun-note", text: "这趟记录较长,时间线保留进门与最近的活动;较早的逐项细节已省略。" }));
|
|
764
|
+
if (trip.routeId) detail.appendChild(el2("p", { class: "fun-note", text: `联程${trip.routeOrder ? ` · 第 ${trip.routeOrder} 站` : ""}`, "data-route-id": trip.routeId }));
|
|
273
765
|
const supplied = Array.isArray(trip.timeline) && trip.timeline.length > 0;
|
|
274
|
-
// Old arrays have no per-action clock. Preserve their text, explicitly unknown.
|
|
275
766
|
const timeline = supplied ? trip.timeline : [
|
|
276
|
-
...(trip.visited ?? []).map((area) => ({ kind:
|
|
277
|
-
...(trip.events ?? []).map((text) => ({ kind:
|
|
278
|
-
...(trip.choices ?? []).map((choice) => ({ kind:
|
|
279
|
-
...(trip.souvenirs ?? []).map((text) => ({ kind:
|
|
280
|
-
...(trip.photos ?? []).map((text) => ({ kind:
|
|
281
|
-
...(trip.ate ?? []).map((item) => ({ kind:
|
|
767
|
+
...(trip.visited ?? []).map((area) => ({ kind: "area", text: typeof area === "string" ? area : area.area, area: typeof area === "string" ? area : area.area, at: null })),
|
|
768
|
+
...(trip.events ?? []).map((text) => ({ kind: "event", text, event: text, at: null })),
|
|
769
|
+
...(trip.choices ?? []).map((choice) => ({ kind: "choice", text: choice.result, event: choice.event, at: null })),
|
|
770
|
+
...(trip.souvenirs ?? []).map((text) => ({ kind: "buy", text, at: null })),
|
|
771
|
+
...(trip.photos ?? []).map((text) => ({ kind: "photo", text, at: null })),
|
|
772
|
+
...(trip.ate ?? []).map((item) => ({ kind: "consume", text: `${item.verb}了 ${item.item}`, at: null }))
|
|
282
773
|
];
|
|
283
774
|
if (timeline.length) {
|
|
284
|
-
detail.appendChild(
|
|
285
|
-
if (!supplied) detail.appendChild(
|
|
286
|
-
const list =
|
|
775
|
+
detail.appendChild(el2("div", { class: "fun-sec", text: "沿途时间线" }));
|
|
776
|
+
if (!supplied) detail.appendChild(el2("p", { class: "fun-note", text: "这趟旧记录没有保存逐项时间,以下均标为时间不详。" }));
|
|
777
|
+
const list = el2("ol", { class: "fun-timeline" });
|
|
287
778
|
const blocks = [];
|
|
288
779
|
let current = null;
|
|
289
780
|
const block = (area) => {
|
|
290
|
-
const node =
|
|
781
|
+
const node = el2("li", { class: "fun-timeline-block", "data-area": area || "" }, el2("div", { class: "fun-timeline-area", text: area || "途中记录(区域未记)" }));
|
|
291
782
|
const value = { area, node, events: [] };
|
|
292
|
-
blocks.push(value);
|
|
783
|
+
blocks.push(value);
|
|
784
|
+
list.appendChild(node);
|
|
785
|
+
return value;
|
|
293
786
|
};
|
|
294
|
-
const labels = { enter:
|
|
787
|
+
const labels = { enter: "进门", area: "逛到", event: "小事", choice: "选择", buy: "带回", photo: "拍照", consume: "吃喝", close: "收摊" };
|
|
295
788
|
for (const entry of timeline) {
|
|
296
|
-
const known = typeof entry.at ===
|
|
297
|
-
const clock = known ? [entry.day, entry.hm].filter(Boolean).join(
|
|
298
|
-
const row =
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
789
|
+
const known = typeof entry.at === "number" && Number.isFinite(entry.at);
|
|
790
|
+
const clock = known ? [entry.day, entry.hm].filter(Boolean).join(" ") || "时间未标注" : "时间不详";
|
|
791
|
+
const row = el2(
|
|
792
|
+
"div",
|
|
793
|
+
{ class: "fun-timeline-row", "data-kind": entry.kind, "data-at": known ? String(entry.at) : "unknown" },
|
|
794
|
+
el2("span", { class: "fun-timeline-time", text: clock }),
|
|
795
|
+
el2("span", null, entry.kind === "buy" ? itemIcon(entry.text) : null, `${labels[entry.kind] ?? "记录"} · ${entry.text || (entry.kind === "area" ? entry.area : "") || "未记内容"}`)
|
|
796
|
+
);
|
|
797
|
+
if (entry.kind === "enter" || entry.kind === "close") {
|
|
798
|
+
current = block(entry.kind === "enter" ? "出发与进门" : "收摊");
|
|
799
|
+
current.node.appendChild(row);
|
|
800
|
+
current = null;
|
|
801
|
+
continue;
|
|
304
802
|
}
|
|
305
|
-
const source = entry.kind ===
|
|
306
|
-
.find((event) => entry.event && event.name === entry.event && (!entry.area || event.area === entry.area)) : null;
|
|
803
|
+
const source = entry.kind === "choice" ? [...blocks].reverse().flatMap((group) => [...group.events].reverse()).find((event) => entry.event && event.name === entry.event && (!entry.area || event.area === entry.area)) : null;
|
|
307
804
|
if (source && current === source.group && current.lastNode === source.node) {
|
|
308
|
-
source.node.appendChild(
|
|
805
|
+
source.node.appendChild(el2("div", { class: "fun-timeline-choice", "data-event": entry.event }, row));
|
|
309
806
|
continue;
|
|
310
807
|
}
|
|
311
|
-
|
|
312
|
-
// nest it. Its source label links it while chronological order stays put.
|
|
313
|
-
const area = entry.area || '';
|
|
808
|
+
const area = entry.area || "";
|
|
314
809
|
if (!current || area !== current.area) current = block(area);
|
|
315
|
-
if (entry.kind ===
|
|
316
|
-
const event =
|
|
810
|
+
if (entry.kind === "event") {
|
|
811
|
+
const event = el2("div", { class: "fun-timeline-event", "data-event": entry.event || entry.text }, row);
|
|
317
812
|
current.events.push({ name: entry.event || entry.text, area: current.area, group: current, node: event });
|
|
318
|
-
current.node.appendChild(event);
|
|
813
|
+
current.node.appendChild(event);
|
|
814
|
+
current.lastNode = event;
|
|
319
815
|
} else {
|
|
320
|
-
if (entry.kind ===
|
|
321
|
-
row.appendChild(
|
|
322
|
-
const choice =
|
|
323
|
-
current.node.appendChild(choice);
|
|
324
|
-
|
|
816
|
+
if (entry.kind === "choice" && entry.event) {
|
|
817
|
+
row.appendChild(el2("span", { class: "fun-timeline-source", text: `对应小事:${entry.event}` }));
|
|
818
|
+
const choice = el2("div", { class: "fun-timeline-choice", "data-event": entry.event }, row);
|
|
819
|
+
current.node.appendChild(choice);
|
|
820
|
+
current.lastNode = choice;
|
|
821
|
+
} else {
|
|
822
|
+
current.node.appendChild(row);
|
|
823
|
+
current.lastNode = row;
|
|
824
|
+
}
|
|
325
825
|
}
|
|
326
826
|
}
|
|
327
827
|
detail.appendChild(list);
|
|
328
828
|
}
|
|
329
|
-
if (trip.note) detail.appendChild(
|
|
330
|
-
if (trip.scene) detail.appendChild(
|
|
829
|
+
if (trip.note) detail.appendChild(el2("p", { text: `收摊备注 · ${trip.note}` }));
|
|
830
|
+
if (trip.scene) detail.appendChild(el2("p", { class: "fun-dim", text: `生图 scene:${trip.scene}${trip.outfit ? ` · outfits:${trip.outfit}` : ""}` }));
|
|
331
831
|
return detail;
|
|
332
832
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const states = new Map();
|
|
337
|
-
const views = new Map();
|
|
833
|
+
function tripLookup(ctx, method, parameter, label2) {
|
|
834
|
+
const states = /* @__PURE__ */ new Map();
|
|
835
|
+
const views = /* @__PURE__ */ new Map();
|
|
338
836
|
const redraw = (id) => {
|
|
339
837
|
for (const view of views.get(id) ?? []) {
|
|
340
838
|
if (view.host.isConnected === false) views.get(id).delete(view);
|
|
@@ -342,463 +840,479 @@ function tripLookup(ctx, method, parameter, label) {
|
|
|
342
840
|
}
|
|
343
841
|
};
|
|
344
842
|
return (id) => {
|
|
345
|
-
const state = states.get(id) ?? { opened: false, pending: false, trips: null, error:
|
|
843
|
+
const state = states.get(id) ?? { opened: false, pending: false, trips: null, error: "" };
|
|
346
844
|
states.set(id, state);
|
|
347
|
-
const host =
|
|
845
|
+
const host = el2("section", { class: "fun-history", "data-lookup-id": id });
|
|
348
846
|
const paint = () => {
|
|
349
847
|
let focused = document.activeElement;
|
|
350
848
|
while (focused && focused !== host) focused = focused.parentNode;
|
|
351
|
-
host.replaceChildren(
|
|
352
|
-
|
|
353
|
-
|
|
849
|
+
host.replaceChildren(el2(
|
|
850
|
+
"button",
|
|
851
|
+
{
|
|
852
|
+
type: "button",
|
|
853
|
+
class: "fun-link fun-history-toggle",
|
|
854
|
+
"aria-expanded": String(state.opened),
|
|
855
|
+
disabled: state.pending ? "disabled" : null,
|
|
856
|
+
onclick: () => {
|
|
857
|
+
if (state.pending) return;
|
|
858
|
+
state.opened = !state.opened;
|
|
859
|
+
if (state.opened && state.trips === null) void load();
|
|
860
|
+
else redraw(id);
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
state.pending ? "读取中…" : state.opened ? "收起回看" : label2
|
|
864
|
+
));
|
|
354
865
|
const restore = () => {
|
|
355
866
|
if (!focused) return;
|
|
356
|
-
if (state.pending) {
|
|
357
|
-
|
|
867
|
+
if (state.pending) {
|
|
868
|
+
host.setAttribute("tabindex", "-1");
|
|
869
|
+
host.focus?.();
|
|
870
|
+
} else host.querySelector(".fun-history-toggle")?.focus?.();
|
|
358
871
|
};
|
|
359
|
-
if (!state.opened) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
872
|
+
if (!state.opened) {
|
|
873
|
+
restore();
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
const content = el2("div", { class: "fun-history-content", "aria-live": "polite" });
|
|
877
|
+
host.appendChild(content);
|
|
878
|
+
if (state.pending) content.appendChild(el2("div", { class: "fun-inline-status", role: "status", text: "正在找这段回忆…" }));
|
|
879
|
+
if (state.error) content.appendChild(el2("div", { class: "fun-err", role: "alert" }, el2("span", { text: state.error }), el2("button", { type: "button", onclick: () => {
|
|
880
|
+
void load();
|
|
881
|
+
} }, "重试")));
|
|
882
|
+
if (state.trips?.length === 0) content.appendChild(el2("div", { class: "fun-note", text: "没有可回看的详细行程;较早记录可能已经归档。" }));
|
|
883
|
+
for (const trip of state.trips ?? []) content.appendChild(el2(
|
|
884
|
+
"details",
|
|
885
|
+
{ class: "fun-inspector", open: state.trips.length === 1 ? "open" : null, "data-trip-id": trip.id },
|
|
886
|
+
el2("summary", { text: `${trip.placeName} · ${trip.day || "日期不详"} · ${trip.summary || "行程记录"}` }),
|
|
887
|
+
tripDetails(trip)
|
|
888
|
+
));
|
|
366
889
|
restore();
|
|
367
890
|
};
|
|
368
891
|
const load = async () => {
|
|
369
892
|
if (state.pending) return;
|
|
370
|
-
state.pending = true;
|
|
893
|
+
state.pending = true;
|
|
894
|
+
state.error = "";
|
|
895
|
+
redraw(id);
|
|
371
896
|
try {
|
|
372
897
|
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(
|
|
898
|
+
if (!result?.ok) throw new Error(result?.error ?? "详细行程暂时读不到");
|
|
899
|
+
if (!Array.isArray(result.trips)) throw new Error("详细行程格式不正确");
|
|
375
900
|
state.trips = result.trips;
|
|
376
|
-
} catch (error) {
|
|
377
|
-
|
|
901
|
+
} catch (error) {
|
|
902
|
+
state.error = error?.message ?? String(error);
|
|
903
|
+
} finally {
|
|
904
|
+
state.pending = false;
|
|
905
|
+
if (!ctx.signal?.aborted) redraw(id);
|
|
906
|
+
}
|
|
378
907
|
};
|
|
379
|
-
if (!views.has(id)) views.set(id, new Set());
|
|
380
|
-
views.get(id).add({ host, paint });
|
|
908
|
+
if (!views.has(id)) views.set(id, /* @__PURE__ */ new Set());
|
|
909
|
+
views.get(id).add({ host, paint });
|
|
910
|
+
paint();
|
|
911
|
+
return host;
|
|
381
912
|
};
|
|
382
913
|
}
|
|
383
|
-
|
|
384
|
-
// ---------------------------------------------------------------------------
|
|
385
|
-
// places —— 去哪儿
|
|
386
|
-
// ---------------------------------------------------------------------------
|
|
387
|
-
|
|
388
914
|
function mountPlaces(ctx) {
|
|
389
915
|
const root = ctx.root;
|
|
390
916
|
root.replaceChildren();
|
|
391
917
|
const box = shell(root);
|
|
392
|
-
const body =
|
|
918
|
+
const body = el2("div");
|
|
393
919
|
box.appendChild(body);
|
|
394
|
-
|
|
395
|
-
let
|
|
396
|
-
let quickFilter = '全部';
|
|
920
|
+
let keyword = "";
|
|
921
|
+
let quickFilter = "全部";
|
|
397
922
|
let expanded = null;
|
|
398
|
-
let expandedOrigin =
|
|
399
|
-
const historyView = tripLookup(ctx,
|
|
400
|
-
/** null = 没在编辑;{ mode: 'new' | 'edit', venue } = 打开表单。 */
|
|
923
|
+
let expandedOrigin = "list";
|
|
924
|
+
const historyView = tripLookup(ctx, "history", "placeId", "回看这里的行程");
|
|
401
925
|
let editing = null;
|
|
402
|
-
let formError =
|
|
403
|
-
let outingAction =
|
|
926
|
+
let formError = "";
|
|
927
|
+
let outingAction = "";
|
|
404
928
|
let notice = null;
|
|
405
929
|
let loadSequence = 0;
|
|
406
|
-
/** 表单打开期间收到的最新数据,等关掉表单再补画,免得把用户填的内容冲掉。 */
|
|
407
930
|
let currentData = null;
|
|
408
|
-
const status =
|
|
409
|
-
body.appendChild(
|
|
410
|
-
|
|
931
|
+
const status = feedback2(box);
|
|
932
|
+
body.appendChild(el2("div", { class: "fun-loading", role: "status", text: "正在看看有哪些地方开着…" }));
|
|
411
933
|
const render = (data) => {
|
|
412
934
|
const restoreFocus = rememberFocus(body);
|
|
413
|
-
// 表单相关声明要放在最前:点「添加地点」时 render 会重跑,
|
|
414
|
-
// 而那一轮里 `venueForm()` 在 `if (editing)` 处就会用到 `fields`。
|
|
415
|
-
// 放在后面会撞上 TDZ(`Cannot access 'fields' before initialization`)。
|
|
416
935
|
const renderAll = () => render(data);
|
|
417
936
|
const fields = {};
|
|
418
|
-
const lines = (v) =>
|
|
419
|
-
const parseLines = (s) => String(s ??
|
|
937
|
+
const lines = (v) => Array.isArray(v) ? v.join("\n") : "";
|
|
938
|
+
const parseLines = (s) => String(s ?? "").split(/[\n,,、]/).map((x) => x.trim()).filter(Boolean);
|
|
420
939
|
currentData = data;
|
|
421
|
-
body.replaceChildren(heading(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
940
|
+
body.replaceChildren(heading("去哪儿", "挑一处喜欢的地方,慢慢逛。"));
|
|
941
|
+
const pendingChoice = (choice) => choice ? el2(
|
|
942
|
+
"div",
|
|
943
|
+
{ class: "fun-choice" },
|
|
944
|
+
el2("div", { class: "fun-choice-title", text: choice.prompt || "待选择事件" }),
|
|
945
|
+
el2("ul", { class: "fun-list" }, choice.options.map((option) => el2("li", { text: option.label }))),
|
|
946
|
+
el2("p", { class: "fun-choice-note", text: "她可以选一项,也可以略过。" })
|
|
947
|
+
) : null;
|
|
428
948
|
const draft = data.draft;
|
|
429
949
|
if (draft) {
|
|
430
|
-
const draftAction = (method,
|
|
431
|
-
type:
|
|
432
|
-
disabled: outingAction ||
|
|
433
|
-
onclick: () => resolveDraft(method, draft.id)
|
|
434
|
-
}, outingAction === method ?
|
|
435
|
-
body.appendChild(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
950
|
+
const draftAction = (method, label2) => el2("button", {
|
|
951
|
+
type: "button",
|
|
952
|
+
disabled: outingAction || method === "resume" && draft.canResume === false ? "disabled" : null,
|
|
953
|
+
onclick: () => resolveDraft(method, draft.id)
|
|
954
|
+
}, outingAction === method ? "处理中…" : label2);
|
|
955
|
+
body.appendChild(el2(
|
|
956
|
+
"section",
|
|
957
|
+
{ class: "fun-draft" },
|
|
958
|
+
el2("h3", { text: `未逛完 · ${draft.placeName}` }),
|
|
959
|
+
el2("div", { class: "fun-meta", text: `最后活动 ${draft.lastDay ? `${draft.lastDay} ` : ""}${draft.lastHm} · 逛了 ${draft.visited.length} 处` }),
|
|
960
|
+
el2("div", { class: "fun-meta", text: draft.visited.length ? `逛过:${draft.visited.map((v) => v.area).join("、")}` : "还没逛到哪儿" }),
|
|
439
961
|
pendingChoice(draft.pendingChoice),
|
|
440
|
-
draft.canResume === false ?
|
|
441
|
-
|
|
962
|
+
draft.canResume === false ? el2("div", { class: "fun-meta", text: "这处已不在地点清单中,可以按已有记录收摊。" }) : null,
|
|
963
|
+
el2("div", { class: "fun-draft-actions" }, draftAction("resume", "继续逛"), draftAction("closeDraft", "按已有记录收摊"))
|
|
964
|
+
));
|
|
442
965
|
}
|
|
443
|
-
|
|
444
|
-
// ---- 正在逛的那一趟 ----
|
|
445
966
|
if (data.session) {
|
|
446
967
|
const s = data.session;
|
|
447
968
|
const venue = data.places.find((p) => p.id === s.placeId);
|
|
448
|
-
const leftAreas = venue
|
|
449
|
-
|
|
450
|
-
: [];
|
|
451
|
-
const leftText = venue?.state === 'closed' ? '这处已经打烊'
|
|
452
|
-
: leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join('、')}` : '这会儿开放的都逛过了';
|
|
969
|
+
const leftAreas = venue ? venue.areas.filter((a) => !s.visited.some((v) => v.area === a)) : [];
|
|
970
|
+
const leftText = venue?.state === "closed" ? "这处已经打烊" : leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join("、")}` : "这会儿开放的都逛过了";
|
|
453
971
|
const progress = s.venueAreaCount ? `${s.visited.length}/${s.venueAreaCount}` : String(s.visited.length);
|
|
454
|
-
body.appendChild(
|
|
455
|
-
|
|
456
|
-
|
|
972
|
+
body.appendChild(el2(
|
|
973
|
+
"div",
|
|
974
|
+
{ class: "fun-live" },
|
|
975
|
+
el2("h3", { text: `正在${s.placeName}逛` }),
|
|
976
|
+
el2(
|
|
977
|
+
"div",
|
|
978
|
+
{ class: "fun-meta" },
|
|
457
979
|
`${s.enteredHm} 进门 · 待了 ${s.stayedMin} 分钟 · 逛了 ${progress} 处`,
|
|
458
|
-
s.stale ?
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
s.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
pendingChoice(s.pendingChoice),
|
|
980
|
+
s.stale ? el2("span", { class: "fun-stale", text: " · 这一趟挂得有点久了" }) : null
|
|
981
|
+
),
|
|
982
|
+
el2("div", { class: "fun-meta", text: `逛过:${s.visited.length ? s.visited.map((v) => v.area).join("、") : "还没逛到哪儿"}` }),
|
|
983
|
+
s.souvenirs.length ? el2("div", { class: "fun-chips" }, s.souvenirs.map((x) => el2("span", { class: "fun-chip fun-chip-on", text: `买了 ${x}` }))) : null,
|
|
984
|
+
s.photos.length ? el2("div", { class: "fun-chips" }, s.photos.map((x) => el2("span", { class: "fun-chip", text: `📷 ${x}` }))) : null,
|
|
985
|
+
s.ate && s.ate.length ? el2("div", { class: "fun-chips" }, s.ate.map((x) => el2("span", { class: "fun-chip fun-chip-ate", text: `${x.verb}了 ${x.item}` }))) : null,
|
|
986
|
+
s.events.length ? el2("ul", { class: "fun-list" }, s.events.slice(-3).map((e) => el2("li", { text: e }))) : null,
|
|
987
|
+
venue ? el2("div", { class: "fun-meta", text: leftText }) : null,
|
|
988
|
+
pendingChoice(s.pendingChoice)
|
|
468
989
|
));
|
|
469
990
|
} else if (!draft) {
|
|
470
|
-
body.appendChild(
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
991
|
+
body.appendChild(el2(
|
|
992
|
+
"div",
|
|
993
|
+
{ class: "fun-live fun-live-idle" },
|
|
994
|
+
el2("h3", { text: "这会儿没在逛" }),
|
|
995
|
+
el2("div", { class: "fun-meta", text: `现在 ${data.nowHm} · ${data.total} 处地方里 ${data.openCount} 处开着` }),
|
|
996
|
+
el2("div", { class: "fun-meta fun-dim", text: "她会自己挑一处进去;你在下面点一张卡也能看细节。" })
|
|
474
997
|
));
|
|
475
998
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
999
|
+
if (notice) body.appendChild(el2("div", {
|
|
1000
|
+
class: "fun-meta fun-outing-result",
|
|
1001
|
+
role: notice.error ? "alert" : "status",
|
|
1002
|
+
tabindex: "-1",
|
|
1003
|
+
text: notice.text
|
|
479
1004
|
}));
|
|
480
|
-
if (data.upcomingWish) body.appendChild(
|
|
481
|
-
|
|
1005
|
+
if (data.upcomingWish) body.appendChild(el2("div", { class: "fun-upcoming-wish", text: data.upcomingWish }));
|
|
482
1006
|
if (data.route) body.appendChild(routeSummary(data.route));
|
|
483
|
-
const recommendBox =
|
|
1007
|
+
const recommendBox = el2("section", { class: "fun-recommendations", "aria-label": "此刻推荐" });
|
|
484
1008
|
body.appendChild(recommendBox);
|
|
485
|
-
body.appendChild(
|
|
486
|
-
const management =
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
value: keyword,
|
|
1009
|
+
body.appendChild(el2("div", { class: "fun-sec", text: "全部地方 · 找一处看看" }));
|
|
1010
|
+
const management = el2("details", { class: "fun-management", open: editing ? "open" : null }, el2("summary", { text: "地点管理与说明" }));
|
|
1011
|
+
const input = el2("input", {
|
|
1012
|
+
class: "fun-search",
|
|
1013
|
+
type: "search",
|
|
1014
|
+
placeholder: "搜地方名、别名或标签(庙会 / 室内 / 夜…)",
|
|
1015
|
+
"aria-label": "搜索全部地方",
|
|
1016
|
+
"data-focus-key": "places-search",
|
|
1017
|
+
value: keyword
|
|
495
1018
|
});
|
|
496
|
-
input.addEventListener(
|
|
1019
|
+
input.addEventListener("input", () => {
|
|
497
1020
|
keyword = input.value;
|
|
498
|
-
// 只重画列表,不重画搜索框——否则每敲一个字就丢焦点(feast 踩过这条)。
|
|
499
1021
|
renderList();
|
|
500
1022
|
});
|
|
501
|
-
const addBtn =
|
|
502
|
-
type:
|
|
1023
|
+
const addBtn = el2("button", {
|
|
1024
|
+
type: "button",
|
|
503
1025
|
onclick: () => {
|
|
504
|
-
editing = { mode:
|
|
505
|
-
formError =
|
|
1026
|
+
editing = { mode: "new", venue: null };
|
|
1027
|
+
formError = "";
|
|
506
1028
|
renderAll();
|
|
507
|
-
}
|
|
508
|
-
},
|
|
509
|
-
body.appendChild(
|
|
510
|
-
management.appendChild(
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
`预设的 ${data.total - data.userVenueCount}
|
|
515
|
-
|
|
516
|
-
+ (data.overriddenCount
|
|
517
|
-
? ` 已改过 ${data.overriddenCount} 处预设。`
|
|
518
|
-
: '')
|
|
519
|
-
+ (data.feast
|
|
520
|
-
? ' 吃喝的味道会去「鱼的每一天」拿(可在配置里关掉)。'
|
|
521
|
-
: ' 吃喝只记名字、不描述味道(可在配置里打开「去鱼的每一天拿」)。')));
|
|
522
|
-
|
|
523
|
-
// 一键恢复全部预设:只在真有覆盖层时给,免得平时多一个没用的按钮。
|
|
1029
|
+
}
|
|
1030
|
+
}, "+ 添加地点");
|
|
1031
|
+
body.appendChild(el2("div", { class: "fun-bar" }, input));
|
|
1032
|
+
management.appendChild(el2("div", { class: "fun-bar" }, addBtn));
|
|
1033
|
+
management.appendChild(el2(
|
|
1034
|
+
"div",
|
|
1035
|
+
{ class: "fun-hint" },
|
|
1036
|
+
`预设的 ${data.total - data.userVenueCount} 处插件自带,现在也能改——改过的会标「已改」,随时能恢复;你自己加了 ${data.userVenueCount} 处,随时能改能删。` + (data.overriddenCount ? ` 已改过 ${data.overriddenCount} 处预设。` : "") + (data.feast ? " 吃喝的味道会去「鱼的每一天」拿(可在配置里关掉)。" : " 吃喝只记名字、不描述味道(可在配置里打开「去鱼的每一天拿」)。")
|
|
1037
|
+
));
|
|
524
1038
|
if (data.overriddenCount) {
|
|
525
|
-
const resetError =
|
|
526
|
-
const resetButton =
|
|
527
|
-
type:
|
|
528
|
-
style: { marginBottom:
|
|
1039
|
+
const resetError = el2("div", { class: "fun-form-error", role: "alert" });
|
|
1040
|
+
const resetButton = el2("button", {
|
|
1041
|
+
type: "button",
|
|
1042
|
+
style: { marginBottom: "10px" },
|
|
529
1043
|
onclick: async () => {
|
|
530
1044
|
if (resetButton.disabled) return;
|
|
531
|
-
resetButton.disabled = true;
|
|
1045
|
+
resetButton.disabled = true;
|
|
1046
|
+
resetError.textContent = "";
|
|
1047
|
+
resetButton.textContent = "恢复中…";
|
|
532
1048
|
try {
|
|
533
|
-
const r = await ctx.invoke(
|
|
534
|
-
if (!r?.ok) throw new Error(r?.error ??
|
|
535
|
-
formError =
|
|
1049
|
+
const r = await ctx.invoke("resetAll", []);
|
|
1050
|
+
if (!r?.ok) throw new Error(r?.error ?? "恢复不了");
|
|
1051
|
+
formError = "";
|
|
536
1052
|
await load();
|
|
537
1053
|
} catch (err) {
|
|
538
1054
|
resetError.textContent = err?.message ?? String(err);
|
|
539
|
-
} finally {
|
|
540
|
-
|
|
1055
|
+
} finally {
|
|
1056
|
+
resetButton.disabled = false;
|
|
1057
|
+
resetButton.textContent = `恢复全部预设(${data.overriddenCount} 处)`;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
541
1060
|
}, `恢复全部预设(${data.overriddenCount} 处)`);
|
|
542
|
-
management.appendChild(resetButton);
|
|
1061
|
+
management.appendChild(resetButton);
|
|
1062
|
+
management.appendChild(resetError);
|
|
543
1063
|
}
|
|
544
|
-
|
|
545
|
-
// ---- 编辑表单(打开时在最上面) ----
|
|
546
1064
|
if (editing) body.appendChild(venueForm());
|
|
547
|
-
|
|
548
|
-
const filterBar = el('div', { class: 'fun-filters', role: 'group', 'aria-label': '地点快捷筛选' });
|
|
1065
|
+
const filterBar = el2("div", { class: "fun-filters", role: "group", "aria-label": "地点快捷筛选" });
|
|
549
1066
|
const filterButtons = [];
|
|
550
|
-
for (const
|
|
551
|
-
const button =
|
|
552
|
-
quickFilter =
|
|
553
|
-
for (const item of filterButtons) item.button.setAttribute(
|
|
1067
|
+
for (const label2 of ["全部", "现在开着", "室内", "户外", "夜游", "我的地点"]) {
|
|
1068
|
+
const button = el2("button", { type: "button", "aria-pressed": String(quickFilter === label2), onclick: () => {
|
|
1069
|
+
quickFilter = label2;
|
|
1070
|
+
for (const item of filterButtons) item.button.setAttribute("aria-pressed", String(item.label === label2));
|
|
554
1071
|
renderList();
|
|
555
|
-
} },
|
|
556
|
-
filterButtons.push({ label, button });
|
|
1072
|
+
} }, label2);
|
|
1073
|
+
filterButtons.push({ label: label2, button });
|
|
557
1074
|
filterBar.appendChild(button);
|
|
558
1075
|
}
|
|
559
1076
|
body.appendChild(filterBar);
|
|
560
|
-
const listBox =
|
|
1077
|
+
const listBox = el2("div");
|
|
561
1078
|
body.appendChild(listBox);
|
|
562
1079
|
body.appendChild(management);
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* 重画列表。
|
|
566
|
-
*
|
|
567
|
-
* 展开的详情**就地插在它那张卡下面**,占满一整行(grid-column: 1/-1),
|
|
568
|
-
* 而不是像 0.1.1 那样统统追加到列表末尾——那样点第一张卡要滑过十二张才看得见。
|
|
569
|
-
*/
|
|
570
1080
|
function renderList() {
|
|
571
1081
|
listBox.replaceChildren();
|
|
572
1082
|
const kw = keyword.trim().toLowerCase();
|
|
573
1083
|
recommendBox.replaceChildren();
|
|
574
|
-
const recommendations = [...new Set(data.recommendationIds ?? [])].map((id) => data.places.find((p) => p.id === id && p.state !==
|
|
575
|
-
if (!kw && quickFilter ===
|
|
576
|
-
recommendBox.appendChild(
|
|
577
|
-
recommendBox.appendChild(
|
|
578
|
-
recommendBox.appendChild(
|
|
579
|
-
const selected = expanded === p.id && expandedOrigin ===
|
|
580
|
-
const
|
|
581
|
-
if (selected)
|
|
582
|
-
return
|
|
1084
|
+
const recommendations = [...new Set(data.recommendationIds ?? [])].map((id) => data.places.find((p) => p.id === id && p.state !== "closed")).filter(Boolean).slice(0, 3);
|
|
1085
|
+
if (!kw && quickFilter === "全部" && recommendations.length) {
|
|
1086
|
+
recommendBox.appendChild(el2("h3", { text: "此刻可以看看" }));
|
|
1087
|
+
recommendBox.appendChild(el2("p", { class: "fun-note", text: "几处开着的地方,点开只看细节;出发与选择仍由她自己决定。" }));
|
|
1088
|
+
recommendBox.appendChild(el2("div", { class: "fun-recommend-grid" }, recommendations.map((p) => {
|
|
1089
|
+
const selected = expanded === p.id && expandedOrigin === "recommend";
|
|
1090
|
+
const cell2 = el2("div", { class: selected ? "fun-cell fun-cell-open" : "fun-cell" }, card(p, true));
|
|
1091
|
+
if (selected) cell2.appendChild(detail(p));
|
|
1092
|
+
return cell2;
|
|
583
1093
|
})));
|
|
584
1094
|
}
|
|
585
1095
|
const filtered = data.places.filter((p) => {
|
|
586
1096
|
const tags = p.tags ?? [];
|
|
587
|
-
if (quickFilter ===
|
|
588
|
-
if (quickFilter ===
|
|
589
|
-
if (quickFilter ===
|
|
590
|
-
if (quickFilter ===
|
|
591
|
-
if (quickFilter ===
|
|
1097
|
+
if (quickFilter === "现在开着") return p.state !== "closed";
|
|
1098
|
+
if (quickFilter === "我的地点") return p.userVenue;
|
|
1099
|
+
if (quickFilter === "室内") return tags.some((tag) => tag.includes("室内"));
|
|
1100
|
+
if (quickFilter === "户外") return tags.some((tag) => /户外|室外/.test(tag));
|
|
1101
|
+
if (quickFilter === "夜游") return tags.some((tag) => /夜/.test(tag));
|
|
592
1102
|
return true;
|
|
593
1103
|
});
|
|
594
|
-
const matched = kw
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|| p.tags.some((t) => t.toLowerCase().includes(kw)))
|
|
598
|
-
: filtered;
|
|
599
|
-
|
|
600
|
-
const open = matched.filter((p) => p.state !== 'closed');
|
|
601
|
-
const closed = matched.filter((p) => p.state === 'closed');
|
|
602
|
-
|
|
603
|
-
/** 一格里画卡;展开时它后面紧跟一条详情,并且这一格跨满整行。 */
|
|
1104
|
+
const matched = kw ? filtered.filter((p) => p.name.toLowerCase().includes(kw) || p.aliases.some((a) => a.toLowerCase().includes(kw)) || p.tags.some((t) => t.toLowerCase().includes(kw))) : filtered;
|
|
1105
|
+
const open = matched.filter((p) => p.state !== "closed");
|
|
1106
|
+
const closed = matched.filter((p) => p.state === "closed");
|
|
604
1107
|
const cell = (p) => {
|
|
605
|
-
const isOpen = expanded === p.id && expandedOrigin ===
|
|
606
|
-
const wrap =
|
|
1108
|
+
const isOpen = expanded === p.id && expandedOrigin === "list";
|
|
1109
|
+
const wrap = el2("div", { class: isOpen ? "fun-cell fun-cell-open" : "fun-cell" });
|
|
607
1110
|
wrap.appendChild(card(p));
|
|
608
1111
|
if (isOpen) wrap.appendChild(detail(p));
|
|
609
1112
|
return wrap;
|
|
610
1113
|
};
|
|
611
|
-
|
|
612
1114
|
const section = (title, items) => {
|
|
613
1115
|
if (!items.length) return;
|
|
614
|
-
listBox.appendChild(
|
|
615
|
-
listBox.appendChild(
|
|
1116
|
+
listBox.appendChild(el2("div", { class: "fun-sec", text: title }));
|
|
1117
|
+
listBox.appendChild(el2("div", { class: "fun-grid" }, items.map(cell)));
|
|
616
1118
|
};
|
|
617
|
-
section(kw || quickFilter !==
|
|
618
|
-
section(
|
|
1119
|
+
section(kw || quickFilter !== "全部" ? `筛选结果 · 开着的(${open.length})` : `开着的(${open.length})`, open);
|
|
1120
|
+
section("已经关了", closed);
|
|
619
1121
|
if (!matched.length) {
|
|
620
|
-
listBox.appendChild(
|
|
1122
|
+
listBox.appendChild(el2("div", { class: "fun-empty", text: kw ? `没有匹配「${keyword}」的地方,试试其他筛选。` : "这个筛选下还没有地方,换一项看看。" }));
|
|
621
1123
|
}
|
|
622
1124
|
}
|
|
623
|
-
|
|
624
1125
|
const card = (p, recommended = false) => {
|
|
625
|
-
const selected = expanded === p.id && expandedOrigin === (recommended ?
|
|
626
|
-
const cls = [recommended ?
|
|
627
|
-
if (p.state ===
|
|
628
|
-
else if (p.state ===
|
|
629
|
-
else cls.push(
|
|
630
|
-
if (selected) cls.push(
|
|
631
|
-
const stateCls = p.state ===
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
ev.
|
|
644
|
-
|
|
1126
|
+
const selected = expanded === p.id && expandedOrigin === (recommended ? "recommend" : "list");
|
|
1127
|
+
const cls = [recommended ? "fun-recommend-card" : "fun-card"];
|
|
1128
|
+
if (p.state === "closed") cls.push("fun-card-closed");
|
|
1129
|
+
else if (p.state === "closingSoon") cls.push("fun-card-soon");
|
|
1130
|
+
else cls.push("fun-card-open");
|
|
1131
|
+
if (selected) cls.push("fun-card-active");
|
|
1132
|
+
const stateCls = p.state === "open" ? "fun-card-state-open" : p.state === "closingSoon" ? "fun-card-state-soon" : "";
|
|
1133
|
+
const node = el2(
|
|
1134
|
+
"div",
|
|
1135
|
+
{
|
|
1136
|
+
class: cls.join(" "),
|
|
1137
|
+
role: "button",
|
|
1138
|
+
tabindex: "0",
|
|
1139
|
+
"aria-expanded": selected ? "true" : "false",
|
|
1140
|
+
"aria-label": `${p.name},${p.stateLabel},查看详情`,
|
|
1141
|
+
"data-place-id": p.id,
|
|
1142
|
+
onclick: () => toggle(p.id, recommended),
|
|
1143
|
+
onkeydown: (ev) => {
|
|
1144
|
+
if (ev.key === "Enter" || ev.key === " " || ev.key === "Spacebar") {
|
|
1145
|
+
ev.preventDefault?.();
|
|
1146
|
+
toggle(p.id, recommended, true);
|
|
1147
|
+
}
|
|
645
1148
|
}
|
|
646
1149
|
},
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
1150
|
+
sceneArt(p),
|
|
1151
|
+
el2(
|
|
1152
|
+
"div",
|
|
1153
|
+
{ class: "fun-card-head" },
|
|
1154
|
+
el2("span", { class: recommended ? "fun-recommend-name" : "fun-card-name", text: p.name }),
|
|
1155
|
+
p.phase ? el2("span", { class: "fun-chip fun-chip-phase", text: p.phase }) : null,
|
|
1156
|
+
el2("span", { class: `fun-card-state ${stateCls}`, text: p.stateLabel }),
|
|
1157
|
+
el2("span", { class: "fun-card-arrow", text: selected ? "⌃" : "⌄" })
|
|
1158
|
+
),
|
|
1159
|
+
recommended ? el2("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,
|
|
1160
|
+
recommended ? null : el2("div", { class: "fun-card-desc", text: p.desc }),
|
|
1161
|
+
!recommended && p.wishReason ? el2("div", { class: "fun-meta", text: p.wishReason }) : null,
|
|
1162
|
+
!recommended && p.revisitReason ? el2("div", { class: "fun-meta", text: p.revisitReason }) : null,
|
|
1163
|
+
el2(
|
|
1164
|
+
"div",
|
|
1165
|
+
{ class: "fun-card-foot" },
|
|
1166
|
+
el2("span", { text: `${p.hours.open}–${p.hours.close}` }),
|
|
1167
|
+
el2("span", { text: p.crowdLabel }),
|
|
1168
|
+
el2("span", { text: `${p.areaCount} 处可逛` }),
|
|
1169
|
+
p.food ? el2("span", { class: "fun-chip fun-chip-ate", text: p.food.verb === "喝" ? "能喝" : "能吃" }) : null,
|
|
1170
|
+
p.visitCount > 0 ? el2("span", { class: "fun-chip", text: `去过 ${p.visitCount} 次` }) : null,
|
|
1171
|
+
p.recent ? el2("span", { class: "fun-chip", text: "刚去过" }) : null
|
|
1172
|
+
)
|
|
1173
|
+
);
|
|
665
1174
|
return node;
|
|
666
1175
|
};
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
* 开合一张卡。
|
|
670
|
-
*
|
|
671
|
-
* 重画之后把刚展开的那一块滚进视野——否则点上面第一张、展开的内容在下面一屏以外,
|
|
672
|
-
* 用户会以为自己点错了。`block: 'nearest'` 保证「已经看得见就不动」,
|
|
673
|
-
* 不会因为点一张本来就在屏幕里的卡而把页面跳一下。
|
|
674
|
-
*/
|
|
675
1176
|
function toggle(id, recommended = false, keyboard = false) {
|
|
676
|
-
const origin = recommended ?
|
|
1177
|
+
const origin = recommended ? "recommend" : "list";
|
|
677
1178
|
const wasOpen = expanded === id && expandedOrigin === origin;
|
|
678
1179
|
expanded = wasOpen ? null : id;
|
|
679
1180
|
expandedOrigin = origin;
|
|
680
1181
|
renderList();
|
|
681
|
-
if (keyboard) [...(recommended ? recommendBox : listBox).querySelectorAll(recommended ?
|
|
682
|
-
.find((node) => node.getAttribute('data-place-id') === id)?.focus?.();
|
|
1182
|
+
if (keyboard) [...(recommended ? recommendBox : listBox).querySelectorAll(recommended ? ".fun-recommend-card" : ".fun-card")].find((node) => node.getAttribute("data-place-id") === id)?.focus?.();
|
|
683
1183
|
if (!wasOpen) {
|
|
684
|
-
|
|
685
|
-
// 卡片恰好贴在视口底部时,只保证卡片可见等于详情还在屏幕外。
|
|
686
|
-
const active = (recommended ? recommendBox : listBox).querySelector('.fun-card-active');
|
|
1184
|
+
const active = (recommended ? recommendBox : listBox).querySelector(".fun-card-active");
|
|
687
1185
|
const target = active?.parentNode ?? active;
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
target.scrollIntoView({ block: 'nearest', behavior: 'auto' });
|
|
1186
|
+
if (target && typeof target.scrollIntoView === "function") {
|
|
1187
|
+
target.scrollIntoView({ block: "nearest", behavior: "auto" });
|
|
691
1188
|
}
|
|
692
1189
|
}
|
|
693
1190
|
}
|
|
694
|
-
|
|
695
1191
|
const detail = (p) => {
|
|
696
|
-
const d =
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
1192
|
+
const d = el2(
|
|
1193
|
+
"div",
|
|
1194
|
+
{ class: "fun-detail" },
|
|
1195
|
+
el2(
|
|
1196
|
+
"div",
|
|
1197
|
+
{ class: "fun-detail-top" },
|
|
1198
|
+
el2(
|
|
1199
|
+
"h4",
|
|
1200
|
+
{ text: p.name },
|
|
1201
|
+
p.overridden ? el2("span", { class: "fun-chip fun-chip-on", text: "已改", style: { marginLeft: "6px" } }) : null
|
|
1202
|
+
),
|
|
1203
|
+
el2(
|
|
1204
|
+
"div",
|
|
1205
|
+
{ class: "fun-detail-actions" },
|
|
701
1206
|
// B 阶段起预设也能编辑:改的是覆盖层,预设常量不动。
|
|
702
|
-
|
|
703
|
-
class:
|
|
704
|
-
type:
|
|
1207
|
+
el2("button", {
|
|
1208
|
+
class: "fun-detail-edit",
|
|
1209
|
+
type: "button",
|
|
705
1210
|
onclick: (ev) => {
|
|
706
1211
|
ev?.stopPropagation?.();
|
|
707
|
-
editing = { mode:
|
|
708
|
-
formError =
|
|
1212
|
+
editing = { mode: "edit", venue: p };
|
|
1213
|
+
formError = "";
|
|
709
1214
|
renderAll();
|
|
710
|
-
}
|
|
711
|
-
},
|
|
712
|
-
|
|
713
|
-
class:
|
|
714
|
-
type:
|
|
715
|
-
title:
|
|
1215
|
+
}
|
|
1216
|
+
}, "编辑"),
|
|
1217
|
+
el2("button", {
|
|
1218
|
+
class: "fun-detail-close",
|
|
1219
|
+
type: "button",
|
|
1220
|
+
title: "收起",
|
|
716
1221
|
onclick: (ev) => {
|
|
717
|
-
// 卡片自己也绑了 onclick:不拦住的话会先收起再被卡片重新展开。
|
|
718
1222
|
ev?.stopPropagation?.();
|
|
719
1223
|
expanded = null;
|
|
720
1224
|
renderList();
|
|
721
|
-
}
|
|
722
|
-
},
|
|
1225
|
+
}
|
|
1226
|
+
}, "收起")
|
|
1227
|
+
)
|
|
1228
|
+
),
|
|
723
1229
|
sceneArt(p, true),
|
|
724
|
-
|
|
1230
|
+
el2("p", { class: "fun-dim", text: `${p.kindLabel} · ${p.crowdLabel} · ${p.hours.open}–${p.hours.close} · ${p.stateLabel}` }),
|
|
725
1231
|
// 此刻的那段描写:有阶段的场所显示的是「这会儿的样子」,不是通用那段。
|
|
726
|
-
|
|
1232
|
+
el2("p", { class: "fun-detail-desc", text: p.desc }),
|
|
727
1233
|
// 时段一览:让她和主人都看得出「换个时间来是另一副样子」。
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
|
|
1234
|
+
p.phases && p.phases.length > 1 ? el2(
|
|
1235
|
+
"div",
|
|
1236
|
+
{},
|
|
1237
|
+
el2("div", { class: "fun-sec", text: "不同时段" }),
|
|
1238
|
+
el2("div", { class: "fun-phases" }, p.phases.map((ph) => el2("span", {
|
|
1239
|
+
class: ph.label === p.phase ? "fun-chip fun-chip-phase fun-chip-on" : "fun-chip",
|
|
1240
|
+
title: `${ph.from}–${ph.to}`,
|
|
1241
|
+
text: `${ph.label} ${ph.from}–${ph.to}`
|
|
1242
|
+
})))
|
|
1243
|
+
) : null,
|
|
737
1244
|
// 三块并成一排:能逛的 / 纪念品 / 拍照点,省纵向高度(原来三个小节摞起来很高)。
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
1245
|
+
el2(
|
|
1246
|
+
"div",
|
|
1247
|
+
{ class: "fun-detail-cols" },
|
|
1248
|
+
el2(
|
|
1249
|
+
"div",
|
|
1250
|
+
{ class: "fun-detail-col" },
|
|
1251
|
+
el2("div", { class: "fun-sec", text: "能逛的" }),
|
|
1252
|
+
el2("ul", { class: "fun-list" }, p.areas.map((a) => el2("li", { text: a })))
|
|
1253
|
+
),
|
|
1254
|
+
el2(
|
|
1255
|
+
"div",
|
|
1256
|
+
{ class: "fun-detail-col" },
|
|
1257
|
+
el2("div", { class: "fun-sec", text: "纪念品" }),
|
|
1258
|
+
el2("div", { class: "fun-chips" }, p.souvenirs.map((s) => el2("span", { class: "fun-chip" }, itemIcon(s), s))),
|
|
1259
|
+
el2("div", { class: "fun-sec", text: "拍照点" }),
|
|
1260
|
+
el2("div", { class: "fun-chips" }, p.photoSpots.map((s) => el2("span", { class: "fun-chip", text: s }))),
|
|
1261
|
+
p.food ? el2(
|
|
1262
|
+
"div",
|
|
1263
|
+
{},
|
|
1264
|
+
el2("div", { class: "fun-sec", text: `能${p.food.verb}的` }),
|
|
1265
|
+
el2("div", { class: "fun-chips" }, p.food.items.map((s) => el2("span", { class: "fun-chip", text: s }))),
|
|
1266
|
+
el2("div", { class: "fun-note", text: `味道不在这儿——装了「鱼的每一天」才有九维口感,没装就只知道${p.food.verb}了什么。` })
|
|
1267
|
+
) : null
|
|
1268
|
+
)
|
|
1269
|
+
),
|
|
1270
|
+
el2(
|
|
1271
|
+
"div",
|
|
1272
|
+
{ class: "fun-scene" },
|
|
1273
|
+
p.hasScene ? el2("span", {}, "生图时 ", el2("b", { text: `scene 填「${p.scene}」` }), `,outfits 建议「${p.outfit}」`) : el2("span", {}, "素材库里没有这处的场景,生图时 ", el2("b", { text: "scene 不用填" }), ",把地方写进 prompt 就行")
|
|
1274
|
+
)
|
|
1275
|
+
);
|
|
758
1276
|
d.appendChild(historyView(p.id));
|
|
759
1277
|
return d;
|
|
760
1278
|
};
|
|
761
|
-
|
|
762
|
-
// ---- 地点表单(自填新建 / 自填编辑 / 预设编辑三态)----
|
|
763
|
-
// 放在 render 内部:能直接拿到当前 data 与 editing,保存后整体重画一次即可。
|
|
764
1279
|
function venueForm() {
|
|
765
1280
|
const v = editing.venue ?? {};
|
|
766
|
-
// 预设编辑:改的是覆盖层,不删场所;没改过的字段仍跟着预设升级走。
|
|
767
1281
|
const isPreset = Boolean(v.id) && !v.userVenue;
|
|
768
1282
|
const phases = isPreset && Array.isArray(v.phases) ? v.phases : [];
|
|
769
1283
|
const descPhases = phases.filter((ph) => ph.overridesDesc);
|
|
770
1284
|
const areaPhases = phases.filter((ph) => ph.overridesAreas);
|
|
771
|
-
const phaseNames = (items) => items.map((ph) => `${ph.label} ${ph.from}–${ph.to}`).join(
|
|
772
|
-
const scopeNote = (items, noun) => items.length
|
|
773
|
-
|
|
774
|
-
: '';
|
|
775
|
-
const verb = v.food?.verb ?? 'none';
|
|
1285
|
+
const phaseNames = (items) => items.map((ph) => `${ph.label} ${ph.from}–${ph.to}`).join("、");
|
|
1286
|
+
const scopeNote = (items, noun) => items.length ? `通用${noun}会保存;在${phaseNames(items)}使用预设时段${noun},未命中这些时段时才使用这里的内容。保存不会同步修改时段。` : "";
|
|
1287
|
+
const verb = v.food?.verb ?? "none";
|
|
776
1288
|
const foodItems = v.food?.items ?? [];
|
|
777
|
-
const errorNode =
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
let input;
|
|
1289
|
+
const errorNode = el2("div", { class: "fun-form-error", text: formError });
|
|
1290
|
+
const field = (label2, key, opts = {}) => {
|
|
1291
|
+
const { type = "text", value = "", hint = "", note: note2 = "", multiline = false, options = null, rows = "3" } = opts;
|
|
1292
|
+
let input2;
|
|
782
1293
|
if (options) {
|
|
783
|
-
|
|
784
|
-
for (const [val, lab] of options)
|
|
785
|
-
|
|
1294
|
+
input2 = el2("select", {});
|
|
1295
|
+
for (const [val, lab] of options) input2.appendChild(el2("option", { value: val, text: lab }));
|
|
1296
|
+
input2.value = value;
|
|
786
1297
|
} else if (multiline) {
|
|
787
|
-
|
|
788
|
-
|
|
1298
|
+
input2 = el2("textarea", { rows, placeholder: hint });
|
|
1299
|
+
input2.value = value;
|
|
789
1300
|
} else {
|
|
790
|
-
|
|
791
|
-
|
|
1301
|
+
input2 = el2("input", { type, placeholder: hint });
|
|
1302
|
+
input2.value = value;
|
|
792
1303
|
}
|
|
793
|
-
fields[key] =
|
|
794
|
-
return
|
|
795
|
-
|
|
796
|
-
|
|
1304
|
+
fields[key] = input2;
|
|
1305
|
+
return el2(
|
|
1306
|
+
"label",
|
|
1307
|
+
{ class: "fun-field" },
|
|
1308
|
+
el2("span", { class: "fun-field-label", text: label2 }),
|
|
1309
|
+
input2,
|
|
1310
|
+
note2 ? el2("span", { class: "fun-field-scope fun-note", text: note2 }) : null
|
|
1311
|
+
);
|
|
797
1312
|
};
|
|
798
|
-
|
|
799
1313
|
const save = async () => {
|
|
800
1314
|
const payload = {
|
|
801
|
-
...
|
|
1315
|
+
...v.id ? { id: v.id } : {},
|
|
802
1316
|
name: fields.name.value.trim(),
|
|
803
1317
|
aliases: parseLines(fields.aliases.value),
|
|
804
1318
|
tags: parseLines(fields.tags.value),
|
|
@@ -809,23 +1323,22 @@ function mountPlaces(ctx) {
|
|
|
809
1323
|
areas: parseLines(fields.areas.value),
|
|
810
1324
|
souvenirs: parseLines(fields.souvenirs.value),
|
|
811
1325
|
photoSpots: parseLines(fields.photoSpots.value),
|
|
812
|
-
randomEvents: parseLines(fields.randomEvents.value)
|
|
1326
|
+
randomEvents: parseLines(fields.randomEvents.value)
|
|
813
1327
|
};
|
|
814
1328
|
const foodVerb = fields.foodVerb.value;
|
|
815
|
-
if (foodVerb && foodVerb !==
|
|
816
|
-
payload.food = { verb: foodVerb ===
|
|
1329
|
+
if (foodVerb && foodVerb !== "none") {
|
|
1330
|
+
payload.food = { verb: foodVerb === "drink" ? "喝" : "吃", items: parseLines(fields.foodItems.value) };
|
|
817
1331
|
}
|
|
818
1332
|
try {
|
|
819
|
-
const r = await ctx.invoke(
|
|
1333
|
+
const r = await ctx.invoke("save", [payload]);
|
|
820
1334
|
if (!r?.ok) {
|
|
821
|
-
|
|
822
|
-
formError = r?.error ?? '存不下来';
|
|
1335
|
+
formError = r?.error ?? "存不下来";
|
|
823
1336
|
errorNode.textContent = formError;
|
|
824
1337
|
return;
|
|
825
1338
|
}
|
|
826
1339
|
editing = null;
|
|
827
|
-
formError =
|
|
828
|
-
keyword =
|
|
1340
|
+
formError = "";
|
|
1341
|
+
keyword = "";
|
|
829
1342
|
expanded = null;
|
|
830
1343
|
await load();
|
|
831
1344
|
} catch (err) {
|
|
@@ -833,17 +1346,17 @@ function mountPlaces(ctx) {
|
|
|
833
1346
|
errorNode.textContent = formError;
|
|
834
1347
|
}
|
|
835
1348
|
};
|
|
836
|
-
|
|
837
1349
|
const remove = async () => {
|
|
838
1350
|
if (!v.id) return;
|
|
839
1351
|
try {
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
1352
|
+
const r = isPreset ? await ctx.invoke("reset", [{ id: v.id }]) : await ctx.invoke("remove", [{ id: v.id }]);
|
|
1353
|
+
if (!r?.ok) {
|
|
1354
|
+
formError = r?.error ?? "操作没成";
|
|
1355
|
+
errorNode.textContent = formError;
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
845
1358
|
editing = null;
|
|
846
|
-
formError =
|
|
1359
|
+
formError = "";
|
|
847
1360
|
expanded = null;
|
|
848
1361
|
await load();
|
|
849
1362
|
} catch (err) {
|
|
@@ -851,75 +1364,85 @@ function mountPlaces(ctx) {
|
|
|
851
1364
|
errorNode.textContent = formError;
|
|
852
1365
|
}
|
|
853
1366
|
};
|
|
854
|
-
|
|
855
|
-
const
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
}))) : null,
|
|
1367
|
+
const title = editing.mode === "new" ? "添加一处自己的地方" : isPreset ? `编辑预设:${v.name}` : `编辑:${v.name}`;
|
|
1368
|
+
const note = isPreset ? "改的是「覆盖层」,预设本身不动:只存你真改过的字段,以后预设升级的新内容照样能拿到。时段分段(不同时段不一样)不在这里改;想还原就点「恢复预设」。名字别改成另一处预设的正名。" : "只写名字和「能逛的」就能用;别的留空也行。一行一条。";
|
|
1369
|
+
return el2(
|
|
1370
|
+
"div",
|
|
1371
|
+
{ class: "fun-form" },
|
|
1372
|
+
el2("div", { class: "fun-form-title", text: title }),
|
|
1373
|
+
el2("div", { class: "fun-form-note", text: note }),
|
|
1374
|
+
phases.length ? el2(
|
|
1375
|
+
"div",
|
|
1376
|
+
{ class: "fun-form-phases" },
|
|
1377
|
+
el2("div", { class: "fun-form-note", text: `现在 ${data.nowHm} · ${v.phase ? `当前阶段:${v.phase}` : "当前未命中预设时段,使用通用内容"}。编辑通用字段不会改变以下预设时段及其内容;修改营业时间也不会移动这些时段。` }),
|
|
1378
|
+
el2("ul", { class: "fun-list" }, phases.map((ph) => {
|
|
1379
|
+
const covered = [ph.overridesDesc ? "描写(desc)" : "", ph.overridesAreas ? "能逛的(areas)" : ""].filter(Boolean);
|
|
1380
|
+
return el2("li", { text: `${ph.label} ${ph.from}–${ph.to}${ph.label === v.phase ? "(当前)" : ""}:${covered.length ? `覆盖通用${covered.join("、")}` : "沿用通用描写与可逛清单"}` });
|
|
1381
|
+
}))
|
|
1382
|
+
) : null,
|
|
871
1383
|
errorNode,
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
field(
|
|
876
|
-
field(
|
|
877
|
-
field(
|
|
878
|
-
field(
|
|
879
|
-
field(
|
|
880
|
-
|
|
881
|
-
|
|
1384
|
+
el2(
|
|
1385
|
+
"div",
|
|
1386
|
+
{ class: "fun-form-grid" },
|
|
1387
|
+
field("名字 *", "name", { value: v.name ?? "", hint: "例如「巷子里的旧书店」" }),
|
|
1388
|
+
field("别名", "aliases", { value: lines(v.aliases), hint: "一行一个,可选" }),
|
|
1389
|
+
field("标签", "tags", { value: lines(v.tags), hint: "室内 / 夜 / 免费… 一行一个" }),
|
|
1390
|
+
field("推荐穿搭", "outfit", { value: v.recommendedOutfit ?? "", hint: "可选,例如「外出外套」" }),
|
|
1391
|
+
field("开门时间", "open", { value: v.hours?.open ?? "09:00", hint: "HH:MM" }),
|
|
1392
|
+
field("关门时间", "close", { value: v.hours?.close ?? "21:00", hint: "HH:MM" }),
|
|
1393
|
+
field("人多不多", "crowd", {
|
|
1394
|
+
value: v.crowd ?? "normal",
|
|
1395
|
+
options: [["quiet", "人不多"], ["normal", "人不算多"], ["packed", "人很多"]]
|
|
882
1396
|
}),
|
|
883
|
-
field(
|
|
884
|
-
value: verb ===
|
|
885
|
-
options: [[
|
|
886
|
-
})
|
|
1397
|
+
field("能吃能喝", "foodVerb", {
|
|
1398
|
+
value: verb === "喝" ? "drink" : verb === "吃" ? "eat" : "none",
|
|
1399
|
+
options: [["none", "没有"], ["drink", "喝的"], ["eat", "吃的"]]
|
|
1400
|
+
})
|
|
1401
|
+
),
|
|
887
1402
|
// 预设可能带时段:面板的 desc 是「此刻那段」,编辑要用通用那段(descAll),
|
|
888
1403
|
// 否则编辑一次会把某一段的描写写进覆盖层,别的时段全变成那一段。
|
|
889
|
-
field(phases.length ?
|
|
890
|
-
field(phases.length ?
|
|
891
|
-
field(
|
|
892
|
-
field(
|
|
893
|
-
field(
|
|
894
|
-
field(
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1404
|
+
field(phases.length ? "通用描写(desc)" : "这处是什么样子", "desc", { value: v.descAll ?? v.desc ?? "", hint: "只写空间与陈设,别写她在干什么", note: scopeNote(descPhases, "描写"), multiline: true, rows: "3" }),
|
|
1405
|
+
field(phases.length ? "通用可逛清单(areas)*" : "能逛的 *", "areas", { value: lines(v.allAreas ?? v.areas), hint: "一行一处,至少一处", note: scopeNote(areaPhases, "可逛清单"), multiline: true, rows: "4" }),
|
|
1406
|
+
field("纪念品", "souvenirs", { value: lines(v.souvenirs), hint: "一行一样", multiline: true, rows: "2" }),
|
|
1407
|
+
field("拍照点", "photoSpots", { value: lines(v.photoSpots), hint: "一行一处", multiline: true, rows: "2" }),
|
|
1408
|
+
field("能吃能喝的品类", "foodItems", { value: lines(foodItems), hint: "品类名,一行一样;别写味道", multiline: true, rows: "2" }),
|
|
1409
|
+
field("可能碰上的小事", "randomEvents", { value: lines(v.randomEvents), hint: "一行一条,可选", multiline: true, rows: "2" }),
|
|
1410
|
+
el2(
|
|
1411
|
+
"div",
|
|
1412
|
+
{ class: "fun-form-actions" },
|
|
1413
|
+
el2("button", { class: "fun-btn-primary", type: "button", onclick: save }, "保存"),
|
|
1414
|
+
v.id ? el2(
|
|
1415
|
+
"button",
|
|
1416
|
+
{ class: "fun-danger", type: "button", onclick: remove },
|
|
1417
|
+
isPreset ? "恢复预设" : "删除这处"
|
|
1418
|
+
) : null,
|
|
1419
|
+
el2("button", {
|
|
1420
|
+
type: "button",
|
|
901
1421
|
onclick: () => {
|
|
902
1422
|
editing = null;
|
|
903
|
-
formError =
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1423
|
+
formError = "";
|
|
1424
|
+
if (currentData) {
|
|
1425
|
+
render(currentData);
|
|
1426
|
+
currentData = null;
|
|
1427
|
+
} else renderAll();
|
|
1428
|
+
}
|
|
1429
|
+
}, "取消")
|
|
1430
|
+
)
|
|
1431
|
+
);
|
|
909
1432
|
}
|
|
910
|
-
|
|
911
1433
|
renderList();
|
|
912
1434
|
restoreFocus();
|
|
913
1435
|
};
|
|
914
|
-
|
|
915
1436
|
const load = async () => {
|
|
916
1437
|
const sequence = ++loadSequence;
|
|
917
1438
|
try {
|
|
918
|
-
const data = await ctx.invoke(
|
|
1439
|
+
const data = await ctx.invoke("list");
|
|
919
1440
|
if (sequence !== loadSequence || ctx.signal?.aborted) return;
|
|
920
|
-
if (!data?.ok) throw new Error(data?.error ??
|
|
921
|
-
|
|
922
|
-
|
|
1441
|
+
if (!data?.ok) throw new Error(data?.error ?? "返回不正常");
|
|
1442
|
+
if (editing) {
|
|
1443
|
+
currentData = data;
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
923
1446
|
status.replaceChildren();
|
|
924
1447
|
render(data);
|
|
925
1448
|
} catch (err) {
|
|
@@ -928,7 +1451,6 @@ function mountPlaces(ctx) {
|
|
|
928
1451
|
status.replaceChildren(errorCard(err, load, Boolean(currentData)));
|
|
929
1452
|
}
|
|
930
1453
|
};
|
|
931
|
-
|
|
932
1454
|
async function resolveDraft(method, id) {
|
|
933
1455
|
if (outingAction) return;
|
|
934
1456
|
outingAction = method;
|
|
@@ -936,149 +1458,179 @@ function mountPlaces(ctx) {
|
|
|
936
1458
|
render(currentData);
|
|
937
1459
|
try {
|
|
938
1460
|
const result = await ctx.invoke(method, [{ id }]);
|
|
939
|
-
if (!result?.ok) throw new Error(result?.error ??
|
|
940
|
-
notice = { text: result.text ||
|
|
941
|
-
// 写操作已成功,刷新失败时也不重新启用这张旧草稿的按钮。
|
|
1461
|
+
if (!result?.ok) throw new Error(result?.error ?? "行程更新失败");
|
|
1462
|
+
notice = { text: result.text || "行程已更新。" };
|
|
942
1463
|
currentData = { ...currentData, draft: null };
|
|
943
1464
|
} catch (err) {
|
|
944
1465
|
notice = { text: err?.message ?? String(err), error: true };
|
|
945
1466
|
} finally {
|
|
946
|
-
outingAction =
|
|
1467
|
+
outingAction = "";
|
|
947
1468
|
if (ctx.signal?.aborted) return;
|
|
948
1469
|
render(currentData);
|
|
949
1470
|
await load();
|
|
950
|
-
body.querySelector(
|
|
1471
|
+
body.querySelector(".fun-outing-result")?.focus?.();
|
|
951
1472
|
}
|
|
952
1473
|
}
|
|
953
|
-
|
|
954
1474
|
void load();
|
|
955
|
-
|
|
956
|
-
|
|
1475
|
+
ctx.interval(() => {
|
|
1476
|
+
void load();
|
|
1477
|
+
}, 6e4);
|
|
957
1478
|
return { refresh: load };
|
|
958
1479
|
}
|
|
959
|
-
|
|
960
|
-
// ---------------------------------------------------------------------------
|
|
961
|
-
// book —— 纪念册
|
|
962
|
-
// ---------------------------------------------------------------------------
|
|
963
|
-
|
|
964
1480
|
function mountBook(ctx) {
|
|
965
1481
|
const root = ctx.root;
|
|
966
1482
|
root.replaceChildren();
|
|
967
1483
|
const box = shell(root);
|
|
968
|
-
const body =
|
|
1484
|
+
const body = el2("div");
|
|
969
1485
|
box.appendChild(body);
|
|
970
|
-
let bookTab =
|
|
971
|
-
let bookKeyword =
|
|
972
|
-
let bookPlace =
|
|
973
|
-
let bookDate =
|
|
1486
|
+
let bookTab = "all";
|
|
1487
|
+
let bookKeyword = "";
|
|
1488
|
+
let bookPlace = "";
|
|
1489
|
+
let bookDate = "";
|
|
974
1490
|
let wishFormOpen = false;
|
|
975
|
-
const expandedTrips = new Set();
|
|
976
|
-
const status =
|
|
977
|
-
body.appendChild(
|
|
978
|
-
const pending = new Set();
|
|
979
|
-
const errors = new Map();
|
|
1491
|
+
const expandedTrips = /* @__PURE__ */ new Set();
|
|
1492
|
+
const status = feedback2(box);
|
|
1493
|
+
body.appendChild(el2("div", { class: "fun-loading", role: "status", text: "正在翻开纪念册…" }));
|
|
1494
|
+
const pending = /* @__PURE__ */ new Set();
|
|
1495
|
+
const errors = /* @__PURE__ */ new Map();
|
|
980
1496
|
let currentData = null;
|
|
981
|
-
let wishDraft = { placeId:
|
|
982
|
-
const wishPending = new Set();
|
|
983
|
-
const wishErrors = new Map();
|
|
984
|
-
const wishTypes = { visit:
|
|
985
|
-
|
|
1497
|
+
let wishDraft = { placeId: "", type: "", target: "", reason: "" };
|
|
1498
|
+
const wishPending = /* @__PURE__ */ new Set();
|
|
1499
|
+
const wishErrors = /* @__PURE__ */ new Map();
|
|
1500
|
+
const wishTypes = { visit: "去看看", area: "逛一处", phase: "在某个时段去", souvenir: "带回纪念品" };
|
|
986
1501
|
const renderWishes = (data) => {
|
|
987
1502
|
const places = data.places ?? [];
|
|
988
1503
|
const wishes = data.wishes ?? [];
|
|
989
|
-
const adding = wishPending.has(
|
|
990
|
-
const section =
|
|
991
|
-
section.appendChild(
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1504
|
+
const adding = wishPending.has("add");
|
|
1505
|
+
const section = el2("section", { class: "fun-wishes", "aria-label": "出游心愿" });
|
|
1506
|
+
section.appendChild(el2(
|
|
1507
|
+
"div",
|
|
1508
|
+
{ class: "fun-bar" },
|
|
1509
|
+
el2("span", { class: "fun-sec", text: "出游心愿" }),
|
|
1510
|
+
el2("button", { type: "button", "aria-expanded": String(wishFormOpen), disabled: adding ? "disabled" : null, onclick: () => {
|
|
1511
|
+
wishFormOpen = !wishFormOpen;
|
|
1512
|
+
render(currentData);
|
|
1513
|
+
} }, wishFormOpen ? "收起表单" : "记个心愿")
|
|
1514
|
+
));
|
|
1515
|
+
const field = (label2, input) => el2(
|
|
1516
|
+
"label",
|
|
1517
|
+
{ class: "fun-field" },
|
|
1518
|
+
el2("span", { class: "fun-field-label", text: label2 }),
|
|
1519
|
+
input
|
|
1520
|
+
);
|
|
996
1521
|
const select = (className, placeholder, options, value) => {
|
|
997
|
-
const input =
|
|
998
|
-
|
|
999
|
-
|
|
1522
|
+
const input = el2(
|
|
1523
|
+
"select",
|
|
1524
|
+
{ class: className, disabled: adding ? "disabled" : null },
|
|
1525
|
+
el2("option", { value: "", text: placeholder }),
|
|
1526
|
+
options.map(([id, name]) => el2("option", { value: id, text: name }))
|
|
1527
|
+
);
|
|
1000
1528
|
input.value = value;
|
|
1001
1529
|
return input;
|
|
1002
1530
|
};
|
|
1003
1531
|
const place = places.find((p) => p.id === wishDraft.placeId);
|
|
1004
|
-
const targets = place ? (wishDraft.type ===
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
const
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1532
|
+
const targets = place ? (wishDraft.type === "area" ? place.areas : wishDraft.type === "phase" ? place.phaseNames : wishDraft.type === "souvenir" ? place.souvenirs : []) ?? [] : [];
|
|
1533
|
+
const placeInput = select("fun-wish-place", "请选择地点", places.map((p) => [p.id, p.name]), wishDraft.placeId);
|
|
1534
|
+
const typeInput = select("fun-wish-type", "请选择心愿类型", Object.entries(wishTypes), wishDraft.type);
|
|
1535
|
+
const targetInput = select(
|
|
1536
|
+
"fun-wish-target",
|
|
1537
|
+
wishDraft.type === "visit" ? "去看看无需目标" : !place || !wishDraft.type ? "先选择地点和类型" : targets.length ? "请选择目标" : "此地点没有可选目标",
|
|
1538
|
+
targets.map((target) => [target, target]),
|
|
1539
|
+
wishDraft.target
|
|
1540
|
+
);
|
|
1012
1541
|
targetInput.disabled = adding || !targets.length;
|
|
1013
|
-
const reasonInput =
|
|
1542
|
+
const reasonInput = el2("input", { class: "fun-wish-reason", type: "text", placeholder: "可选,记下为什么想去", disabled: adding ? "disabled" : null });
|
|
1014
1543
|
reasonInput.value = wishDraft.reason;
|
|
1015
|
-
placeInput.addEventListener(
|
|
1544
|
+
placeInput.addEventListener("change", () => {
|
|
1016
1545
|
wishDraft.placeId = placeInput.value;
|
|
1017
|
-
wishDraft.target =
|
|
1018
|
-
wishErrors.delete(
|
|
1546
|
+
wishDraft.target = "";
|
|
1547
|
+
wishErrors.delete("add");
|
|
1019
1548
|
render(currentData);
|
|
1020
1549
|
});
|
|
1021
|
-
typeInput.addEventListener(
|
|
1550
|
+
typeInput.addEventListener("change", () => {
|
|
1022
1551
|
wishDraft.type = typeInput.value;
|
|
1023
|
-
wishDraft.target =
|
|
1024
|
-
wishErrors.delete(
|
|
1552
|
+
wishDraft.target = "";
|
|
1553
|
+
wishErrors.delete("add");
|
|
1025
1554
|
render(currentData);
|
|
1026
1555
|
});
|
|
1027
|
-
targetInput.addEventListener(
|
|
1028
|
-
|
|
1029
|
-
|
|
1556
|
+
targetInput.addEventListener("change", () => {
|
|
1557
|
+
wishDraft.target = targetInput.value;
|
|
1558
|
+
});
|
|
1559
|
+
reasonInput.addEventListener("input", () => {
|
|
1560
|
+
wishDraft.reason = reasonInput.value;
|
|
1561
|
+
});
|
|
1562
|
+
const errorNode = el2("div", { class: "fun-form-error", role: "alert", text: wishErrors.get("add") ?? "" });
|
|
1030
1563
|
const save = async () => {
|
|
1031
|
-
if (wishPending.has(
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1564
|
+
if (wishPending.has("add")) return;
|
|
1565
|
+
const payload = {
|
|
1566
|
+
action: "add",
|
|
1567
|
+
placeId: placeInput.value,
|
|
1568
|
+
type: typeInput.value,
|
|
1569
|
+
target: typeInput.value === "visit" ? "" : targetInput.value,
|
|
1570
|
+
reason: reasonInput.value.trim()
|
|
1571
|
+
};
|
|
1035
1572
|
const chosenPlace = (currentData.places ?? []).find((p) => p.id === payload.placeId);
|
|
1036
|
-
const validTargets = chosenPlace ? (payload.type ===
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
const message = '请选择地点、心愿类型及对应目标。';
|
|
1041
|
-
wishErrors.set('add', message);
|
|
1573
|
+
const validTargets = chosenPlace ? (payload.type === "area" ? chosenPlace.areas : payload.type === "phase" ? chosenPlace.phaseNames : chosenPlace.souvenirs) ?? [] : [];
|
|
1574
|
+
if (!chosenPlace || !Object.hasOwn(wishTypes, payload.type) || payload.type !== "visit" && !validTargets.includes(payload.target)) {
|
|
1575
|
+
const message = "请选择地点、心愿类型及对应目标。";
|
|
1576
|
+
wishErrors.set("add", message);
|
|
1042
1577
|
errorNode.textContent = message;
|
|
1043
1578
|
return;
|
|
1044
1579
|
}
|
|
1045
1580
|
wishDraft = { placeId: payload.placeId, type: payload.type, target: payload.target, reason: reasonInput.value };
|
|
1046
|
-
await changeWish(
|
|
1581
|
+
await changeWish("add", payload, data);
|
|
1047
1582
|
};
|
|
1048
|
-
if (wishFormOpen) section.appendChild(
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1583
|
+
if (wishFormOpen) section.appendChild(el2(
|
|
1584
|
+
"div",
|
|
1585
|
+
{ class: "fun-form fun-wish-form" },
|
|
1586
|
+
el2("div", { class: "fun-form-note", text: "由你选择想去的地方,按保存才记下心愿;心愿不保证立即出发。" }),
|
|
1587
|
+
el2("div", { class: "fun-form-grid" }, field("地点", placeInput), field("心愿类型", typeInput), field("目标", targetInput)),
|
|
1588
|
+
field("缘由(可选)", reasonInput),
|
|
1589
|
+
errorNode,
|
|
1590
|
+
el2("button", { class: "fun-btn-primary", type: "button", disabled: adding ? "disabled" : null, onclick: save }, adding ? "保存中…" : "保存心愿")
|
|
1591
|
+
));
|
|
1592
|
+
if (!wishes.length) section.appendChild(el2("div", { class: "fun-note", text: "还没有出游心愿,想好了再记下。" }));
|
|
1593
|
+
const statusNames = { active: "待实现", paused: "已暂缓", completed: "已实现", cancelled: "已取消" };
|
|
1594
|
+
const history = el2("details", {
|
|
1595
|
+
class: "fun-wish-history",
|
|
1596
|
+
open: wishes.some((w) => w.status !== "active" && (wishErrors.has(`wish:${w.id}`) || wishPending.has(`wish:${w.id}`))) ? "open" : null
|
|
1597
|
+
}, el2("summary", { text: `已实现、暂缓与取消(${wishes.filter((w) => w.status !== "active").length})` }));
|
|
1058
1598
|
for (const wish of wishes) {
|
|
1059
1599
|
const key = `wish:${wish.id}`;
|
|
1060
1600
|
const busy = wishPending.has(key);
|
|
1061
1601
|
const state = wish.status;
|
|
1062
|
-
const actions =
|
|
1063
|
-
if (state ===
|
|
1064
|
-
actions.appendChild(
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
onclick: () => changeWish(key, { action:
|
|
1602
|
+
const actions = el2("div", { class: "fun-trip-actions" });
|
|
1603
|
+
if (state === "active" || state === "paused") {
|
|
1604
|
+
actions.appendChild(el2("button", {
|
|
1605
|
+
type: "button",
|
|
1606
|
+
disabled: busy ? "disabled" : null,
|
|
1607
|
+
onclick: () => changeWish(key, { action: state === "paused" ? "resume" : "pause", id: wish.id }, data)
|
|
1608
|
+
}, state === "paused" ? "恢复" : "暂缓"));
|
|
1609
|
+
actions.appendChild(el2("button", {
|
|
1610
|
+
type: "button",
|
|
1611
|
+
disabled: busy ? "disabled" : null,
|
|
1612
|
+
onclick: () => changeWish(key, { action: "cancel", id: wish.id }, data)
|
|
1613
|
+
}, "取消"));
|
|
1068
1614
|
}
|
|
1069
|
-
if (busy) actions.appendChild(
|
|
1070
|
-
if (wishErrors.has(key)) actions.appendChild(
|
|
1071
|
-
(state ===
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1615
|
+
if (busy) actions.appendChild(el2("span", { class: "fun-dim", text: "保存中…" }));
|
|
1616
|
+
if (wishErrors.has(key)) actions.appendChild(el2("span", { class: "fun-trip-error", role: "alert", text: wishErrors.get(key) }));
|
|
1617
|
+
(state === "active" ? section : history).appendChild(el2(
|
|
1618
|
+
"div",
|
|
1619
|
+
{ class: "fun-wish fun-trip" },
|
|
1620
|
+
el2(
|
|
1621
|
+
"div",
|
|
1622
|
+
{ class: "fun-trip-head" },
|
|
1623
|
+
el2("span", { class: "fun-trip-name", text: wish.placeName ?? places.find((p) => p.id === wish.placeId)?.name ?? wish.placeId }),
|
|
1624
|
+
el2("span", { class: "fun-wish-status fun-dim", text: statusNames[state] ?? state ?? "状态未知" })
|
|
1625
|
+
),
|
|
1626
|
+
el2("div", { class: "fun-trip-sum", text: `${wishTypes[wish.type] ?? wish.type}${wish.target ? ` · ${wish.target}` : ""}` }),
|
|
1627
|
+
wish.reason ? el2("div", { class: "fun-wish-note fun-note", text: `缘由:${wish.reason}` }) : null,
|
|
1628
|
+
actions
|
|
1629
|
+
));
|
|
1077
1630
|
}
|
|
1078
|
-
if (wishes.some((w) => w.status !==
|
|
1631
|
+
if (wishes.some((w) => w.status !== "active")) section.appendChild(history);
|
|
1079
1632
|
body.appendChild(section);
|
|
1080
1633
|
};
|
|
1081
|
-
|
|
1082
1634
|
const changeWish = async (key, payload, data) => {
|
|
1083
1635
|
if (wishPending.has(key)) return;
|
|
1084
1636
|
wishPending.add(key);
|
|
@@ -1086,140 +1638,225 @@ function mountBook(ctx) {
|
|
|
1086
1638
|
render(currentData ?? data);
|
|
1087
1639
|
let saved = false;
|
|
1088
1640
|
try {
|
|
1089
|
-
const result = await ctx.invoke(
|
|
1090
|
-
if (!result?.ok) throw new Error(result?.error ??
|
|
1641
|
+
const result = await ctx.invoke("wish", [payload]);
|
|
1642
|
+
if (!result?.ok) throw new Error(result?.error ?? "心愿保存失败");
|
|
1091
1643
|
saved = true;
|
|
1092
|
-
if (key ===
|
|
1644
|
+
if (key === "add") {
|
|
1645
|
+
wishDraft = { placeId: "", type: "", target: "", reason: "" };
|
|
1646
|
+
wishFormOpen = false;
|
|
1647
|
+
}
|
|
1093
1648
|
await load(true);
|
|
1094
1649
|
} catch (error) {
|
|
1095
|
-
wishErrors.set(key, `${saved ?
|
|
1096
|
-
if (key ===
|
|
1650
|
+
wishErrors.set(key, `${saved ? "已保存,但列表刷新失败:" : ""}${error?.message ?? String(error)}`);
|
|
1651
|
+
if (key === "add") wishFormOpen = true;
|
|
1097
1652
|
} finally {
|
|
1098
1653
|
wishPending.delete(key);
|
|
1099
1654
|
render(currentData ?? data);
|
|
1100
1655
|
}
|
|
1101
1656
|
};
|
|
1102
|
-
|
|
1103
1657
|
const render = (data) => {
|
|
1104
1658
|
const restoreFocus = rememberFocus(body);
|
|
1105
1659
|
currentData = data;
|
|
1106
|
-
body.replaceChildren(heading(
|
|
1107
|
-
if (data.session) body.appendChild(
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1660
|
+
body.replaceChildren(heading("纪念册", "把走过的地方,收成可以回看的小回忆。"));
|
|
1661
|
+
if (data.session) body.appendChild(el2(
|
|
1662
|
+
"div",
|
|
1663
|
+
{ class: "fun-live" },
|
|
1664
|
+
el2("h3", { text: "正在逛 · " + data.session.placeName }),
|
|
1665
|
+
el2("div", { class: "fun-trip-sum", text: data.session.summary })
|
|
1666
|
+
));
|
|
1667
|
+
else if (data.trips?.length) body.appendChild(el2(
|
|
1668
|
+
"div",
|
|
1669
|
+
{ class: "fun-live" },
|
|
1670
|
+
el2("div", { class: "fun-meta", text: "最近一趟 · " + data.trips[0].day }),
|
|
1671
|
+
el2("h3", { text: data.trips[0].placeName }),
|
|
1672
|
+
el2("div", { class: "fun-trip-sum", text: data.trips[0].summary })
|
|
1673
|
+
));
|
|
1674
|
+
const tabs = el2("nav", { class: "fun-tabs", "aria-label": "纪念册分类" });
|
|
1675
|
+
for (const [id, label2] of [["all", "全部行程"], ["kept", "珍藏"], ["wishes", "心愿"]]) tabs.appendChild(el2("button", {
|
|
1676
|
+
type: "button",
|
|
1677
|
+
"aria-pressed": String(bookTab === id),
|
|
1678
|
+
onclick: () => {
|
|
1679
|
+
bookTab = id;
|
|
1680
|
+
render(currentData);
|
|
1681
|
+
}
|
|
1682
|
+
}, label2));
|
|
1117
1683
|
body.appendChild(tabs);
|
|
1118
|
-
if (bookTab ===
|
|
1684
|
+
if (bookTab === "wishes") {
|
|
1685
|
+
renderWishes(data);
|
|
1686
|
+
restoreFocus();
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1119
1689
|
if (!data.total && !(data.keepsakeCount > 0)) {
|
|
1120
|
-
body.appendChild(
|
|
1690
|
+
body.appendChild(el2("div", { class: "fun-empty", text: "纪念册还是空的——她收一次摊,这里就有一趟。" }));
|
|
1121
1691
|
return;
|
|
1122
1692
|
}
|
|
1123
|
-
body.appendChild(
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1693
|
+
body.appendChild(el2(
|
|
1694
|
+
"div",
|
|
1695
|
+
{ class: "fun-stats" },
|
|
1696
|
+
stat(data.totalRecent ?? data.total, "近期行程"),
|
|
1697
|
+
stat(data.keepsakeCount ?? 0, "珍藏"),
|
|
1698
|
+
stat(data.visitedAreaCount, "处逛过"),
|
|
1699
|
+
stat(data.souvenirCount, "件纪念品"),
|
|
1700
|
+
stat(data.photoCount, "张照片")
|
|
1701
|
+
));
|
|
1702
|
+
if (data.mostVisited?.length) body.appendChild(el2(
|
|
1703
|
+
"details",
|
|
1704
|
+
{ class: "fun-wish-history" },
|
|
1705
|
+
el2("summary", { text: "常去的" }),
|
|
1706
|
+
el2("div", { class: "fun-chips" }, data.mostVisited.slice(0, 8).map((m) => el2("span", { class: "fun-chip", text: `${m.name} ×${m.times}` })))
|
|
1707
|
+
));
|
|
1708
|
+
const search = el2("input", { class: "fun-book-search", type: "search", placeholder: "搜地点、同行人、日期、备注或沿途回忆", value: bookKeyword, "aria-label": "搜索纪念册", "data-focus-key": "book-search" });
|
|
1129
1709
|
const placeOptions = new Map((data.trips ?? []).map((trip) => [trip.placeId, trip.placeName]));
|
|
1130
|
-
const place =
|
|
1131
|
-
|
|
1710
|
+
const place = el2(
|
|
1711
|
+
"select",
|
|
1712
|
+
{ class: "fun-book-place", "aria-label": "按地点筛选行程", "data-focus-key": "book-place" },
|
|
1713
|
+
el2("option", { value: "", text: "所有地点" }),
|
|
1714
|
+
[...placeOptions].map(([id, name]) => el2("option", { value: id, text: name }))
|
|
1715
|
+
);
|
|
1132
1716
|
place.value = bookPlace;
|
|
1133
|
-
const days = [...new Set((data.trips ?? []).map((trip) => trip.day ||
|
|
1134
|
-
const date =
|
|
1135
|
-
|
|
1717
|
+
const days = [...new Set((data.trips ?? []).map((trip) => trip.day || "unknown"))];
|
|
1718
|
+
const date = el2(
|
|
1719
|
+
"select",
|
|
1720
|
+
{ class: "fun-book-date", "aria-label": "按日期筛选行程", "data-focus-key": "book-date" },
|
|
1721
|
+
el2("option", { value: "", text: "所有日期" }),
|
|
1722
|
+
days.map((day) => el2("option", { value: day, text: day === "unknown" ? "日期不详" : day }))
|
|
1723
|
+
);
|
|
1136
1724
|
date.value = bookDate;
|
|
1137
|
-
body.appendChild(
|
|
1138
|
-
const results =
|
|
1725
|
+
body.appendChild(el2("div", { class: "fun-album-filters" }, search, place, date));
|
|
1726
|
+
const results = el2("div", { class: "fun-book-results" });
|
|
1727
|
+
body.appendChild(results);
|
|
1139
1728
|
const allTrips = data.trips ?? [];
|
|
1140
|
-
const textFor = (trip) => [
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1729
|
+
const textFor = (trip) => [
|
|
1730
|
+
trip.placeName,
|
|
1731
|
+
trip.company,
|
|
1732
|
+
trip.day,
|
|
1733
|
+
trip.note,
|
|
1734
|
+
trip.summary,
|
|
1735
|
+
...(trip.visited ?? []).map((area) => typeof area === "string" ? area : area.area),
|
|
1736
|
+
...trip.events ?? [],
|
|
1737
|
+
...trip.souvenirs ?? [],
|
|
1738
|
+
...trip.photos ?? [],
|
|
1739
|
+
...(trip.choices ?? []).map((choice) => choice.event + " " + choice.result),
|
|
1740
|
+
...(trip.timeline ?? []).map((entry) => entry.text)
|
|
1741
|
+
].filter(Boolean).join(" ").toLowerCase();
|
|
1144
1742
|
const renderResults = () => {
|
|
1145
1743
|
results.replaceChildren();
|
|
1146
1744
|
const keyword = bookKeyword.trim().toLowerCase();
|
|
1147
1745
|
const trips = allTrips.filter((trip) => {
|
|
1148
|
-
if (bookTab ===
|
|
1746
|
+
if (bookTab === "kept" && !trip.kept) return false;
|
|
1149
1747
|
if (bookPlace && trip.placeId !== bookPlace) return false;
|
|
1150
|
-
if (bookDate && (trip.day ||
|
|
1748
|
+
if (bookDate && (trip.day || "unknown") !== bookDate) return false;
|
|
1151
1749
|
if (!keyword) return true;
|
|
1152
1750
|
const route = (data.routes ?? []).find((group) => group.id === trip.routeId);
|
|
1153
1751
|
const linked = route ? allTrips.filter((member) => (route.tripIds ?? []).includes(member.id)) : [];
|
|
1154
|
-
const linkedText = route ? [(route.stops ?? []).map((stop) => stop.placeName).join(
|
|
1752
|
+
const linkedText = route ? [(route.stops ?? []).map((stop) => stop.placeName).join(" "), ...linked.map(textFor)].join(" ").toLowerCase() : "";
|
|
1155
1753
|
return textFor(trip).includes(keyword) || linkedText.includes(keyword);
|
|
1156
1754
|
});
|
|
1157
|
-
if (keyword || bookPlace || bookDate) results.appendChild(
|
|
1755
|
+
if (keyword || bookPlace || bookDate) results.appendChild(el2("div", { class: "fun-note", role: "status", text: "找到 " + trips.length + " 趟行程;联程同时检索相连的地点与记录。" }));
|
|
1158
1756
|
const appendTrip = (trip, parent) => {
|
|
1159
1757
|
const open = expandedTrips.has(trip.id);
|
|
1160
1758
|
const toggleKeep = async () => {
|
|
1161
1759
|
if (pending.has(trip.id)) return;
|
|
1162
|
-
pending.add(trip.id);
|
|
1760
|
+
pending.add(trip.id);
|
|
1761
|
+
errors.delete(trip.id);
|
|
1762
|
+
renderResults();
|
|
1163
1763
|
try {
|
|
1164
|
-
const result = await ctx.invoke(
|
|
1165
|
-
if (!result?.ok) throw new Error(result?.error ??
|
|
1764
|
+
const result = await ctx.invoke("favorite", [{ id: trip.id, keep: !trip.kept }]);
|
|
1765
|
+
if (!result?.ok) throw new Error(result?.error ?? "珍藏状态保存失败");
|
|
1166
1766
|
await load(true);
|
|
1167
|
-
} catch (error) {
|
|
1168
|
-
|
|
1767
|
+
} catch (error) {
|
|
1768
|
+
errors.set(trip.id, error?.message ?? String(error));
|
|
1769
|
+
} finally {
|
|
1770
|
+
pending.delete(trip.id);
|
|
1771
|
+
render(currentData ?? data);
|
|
1772
|
+
}
|
|
1169
1773
|
};
|
|
1170
|
-
const card =
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1774
|
+
const card = el2(
|
|
1775
|
+
"article",
|
|
1776
|
+
{ class: "fun-trip fun-ticket", "data-trip-id": trip.id },
|
|
1777
|
+
el2(
|
|
1778
|
+
"div",
|
|
1779
|
+
{ class: "fun-trip-head" },
|
|
1780
|
+
el2("span", { class: "fun-trip-name", text: trip.placeName }),
|
|
1781
|
+
el2("span", { class: "fun-trip-when", text: (trip.enteredHm || "时间不详") + "–" + (trip.leftHm || "时间不详") + (trip.stayedMin ? " · " + trip.stayedMin + " 分钟" : "") })
|
|
1782
|
+
),
|
|
1783
|
+
el2("div", { class: "fun-trip-sum", text: trip.summary }),
|
|
1784
|
+
trip.routeOrder ? el2("div", { class: "fun-note", text: "联程 · 第 " + trip.routeOrder + " 站" }) : null,
|
|
1785
|
+
el2(
|
|
1786
|
+
"div",
|
|
1787
|
+
{ class: "fun-trip-actions" },
|
|
1788
|
+
el2("button", { type: "button", class: "fun-detail-toggle", "data-trip-id": trip.id, "aria-expanded": String(open), onclick: () => {
|
|
1789
|
+
if (open) expandedTrips.delete(trip.id);
|
|
1790
|
+
else expandedTrips.add(trip.id);
|
|
1178
1791
|
renderResults();
|
|
1179
|
-
[...results.querySelectorAll(
|
|
1180
|
-
} }, open ?
|
|
1181
|
-
|
|
1182
|
-
errors.has(trip.id) ?
|
|
1792
|
+
[...results.querySelectorAll(".fun-detail-toggle")].find((button) => button.getAttribute("data-trip-id") === trip.id)?.focus?.();
|
|
1793
|
+
} }, open ? "收起详情" : "查看详情"),
|
|
1794
|
+
el2("button", { type: "button", disabled: pending.has(trip.id) ? "disabled" : null, onclick: toggleKeep }, pending.has(trip.id) ? "保存中…" : trip.kept ? "取消珍藏" : "珍藏"),
|
|
1795
|
+
errors.has(trip.id) ? el2("span", { class: "fun-trip-error", role: "alert", text: errors.get(trip.id) }) : null
|
|
1796
|
+
)
|
|
1797
|
+
);
|
|
1183
1798
|
if (open) card.appendChild(tripDetails(trip));
|
|
1184
1799
|
parent.appendChild(card);
|
|
1185
1800
|
};
|
|
1186
|
-
const drawnRoutes = new Set();
|
|
1801
|
+
const drawnRoutes = /* @__PURE__ */ new Set();
|
|
1187
1802
|
let previousDay = null;
|
|
1188
1803
|
for (const trip of trips) {
|
|
1189
1804
|
const route = trip.routeId && (data.routes ?? []).find((group) => group.id === trip.routeId);
|
|
1190
1805
|
if (route) {
|
|
1191
1806
|
if (drawnRoutes.has(route.id)) continue;
|
|
1192
1807
|
drawnRoutes.add(route.id);
|
|
1193
|
-
const group =
|
|
1808
|
+
const group = el2("section", { class: "fun-route-group", "data-route-id": route.id });
|
|
1194
1809
|
group.appendChild(routeSummary(route, allTrips, (selected) => {
|
|
1195
|
-
expandedTrips.add(selected.id);
|
|
1810
|
+
expandedTrips.add(selected.id);
|
|
1811
|
+
bookKeyword = "";
|
|
1812
|
+
bookPlace = "";
|
|
1813
|
+
bookDate = "";
|
|
1814
|
+
bookTab = "all";
|
|
1196
1815
|
render(currentData);
|
|
1197
|
-
[...body.querySelectorAll(
|
|
1816
|
+
[...body.querySelectorAll(".fun-detail-toggle")].find((button) => button.getAttribute("data-trip-id") === selected.id)?.focus?.();
|
|
1198
1817
|
}));
|
|
1199
1818
|
const members = (route.tripIds ?? []).map((id) => trips.find((member) => member.id === id)).filter(Boolean);
|
|
1200
|
-
for (const member of members) {
|
|
1201
|
-
|
|
1819
|
+
for (const member of members) {
|
|
1820
|
+
group.appendChild(el2("div", { class: "fun-date", text: member.day || "日期不详" }));
|
|
1821
|
+
appendTrip(member, group);
|
|
1822
|
+
}
|
|
1823
|
+
results.appendChild(group);
|
|
1824
|
+
previousDay = null;
|
|
1202
1825
|
} else {
|
|
1203
|
-
if (trip.day !== previousDay) {
|
|
1826
|
+
if (trip.day !== previousDay) {
|
|
1827
|
+
results.appendChild(el2("div", { class: "fun-date", text: trip.day || "日期不详" }));
|
|
1828
|
+
previousDay = trip.day;
|
|
1829
|
+
}
|
|
1204
1830
|
appendTrip(trip, results);
|
|
1205
1831
|
}
|
|
1206
1832
|
}
|
|
1207
|
-
if (!trips.length) results.appendChild(
|
|
1833
|
+
if (!trips.length) results.appendChild(el2("div", { class: "fun-empty", text: bookKeyword || bookPlace || bookDate ? "没有匹配的行程,试试其他地点、日期或搜索词。" : bookTab === "kept" ? "还没有珍藏的行程。" : "还没有可回看的行程。" }));
|
|
1208
1834
|
};
|
|
1209
|
-
search.addEventListener(
|
|
1210
|
-
|
|
1211
|
-
|
|
1835
|
+
search.addEventListener("input", () => {
|
|
1836
|
+
bookKeyword = search.value;
|
|
1837
|
+
renderResults();
|
|
1838
|
+
});
|
|
1839
|
+
place.addEventListener("change", () => {
|
|
1840
|
+
bookPlace = place.value;
|
|
1841
|
+
renderResults();
|
|
1842
|
+
});
|
|
1843
|
+
date.addEventListener("change", () => {
|
|
1844
|
+
bookDate = date.value;
|
|
1845
|
+
renderResults();
|
|
1846
|
+
});
|
|
1212
1847
|
renderResults();
|
|
1213
1848
|
restoreFocus();
|
|
1214
1849
|
};
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1850
|
+
const stat = (n, label2) => el2(
|
|
1851
|
+
"div",
|
|
1852
|
+
{ class: "fun-stat" },
|
|
1853
|
+
el2("b", { text: String(n) }),
|
|
1854
|
+
el2("span", { text: label2 })
|
|
1855
|
+
);
|
|
1219
1856
|
const load = async (propagate = false) => {
|
|
1220
1857
|
try {
|
|
1221
|
-
const data = await ctx.invoke(
|
|
1222
|
-
if (!data?.ok) throw new Error(data?.error ??
|
|
1858
|
+
const data = await ctx.invoke("list");
|
|
1859
|
+
if (!data?.ok) throw new Error(data?.error ?? "返回不正常");
|
|
1223
1860
|
status.replaceChildren();
|
|
1224
1861
|
render(data);
|
|
1225
1862
|
} catch (err) {
|
|
@@ -1228,89 +1865,99 @@ function mountBook(ctx) {
|
|
|
1228
1865
|
status.replaceChildren(errorCard(err, load, Boolean(currentData)));
|
|
1229
1866
|
}
|
|
1230
1867
|
};
|
|
1231
|
-
|
|
1232
1868
|
void load();
|
|
1233
1869
|
return { refresh: load };
|
|
1234
1870
|
}
|
|
1235
|
-
|
|
1236
|
-
/**
|
|
1237
|
-
* 纪念品架:跨趟归集的收藏 + 每处的集齐进度。
|
|
1238
|
-
*
|
|
1239
|
-
* 数据全部由服务端的 `shelf/list` 算好(`keepsakes.js` 是纯函数),
|
|
1240
|
-
* 这里只负责画。**不自己聚合、不自己算日期**——两边各算一遍必然会不一致。
|
|
1241
|
-
*/
|
|
1242
1871
|
function mountShelf(ctx) {
|
|
1243
1872
|
const root = ctx.root;
|
|
1244
1873
|
root.replaceChildren();
|
|
1245
1874
|
const box = shell(root);
|
|
1246
|
-
const body =
|
|
1875
|
+
const body = el2("div");
|
|
1247
1876
|
box.appendChild(body);
|
|
1248
|
-
const status =
|
|
1877
|
+
const status = feedback2(box);
|
|
1249
1878
|
let currentData = null;
|
|
1250
|
-
body.appendChild(
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1879
|
+
body.appendChild(el2("div", { class: "fun-loading", role: "status", text: "正在整理纪念品架…" }));
|
|
1880
|
+
const stat = (n, label2) => el2(
|
|
1881
|
+
"div",
|
|
1882
|
+
{ class: "fun-stat" },
|
|
1883
|
+
el2("b", { text: String(n) }),
|
|
1884
|
+
el2("span", { text: label2 })
|
|
1885
|
+
);
|
|
1255
1886
|
const pct = (part) => `${part.done}/${part.total}`;
|
|
1256
|
-
const memoryTrip = tripLookup(ctx,
|
|
1257
|
-
|
|
1887
|
+
const memoryTrip = tripLookup(ctx, "trip", "id", "回看这趟行程");
|
|
1258
1888
|
const render = (data) => {
|
|
1259
1889
|
currentData = data;
|
|
1260
|
-
body.replaceChildren(heading(
|
|
1890
|
+
body.replaceChildren(heading("纪念品架", "每一件小东西,都有带它回来的那一天。"));
|
|
1261
1891
|
if (!data.total) {
|
|
1262
|
-
body.appendChild(
|
|
1892
|
+
body.appendChild(el2("div", { class: "fun-empty", text: "架子上还什么都没有——她买过纪念品,这里就有了。" }));
|
|
1263
1893
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
stat(data.
|
|
1268
|
-
stat(data.
|
|
1269
|
-
stat(data.
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
if (data.byPlace.length) body.appendChild(el('div', { class: 'fun-sec', text: '按地方归着' }));
|
|
1894
|
+
body.appendChild(el2(
|
|
1895
|
+
"div",
|
|
1896
|
+
{ class: "fun-stats" },
|
|
1897
|
+
stat(data.total, "样东西"),
|
|
1898
|
+
stat(data.pieces, "件"),
|
|
1899
|
+
stat(data.places, "处地方"),
|
|
1900
|
+
stat(data.completePlaces, "处逛遍")
|
|
1901
|
+
));
|
|
1902
|
+
body.appendChild(el2("div", { class: "fun-meta", text: "收藏账本长期保留;详细行程可查看最近 40 趟与珍藏行程。进度按当前场所清单统计,移除或改名不删除旧回忆。" }));
|
|
1903
|
+
if (data.byPlace.length) body.appendChild(el2("div", { class: "fun-sec", text: "按地方归着" }));
|
|
1275
1904
|
for (const g of data.byPlace) {
|
|
1276
|
-
body.appendChild(
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1905
|
+
body.appendChild(el2(
|
|
1906
|
+
"div",
|
|
1907
|
+
{ class: "fun-trip" },
|
|
1908
|
+
el2(
|
|
1909
|
+
"div",
|
|
1910
|
+
{ class: "fun-trip-head" },
|
|
1911
|
+
el2("span", { class: "fun-trip-name", text: g.placeName }),
|
|
1912
|
+
el2("span", { class: "fun-trip-when", text: `${g.items.length} 样 · 最早 ${g.firstDay || "—"}` })
|
|
1913
|
+
),
|
|
1914
|
+
el2("div", { class: "fun-shelf-grid" }, g.items.map((it) => el2(
|
|
1915
|
+
"details",
|
|
1916
|
+
{ class: "fun-keepsake" },
|
|
1917
|
+
el2(
|
|
1918
|
+
"summary",
|
|
1919
|
+
null,
|
|
1920
|
+
itemIcon(it.name),
|
|
1921
|
+
el2("strong", { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ""}` }),
|
|
1922
|
+
el2("span", { class: "fun-dim", text: `记录中最早 ${it.firstDay || "日期不详"}` })
|
|
1923
|
+
),
|
|
1924
|
+
it.archivedCount ? el2("div", { class: "fun-note", text: `${it.archivedCount} 次收藏仅保留账本,详细行程已不在近期记录中。` }) : null,
|
|
1925
|
+
...(it.memories ?? []).map((m) => el2(
|
|
1926
|
+
"div",
|
|
1927
|
+
{ class: "fun-trip-sum" },
|
|
1928
|
+
el2("div", { text: `${m.day || "日期不详"} · ${m.summary}` }),
|
|
1929
|
+
m.note ? el2("div", { text: `你记的:${m.note}` }) : null,
|
|
1930
|
+
m.id ? memoryTrip(m.id) : null
|
|
1931
|
+
))
|
|
1932
|
+
)))
|
|
1933
|
+
));
|
|
1288
1934
|
}
|
|
1289
|
-
|
|
1290
|
-
// 进度:只列去过的。服务端已按「快逛遍的」排好,这里照顺序画。
|
|
1291
1935
|
const visited = data.progress.filter((p) => p.visits > 0);
|
|
1292
1936
|
if (visited.length) {
|
|
1293
|
-
body.appendChild(
|
|
1937
|
+
body.appendChild(el2("div", { class: "fun-sec", text: `逛过的 ${visited.length} 处` }));
|
|
1294
1938
|
for (const p of visited) {
|
|
1295
1939
|
const left = p.areas.left.length;
|
|
1296
|
-
body.appendChild(
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1940
|
+
body.appendChild(el2(
|
|
1941
|
+
"div",
|
|
1942
|
+
{ class: "fun-trip" },
|
|
1943
|
+
el2(
|
|
1944
|
+
"div",
|
|
1945
|
+
{ class: "fun-trip-head" },
|
|
1946
|
+
el2("span", { class: "fun-trip-name", text: p.placeName }),
|
|
1947
|
+
el2("span", { class: "fun-trip-when", text: `去过 ${p.visits} 次 · ${p.percent}%` })
|
|
1948
|
+
),
|
|
1949
|
+
el2("progress", { class: "fun-progress", max: "100", value: String(p.percent), "aria-label": `${p.placeName}探索进度 ${p.percent}%` }),
|
|
1950
|
+
el2("div", { class: "fun-meta", text: `逛过 ${pct(p.areas)}${p.souvenirs.total ? ` · 纪念品 ${pct(p.souvenirs)}` : ""}${p.photos.total ? ` · 拍过 ${pct(p.photos)}` : ""}` }),
|
|
1951
|
+
p.phases?.length ? el2("div", { class: "fun-note fun-visited-phases", text: `去过的时段:${p.phases.join("、")}` }) : null,
|
|
1952
|
+
left ? el2("div", { class: "fun-trip-sum", text: `还差:${p.areas.left.slice(0, 6).join("、")}${left > 6 ? ` 等 ${left} 处` : ""}` }) : el2("div", { class: "fun-trip-sum", text: "这一处已经逛遍了。" })
|
|
1953
|
+
));
|
|
1306
1954
|
}
|
|
1307
1955
|
}
|
|
1308
1956
|
};
|
|
1309
|
-
|
|
1310
1957
|
const load = async () => {
|
|
1311
1958
|
try {
|
|
1312
|
-
const data = await ctx.invoke(
|
|
1313
|
-
if (!data?.ok) throw new Error(data?.error ??
|
|
1959
|
+
const data = await ctx.invoke("list");
|
|
1960
|
+
if (!data?.ok) throw new Error(data?.error ?? "返回不正常");
|
|
1314
1961
|
status.replaceChildren();
|
|
1315
1962
|
render(data);
|
|
1316
1963
|
} catch (err) {
|
|
@@ -1318,16 +1965,17 @@ function mountShelf(ctx) {
|
|
|
1318
1965
|
status.replaceChildren(errorCard(err, load, Boolean(currentData)));
|
|
1319
1966
|
}
|
|
1320
1967
|
};
|
|
1321
|
-
|
|
1322
1968
|
void load();
|
|
1323
1969
|
return { refresh: load };
|
|
1324
1970
|
}
|
|
1325
|
-
|
|
1326
|
-
export default {
|
|
1971
|
+
var webui_default = {
|
|
1327
1972
|
panels: {
|
|
1328
1973
|
places: { mount: mountPlaces },
|
|
1329
1974
|
book: { mount: mountBook },
|
|
1330
1975
|
shelf: { mount: mountShelf },
|
|
1331
|
-
stories: { mount: mountStories }
|
|
1332
|
-
}
|
|
1976
|
+
stories: { mount: mountStories }
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
export {
|
|
1980
|
+
webui_default as default
|
|
1333
1981
|
};
|