diff --git a/napcat.webui/src/pages/dashboard/config/index.tsx b/napcat.webui/src/pages/dashboard/config/index.tsx index b90558d3..980a55fa 100644 --- a/napcat.webui/src/pages/dashboard/config/index.tsx +++ b/napcat.webui/src/pages/dashboard/config/index.tsx @@ -4,6 +4,7 @@ import { useMediaQuery } from 'react-responsive' import { useNavigate, useSearchParams } from 'react-router-dom' import ChangePasswordCard from './change_password' +import LoginConfigCard from './login' import OneBotConfigCard from './onebot' import WebUIConfigCard from './webui' @@ -58,6 +59,11 @@ export default function ConfigPage() { + + + + + diff --git a/napcat.webui/src/pages/dashboard/config/login.tsx b/napcat.webui/src/pages/dashboard/config/login.tsx new file mode 100644 index 00000000..9abbb7d3 --- /dev/null +++ b/napcat.webui/src/pages/dashboard/config/login.tsx @@ -0,0 +1,100 @@ +import { Input } from '@heroui/input' +import { useRequest } from 'ahooks' +import { useEffect, useState } from 'react' +import { Controller, useForm } from 'react-hook-form' +import toast from 'react-hot-toast' + +import SaveButtons from '@/components/button/save_buttons' +import PageLoading from '@/components/page_loading' + +import QQManager from '@/controllers/qq_manager' + +const LoginConfigCard = () => { + const { + data: quickLoginData, + loading: quickLoginLoading, + error: quickLoginError, + refreshAsync: refreshQuickLogin + } = useRequest(QQManager.getQuickLoginQQ) + const [loading, setLoading] = useState(false) + const { + control, + handleSubmit: handleOnebotSubmit, + formState: { isSubmitting }, + setValue: setOnebotValue + } = useForm<{ + quickLoginQQ: string + }>({ + defaultValues: { + quickLoginQQ: '' + } + }) + + const reset = () => { + setOnebotValue('quickLoginQQ', quickLoginData ?? '') + } + + const onSubmit = handleOnebotSubmit((data) => { + try { + setLoading(true) + QQManager.setQuickLoginQQ(data.quickLoginQQ) + toast.success('保存成功') + } catch (error) { + const msg = (error as Error).message + toast.error(`保存失败: ${msg}`) + } finally { + setLoading(false) + } + }) + + const onRefresh = async (shotTip = true) => { + try { + setLoading(true) + await refreshQuickLogin() + if (shotTip) toast.success('刷新成功') + } catch (error) { + const msg = (error as Error).message + toast.error(`刷新失败: ${msg}`) + } finally { + setLoading(false) + } + } + + useEffect(() => { + reset() + }, [quickLoginData]) + + useEffect(() => { + onRefresh(false) + }, []) + + if (loading) return + + return ( + <> + OneBot配置 - NapCat WebUI +
快速登录QQ
+ ( + + )} + /> + + + ) +} + +export default LoginConfigCard