ChatArea.js 3.3 KB

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