mock平台

Notify.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { Component } from 'react';
  2. import axios from 'axios';
  3. import { Alert, message } from 'antd';
  4. export default class Notify extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. newVersion: process.env.version,
  9. version: process.env.version
  10. };
  11. }
  12. componentDidMount() {
  13. axios.get('https://www.easy-mock.com/mock/5c2851e3d84c733cb500c3b9/yapi/versions').then(req => {
  14. if (req.status === 200) {
  15. this.setState({ newVersion: req.data.data[0] });
  16. } else {
  17. message.error('无法获取新版本信息!');
  18. }
  19. });
  20. }
  21. render() {
  22. const isShow = this.state.newVersion !== this.state.version;
  23. return (
  24. <div>
  25. {isShow && (
  26. <Alert
  27. message={
  28. <div>
  29. 当前版本是:{this.state.version}&nbsp;&nbsp;可升级到: {this.state.newVersion}
  30. &nbsp;&nbsp;&nbsp;
  31. <a
  32. target="view_window"
  33. href="https://github.com/YMFE/yapi/blob/master/CHANGELOG.md"
  34. >
  35. 版本详情
  36. </a>
  37. </div>
  38. }
  39. banner
  40. closable
  41. type="info"
  42. />
  43. )}
  44. </div>
  45. );
  46. }
  47. }