feat(admin): add route reordering with up/down buttons

This commit is contained in:
RhenCloud 2026-08-03 08:40:59 +08:00
parent ac8b4a77b8
commit 7ee1e5899f
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
4 changed files with 54 additions and 3 deletions

View file

@ -56,10 +56,13 @@
v-for="(r, i) in groupRoutes"
:key="r.id"
:route="r"
:at-first="i === 0"
:at-last="i === groupRoutes.length - 1"
:style="{ animationDelay: i * 45 + 'ms' }"
@toggle="onToggle"
@edit="openEdit"
@delete="onDelete"
@move="onMove"
/>
</section>
@ -271,6 +274,22 @@ async function onSave(route: Route): Promise<void> {
}
}
async function onMove(route: Route, dir: -1 | 1): Promise<void> {
const group = selectedGroup.value;
if (!group) return;
const i = groupRoutes.value.findIndex((r) => r.id === route.id);
const j = i + dir;
if (i < 0 || j < 0 || j >= groupRoutes.value.length) return;
const next = [...groupRoutes.value];
[next[i], next[j]] = [next[j]!, next[i]!];
try {
await saveGroupRoutes(group.id, next);
} catch (err) {
push(t("toast.saveFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad");
loadGroupRoutes(group.id);
}
}
async function onToggle(route: Route): Promise<void> {
const group = selectedGroup.value;
if (!group) return;