对WebUI布局的修改 (#1906)
* 把“系统设置-修改密码”移动到“系统设置-WebUI配置”中 * 修正语法错误 * 把修改密码移动到上方
This commit is contained in:
1 parent
fbd70bbb04
commit
8a3faf64f9
2 files changed
+123
-1
No files matched your search
@@ -6,7 +6,8 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
|
|||||||
|
|
||||||
import key from '@/const/key';
|
import key from '@/const/key';
|
||||||
|
|
||||||
import ChangePasswordCard from './change_password';
|
//把修改密码移动到WebUI栏目中
|
||||||
|
//import ChangePasswordCard from './change_password';
|
||||||
import LoginConfigCard from './login';
|
import LoginConfigCard from './login';
|
||||||
import OneBotConfigCard from './onebot';
|
import OneBotConfigCard from './onebot';
|
||||||
import ServerConfigCard from './server';
|
import ServerConfigCard from './server';
|
||||||
@@ -101,11 +102,16 @@ export default function ConfigPage () {
|
|||||||
<LoginConfigCard />
|
<LoginConfigCard />
|
||||||
</ConfigPageItem>
|
</ConfigPageItem>
|
||||||
</Tab>
|
</Tab>
|
||||||
|
//把修改密码移动到WebUI栏目中
|
||||||
|
{
|
||||||
|
/*
|
||||||
<Tab title='修改密码' key='token'>
|
<Tab title='修改密码' key='token'>
|
||||||
<ConfigPageItem size='sm'>
|
<ConfigPageItem size='sm'>
|
||||||
<ChangePasswordCard />
|
<ChangePasswordCard />
|
||||||
</ConfigPageItem>
|
</ConfigPageItem>
|
||||||
</Tab>
|
</Tab>
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
<Tab title='主题配置' key='theme'>
|
<Tab title='主题配置' key='theme'>
|
||||||
<ConfigPageItem size='lg'>
|
<ConfigPageItem size='lg'>
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { Button } from '@heroui/button';
|
import { Button } from '@heroui/button';
|
||||||
|
import { Input } from '@heroui/input';
|
||||||
import { useLocalStorage } from '@uidotdev/usehooks';
|
import { useLocalStorage } from '@uidotdev/usehooks';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Controller, useForm } from 'react-hook-form';
|
import { Controller, useForm } from 'react-hook-form';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import key from '@/const/key';
|
import key from '@/const/key';
|
||||||
|
|
||||||
@@ -50,6 +52,39 @@ const WebUIConfigCard = () => {
|
|||||||
const [registrationOptions, setRegistrationOptions] = useState<any>(null);
|
const [registrationOptions, setRegistrationOptions] = useState<any>(null);
|
||||||
const [isLoadingOptions, setIsLoadingOptions] = useState(false);
|
const [isLoadingOptions, setIsLoadingOptions] = useState(false);
|
||||||
|
|
||||||
|
// 修改密码独立表单
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [, setToken] = useLocalStorage(key.token, '');
|
||||||
|
const {
|
||||||
|
control: pwdControl,
|
||||||
|
handleSubmit: handlePwdSubmit,
|
||||||
|
formState: { isSubmitting: isPwdSubmitting, errors: pwdErrors },
|
||||||
|
watch,
|
||||||
|
} = useForm<{
|
||||||
|
oldToken: string;
|
||||||
|
newToken: string;
|
||||||
|
}>({
|
||||||
|
defaultValues: {
|
||||||
|
oldToken: '',
|
||||||
|
newToken: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const oldTokenValue = watch('oldToken');
|
||||||
|
|
||||||
|
// 修复类型错误:显式包装为无参函数,满足 onPress 的类型要求
|
||||||
|
const onPasswordSubmit = handlePwdSubmit(async (data) => {
|
||||||
|
try {
|
||||||
|
await WebUIManager.changePassword(data.oldToken, data.newToken);
|
||||||
|
toast.success('修改成功');
|
||||||
|
setToken('');
|
||||||
|
localStorage.removeItem(key.token);
|
||||||
|
navigate('/web_login');
|
||||||
|
} catch (error) {
|
||||||
|
const msg = (error as Error).message;
|
||||||
|
toast.error(`修改失败: ${msg}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 预先获取注册选项(可以在任何时候调用)
|
// 预先获取注册选项(可以在任何时候调用)
|
||||||
const preloadRegistrationOptions = async () => {
|
const preloadRegistrationOptions = async () => {
|
||||||
setIsLoadingOptions(true);
|
setIsLoadingOptions(true);
|
||||||
@@ -90,6 +125,86 @@ const WebUIConfigCard = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<title>WebUI配置 - NapCat WebUI</title>
|
<title>WebUI配置 - NapCat WebUI</title>
|
||||||
|
|
||||||
|
{/* 修改密码区块 - 移到顶部 */}
|
||||||
|
<div className='flex flex-col gap-4'>
|
||||||
|
<div className='flex-shrink-0 w-full font-bold text-default-600 dark:text-default-400 px-1'>修改密码</div>
|
||||||
|
<Controller
|
||||||
|
control={pwdControl}
|
||||||
|
name='oldToken'
|
||||||
|
rules={{
|
||||||
|
required: '旧密码不能为空',
|
||||||
|
validate: (value) => {
|
||||||
|
if (!value || value.trim().length === 0) {
|
||||||
|
return '旧密码不能为空';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
render={({ field }) => (
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
label='旧密码'
|
||||||
|
placeholder='请输入旧密码'
|
||||||
|
type='password'
|
||||||
|
isRequired
|
||||||
|
isInvalid={!!pwdErrors.oldToken}
|
||||||
|
errorMessage={pwdErrors.oldToken?.message}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={pwdControl}
|
||||||
|
name='newToken'
|
||||||
|
rules={{
|
||||||
|
required: '新密码不能为空',
|
||||||
|
minLength: {
|
||||||
|
value: 6,
|
||||||
|
message: '新密码至少需要6个字符',
|
||||||
|
},
|
||||||
|
validate: (value) => {
|
||||||
|
if (!value || value.trim().length === 0) {
|
||||||
|
return '新密码不能为空';
|
||||||
|
}
|
||||||
|
if (value.trim().length !== value.length) {
|
||||||
|
return '新密码不能包含前后空格';
|
||||||
|
}
|
||||||
|
if (value === oldTokenValue) {
|
||||||
|
return '新密码不能与旧密码相同';
|
||||||
|
}
|
||||||
|
if (!/[a-zA-Z]/.test(value)) {
|
||||||
|
return '新密码必须包含字母';
|
||||||
|
}
|
||||||
|
if (!/[0-9]/.test(value)) {
|
||||||
|
return '新密码必须包含数字';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
render={({ field }) => (
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
label='新密码'
|
||||||
|
placeholder='至少6位,包含字母和数字'
|
||||||
|
type='password'
|
||||||
|
isRequired
|
||||||
|
isInvalid={!!pwdErrors.newToken}
|
||||||
|
errorMessage={pwdErrors.newToken?.message}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{/* 自定义确认按钮,无取消按钮;onPress 调用 onPasswordSubmit(已通过 handlePwdSubmit 包装,类型兼容) */}
|
||||||
|
<div className='flex justify-end'>
|
||||||
|
<Button
|
||||||
|
color='primary'
|
||||||
|
onPress={() => { onPasswordSubmit(); }}
|
||||||
|
isLoading={isPwdSubmitting}
|
||||||
|
>
|
||||||
|
确认修改密码
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className='flex flex-col gap-2'>
|
<div className='flex flex-col gap-2'>
|
||||||
<div className='flex-shrink-0 w-full font-bold text-default-600 dark:text-default-400 px-1'>背景图</div>
|
<div className='flex-shrink-0 w-full font-bold text-default-600 dark:text-default-400 px-1'>背景图</div>
|
||||||
<Controller
|
<Controller
|
||||||
@@ -251,6 +366,7 @@ const WebUIConfigCard = () => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<SaveButtons
|
<SaveButtons
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
reset={reset}
|
reset={reset}
|
||||||
|
|||||||
Reference in new issue
Block a user