修改判断是否有新版本方法
This commit is contained in:
parent
b4b88b0cd7
commit
b535e5ad3c
@ -18,7 +18,7 @@ export default defineManifestConfig({
|
||||
appid: VITE_UNI_APPID,
|
||||
description: '',
|
||||
versionName: '2.0.2',
|
||||
versionCode: '20250615',
|
||||
versionCode: '20250616',
|
||||
transformPx: false,
|
||||
locale: VITE_FALLBACK_LOCALE, // 'zh-Hans'
|
||||
/* 5+App特有相关 */
|
||||
|
@ -3,8 +3,8 @@
|
||||
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
||||
import { beforEach } from '@/router/index'
|
||||
import { jurisdictionApi } from '@/api/system';
|
||||
import { useAppStore, useUpdateApp } from '@/store'
|
||||
import { getLocation } from '@/utils';
|
||||
import { useAppStore } from '@/store'
|
||||
import { getLocation, useUpdateApp } from '@/utils';
|
||||
export default {
|
||||
onLaunch: function (options) {
|
||||
// 检查更新
|
||||
|
@ -3,7 +3,7 @@
|
||||
"appid": "__UNI__9F097F0",
|
||||
"description": "",
|
||||
"versionName": "2.0.2",
|
||||
"versionCode": "20250615",
|
||||
"versionCode": "20250616",
|
||||
"transformPx": false,
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
|
@ -1,8 +1,5 @@
|
||||
import { createPinia, defineStore } from 'pinia'
|
||||
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
|
||||
import { upDateAppApi } from '@/api/system'
|
||||
import { hasNewVersion, onClickUpdate } from '@/utils/index'
|
||||
import { getEnvBaseUrl } from '@/utils/index'
|
||||
|
||||
const store = createPinia()
|
||||
store.use(
|
||||
@ -41,66 +38,6 @@ export const useAppStore = defineStore('app', {
|
||||
persist: true, // 启用持久化
|
||||
})
|
||||
|
||||
export const useUpdateApp = defineStore('updateApp', () => {
|
||||
const updateOptions = reactive({
|
||||
force: false,
|
||||
hasNew: false,
|
||||
content: '',
|
||||
url: '',
|
||||
apkUrl: '',
|
||||
wgtUrl: ''
|
||||
})
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
|
||||
/**
|
||||
* 当前处于APP_PLUS时 检查是否有新版本
|
||||
*
|
||||
* @param to 是否跳转新页面显示更新 默认值false
|
||||
*/
|
||||
function checkAppUpdate(to = false) {
|
||||
try {
|
||||
upDateAppApi().then(async (res : any) => {
|
||||
let {
|
||||
result
|
||||
} = res
|
||||
result.apkUrl = getEnvBaseUrl() + '/sys/common/static/' + result.apkUrl
|
||||
result.wgtUrl = getEnvBaseUrl() + '/sys/common/static/' + result.wgtUrl
|
||||
updateOptions.wgtUrl = result.wgtUrl
|
||||
if (systemInfo.osName === 'android') {
|
||||
// Android
|
||||
updateOptions.apkUrl = result.apkUrl
|
||||
// #ifdef APP_PLUS
|
||||
updateOptions.hasNew = await hasNewVersion(result.versionCode, result.update == 'wgt') as boolean
|
||||
// #endif
|
||||
} else {
|
||||
// IOS
|
||||
updateOptions.url = `itms-apps://itunes.apple.com/cn/app/id${123456}?mt=8`
|
||||
}
|
||||
updateOptions.hasNew &&
|
||||
uni.showModal({
|
||||
title: '更新',
|
||||
content: '发现新版本,请更新',
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
onClickUpdate(result.update, result)
|
||||
} else {
|
||||
plus.runtime.quit()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
} catch (error) {
|
||||
updateOptions.hasNew = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
checkAppUpdate,
|
||||
...toRefs(updateOptions),
|
||||
systemInfo
|
||||
}
|
||||
})
|
||||
|
||||
export default store
|
||||
|
||||
// 模块统一导出
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { pages, subPackages, tabBar } from '@/pages.json'
|
||||
import { isMpWeixin } from './platform'
|
||||
import { useAppStore } from '@/store'
|
||||
import { upDateAppApi } from '@/api/system'
|
||||
|
||||
const getLastPage = () => {
|
||||
// getCurrentPages() 至少有1个元素,所以不再额外判断
|
||||
@ -208,6 +210,66 @@ export function formatDate(value, fmt) {
|
||||
}
|
||||
}
|
||||
|
||||
export const useUpdateApp = defineStore('updateApp', () => {
|
||||
const updateOptions = reactive({
|
||||
force: false,
|
||||
hasNew: false,
|
||||
content: '',
|
||||
url: '',
|
||||
apkUrl: '',
|
||||
wgtUrl: ''
|
||||
})
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
|
||||
/**
|
||||
* 当前处于APP_PLUS时 检查是否有新版本
|
||||
*
|
||||
* @param to 是否跳转新页面显示更新 默认值false
|
||||
*/
|
||||
function checkAppUpdate(to = false) {
|
||||
try {
|
||||
upDateAppApi().then(async (res : any) => {
|
||||
let {
|
||||
result
|
||||
} = res
|
||||
result.apkUrl = getEnvBaseUrl() + '/sys/common/static/' + result.apkUrl
|
||||
result.wgtUrl = getEnvBaseUrl() + '/sys/common/static/' + result.wgtUrl
|
||||
updateOptions.wgtUrl = result.wgtUrl
|
||||
if (systemInfo.osName === 'android') {
|
||||
// Android
|
||||
updateOptions.apkUrl = result.apkUrl
|
||||
// #ifdef APP_PLUS
|
||||
updateOptions.hasNew = await hasNewVersion(result.versionCode, result.update == 'wgt') as boolean
|
||||
// #endif
|
||||
} else {
|
||||
// IOS
|
||||
updateOptions.url = `itms-apps://itunes.apple.com/cn/app/id${123456}?mt=8`
|
||||
}
|
||||
updateOptions.hasNew &&
|
||||
uni.showModal({
|
||||
title: '更新',
|
||||
content: '发现新版本,请更新',
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
onClickUpdate(result.update, result)
|
||||
} else {
|
||||
plus.runtime.quit()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
} catch (error) {
|
||||
updateOptions.hasNew = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
checkAppUpdate,
|
||||
...toRefs(updateOptions),
|
||||
systemInfo
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 判断是否有新版本
|
||||
* @param version 接口返回的版本号
|
||||
@ -216,18 +278,14 @@ export function formatDate(value, fmt) {
|
||||
export const hasNewVersion = (version, isWgt = false) => {
|
||||
// #ifdef APP_PLUS
|
||||
return new Promise((resolve) => {
|
||||
const transfer = (str) => {
|
||||
const parts = str.split('.').map(part => part.padStart(4, '0'))
|
||||
return parts.join('')
|
||||
}
|
||||
if (isWgt) {
|
||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||
const currentVersion = widgetInfo.version
|
||||
resolve(+transfer(version) > +transfer(currentVersion))
|
||||
const currentVersion = widgetInfo.versionCode
|
||||
resolve(Number(version) > Number(currentVersion))
|
||||
})
|
||||
} else {
|
||||
const currentVersion = plus.runtime.version
|
||||
resolve(+transfer(version) > +transfer(currentVersion))
|
||||
const currentVersion = plus.runtime.versionCode
|
||||
resolve(Number(version) > Number(currentVersion))
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
|
Loading…
Reference in New Issue
Block a user