refactor(admin): unify webui fetch/copy/format helpers; fix audit tab load and delete-group count

- apiFetch + shared needLogin (any 401 shows the login card) replaces six
  duplicated fetch/401/error-handling blocks in the admin composables
- useCopy composable: clipboard + execCommand fallback with timed reset,
  used by MembersPanel and WebhookPanel
- utils/format.ts (fmtTime/splitList/parseMatch) removes inline duplicates
  across SendLogs, AuditLog, RouteEditor and GroupEditor
- fix: load the audit log when the audit tab becomes active (client-side
  navigation never remounted the page, leaving the list empty on first visit)
- fix: fetch the real route count for a group before confirming deletion
  instead of reusing the currently open group's route list
This commit is contained in:
RhenCloud 2026-08-14 07:18:55 +08:00
parent c438fe96dc
commit e59b10f739
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
16 changed files with 137 additions and 202 deletions

View file

@ -72,7 +72,7 @@
<span class="role-pill" :class="inv.role">{{ t("roles." + inv.role) }}</span>
<span class="invite-exp">{{ fmtExp(inv.expiresAt) }}</span>
<button class="btn btn-ghost btn-sm" @click="copyInvite(inv)">
{{ copiedToken === inv.token ? t("members.copied") : t("members.copyLink") }}
{{ copied === inv.token ? t("members.copied") : t("members.copyLink") }}
</button>
<button class="icon-btn danger" @click="revoke(inv)">{{ t("members.revoke") }}</button>
</li>
@ -101,8 +101,8 @@ const newLogin = ref("");
const newRole = ref<GroupRole>("admin");
const inviteRole = ref<"admin" | "viewer">("admin");
const inviting = ref(false);
const copiedToken = ref("");
const formError = ref("");
const { copied, copy } = useCopy(2000);
watch(
() => props.group,
@ -175,11 +175,7 @@ async function createInvite(): Promise<void> {
...invites.value,
];
}
copyText(`${window.location.origin}${url}`);
copiedToken.value = token;
window.setTimeout(() => {
copiedToken.value = "";
}, 2000);
copy(`${window.location.origin}${url}`, token);
await loadInvites();
} catch (err) {
formError.value = err instanceof Error ? err.message : String(err);
@ -190,11 +186,7 @@ async function createInvite(): Promise<void> {
async function copyInvite(inv: GroupInvite): Promise<void> {
const url = `${window.location.origin}/admin/invite?token=${inv.token}`;
copyText(url);
copiedToken.value = inv.token;
window.setTimeout(() => {
copiedToken.value = "";
}, 2000);
await copy(url, inv.token);
}
async function revoke(inv: GroupInvite): Promise<void> {
@ -206,19 +198,6 @@ async function revoke(inv: GroupInvite): Promise<void> {
}
}
async function copyText(text: string): Promise<void> {
try {
await navigator.clipboard.writeText(text);
} catch {
const ta = document.createElement("textarea");
ta.value = text;
document.body.appendChild(ta);
ta.select();
document.execCommand("copy");
document.body.removeChild(ta);
}
}
function shortToken(token: string): string {
return token.slice(0, 8) + "…";
}