feat(license): Pro 授权机制 — 离线许可码 + 免费版功能闸门
免费版:日志查询/部署管理/采集/用户管理/LDAP/设置;Pro(¥199 个人单实例永久 / ¥499 团队多实例永久): 日志分析、日志告警、智能运维(AI)、审计日志。 - 后端:HMAC-SHA256 离线许可码(签发 CLI / license --plan --edition --seats --customer --days; 永久=days 0),GET /system/license + POST activate;RequirePro 闸门挂 metrics/ai/audit; 过期自动回落免费;测试覆盖签发-校验/篡改/免费拒签 - 前端:菜单 Pro 项带锁标;四个 Pro 页面免费版渲染升级引导卡(功能清单+定价+页内激活); 设置页新增授权区(版本/席位/到期/激活入口);license 词典中英 - domains 注册提升到 main.tsx 全局(修复 license 命名空间在未引 domains 的页面显示裸键)
This commit is contained in:
1 parent
c60b827262
commit
9641503007
26 files changed
+632
-23
No files matched your search
@@ -3,6 +3,8 @@ import { useTranslation } from 'react-i18next'
|
||||
import { LLM_PROVIDERS, matchProvider } from './llmProviders'
|
||||
import { Loader2, Play, Save, Sparkles, PlugZap, History, ShieldCheck } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { ProGate } from '@/components/ProGate'
|
||||
import { useLicense } from '@/hooks/useLicense'
|
||||
import { PageContainer } from '@/components/PageContainer'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
@@ -44,6 +46,7 @@ function fmtNum(value: number): string {
|
||||
|
||||
export default function AiopsPage() {
|
||||
const { t } = useTranslation('aiops')
|
||||
const { pro } = useLicense()
|
||||
const [tab, setTab] = useState('analyze')
|
||||
|
||||
// ── 分析 ──
|
||||
@@ -213,6 +216,7 @@ export default function AiopsPage() {
|
||||
|
||||
const totalPages = Math.max(1, Math.ceil(runTotal / PAGE_SIZE))
|
||||
|
||||
if (!pro) return <ProGate featureKey="ai_ops" />
|
||||
return (
|
||||
<PageContainer title={t('title')} description={t('subtitle')}>
|
||||
<Tabs value={tab} onValueChange={setTab} className="space-y-4">
|
||||
|
||||
@@ -6,6 +6,8 @@ import { Switch } from '@/components/ui/switch'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { NotifySection } from '@/components/NotifySection'
|
||||
import { RuleFormDialog } from './components/RuleFormDialog'
|
||||
import { ProGate } from '@/components/ProGate'
|
||||
import { useLicense } from '@/hooks/useLicense'
|
||||
import { PageContainer } from '@/components/PageContainer'
|
||||
import { EmptyState } from '@/components/EmptyState'
|
||||
import { ConfirmDialog } from '@/components/ConfirmDialog'
|
||||
@@ -18,6 +20,7 @@ import { useTranslation } from 'react-i18next'
|
||||
/** 告警规则页:规则 CRUD + 立即检查 + 发送历史 */
|
||||
const AlertsPage = memo(function AlertsPage() {
|
||||
const { t } = useTranslation(['alerts', 'common'])
|
||||
const { pro } = useLicense()
|
||||
const [rules, setRules] = useState<AlertRule[]>([])
|
||||
const [sources, setSources] = useState<LogSource[]>([])
|
||||
const [channels, setChannels] = useState<NotifyChannel[]>([])
|
||||
@@ -100,6 +103,7 @@ const AlertsPage = memo(function AlertsPage() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!pro) return <ProGate featureKey="log_alerts" />
|
||||
return (
|
||||
<PageContainer
|
||||
title={t('title')}
|
||||
|
||||
@@ -6,6 +6,8 @@ import { BarChart3, Boxes, FileWarning, Loader2, RefreshCw, ScrollText } from 'l
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { ProGate } from '@/components/ProGate'
|
||||
import { useLicense } from '@/hooks/useLicense'
|
||||
import { PageContainer } from '@/components/PageContainer'
|
||||
import { EmptyState } from '@/components/EmptyState'
|
||||
import { ErrorState } from '@/components/ErrorState'
|
||||
@@ -34,6 +36,7 @@ const ALL_NAMESPACES = '__all__'
|
||||
*/
|
||||
const AnalysisPage = memo(function AnalysisPage() {
|
||||
const { t } = useTranslation('analysis')
|
||||
const { pro } = useLicense()
|
||||
const navigate = useNavigate()
|
||||
const isAdmin = getUser()?.role === 'admin'
|
||||
|
||||
@@ -255,6 +258,8 @@ const AnalysisPage = memo(function AnalysisPage() {
|
||||
const rankPageRows = rankRows.slice((rankSafePage - 1) * RANK_PAGE_SIZE, rankSafePage * RANK_PAGE_SIZE)
|
||||
|
||||
// 非 admin:菜单不可见,直访时给明确提示(后端 AdminAuth 403 兜底)
|
||||
if (!pro) return <ProGate featureKey="log_analysis" />
|
||||
|
||||
if (!isAdmin) {
|
||||
return (
|
||||
<PageContainer title={t('title')}>
|
||||
|
||||
@@ -5,6 +5,8 @@ import '@/i18n/domains'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { ProGate } from '@/components/ProGate'
|
||||
import { useLicense } from '@/hooks/useLicense'
|
||||
import { PageContainer } from '@/components/PageContainer'
|
||||
import { LoadingSpinner } from '@/components/LoadingSpinner'
|
||||
import { EmptyState } from '@/components/EmptyState'
|
||||
@@ -164,6 +166,7 @@ const DetailDialog = memo(function DetailDialog({
|
||||
*/
|
||||
export default function AuditPage() {
|
||||
const { t } = useTranslation('audit')
|
||||
const { pro } = useLicense()
|
||||
const [list, setList] = useState<AuditLog[]>([])
|
||||
const [total, setTotal] = useState(0)
|
||||
const [page, setPage] = useState(1)
|
||||
@@ -231,6 +234,8 @@ export default function AuditPage() {
|
||||
{ label: t('stat.total'), value: stats?.totalCount ?? 0, icon: History },
|
||||
]
|
||||
|
||||
if (!pro) return <ProGate featureKey="audit_log" />
|
||||
|
||||
return (
|
||||
<PageContainer
|
||||
title={t('title')}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { memo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { toast } from 'sonner'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { KeyRound } from 'lucide-react'
|
||||
import { licenseApi } from '@/api/license'
|
||||
import { useLicense } from '@/hooks/useLicense'
|
||||
import { getUser } from '@/lib/auth-storage'
|
||||
|
||||
/** 授权区块:当前版本状态 + 许可码激活(仅管理员可操作) */
|
||||
export const LicenseSection = memo(function LicenseSection() {
|
||||
const { t } = useTranslation('license')
|
||||
const { pro, info, reload } = useLicense()
|
||||
const isAdmin = getUser()?.role === 'admin'
|
||||
const [key, setKey] = useState('')
|
||||
const [activating, setActivating] = useState(false)
|
||||
|
||||
const activate = async () => {
|
||||
if (!key.trim()) return
|
||||
setActivating(true)
|
||||
try {
|
||||
await licenseApi.activate(key.trim())
|
||||
toast.success(t('activated'))
|
||||
setKey('')
|
||||
reload()
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : t('activateFailed'))
|
||||
} finally {
|
||||
setActivating(false)
|
||||
}
|
||||
}
|
||||
|
||||
const expiry = info?.expiresAt
|
||||
? info.expiresAt > 0
|
||||
? new Date(info.expiresAt * 1000).toLocaleDateString()
|
||||
: t('permanent')
|
||||
: null
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="flex items-center gap-2 text-base">
|
||||
<KeyRound className="size-4" />
|
||||
{t('title')}
|
||||
<Badge variant={pro ? 'default' : 'secondary'} className={pro ? 'bg-success text-success-foreground' : ''}>
|
||||
{pro ? 'Pro' : t('freeBadge')}
|
||||
</Badge>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="text-sm">
|
||||
{pro ? (
|
||||
<div className="grid gap-1 text-muted-foreground sm:grid-cols-2">
|
||||
<p>{t('edition')}: {info?.edition === 'team' ? t('teamTitle') : t('personalTitle')}</p>
|
||||
<p>{t('expiry')}: {expiry}</p>
|
||||
{info?.customer && <p>{t('customer')}: {info.customer}</p>}
|
||||
{Boolean(info?.seats) && <p>{t('seats')}: {info?.seats}</p>}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-muted-foreground">{t('freeDesc')}</p>
|
||||
)}
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<div className="flex gap-2">
|
||||
<Input value={key} onChange={e => setKey(e.target.value)} placeholder={t('keyPlaceholder')} className="font-mono text-sm" />
|
||||
<Button onClick={() => void activate()} disabled={activating || !key.trim()}>
|
||||
{activating ? t('activating') : t('activate')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
})
|
||||
@@ -3,11 +3,7 @@ import { useTranslation } from 'react-i18next'
|
||||
import { useTheme } from 'next-themes'
|
||||
import { Sun, Moon, Monitor, Clock } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import {
|
||||
DAY_START_HOUR,
|
||||
DAY_END_HOUR,
|
||||
setThemeAuto,
|
||||
} from '@/lib/theme-schedule'
|
||||
import { setThemeAuto } from '@/lib/theme-schedule'
|
||||
import { useScheduledTheme } from '@/hooks/useScheduledTheme'
|
||||
|
||||
type ThemeMode = 'light' | 'dark' | 'system' | 'auto'
|
||||
@@ -67,14 +63,6 @@ export const ThemeSection = memo(function ThemeSection() {
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
{auto && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('themeCard.autoHint', {
|
||||
start: String(DAY_START_HOUR).padStart(2, '0'),
|
||||
end: String(DAY_END_HOUR).padStart(2, '0'),
|
||||
})}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -12,6 +12,7 @@ import { toast } from 'sonner'
|
||||
import { PageContainer } from '@/components/PageContainer'
|
||||
import { ThemeSection } from './components/ThemeSection'
|
||||
import { RetentionSection } from './components/RetentionSection'
|
||||
import { LicenseSection } from './components/LicenseSection'
|
||||
import { LanguageSection } from '@/i18n/LanguageSection'
|
||||
import { Palette } from 'lucide-react'
|
||||
|
||||
@@ -69,6 +70,7 @@ const SettingsPage = memo(function SettingsPage() {
|
||||
|
||||
return (
|
||||
<PageContainer title={t('title')}>
|
||||
<LicenseSection />
|
||||
{/* 不再有内层 tab:LDAP / 镜像源 已拆成独立路由,
|
||||
由左侧「系统设置」分组的顶层 tab 切换(单层 tab 更好理解)。 */}
|
||||
<div className="space-y-6">
|
||||
|
||||
Reference in new issue
Block a user