提交 a0394b8b 编写于 作者: D DCloud_LXH

feat(升级中心): 升级至 0.9.0 使用 dialogPage 实现需要 HBuilderX 4.31

上级 afa3298d
......@@ -1258,6 +1258,15 @@
"enablePullDownRefresh": false
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS
{
"path" : "uni_modules/uni-upgrade-center-app/pages/uni-app-x/upgrade-popup",
"style" :
{
"navigationBarTitleText" : ""
}
},
// #endif
{
"path": "pages/tabBar/CSS",
......
......@@ -39,10 +39,6 @@
</template>
</uni-collapse-item>
</uni-collapse>
<!-- #ifdef UNI-APP-X && APP -->
<uni-upgrade-center-app ref="upgradePopup" @show="upgradePopupShow" @close="upgradePopupClose" />
<!-- #endif -->
</view>
<!-- #ifdef APP -->
</scroll-view>
......@@ -80,19 +76,7 @@
} else {
uni.navigateTo({ url })
}
},
// #ifdef UNI-APP-X && APP
upgradePopupShow() {
console.log('upgradePopup show');
if (!this.pageHiden) {
uni.hideTabBar()?.catch(_ => { })
}
}
, upgradePopupClose() {
console.log('upgradePopup close');
uni.showTabBar()?.catch(_ => { })
}
// #endif
},
// #ifdef WEB
watch: {
......@@ -118,11 +102,11 @@
if (res.needAuthorization) {
uni.onPrivacyAuthorizationChange((res) => {
if (!res.needAuthorization) {
checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
checkUpdate()
}
})
} else {
checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
checkUpdate()
}
}
})
......
## 0.9.0(2024-10-30)
- **重要更新** 在 uni-app x 项目中弃用之前弹窗方案使用[dialogPage](https://doc.dcloud.net.cn/uni-app-x/api/dialog-page.html)实现,需要 `HBuilderX 4.31+`
## 0.8.5(2024-10-26)
- 优化 去除不必要代码
## 0.8.4(2024-10-26)
......
{
"id": "uni-upgrade-center-app",
"displayName": "升级中心 uni-upgrade-center - App",
"version": "0.8.5",
"version": "0.9.0",
"description": "uni升级中心 - 客户端检查更新",
"keywords": [
"uniCloud",
......
<template>
<view v-show="shown" class="mask flex-center">
<view class="mask flex-center">
<view class="content">
<view class="content-top">
<text class="content-top-text">{{title}}</text>
<image class="content-top-image" mode="widthFix"
......@@ -31,10 +30,13 @@
<template v-else>
<template v-if="!downloadSuccess">
<view class="progress-box flex-column" v-if="downloading">
<progress class="progress" :percent="downLoadPercent" activeColor="#3DA7FF" :show-info="true" :stroke-width="10" />
<view style="width:100%;display: flex;justify-content: space-around;flex-direction: row;">
<progress class="progress" :percent="downLoadPercent" activeColor="#3DA7FF"
:show-info="true" :stroke-width="10" />
<view
style="width:100%;display: flex;justify-content: space-around;flex-direction: row;">
<text class="text" style="font-size: 14px;">{{downLoadingText}}</text>
<text class="text" style="font-size: 14px;">({{downloadedSize}}/{{packageFileSize}}M)</text>
<text class="text"
style="font-size: 14px;">({{downloadedSize}}/{{packageFileSize}}M)</text>
</view>
</view>
......@@ -43,7 +45,8 @@
</button>
</template>
<button v-else-if="downloadSuccess && !installed" class="content-button" :loading="installing" :disabled="installing" @click="installPackage">
<button v-else-if="downloadSuccess && !installed" class="content-button" :loading="installing"
:disabled="installing" @click="installPackage">
{{installing ? '正在安装……' : '下载完成,立即安装'}}
</button>
......@@ -55,7 +58,8 @@
</view>
<view class="content-bottom">
<image v-if="!is_mandatory" class="close-img" mode="widthFix" src="/uni_modules/uni-upgrade-center-app/static/app/app_update_close.png" @click="closeUpdate">
<image v-if="!is_mandatory" class="close-img" mode="widthFix"
src="/uni_modules/uni-upgrade-center-app/static/app/app_update_close.png" @click="closeUpdate">
</image>
</view>
</view>
......@@ -67,27 +71,24 @@
import { createNotificationProgress, cancelNotificationProgress, finishNotificationProgress } from '@/uni_modules/uts-progressNotification'
import { type CreateNotificationProgressOptions, type FinishNotificationProgressOptions } from '@/uni_modules/uts-progressNotification/utssdk/interface.uts'
import { UniUpgradeCenterResult, StoreListItem } from '../../utils/call-check-version'
const platform_iOS = 'iOS';
const platform_Android = 'Android';
const requiredKey = ['version', 'url', 'type']
let downloadTask : DownloadTask | null = null;
let openSchemePromise: Promise<boolean> | null = null;
let openSchemePromise : Promise<boolean> | null = null;
const openSchema = (url: string): Promise<boolean> => new Promise<boolean>((resolve,reject) =>{
try{
const openSchema = (url : string) : Promise<boolean> => new Promise<boolean>((resolve, reject) => {
try {
utsOpenSchema(url)
resolve(true)
}catch(e){
} catch (e) {
reject(false)
}
})
export default {
emits: ['close', 'show'],
data() {
return {
shown: false,
// 从之前下载安装
installForBeforeFilePath: '',
......@@ -128,26 +129,52 @@
isAndroid() : boolean {
return this.platform.includes(platform_Android);
},
needNotificationProgress(): boolean {
needNotificationProgress() : boolean {
return this.isAndroid && !this.is_mandatory
}
},
beforeUnmount() {
onUnload() {
if (this.needNotificationProgress) {
cancelNotificationProgress()
}
},
onLoad(onLoadOptions: OnLoadOptions) {
const local_storage_key: string | null = onLoadOptions['local_storage_key']
if (local_storage_key == null) {
console.error('local_storage_key为空,请检查后重试')
this.closePopup()
return;
};
const localPackageInfo = uni.getStorageSync(local_storage_key);
if (localPackageInfo == null) {
console.error('安装包信息为空,请检查后重试')
this.closePopup()
return;
};
this.show(JSON.parse<UniUpgradeCenterResult>(JSON.stringify(localPackageInfo)) as UniUpgradeCenterResult)
},
onBackPress(options : OnBackPressOptions) : boolean | null {
if (this.is_mandatory) return true
if (!this.needNotificationProgress) {
if (downloadTask !== null) {
downloadTask!.abort()
}
}
return false
},
methods: {
jumpToAppStore() {
openSchema(this.url)
},
show(shown : boolean, localPackageInfo : UniUpgradeCenterResult | null) {
show(localPackageInfo : UniUpgradeCenterResult | null) {
if (localPackageInfo === null) return;
for (let key in localPackageInfo) {
if (requiredKey.indexOf(key) != -1 && localPackageInfo[key] === null) {
console.error(`参数 ${key} 必填,请检查后重试`)
uni.navigateBack()
this.closePopup()
return;
}
}
......@@ -159,9 +186,6 @@
this.platform = localPackageInfo.platform
this.version = localPackageInfo.version
this.store_list = localPackageInfo.store_list
this.shown = shown
this.$emit('show')
},
askAbortDownload() {
uni.showModal({
......@@ -177,23 +201,14 @@
});
},
closeUpdate() {
if (this.downloading) {
if (this.is_mandatory) {
return uni.showToast({
title: '下载中,请稍后……',
icon: 'none',
duration: 500
})
}
if (!this.needNotificationProgress) {
if (this.downloading && !this.needNotificationProgress) {
this.askAbortDownload()
return;
}
}
this.closePopup()
},
closePopup() {
this.shown = false
this.downloadSuccess = false
this.downloading = false
this.downLoadPercent = 0
......@@ -204,8 +219,9 @@
this.installing = false
this.installed = false
if (this.needNotificationProgress) cancelNotificationProgress()
this.$emit('close')
uni.closeDialogPage({
dialogPage: this.$page
})
},
updateApp() {
const checkStoreScheme = this.checkStoreScheme()
......@@ -219,18 +235,18 @@
} else { this.downloadPackage() }
},
// 跳转应用商店
checkStoreScheme(): Promise<boolean> | null {
checkStoreScheme() : Promise<boolean> | null {
if (this.store_list !== null) {
const storeList: StoreListItem[] = this.store_list!.filter((item: StoreListItem): boolean => item.enable)
const storeList : StoreListItem[] = this.store_list!.filter((item : StoreListItem) : boolean => item.enable)
if (storeList.length > 0) {
if (openSchemePromise === null) {
openSchemePromise = Promise.reject() as Promise<boolean>
}
storeList
.sort((cur: StoreListItem, next: StoreListItem): number => next.priority - cur.priority)
.map((item: StoreListItem): string => item.scheme)
.reduce((promise: Promise<boolean>, cur: string): Promise<boolean> => {
openSchemePromise = promise.catch<boolean>((): Promise<boolean> => openSchema(cur))
.sort((cur : StoreListItem, next : StoreListItem) : number => next.priority - cur.priority)
.map((item : StoreListItem) : string => item.scheme)
.reduce((promise : Promise<boolean>, cur : string) : Promise<boolean> => {
openSchemePromise = promise.catch<boolean>(() : Promise<boolean> => openSchema(cur))
return openSchemePromise!
}, openSchemePromise!)
return openSchemePromise!
......@@ -292,7 +308,7 @@
finishNotificationProgress({
title: "安装升级包",
content: "下载完成",
onClick(){}
onClick() { }
} as FinishNotificationProgressOptions)
this.installPackage();
......@@ -310,7 +326,6 @@
uni.installApk({
filePath: this.tempFilePath,
success: _ => {
console.log('installApk success');
this.installing = false;
this.installed = true;
},
......
......@@ -6,13 +6,7 @@ import { openSchema } from '@/uni_modules/uts-openSchema'
// 推荐再App.vue中使用
const PACKAGE_INFO_KEY = '__package_info__'
// uni-app 项目无法从 vue 中导出 ComponentPublicInstance 类型,故使用条件编译
// #ifdef UNI-APP-X
export default function (component : ComponentPublicInstance | null = null) : Promise<UniUpgradeCenterResult> {
// #endif
// #ifndef UNI-APP-X
export default function () : Promise<UniUpgradeCenterResult> {
// #endif
return new Promise<UniUpgradeCenterResult>((resolve, reject) => {
callCheckVersion().then(async (uniUpgradeCenterResult) => {
// NOTE uni-app x 3.96 解构有问题
......@@ -54,8 +48,8 @@ export default function () : Promise<UniUpgradeCenterResult> {
* 提示升级二
* 官方适配的升级弹窗,可自行替换资源适配UI风格
*/
// #ifndef UNI-APP-X
uni.setStorageSync(PACKAGE_INFO_KEY, uniUpgradeCenterResult)
// #ifndef UNI-APP-X
uni.navigateTo({
url: `/uni_modules/uni-upgrade-center-app/pages/upgrade-popup?local_storage_key=${PACKAGE_INFO_KEY}`,
fail: (err) => {
......@@ -65,7 +59,14 @@ export default function () : Promise<UniUpgradeCenterResult> {
})
// #endif
// #ifdef UNI-APP-X
component?.$callMethod('show', true, uniUpgradeCenterResult)
uni.openDialogPage({
url: `/uni_modules/uni-upgrade-center-app/pages/uni-app-x/upgrade-popup?local_storage_key=${PACKAGE_INFO_KEY}`,
disableEscBack: true,
fail: (err) => {
console.error('更新弹框跳转失败', err)
uni.removeStorageSync(PACKAGE_INFO_KEY)
}
})
// #endif
return resolve(uniUpgradeCenterResult)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册