diff --git a/client/components/Notify/Notify.js b/client/components/Notify/Notify.js index 3fb84ddfc..6a63a584a 100644 --- a/client/components/Notify/Notify.js +++ b/client/components/Notify/Notify.js @@ -12,18 +12,45 @@ export default class Notify extends Component { } componentDidMount() { - const versions = 'https://www.fastmock.site/mock/1529fa78fa4c4880ad153d115084a940/yapi/versions'; + const versions = 'https://registry.npmmirror.com/yapi-vendor'; axios.get(versions).then(req => { if (req.status === 200) { - this.setState({ newVersion: req.data.data[0] }); + this.setState({ newVersion: req.data.dist-tags.latest }); } else { message.error('无法获取新版本信息!'); } }); } + /** + * 版本号比较 + * latestVersion < nowVersion ==> -1; + * latestVersion == nowVersion ==> 0; + * latestVersion > nowVersion ==> 1; + * @param {当前版本号} nowVersion + * @param {最新版本号} latestVersion + * @returns 1、-1、0 + */ + compareVersion(nowVersion, latestVersion) { + nowVersion = nowVersion.replace(/[^0-9.]/, ''); + latestVersion = latestVersion.replace(/[^0-9.]/, ''); + if(nowVersion === latestVersion) return 0; + let arr1 = latestVersion.split('.'); + let arr2 = nowVersion.split('.'); + let minLength = Math.min(arr1.length, arr2.length) + for (let i = 0; index < minLength; i++) { + if(arr1[i] > arr2[i]) { + return 1; + } else if (arr1[i] < arr2[i]) { + return -1; + } + } + return 0; + } + render() { - const isShow = this.state.newVersion !== this.state.version; + const isShow = this.compareVersion(this.state.version, this.state.newVersion) == 1; + return (
{isShow && (