perf: 发送按键

This commit is contained in:
archer
2023-04-03 17:14:46 +08:00
parent f97c29b41e
commit 042b0c535a
2 changed files with 18 additions and 17 deletions

View File

@@ -194,11 +194,7 @@ const Chat = ({ chatId }: { chatId: string }) => {
const sendPrompt = useCallback(async () => { const sendPrompt = useCallback(async () => {
const storeInput = inputVal; const storeInput = inputVal;
// 去除空行 // 去除空行
const val = inputVal const val = inputVal.trim().replace(/\n\s*/g, '\n');
.trim()
.split('\n')
.filter((val) => val)
.join('\n');
if (!chatData?.modelId || !val || isChatting) { if (!chatData?.modelId || !val || isChatting) {
toast({ toast({
@@ -458,8 +454,7 @@ const Chat = ({ chatId }: { chatId: string }) => {
</Box> </Box>
{/* 发送区 */} {/* 发送区 */}
<Box m={media('20px auto', '0 auto')} w={'100%'} maxW={media('min(750px, 100%)', 'auto')}> <Box m={media('20px auto', '0 auto')} w={'100%'} maxW={media('min(750px, 100%)', 'auto')}>
<Flex <Box
alignItems={'center'}
py={5} py={5}
position={'relative'} position={'relative'}
boxShadow={`0 0 15px rgba(0,0,0,0.1)`} boxShadow={`0 0 15px rgba(0,0,0,0.1)`}
@@ -471,23 +466,23 @@ const Chat = ({ chatId }: { chatId: string }) => {
{/* 输入框 */} {/* 输入框 */}
<Textarea <Textarea
ref={TextareaDom} ref={TextareaDom}
flex={1}
w={0}
py={0} py={0}
pr={0} pr={['45px', '55px']}
border={'none'} border={'none'}
_focusVisible={{ _focusVisible={{
border: 'none' border: 'none'
}} }}
placeholder="提问" placeholder="提问"
resize={'none'} resize={'none'}
value={inputVal} defaultValue={inputVal}
rows={1} rows={1}
height={'22px'} height={'22px'}
lineHeight={'22px'} lineHeight={'22px'}
maxHeight={'150px'} maxHeight={'150px'}
maxLength={-1} maxLength={-1}
overflowY={'auto'} overflowY={'auto'}
whiteSpace={'pre-wrap'}
wordBreak={'break-all'}
color={useColorModeValue('blackAlpha.700', 'white')} color={useColorModeValue('blackAlpha.700', 'white')}
onChange={(e) => { onChange={(e) => {
const textarea = e.target; const textarea = e.target;
@@ -507,7 +502,16 @@ const Chat = ({ chatId }: { chatId: string }) => {
}} }}
/> />
{/* 发送和等待按键 */} {/* 发送和等待按键 */}
<Flex px={4} h={'30px'} alignItems={'flex-end'} onClick={sendPrompt}> <Flex
alignItems={'center'}
justifyContent={'center'}
h={'30px'}
w={'30px'}
position={'absolute'}
right={['12px', '20px']}
bottom={3}
onClick={sendPrompt}
>
{isChatting ? ( {isChatting ? (
<Image <Image
style={{ transform: 'translateY(4px)' }} style={{ transform: 'translateY(4px)' }}
@@ -527,7 +531,7 @@ const Chat = ({ chatId }: { chatId: string }) => {
</Box> </Box>
)} )}
</Flex> </Flex>
</Flex> </Box>
</Box> </Box>
</Flex> </Flex>
</Flex> </Flex>

View File

@@ -155,10 +155,7 @@ function splitText(text: string) {
// 如果Q和A都存在就将其添加到结果中 // 如果Q和A都存在就将其添加到结果中
result.push({ result.push({
q, q,
a: a // 过滤空行 a: a.trim().replace(/\n\s*/g, '\n')
.split('\n')
.filter((item) => item)
.join('\n')
}); });
} }
} }