mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
feat(ui): migrate to @recloudstudio/ui, add theme toggle and polish console UX
This commit is contained in:
45 files changed
+1489
-1343
No files matched your search
@@ -25,6 +25,11 @@ const en: Dict = {
|
||||
"overview.recent": "Recent deliveries",
|
||||
"overview.viewAll": "View all",
|
||||
"overview.refreshed": "Refreshed",
|
||||
"overview.thRoute": "Route",
|
||||
"overview.thGroup": "Group",
|
||||
"overview.thEvents": "Events",
|
||||
"overview.thTargets": "Targets",
|
||||
"overview.thState": "State",
|
||||
"metrics.refresh": "Refresh",
|
||||
"metrics.total": "Total",
|
||||
"metrics.ok": "OK",
|
||||
@@ -412,6 +417,11 @@ const zh: Dict = {
|
||||
"overview.recent": "最近投递",
|
||||
"overview.viewAll": "查看全部",
|
||||
"overview.refreshed": "已刷新",
|
||||
"overview.thRoute": "路由",
|
||||
"overview.thGroup": "分组",
|
||||
"overview.thEvents": "事件",
|
||||
"overview.thTargets": "目标",
|
||||
"overview.thState": "状态",
|
||||
"metrics.refresh": "刷新",
|
||||
"metrics.total": "总计",
|
||||
"metrics.ok": "成功",
|
||||
@@ -511,6 +521,8 @@ const zh: Dict = {
|
||||
"webhook.usageGitea": "Gitea:仓库 Settings → Webhooks → Add Webhook,填写同样的 URL 和 secret。",
|
||||
"webhook.usageCustom":
|
||||
"自定义:用 X-WebHooker-Signature(sha256 HMAC)签名任意 JSON 后 POST。创建一条 event = custom 的路由即可接收:",
|
||||
"groups.empty": "暂无分组。分组可按组织或用户划分路由并分配管理权限。",
|
||||
"groups.createFirst": "创建第一个分组",
|
||||
"groups.admins": "管理员",
|
||||
"groups.owners": "来源",
|
||||
"groups.members": "成员",
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { onMounted, readonly, ref } from "vue";
|
||||
|
||||
export type ThemePreference = "auto" | "light" | "dark";
|
||||
|
||||
const STORAGE_KEY = "wh-theme";
|
||||
const theme = ref<ThemePreference>("auto");
|
||||
const isDark = ref(false);
|
||||
let initialized = false;
|
||||
|
||||
function resolveSystemDark(): boolean {
|
||||
if (typeof window === "undefined") return false;
|
||||
return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
}
|
||||
|
||||
function applyTheme(targetTheme: ThemePreference) {
|
||||
if (typeof document === "undefined") return;
|
||||
const root = document.documentElement;
|
||||
const darkActive = targetTheme === "dark" || (targetTheme === "auto" && resolveSystemDark());
|
||||
isDark.value = darkActive;
|
||||
if (darkActive) {
|
||||
root.classList.add("dark");
|
||||
root.setAttribute("data-theme", "dark");
|
||||
} else {
|
||||
root.classList.remove("dark");
|
||||
if (targetTheme === "light") {
|
||||
root.setAttribute("data-theme", "light");
|
||||
} else {
|
||||
root.removeAttribute("data-theme");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function useTheme() {
|
||||
function setTheme(next: ThemePreference) {
|
||||
theme.value = next;
|
||||
try {
|
||||
if (next === "auto") {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
} else {
|
||||
localStorage.setItem(STORAGE_KEY, next);
|
||||
}
|
||||
} catch {
|
||||
// localStorage may fail in sandboxed or private contexts
|
||||
}
|
||||
applyTheme(next);
|
||||
}
|
||||
|
||||
function cycleTheme() {
|
||||
const order: readonly ThemePreference[] = ["auto", "light", "dark"] as const;
|
||||
const idx = order.indexOf(theme.value);
|
||||
const next = order[(idx + 1) % order.length];
|
||||
if (next) {
|
||||
setTheme(next);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
if (stored === "light" || stored === "dark" || stored === "auto") {
|
||||
theme.value = stored;
|
||||
}
|
||||
} catch {
|
||||
// fallback to auto
|
||||
}
|
||||
|
||||
applyTheme(theme.value);
|
||||
|
||||
if (window.matchMedia) {
|
||||
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
mq.addEventListener?.("change", () => {
|
||||
if (theme.value === "auto") {
|
||||
applyTheme("auto");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
theme: readonly(theme),
|
||||
isDark: readonly(isDark),
|
||||
setTheme,
|
||||
cycleTheme,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user