From becee69d6acfbd424cf4528ef090cf1bd3db9ee4 Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Mon, 3 Apr 2023 17:28:35 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=8F=91=E9=80=81=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/_app.tsx | 15 ++++++++++++++- src/pages/chat/index.tsx | 33 +++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index fc9cef467..67fbfefd5 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,4 +1,5 @@ -import type { AppProps, NextWebVitalsMetric } from 'next/app'; +import { useEffect } from 'react'; +import type { AppProps } from 'next/app'; import Script from 'next/script'; import Head from 'next/head'; import { ChakraProvider, ColorModeScript } from '@chakra-ui/react'; @@ -9,6 +10,7 @@ import NProgress from 'nprogress'; //nprogress module import Router from 'next/router'; import 'nprogress/nprogress.css'; import '../styles/reset.scss'; +import { useToast } from '@/hooks/useToast'; //Binding events. Router.events.on('routeChangeStart', () => NProgress.start()); @@ -27,6 +29,17 @@ const queryClient = new QueryClient({ }); export default function App({ Component, pageProps }: AppProps) { + const { toast } = useToast(); + // 校验是否支持 click 事件 + useEffect(() => { + if (typeof document.createElement('div').click !== 'function') { + toast({ + title: '你的浏览器版本过低', + status: 'warning' + }); + } + }, [toast]); + return ( <> diff --git a/src/pages/chat/index.tsx b/src/pages/chat/index.tsx index 58ac52b63..243e254e8 100644 --- a/src/pages/chat/index.tsx +++ b/src/pages/chat/index.tsx @@ -192,11 +192,18 @@ const Chat = ({ chatId }: { chatId: string }) => { * 发送一个内容 */ const sendPrompt = useCallback(async () => { + if (isChatting) { + toast({ + title: '正在聊天中...请等待结束', + status: 'warning' + }); + return; + } const storeInput = inputVal; // 去除空行 const val = inputVal.trim().replace(/\n\s*/g, '\n'); - if (!chatData?.modelId || !val || isChatting) { + if (!chatData?.modelId || !val) { toast({ title: '内容为空', status: 'warning' @@ -455,7 +462,7 @@ const Chat = ({ chatId }: { chatId: string }) => { {/* 发送区 */} { }} placeholder="提问" resize={'none'} - defaultValue={inputVal} + value={inputVal} rows={1} height={'22px'} lineHeight={'22px'} @@ -509,26 +516,24 @@ const Chat = ({ chatId }: { chatId: string }) => { w={'30px'} position={'absolute'} right={['12px', '20px']} - bottom={3} + bottom={'15px'} onClick={sendPrompt} > {isChatting ? ( {''} ) : ( - - - + )}