提交 ca11f03a 编写于 作者: D DCloud_LXH

feat(upgrade-center): 商店跳转、版本号

上级 650952e3
...@@ -38,18 +38,17 @@ ...@@ -38,18 +38,17 @@
</view> </view>
</uni-collapse-item> </uni-collapse-item>
</template> </template>
</uni-collapse> </uni-collapse>
<!-- <upgradePopup ref="upgradePopup" @close="upgradePopupClose" /> --> <uni-upgrade-center-app ref="upgradePopup" @close="upgradePopupClose" />
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
</template> </template>
<script lang="uts"> <script lang="uts">
/* import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update' import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
import upgradePopup from '@/uni_modules/uni-upgrade-center-app/pages/upgrade-popup-uts.uvue' */
type Page = { type Page = {
name : string name : string
...@@ -92,9 +91,9 @@ export default { ...@@ -92,9 +91,9 @@ export default {
*/ */
{ {
name: 'list-view', name: 'list-view',
}, },
{ {
name: 'sticky-header', name: 'sticky-header',
} }
] as Page[], ] as Page[],
}, },
...@@ -224,17 +223,17 @@ export default { ...@@ -224,17 +223,17 @@ export default {
url: '/pages/component/web-view-local/web-view-local', url: '/pages/component/web-view-local/web-view-local',
}, },
] as Page[], ] as Page[],
}, },
{ {
id: 'unicloud-db', id: 'unicloud-db',
name: 'unicloud-db', name: 'unicloud-db',
pages: [ pages: [
{ {
name: '联系人', name: '联系人',
enable: true, enable: true,
url: '/pages/component/unicloud-db-contacts/list' url: '/pages/component/unicloud-db-contacts/list'
} }
] as Page[], ] as Page[],
}, },
/* /*
{ {
...@@ -270,10 +269,7 @@ export default { ...@@ -270,10 +269,7 @@ export default {
arrowDownIcon: '/static/icons/arrow-down.png', arrowDownIcon: '/static/icons/arrow-down.png',
arrowRightIcon: '/static/icons/arrow-right.png', arrowRightIcon: '/static/icons/arrow-right.png',
} }
}, },
/* components: {
upgradePopup: upgradePopup
}, */
methods: { methods: {
goDetailPage(e : Page) { goDetailPage(e : Page) {
if (e.enable == false) { if (e.enable == false) {
...@@ -288,18 +284,17 @@ export default { ...@@ -288,18 +284,17 @@ export default {
uni.navigateTo({ uni.navigateTo({
url, url,
}) })
}, },
upgradePopupClose() { upgradePopupClose() {
console.log('upgradePopup close'); console.log('upgradePopup close');
} }
}, },
/* , onReady() {
onReady() { checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
checkUpdate(this.$refs['upgradePopup'] as ComponentPublicInstance) },
}, beforeUnmount() {
beforeUnmount() { uni.showTabBar()?.catch(_ => {})
uni.showTabBar()?.catch(_ => {}) }
} */
} }
</script> </script>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<view class="content-body"> <view class="content-body">
<view class="content-body-title"> <view class="content-body-title">
<text class="text title">{{subTitle}}</text> <text class="text title">{{subTitle}}</text>
<!-- <text style="padding-left:20rpx;font-size: 0.5em;color: #666;">v.{{version}}</text> --> <text class="text version">v{{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">
...@@ -41,22 +41,16 @@ ...@@ -41,22 +41,16 @@
</view> </view>
</view> </view>
<button v-else class="content-button" <button v-else class="content-button" @click="updateApp">
style="border: none; color: #fff;width: 100%;height: 80rpx;line-height: 80rpx;font-size: 30rpx;font-weight: 400;border-radius: 40rpx;text-align: center;background: #1785ff"
:plain="true" @click="updateApp">
{{downLoadBtnText}} {{downLoadBtnText}}
</button> </button>
</template> </template>
<button v-else-if="downloadSuccess && !installed" class="content-button" <button v-else-if="downloadSuccess && !installed" class="content-button" :loading="installing" :disabled="installing" @click="installPackage">
style="border: none; color: #fff;width: 100%;height: 80rpx;line-height: 80rpx;font-size: 30rpx;font-weight: 400;border-radius: 40rpx;text-align: center;background: #1785ff"
:plain="true" :loading="installing" :disabled="installing" @click="installPackage">
{{installing ? '正在安装……' : '下载完成,立即安装'}} {{installing ? '正在安装……' : '下载完成,立即安装'}}
</button> </button>
<button v-else-if="installed" class="content-button" <button v-else-if="installed" class="content-button" :disabled="true">
style="border: none; color: #ccc;width: 100%;height: 80rpx;line-height: 80rpx;font-size: 30rpx;font-weight: 400;border-radius: 40rpx;text-align: center;background: #1785ff"
:plain="true" :disabled="true">
安装完成后,请重启应用 安装完成后,请重启应用
</button> </button>
</template> </template>
...@@ -64,8 +58,7 @@ ...@@ -64,8 +58,7 @@
</view> </view>
<view class="content-bottom"> <view class="content-bottom">
<image v-if="!is_mandatory" class="close-img" mode="widthFix" <image v-if="!is_mandatory" class="close-img" mode="widthFix" src="/uni_modules/uni-upgrade-center-app/static/app_update_close.png" @click="closeUpdate">
src="/uni_modules/uni-upgrade-center-app/static/app_update_close.png" @click="closeUpdate">
</image> </image>
</view> </view>
</view> </view>
...@@ -73,12 +66,14 @@ ...@@ -73,12 +66,14 @@
</template> </template>
<script> <script>
import { UniUpgradeCenterResult } from '../utils/call-check-version' import { UniUpgradeCenterResult, StoreListItem } from '../../utils/call-check-version'
import { openSchema } from '../../utils/utils.uts'
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 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;
/** /**
* 对比版本号,如需要,请自行修改判断规则 * 对比版本号,如需要,请自行修改判断规则
...@@ -148,6 +143,7 @@ ...@@ -148,6 +143,7 @@
// 默认安装包信息 // 默认安装包信息
title: '更新日志', title: '更新日志',
contents: '', contents: '',
version: '',
is_mandatory: false, is_mandatory: false,
// 可自定义属性 // 可自定义属性
...@@ -157,7 +153,8 @@ ...@@ -157,7 +153,8 @@
downLoadingText: '安装包下载中,请稍后', downLoadingText: '安装包下载中,请稍后',
url: "", url: "",
platform: [] as string[] platform: [] as string[],
store_list: null as StoreListItem[] | null
} }
}, },
computed: { computed: {
...@@ -184,6 +181,8 @@ ...@@ -184,6 +181,8 @@
this.contents = localPackageInfo.contents this.contents = localPackageInfo.contents
this.is_mandatory = localPackageInfo.is_mandatory this.is_mandatory = localPackageInfo.is_mandatory
this.platform = localPackageInfo.platform this.platform = localPackageInfo.platform
this.version = localPackageInfo.version
this.store_list = localPackageInfo.store_list
this.shown = shown this.shown = shown
}, },
closeUpdate() { closeUpdate() {
...@@ -230,14 +229,43 @@ ...@@ -230,14 +229,43 @@
this.$emit('close') this.$emit('close')
}, },
updateApp() { updateApp() {
this.downloadPackage() const checkStoreScheme = this.checkStoreScheme()
if (checkStoreScheme !== null) {
checkStoreScheme
.then(_ => { })
.catch(() => { this.downloadPackage() })
.finally(() => {
openSchemePromise = null
})
} else { this.downloadPackage() }
}, },
// 跳转应用商店
checkStoreScheme(): Promise<boolean> | null {
if (this.store_list !== null) {
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((): Promise<boolean> => openSchema(cur))
return openSchemePromise!
}, openSchemePromise!)
return openSchemePromise!
}
}
return null
},
downloadPackage() { downloadPackage() {
//下载包 //下载包
downloadTask = uni.downloadFile({ downloadTask = uni.downloadFile({
url: this.url, url: this.url,
success: res => { success: res => {
console.log('downloadFile res: ',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()
...@@ -367,6 +395,21 @@ ...@@ -367,6 +395,21 @@
border-bottom-right-radius: 30rpx; border-bottom-right-radius: 30rpx;
} }
.content-body-title {
flex-direction: row;
align-items: center;
}
.content-body-title .version {
padding-left: 20rpx;
color: #fff;
font-size: 20rpx;
margin-left: 10rpx;
padding: 4rpx 8rpx;
border-radius: 20rpx;
background: #50aefd;
}
.title { .title {
font-size: 32rpx; font-size: 32rpx;
font-weight: bold; font-weight: bold;
...@@ -416,6 +459,8 @@ ...@@ -416,6 +459,8 @@
} }
.content-button { .content-button {
border: none;
color: #fff;
width: 100%; width: 100%;
height: 80rpx; height: 80rpx;
line-height: 80rpx; line-height: 80rpx;
...@@ -427,6 +472,7 @@ ...@@ -427,6 +472,7 @@
text-align: center; text-align: center;
background-color: #1785ff; background-color: #1785ff;
} }
.flex-column { .flex-column {
...@@ -434,4 +480,4 @@ ...@@ -434,4 +480,4 @@
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
</style> </style>
\ No newline at end of file
...@@ -245,9 +245,13 @@ ...@@ -245,9 +245,13 @@
uni.navigateBack() uni.navigateBack()
}, },
updateApp() { updateApp() {
this.checkStoreScheme().catch(() => { this.checkStoreScheme()
this.downloadPackage() .catch(() => {
}) this.downloadPackage()
})
.finally(() => {
openSchemePromise = null
})
}, },
// 跳转应用商店 // 跳转应用商店
checkStoreScheme() { checkStoreScheme() {
......
...@@ -76,18 +76,20 @@ export default function (): Promise<UniUpgradeCenterResult> { ...@@ -76,18 +76,20 @@ export default function (): Promise<UniUpgradeCenterResult> {
name: 'uni-upgrade-center', name: 'uni-upgrade-center',
data: data data: data
}).then(res => { }).then(res => {
const result = JSON.parse<UniUpgradeCenterResult>(JSON.stringify(res.result)) const code = res.result['code']
if (result === null ){ if (['Int', 'Long', 'number'].includes(typeof code) && (code as number) < 0) {
reject({ reject({
code: res.result['code'], code: res.result['code'],
message: res.result['message'] message: res.result['message']
}) })
} else { } else {
const result = JSON.parse<UniUpgradeCenterResult>(JSON.stringify(res.result)) as UniUpgradeCenterResult
resolve(result) resolve(result)
} }
}).catch<void>((err : any | null) => { }).catch<void>((err : any | null) => {
console.log('err: ', err);
const error = err as UniCloudError const error = err as UniCloudError
if (error.errMsg == '未匹配到云函数[uni-upgrade-center]')
error.errMsg = '【uni-upgrade-center-app】未配置uni-upgrade-center,无法升级。参考: https://uniapp.dcloud.net.cn/uniCloud/upgrade-center.html'
reject(error.errMsg) reject(error.errMsg)
}) })
} catch (e) { } catch (e) {
......
...@@ -22,11 +22,11 @@ export default function () : Promise<UniUpgradeCenterResult> { ...@@ -22,11 +22,11 @@ export default function () : Promise<UniUpgradeCenterResult> {
// const platform = uniUpgradeCenterResult.platform // 安装包平台 // const platform = uniUpgradeCenterResult.platform // 安装包平台
// const type = uniUpgradeCenterResult.type // 安装包类型 // const type = uniUpgradeCenterResult.type // 安装包类型
// 此处逻辑仅为实例,可自行编写 // 此处逻辑仅为示例,可自行编写
if (code > 0) { if (code > 0) {
// 腾讯云和阿里云下载链接不同,需要处理一下,阿里云会原样返回 // 腾讯云和阿里云下载链接不同,需要处理一下,阿里云会原样返回
const tcbRes = await uniCloud.getTempFileURL({ fileList: [url] }); const tcbRes = await uniCloud.getTempFileURL({ fileList: [url] });
if (typeof tcbRes.fileList[0].tempFileURL !== 'undefined') uniUpgradeCenterResult.url = tcbRes.fileList[0].tempFileURL; if (typeof tcbRes.fileList[0].tempFileURL !== 'undefined') uniUpgradeCenterResult.url = tcbRes.fileList[0].tempFileURL;
/** /**
* 提示升级一 * 提示升级一
...@@ -52,21 +52,20 @@ export default function () : Promise<UniUpgradeCenterResult> { ...@@ -52,21 +52,20 @@ export default function () : Promise<UniUpgradeCenterResult> {
component?.$callMethod('show', true, uniUpgradeCenterResult) component?.$callMethod('show', true, uniUpgradeCenterResult)
// #endif // #endif
return resolve(uniUpgradeCenterResult) return resolve(uniUpgradeCenterResult)
} else if (code < 0) { } else if (code < 0) {
// TODO 云函数报错处理 // TODO 云函数报错处理
console.error(message) console.error(message)
return reject(uniUpgradeCenterResult) return reject(uniUpgradeCenterResult)
} }
return resolve(uniUpgradeCenterResult) return resolve(uniUpgradeCenterResult)
}).catch((err) => { }).catch((err) => {
// TODO 云函数报错处理 // TODO 云函数报错处理
console.error(err) reject(err)
reject(err) })
}) });
}); // #endif
// #endif }
}
// #ifdef UNI-APP-X // #ifdef UNI-APP-X
/** /**
...@@ -203,4 +202,4 @@ function updateUseModal(packageInfo : UniUpgradeCenterResult) : void { ...@@ -203,4 +202,4 @@ function updateUseModal(packageInfo : UniUpgradeCenterResult) : void {
} }
}); });
} }
// #endif // #endif
\ No newline at end of file
import Intent from 'android.content.Intent';
import Uri from 'android.net.Uri';
export function openSchema(url : string) : Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
try {
const context = UTSAndroid.getUniActivity()!;
const uri = Uri.parse(url)
const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.setData(uri);
context.startActivity(intent);
resolve(true)
} catch (e) {
reject(e)
}
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册