mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2025-12-17 16:05:53 +08:00
优化app中应用升级逻辑
This commit is contained in:
@@ -5,6 +5,27 @@
|
|||||||
import { getAppVersion } from "@/api/message.js";
|
import { getAppVersion } from "@/api/message.js";
|
||||||
|
|
||||||
const platform = uni.getSystemInfoSync().platform;
|
const platform = uni.getSystemInfoSync().platform;
|
||||||
|
|
||||||
|
// 版本号比较函数
|
||||||
|
function compareVersion(version1, version2) {
|
||||||
|
const v1Parts = version1.split('.').map(Number);
|
||||||
|
const v2Parts = version2.split('.').map(Number);
|
||||||
|
|
||||||
|
const maxLength = Math.max(v1Parts.length, v2Parts.length);
|
||||||
|
|
||||||
|
for (let i = 0; i < maxLength; i++) {
|
||||||
|
const v1Part = v1Parts[i] || 0;
|
||||||
|
const v2Part = v2Parts[i] || 0;
|
||||||
|
|
||||||
|
if (v1Part > v2Part) {
|
||||||
|
return 1;
|
||||||
|
} else if (v1Part < v2Part) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
// 主颜色
|
// 主颜色
|
||||||
const $mainColor = "#1ABC9C";
|
const $mainColor = "#1ABC9C";
|
||||||
// 弹窗图标url
|
// 弹窗图标url
|
||||||
@@ -29,7 +50,7 @@ export const getServerNo = function (callback) {
|
|||||||
platform == "android" ? (type = "ANDROID") : (type = "IOS");
|
platform == "android" ? (type = "ANDROID") : (type = "IOS");
|
||||||
|
|
||||||
getAppVersion(type).then((res) => {
|
getAppVersion(type).then((res) => {
|
||||||
if (res.data.success && res.data.result.downloadUrl) {
|
if (res.data.success && res.data.result && res.data.result.downloadUrl) {
|
||||||
let response = res.data.result;
|
let response = res.data.result;
|
||||||
let result = {};
|
let result = {};
|
||||||
result.versionCode = response.version;
|
result.versionCode = response.version;
|
||||||
@@ -854,11 +875,9 @@ function downloadPopup(data, callback, cancelCallback, rebootCallback) {
|
|||||||
export default function (isPrompt = false) {
|
export default function (isPrompt = false) {
|
||||||
getCurrentNo((version) => {
|
getCurrentNo((version) => {
|
||||||
getServerNo((res) => {
|
getServerNo((res) => {
|
||||||
|
if (compareVersion(res.versionCode, version.version) <= 0) {
|
||||||
if (res.versionCode.replace(/\./g, "") <= version.version.replace(/\./g, "")) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.forceUpdate) {
|
if (res.forceUpdate) {
|
||||||
if (/\.wgt$/i.test(res.downloadUrl)) {
|
if (/\.wgt$/i.test(res.downloadUrl)) {
|
||||||
getDownload(res);
|
getDownload(res);
|
||||||
|
|||||||
Reference in New Issue
Block a user