feat: 新增授权逻辑

This commit is contained in:
zhangjianing 2023-03-31 16:23:41 +08:00
parent 61eb356fd9
commit 36feef834e
2 changed files with 154 additions and 74 deletions

View File

@ -19,6 +19,38 @@
height: var(--window-height); height: var(--window-height);
} }
.button {
cursor: pointer;
position: relative;
display: inline-block;
font-weight: 400;
white-space: nowrap;
text-align: center;
background-image: none;
border: 1px solid transparent;
box-shadow: 0 2px #00000004;
cursor: pointer;
transition: all .3s cubic-bezier(.645,.045,.355,1);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
touch-action: manipulation;
height: 32px;
line-height: 32px;
padding: 4px 15px;
font-size: 17px;
border-radius: 2px;
color: #000000d9;
border-color: #d9d9d9;
background: #fff;
color: #fff;
border-color: #1890ff;
background: #1890ff;
text-shadow: 0 -1px 0 rgba(0,0,0,.12);
box-shadow: 0 2px #0000000b;
}
.container { .container {
@include container(); @include container();
} }

View File

@ -608,6 +608,34 @@ export function Home() {
// setting // setting
const [openSettings, setOpenSettings] = useState(false); const [openSettings, setOpenSettings] = useState(false);
const config = useChatStore((state) => state.config); const config = useChatStore((state) => state.config);
const [isAllow, setIsAllow] = useState(undefined);
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
const signature = urlParams.get("signature");
// 不是企业微信环境,拦截
fetch(`//192.168.5.198/api/check_user_white/?signature=${signature}`)
.then((response) => response.json())
.then((data) => {
const { code, msg } = data;
setIsAllow(code === 0); // 是否在白名单
})
.catch((error) => console.error(error));
}, []);
const isWorkWechat = () => {
//获取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;
}
};
useSwitchTheme(); useSwitchTheme();
@ -615,6 +643,11 @@ export function Home() {
return <Loading />; return <Loading />;
} }
const goApply = () => {
location.href =
"http://work-order.zhiketong.net/#/process/create-ticket?processId=117";
};
return ( return (
<div <div
className={`${ className={`${
@ -623,85 +656,100 @@ export function Home() {
: styles.container : styles.container
}`} }`}
> >
<div {!isWorkWechat() ? (
className={styles.sidebar + ` ${showSideBar && styles["sidebar-show"]}`} <h2 className="not-wx-work">使Gpt~</h2>
> ) : typeof isAllow === "boolean" && !isAllow ? (
<div className={styles["sidebar-header"]}> <h2 className="not-allow">
<div className={styles["sidebar-title"]}>ChatGPT Next</div> <span className="text">使Gpt~</span>
<div className={styles["sidebar-sub-title"]}> <span onClick={goApply} className={styles["button"]}>
Build your own AI assistant.
</div> </span>
<div className={styles["sidebar-logo"]}> </h2>
<ChatGptIcon /> ) : (
</div> <>
</div> <div
className={
styles.sidebar + ` ${showSideBar && styles["sidebar-show"]}`
}
>
<div className={styles["sidebar-header"]}>
<div className={styles["sidebar-title"]}>ChatGPT Next</div>
<div className={styles["sidebar-sub-title"]}>
Build your own AI assistant.
</div>
<div className={styles["sidebar-logo"]}>
<ChatGptIcon />
</div>
</div>
<div <div
className={styles["sidebar-body"]} className={styles["sidebar-body"]}
onClick={() => {
setOpenSettings(false);
setShowSideBar(false);
}}
>
<ChatList />
</div>
<div className={styles["sidebar-tail"]}>
<div className={styles["sidebar-actions"]}>
<div className={styles["sidebar-action"] + " " + styles.mobile}>
<IconButton
icon={<CloseIcon />}
onClick={() => {
if (confirm(Locale.Home.DeleteChat)) {
removeSession(currentIndex);
}
}}
/>
</div>
<div className={styles["sidebar-action"]}>
<IconButton
icon={<SettingsIcon />}
onClick={() => {
setOpenSettings(true);
setShowSideBar(false);
}}
/>
</div>
<div className={styles["sidebar-action"]}>
<a href={REPO_URL} target="_blank">
<IconButton icon={<GithubIcon />} />
</a>
</div>
</div>
<div>
<IconButton
icon={<AddIcon />}
text={Locale.Home.NewChat}
onClick={() => { onClick={() => {
createNewSession(); setOpenSettings(false);
setShowSideBar(false); setShowSideBar(false);
}} }}
/> >
</div> <ChatList />
</div> </div>
</div>
<div className={styles["window-content"]}> <div className={styles["sidebar-tail"]}>
{openSettings ? ( <div className={styles["sidebar-actions"]}>
<Settings <div className={styles["sidebar-action"] + " " + styles.mobile}>
closeSettings={() => { <IconButton
setOpenSettings(false); icon={<CloseIcon />}
setShowSideBar(true); onClick={() => {
}} if (confirm(Locale.Home.DeleteChat)) {
/> removeSession(currentIndex);
) : ( }
<Chat }}
key="chat" />
showSideBar={() => setShowSideBar(true)} </div>
sideBarShowing={showSideBar} <div className={styles["sidebar-action"]}>
/> <IconButton
)} icon={<SettingsIcon />}
</div> onClick={() => {
setOpenSettings(true);
setShowSideBar(false);
}}
/>
</div>
<div className={styles["sidebar-action"]}>
<a href={REPO_URL} target="_blank">
<IconButton icon={<GithubIcon />} />
</a>
</div>
</div>
<div>
<IconButton
icon={<AddIcon />}
text={Locale.Home.NewChat}
onClick={() => {
createNewSession();
setShowSideBar(false);
}}
/>
</div>
</div>
</div>
<div className={styles["window-content"]}>
{openSettings ? (
<Settings
closeSettings={() => {
setOpenSettings(false);
setShowSideBar(true);
}}
/>
) : (
<Chat
key="chat"
showSideBar={() => setShowSideBar(true)}
sideBarShowing={showSideBar}
/>
)}
</div>
</>
)}
</div> </div>
); );
} }