mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat(admin): add route reordering with up/down buttons
This commit is contained in:
parent
ac8b4a77b8
commit
7ee1e5899f
4 changed files with 54 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue