提交 856c93a3 编写于 作者: D DCloud_LXH

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

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