修改判断是否有新版本方法
This commit is contained in:
parent
b4b88b0cd7
commit
b535e5ad3c
@ -18,7 +18,7 @@ export default defineManifestConfig({
|
|||||||
appid: VITE_UNI_APPID,
|
appid: VITE_UNI_APPID,
|
||||||
description: '',
|
description: '',
|
||||||
versionName: '2.0.2',
|
versionName: '2.0.2',
|
||||||
versionCode: '20250615',
|
versionCode: '20250616',
|
||||||
transformPx: false,
|
transformPx: false,
|
||||||
locale: VITE_FALLBACK_LOCALE, // 'zh-Hans'
|
locale: VITE_FALLBACK_LOCALE, // 'zh-Hans'
|
||||||
/* 5+App特有相关 */
|
/* 5+App特有相关 */
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
||||||
import { beforEach } from '@/router/index'
|
import { beforEach } from '@/router/index'
|
||||||
import { jurisdictionApi } from '@/api/system';
|
import { jurisdictionApi } from '@/api/system';
|
||||||
import { useAppStore, useUpdateApp } from '@/store'
|
import { useAppStore } from '@/store'
|
||||||
import { getLocation } from '@/utils';
|
import { getLocation, useUpdateApp } from '@/utils';
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function (options) {
|
onLaunch: function (options) {
|
||||||
// 检查更新
|
// 检查更新
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"appid": "__UNI__9F097F0",
|
"appid": "__UNI__9F097F0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"versionName": "2.0.2",
|
"versionName": "2.0.2",
|
||||||
"versionCode": "20250615",
|
"versionCode": "20250616",
|
||||||
"transformPx": false,
|
"transformPx": false,
|
||||||
"app-plus": {
|
"app-plus": {
|
||||||
"usingComponents": true,
|
"usingComponents": true,
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import { createPinia, defineStore } from 'pinia'
|
import { createPinia, defineStore } from 'pinia'
|
||||||
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
|
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()
|
const store = createPinia()
|
||||||
store.use(
|
store.use(
|
||||||
@ -41,66 +38,6 @@ export const useAppStore = defineStore('app', {
|
|||||||
persist: true, // 启用持久化
|
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
|
export default store
|
||||||
|
|
||||||
// 模块统一导出
|
// 模块统一导出
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
import { pages, subPackages, tabBar } from '@/pages.json'
|
import { pages, subPackages, tabBar } from '@/pages.json'
|
||||||
import { isMpWeixin } from './platform'
|
import { isMpWeixin } from './platform'
|
||||||
import { useAppStore } from '@/store'
|
import { useAppStore } from '@/store'
|
||||||
|
import { upDateAppApi } from '@/api/system'
|
||||||
|
|
||||||
const getLastPage = () => {
|
const getLastPage = () => {
|
||||||
// getCurrentPages() 至少有1个元素,所以不再额外判断
|
// 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 接口返回的版本号
|
* @param version 接口返回的版本号
|
||||||
@ -216,18 +278,14 @@ export function formatDate(value, fmt) {
|
|||||||
export const hasNewVersion = (version, isWgt = false) => {
|
export const hasNewVersion = (version, isWgt = false) => {
|
||||||
// #ifdef APP_PLUS
|
// #ifdef APP_PLUS
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const transfer = (str) => {
|
|
||||||
const parts = str.split('.').map(part => part.padStart(4, '0'))
|
|
||||||
return parts.join('')
|
|
||||||
}
|
|
||||||
if (isWgt) {
|
if (isWgt) {
|
||||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||||
const currentVersion = widgetInfo.version
|
const currentVersion = widgetInfo.versionCode
|
||||||
resolve(+transfer(version) > +transfer(currentVersion))
|
resolve(Number(version) > Number(currentVersion))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const currentVersion = plus.runtime.version
|
const currentVersion = plus.runtime.versionCode
|
||||||
resolve(+transfer(version) > +transfer(currentVersion))
|
resolve(Number(version) > Number(currentVersion))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// #endif
|
// #endif
|
||||||
|
Loading…
Reference in New Issue
Block a user