diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 8eb1e9db..a56146b5 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import ProLayout from '@ant-design/pro-layout'; +import ProLayout, { PageLoading } from '@ant-design/pro-layout'; import { enable as enableDarkMode, disable as disableDarkMode, @@ -89,7 +89,9 @@ export default function (props: any) { !navigator.userAgent.includes('Chrome'); const isQQBrowser = navigator.userAgent.includes('QQBrowser'); - return ( + return loading ? ( + + ) : ( { const [select, setSelect] = useState('config.sh'); const [data, setData] = useState([]); const editorRef = useRef(null); + const [confirmLoading, setConfirmLoading] = useState(false); const getConfig = (name: string) => { request.get(`${config.apiPrefix}configs/${name}`).then((data: any) => { @@ -37,6 +38,7 @@ const Config = ({ headerStyle, isPhone, theme }: any) => { }; const updateConfig = () => { + setConfirmLoading(true); const content = editorRef.current ? editorRef.current.getValue().replace(/\r\n/g, '\n') : value; @@ -47,6 +49,7 @@ const Config = ({ headerStyle, isPhone, theme }: any) => { }) .then((data: any) => { message.success(data.message); + setConfirmLoading(false); }); }; @@ -76,7 +79,12 @@ const Config = ({ headerStyle, isPhone, theme }: any) => { defaultValue="config.sh" onSelect={onSelect} />, - , ]} diff --git a/src/pages/script/index.tsx b/src/pages/script/index.tsx index e51e52c4..0c017769 100644 --- a/src/pages/script/index.tsx +++ b/src/pages/script/index.tsx @@ -141,22 +141,25 @@ const Script = ({ headerStyle, isPhone, theme }: any) => { const content = editorRef.current ? editorRef.current.getValue().replace(/\r\n/g, '\n') : value; - request - .put(`${config.apiPrefix}scripts`, { - data: { - filename: select, - content, - }, - }) - .then((_data: any) => { - if (_data.code === 200) { - message.success(`保存成功`); - setValue(content); - setIsEditing(false); - } else { - message.error(_data); - } - }); + return new Promise((resolve) => { + request + .put(`${config.apiPrefix}scripts`, { + data: { + filename: select, + content, + }, + }) + .then((_data: any) => { + if (_data.code === 200) { + message.success(`保存成功`); + setValue(content); + setIsEditing(false); + } else { + message.error(_data); + } + resolve(null); + }); + }); }, onCancel() { console.log('Cancel'); diff --git a/src/pages/setting/security.tsx b/src/pages/setting/security.tsx index ebf9074d..06455ea0 100644 --- a/src/pages/setting/security.tsx +++ b/src/pages/setting/security.tsx @@ -1,9 +1,10 @@ import React, { useEffect, useState } from 'react'; -import { Typography, Input, Form, Button, Spin, message } from 'antd'; +import { Typography, Input, Form, Button, message } from 'antd'; import { request } from '@/utils/http'; import config from '@/utils/config'; import { history } from 'umi'; import QRCode from 'qrcode.react'; +import { PageLoading } from '@ant-design/pro-layout'; const { Title, Link } = Typography; @@ -146,7 +147,7 @@ const SecuritySettings = ({ user, userChange }: any) => { ) : ( - + )} ) : (