From f6e393b3d28422ecf3bbb9d0e9d56c58aa843b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=E5=BC=A0=E5=98=89=E5=AE=81=E2=80=9D?= <“zhangjianing@zhiketong.cn”> Date: Mon, 3 Apr 2023 10:44:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/home.tsx | 236 +++++++++++++++++++++------------------- 1 file changed, 124 insertions(+), 112 deletions(-) diff --git a/app/components/home.tsx b/app/components/home.tsx index c1121bd9c..2a8aa1d0e 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -608,7 +608,8 @@ export function Home() { // setting const [openSettings, setOpenSettings] = useState(false); const config = useChatStore((state) => state.config); - const [isAllow, setIsAllow] = useState(true); + const [isAllow, setIsAllow] = useState(true); // 白名单状态 + const [isRequestErr, setIsRequestErr] = useState(false); // 接口报错状态 useEffect(() => { const urlParams = new URLSearchParams(window.location.search); @@ -620,44 +621,46 @@ export function Home() { const { code, msg } = data; setIsAllow(code === 0); }) - .catch((error) => console.error(error)); + // 接口错误处理 + .catch((error) => { + setIsAllow(false); + setIsRequestErr(true); + console.error(error); + }); }, []); //const isWorkWechat = () => { - //获取user-agaent标识头 - // const ua = window.navigator.userAgent.toLowerCase(); - //判断ua和微信浏览器的标识头是否匹配 + //获取user-agaent标识头 + // const ua = window.navigator.userAgent.toLowerCase(); + //判断ua和微信浏览器的标识头是否匹配 // if ( // ua.match(/micromessenger/i) == "micromessenger" && - // ua.match(/wxwork/i) == "wxwork" - //) { - // return true; - //} else { - // return false; - //} + // ua.match(/wxwork/i) == "wxwork" + //) { + // return true; + //} else { + // return false; + //} //}; -const isWorkWechat = () => { - // 获取user-agent标识头 - const userAgent = window.navigator.userAgent; + const isWorkWechat = () => { + // 获取user-agent标识头 + const userAgent = window.navigator.userAgent; - // 检查userAgent是否为null或undefined - if (!userAgent) { - return false; - } + // 检查userAgent是否为null或undefined + if (!userAgent) { + return false; + } - // 转换为小写 - const ua = userAgent.toLowerCase(); + // 转换为小写 + const ua = userAgent.toLowerCase(); - // 判断ua和微信浏览器的标识头是否匹配 - if ( - /micromessenger/i.test(ua) && - /wxwork/i.test(ua) - ) { - return true; - } else { - return false; - } -}; + // 判断ua和微信浏览器的标识头是否匹配 + if (/micromessenger/i.test(ua) && /wxwork/i.test(ua)) { + return true; + } else { + return false; + } + }; useSwitchTheme(); @@ -677,100 +680,109 @@ const isWorkWechat = () => { : styles.container }`} > - {!isWorkWechat() ? ( -

请在企业微信里使用ChatGPT

- ) : typeof isAllow === "boolean" && !isAllow ? ( -

- 您不在白名单内,请走工单审批使用Gpt~ - - 去申请 - -

- ) : ( - <> -
-
-
ChatGPT Next
-
- Build your own AI assistant. -
-
- -
-
- + { + // 接口报错 + isRequestErr ? ( +

服务出了点问题~

+ ) : // 不在企业微信 + !isWorkWechat() ? ( +

请在企业微信里使用ChatGPT

+ ) : // 不在白名单 + !isAllow ? ( +

+ 您不在白名单内,请走工单审批使用Gpt~ + + 去申请 + +

+ ) : ( + <>
{ - setOpenSettings(false); - setShowSideBar(false); - }} + className={ + styles.sidebar + ` ${showSideBar && styles["sidebar-show"]}` + } > - -
- -
-
-
- } - onClick={() => { - if (confirm(Locale.Home.DeleteChat)) { - removeSession(currentIndex); - } - }} - /> +
+
ChatGPT Next
+
+ Build your own AI assistant.
-
+
+ +
+
+ +
{ + setOpenSettings(false); + setShowSideBar(false); + }} + > + +
+ +
+
+
+ } + onClick={() => { + if (confirm(Locale.Home.DeleteChat)) { + removeSession(currentIndex); + } + }} + /> +
+
+ } + onClick={() => { + setOpenSettings(true); + setShowSideBar(false); + }} + /> +
+ +
+
} + icon={} + text={Locale.Home.NewChat} onClick={() => { - setOpenSettings(true); + createNewSession(); setShowSideBar(false); }} />
- -
-
- } - text={Locale.Home.NewChat} - onClick={() => { - createNewSession(); - setShowSideBar(false); - }} - />
-
-
- {openSettings ? ( - { - setOpenSettings(false); - setShowSideBar(true); - }} - /> - ) : ( - setShowSideBar(true)} - sideBarShowing={showSideBar} - /> - )} -
- - )} +
+ {openSettings ? ( + { + setOpenSettings(false); + setShowSideBar(true); + }} + /> + ) : ( + setShowSideBar(true)} + sideBarShowing={showSideBar} + /> + )} +
+ + ) + }
); }