feat(webui): unify dialog feedback
Move confirmations, editors, and help surfaces onto one consistent interaction model. Preserve accessible focus handling while making destructive and in-progress actions clearer.
This commit is contained in:
13 files changed
+805
-608
No files matched your search
@@ -13,7 +13,6 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-alert-dialog": "^1.1.7",
|
|
||||||
"@radix-ui/react-dialog": "^1.1.7",
|
"@radix-ui/react-dialog": "^1.1.7",
|
||||||
"@radix-ui/react-label": "^2.1.3",
|
"@radix-ui/react-label": "^2.1.3",
|
||||||
"@radix-ui/react-scroll-area": "^1.2.4",
|
"@radix-ui/react-scroll-area": "^1.2.4",
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
import {
|
import { Modal } from '@/components/interior/modal';
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { ChangePasswordForm } from '@/components/pages/change-password-form';
|
import { ChangePasswordForm } from '@/components/pages/change-password-form';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
|
|
||||||
@@ -17,32 +11,30 @@ interface ChangePasswordDialogProps {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* In-app "修改访问密码" modal. The forced first-time flow uses the full-screen
|
* In-app "修改访问密码" modal. The forced first-time flow uses the full-screen
|
||||||
* ChangePasswordPage; this is the voluntary change a logged-in admin triggers
|
* the onboarding wizard; this is the voluntary change a logged-in admin triggers
|
||||||
* from 设置 → 账号安全. Both share ChangePasswordForm, so behaviour is identical.
|
* from 设置 → 账号安全. Both share ChangePasswordForm, so behaviour is identical.
|
||||||
*/
|
*/
|
||||||
export function ChangePasswordDialog({ open, onOpenChange, onSuccess }: ChangePasswordDialogProps) {
|
export function ChangePasswordDialog({ open, onOpenChange, onSuccess }: ChangePasswordDialogProps) {
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Modal
|
||||||
<DialogContent className="max-w-md">
|
open={open}
|
||||||
<DialogHeader>
|
onClose={() => onOpenChange(false)}
|
||||||
<DialogTitle>修改访问密码</DialogTitle>
|
title="修改访问密码"
|
||||||
<DialogDescription>
|
description="设置一个全新的强密码后,其它会话将被立即下线,需要重新登录。"
|
||||||
设置一个全新的强密码后,其它会话将被立即下线,需要重新登录。
|
closeLabel="关闭修改密码弹窗"
|
||||||
</DialogDescription>
|
>
|
||||||
</DialogHeader>
|
<ChangePasswordForm
|
||||||
<ChangePasswordForm
|
checkStrength={(p) => api.checkPasswordStrength(p)}
|
||||||
checkStrength={(p) => api.checkPasswordStrength(p)}
|
submit={(o, n) => api.changePassword(o, n)}
|
||||||
submit={(o, n) => api.changePassword(o, n)}
|
onSuccess={() => {
|
||||||
onSuccess={() => {
|
onSuccess();
|
||||||
onSuccess();
|
onOpenChange(false);
|
||||||
onOpenChange(false);
|
}}
|
||||||
}}
|
onCancel={() => onOpenChange(false)}
|
||||||
onCancel={() => onOpenChange(false)}
|
idPrefix="dialog-cpw"
|
||||||
idPrefix="dialog-cpw"
|
/>
|
||||||
/>
|
</Modal>
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -20,15 +20,8 @@ import {
|
|||||||
Server,
|
Server,
|
||||||
type LucideIcon,
|
type LucideIcon,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
import { Modal } from '@/components/interior/modal';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { DropdownSelect, type DropdownOption } from '@/components/ui/dropdown-select';
|
import { DropdownSelect, type DropdownOption } from '@/components/ui/dropdown-select';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
@@ -92,120 +85,27 @@ export function NodeEditDialog<K extends NetworkKind>(props: NodeEditDialogProps
|
|||||||
const role = ((draft as WsServerNetwork | WsClientNetwork).role ?? 'Universal') as WsRole;
|
const role = ((draft as WsServerNetwork | WsClientNetwork).role ?? 'Universal') as WsRole;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Modal
|
||||||
<DialogContent
|
open={open}
|
||||||
className="max-w-xl"
|
onClose={() => onOpenChange(false)}
|
||||||
viewportClassName="grid max-h-[calc(100dvh_-_2rem)] grid-rows-[auto_minmax(0,1fr)_auto] gap-0 overflow-hidden p-0"
|
title={(
|
||||||
>
|
<span className="inline-flex items-center gap-2">
|
||||||
<DialogHeader className="px-4 pb-4 pr-14 pt-5 sm:px-6 sm:pr-16 sm:pt-6">
|
<span className="grid size-8 place-items-center rounded-[10px] bg-primary/10 text-primary">
|
||||||
<div className="flex items-center gap-3">
|
<Icon className="size-4" />
|
||||||
<div className="flex size-11 shrink-0 items-center justify-center rounded-2xl bg-primary/10 text-primary">
|
</span>
|
||||||
<Icon className="size-5" />
|
{isEdit ? `编辑 ${tab.noun}` : `新建 ${tab.noun}`}
|
||||||
</div>
|
</span>
|
||||||
<div className="min-w-0">
|
)}
|
||||||
<DialogTitle>{isEdit ? `编辑 ${tab.noun}` : `新建 ${tab.noun}`}</DialogTitle>
|
description={tab.description}
|
||||||
<DialogDescription className="mt-0.5">{tab.description}</DialogDescription>
|
closeLabel="关闭节点编辑弹窗"
|
||||||
</div>
|
maxWidth={576}
|
||||||
</div>
|
maxHeight="calc(100dvh - 2rem)"
|
||||||
</DialogHeader>
|
footer={(
|
||||||
|
<>
|
||||||
<div className="min-h-0 overflow-y-auto overscroll-contain px-4 pb-5 sm:px-6">
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
<div className="flex flex-col gap-5">
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, y: 8 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ duration: 0.3, delay: 0 }}
|
|
||||||
className="flex items-center justify-between gap-4 rounded-2xl border border-border/60 bg-card/60 px-4 py-3.5 shadow-[0_1px_2px_rgb(0_0_0/0.04)]"
|
|
||||||
>
|
|
||||||
<div className="min-w-0">
|
|
||||||
<Label className="text-sm font-medium text-foreground">启用</Label>
|
|
||||||
<p className="mt-0.5 text-xs leading-relaxed text-muted-foreground">
|
|
||||||
关闭后保存即可保留配置但不启动该节点
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<ToggleSwitch
|
|
||||||
value={draft.enabled !== false}
|
|
||||||
onChange={(v) => patch({ enabled: v ? undefined : false } as Partial<AnyAdapter<K>>)}
|
|
||||||
ariaLabel="启用"
|
|
||||||
/>
|
|
||||||
</motion.div>
|
|
||||||
|
|
||||||
<Section caption="连接" delay={0.05}>
|
|
||||||
<div className="flex flex-col gap-3 p-4">
|
|
||||||
<Field
|
|
||||||
label="名称"
|
|
||||||
placeholder="自定义"
|
|
||||||
value={draft.name}
|
|
||||||
onChange={(v) => patch({ name: v } as Partial<AnyAdapter<K>>)}
|
|
||||||
error={blankName ? '请填写名称' : duplicateName ? '名称与其它节点重复' : undefined}
|
|
||||||
/>
|
|
||||||
<KindFields kind={kind} draft={draft} patch={patch} />
|
|
||||||
</div>
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<Section caption="鉴权" delay={0.1}>
|
|
||||||
<div className="p-4">
|
|
||||||
<TokenField
|
|
||||||
label="授权 Token"
|
|
||||||
placeholder="不填则无密码"
|
|
||||||
value={draft.accessToken}
|
|
||||||
onChange={(v) => patch({ accessToken: v || undefined } as Partial<AnyAdapter<K>>)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<Section caption="行为" delay={0.15}>
|
|
||||||
<div className="divide-y divide-border/60">
|
|
||||||
{isHttpServer && (
|
|
||||||
<SettingRow label="启用 WebSocket" desc="复用当前 HTTP 端口和授权 Token 接收 WebSocket 连接">
|
|
||||||
<ToggleSwitch
|
|
||||||
value={(draft as HttpServerNetwork).enableWebSocket === true}
|
|
||||||
onChange={(v) => patch({ enableWebSocket: v } as unknown as Partial<AnyAdapter<K>>)}
|
|
||||||
ariaLabel="启用 WebSocket"
|
|
||||||
/>
|
|
||||||
</SettingRow>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<SettingRow label="消息格式" desc="数组为标准 OneBot 段,CQ 码为兼容字符串">
|
|
||||||
<DropdownSelect
|
|
||||||
className="w-32"
|
|
||||||
ariaLabel="消息格式"
|
|
||||||
value={(draft.messageFormat ?? 'array') as MessageFormat}
|
|
||||||
options={FORMAT_OPTIONS}
|
|
||||||
onChange={(v) => patch({ messageFormat: v } as Partial<AnyAdapter<K>>)}
|
|
||||||
/>
|
|
||||||
</SettingRow>
|
|
||||||
|
|
||||||
{isWs && (
|
|
||||||
<SettingRow label="角色" desc="Universal 收发合一,Event / Api 分离">
|
|
||||||
<DropdownSelect
|
|
||||||
className="w-32"
|
|
||||||
ariaLabel="角色"
|
|
||||||
value={role}
|
|
||||||
options={WS_ROLE_OPTIONS}
|
|
||||||
onChange={(v) => patch({ role: v } as unknown as Partial<AnyAdapter<K>>)}
|
|
||||||
/>
|
|
||||||
</SettingRow>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<SettingRow label="上报自身消息" desc="将机器人自己发送的消息也作为 message_sent 事件上报">
|
|
||||||
<ToggleSwitch
|
|
||||||
value={!!draft.reportSelfMessage}
|
|
||||||
onChange={(v) => patch({ reportSelfMessage: v } as Partial<AnyAdapter<K>>)}
|
|
||||||
ariaLabel="上报自身消息"
|
|
||||||
/>
|
|
||||||
</SettingRow>
|
|
||||||
</div>
|
|
||||||
</Section>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<DialogFooter className="flex-row justify-end border-t border-border/60 bg-card px-4 py-3 sm:px-6 sm:py-4">
|
|
||||||
<Button className="flex-1 sm:flex-none" variant="outline" onClick={() => onOpenChange(false)}>
|
|
||||||
取消
|
取消
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
className="flex-1 sm:flex-none"
|
|
||||||
disabled={!canSave}
|
disabled={!canSave}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const cleaned = { ...draft, name: trimmedName } as AnyAdapter<K>;
|
const cleaned = { ...draft, name: trimmedName } as AnyAdapter<K>;
|
||||||
@@ -215,9 +115,98 @@ export function NodeEditDialog<K extends NetworkKind>(props: NodeEditDialogProps
|
|||||||
>
|
>
|
||||||
{isEdit ? '保存修改' : '创建节点'}
|
{isEdit ? '保存修改' : '创建节点'}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</>
|
||||||
</DialogContent>
|
)}
|
||||||
</Dialog>
|
>
|
||||||
|
<div className="flex flex-col gap-5">
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 8 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ duration: 0.3, delay: 0 }}
|
||||||
|
className="flex items-center justify-between gap-4 rounded-2xl border border-border/60 bg-card/60 px-4 py-3.5 shadow-[0_1px_2px_rgb(0_0_0/0.04)]"
|
||||||
|
>
|
||||||
|
<div className="min-w-0">
|
||||||
|
<Label className="text-sm font-medium text-foreground">启用</Label>
|
||||||
|
<p className="mt-0.5 text-xs leading-relaxed text-muted-foreground">
|
||||||
|
关闭后保存即可保留配置但不启动该节点
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<ToggleSwitch
|
||||||
|
value={draft.enabled !== false}
|
||||||
|
onChange={(v) => patch({ enabled: v ? undefined : false } as Partial<AnyAdapter<K>>)}
|
||||||
|
ariaLabel="启用"
|
||||||
|
/>
|
||||||
|
</motion.div>
|
||||||
|
|
||||||
|
<Section caption="连接" delay={0.05}>
|
||||||
|
<div className="flex flex-col gap-3 p-4">
|
||||||
|
<Field
|
||||||
|
label="名称"
|
||||||
|
placeholder="自定义"
|
||||||
|
value={draft.name}
|
||||||
|
onChange={(v) => patch({ name: v } as Partial<AnyAdapter<K>>)}
|
||||||
|
error={blankName ? '请填写名称' : duplicateName ? '名称与其它节点重复' : undefined}
|
||||||
|
/>
|
||||||
|
<KindFields kind={kind} draft={draft} patch={patch} />
|
||||||
|
</div>
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
<Section caption="鉴权" delay={0.1}>
|
||||||
|
<div className="p-4">
|
||||||
|
<TokenField
|
||||||
|
label="授权 Token"
|
||||||
|
placeholder="不填则无密码"
|
||||||
|
value={draft.accessToken}
|
||||||
|
onChange={(v) => patch({ accessToken: v || undefined } as Partial<AnyAdapter<K>>)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
<Section caption="行为" delay={0.15}>
|
||||||
|
<div className="divide-y divide-border/60">
|
||||||
|
{isHttpServer && (
|
||||||
|
<SettingRow label="启用 WebSocket" desc="复用当前 HTTP 端口和授权 Token 接收 WebSocket 连接">
|
||||||
|
<ToggleSwitch
|
||||||
|
value={(draft as HttpServerNetwork).enableWebSocket === true}
|
||||||
|
onChange={(v) => patch({ enableWebSocket: v } as unknown as Partial<AnyAdapter<K>>)}
|
||||||
|
ariaLabel="启用 WebSocket"
|
||||||
|
/>
|
||||||
|
</SettingRow>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<SettingRow label="消息格式" desc="数组为标准 OneBot 段,CQ 码为兼容字符串">
|
||||||
|
<DropdownSelect
|
||||||
|
className="w-32"
|
||||||
|
ariaLabel="消息格式"
|
||||||
|
value={(draft.messageFormat ?? 'array') as MessageFormat}
|
||||||
|
options={FORMAT_OPTIONS}
|
||||||
|
onChange={(v) => patch({ messageFormat: v } as Partial<AnyAdapter<K>>)}
|
||||||
|
/>
|
||||||
|
</SettingRow>
|
||||||
|
|
||||||
|
{isWs && (
|
||||||
|
<SettingRow label="角色" desc="Universal 收发合一,Event / Api 分离">
|
||||||
|
<DropdownSelect
|
||||||
|
className="w-32"
|
||||||
|
ariaLabel="角色"
|
||||||
|
value={role}
|
||||||
|
options={WS_ROLE_OPTIONS}
|
||||||
|
onChange={(v) => patch({ role: v } as unknown as Partial<AnyAdapter<K>>)}
|
||||||
|
/>
|
||||||
|
</SettingRow>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<SettingRow label="上报自身消息" desc="将机器人自己发送的消息也作为 message_sent 事件上报">
|
||||||
|
<ToggleSwitch
|
||||||
|
value={!!draft.reportSelfMessage}
|
||||||
|
onChange={(v) => patch({ reportSelfMessage: v } as Partial<AnyAdapter<K>>)}
|
||||||
|
ariaLabel="上报自身消息"
|
||||||
|
/>
|
||||||
|
</SettingRow>
|
||||||
|
</div>
|
||||||
|
</Section>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,11 @@
|
|||||||
import { useState, type ReactNode } from 'react';
|
import { useRef, useState, type ReactNode } from 'react';
|
||||||
import {
|
import { Modal } from '@/components/interior/modal';
|
||||||
AlertDialog,
|
import { Button } from '@/components/ui/button';
|
||||||
AlertDialogAction,
|
|
||||||
AlertDialogCancel,
|
|
||||||
AlertDialogContent,
|
|
||||||
AlertDialogDescription,
|
|
||||||
AlertDialogFooter,
|
|
||||||
AlertDialogHeader,
|
|
||||||
AlertDialogTitle,
|
|
||||||
} from '@/components/ui/alert-dialog';
|
|
||||||
import { buttonVariants } from '@/components/ui/button';
|
|
||||||
import {
|
import {
|
||||||
actionErrorMessage,
|
actionErrorMessage,
|
||||||
useActionFeedback,
|
useActionFeedback,
|
||||||
type ActionFeedbackOptions,
|
type ActionFeedbackOptions,
|
||||||
} from '@/contexts/ActionFeedbackContext';
|
} from '@/contexts/ActionFeedbackContext';
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
interface ConfirmDialogProps {
|
interface ConfirmDialogProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -47,6 +37,7 @@ export function ConfirmDialog({
|
|||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const { runAction } = useActionFeedback();
|
const { runAction } = useActionFeedback();
|
||||||
|
const cancelRef = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
const handleConfirm = async () => {
|
const handleConfirm = async () => {
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
@@ -74,36 +65,40 @@ export function ConfirmDialog({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AlertDialog open={open} onOpenChange={handleOpenChange}>
|
<Modal
|
||||||
<AlertDialogContent>
|
open={open}
|
||||||
<AlertDialogHeader>
|
onClose={() => handleOpenChange(false)}
|
||||||
<AlertDialogTitle>{title}</AlertDialogTitle>
|
title={title}
|
||||||
{description && (
|
description={description}
|
||||||
<AlertDialogDescription asChild>
|
showClose={false}
|
||||||
<div>{description}</div>
|
closeOnBackdrop={!busy}
|
||||||
</AlertDialogDescription>
|
closeOnEscape={!busy}
|
||||||
)}
|
initialFocusRef={cancelRef}
|
||||||
</AlertDialogHeader>
|
maxWidth={512}
|
||||||
|
footer={(
|
||||||
|
<>
|
||||||
|
<Button ref={cancelRef} type="button" variant="outline" disabled={busy} onClick={() => handleOpenChange(false)}>
|
||||||
|
{cancelText}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant={destructive ? 'destructive' : 'default'}
|
||||||
|
onClick={() => { void handleConfirm(); }}
|
||||||
|
disabled={busy || confirmDisabled}
|
||||||
|
>
|
||||||
|
{busy ? '处理中…' : confirmText}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
{error && (
|
{error && (
|
||||||
<div role="alert" className="rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
<div role="alert" className="rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{content}
|
{content}
|
||||||
<AlertDialogFooter>
|
</div>
|
||||||
<AlertDialogCancel disabled={busy}>{cancelText}</AlertDialogCancel>
|
</Modal>
|
||||||
<AlertDialogAction
|
|
||||||
onClick={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
void handleConfirm();
|
|
||||||
}}
|
|
||||||
className={cn(destructive && buttonVariants({ variant: 'destructive' }))}
|
|
||||||
disabled={busy || confirmDisabled}
|
|
||||||
>
|
|
||||||
{busy ? '处理中…' : confirmText}
|
|
||||||
</AlertDialogAction>
|
|
||||||
</AlertDialogFooter>
|
|
||||||
</AlertDialogContent>
|
|
||||||
</AlertDialog>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import { AlertTriangle, FlaskConical, History, Loader2, Play, RotateCcw, ShieldC
|
|||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { Picker } from '@/components/ui/picker';
|
import { Picker } from '@/components/ui/picker';
|
||||||
import { JsonTree } from '@/components/ui/json-tree';
|
import { JsonTree } from '@/components/ui/json-tree';
|
||||||
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
import { ParamField } from '@/components/debug/param-field';
|
import { ParamField } from '@/components/debug/param-field';
|
||||||
import { Segmented } from '@/components/debug/segmented';
|
import { Segmented } from '@/components/debug/segmented';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
@@ -363,43 +364,21 @@ export function ActionTester({ accounts, docs, presetAction }: { accounts: QQInf
|
|||||||
)}
|
)}
|
||||||
</motion.section>
|
</motion.section>
|
||||||
|
|
||||||
{confirmOpen && (
|
<ConfirmDialog
|
||||||
<ConfirmDestructive
|
open={confirmOpen}
|
||||||
action={actionName}
|
onOpenChange={setConfirmOpen}
|
||||||
uin={uin}
|
title="确认执行破坏性操作"
|
||||||
onCancel={() => setConfirmOpen(false)}
|
description={(
|
||||||
onConfirm={() => { setConfirmOpen(false); void runInvoke(); }}
|
<>
|
||||||
/>
|
即将以账号 <code className="font-mono text-foreground">{uin}</code> 执行{' '}
|
||||||
)}
|
<code className="font-mono text-foreground">{actionName}</code>,该操作会
|
||||||
</div>
|
<strong className="text-foreground">真实生效且通常不可撤销</strong>。确认继续?
|
||||||
);
|
</>
|
||||||
}
|
)}
|
||||||
|
confirmText="确认执行"
|
||||||
function ConfirmDestructive({ action, uin, onCancel, onConfirm }: { action: string; uin: string; onCancel: () => void; onConfirm: () => void }) {
|
destructive
|
||||||
useEffect(() => {
|
onConfirm={runInvoke}
|
||||||
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onCancel(); };
|
/>
|
||||||
window.addEventListener('keydown', onKey);
|
|
||||||
return () => window.removeEventListener('keydown', onKey);
|
|
||||||
}, [onCancel]);
|
|
||||||
return (
|
|
||||||
<div className="fixed inset-0 z-[70] flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm" onClick={onCancel}>
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, scale: 0.96 }} animate={{ opacity: 1, scale: 1 }}
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
className="w-full max-w-sm rounded-2xl border border-border/60 bg-card p-5 shadow-xl"
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-2.5">
|
|
||||||
<div className="flex h-9 w-9 items-center justify-center rounded-xl bg-destructive/12 text-destructive"><AlertTriangle className="h-5 w-5" /></div>
|
|
||||||
<h3 className="text-base font-semibold">确认执行破坏性操作</h3>
|
|
||||||
</div>
|
|
||||||
<p className="mt-3 text-sm text-muted-foreground">
|
|
||||||
即将以账号 <code className="font-mono text-foreground">{uin}</code> 执行 <code className="font-mono text-foreground">{action}</code>,该操作会<strong className="text-foreground">真实生效且通常不可撤销</strong>。确认继续?
|
|
||||||
</p>
|
|
||||||
<div className="mt-5 flex justify-end gap-2">
|
|
||||||
<button type="button" onClick={onCancel} className="rounded-lg border border-border px-4 py-2 text-sm font-medium hover:bg-muted">取消</button>
|
|
||||||
<button type="button" onClick={onConfirm} className="rounded-lg bg-destructive px-4 py-2 text-sm font-medium text-destructive-foreground hover:bg-destructive/90">确认执行</button>
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,464 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useId,
|
||||||
|
useLayoutEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
||||||
|
|
||||||
|
const EASE = [0.23, 1, 0.32, 1] as const;
|
||||||
|
|
||||||
|
const LEAVE = [0.4, 0, 1, 1] as const;
|
||||||
|
|
||||||
|
const SURFACE = { type: "spring", stiffness: 420, damping: 36, mass: 0.9 } as const;
|
||||||
|
|
||||||
|
const useIsomorphicLayoutEffect =
|
||||||
|
typeof window === "undefined" ? useEffect : useLayoutEffect;
|
||||||
|
|
||||||
|
const FOCUSABLE = [
|
||||||
|
"a[href]",
|
||||||
|
"area[href]",
|
||||||
|
"button:not([disabled])",
|
||||||
|
"input:not([disabled]):not([type='hidden'])",
|
||||||
|
"select:not([disabled])",
|
||||||
|
"textarea:not([disabled])",
|
||||||
|
"iframe",
|
||||||
|
"summary",
|
||||||
|
"[contenteditable='true']",
|
||||||
|
"[tabindex]:not([tabindex='-1'])",
|
||||||
|
].join(",");
|
||||||
|
|
||||||
|
function focusableWithin(root: HTMLElement): HTMLElement[] {
|
||||||
|
return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(
|
||||||
|
(el) =>
|
||||||
|
el.tabIndex !== -1 &&
|
||||||
|
!el.hasAttribute("inert") &&
|
||||||
|
el.getAttribute("aria-hidden") !== "true" &&
|
||||||
|
el.getClientRects().length > 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let locks = 0;
|
||||||
|
let releaseLock: (() => void) | null = null;
|
||||||
|
|
||||||
|
function lockDocumentScroll() {
|
||||||
|
locks += 1;
|
||||||
|
if (locks > 1) return;
|
||||||
|
|
||||||
|
const body = document.body;
|
||||||
|
const gap = window.innerWidth - document.documentElement.clientWidth;
|
||||||
|
const overflow = body.style.overflow;
|
||||||
|
const paddingRight = body.style.paddingRight;
|
||||||
|
const base = Number.parseFloat(window.getComputedStyle(body).paddingRight);
|
||||||
|
|
||||||
|
body.style.overflow = "hidden";
|
||||||
|
if (gap > 0) {
|
||||||
|
body.style.paddingRight = `${(Number.isFinite(base) ? base : 0) + gap}px`;
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseLock = () => {
|
||||||
|
body.style.overflow = overflow;
|
||||||
|
body.style.paddingRight = paddingRight;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function unlockDocumentScroll() {
|
||||||
|
locks = Math.max(0, locks - 1);
|
||||||
|
if (locks > 0) return;
|
||||||
|
releaseLock?.();
|
||||||
|
releaseLock = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stack: object[] = [];
|
||||||
|
|
||||||
|
export type UseModalOptions = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
closeOnEscape?: boolean;
|
||||||
|
closeOnBackdrop?: boolean;
|
||||||
|
lockScroll?: boolean;
|
||||||
|
initialFocusRef?: React.RefObject<HTMLElement | null>;
|
||||||
|
container?: HTMLElement | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ModalOverlayProps = {
|
||||||
|
ref: React.RefObject<HTMLDivElement | null>;
|
||||||
|
onPointerDown: (event: React.PointerEvent) => void;
|
||||||
|
onClick: (event: React.MouseEvent) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ModalPanelProps = {
|
||||||
|
ref: React.RefObject<HTMLDivElement | null>;
|
||||||
|
role: "dialog";
|
||||||
|
"aria-modal": true;
|
||||||
|
"aria-labelledby": string;
|
||||||
|
tabIndex: -1;
|
||||||
|
onKeyDown: (event: React.KeyboardEvent) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UseModalResult = {
|
||||||
|
target: HTMLElement | null;
|
||||||
|
titleId: string;
|
||||||
|
descriptionId: string;
|
||||||
|
overlayProps: ModalOverlayProps;
|
||||||
|
panelProps: ModalPanelProps;
|
||||||
|
close: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useModal({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
closeOnEscape = true,
|
||||||
|
closeOnBackdrop = true,
|
||||||
|
lockScroll = true,
|
||||||
|
initialFocusRef,
|
||||||
|
container,
|
||||||
|
}: UseModalOptions): UseModalResult {
|
||||||
|
const [target, setTarget] = useState<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
const overlayRef = useRef<HTMLDivElement>(null);
|
||||||
|
const panelRef = useRef<HTMLDivElement>(null);
|
||||||
|
const downedOutside = useRef(false);
|
||||||
|
|
||||||
|
const baseId = useId();
|
||||||
|
const titleId = `${baseId}-title`;
|
||||||
|
const descriptionId = `${baseId}-description`;
|
||||||
|
|
||||||
|
const latest = useRef({ onClose, closeOnEscape, closeOnBackdrop, initialFocusRef });
|
||||||
|
useEffect(() => {
|
||||||
|
latest.current = { onClose, closeOnEscape, closeOnBackdrop, initialFocusRef };
|
||||||
|
}, [onClose, closeOnEscape, closeOnBackdrop, initialFocusRef]);
|
||||||
|
|
||||||
|
const close = useCallback(() => latest.current.onClose(), []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTarget(container === undefined ? document.body : container);
|
||||||
|
}, [container]);
|
||||||
|
|
||||||
|
useIsomorphicLayoutEffect(() => {
|
||||||
|
if (!open || !lockScroll) return;
|
||||||
|
lockDocumentScroll();
|
||||||
|
return () => unlockDocumentScroll();
|
||||||
|
}, [open, lockScroll]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !target) return;
|
||||||
|
const overlay = overlayRef.current;
|
||||||
|
const parent = overlay?.parentElement;
|
||||||
|
if (!overlay || !parent) return;
|
||||||
|
|
||||||
|
const changed: Array<[Element, string | null]> = [];
|
||||||
|
for (const child of Array.from(parent.children)) {
|
||||||
|
if (child === overlay) continue;
|
||||||
|
changed.push([child, child.getAttribute("inert")]);
|
||||||
|
child.setAttribute("inert", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
for (const [child, previous] of changed) {
|
||||||
|
if (previous === null) child.removeAttribute("inert");
|
||||||
|
else child.setAttribute("inert", previous);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [open, target]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const token = {};
|
||||||
|
stack.push(token);
|
||||||
|
|
||||||
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key !== "Escape") return;
|
||||||
|
if (stack[stack.length - 1] !== token) return;
|
||||||
|
if (!latest.current.closeOnEscape) return;
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
latest.current.onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("keydown", onKeyDown);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("keydown", onKeyDown);
|
||||||
|
const index = stack.indexOf(token);
|
||||||
|
if (index > -1) stack.splice(index, 1);
|
||||||
|
};
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !target) return;
|
||||||
|
const onFocusIn = (event: FocusEvent) => {
|
||||||
|
const panel = panelRef.current;
|
||||||
|
const node = event.target as Node | null;
|
||||||
|
if (!panel || !node || panel.contains(node)) return;
|
||||||
|
panel.focus({ preventScroll: true });
|
||||||
|
};
|
||||||
|
document.addEventListener("focusin", onFocusIn);
|
||||||
|
return () => document.removeEventListener("focusin", onFocusIn);
|
||||||
|
}, [open, target]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !target) return;
|
||||||
|
const panel = panelRef.current;
|
||||||
|
if (!panel) return;
|
||||||
|
|
||||||
|
const previous =
|
||||||
|
document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||||
|
const preferred = latest.current.initialFocusRef?.current;
|
||||||
|
(preferred ?? focusableWithin(panel)[0] ?? panel).focus({ preventScroll: true });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (previous && previous.isConnected) previous.focus({ preventScroll: true });
|
||||||
|
};
|
||||||
|
}, [open, target]);
|
||||||
|
|
||||||
|
const onKeyDown = useCallback((event: React.KeyboardEvent) => {
|
||||||
|
if (event.key !== "Tab") return;
|
||||||
|
const panel = panelRef.current;
|
||||||
|
if (!panel) return;
|
||||||
|
|
||||||
|
const items = focusableWithin(panel);
|
||||||
|
if (items.length === 0) {
|
||||||
|
event.preventDefault();
|
||||||
|
panel.focus({ preventScroll: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const first = items[0];
|
||||||
|
const last = items[items.length - 1];
|
||||||
|
const active = document.activeElement;
|
||||||
|
|
||||||
|
if (event.shiftKey && (active === first || active === panel)) {
|
||||||
|
event.preventDefault();
|
||||||
|
last.focus({ preventScroll: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!event.shiftKey && active === last) {
|
||||||
|
event.preventDefault();
|
||||||
|
first.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onPointerDown = useCallback((event: React.PointerEvent) => {
|
||||||
|
const panel = panelRef.current;
|
||||||
|
downedOutside.current = !panel?.contains(event.target as Node);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onClick = useCallback((event: React.MouseEvent) => {
|
||||||
|
const panel = panelRef.current;
|
||||||
|
if (!latest.current.closeOnBackdrop) return;
|
||||||
|
if (panel?.contains(event.target as Node)) return;
|
||||||
|
if (!downedOutside.current) return;
|
||||||
|
downedOutside.current = false;
|
||||||
|
latest.current.onClose();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
target,
|
||||||
|
titleId,
|
||||||
|
descriptionId,
|
||||||
|
overlayProps: { ref: overlayRef, onPointerDown, onClick },
|
||||||
|
panelProps: {
|
||||||
|
ref: panelRef,
|
||||||
|
role: "dialog",
|
||||||
|
"aria-modal": true,
|
||||||
|
"aria-labelledby": titleId,
|
||||||
|
tabIndex: -1,
|
||||||
|
onKeyDown,
|
||||||
|
},
|
||||||
|
close,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const CLOSE_ICON = (
|
||||||
|
<svg width="14" height="14" viewBox="0 0 256 256" fill="none" aria-hidden="true">
|
||||||
|
<line
|
||||||
|
x1="200"
|
||||||
|
y1="56"
|
||||||
|
x2="56"
|
||||||
|
y2="200"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="16"
|
||||||
|
strokeLinecap="round"
|
||||||
|
/>
|
||||||
|
<line
|
||||||
|
x1="200"
|
||||||
|
y1="200"
|
||||||
|
x2="56"
|
||||||
|
y2="56"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="16"
|
||||||
|
strokeLinecap="round"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
|
export type ModalProps = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
title: React.ReactNode;
|
||||||
|
description?: React.ReactNode;
|
||||||
|
children?: React.ReactNode;
|
||||||
|
footer?: React.ReactNode;
|
||||||
|
closeLabel?: string;
|
||||||
|
showClose?: boolean;
|
||||||
|
closeOnEscape?: boolean;
|
||||||
|
closeOnBackdrop?: boolean;
|
||||||
|
lockScroll?: boolean;
|
||||||
|
initialFocusRef?: React.RefObject<HTMLElement | null>;
|
||||||
|
container?: HTMLElement | null;
|
||||||
|
maxWidth?: number;
|
||||||
|
maxHeight?: string;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function Modal({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
children,
|
||||||
|
footer,
|
||||||
|
closeLabel = "Close dialog",
|
||||||
|
showClose = true,
|
||||||
|
closeOnEscape = true,
|
||||||
|
closeOnBackdrop = true,
|
||||||
|
lockScroll = true,
|
||||||
|
initialFocusRef,
|
||||||
|
container,
|
||||||
|
maxWidth = 440,
|
||||||
|
maxHeight = "min(78vh, 620px)",
|
||||||
|
className = "",
|
||||||
|
}: ModalProps) {
|
||||||
|
const reduced = useReducedMotion();
|
||||||
|
|
||||||
|
const { target, titleId, descriptionId, overlayProps, panelProps } = useModal({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
closeOnEscape,
|
||||||
|
closeOnBackdrop,
|
||||||
|
lockScroll,
|
||||||
|
initialFocusRef,
|
||||||
|
container,
|
||||||
|
});
|
||||||
|
|
||||||
|
const variants = useMemo(() => {
|
||||||
|
if (reduced) {
|
||||||
|
return {
|
||||||
|
backdrop: {
|
||||||
|
closed: { opacity: 0 },
|
||||||
|
open: { opacity: 1, transition: { duration: 0 } },
|
||||||
|
gone: { opacity: 0, transition: { duration: 0 } },
|
||||||
|
},
|
||||||
|
panel: {
|
||||||
|
closed: { opacity: 0 },
|
||||||
|
open: { opacity: 1, transition: { duration: 0 } },
|
||||||
|
gone: { opacity: 0, transition: { duration: 0 } },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
backdrop: {
|
||||||
|
closed: { opacity: 0 },
|
||||||
|
open: { opacity: 1, transition: { duration: 0.2, ease: EASE } },
|
||||||
|
gone: { opacity: 0, transition: { duration: 0.15, ease: LEAVE } },
|
||||||
|
},
|
||||||
|
panel: {
|
||||||
|
closed: { opacity: 0, scale: 0.96, y: 12 },
|
||||||
|
open: {
|
||||||
|
opacity: 1,
|
||||||
|
scale: 1,
|
||||||
|
y: 0,
|
||||||
|
transition: { ...SURFACE, opacity: { duration: 0.16, ease: EASE } },
|
||||||
|
},
|
||||||
|
|
||||||
|
gone: {
|
||||||
|
opacity: 0,
|
||||||
|
scale: 0.98,
|
||||||
|
y: 6,
|
||||||
|
transition: { duration: 0.15, ease: LEAVE },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [reduced]);
|
||||||
|
|
||||||
|
if (!target) return null;
|
||||||
|
|
||||||
|
return createPortal(
|
||||||
|
<AnimatePresence>
|
||||||
|
{open ? (
|
||||||
|
<motion.div
|
||||||
|
key="modal"
|
||||||
|
{...overlayProps}
|
||||||
|
initial="closed"
|
||||||
|
animate="open"
|
||||||
|
exit="gone"
|
||||||
|
variants={{ closed: {}, open: {}, gone: {} }}
|
||||||
|
className="fixed inset-0 z-50 grid place-items-center p-4 sm:p-6"
|
||||||
|
>
|
||||||
|
<motion.div
|
||||||
|
aria-hidden="true"
|
||||||
|
variants={variants.backdrop}
|
||||||
|
style={{ touchAction: "none" }}
|
||||||
|
className="absolute inset-0 bg-black/50"
|
||||||
|
/>
|
||||||
|
<motion.div
|
||||||
|
{...panelProps}
|
||||||
|
aria-describedby={description ? descriptionId : undefined}
|
||||||
|
variants={variants.panel}
|
||||||
|
style={{ maxWidth, maxHeight }}
|
||||||
|
className={`relative flex w-full flex-col overflow-hidden rounded-[14px] border border-border bg-card text-foreground shadow-[0_28px_56px_-24px_rgba(24,22,20,0.45)] outline-none ${className}`}
|
||||||
|
>
|
||||||
|
<div className="flex shrink-0 items-start gap-3 px-4 pb-3 pt-4">
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<h2
|
||||||
|
id={titleId}
|
||||||
|
className="text-[15px] font-medium tracking-[-0.01em] text-foreground"
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</h2>
|
||||||
|
{description ? (
|
||||||
|
<div
|
||||||
|
id={descriptionId}
|
||||||
|
className="mt-1 text-[12.5px] leading-relaxed text-muted-foreground"
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showClose ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onClose}
|
||||||
|
aria-label={closeLabel}
|
||||||
|
className="-mr-1 -mt-1 grid size-7 shrink-0 place-items-center rounded-[7px] text-muted-foreground outline-none transition-colors duration-150 hover:bg-muted hover:text-foreground focus-visible:bg-primary/[0.06] focus-visible:text-foreground focus-visible:shadow-[inset_0_0_0_1px_var(--ring)]"
|
||||||
|
>
|
||||||
|
{CLOSE_ICON}
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{children ? (
|
||||||
|
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-4 text-[13px] leading-relaxed">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{footer ? (
|
||||||
|
<div className="flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3">
|
||||||
|
{footer}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</motion.div>
|
||||||
|
</motion.div>
|
||||||
|
) : null}
|
||||||
|
</AnimatePresence>,
|
||||||
|
target,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { motion } from 'motion/react';
|
import { motion } from 'motion/react';
|
||||||
import { ArrowRight, KeyRound, Sparkles } from 'lucide-react';
|
import { ArrowRight, KeyRound, Sparkles } from 'lucide-react';
|
||||||
|
import { Modal } from '@/components/interior/modal';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Card, CardContent } from '@/components/ui/card';
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
|
||||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||||
import { PasswordVisibilityIcon } from '@/components/ui/password-visibility-icon';
|
import { PasswordVisibilityIcon } from '@/components/ui/password-visibility-icon';
|
||||||
import { ThemeToggle } from '@/components/theme-toggle';
|
import { ThemeToggle } from '@/components/theme-toggle';
|
||||||
@@ -175,15 +175,15 @@ export function LoginPage({ onLogin }: LoginPageProps) {
|
|||||||
</motion.button>
|
</motion.button>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|
||||||
<Dialog open={helpOpen} onOpenChange={setHelpOpen}>
|
<Modal
|
||||||
<DialogContent className="max-w-sm rounded-2xl">
|
open={helpOpen}
|
||||||
<DialogHeader>
|
onClose={() => setHelpOpen(false)}
|
||||||
<DialogTitle>界面有点卡顿?</DialogTitle>
|
title="界面有点卡顿?"
|
||||||
<DialogDescription>
|
description="登录页背景是一个跟随鼠标的动态线条效果,在部分设备上可能比较吃性能。可以在这里关掉它——该开关仅作用于本设备的登录页,与系统的动效设置相互独立。"
|
||||||
登录页背景是一个跟随鼠标的动态线条效果,在部分设备上可能比较吃性能。可以在这里关掉它——该开关仅作用于本设备的登录页,与系统的动效设置相互独立。
|
closeLabel="关闭性能设置弹窗"
|
||||||
</DialogDescription>
|
maxWidth={384}
|
||||||
</DialogHeader>
|
>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
<div className="flex items-center justify-between gap-4 rounded-xl border bg-muted/30 px-4 py-3">
|
<div className="flex items-center justify-between gap-4 rounded-xl border bg-muted/30 px-4 py-3">
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
<p className="text-sm font-medium">登录页动态背景</p>
|
<p className="text-sm font-medium">登录页动态背景</p>
|
||||||
@@ -195,8 +195,8 @@ export function LoginPage({ onLogin }: LoginPageProps) {
|
|||||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||||
登录后,你还可以在「系统设置 → 无障碍」里进一步「减弱动效」或「关闭全部动效」。
|
登录后,你还可以在「系统设置 → 无障碍」里进一步「减弱动效」或「关闭全部动效」。
|
||||||
</p>
|
</p>
|
||||||
</DialogContent>
|
</div>
|
||||||
</Dialog>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ import { ScrollArea } from '@/components/ui/scroll-area';
|
|||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
|
import { Modal } from '@/components/interior/modal';
|
||||||
import { cn, formatBytes, formatUptime } from '@/lib/utils';
|
import { cn, formatBytes, formatUptime } from '@/lib/utils';
|
||||||
import type { AppPath } from '@/router';
|
import type { AppPath } from '@/router';
|
||||||
import type {
|
import type {
|
||||||
@@ -36,7 +37,6 @@ import {
|
|||||||
type AccountConfig, type AlertsConfig, type ConnectionsConfig, type HostConfig,
|
type AccountConfig, type AlertsConfig, type ConnectionsConfig, type HostConfig,
|
||||||
type LinkConfig, type NoteConfig, type SessionsConfig,
|
type LinkConfig, type NoteConfig, type SessionsConfig,
|
||||||
} from '@/lib/dashboard-layout';
|
} from '@/lib/dashboard-layout';
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
|
||||||
import { DashboardGrid, WIDGET_DRAG_TYPE, type GridCoord } from '@/components/pages/dashboard-grid';
|
import { DashboardGrid, WIDGET_DRAG_TYPE, type GridCoord } from '@/components/pages/dashboard-grid';
|
||||||
import {
|
import {
|
||||||
AccountConfigForm, AlertsConfigForm, ConnectionsConfigForm, HostConfigForm,
|
AccountConfigForm, AlertsConfigForm, ConnectionsConfigForm, HostConfigForm,
|
||||||
@@ -212,11 +212,14 @@ export function OverviewPage() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Dialog open={!!configId} onOpenChange={(o) => { if (!o) setConfigId(null); }}>
|
<Modal
|
||||||
<DialogContent className="max-w-sm">
|
open={!!configId}
|
||||||
<DialogHeader>
|
onClose={() => setConfigId(null)}
|
||||||
<DialogTitle>{configBlock ? `${widgetLabel(configBlock.id)} · 设置` : '设置'}</DialogTitle>
|
title={configBlock ? `${widgetLabel(configBlock.id)} · 设置` : '设置'}
|
||||||
</DialogHeader>
|
closeLabel="关闭卡片设置弹窗"
|
||||||
|
maxWidth={384}
|
||||||
|
>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
{configBlock?.id === 'alerts' && <AlertsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('alerts', c)} />}
|
{configBlock?.id === 'alerts' && <AlertsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('alerts', c)} />}
|
||||||
{configBlock?.id === 'sessions' && <SessionsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('sessions', c)} />}
|
{configBlock?.id === 'sessions' && <SessionsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('sessions', c)} />}
|
||||||
{configBlock?.id === 'host' && <HostConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('host', c)} />}
|
{configBlock?.id === 'host' && <HostConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('host', c)} />}
|
||||||
@@ -224,8 +227,8 @@ export function OverviewPage() {
|
|||||||
{configBlock?.id === 'note' && <NoteConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('note', c)} />}
|
{configBlock?.id === 'note' && <NoteConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('note', c)} />}
|
||||||
{configBlock?.id === 'link' && <LinkConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('link', c)} />}
|
{configBlock?.id === 'link' && <LinkConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('link', c)} />}
|
||||||
{configBlock?.id === 'account' && <AccountConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('account', c)} />}
|
{configBlock?.id === 'account' && <AccountConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('account', c)} />}
|
||||||
</DialogContent>
|
</div>
|
||||||
</Dialog>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { Eye, User, UserX } from 'lucide-react';
|
import { Eye, User, UserX } from 'lucide-react';
|
||||||
|
import { Modal } from '@/components/interior/modal';
|
||||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
@@ -83,85 +77,82 @@ export function ProcessProbeDialog({ pid, processName, open, onOpenChange, onLoa
|
|||||||
}, [open, probe]);
|
}, [open, probe]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Modal
|
||||||
<DialogContent className="sm:max-w-md">
|
open={open}
|
||||||
<DialogHeader>
|
onClose={() => onOpenChange(false)}
|
||||||
<DialogTitle>查看登录状态</DialogTitle>
|
title="查看登录状态"
|
||||||
<DialogDescription>
|
description={`${processName} (PID ${pid})`}
|
||||||
{processName} (PID {pid})
|
closeLabel="关闭登录状态弹窗"
|
||||||
</DialogDescription>
|
>
|
||||||
</DialogHeader>
|
<div className="space-y-4">
|
||||||
|
<SkeletonSwap
|
||||||
<div className="space-y-4">
|
ready={!loading}
|
||||||
<SkeletonSwap
|
reserve={128}
|
||||||
ready={!loading}
|
lines={5}
|
||||||
reserve={128}
|
lineHeight={24}
|
||||||
lines={5}
|
label="登录状态"
|
||||||
lineHeight={24}
|
className={!loading ? 'skeleton-swap-fluid min-h-32' : ''}
|
||||||
label="登录状态"
|
>
|
||||||
className={!loading ? 'skeleton-swap-fluid min-h-32' : ''}
|
{!loading ? (
|
||||||
>
|
error ? (
|
||||||
{!loading ? (
|
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
||||||
error ? (
|
<UserX className="size-8" strokeWidth={1.5} />
|
||||||
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
<p className="text-sm">{error}</p>
|
||||||
<UserX className="size-8" strokeWidth={1.5} />
|
</div>
|
||||||
<p className="text-sm">{error}</p>
|
) : info ? (
|
||||||
</div>
|
<div className="space-y-4">
|
||||||
) : info ? (
|
{info.loggedIn ? (
|
||||||
<div className="space-y-4">
|
<div className="flex items-center gap-4 rounded-lg border bg-card/50 p-4">
|
||||||
{info.loggedIn ? (
|
<Avatar className="size-14">
|
||||||
<div className="flex items-center gap-4 rounded-lg border bg-card/50 p-4">
|
<AvatarImage src={qqAvatarUrl(info.uin)} alt={info.uin} />
|
||||||
<Avatar className="size-14">
|
<AvatarFallback>
|
||||||
<AvatarImage src={qqAvatarUrl(info.uin)} alt={info.uin} />
|
<User className="size-6" />
|
||||||
<AvatarFallback>
|
</AvatarFallback>
|
||||||
<User className="size-6" />
|
</Avatar>
|
||||||
</AvatarFallback>
|
<div className="flex-1">
|
||||||
</Avatar>
|
<div className="flex items-center gap-2">
|
||||||
<div className="flex-1">
|
<span className="font-semibold">{info.nickName || info.uin}</span>
|
||||||
<div className="flex items-center gap-2">
|
<Badge variant="success">已登录</Badge>
|
||||||
<span className="font-semibold">{info.nickName || info.uin}</span>
|
</div>
|
||||||
<Badge variant="success">已登录</Badge>
|
<div className="mt-1 text-sm text-muted-foreground">UIN: {info.uin}</div>
|
||||||
</div>
|
{info.uid && (
|
||||||
<div className="mt-1 text-sm text-muted-foreground">UIN: {info.uin}</div>
|
<div className="mt-0.5 truncate font-mono text-xs text-muted-foreground">
|
||||||
{info.uid && (
|
|
||||||
<div className="mt-0.5 truncate font-mono text-xs text-muted-foreground">
|
|
||||||
UID: {info.uid}
|
UID: {info.uid}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="mt-1 text-xs text-muted-foreground">端口: {info.port}</div>
|
<div className="mt-1 text-xs text-muted-foreground">端口: {info.port}</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
</div>
|
||||||
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
) : (
|
||||||
<UserX className="size-8" strokeWidth={1.5} />
|
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
||||||
<div className="text-center">
|
<UserX className="size-8" strokeWidth={1.5} />
|
||||||
<p className="text-sm font-medium">等待登录</p>
|
<div className="text-center">
|
||||||
<p className="mt-1 text-xs">端口 {info.port} 已响应,但未检测到登录账号</p>
|
<p className="text-sm font-medium">等待登录</p>
|
||||||
</div>
|
<p className="mt-1 text-xs">端口 {info.port} 已响应,但未检测到登录账号</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</div>
|
)}
|
||||||
) : null
|
</div>
|
||||||
) : null}
|
) : null
|
||||||
</SkeletonSwap>
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
|
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="outline" size="sm" onClick={() => onOpenChange(false)}>
|
<Button variant="outline" size="sm" onClick={() => onOpenChange(false)}>
|
||||||
关闭
|
关闭
|
||||||
</Button>
|
</Button>
|
||||||
{!loading && info?.loggedIn && onLoad && (
|
{!loading && info?.loggedIn && onLoad && (
|
||||||
<Button size="sm" onClick={onLoad}>
|
<Button size="sm" onClick={onLoad}>
|
||||||
加载
|
加载
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{!loading && (
|
{!loading && (
|
||||||
<Button size="sm" onClick={probe}>
|
<Button size="sm" onClick={probe}>
|
||||||
<Eye className="size-3.5" /> 重新探测
|
<Eye className="size-3.5" /> 重新探测
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</div>
|
||||||
</Dialog>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -3,15 +3,8 @@
|
|||||||
// The channel id is the stable key per-account opt-ins reference, so it's
|
// The channel id is the stable key per-account opt-ins reference, so it's
|
||||||
// editable only on create and locked on edit.
|
// editable only on create and locked on edit.
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { Modal } from '@/components/interior/modal';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
@@ -64,68 +57,15 @@ export function NotificationChannelDialog(props: NotificationChannelDialogProps)
|
|||||||
const urlError = urlBlank ? '请填写 Webhook URL' : urlBad ? '必须是 http(s) 地址' : undefined;
|
const urlError = urlBlank ? '请填写 Webhook URL' : urlBad ? '必须是 http(s) 地址' : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Modal
|
||||||
<DialogContent className="max-w-xl">
|
open={open}
|
||||||
<DialogHeader>
|
onClose={() => onOpenChange(false)}
|
||||||
<DialogTitle>{isEdit ? '编辑渠道' : '新建渠道'}</DialogTitle>
|
title={isEdit ? '编辑渠道' : '新建渠道'}
|
||||||
<DialogDescription>账号上线 / 下线时向该 Webhook POST 一条渲染后的通知。</DialogDescription>
|
description="账号上线 / 下线时向该 Webhook POST 一条渲染后的通知。"
|
||||||
</DialogHeader>
|
closeLabel="关闭渠道编辑弹窗"
|
||||||
|
maxWidth={576}
|
||||||
<div className="flex flex-col gap-3">
|
footer={(
|
||||||
<div className="grid gap-3 sm:grid-cols-2">
|
<>
|
||||||
<Field
|
|
||||||
label="渠道 ID"
|
|
||||||
placeholder="dingtalk"
|
|
||||||
value={draft.id}
|
|
||||||
disabled={isEdit}
|
|
||||||
hint={isEdit ? '创建后不可更改' : '账号据此勾选;字母/数字/. _ -'}
|
|
||||||
error={idError}
|
|
||||||
onChange={(v) => patch({ id: v })}
|
|
||||||
/>
|
|
||||||
<Field
|
|
||||||
label="显示名"
|
|
||||||
placeholder="钉钉群机器人"
|
|
||||||
value={draft.name}
|
|
||||||
onChange={(v) => patch({ name: v })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Field
|
|
||||||
label="Webhook URL"
|
|
||||||
type="url"
|
|
||||||
placeholder="https://oapi.dingtalk.com/robot/send?access_token=…"
|
|
||||||
value={draft.url}
|
|
||||||
error={urlError}
|
|
||||||
onChange={(v) => patch({ url: v })}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className="flex flex-col gap-1.5">
|
|
||||||
<Label>Body 模板</Label>
|
|
||||||
<Textarea
|
|
||||||
value={draft.bodyTemplate}
|
|
||||||
rows={3}
|
|
||||||
spellCheck={false}
|
|
||||||
onChange={(e) => patch({ bodyTemplate: e.target.value })}
|
|
||||||
className="font-mono text-xs leading-relaxed"
|
|
||||||
/>
|
|
||||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
|
||||||
变量:<code className="font-mono">{'{uin}'}</code> <code className="font-mono">{'{nickname}'}</code>{' '}
|
|
||||||
<code className="font-mono">{'{event}'}</code>(offline/online) <code className="font-mono">{'{time}'}</code>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between rounded-lg border bg-card/40 p-3">
|
|
||||||
<div className="min-w-0">
|
|
||||||
<Label className="text-sm">启用</Label>
|
|
||||||
<p className="mt-1 text-xs leading-relaxed text-muted-foreground">
|
|
||||||
关闭后保留配置但不推送;账号侧对应开关会被锁定并关闭。
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<ToggleSwitch value={draft.enabled} onChange={(v) => patch({ enabled: v })} ariaLabel="启用渠道" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<DialogFooter>
|
|
||||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
取消
|
取消
|
||||||
</Button>
|
</Button>
|
||||||
@@ -138,9 +78,63 @@ export function NotificationChannelDialog(props: NotificationChannelDialogProps)
|
|||||||
>
|
>
|
||||||
{isEdit ? '保存修改' : '创建渠道'}
|
{isEdit ? '保存修改' : '创建渠道'}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</>
|
||||||
</DialogContent>
|
)}
|
||||||
</Dialog>
|
>
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<div className="grid gap-3 sm:grid-cols-2">
|
||||||
|
<Field
|
||||||
|
label="渠道 ID"
|
||||||
|
placeholder="dingtalk"
|
||||||
|
value={draft.id}
|
||||||
|
disabled={isEdit}
|
||||||
|
hint={isEdit ? '创建后不可更改' : '账号据此勾选;字母/数字/. _ -'}
|
||||||
|
error={idError}
|
||||||
|
onChange={(v) => patch({ id: v })}
|
||||||
|
/>
|
||||||
|
<Field
|
||||||
|
label="显示名"
|
||||||
|
placeholder="钉钉群机器人"
|
||||||
|
value={draft.name}
|
||||||
|
onChange={(v) => patch({ name: v })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Field
|
||||||
|
label="Webhook URL"
|
||||||
|
type="url"
|
||||||
|
placeholder="https://oapi.dingtalk.com/robot/send?access_token=…"
|
||||||
|
value={draft.url}
|
||||||
|
error={urlError}
|
||||||
|
onChange={(v) => patch({ url: v })}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label>Body 模板</Label>
|
||||||
|
<Textarea
|
||||||
|
value={draft.bodyTemplate}
|
||||||
|
rows={3}
|
||||||
|
spellCheck={false}
|
||||||
|
onChange={(e) => patch({ bodyTemplate: e.target.value })}
|
||||||
|
className="font-mono text-xs leading-relaxed"
|
||||||
|
/>
|
||||||
|
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||||
|
变量:<code className="font-mono">{'{uin}'}</code> <code className="font-mono">{'{nickname}'}</code>{' '}
|
||||||
|
<code className="font-mono">{'{event}'}</code>(offline/online) <code className="font-mono">{'{time}'}</code>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between rounded-lg border bg-card/40 p-3">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<Label className="text-sm">启用</Label>
|
||||||
|
<p className="mt-1 text-xs leading-relaxed text-muted-foreground">
|
||||||
|
关闭后保留配置但不推送;账号侧对应开关会被锁定并关闭。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<ToggleSwitch value={draft.enabled} onChange={(v) => patch({ enabled: v })} ariaLabel="启用渠道" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { buttonVariants } from '@/components/ui/button';
|
|
||||||
|
|
||||||
const AlertDialog = AlertDialogPrimitive.Root;
|
|
||||||
const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
|
|
||||||
const AlertDialogPortal = AlertDialogPrimitive.Portal;
|
|
||||||
|
|
||||||
const AlertDialogOverlay = React.forwardRef<
|
|
||||||
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<AlertDialogPrimitive.Overlay
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
'fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
AlertDialogOverlay.displayName = 'AlertDialogOverlay';
|
|
||||||
|
|
||||||
const AlertDialogContent = React.forwardRef<
|
|
||||||
React.ElementRef<typeof AlertDialogPrimitive.Content>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<AlertDialogPortal>
|
|
||||||
<AlertDialogOverlay />
|
|
||||||
<AlertDialogPrimitive.Content
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
'fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl border bg-card p-6 shadow-lg outline-none',
|
|
||||||
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
|
||||||
'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
</AlertDialogPortal>
|
|
||||||
));
|
|
||||||
AlertDialogContent.displayName = 'AlertDialogContent';
|
|
||||||
|
|
||||||
const AlertDialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
|
||||||
<div className={cn('flex flex-col gap-1.5 text-left', className)} {...props} />
|
|
||||||
);
|
|
||||||
|
|
||||||
const AlertDialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
|
||||||
<div className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)} {...props} />
|
|
||||||
);
|
|
||||||
|
|
||||||
const AlertDialogTitle = React.forwardRef<
|
|
||||||
React.ElementRef<typeof AlertDialogPrimitive.Title>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<AlertDialogPrimitive.Title ref={ref} className={cn('text-lg font-semibold', className)} {...props} />
|
|
||||||
));
|
|
||||||
AlertDialogTitle.displayName = 'AlertDialogTitle';
|
|
||||||
|
|
||||||
const AlertDialogDescription = React.forwardRef<
|
|
||||||
React.ElementRef<typeof AlertDialogPrimitive.Description>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<AlertDialogPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
|
|
||||||
));
|
|
||||||
AlertDialogDescription.displayName = 'AlertDialogDescription';
|
|
||||||
|
|
||||||
const AlertDialogAction = React.forwardRef<
|
|
||||||
React.ElementRef<typeof AlertDialogPrimitive.Action>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<AlertDialogPrimitive.Action ref={ref} className={cn(buttonVariants(), className)} {...props} />
|
|
||||||
));
|
|
||||||
AlertDialogAction.displayName = 'AlertDialogAction';
|
|
||||||
|
|
||||||
const AlertDialogCancel = React.forwardRef<
|
|
||||||
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<AlertDialogPrimitive.Cancel ref={ref} className={cn(buttonVariants({ variant: 'outline' }), 'mt-0', className)} {...props} />
|
|
||||||
));
|
|
||||||
AlertDialogCancel.displayName = 'AlertDialogCancel';
|
|
||||||
|
|
||||||
export {
|
|
||||||
AlertDialog,
|
|
||||||
AlertDialogPortal,
|
|
||||||
AlertDialogOverlay,
|
|
||||||
AlertDialogTrigger,
|
|
||||||
AlertDialogContent,
|
|
||||||
AlertDialogHeader,
|
|
||||||
AlertDialogFooter,
|
|
||||||
AlertDialogTitle,
|
|
||||||
AlertDialogDescription,
|
|
||||||
AlertDialogAction,
|
|
||||||
AlertDialogCancel,
|
|
||||||
};
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
||||||
import { X } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
const Dialog = DialogPrimitive.Root;
|
|
||||||
const DialogTrigger = DialogPrimitive.Trigger;
|
|
||||||
const DialogPortal = DialogPrimitive.Portal;
|
|
||||||
const DialogClose = DialogPrimitive.Close;
|
|
||||||
|
|
||||||
const DialogOverlay = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<DialogPrimitive.Overlay
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
'fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
DialogOverlay.displayName = 'DialogOverlay';
|
|
||||||
|
|
||||||
const DialogContent = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
|
|
||||||
showClose?: boolean;
|
|
||||||
viewportClassName?: string;
|
|
||||||
}
|
|
||||||
>(({ className, children, showClose = true, viewportClassName, ...props }, ref) => (
|
|
||||||
<DialogPortal>
|
|
||||||
<DialogOverlay />
|
|
||||||
<DialogPrimitive.Content
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
// `w-[calc(100vw-2rem)]` keeps a 1rem gutter on every side on small
|
|
||||||
// phones (plain `w-full` made the dialog touch both edges). Callers
|
|
||||||
// only ever override `max-w-*` (the desktop cap), so the width floor
|
|
||||||
// here survives those overrides — width and max-width are distinct.
|
|
||||||
'fixed left-1/2 top-1/2 z-50 max-h-[calc(100dvh_-_2rem)] w-[calc(100vw_-_2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 overflow-hidden rounded-xl border bg-card shadow-lg outline-none',
|
|
||||||
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
|
||||||
'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<div className={cn(
|
|
||||||
'grid max-h-[calc(100dvh_-_2rem)] gap-4 overflow-y-auto overscroll-contain p-6',
|
|
||||||
viewportClassName,
|
|
||||||
)}>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
{showClose && (
|
|
||||||
<DialogPrimitive.Close asChild>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
size="icon-sm"
|
|
||||||
className="absolute right-2 top-2 z-10 text-muted-foreground hover:text-foreground"
|
|
||||||
>
|
|
||||||
<X className="size-4" />
|
|
||||||
<span className="sr-only">关闭</span>
|
|
||||||
</Button>
|
|
||||||
</DialogPrimitive.Close>
|
|
||||||
)}
|
|
||||||
</DialogPrimitive.Content>
|
|
||||||
</DialogPortal>
|
|
||||||
));
|
|
||||||
DialogContent.displayName = 'DialogContent';
|
|
||||||
|
|
||||||
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
|
||||||
<div className={cn('flex flex-col gap-1.5 text-left', className)} {...props} />
|
|
||||||
);
|
|
||||||
|
|
||||||
const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
|
||||||
<div className={cn('flex flex-col-reverse sm:flex-row sm:justify-end gap-2', className)} {...props} />
|
|
||||||
);
|
|
||||||
|
|
||||||
const DialogTitle = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<DialogPrimitive.Title ref={ref} className={cn('text-lg font-semibold leading-none tracking-tight', className)} {...props} />
|
|
||||||
));
|
|
||||||
DialogTitle.displayName = 'DialogTitle';
|
|
||||||
|
|
||||||
const DialogDescription = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DialogPrimitive.Description>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<DialogPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
|
|
||||||
));
|
|
||||||
DialogDescription.displayName = 'DialogDescription';
|
|
||||||
|
|
||||||
export {
|
|
||||||
Dialog,
|
|
||||||
DialogPortal,
|
|
||||||
DialogOverlay,
|
|
||||||
DialogTrigger,
|
|
||||||
DialogClose,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogFooter,
|
|
||||||
DialogTitle,
|
|
||||||
DialogDescription,
|
|
||||||
};
|
|
||||||
Generated
-3
@@ -361,9 +361,6 @@ importers:
|
|||||||
|
|
||||||
packages/webui:
|
packages/webui:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@radix-ui/react-alert-dialog':
|
|
||||||
specifier: ^1.1.7
|
|
||||||
version: 1.1.15(@types/[email protected](@types/[email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])
|
|
||||||
'@radix-ui/react-dialog':
|
'@radix-ui/react-dialog':
|
||||||
specifier: ^1.1.7
|
specifier: ^1.1.7
|
||||||
version: 1.1.15(@types/[email protected](@types/[email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])
|
version: 1.1.15(@types/[email protected](@types/[email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])
|
||||||
|
|||||||
Reference in new issue
Block a user