Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复版本判断 #2637 #2640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions client/components/Notify/Notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div>
{isShow && (
Expand Down