mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-22 05:30:19 +09:00

- 在模型配置中添加服务商选择选项 - 实现服务商切换时自动选择该服务商下的第一个可用模型 - 优化模型选择界面,仅显示当前选中服务商的模型 - 添加摘要模型服务商选择功能 - 移除授权页面的 Saas 相关功能 - 调整聊天页面的模型选择逻辑
140 lines
4.2 KiB
TypeScript
140 lines
4.2 KiB
TypeScript
import styles from "./auth.module.scss";
|
|
import { IconButton } from "./button";
|
|
import { useState, useEffect } from "react";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { Path } from "../constant";
|
|
import { useAccessStore } from "../store";
|
|
import Locale from "../locales";
|
|
import { useMobileScreen } from "@/app/utils";
|
|
import BotIcon from "../icons/bot.svg";
|
|
import { getClientConfig } from "../config/client";
|
|
import { PasswordInput } from "./ui-lib";
|
|
import LeftIcon from "@/app/icons/left.svg";
|
|
import { safeLocalStorage } from "@/app/utils";
|
|
|
|
import clsx from "clsx";
|
|
|
|
const storage = safeLocalStorage();
|
|
|
|
export function AuthPage() {
|
|
const navigate = useNavigate();
|
|
const accessStore = useAccessStore();
|
|
const goChat = () => navigate(Path.Chat);
|
|
// Reset access code to empty string
|
|
|
|
useEffect(() => {
|
|
if (getClientConfig()?.isApp) {
|
|
navigate(Path.Settings);
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
return (
|
|
<div className={styles["auth-page"]}>
|
|
<TopBanner></TopBanner>
|
|
<div className={styles["auth-header"]}>
|
|
<IconButton
|
|
icon={<LeftIcon />}
|
|
text={Locale.Auth.Return}
|
|
onClick={() => navigate(Path.Home)}
|
|
></IconButton>
|
|
</div>
|
|
<div className={clsx("no-dark", styles["auth-logo"])}>
|
|
<BotIcon />
|
|
</div>
|
|
|
|
<div className={styles["auth-title"]}>{Locale.Auth.Title}</div>
|
|
<div className={styles["auth-tips"]}>{Locale.Auth.Tips}</div>
|
|
|
|
<PasswordInput
|
|
style={{ marginTop: "3vh", marginBottom: "3vh" }}
|
|
aria={Locale.Settings.ShowPassword}
|
|
aria-label={Locale.Auth.Input}
|
|
value={accessStore.accessCode}
|
|
type="text"
|
|
placeholder={Locale.Auth.Input}
|
|
onChange={(e) => {
|
|
accessStore.update(
|
|
(access) => (access.accessCode = e.currentTarget.value),
|
|
);
|
|
}}
|
|
/>
|
|
|
|
{!accessStore.hideUserApiKey ? (
|
|
<>
|
|
<div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>
|
|
<PasswordInput
|
|
style={{ marginTop: "3vh", marginBottom: "3vh" }}
|
|
aria={Locale.Settings.ShowPassword}
|
|
aria-label={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
|
|
value={accessStore.openaiApiKey}
|
|
type="text"
|
|
placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
|
|
onChange={(e) => {
|
|
accessStore.update(
|
|
(access) => (access.openaiApiKey = e.currentTarget.value),
|
|
);
|
|
}}
|
|
/>
|
|
<PasswordInput
|
|
style={{ marginTop: "3vh", marginBottom: "3vh" }}
|
|
aria={Locale.Settings.ShowPassword}
|
|
aria-label={Locale.Settings.Access.Google.ApiKey.Placeholder}
|
|
value={accessStore.googleApiKey}
|
|
type="text"
|
|
placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}
|
|
onChange={(e) => {
|
|
accessStore.update(
|
|
(access) => (access.googleApiKey = e.currentTarget.value),
|
|
);
|
|
}}
|
|
/>
|
|
</>
|
|
) : null}
|
|
|
|
<div className={styles["auth-actions"]}>
|
|
<IconButton
|
|
text={Locale.Auth.Confirm}
|
|
type="primary"
|
|
onClick={goChat}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
function TopBanner() {
|
|
const [isHovered, setIsHovered] = useState(false);
|
|
const [isVisible, setIsVisible] = useState(true);
|
|
const isMobile = useMobileScreen();
|
|
useEffect(() => {
|
|
// 检查 localStorage 中是否有标记
|
|
const bannerDismissed = storage.getItem("bannerDismissed");
|
|
// 如果标记不存在,存储默认值并显示横幅
|
|
if (!bannerDismissed) {
|
|
storage.setItem("bannerDismissed", "false");
|
|
setIsVisible(true); // 显示横幅
|
|
} else if (bannerDismissed === "true") {
|
|
// 如果标记为 "true",则隐藏横幅
|
|
setIsVisible(false);
|
|
}
|
|
}, []);
|
|
|
|
const handleMouseEnter = () => {
|
|
setIsHovered(true);
|
|
};
|
|
|
|
const handleMouseLeave = () => {
|
|
setIsHovered(false);
|
|
};
|
|
|
|
const handleClose = () => {
|
|
setIsVisible(false);
|
|
storage.setItem("bannerDismissed", "true");
|
|
};
|
|
|
|
if (!isVisible) {
|
|
return null;
|
|
}
|
|
return null;
|
|
}
|