105 lines
3.2 KiB
TypeScript
105 lines
3.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { toast } from "sonner";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/components/ui/dialog";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import {
|
|
DEFAULT_SENTIMENT_AGENT_PROFILE,
|
|
type SentimentAgentProfile,
|
|
readSentimentAgentProfile,
|
|
saveSentimentAgentProfile,
|
|
} from "@/core/sentiment-agent/profile";
|
|
|
|
/**
|
|
* 舆情分析智能体的「编辑信息」弹窗:修改名称 / 简介并保存到 localStorage。
|
|
* 智能体管理页的卡片和对话页顶栏共用。
|
|
*/
|
|
export function SentimentAgentProfileDialog({
|
|
open,
|
|
onOpenChange,
|
|
}: {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
}) {
|
|
const [name, setName] = useState("");
|
|
const [description, setDescription] = useState("");
|
|
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
const profile = readSentimentAgentProfile();
|
|
setName(profile.name);
|
|
setDescription(profile.description);
|
|
}, [open]);
|
|
|
|
const handleSave = () => {
|
|
const next: SentimentAgentProfile = {
|
|
name: name.trim() || DEFAULT_SENTIMENT_AGENT_PROFILE.name,
|
|
description:
|
|
description.trim() || DEFAULT_SENTIMENT_AGENT_PROFILE.description,
|
|
};
|
|
saveSentimentAgentProfile(next);
|
|
toast.success("舆情分析智能体信息已更新");
|
|
onOpenChange(false);
|
|
};
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="sm:max-w-[480px]">
|
|
<DialogHeader>
|
|
<DialogTitle>编辑舆情分析智能体</DialogTitle>
|
|
</DialogHeader>
|
|
<div className="flex flex-col gap-4 py-2">
|
|
<div className="flex flex-col gap-2">
|
|
<label htmlFor="sentiment-agent-name" className="text-sm font-medium">
|
|
名称
|
|
</label>
|
|
<Input
|
|
id="sentiment-agent-name"
|
|
value={name}
|
|
maxLength={50}
|
|
onChange={(e) => setName(e.target.value)}
|
|
placeholder="智能体名称"
|
|
/>
|
|
</div>
|
|
<div className="flex flex-col gap-2">
|
|
<label
|
|
htmlFor="sentiment-agent-description"
|
|
className="text-sm font-medium"
|
|
>
|
|
简介
|
|
</label>
|
|
<Textarea
|
|
id="sentiment-agent-description"
|
|
value={description}
|
|
maxLength={300}
|
|
onChange={(e) => setDescription(e.target.value)}
|
|
placeholder="智能体简介(展示在卡片与对话页)"
|
|
className="min-h-[96px] resize-none"
|
|
/>
|
|
</div>
|
|
<p className="text-muted-foreground text-xs">
|
|
仅修改本浏览器展示的名称与简介;接口地址与鉴权请在部署目录的
|
|
runtime-config.js 中配置。
|
|
</p>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
|
取消
|
|
</Button>
|
|
<Button onClick={handleSave}>保存</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|