Files
JsonTool/json-to-class/src/serve/gitee.ts
2024-09-27 01:15:47 +08:00

48 lines
1.2 KiB
TypeScript
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.

/*
* Copyright (c) 2023.
*
* 作者bmy
* 邮箱2271608011@qq.com
* giteehttps://gitee.com/bmycode
* githubhttps://github.com/helpcode
*
*/
import Http from "@/http";
import config from "@/config";
import type { ReleasesLatestType } from "@/serve/types/ReleasesLatestType";
class Gitee {
public async ReleasesLatest(): Promise<ReleasesLatestType> {
return await Http.get(config.giteeApi.releasesUrl)
}
/**
*
* @param curV 新版本号
* @param reqV 当前应用的版本号
*/
public compare(curV: string, reqV: string): boolean {
if (curV && reqV) {
//将两个版本号拆成数字
let arr1 = curV.split('.'),
arr2 = reqV.split('.');
let minLength = Math.min(arr1.length, arr2.length),
position = 0,
diff = 0;
//依次比较版本号每一位大小,当对比得出结果后跳出循环(后文有简单介绍)
while (position < minLength && ((diff = parseInt(arr1[position]) - parseInt(arr2[position])) == 0)) {
position++;
}
diff = (diff != 0) ? diff : (arr1.length - arr2.length);
//若curV大于reqV则返回true
return diff > 0;
} else {
//输入为空
return false;
}
}
}
export default new Gitee