ai创建替换缩略图
This commit is contained in:
@@ -18,10 +18,6 @@ import {
|
||||
App,
|
||||
} from 'antd';
|
||||
|
||||
import bg1 from '../assets/bg1.png';
|
||||
import bg2 from '../assets/bg2.png';
|
||||
import bg3 from '../assets/bg3.png';
|
||||
import text from '../assets/testb.png';
|
||||
|
||||
import UploadSelector from '../components/UploadSelector';
|
||||
import GenerationTaskResourceGrid from '../components/generation/GenerationTaskResourceGrid';
|
||||
@@ -313,8 +309,7 @@ const AIChatPage: React.FC = () => {
|
||||
}
|
||||
}, [previewVisible, previewType]);
|
||||
|
||||
// 提示词展开状态
|
||||
const [expandedPrompts, setExpandedPrompts] = useState<Set<string>>(new Set());
|
||||
|
||||
|
||||
// 从URL中提取exp时间戳(支持相对路径和完整URL)
|
||||
const extractExpTimestamp = (url: string): number | null => {
|
||||
@@ -947,56 +942,6 @@ const AIChatPage: React.FC = () => {
|
||||
setLastFrame(null);
|
||||
};
|
||||
|
||||
// ==================== 事处理函数 ====================
|
||||
|
||||
const handleNewChat = () => {
|
||||
// 生成唯一ID(使用时间戳)
|
||||
const newId = Date.now().toString();
|
||||
const newConversation: Conversation = {
|
||||
id: newId,
|
||||
title: '新对话',
|
||||
lastMessage: '',
|
||||
timestamp: new Date().toLocaleString('zh-CN'),
|
||||
messages: [],
|
||||
};
|
||||
|
||||
// 将新对话插入到列表顶部
|
||||
setConversations((prev) => [newConversation, ...prev]);
|
||||
// 切换到新对话
|
||||
setCurrentConversationId(newId);
|
||||
// 清空输入框和已上传媒体
|
||||
setInputValue('');
|
||||
setCurrentMedia([]);
|
||||
setFirstFrame(null);
|
||||
setLastFrame(null);
|
||||
// 显示提示消息
|
||||
antdMessage.info('已开启新对话');
|
||||
|
||||
};
|
||||
|
||||
|
||||
const handleDeleteChat = (conversationId: string) => {
|
||||
// 过滤掉要删除的对话
|
||||
setConversations((prev) => prev.filter((c) => c.id !== conversationId));
|
||||
// 如果删除的是当前选中的对话,切换到其他对话
|
||||
if (currentConversationId === conversationId) {
|
||||
setCurrentConversationId(
|
||||
conversations[0]?.id === conversationId
|
||||
? conversations[1]?.id || null
|
||||
: conversations[0]?.id || null
|
||||
);
|
||||
}
|
||||
// 显示成功提示
|
||||
antdMessage.success('对话已删除');
|
||||
};
|
||||
|
||||
|
||||
const handleSelectChat = (conversationId: string) => {
|
||||
setCurrentConversationId(conversationId);
|
||||
setCurrentMedia([]);
|
||||
setFirstFrame(null);
|
||||
setLastFrame(null);
|
||||
};
|
||||
|
||||
|
||||
const handleSend = async () => {
|
||||
@@ -1873,12 +1818,60 @@ const AIChatPage: React.FC = () => {
|
||||
return false;
|
||||
};
|
||||
|
||||
// 检测文本是否包含中文字符
|
||||
const isChineseText = (text: string): boolean => {
|
||||
return /[\u4e00-\u9fa5]/.test(text);
|
||||
};
|
||||
|
||||
// 统计字数:中文按字符计数,英文按单词计数
|
||||
const countInput = (text: string): number => {
|
||||
if (!text.trim()) return 0;
|
||||
if (isChineseText(text)) {
|
||||
// 中文:按字符数(不含空白)
|
||||
return text.replace(/\s/g, '').length;
|
||||
} else {
|
||||
// 英文:按单词数
|
||||
const words = text.trim().split(/\s+/);
|
||||
return words[0] === '' ? 0 : words.length;
|
||||
}
|
||||
};
|
||||
|
||||
// 获取最大限制,默认显示500
|
||||
const getMaxLimit = (text: string): number => {
|
||||
if (!text.trim()) return 500;
|
||||
return isChineseText(text) ? 500 : 1000;
|
||||
};
|
||||
|
||||
// 输入框变化处理
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const value = e.target.value;
|
||||
setInputValue(value);
|
||||
const textarea = e.target;
|
||||
checkMention(textarea, value);
|
||||
const maxLimit = getMaxLimit(value);
|
||||
const count = countInput(value);
|
||||
if (count <= maxLimit) {
|
||||
setInputValue(value);
|
||||
checkMention(e.target, value);
|
||||
} else {
|
||||
// 截断到限制内
|
||||
if (isChineseText(value)) {
|
||||
let trimmed = value;
|
||||
let cjkCount = 0;
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
if (/\s/.test(value[i])) continue;
|
||||
cjkCount++;
|
||||
if (cjkCount > maxLimit) {
|
||||
trimmed = value.slice(0, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
setInputValue(trimmed);
|
||||
checkMention(e.target, trimmed);
|
||||
} else {
|
||||
const words = value.trim().split(/\s+/);
|
||||
const limited = words.slice(0, maxLimit).join(' ');
|
||||
setInputValue(limited);
|
||||
checkMention(e.target, limited);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 键盘事件处理(ESC 关闭提及、Tab/Enter 选择)
|
||||
@@ -2414,60 +2407,7 @@ const AIChatPage: React.FC = () => {
|
||||
</Popconfirm>
|
||||
</div>
|
||||
|
||||
{/* 文本内容 */}
|
||||
{/* <div
|
||||
style={{
|
||||
width: '100%',
|
||||
position: 'relative',
|
||||
margin: '8px 0',
|
||||
padding: '12px 16px',
|
||||
backgroundColor: 'rgba(139, 92, 246, 0.04)',
|
||||
borderRadius: 10,
|
||||
border: '1px solid rgba(139, 92, 246, 0.08)',
|
||||
fontSize: 13,
|
||||
color: '#475467',
|
||||
lineHeight: 1.6,
|
||||
cursor: 'pointer',
|
||||
transition: 'all 0.2s ease',
|
||||
boxShadow: '0 1px 3px rgba(47, 52, 64, 0.035)',
|
||||
}}
|
||||
onMouseEnter={() => {
|
||||
setExpandedPrompts(prev => {
|
||||
const newSet = new Set(prev);
|
||||
newSet.add(msg.id);
|
||||
return newSet;
|
||||
});
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
setExpandedPrompts(prev => {
|
||||
const newSet = new Set(prev);
|
||||
newSet.delete(msg.id);
|
||||
return newSet;
|
||||
});
|
||||
}}
|
||||
>
|
||||
默认显示:一行省略
|
||||
<div style={{
|
||||
width: '100%',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
display: expandedPrompts.has(msg.id) ? 'none' : 'block',
|
||||
}}>
|
||||
{msg.originalPrompt}
|
||||
</div>
|
||||
|
||||
鼠标移入显示:完整内容
|
||||
<div style={{
|
||||
width: '100%',
|
||||
maxHeight: 200,
|
||||
overflowY: 'auto',
|
||||
display: expandedPrompts.has(msg.id) ? 'block' : 'none',
|
||||
wordBreak: 'break-word',
|
||||
}}>
|
||||
{msg.originalPrompt}
|
||||
</div>
|
||||
</div> */}
|
||||
|
||||
{/* 根据 status 显示不同内容 */}
|
||||
{(msg.status === 'generating' || msg.status === 'failed' || msg.status === 'completed') && (
|
||||
@@ -3304,6 +3244,19 @@ const AIChatPage: React.FC = () => {
|
||||
disabled={loading}
|
||||
/>
|
||||
|
||||
{/* 字数统计 */}
|
||||
<div style={{
|
||||
display: 'flex', justifyContent: 'flex-end',
|
||||
paddingRight: 10, marginTop: 2,
|
||||
}}>
|
||||
<span style={{
|
||||
fontSize: 11,
|
||||
color: countInput(inputValue) > getMaxLimit(inputValue) ? '#ef4444' : '#9ca3af',
|
||||
}}>
|
||||
{countInput(inputValue)} / {getMaxLimit(inputValue)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* @ 提及下拉列表 */}
|
||||
{mentionVisible && currentMedia.length > 0 && referenceMode === 'universal' && (
|
||||
<div
|
||||
@@ -4736,7 +4689,7 @@ const AIChatPage: React.FC = () => {
|
||||
width={800}
|
||||
footer={
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 12, padding: '16px 24px', background: 'rgba(255,255,255,0.6)', borderTop: '1px solid rgba(139, 92, 246, 0.08)' }}>
|
||||
<Button
|
||||
{/* <Button
|
||||
type="primary"
|
||||
icon={<DownloadOutlined />}
|
||||
onClick={() => {
|
||||
@@ -4751,7 +4704,7 @@ const AIChatPage: React.FC = () => {
|
||||
style={{ borderRadius: 10, background: 'linear-gradient(135deg, #8b5cf6 0%, #ddd6fe 100%)', border: 'none', boxShadow: '0 8px 18px rgba(47, 52, 64, 0.15)' }}
|
||||
>
|
||||
下载
|
||||
</Button>
|
||||
</Button> */}
|
||||
</div>
|
||||
}
|
||||
centered
|
||||
@@ -4769,7 +4722,7 @@ const AIChatPage: React.FC = () => {
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', width: '100%', height: '100%' }}>
|
||||
{attachmentPreviewType === 'image' ? (
|
||||
<img
|
||||
src={buildPreviewUrl(attachmentPreviewUrl)}
|
||||
src={buildPreviewUrl(`/static${attachmentPreviewUrl}?w=300&q=50`)}
|
||||
alt="预览"
|
||||
style={{ width: '100%', maxHeight: '400px', objectFit: 'contain' }}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user