mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 01:36:37 +08:00
feat(frontend): 控制台 next-intl 中英双语
接入无 URL 前缀的 zh-CN/en,顶栏与外观设置可切换语言;选择写入 cookie 后刷新生效。
This commit is contained in:
@@ -29,14 +29,19 @@ const match = ((): MatchFunction | null => {
|
||||
return null;
|
||||
})();
|
||||
|
||||
export interface SearchItem {
|
||||
export interface SearchItemSource {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
titleKey: string;
|
||||
descriptionKey: string;
|
||||
url: string;
|
||||
category: 'page' | 'feature' | 'setting' | 'admin';
|
||||
keywords: string[];
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export interface SearchItem extends SearchItemSource {
|
||||
title: string;
|
||||
description: string;
|
||||
matchRange?: [number, number];
|
||||
}
|
||||
|
||||
@@ -44,12 +49,12 @@ export interface SearchItem {
|
||||
* 全局搜索数据源
|
||||
* 包含所有可搜索的页面和功能
|
||||
*/
|
||||
export const searchData: SearchItem[] = [
|
||||
export const searchData: SearchItemSource[] = [
|
||||
// ==================== 总览 ====================
|
||||
{
|
||||
id: 'home',
|
||||
title: '总览',
|
||||
description: '返回控制台总览',
|
||||
titleKey: 'nav.dashboard',
|
||||
descriptionKey: 'search.items.homeDesc',
|
||||
url: '/',
|
||||
category: 'page',
|
||||
keywords: ['home', '主页', '首页', 'dashboard', '总览'],
|
||||
@@ -58,8 +63,8 @@ export const searchData: SearchItem[] = [
|
||||
// ==================== 文档库 ====================
|
||||
{
|
||||
id: 'docs-how-to-use',
|
||||
title: '使用帮助文档',
|
||||
description: '查看新手教程和集成示例',
|
||||
titleKey: 'nav.usageDocs',
|
||||
descriptionKey: 'search.items.usageDocsDesc',
|
||||
url: 'https://open-flare.pages.dev/',
|
||||
category: 'page',
|
||||
keywords: ['docs', '文档', '使用', 'how to', 'tutorial', '教程', 'help'],
|
||||
@@ -68,8 +73,8 @@ export const searchData: SearchItem[] = [
|
||||
// ==================== 业务控制台 ====================
|
||||
{
|
||||
id: 'console-nodes',
|
||||
title: '节点管理',
|
||||
description: '管理边缘节点、中继节点与内网穿透通道',
|
||||
titleKey: 'nav.nodes',
|
||||
descriptionKey: 'search.items.nodesDesc',
|
||||
url: '/nodes',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
@@ -84,32 +89,32 @@ export const searchData: SearchItem[] = [
|
||||
},
|
||||
{
|
||||
id: 'console-proxy-routes',
|
||||
title: '规则管理',
|
||||
description: '配置反向代理、路由匹配规则、WAF 策略与缓存设置',
|
||||
titleKey: 'nav.proxyRoutes',
|
||||
descriptionKey: 'search.items.proxyRoutesDesc',
|
||||
url: '/proxy-routes',
|
||||
category: 'page',
|
||||
keywords: ['route', '规则', '路由', '代理', '反向代理', 'proxy'],
|
||||
},
|
||||
{
|
||||
id: 'console-websites',
|
||||
title: '域名列表',
|
||||
description: '管理托管域名及证书绑定与监听配置',
|
||||
titleKey: 'nav.websites',
|
||||
descriptionKey: 'search.items.websitesDesc',
|
||||
url: '/websites',
|
||||
category: 'page',
|
||||
keywords: ['website', 'domain', '网站', '域名', '站点'],
|
||||
},
|
||||
{
|
||||
id: 'console-certificates',
|
||||
title: 'TLS 证书',
|
||||
description: '申请与管理 SSL/TLS 证书,支持自动续期',
|
||||
titleKey: 'nav.certificates',
|
||||
descriptionKey: 'search.items.certificatesDesc',
|
||||
url: '/certificates',
|
||||
category: 'page',
|
||||
keywords: ['certificate', 'ssl', 'tls', '证书', 'https', '加密'],
|
||||
},
|
||||
{
|
||||
id: 'console-dns-accounts',
|
||||
title: 'DNS 账号',
|
||||
description: '配置 DNS 服务商 API 凭证以自动申请证书及管理解析',
|
||||
titleKey: 'nav.dnsAccounts',
|
||||
descriptionKey: 'search.items.dnsAccountsDesc',
|
||||
url: '/dns-accounts',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
@@ -124,16 +129,16 @@ export const searchData: SearchItem[] = [
|
||||
},
|
||||
{
|
||||
id: 'console-origins',
|
||||
title: '源站地址',
|
||||
description: '管理反向代理的目标后端服务器与负载均衡组',
|
||||
titleKey: 'nav.origins',
|
||||
descriptionKey: 'search.items.originsDesc',
|
||||
url: '/origins',
|
||||
category: 'page',
|
||||
keywords: ['origin', '源站', '后端', 'backend', '服务器', '负载均衡'],
|
||||
},
|
||||
{
|
||||
id: 'console-responses',
|
||||
title: '响应页面',
|
||||
description: '配置源站错误页与离线兜底联系页',
|
||||
titleKey: 'nav.responses',
|
||||
descriptionKey: 'search.items.responsesDesc',
|
||||
url: '/responses',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
@@ -151,24 +156,24 @@ export const searchData: SearchItem[] = [
|
||||
},
|
||||
{
|
||||
id: 'console-waf',
|
||||
title: 'WAF 防火墙',
|
||||
description: '配置 Web 应用防火墙规则,阻断恶意请求',
|
||||
titleKey: 'nav.waf',
|
||||
descriptionKey: 'search.items.wafDesc',
|
||||
url: '/waf',
|
||||
category: 'page',
|
||||
keywords: ['waf', '防火墙', '安全', 'security', '拦截', '规则'],
|
||||
},
|
||||
{
|
||||
id: 'console-ip-groups',
|
||||
title: 'IP 组',
|
||||
description: '定义 IP 地址列表以在 WAF 或路由中实现黑白名单控制',
|
||||
titleKey: 'nav.ipGroups',
|
||||
descriptionKey: 'search.items.ipGroupsDesc',
|
||||
url: '/ip-groups',
|
||||
category: 'page',
|
||||
keywords: ['ip', 'ip group', 'ip组', '黑名单', '白名单', '访问控制'],
|
||||
},
|
||||
{
|
||||
id: 'console-rate-limits',
|
||||
title: '限流',
|
||||
description: '配置边缘站点默认并发与带宽限流策略',
|
||||
titleKey: 'nav.rateLimits',
|
||||
descriptionKey: 'search.items.rateLimitsDesc',
|
||||
url: '/rate-limits',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
@@ -182,32 +187,32 @@ export const searchData: SearchItem[] = [
|
||||
},
|
||||
{
|
||||
id: 'console-pages',
|
||||
title: 'Pages 静态托管',
|
||||
description: '上传或部署静态网页,提供全球 CDN 加速托管',
|
||||
titleKey: 'nav.pages',
|
||||
descriptionKey: 'search.items.pagesDesc',
|
||||
url: '/pages',
|
||||
category: 'page',
|
||||
keywords: ['pages', '静态托管', 'cdn', '网站', '部署', 'static'],
|
||||
},
|
||||
{
|
||||
id: 'console-config-versions',
|
||||
title: '版本发布',
|
||||
description: '查看、对比、发布与回滚系统配置版本',
|
||||
titleKey: 'nav.configVersions',
|
||||
descriptionKey: 'search.items.configVersionsDesc',
|
||||
url: '/config-versions',
|
||||
category: 'page',
|
||||
keywords: ['version', 'config', '版本', '发布', '回滚', '对比', '部署'],
|
||||
},
|
||||
{
|
||||
id: 'console-access-logs',
|
||||
title: '访问日志',
|
||||
description: '查看并检索全量网站访问请求日志与网络分析数据',
|
||||
titleKey: 'nav.accessLogs',
|
||||
descriptionKey: 'search.items.accessLogsDesc',
|
||||
url: '/access-logs',
|
||||
category: 'page',
|
||||
keywords: ['log', 'logs', '访问日志', '分析', '流量', '请求'],
|
||||
},
|
||||
{
|
||||
id: 'console-apply-logs',
|
||||
title: '应用记录',
|
||||
description: '查看节点配置下发、同步与生效的历史记录',
|
||||
titleKey: 'nav.applyLogs',
|
||||
descriptionKey: 'search.items.applyLogsDesc',
|
||||
url: '/apply-logs',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
@@ -222,8 +227,8 @@ export const searchData: SearchItem[] = [
|
||||
},
|
||||
{
|
||||
id: 'console-performance',
|
||||
title: '性能调优',
|
||||
description: '调优网络连接、代理超时与核心系统性能参数',
|
||||
titleKey: 'nav.performance',
|
||||
descriptionKey: 'search.items.performanceDesc',
|
||||
url: '/performance',
|
||||
category: 'page',
|
||||
keywords: ['performance', '性能', '调优', '优化', '参数', '连接', '超时'],
|
||||
@@ -232,32 +237,32 @@ export const searchData: SearchItem[] = [
|
||||
// ==================== 个人设置 ====================
|
||||
{
|
||||
id: 'settings',
|
||||
title: '全局设置',
|
||||
description: '配置应用个人偏好选项',
|
||||
titleKey: 'search.items.globalSettings',
|
||||
descriptionKey: 'search.items.settingsDesc',
|
||||
url: '/settings',
|
||||
category: 'setting',
|
||||
keywords: ['settings', '设置', '偏好', 'preferences'],
|
||||
},
|
||||
{
|
||||
id: 'settings-profile',
|
||||
title: '我的资料',
|
||||
description: '编辑昵称、头像和个人属性',
|
||||
titleKey: 'user.profile',
|
||||
descriptionKey: 'search.items.profileDesc',
|
||||
url: '/settings/profile',
|
||||
category: 'setting',
|
||||
keywords: ['profile', '资料', '个人', '我的', '信息', 'avatar'],
|
||||
},
|
||||
{
|
||||
id: 'settings-appearance',
|
||||
title: '外观设置',
|
||||
description: '配置系统显示主题(亮色/暗色)',
|
||||
titleKey: 'search.items.appearance',
|
||||
descriptionKey: 'search.items.appearanceDesc',
|
||||
url: '/settings/appearance',
|
||||
category: 'setting',
|
||||
keywords: ['appearance', '外观', '主题', 'theme', 'dark', 'light'],
|
||||
},
|
||||
{
|
||||
id: 'admin-settings',
|
||||
title: '系统设置',
|
||||
description: '管理系统登录注册与认证源配置 (管理员专属)',
|
||||
titleKey: 'nav.adminSettings',
|
||||
descriptionKey: 'search.items.adminSettingsDesc',
|
||||
url: '/admin/settings',
|
||||
category: 'admin',
|
||||
keywords: [
|
||||
@@ -272,24 +277,24 @@ export const searchData: SearchItem[] = [
|
||||
},
|
||||
{
|
||||
id: 'admin-system',
|
||||
title: '系统配置',
|
||||
description: '动态修改平台核心运行时配置 (管理员专属)',
|
||||
titleKey: 'nav.system',
|
||||
descriptionKey: 'search.items.systemDesc',
|
||||
url: '/admin/system',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '系统', '配置', 'system', 'configurations'],
|
||||
},
|
||||
{
|
||||
id: 'admin-users',
|
||||
title: '用户管理',
|
||||
description: '管理平台注册用户的活跃状态 (管理员专属)',
|
||||
titleKey: 'nav.users',
|
||||
descriptionKey: 'search.items.usersDesc',
|
||||
url: '/admin/users',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '用户', '管理', 'users', 'status'],
|
||||
},
|
||||
{
|
||||
id: 'admin-tasks',
|
||||
title: '异步任务管理',
|
||||
description: '下发与排查后台异步定时任务 (管理员专属)',
|
||||
titleKey: 'nav.tasks',
|
||||
descriptionKey: 'search.items.tasksDesc',
|
||||
url: '/admin/tasks',
|
||||
category: 'admin',
|
||||
keywords: [
|
||||
@@ -304,25 +309,24 @@ export const searchData: SearchItem[] = [
|
||||
},
|
||||
{
|
||||
id: 'admin-files',
|
||||
title: '存储管理',
|
||||
description: '查看、检索与清理上传到对象存储中的文件 (管理员专属)',
|
||||
titleKey: 'nav.storage',
|
||||
descriptionKey: 'search.items.storageDesc',
|
||||
url: '/admin/files',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '存储', '文件', 'files', 'upload', 's3'],
|
||||
},
|
||||
{
|
||||
id: 'admin-database',
|
||||
title: '数据管理',
|
||||
description:
|
||||
'监控数据库表大小、分页浏览物理表内容并支持交互式 SQL (管理员专属)',
|
||||
titleKey: 'nav.database',
|
||||
descriptionKey: 'search.items.databaseDesc',
|
||||
url: '/admin/database',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '数据库', 'database', 'sql', 'query', 'gorm'],
|
||||
},
|
||||
{
|
||||
id: 'admin-push',
|
||||
title: '通知推送',
|
||||
description: '配置与下发邮件、Lark 和 Telegram 渠道通知推送 (管理员专属)',
|
||||
titleKey: 'nav.push',
|
||||
descriptionKey: 'search.items.pushDesc',
|
||||
url: '/admin/push',
|
||||
category: 'admin',
|
||||
keywords: [
|
||||
@@ -338,8 +342,8 @@ export const searchData: SearchItem[] = [
|
||||
},
|
||||
{
|
||||
id: 'admin-logs',
|
||||
title: '系统日志',
|
||||
description: '查看系统日志与后台异步任务执行日志 (管理员专属)',
|
||||
titleKey: 'nav.logs',
|
||||
descriptionKey: 'search.items.logsDesc',
|
||||
url: '/admin/logs',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '日志', 'logs', 'system log', 'terminal'],
|
||||
@@ -350,11 +354,13 @@ export const searchData: SearchItem[] = [
|
||||
* 搜索功能
|
||||
* @param query 搜索关键词
|
||||
* @param isAdmin 是否为管理员
|
||||
* @param t 文案解析函数(layout 命名空间)
|
||||
* @returns 匹配的搜索结果
|
||||
*/
|
||||
export function searchItems(
|
||||
query: string,
|
||||
isAdmin: boolean = false,
|
||||
t: (key: string) => string,
|
||||
): SearchItem[] {
|
||||
const trimmedQuery = query.trim();
|
||||
|
||||
@@ -363,11 +369,17 @@ export function searchItems(
|
||||
? searchData
|
||||
: searchData.filter((item) => item.category !== 'admin');
|
||||
|
||||
const resolved = filteredData.map((item) => ({
|
||||
...item,
|
||||
title: t(item.titleKey),
|
||||
description: t(item.descriptionKey),
|
||||
}));
|
||||
|
||||
if (!trimmedQuery) {
|
||||
return filteredData;
|
||||
return resolved;
|
||||
}
|
||||
|
||||
return filteredData
|
||||
return resolved
|
||||
.map((item) => {
|
||||
// 优先匹配标题
|
||||
const titleMatch =
|
||||
|
||||
Reference in New Issue
Block a user