yapi-next/vendors/client/components/Notify/Notify.js
2023-06-27 18:59:45 +08:00

52 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { Component } from 'react';
import axios from 'axios';
import { Alert, message } from 'antd';
export default class Notify extends Component {
constructor(props) {
super(props);
this.state = {
newVersion: process.env.version,
version: process.env.version
};
}
componentDidMount() {
const versions = 'https://www.fastmock.site/mock/1529fa78fa4c4880ad153d115084a940/yapi/versions';
axios.get(versions).then(req => {
if (req.status === 200) {
this.setState({ newVersion: req.data.data[0] });
} else {
message.error('无法获取新版本信息!');
}
});
}
render() {
const isShow = this.state.newVersion > this.state.version;
return (
<div>
{isShow && (
<Alert
message={
<div>
当前版本是{this.state.version}&nbsp;&nbsp;可升级到: {this.state.newVersion}
&nbsp;&nbsp;&nbsp;
<a
target="view_window"
href="https://github.com/YMFE/yapi/blob/master/CHANGELOG.md"
>
版本详情
</a>
</div>
}
banner
closable
type="info"
/>
)}
</div>
);
}
}