Refactor API interactions in GlobalPromptModal to utilize new initGlobalPrompt and saveGlobalPrompt functions. Update modal logic to handle prompt configuration more effectively, removing deprecated state management for enabling prompts. Enhance user experience with improved input handling and feedback mechanisms.
This commit is contained in:
@@ -62,29 +62,33 @@ export function deleteKnowledgeBase(id: number): Promise<any> {
|
||||
return request("/v1/knowledge/deleteType", { id }, "DELETE");
|
||||
}
|
||||
|
||||
// 切换知识库状态(启用/禁用)- 注意:实际接口未提供,保留兼容
|
||||
export function toggleKnowledgeBaseStatus(
|
||||
id: number,
|
||||
status: 0 | 1,
|
||||
): Promise<any> {
|
||||
// 由于接口文档中没有此接口,暂时使用编辑接口实现
|
||||
console.warn("toggleKnowledgeBaseStatus 接口未提供,需要后端补充");
|
||||
return Promise.resolve({ success: true });
|
||||
// 初始化统一提示词配置
|
||||
export function initGlobalPrompt(): Promise<any> {
|
||||
return request("/v1/knowledge/init", undefined, "GET");
|
||||
}
|
||||
|
||||
// 获取统一提示词配置 - 使用发布接口返回的 prompt_info
|
||||
export function getGlobalPrompt(): Promise<GlobalPromptConfig> {
|
||||
// 注意:实际接口未单独提供,需要通过 release 接口获取
|
||||
console.warn("getGlobalPrompt 接口未提供,需要后端补充");
|
||||
return Promise.resolve({
|
||||
enabled: true,
|
||||
content: "",
|
||||
});
|
||||
interface SaveGlobalPromptData {
|
||||
promptInfo: string;
|
||||
}
|
||||
interface PromptResponse {
|
||||
id: number;
|
||||
companyId: number;
|
||||
userId: number;
|
||||
config: {
|
||||
name: string;
|
||||
model_id: string;
|
||||
prompt_info: string;
|
||||
};
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
isRelease: number;
|
||||
releaseTime: number;
|
||||
botId: string;
|
||||
datasetId: string;
|
||||
}
|
||||
|
||||
// 保存统一提示词配置
|
||||
export function saveGlobalPrompt(data: GlobalPromptConfig): Promise<any> {
|
||||
// 注意:实际接口未提供,需要后端补充
|
||||
console.warn("saveGlobalPrompt 接口未提供,需要后端补充");
|
||||
return Promise.resolve({ success: true });
|
||||
export function saveGlobalPrompt(
|
||||
data: SaveGlobalPromptData,
|
||||
): Promise<PromptResponse> {
|
||||
return request("/v1/knowledge/savePrompt", data, "POST");
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Popup, Toast } from "antd-mobile";
|
||||
import { Input, Button, Switch } from "antd";
|
||||
import { CloseOutlined } from "@ant-design/icons";
|
||||
import { Input, Button } from "antd";
|
||||
const { TextArea } = Input;
|
||||
import {
|
||||
InfoCircleOutlined,
|
||||
ExclamationCircleFilled,
|
||||
InfoCircleFilled,
|
||||
} from "@ant-design/icons";
|
||||
import { getGlobalPrompt, saveGlobalPrompt } from "../api";
|
||||
import { initGlobalPrompt, saveGlobalPrompt } from "../api";
|
||||
import style from "../index.module.scss";
|
||||
import { config } from "antd-mobile/es/components/toast/methods";
|
||||
|
||||
interface GlobalPromptModalProps {
|
||||
visible: boolean;
|
||||
@@ -30,7 +30,6 @@ const GlobalPromptModal: React.FC<GlobalPromptModalProps> = ({
|
||||
}) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [enabled, setEnabled] = useState(true);
|
||||
const [content, setContent] = useState(DEFAULT_PROMPT);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -43,9 +42,9 @@ const GlobalPromptModal: React.FC<GlobalPromptModalProps> = ({
|
||||
const fetchGlobalPrompt = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const config = await getGlobalPrompt();
|
||||
setEnabled(config.enabled);
|
||||
setContent(config.content || DEFAULT_PROMPT);
|
||||
const res = await initGlobalPrompt();
|
||||
// 假定返回的数据结构包含 promptInfo 字段
|
||||
setContent(res?.config?.prompt_info || DEFAULT_PROMPT);
|
||||
} catch (error) {
|
||||
Toast.show({ content: "获取配置失败", position: "bottom" });
|
||||
} finally {
|
||||
@@ -54,9 +53,9 @@ const GlobalPromptModal: React.FC<GlobalPromptModalProps> = ({
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
if (enabled && !content.trim()) {
|
||||
if (!content.trim()) {
|
||||
Toast.show({
|
||||
content: "启用统一提示词时,请输入提示词内容",
|
||||
content: "请输入提示词内容",
|
||||
position: "bottom",
|
||||
});
|
||||
return;
|
||||
@@ -64,8 +63,7 @@ const GlobalPromptModal: React.FC<GlobalPromptModalProps> = ({
|
||||
setSaving(true);
|
||||
try {
|
||||
await saveGlobalPrompt({
|
||||
enabled,
|
||||
content: content.trim(),
|
||||
promptInfo: content.trim(),
|
||||
});
|
||||
Toast.show({ content: "保存成功", position: "bottom" });
|
||||
onClose();
|
||||
@@ -105,26 +103,30 @@ const GlobalPromptModal: React.FC<GlobalPromptModalProps> = ({
|
||||
/>
|
||||
<span>统一提示词配置</span>
|
||||
</div>
|
||||
<CloseOutlined onClick={onClose} />
|
||||
<span
|
||||
onClick={onClose}
|
||||
style={{
|
||||
fontSize: 22,
|
||||
color: "#999",
|
||||
cursor: "pointer",
|
||||
transition: "color 0.15s",
|
||||
}}
|
||||
>
|
||||
×
|
||||
</span>
|
||||
</div>
|
||||
<div className={style.promptContent}>
|
||||
<div style={{ fontSize: 13, color: "#888", marginBottom: 12 }}>
|
||||
设置所有知识库的通用回复规范
|
||||
</div>
|
||||
<div className={style.promptToggle}>
|
||||
<span className={style.promptToggleLabel}>启用统一提示词</span>
|
||||
<Switch checked={enabled} onChange={setEnabled} loading={loading} />
|
||||
</div>
|
||||
{enabled && (
|
||||
<TextArea
|
||||
value={content}
|
||||
onChange={e => setContent(e.target.value)}
|
||||
placeholder="请输入统一提示词..."
|
||||
maxLength={2000}
|
||||
disabled={loading}
|
||||
className={style.promptTextarea}
|
||||
/>
|
||||
)}
|
||||
<TextArea
|
||||
value={content}
|
||||
onChange={e => setContent(e.target.value)}
|
||||
placeholder="请输入统一提示词..."
|
||||
maxLength={2000}
|
||||
disabled={loading}
|
||||
style={{ height: "200px", marginBottom: 15 }}
|
||||
/>
|
||||
<div className={style.promptSection}>
|
||||
<div className={style.sectionTitle}>
|
||||
<InfoCircleFilled
|
||||
@@ -159,13 +161,13 @@ const GlobalPromptModal: React.FC<GlobalPromptModalProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
<div className={style.modalFooter}>
|
||||
<Button size="large" onClick={onClose}>
|
||||
<Button onClick={onClose} size="large">
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
size="large"
|
||||
onClick={handleSave}
|
||||
disabled={saving}
|
||||
size="large"
|
||||
type="primary"
|
||||
>
|
||||
{saving ? "保存中..." : "保存配置"}
|
||||
|
||||
Reference in New Issue
Block a user