feat(webui): Select/Textarea UI components + hide installed TLS cert
Add reusable Select (styled native select + chevron) and Textarea components matching Input's design language, and replace every native <select>/<textarea> across the app (system-panel, node-edit-dialog, notification-channel-dialog, settings customCss, widget note) with them. TLS cert UX: once a cert is installed, the sensitive PEM is no longer rendered on revisit — show an '已安装(未改变)' summary with 更改/删除 buttons; 更改 reveals the inputs again (with a 取消). Private key is never sent back to the client. Verified by tsc + vite build.
This commit is contained in:
7 files changed
+118
-44
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Select } from '@/components/ui/select';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type {
|
||||
HttpClientNetwork,
|
||||
@@ -447,17 +448,13 @@ function SelectField<T extends string>({
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>{label}</Label>
|
||||
<select
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value as T)}
|
||||
className="h-9 rounded-md border bg-background px-2 text-sm shadow-xs"
|
||||
>
|
||||
<Select value={value} onChange={(e) => onChange(e.target.value as T)}>
|
||||
{options.map((opt) => (
|
||||
<option key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/com
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
import { Slider } from '@/components/ui/slider';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
ACCENTS,
|
||||
DEFAULT_APPEARANCE,
|
||||
@@ -980,7 +981,7 @@ function AdvancedPanel() {
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<textarea
|
||||
<Textarea
|
||||
ref={cssRef}
|
||||
value={appearance.customCss}
|
||||
onChange={(e) => { setAppearance({ customCss: e.target.value }); if (cssWarn) setCssWarn(null); }}
|
||||
@@ -988,7 +989,7 @@ function AdvancedPanel() {
|
||||
maxLength={50000}
|
||||
spellCheck={false}
|
||||
placeholder={'/* 例如:放大侧栏字号 */\n.text-sidebar-foreground { font-size: 1.05em; }'}
|
||||
className="h-64 w-full resize-y rounded-lg border bg-card/40 p-3 font-mono text-[12px] leading-relaxed outline-none focus:border-primary"
|
||||
className="h-64 resize-y rounded-lg bg-card/40 p-3 font-mono text-[12px] leading-relaxed"
|
||||
/>
|
||||
{cssWarn && (
|
||||
<p className="flex items-start gap-1.5 text-[11px] text-warning">
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useId } from 'react';
|
||||
import { Bell, BookOpen, ExternalLink, Github, Globe, Link2, Server, Star } from 'lucide-react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useAppState } from '@/contexts/AppStateContext';
|
||||
import {
|
||||
@@ -172,13 +173,13 @@ export function NoteConfigForm({ config, onChange }: FormProps) {
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-sm text-muted-foreground">便签内容(纯文本,保留换行)</span>
|
||||
<textarea
|
||||
<Textarea
|
||||
value={c.text}
|
||||
onChange={(e) => onChange({ text: e.target.value.slice(0, NOTE_MAX) })}
|
||||
maxLength={NOTE_MAX}
|
||||
spellCheck={false}
|
||||
placeholder="写点备注、待办或快捷信息…"
|
||||
className="h-40 w-full resize-y rounded-lg border bg-card/40 p-3 text-sm leading-relaxed outline-none focus:border-primary"
|
||||
className="h-40 resize-y rounded-lg bg-card/40 p-3 text-sm leading-relaxed"
|
||||
/>
|
||||
<span className="text-right text-[11px] text-muted-foreground">{c.text.length} / {NOTE_MAX}</span>
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { NotificationChannel } from '@/types';
|
||||
@@ -100,12 +101,12 @@ export function NotificationChannelDialog(props: NotificationChannelDialogProps)
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>Body 模板</Label>
|
||||
<textarea
|
||||
<Textarea
|
||||
value={draft.bodyTemplate}
|
||||
rows={3}
|
||||
spellCheck={false}
|
||||
onChange={(e) => patch({ bodyTemplate: e.target.value })}
|
||||
className="w-full rounded-md border border-border bg-transparent px-3 py-2 font-mono text-xs leading-relaxed shadow-xs outline-none transition-[color,box-shadow] placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/40"
|
||||
className="font-mono text-xs leading-relaxed"
|
||||
/>
|
||||
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
||||
变量:<code className="font-mono">{'{uin}'}</code> <code className="font-mono">{'{nickname}'}</code>{' '}
|
||||
|
||||
@@ -6,21 +6,19 @@
|
||||
// won't take effect until the env var is removed).
|
||||
import { useEffect, useState } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import { AlertTriangle, Loader2, Lock, Save, ShieldCheck, Trash2 } from 'lucide-react';
|
||||
import { AlertTriangle, Loader2, Lock, Pencil, Save, ShieldCheck, Trash2 } from 'lucide-react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Select } from '@/components/ui/select';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { SystemSettingsResponse } from '@/types';
|
||||
|
||||
const TEXTAREA_CLS =
|
||||
'w-full min-h-28 rounded-lg border border-border bg-background px-3 py-2 font-mono text-xs ' +
|
||||
'outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
||||
|
||||
export function SystemPanel() {
|
||||
const api = useApi();
|
||||
const [data, setData] = useState<SystemSettingsResponse | null>(null);
|
||||
@@ -35,6 +33,9 @@ export function SystemPanel() {
|
||||
const [tlsEnabled, setTlsEnabled] = useState(false);
|
||||
const [certPem, setCertPem] = useState('');
|
||||
const [keyPem, setKeyPem] = useState('');
|
||||
// When a cert is already installed we hide the PEM inputs (sensitive) and
|
||||
// show a "已安装" summary + 更改 button; editing reveals the inputs again.
|
||||
const [editingCert, setEditingCert] = useState(false);
|
||||
|
||||
const load = async () => {
|
||||
try {
|
||||
@@ -83,6 +84,7 @@ export function SystemPanel() {
|
||||
try {
|
||||
await api.systemSettings.uploadCert(certPem, keyPem);
|
||||
setCertPem(''); setKeyPem('');
|
||||
setEditingCert(false);
|
||||
await load();
|
||||
flash('ok', '证书已保存,重启后生效');
|
||||
} catch (e) {
|
||||
@@ -96,6 +98,7 @@ export function SystemPanel() {
|
||||
setSaving(true);
|
||||
try {
|
||||
await api.systemSettings.deleteCert();
|
||||
setEditingCert(false);
|
||||
await load();
|
||||
flash('ok', '证书已删除');
|
||||
} catch (e) {
|
||||
@@ -140,14 +143,10 @@ export function SystemPanel() {
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">绑定地址<EnvBadge field="webuiHost" /></Label>
|
||||
<select
|
||||
value={host}
|
||||
onChange={(e) => setHost(e.target.value)}
|
||||
className="h-9 rounded-lg border border-border bg-background px-2 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
>
|
||||
<Select value={host} onChange={(e) => setHost(e.target.value)}>
|
||||
<option value="0.0.0.0">0.0.0.0(所有网卡)</option>
|
||||
<option value="127.0.0.1">127.0.0.1(仅本机)</option>
|
||||
</select>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">信任代理 (trust-proxy)<EnvBadge field="trustProxy" /></Label>
|
||||
@@ -177,27 +176,48 @@ export function SystemPanel() {
|
||||
<ToggleSwitch value={tlsEnabled} onChange={setTlsEnabled} ariaLabel="启用 HTTPS" />
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>证书 (cert.pem)</Label>
|
||||
<textarea className={TEXTAREA_CLS} value={certPem} onChange={(e) => setCertPem(e.target.value)} placeholder="-----BEGIN CERTIFICATE-----" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>私钥 (key.pem)</Label>
|
||||
<textarea className={TEXTAREA_CLS} value={keyPem} onChange={(e) => setKeyPem(e.target.value)} placeholder="-----BEGIN PRIVATE KEY-----" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={uploadCert} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存证书
|
||||
</Button>
|
||||
{data?.hasCert && (
|
||||
<Button variant="outline" onClick={deleteCert} disabled={saving} className="gap-1.5">
|
||||
<Trash2 className="h-4 w-4" /> 删除证书
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
私钥仅写入服务器 config/key.pem,不会回显。证书无效时保存会被拒绝;若启用了 TLS 但证书加载失败,启动时会自动回退到 HTTP。
|
||||
</p>
|
||||
{data?.hasCert && !editingCert ? (
|
||||
// Cert already installed — don't re-render the sensitive PEM. Show a
|
||||
// summary + actions; private key is never sent back to the client.
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground">
|
||||
<ShieldCheck className="h-4 w-4 text-emerald-500" />
|
||||
<span>证书与私钥已安装(出于安全不回显,未改变)。</span>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={() => setEditingCert(true)} className="gap-1.5">
|
||||
<Pencil className="h-4 w-4" /> 更改证书
|
||||
</Button>
|
||||
<Button variant="outline" onClick={deleteCert} disabled={saving} className="gap-1.5">
|
||||
<Trash2 className="h-4 w-4" /> 删除证书
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>证书 (cert.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={certPem} onChange={(e) => setCertPem(e.target.value)} placeholder="-----BEGIN CERTIFICATE-----" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>私钥 (key.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={keyPem} onChange={(e) => setKeyPem(e.target.value)} placeholder="-----BEGIN PRIVATE KEY-----" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={uploadCert} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存证书
|
||||
</Button>
|
||||
{data?.hasCert && editingCert && (
|
||||
<Button variant="outline" onClick={() => { setEditingCert(false); setCertPem(''); setKeyPem(''); }} className="gap-1.5">
|
||||
取消
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
私钥仅写入服务器 config/key.pem(0600 权限),不会回显。证书无效时保存会被拒绝;若启用了 TLS 但证书加载失败,启动时会自动回退到 HTTP。
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</motion.div>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import * as React from 'react';
|
||||
import { ChevronDown } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
// A styled native <select> matching Input's design language. Native keeps it
|
||||
// accessible + zero-dep; we hide the OS arrow (appearance-none) and draw our
|
||||
// own chevron for a consistent look. Pass <option>s as children.
|
||||
const Select = React.forwardRef<HTMLSelectElement, React.SelectHTMLAttributes<HTMLSelectElement>>(
|
||||
({ className, children, ...props }, ref) => (
|
||||
<div className="relative w-full">
|
||||
<select
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'flex h-9 w-full min-w-0 appearance-none rounded-md border border-border bg-transparent px-3 py-1 pr-8 text-sm shadow-xs transition-[color,box-shadow] outline-none',
|
||||
'focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/40',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</select>
|
||||
<ChevronDown className="pointer-events-none absolute right-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
Select.displayName = 'Select';
|
||||
|
||||
export { Select };
|
||||
@@ -0,0 +1,25 @@
|
||||
import * as React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
// Shares Input's design language (border-border, bg-transparent, shadow-xs,
|
||||
// focus ring). Callers may override surface specifics (height, resize, bg,
|
||||
// font-mono) via className — twMerge lets later classes win.
|
||||
const Textarea = React.forwardRef<HTMLTextAreaElement, React.TextareaHTMLAttributes<HTMLTextAreaElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<textarea
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'flex w-full min-w-0 rounded-md border border-border bg-transparent px-3 py-2 text-sm shadow-xs transition-[color,box-shadow] outline-none',
|
||||
'placeholder:text-muted-foreground',
|
||||
'focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/40',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
'aria-invalid:border-destructive aria-invalid:ring-destructive/20',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
Textarea.displayName = 'Textarea';
|
||||
|
||||
export { Textarea };
|
||||
Reference in new issue
Block a user