Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
1c544af2
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1c544af2
编写于
12月 08, 2023
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 升级中心适配通知栏进度条
上级
eaad25d3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
169 addition
and
55 deletion
+169
-55
uni_modules/uni-upgrade-center-app/components/uni-upgrade-center-app/uni-upgrade-center-app.uvue
...onents/uni-upgrade-center-app/uni-upgrade-center-app.uvue
+73
-24
uni_modules/uni-upgrade-center-app/package.json
uni_modules/uni-upgrade-center-app/package.json
+3
-1
uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue
uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue
+74
-29
uni_modules/uni-upgrade-center-app/utils/call-check-version.ts
...odules/uni-upgrade-center-app/utils/call-check-version.ts
+1
-1
uni_modules/uni-upgrade-center-app/utils/check-update.ts
uni_modules/uni-upgrade-center-app/utils/check-update.ts
+18
-0
未找到文件。
uni_modules/uni-upgrade-center-app/components/uni-upgrade-center-app/uni-upgrade-center-app.uvue
浏览文件 @
1c544af2
...
@@ -46,8 +46,8 @@
...
@@ -46,8 +46,8 @@
{{installing ? '正在安装……' : '下载完成,立即安装'}}
{{installing ? '正在安装……' : '下载完成,立即安装'}}
</button>
</button>
<button v-else-if="installed" class="content-button"
:disabled="tru
e">
<button v-else-if="installed" class="content-button"
@click="installPackag
e">
安装
完成后,请重启应用
安装
未完成,点击安装
</button>
</button>
</template>
</template>
</view>
</view>
...
@@ -67,9 +67,11 @@
...
@@ -67,9 +67,11 @@
const localFilePathKey = 'UNI_ADMIN_UPGRADE_CENTER_LOCAL_FILE_PATH'
const localFilePathKey = 'UNI_ADMIN_UPGRADE_CENTER_LOCAL_FILE_PATH'
const platform_iOS = 'iOS';
const platform_iOS = 'iOS';
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;
let notificationAbortDownload: boolean = false
/**
/**
* 对比版本号,如需要,请自行修改判断规则
* 对比版本号,如需要,请自行修改判断规则
...
@@ -115,6 +117,7 @@
...
@@ -115,6 +117,7 @@
}
}
export default {
export default {
emits: ['close'],
data() {
data() {
return {
return {
shown: false,
shown: false,
...
@@ -141,23 +144,33 @@
...
@@ -141,23 +144,33 @@
contents: '',
contents: '',
version: '',
version: '',
is_mandatory: false,
is_mandatory: false,
url: "",
platform: [] as string[],
store_list: null as StoreListItem[] | null,
// 可自定义属性
// 可自定义属性
subTitle: '发现新版本',
subTitle: '发现新版本',
downLoadBtnTextiOS: '立即跳转更新',
downLoadBtnTextiOS: '立即跳转更新',
downLoadBtnText: '立即下载更新',
downLoadBtnText: '立即下载更新',
downLoadingText: '安装包下载中,请稍后',
downLoadingText: '安装包下载中,请稍后'
url: "",
platform: [] as string[],
store_list: null as StoreListItem[] | null
}
}
},
},
computed: {
computed: {
isiOS() : boolean {
isiOS() : boolean {
return this.platform.includes(platform_iOS);
return this.platform.includes(platform_iOS);
},
isAndroid() : boolean {
return this.platform.includes(platform_Android);
},
needNotificationProgress(): boolean {
return this.isAndroid && !this.is_mandatory
}
}
},
},
beforeUnmount() {
if (this.needNotificationProgress) {
uni.cancelNotificationProgress()
}
},
methods: {
methods: {
show(shown : boolean, localPackageInfo : UniUpgradeCenterResult | null) {
show(shown : boolean, localPackageInfo : UniUpgradeCenterResult | null) {
if (localPackageInfo === null) return;
if (localPackageInfo === null) return;
...
@@ -181,6 +194,19 @@
...
@@ -181,6 +194,19 @@
this.store_list = localPackageInfo.store_list
this.store_list = localPackageInfo.store_list
this.shown = shown
this.shown = shown
},
},
askAbortDownload() {
uni.showModal({
title: '是否取消下载?',
cancelText: '否',
confirmText: '是',
success: res => {
if (res.confirm) {
if (downloadTask !== null) downloadTask!.abort()
this.closePopup()
}
}
});
},
closeUpdate() {
closeUpdate() {
if (this.downloading) {
if (this.downloading) {
if (this.is_mandatory) {
if (this.is_mandatory) {
...
@@ -190,18 +216,10 @@
...
@@ -190,18 +216,10 @@
duration: 500
duration: 500
})
})
}
}
uni.showModal({
if (!this.needNotificationProgress) {
title: '是否取消下载?',
this.askAbortDownload()
cancelText: '否',
return;
confirmText: '是',
}
success: res => {
if (res.confirm) {
if (downloadTask !== null) downloadTask!.abort()
this.closePopup()
}
}
});
return;
}
}
this.closePopup()
this.closePopup()
},
},
...
@@ -222,7 +240,11 @@
...
@@ -222,7 +240,11 @@
this.installed = false
this.installed = false
this.showTabbar = false
this.showTabbar = false
this.$emit('close')
if (this.needNotificationProgress) uni.cancelNotificationProgress()
if (!notificationAbortDownload) this.$emit('close')
notificationAbortDownload = false
},
},
updateApp() {
updateApp() {
const checkStoreScheme = this.checkStoreScheme()
const checkStoreScheme = this.checkStoreScheme()
...
@@ -261,7 +283,6 @@
...
@@ -261,7 +283,6 @@
downloadTask = uni.downloadFile({
downloadTask = uni.downloadFile({
url: this.url,
url: this.url,
success: res => {
success: res => {
console.log('downloadFile res: ', res);
if (res.statusCode == 200) {
if (res.statusCode == 200) {
this.tempFilePath = res.tempFilePath
this.tempFilePath = res.tempFilePath
this.downLoadComplete()
this.downLoadComplete()
...
@@ -273,10 +294,27 @@
...
@@ -273,10 +294,27 @@
});
});
if (downloadTask !== null) {
if (downloadTask !== null) {
this.downloading = true;
this.downloading = true;
if (this.needNotificationProgress) {
this.closePopup()
}
downloadTask!.onProgressUpdate(res => {
downloadTask!.onProgressUpdate(res => {
this.downLoadPercent = parseFloat(res.progress.toFixed(0));
this.downLoadPercent = parseFloat(res.progress.toFixed(0));
this.downloadedSize = parseFloat((res.totalBytesWritten / Math.pow(1024, 2)).toFixed(2));
this.downloadedSize = parseFloat((res.totalBytesWritten / Math.pow(1024, 2)).toFixed(2));
this.packageFileSize = parseFloat((res.totalBytesExpectedToWrite / Math.pow(1024, 2)).toFixed(2));
this.packageFileSize = parseFloat((res.totalBytesExpectedToWrite / Math.pow(1024, 2)).toFixed(2));
if (this.needNotificationProgress) {
uni.createNotificationProgress({
title: "升级中心正在下载安装包……",
content: `${this.downLoadPercent}%`,
progress: this.downLoadPercent,
onClick: () => {
if (!this.downloadSuccess) {
this.askAbortDownload()
notificationAbortDownload = true
}
}
})
}
});
});
}
}
},
},
...
@@ -290,9 +328,20 @@
...
@@ -290,9 +328,20 @@
downloadTask = null;
downloadTask = null;
if (this.needNotificationProgress) {
uni.finishNotificationProgress({
title: "安装升级包",
content: "下载完成",
onClick(){}
})
this.installPackage();
return
}
// 强制更新,直接安装
// 强制更新,直接安装
if (this.is_mandatory) {
if (this.is_mandatory) {
this.installPackage();
this.installPackage();
}
}
},
},
installPackage() {
installPackage() {
...
@@ -306,7 +355,7 @@
...
@@ -306,7 +355,7 @@
this.installed = true;
this.installed = true;
},
},
fail: err => {
fail: err => {
console.
log('installApk fail'
);
console.
error('installApk fail', err
);
// 安装失败需要重新下载安装包
// 安装失败需要重新下载安装包
this.installing = false;
this.installing = false;
this.installed = false;
this.installed = false;
...
@@ -319,7 +368,7 @@
...
@@ -319,7 +368,7 @@
}
}
});
});
//
非wgt包,
安装跳出覆盖安装,此处直接返回上一页
// 安装跳出覆盖安装,此处直接返回上一页
if (!this.is_mandatory) {
if (!this.is_mandatory) {
uni.navigateBack()
uni.navigateBack()
}
}
...
...
uni_modules/uni-upgrade-center-app/package.json
浏览文件 @
1c544af2
...
@@ -34,7 +34,9 @@
...
@@ -34,7 +34,9 @@
"type"
:
"unicloud-template-page"
"type"
:
"unicloud-template-page"
},
},
"uni_modules"
:
{
"uni_modules"
:
{
"dependencies"
:
[],
"dependencies"
:
[
"uni-progress-notification"
],
"encrypt"
:
[],
"encrypt"
:
[],
"platforms"
:
{
"platforms"
:
{
"cloud"
:
{
"cloud"
:
{
...
...
uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue
浏览文件 @
1c544af2
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
<view
class=
"content-body"
>
<view
class=
"content-body"
>
<view
class=
"title"
>
<view
class=
"title"
>
<text>
{{
subTitle
}}
</text>
<text>
{{
subTitle
}}
</text>
<
!--
<text
style=
"padding-left:20rpx;font-size: 0.5em;color: #666;"
>
v.
{{
version
}}
</text>
--
>
<
text
class=
"content-body-version"
>
{{
version
}}
</text
>
</view>
</view>
<view
class=
"body"
>
<view
class=
"body"
>
<scroll-view
class=
"box-des-scroll"
scroll-y=
"true"
>
<scroll-view
class=
"box-des-scroll"
scroll-y=
"true"
>
...
@@ -44,8 +44,12 @@
...
@@ -44,8 +44,12 @@
plain
:loading=
"installing"
:disabled=
"installing"
@
click=
"installPackage"
>
plain
:loading=
"installing"
:disabled=
"installing"
@
click=
"installPackage"
>
{{installing ? '正在安装……' : '下载完成,立即安装'}}
{{installing ? '正在安装……' : '下载完成,立即安装'}}
</button>
</button>
<button
v-else-if=
"installed && !isWGT"
class=
"content-button"
style=
"border: none;color: #fff;"
plain
:loading=
"installing"
:disabled=
"installing"
@
click=
"installPackage"
>
安装未完成,点击安装
</button>
<button
v-if=
"installed && isWGT"
class=
"content-button"
style=
"border: none;color: #fff;"
plain
<button
v-
else-
if=
"installed && isWGT"
class=
"content-button"
style=
"border: none;color: #fff;"
plain
@
click=
"restart"
>
@
click=
"restart"
>
安装完毕,点击重启
安装完毕,点击重启
</button>
</button>
...
@@ -62,6 +66,7 @@
...
@@ -62,6 +66,7 @@
<
script
>
<
script
>
const
localFilePathKey
=
'
UNI_ADMIN_UPGRADE_CENTER_LOCAL_FILE_PATH
'
const
localFilePathKey
=
'
UNI_ADMIN_UPGRADE_CENTER_LOCAL_FILE_PATH
'
const
platform_iOS
=
'
iOS
'
;
const
platform_iOS
=
'
iOS
'
;
const
platform_Android
=
'
Android
'
;
let
downloadTask
=
null
;
let
downloadTask
=
null
;
let
openSchemePromise
let
openSchemePromise
...
@@ -170,11 +175,8 @@
...
@@ -170,11 +175,8 @@
},
},
onBackPress
()
{
onBackPress
()
{
// 强制更新不允许返回
// 强制更新不允许返回
if
(
this
.
is_mandatory
)
{
if
(
this
.
is_mandatory
)
return
true
return
true
if
(
!
this
.
needNotificationProgress
)
downloadTask
&&
downloadTask
.
abort
()
}
downloadTask
&&
downloadTask
.
abort
()
},
},
onHide
()
{
onHide
()
{
openSchemePromise
=
null
openSchemePromise
=
null
...
@@ -186,8 +188,14 @@
...
@@ -186,8 +188,14 @@
isiOS
()
{
isiOS
()
{
return
!
this
.
isWGT
?
this
.
platform
.
includes
(
platform_iOS
)
:
false
;
return
!
this
.
isWGT
?
this
.
platform
.
includes
(
platform_iOS
)
:
false
;
},
},
isAndroid
()
{
return
this
.
platform
.
includes
(
platform_Android
)
},
isAppStore
()
{
isAppStore
()
{
return
this
.
isiOS
||
(
!
this
.
isiOS
&&
!
this
.
isWGT
&&
this
.
url
.
indexOf
(
'
.apk
'
)
===
-
1
)
return
this
.
isiOS
||
(
!
this
.
isiOS
&&
!
this
.
isWGT
&&
this
.
url
.
indexOf
(
'
.apk
'
)
===
-
1
)
},
needNotificationProgress
()
{
return
this
.
isAndroid
&&
!
this
.
is_mandatory
}
}
},
},
methods
:
{
methods
:
{
...
@@ -212,6 +220,19 @@
...
@@ -212,6 +220,19 @@
}
}
}
}
},
},
askAbortDownload
()
{
uni
.
showModal
({
title
:
'
是否取消下载?
'
,
cancelText
:
'
否
'
,
confirmText
:
'
是
'
,
success
:
res
=>
{
if
(
res
.
confirm
)
{
downloadTask
&&
downloadTask
.
abort
()
uni
.
navigateBack
()
}
}
});
},
async
closeUpdate
()
{
async
closeUpdate
()
{
if
(
this
.
downloading
)
{
if
(
this
.
downloading
)
{
if
(
this
.
is_mandatory
)
{
if
(
this
.
is_mandatory
)
{
...
@@ -221,37 +242,27 @@
...
@@ -221,37 +242,27 @@
duration
:
500
duration
:
500
})
})
}
}
uni
.
showModal
({
if
(
!
this
.
needNotificationProgress
)
{
title
:
'
是否取消下载?
'
,
this
.
askAbortDownload
()
cancelText
:
'
否
'
,
return
;
confirmText
:
'
是
'
,
}
success
:
res
=>
{
if
(
res
.
confirm
)
{
downloadTask
&&
downloadTask
.
abort
()
uni
.
navigateBack
()
}
}
});
return
;
}
}
if
(
this
.
downloadSuccess
&&
this
.
tempFilePath
)
{
if
(
!
this
.
needNotificationProgress
&&
this
.
downloadSuccess
&&
this
.
tempFilePath
)
{
// 包已经下载完毕,稍后安装,将包保存在本地
// 包已经下载完毕,稍后安装,将包保存在本地
await
this
.
saveFile
(
this
.
tempFilePath
,
this
.
version
)
await
this
.
saveFile
(
this
.
tempFilePath
,
this
.
version
)
uni
.
navigateBack
()
return
;
}
}
uni
.
navigateBack
()
uni
.
navigateBack
()
},
},
updateApp
()
{
updateApp
()
{
this
.
checkStoreScheme
()
this
.
checkStoreScheme
()
.
catch
(()
=>
{
.
catch
(()
=>
{
this
.
downloadPackage
()
this
.
downloadPackage
()
})
})
.
finally
(()
=>
{
.
finally
(()
=>
{
openSchemePromise
=
null
openSchemePromise
=
null
})
})
},
},
// 跳转应用商店
// 跳转应用商店
checkStoreScheme
()
{
checkStoreScheme
()
{
...
@@ -283,7 +294,6 @@
...
@@ -283,7 +294,6 @@
url
:
this
.
url
,
url
:
this
.
url
,
success
:
res
=>
{
success
:
res
=>
{
if
(
res
.
statusCode
==
200
)
{
if
(
res
.
statusCode
==
200
)
{
this
.
downloadSuccess
=
true
;
// fix: wgt 文件下载完成后后缀不是 wgt
// fix: wgt 文件下载完成后后缀不是 wgt
if
(
this
.
isWGT
&&
res
.
tempFilePath
.
split
(
'
.
'
).
slice
(
-
1
)[
0
]
!==
'
wgt
'
)
{
if
(
this
.
isWGT
&&
res
.
tempFilePath
.
split
(
'
.
'
).
slice
(
-
1
)[
0
]
!==
'
wgt
'
)
{
const
failCallback
=
(
e
)
=>
{
const
failCallback
=
(
e
)
=>
{
...
@@ -310,9 +320,24 @@
...
@@ -310,9 +320,24 @@
this
.
downLoadPercent
=
res
.
progress
;
this
.
downLoadPercent
=
res
.
progress
;
this
.
downloadedSize
=
(
res
.
totalBytesWritten
/
Math
.
pow
(
1024
,
2
)).
toFixed
(
2
);
this
.
downloadedSize
=
(
res
.
totalBytesWritten
/
Math
.
pow
(
1024
,
2
)).
toFixed
(
2
);
this
.
packageFileSize
=
(
res
.
totalBytesExpectedToWrite
/
Math
.
pow
(
1024
,
2
)).
toFixed
(
2
);
this
.
packageFileSize
=
(
res
.
totalBytesExpectedToWrite
/
Math
.
pow
(
1024
,
2
)).
toFixed
(
2
);
if
(
this
.
needNotificationProgress
&&
!
this
.
downloadSuccess
)
{
uni
.
createNotificationProgress
({
title
:
"
升级中心正在下载安装包……
"
,
content
:
`
${
this
.
downLoadPercent
}
%`
,
progress
:
this
.
downLoadPercent
,
onClick
:
()
=>
{
this
.
askAbortDownload
()
}
})
}
});
});
if
(
this
.
needNotificationProgress
)
{
uni
.
navigateBack
()
}
},
},
downLoadComplete
()
{
downLoadComplete
()
{
this
.
downloadSuccess
=
true
;
this
.
downloading
=
false
;
this
.
downloading
=
false
;
this
.
downLoadPercent
=
0
this
.
downLoadPercent
=
0
...
@@ -321,6 +346,16 @@
...
@@ -321,6 +346,16 @@
downloadTask
=
null
;
downloadTask
=
null
;
if
(
this
.
needNotificationProgress
)
{
uni
.
finishNotificationProgress
({
title
:
"
安装升级包
"
,
content
:
"
下载完成
"
})
this
.
installPackage
();
return
}
// 强制更新,直接安装
// 强制更新,直接安装
if
(
this
.
is_mandatory
)
{
if
(
this
.
is_mandatory
)
{
this
.
installPackage
();
this
.
installPackage
();
...
@@ -496,6 +531,16 @@
...
@@ -496,6 +531,16 @@
line-height
:
38px
;
line-height
:
38px
;
}
}
.content-body-version
{
padding-left
:
10px
;
color
:
#fff
;
font-size
:
10px
;
margin-left
:
5px
;
padding
:
2px
4px
;
border-radius
:
10px
;
background
:
#50aefd
;
}
.footer
{
.footer
{
height
:
150
rpx
;
height
:
150
rpx
;
display
:
flex
;
display
:
flex
;
...
...
uni_modules/uni-upgrade-center-app/utils/call-check-version.ts
浏览文件 @
1c544af2
...
@@ -34,7 +34,7 @@ export default function () : Promise<UniUpgradeCenterResult> {
...
@@ -34,7 +34,7 @@ export default function () : Promise<UniUpgradeCenterResult> {
return
new
Promise
<
UniUpgradeCenterResult
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
UniUpgradeCenterResult
>
((
resolve
,
reject
)
=>
{
const
systemInfo
=
uni
.
getSystemInfoSync
()
const
systemInfo
=
uni
.
getSystemInfoSync
()
const
appId
=
systemInfo
.
appId
const
appId
=
systemInfo
.
appId
const
appVersion
=
systemInfo
.
appVersion
const
appVersion
=
'
1.0.15
'
//
systemInfo.appVersion
// #ifndef UNI-APP-X
// #ifndef UNI-APP-X
if
(
typeof
appId
===
'
string
'
&&
typeof
appVersion
===
'
string
'
&&
appId
.
length
>
0
&&
appVersion
.
length
>
0
)
{
if
(
typeof
appId
===
'
string
'
&&
typeof
appVersion
===
'
string
'
&&
appId
.
length
>
0
&&
appVersion
.
length
>
0
)
{
plus
.
runtime
.
getProperty
(
appId
,
function
(
widgetInfo
)
{
plus
.
runtime
.
getProperty
(
appId
,
function
(
widgetInfo
)
{
...
...
uni_modules/uni-upgrade-center-app/utils/check-update.ts
浏览文件 @
1c544af2
...
@@ -32,6 +32,24 @@ export default function () : Promise<UniUpgradeCenterResult> {
...
@@ -32,6 +32,24 @@ export default function () : Promise<UniUpgradeCenterResult> {
*/
*/
// return updateUseModal(uniUpgradeCenterResult)
// return updateUseModal(uniUpgradeCenterResult)
// #ifndef UNI-APP-X
// 静默更新,只有wgt有
if
(
uniUpgradeCenterResult
.
is_silently
)
{
uni
.
downloadFile
({
url
,
success
:
res
=>
{
if
(
res
.
statusCode
==
200
)
{
// 下载好直接安装,下次启动生效
plus
.
runtime
.
install
(
res
.
tempFilePath
,
{
force
:
false
});
}
}
});
return
;
}
// #endif
/**
/**
* 提示升级二
* 提示升级二
* 官方适配的升级弹窗,可自行替换资源适配UI风格
* 官方适配的升级弹窗,可自行替换资源适配UI风格
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录