style: 美化用户隧道权限分配表单UI并统一代码格式

- 使用HeroUI Checkbox组件替换原生checkbox

- 重构隧道列表为card-based tile风格

- 添加选中/未选中/已分配状态视觉区分

- 应用eslint --fix代码格式统一

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
root
2026-02-04 02:22:28 +00:00
parent 72c2e28667
commit 6f6fececa8
31 changed files with 8080 additions and 5740 deletions
+49 -35
View File
@@ -1,15 +1,16 @@
import { getConfigByName, getConfigs } from '@/api';
import { getConfigByName, getConfigs } from "@/api";
export type SiteConfig = typeof siteConfig;
// 缓存相关常量
const CACHE_PREFIX = 'vite_config_';
const CACHE_PREFIX = "vite_config_";
const VERSION = import.meta.env.VITE_APP_VERSION || "dev";
const APP_VERSION = "1.0.3";
const GITHUB_REPO = import.meta.env.VITE_GITHUB_REPO || "https://github.com/Sagit-chu/flux-panel";
const GITHUB_REPO =
import.meta.env.VITE_GITHUB_REPO || "https://github.com/Sagit-chu/flux-panel";
const getInitialConfig = () => {
if (typeof window === 'undefined') {
if (typeof window === "undefined") {
return {
name: "flux",
version: VERSION,
@@ -18,15 +19,17 @@ const getInitialConfig = () => {
};
}
const cachedAppName = localStorage.getItem(CACHE_PREFIX + 'app_name');
if (cachedAppName) {
return {
name: cachedAppName,
version: VERSION,
app_version: APP_VERSION,
github_repo: GITHUB_REPO,
};
}
const cachedAppName = localStorage.getItem(CACHE_PREFIX + "app_name");
if (cachedAppName) {
return {
name: cachedAppName,
version: VERSION,
app_version: APP_VERSION,
github_repo: GITHUB_REPO,
};
}
return {
name: "flux",
version: VERSION,
@@ -41,44 +44,52 @@ export const configCache = {
// 获取缓存的配置
get: (key: string): string | null => {
const cacheKey = CACHE_PREFIX + key;
return localStorage.getItem(cacheKey);
return localStorage.getItem(cacheKey);
},
// 设置缓存的配置
set: (key: string, value: string): void => {
const cacheKey = CACHE_PREFIX + key;
localStorage.setItem(cacheKey, value);
localStorage.setItem(cacheKey, value);
},
// 删除指定配置的缓存
remove: (key: string): void => {
const cacheKey = CACHE_PREFIX + key;
localStorage.removeItem(cacheKey);
},
// 清空所有配置缓存
clear: (): void => {
// 获取所有localStorage的key
const keys = Object.keys(localStorage);
keys.forEach(key => {
if (key.startsWith(CACHE_PREFIX)) {
localStorage.removeItem(key);
}
});
}
// 获取所有localStorage的key
const keys = Object.keys(localStorage);
keys.forEach((key) => {
if (key.startsWith(CACHE_PREFIX)) {
localStorage.removeItem(key);
}
});
},
};
// 获取单个配置(优先从缓存)
export const getCachedConfig = async (key: string): Promise<string | null> => {
const cachedValue = configCache.get(key);
if (cachedValue !== null) {
return cachedValue;
}
const response = await getConfigByName(key);
if (response.code === 0 && response.data?.value) {
const value = response.data.value;
configCache.set(key, value);
return value;
}
@@ -88,29 +99,31 @@ export const getCachedConfig = async (key: string): Promise<string | null> => {
// 获取所有配置(优先从缓存)
export const getCachedConfigs = async (): Promise<Record<string, string>> => {
// 尝试从缓存获取所有配置
const configKeys = ['app_name'];
const configKeys = ["app_name"];
const cachedConfigs: Record<string, string> = {};
let hasCachedData = false;
configKeys.forEach(key => {
configKeys.forEach((key) => {
const cachedValue = configCache.get(key);
if (cachedValue !== null) {
cachedConfigs[key] = cachedValue;
hasCachedData = true;
}
});
// 从API获取最新配置
try {
const response = await getConfigs();
if (response.code === 0 && response.data) {
const configs = response.data;
// 将所有配置存入缓存
Object.entries(configs).forEach(([key, value]) => {
configCache.set(key, value as string);
});
return configs;
}
} catch (error) {
@@ -125,12 +138,13 @@ export const getCachedConfigs = async (): Promise<Record<string, string>> => {
// 动态更新网站配置
export const updateSiteConfig = async () => {
const appName = await getCachedConfig('app_name');
if (appName && appName !== siteConfig.name) {
siteConfig.name = appName;
// 更新页面标题
document.title = appName;
}
const appName = await getCachedConfig("app_name");
if (appName && appName !== siteConfig.name) {
siteConfig.name = appName;
// 更新页面标题
document.title = appName;
}
};
// 清除配置缓存的工具函数
@@ -140,7 +154,7 @@ export const updateSiteConfig = async () => {
export const clearConfigCache = (keys?: string[]) => {
if (keys && keys.length > 0) {
// 删除指定的配置缓存
keys.forEach(key => configCache.remove(key));
keys.forEach((key) => configCache.remove(key));
} else {
// 清空所有配置缓存
configCache.clear();
@@ -148,7 +162,7 @@ export const clearConfigCache = (keys?: string[]) => {
};
// 在页面加载时异步更新配置(如果有更新的话)
if (typeof window !== 'undefined') {
if (typeof window !== "undefined") {
// 延迟执行,避免阻塞初始渲染
setTimeout(() => {
updateSiteConfig();