ChatArea.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React from 'react';
  2. import {
  3. Card,
  4. Chat,
  5. Typography,
  6. Button,
  7. } from '@douyinfe/semi-ui';
  8. import {
  9. MessageSquare,
  10. Eye,
  11. EyeOff,
  12. } from 'lucide-react';
  13. import { useTranslation } from 'react-i18next';
  14. import CustomInputRender from './CustomInputRender';
  15. const ChatArea = ({
  16. chatRef,
  17. message,
  18. inputs,
  19. styleState,
  20. showDebugPanel,
  21. roleInfo,
  22. onMessageSend,
  23. onMessageCopy,
  24. onMessageReset,
  25. onMessageDelete,
  26. onStopGenerator,
  27. onClearMessages,
  28. onToggleDebugPanel,
  29. renderCustomChatContent,
  30. renderChatBoxAction,
  31. }) => {
  32. const { t } = useTranslation();
  33. const renderInputArea = React.useCallback((props) => {
  34. return <CustomInputRender {...props} />;
  35. }, []);
  36. return (
  37. <Card
  38. className="h-full"
  39. bordered={false}
  40. bodyStyle={{ padding: 0, height: 'calc(100vh - 66px)', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}
  41. >
  42. {/* 聊天头部 */}
  43. {styleState.isMobile ? (
  44. <div className="pt-4"></div>
  45. ) : (
  46. <div className="px-6 py-4 bg-gradient-to-r from-purple-500 to-blue-500 rounded-t-2xl">
  47. <div className="flex items-center justify-between">
  48. <div className="flex items-center gap-3">
  49. <div className="w-10 h-10 rounded-full bg-white/20 backdrop-blur flex items-center justify-center">
  50. <MessageSquare size={20} className="text-white" />
  51. </div>
  52. <div>
  53. <Typography.Title heading={5} className="!text-white mb-0">
  54. {t('AI 对话')}
  55. </Typography.Title>
  56. <Typography.Text className="!text-white/80 text-sm hidden sm:inline">
  57. {inputs.model || t('选择模型开始对话')}
  58. </Typography.Text>
  59. </div>
  60. </div>
  61. <div className="flex items-center gap-2">
  62. <Button
  63. icon={showDebugPanel ? <EyeOff size={14} /> : <Eye size={14} />}
  64. onClick={onToggleDebugPanel}
  65. theme="borderless"
  66. type="primary"
  67. size="small"
  68. className="!rounded-lg !text-white/80 hover:!text-white hover:!bg-white/10"
  69. >
  70. {showDebugPanel ? t('隐藏调试') : t('显示调试')}
  71. </Button>
  72. </div>
  73. </div>
  74. </div>
  75. )}
  76. {/* 聊天内容区域 */}
  77. <div className="flex-1 overflow-hidden">
  78. <Chat
  79. ref={chatRef}
  80. chatBoxRenderConfig={{
  81. renderChatBoxContent: renderCustomChatContent,
  82. renderChatBoxAction: renderChatBoxAction,
  83. renderChatBoxTitle: () => null,
  84. }}
  85. renderInputArea={renderInputArea}
  86. roleConfig={roleInfo}
  87. style={{
  88. height: '100%',
  89. maxWidth: '100%',
  90. overflow: 'hidden'
  91. }}
  92. chats={message}
  93. onMessageSend={onMessageSend}
  94. onMessageCopy={onMessageCopy}
  95. onMessageReset={onMessageReset}
  96. onMessageDelete={onMessageDelete}
  97. showClearContext
  98. showStopGenerate
  99. onStopGenerator={onStopGenerator}
  100. onClear={onClearMessages}
  101. className="h-full"
  102. placeholder={t('请输入您的问题...')}
  103. />
  104. </div>
  105. </Card>
  106. );
  107. };
  108. export default ChatArea;