mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
style(route-editor): group options and delivery target fields
Give each target labeled fields and a compact platform header, widen the filter workspace, and align fragment controls. Scroll failed validation into view when the footer is far from the affected section.
This commit is contained in:
1 parent
96f8fce9bf
commit
7aa36f4dc2
3 files changed
+174
-109
No files matched your search
+36
-17
@@ -719,6 +719,19 @@
|
||||
@apply w-full;
|
||||
}
|
||||
|
||||
.option-list {
|
||||
@apply mb-4 flex flex-col gap-3;
|
||||
}
|
||||
|
||||
.option-row {
|
||||
@apply flex flex-col items-start gap-1;
|
||||
}
|
||||
|
||||
/* Indented to line up with the checkbox label text. */
|
||||
.option-hint {
|
||||
@apply m-0 pl-[1.625rem] text-[11.5px] leading-snug text-faint;
|
||||
}
|
||||
|
||||
.ctl-md {
|
||||
@apply w-full max-w-64;
|
||||
}
|
||||
@@ -727,29 +740,31 @@
|
||||
@apply mt-2 flex w-full max-w-md flex-col gap-2;
|
||||
}
|
||||
|
||||
.target-row {
|
||||
@apply mb-2 grid grid-cols-[minmax(130px,1fr)_auto] items-center gap-2 rounded-sm border border-border bg-surface-2 p-2.5 max-sm:grid-cols-[1fr_auto];
|
||||
grid-template-areas:
|
||||
"select del"
|
||||
"in1 in2";
|
||||
.target-card {
|
||||
@apply mb-2 flex flex-col gap-2.5 rounded-lg border border-border bg-surface-2 p-3;
|
||||
}
|
||||
|
||||
.target-row select {
|
||||
@apply w-full rounded border border-border-strong bg-surface px-2 py-1.5 font-ui text-[12.5px] font-medium text-text;
|
||||
grid-area: select;
|
||||
.target-card-head {
|
||||
@apply flex items-center justify-between gap-2;
|
||||
}
|
||||
|
||||
.target-row input.tg-in1 {
|
||||
grid-area: in1;
|
||||
.target-platform {
|
||||
@apply w-44 max-w-full;
|
||||
}
|
||||
|
||||
.target-row input.tg-in2 {
|
||||
grid-area: in2;
|
||||
.target-field {
|
||||
@apply grid items-center gap-x-3 gap-y-1;
|
||||
grid-template-columns: 7rem minmax(0, 28rem);
|
||||
}
|
||||
|
||||
.target-row > .icon-btn {
|
||||
grid-area: del;
|
||||
justify-self: end;
|
||||
.target-field > label {
|
||||
@apply text-xs font-semibold text-muted;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.target-field {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.add-filter {
|
||||
@@ -873,7 +888,7 @@
|
||||
}
|
||||
|
||||
.fragment-row {
|
||||
@apply flex items-center gap-2 rounded-sm border border-border bg-surface-2 p-2;
|
||||
@apply flex items-center gap-2 rounded-lg border border-border bg-surface-2 py-1.5 pl-3 pr-1.5;
|
||||
}
|
||||
|
||||
.fragment-name {
|
||||
@@ -885,7 +900,11 @@
|
||||
}
|
||||
|
||||
.fragment-save {
|
||||
@apply flex items-center gap-2;
|
||||
@apply flex max-w-lg items-center gap-2;
|
||||
}
|
||||
|
||||
.fragment-save-input {
|
||||
@apply min-w-0 flex-1;
|
||||
}
|
||||
|
||||
.log-block {
|
||||
|
||||
+136
-92
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from "vue";
|
||||
import { computed, nextTick, reactive, ref, watch } from "vue";
|
||||
import { Trash2 } from "lucide-vue-next";
|
||||
import type { Filter, FilterNode, NamedFragment, Route, RouteTarget, RouteTemplate } from "~/types";
|
||||
import { FRAGMENT_PRESETS, ROUTE_TEMPLATES } from "~/types";
|
||||
import type { NodeForm } from "~/composables/useFilterNode";
|
||||
@@ -40,6 +41,7 @@ const discordRoles = computed({
|
||||
form.discordRolesText = roles.join(", ");
|
||||
},
|
||||
});
|
||||
const bodyEl = ref<HTMLFormElement | null>(null);
|
||||
const filterError = ref("");
|
||||
const targetError = ref("");
|
||||
const formError = ref("");
|
||||
@@ -181,20 +183,20 @@ function collect(): Route | null {
|
||||
};
|
||||
}
|
||||
|
||||
function save(): void {
|
||||
function validated(): Route | null {
|
||||
const route = collect();
|
||||
if (!route) return;
|
||||
if (!route) return null;
|
||||
if (!/^[a-z0-9][a-z0-9-]*$/.test(route.id)) {
|
||||
formError.value = t("routeEditor.errIdFormat");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (!route.name) {
|
||||
formError.value = t("routeEditor.errName");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (!route.targets.length) {
|
||||
targetError.value = t("routeEditor.errTargets");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
form.targets.forEach((tg, i) => {
|
||||
if ((tg.platform === "telegram" || tg.platform === "feishu") && !tg.chatId.trim()) {
|
||||
@@ -203,8 +205,21 @@ function save(): void {
|
||||
targetError.value = t("routeEditor.errChannel", { n: i + 1 });
|
||||
}
|
||||
});
|
||||
if (targetError.value) return;
|
||||
emit("save", route);
|
||||
return targetError.value ? null : route;
|
||||
}
|
||||
|
||||
function save(): void {
|
||||
const route = validated();
|
||||
if (route) {
|
||||
emit("save", route);
|
||||
return;
|
||||
}
|
||||
// The footer button may be far from the failing section: bring the error into view.
|
||||
nextTick(() =>
|
||||
bodyEl.value
|
||||
?.querySelector("[data-save-error]")
|
||||
?.scrollIntoView({ block: "center", behavior: "smooth" }),
|
||||
);
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
@@ -350,7 +365,7 @@ watch(
|
||||
<RcDialog
|
||||
:open="open"
|
||||
:title="isEdit ? t('routeEditor.editTitle') : t('routeEditor.newTitle')"
|
||||
class="editor-dialog flex flex-col gap-0 max-h-[calc(100dvh-2rem)] overflow-hidden p-0 max-w-3xl"
|
||||
class="editor-dialog flex flex-col gap-0 max-h-[calc(100dvh-2rem)] overflow-hidden p-0 max-w-4xl"
|
||||
@update:open="onOpenChange"
|
||||
>
|
||||
<template #header>
|
||||
@@ -362,7 +377,7 @@ watch(
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<form class="editor-body" @submit.prevent="save">
|
||||
<form ref="bodyEl" class="editor-body" @submit.prevent="save">
|
||||
<section class="editor-section">
|
||||
<h3 class="editor-section-title">{{ t("routeEditor.sectionBasic") }}</h3>
|
||||
<div v-if="!isEdit" class="templates">
|
||||
@@ -378,29 +393,33 @@ watch(
|
||||
{{ t(tmpl.nameKey) }}
|
||||
</RcButton>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t("routeEditor.name") }}</label>
|
||||
<RcInput v-model="form.name" :placeholder="t('routeEditor.namePlaceholder')" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t("routeEditor.id") }}</label>
|
||||
<RcInput v-model="form.id" placeholder="my-route" required />
|
||||
<div class="hint">{{ t("routeEditor.idHint") }}</div>
|
||||
<div class="row2">
|
||||
<div class="field">
|
||||
<label>{{ t("routeEditor.name") }}</label>
|
||||
<RcInput v-model="form.name" :placeholder="t('routeEditor.namePlaceholder')" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t("routeEditor.id") }}</label>
|
||||
<RcInput v-model="form.id" placeholder="my-route" required />
|
||||
<div class="hint">{{ t("routeEditor.idHint") }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="editor-section">
|
||||
<h3 class="editor-section-title">{{ t("routeEditor.sectionOptions") }}</h3>
|
||||
<div class="field inline">
|
||||
<RcSwitch v-model="form.enabled" :label="t('routeEditor.enabled')" />
|
||||
</div>
|
||||
<div class="field inline">
|
||||
<RcCheckbox v-model="form.fallback" :label="t('routeEditor.fallback')" />
|
||||
<span class="lbl-note">{{ t("routeEditor.fallbackHint") }}</span>
|
||||
</div>
|
||||
<div class="field inline">
|
||||
<RcCheckbox v-model="form.stop" :label="t('routeEditor.stop')" />
|
||||
<span class="lbl-note">{{ t("routeEditor.stopHint") }}</span>
|
||||
<div class="option-list">
|
||||
<div class="option-row">
|
||||
<RcSwitch v-model="form.enabled" :label="t('routeEditor.enabled')" />
|
||||
</div>
|
||||
<div class="option-row">
|
||||
<RcCheckbox v-model="form.fallback" :label="t('routeEditor.fallback')" />
|
||||
<p class="option-hint">{{ t("routeEditor.fallbackHint") }}</p>
|
||||
</div>
|
||||
<div class="option-row">
|
||||
<RcCheckbox v-model="form.stop" :label="t('routeEditor.stop')" />
|
||||
<p class="option-hint">{{ t("routeEditor.stopHint") }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t("routeEditor.discordRoles") }}</label>
|
||||
@@ -415,13 +434,8 @@ watch(
|
||||
|
||||
<section class="editor-section">
|
||||
<h3 class="editor-section-title">{{ t("routeEditor.sectionFilters") }}</h3>
|
||||
<div class="field">
|
||||
<label>{{ t("routeEditor.filters") }}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<FilterNodeEditor :node="root" />
|
||||
</div>
|
||||
<div v-if="filterError" class="err">{{ filterError }}</div>
|
||||
<FilterNodeEditor :node="root" />
|
||||
<div v-if="filterError" class="err" data-save-error>{{ filterError }}</div>
|
||||
</section>
|
||||
|
||||
<section class="editor-section">
|
||||
@@ -485,21 +499,31 @@ watch(
|
||||
</RcButton>
|
||||
<RcButton
|
||||
type="button"
|
||||
variant="destructive"
|
||||
variant="ghost"
|
||||
color="error"
|
||||
size="icon"
|
||||
class="h-8 w-8 text-muted hover:text-bad"
|
||||
:title="t('routeEditor.fragmentsDelete')"
|
||||
:aria-label="t('routeEditor.fragmentsDelete')"
|
||||
@click="deleteFragment(frag)"
|
||||
>
|
||||
✕
|
||||
<Trash2 :size="15" />
|
||||
</RcButton>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field fragment-save">
|
||||
<RcInput
|
||||
v-model="fragmentName"
|
||||
:placeholder="t('routeEditor.fragmentsNamePlaceholder')"
|
||||
/>
|
||||
<RcButton type="button" variant="ghost" @click="saveAsFragment">
|
||||
<div class="fragment-save">
|
||||
<div class="fragment-save-input">
|
||||
<RcInput
|
||||
v-model="fragmentName"
|
||||
:placeholder="t('routeEditor.fragmentsNamePlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<RcButton
|
||||
type="button"
|
||||
variant="ghost"
|
||||
class="shrink-0 whitespace-nowrap"
|
||||
@click="saveAsFragment"
|
||||
>
|
||||
{{ t("routeEditor.fragmentsSave") }}
|
||||
</RcButton>
|
||||
</div>
|
||||
@@ -508,65 +532,85 @@ watch(
|
||||
|
||||
<section class="editor-section">
|
||||
<h3 class="editor-section-title">{{ t("routeEditor.sectionTargets") }}</h3>
|
||||
<div v-for="(tg, i) in form.targets" :key="i" class="target-row">
|
||||
<RcSelect
|
||||
v-model="tg.platform"
|
||||
class="[grid-area:select]"
|
||||
:options="[
|
||||
{ label: 'Discord', value: 'discord' },
|
||||
{ label: 'Telegram', value: 'telegram' },
|
||||
{ label: t('routeEditor.platformFeishu'), value: 'feishu' },
|
||||
]"
|
||||
/>
|
||||
<div v-for="(tg, i) in form.targets" :key="i" class="target-card">
|
||||
<div class="target-card-head">
|
||||
<div class="target-platform">
|
||||
<RcSelect
|
||||
v-model="tg.platform"
|
||||
:options="[
|
||||
{ label: 'Discord', value: 'discord' },
|
||||
{ label: 'Telegram', value: 'telegram' },
|
||||
{ label: t('routeEditor.platformFeishu'), value: 'feishu' },
|
||||
]"
|
||||
/>
|
||||
</div>
|
||||
<RcButton
|
||||
type="button"
|
||||
variant="ghost"
|
||||
color="error"
|
||||
size="icon"
|
||||
class="h-8 w-8 text-muted hover:text-bad"
|
||||
:title="t('routeEditor.removeTarget')"
|
||||
:aria-label="t('routeEditor.removeTarget')"
|
||||
@click="removeTarget(tg)"
|
||||
>
|
||||
<Trash2 :size="15" />
|
||||
</RcButton>
|
||||
</div>
|
||||
<template v-if="tg.platform === 'discord'">
|
||||
<RcInput
|
||||
v-model="tg.channelId"
|
||||
class="[grid-area:in1]"
|
||||
:placeholder="t('routeEditor.channelPlaceholder')"
|
||||
/>
|
||||
<RcInput
|
||||
v-model="tg.threadId"
|
||||
class="[grid-area:in2]"
|
||||
:placeholder="t('routeEditor.threadPlaceholder')"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="tg.platform === 'telegram'">
|
||||
<RcInput
|
||||
v-model="tg.chatId"
|
||||
class="[grid-area:in1]"
|
||||
:placeholder="t('routeEditor.chatPlaceholder')"
|
||||
/>
|
||||
<RcInput
|
||||
v-model="tg.topicId"
|
||||
class="[grid-area:in2]"
|
||||
:placeholder="t('routeEditor.topicPlaceholder')"
|
||||
/>
|
||||
<div class="target-field">
|
||||
<label :for="`target-${i}-channel`">{{ t("routeEditor.channel") }}</label>
|
||||
<RcInput
|
||||
:id="`target-${i}-channel`"
|
||||
v-model="tg.channelId"
|
||||
:placeholder="t('routeEditor.channelPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="target-field">
|
||||
<label :for="`target-${i}-thread`"
|
||||
>{{ t("routeEditor.thread") }}
|
||||
<span class="lbl-note">{{ t("routeEditor.threadNote") }}</span></label
|
||||
>
|
||||
<RcInput
|
||||
:id="`target-${i}-thread`"
|
||||
v-model="tg.threadId"
|
||||
:placeholder="t('routeEditor.threadPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<RcInput
|
||||
v-model="tg.chatId"
|
||||
class="[grid-area:in1]"
|
||||
:placeholder="t('routeEditor.feishuChatPlaceholder')"
|
||||
/>
|
||||
<div class="target-field">
|
||||
<label :for="`target-${i}-chat`">{{ t("routeEditor.chat") }}</label>
|
||||
<RcInput
|
||||
:id="`target-${i}-chat`"
|
||||
v-model="tg.chatId"
|
||||
:placeholder="
|
||||
tg.platform === 'telegram'
|
||||
? t('routeEditor.chatPlaceholder')
|
||||
: t('routeEditor.feishuChatPlaceholder')
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="tg.platform === 'telegram'" class="target-field">
|
||||
<label :for="`target-${i}-topic`"
|
||||
>{{ t("routeEditor.topic") }}
|
||||
<span class="lbl-note">{{ t("routeEditor.topicNote") }}</span></label
|
||||
>
|
||||
<RcInput
|
||||
:id="`target-${i}-topic`"
|
||||
v-model="tg.topicId"
|
||||
:placeholder="t('routeEditor.topicPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<RcButton
|
||||
type="button"
|
||||
variant="destructive"
|
||||
size="icon"
|
||||
class="[grid-area:del] justify-self-end"
|
||||
:title="t('routeEditor.remove')"
|
||||
@click="removeTarget(tg)"
|
||||
>
|
||||
✕
|
||||
</RcButton>
|
||||
</div>
|
||||
<RcButton type="button" variant="ghost" class="add-filter" @click="addTarget">
|
||||
{{ t("routeEditor.addTarget") }}
|
||||
</RcButton>
|
||||
<div v-if="targetError" class="err">{{ targetError }}</div>
|
||||
<div v-if="targetError" class="err" data-save-error>{{ targetError }}</div>
|
||||
</section>
|
||||
|
||||
<div v-if="formError" class="err">{{ formError }}</div>
|
||||
<div v-if="formError" class="err" data-save-error>{{ formError }}</div>
|
||||
</form>
|
||||
|
||||
<template #footer>
|
||||
|
||||
@@ -261,6 +261,7 @@ const en: Dict = {
|
||||
"routeEditor.addGroup": "Add group",
|
||||
"routeEditor.addNot": "Add not",
|
||||
"routeEditor.remove": "Remove",
|
||||
"routeEditor.removeTarget": "Remove target",
|
||||
"routeEditor.op": "Operator",
|
||||
"routeEditor.pathPlaceholder": "payload.path",
|
||||
"routeEditor.valuesPlaceholder": "Type a value and press Enter",
|
||||
@@ -671,6 +672,7 @@ const zh: Dict = {
|
||||
"routeEditor.addGroup": "添加分组",
|
||||
"routeEditor.addNot": "添加非",
|
||||
"routeEditor.remove": "删除",
|
||||
"routeEditor.removeTarget": "删除目标",
|
||||
"routeEditor.op": "操作符",
|
||||
"routeEditor.pathPlaceholder": "payload.path",
|
||||
"routeEditor.valuesPlaceholder": "输入值后回车",
|
||||
|
||||
Reference in new issue
Block a user