完善检查更新操作

This commit is contained in:
hanhh 2021-10-12 22:54:17 +08:00
parent ed93b919ba
commit b26d0b4887

View File

@ -1,10 +1,10 @@
import React, { useEffect, useState, useRef } from 'react';
import { Typography, Modal, Tag, Button, Spin, message } from 'antd';
import { Statistic, Modal, Tag, Button, Spin, message } from 'antd';
import { request } from '@/utils/http';
import config from '@/utils/config';
import { version } from '../../version';
const { Text, Link } = Typography;
const { Countdown } = Statistic;
const CheckUpdate = ({ ws }: any) => {
const [updateLoading, setUpdateLoading] = useState(false);
@ -18,19 +18,20 @@ const CheckUpdate = ({ ws }: any) => {
request
.put(`${config.apiPrefix}system/update-check`)
.then((_data: any) => {
message.destroy();
const { code, data } = _data;
if (code === 200 && !data.hasNewVersion) {
if (code === 200 && data.hasNewVersion) {
showConfirmUpdateModal(data);
} else {
message.success('已经是最新版了!');
}
})
.catch((error: any) => {
message.destroy();
console.log(error);
})
.finally(() => {
setUpdateLoading(false);
hide();
});
};
@ -79,9 +80,10 @@ const CheckUpdate = ({ ws }: any) => {
maskClosable: false,
closable: false,
okButtonProps: { disabled: true },
title: <span></span>,
title: '更新日志',
centered: true,
content: (
<div style={{ height: '60vh', overflowY: 'auto' }}>
<pre
style={{
wordBreak: 'break-all',
@ -89,19 +91,39 @@ const CheckUpdate = ({ ws }: any) => {
paddingTop: 15,
fontSize: 12,
fontWeight: 400,
minHeight: '60vh',
}}
>
{value}
</pre>
</div>
),
});
};
useEffect(() => {
ws.onmessage = (e) => {
if (e.data.includes('重启面板')) {
message.warning({
content: (
<span>
<Countdown
className="inline-countdown"
format="ss"
value={Date.now() + 1000 * 10}
/>
</span>
),
duration: 10,
});
setTimeout(() => {
window.location.reload();
}, 10000);
} else {
modalRef.current.update({
content: (
<div style={{ height: '60vh', overflowY: 'auto' }}>
<pre
style={{
wordBreak: 'break-all',
@ -109,14 +131,15 @@ const CheckUpdate = ({ ws }: any) => {
paddingTop: 15,
fontSize: 12,
fontWeight: 400,
minHeight: '60vh',
}}
>
{e.data + value}
{value + e.data}
</pre>
</div>
),
});
setValue(e.data);
}
};
}, []);