修改镜像源按钮增加 loading

This commit is contained in:
whyour 2023-12-01 09:28:11 +08:00
parent 897b710527
commit b89dc6dfc6

View File

@ -24,6 +24,7 @@ const Dependence = () => {
}>(); }>();
const [form] = Form.useForm(); const [form] = Form.useForm();
const [log, setLog] = useState<string>(''); const [log, setLog] = useState<string>('');
const [loading, setLoading] = useState<boolean>(false);
const getSystemConfig = () => { const getSystemConfig = () => {
request request
@ -39,7 +40,8 @@ const Dependence = () => {
}; };
const updateSystemConfigStream = (path: keyof typeof dataMap) => { const updateSystemConfigStream = (path: keyof typeof dataMap) => {
setLog('执行中...\n'); setLoading(true);
setLog('in progress...\n');
request request
.put<string>( .put<string>(
`${config.apiPrefix}system/config/${path}`, `${config.apiPrefix}system/config/${path}`,
@ -52,6 +54,7 @@ const Dependence = () => {
}; };
const updateSystemConfig = (path: keyof typeof dataMap) => { const updateSystemConfig = (path: keyof typeof dataMap) => {
setLoading(true);
setLog(''); setLog('');
request request
.put( .put(
@ -65,12 +68,19 @@ const Dependence = () => {
}) })
.catch((error: any) => { .catch((error: any) => {
console.log(error); console.log(error);
}); })
.finally(() => setLoading(false));
}; };
const handleMessage = (payload: any) => { const handleMessage = (payload: any) => {
const { message } = payload; const { message } = payload;
setLog((p) => `${p}${message}`); setLog((p) => `${p}${message}`);
if (
message.includes('update node mirror end') ||
message.includes('update linux mirror end')
) {
setLoading(false);
}
}; };
useEffect(() => { useEffect(() => {
@ -110,6 +120,7 @@ const Dependence = () => {
/> />
<Button <Button
type="primary" type="primary"
loading={loading}
onClick={() => { onClick={() => {
updateSystemConfig('dependence-proxy'); updateSystemConfig('dependence-proxy');
}} }}
@ -134,6 +145,7 @@ const Dependence = () => {
/> />
<Button <Button
type="primary" type="primary"
loading={loading}
onClick={() => { onClick={() => {
updateSystemConfigStream('node-mirror'); updateSystemConfigStream('node-mirror');
}} }}
@ -158,6 +170,7 @@ const Dependence = () => {
/> />
<Button <Button
type="primary" type="primary"
loading={loading}
onClick={() => { onClick={() => {
updateSystemConfig('python-mirror'); updateSystemConfig('python-mirror');
}} }}
@ -184,6 +197,7 @@ const Dependence = () => {
/> />
<Button <Button
type="primary" type="primary"
loading={loading}
onClick={() => { onClick={() => {
updateSystemConfigStream('linux-mirror'); updateSystemConfigStream('linux-mirror');
}} }}