190 lines
5.0 KiB
Vue
190 lines
5.0 KiB
Vue
<script>
|
|
import {
|
|
compareVersions,
|
|
getCurrentAppVersion,
|
|
getLatestRelease,
|
|
getReleaseUpdateInfo,
|
|
markAutoUpdateChecked,
|
|
shouldAutoCheckForUpdate
|
|
} from '@/api/app-update.js'
|
|
|
|
export default {
|
|
onLaunch: function() {
|
|
// #ifdef APP-PLUS
|
|
this.checkUpdateOnFirstLaunchToday()
|
|
// #endif
|
|
},
|
|
onShow: function() {
|
|
console.log('App Show')
|
|
},
|
|
onHide: function() {
|
|
console.log('App Hide')
|
|
},
|
|
methods: {
|
|
checkUpdateOnFirstLaunchToday() {
|
|
if (!shouldAutoCheckForUpdate()) return
|
|
// 当日第一次启动即记录,网络失败时不在同一天内反复弹出失败提示。
|
|
markAutoUpdateChecked()
|
|
getLatestRelease()
|
|
.then((release) => {
|
|
const updateInfo = getReleaseUpdateInfo(release)
|
|
if (compareVersions(updateInfo.latestVersion, getCurrentAppVersion()) <= 0) return
|
|
const content = `发现新版本 v${updateInfo.latestVersion}\n\n${updateInfo.updateNote}${updateInfo.apkUrl ? '\n\n是否立即下载并安装?' : '\n\n更新包暂未发布,请稍后再试。'}`
|
|
uni.showModal({
|
|
title: '发现新版本',
|
|
content,
|
|
confirmText: updateInfo.apkUrl ? '立即更新' : '知道了',
|
|
showCancel: Boolean(updateInfo.apkUrl),
|
|
cancelText: '暂不更新',
|
|
success: (result) => {
|
|
if (result.confirm && updateInfo.apkUrl) {
|
|
this.downloadAndInstallApk(updateInfo.apkUrl)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
.catch(() => {
|
|
// 自动检查失败静默处理,不打扰用户;手动检查仍会显示具体失败原因。
|
|
})
|
|
},
|
|
downloadAndInstallApk(downloadUrl) {
|
|
if (!downloadUrl) return
|
|
uni.showLoading({ title: '正在下载更新包', mask: true })
|
|
uni.downloadFile({
|
|
url: downloadUrl,
|
|
success: (result) => {
|
|
if (result.statusCode !== 200) {
|
|
uni.showToast({ title: '更新包下载失败', icon: 'none' })
|
|
return
|
|
}
|
|
plus.runtime.install(result.tempFilePath, {}, () => {}, (error) => {
|
|
uni.showModal({
|
|
title: '安装失败',
|
|
content: error.message || '请允许安装未知来源应用后重试',
|
|
showCancel: false
|
|
})
|
|
})
|
|
},
|
|
fail: () => uni.showToast({ title: '更新包下载失败,请检查网络', icon: 'none' }),
|
|
complete: () => uni.hideLoading()
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import "@/uni_modules/uview-pro/index.scss";
|
|
|
|
/* 全局深色主题:页面根节点由 themeMode 自动添加 theme-dark。 */
|
|
.theme-dark {
|
|
background: #151923 !important;
|
|
color: #f2f5fa;
|
|
}
|
|
|
|
.theme-dark .home-hero,
|
|
.theme-dark .user-card,
|
|
.theme-dark .menu-panel,
|
|
.theme-dark .chart-panel,
|
|
.theme-dark .settings-card,
|
|
.theme-dark .auth-panel,
|
|
.theme-dark .profile-header,
|
|
.theme-dark .profile-card,
|
|
.theme-dark .form-card,
|
|
.theme-dark .config-card,
|
|
.theme-dark .query-header,
|
|
.theme-dark .query-tabs,
|
|
.theme-dark .query-panel,
|
|
.theme-dark .result-card,
|
|
.theme-dark .repair-hero,
|
|
.theme-dark .repair-card,
|
|
.theme-dark .task-card,
|
|
.theme-dark .statistics-card,
|
|
.theme-dark .summary-card,
|
|
.theme-dark .trend-card,
|
|
.theme-dark .progress-card,
|
|
.theme-dark .loading-card,
|
|
.theme-dark .empty-card,
|
|
.theme-dark .field-card {
|
|
background: #222936 !important;
|
|
border-color: #364152 !important;
|
|
box-shadow: none !important;
|
|
}
|
|
|
|
.theme-dark .menu-group-0,
|
|
.theme-dark .menu-group-1,
|
|
.theme-dark .menu-item--active {
|
|
background: #1c2431 !important;
|
|
}
|
|
|
|
.theme-dark .setting-row,
|
|
.theme-dark .menu-item,
|
|
.theme-dark .info-row,
|
|
.theme-dark .action-item,
|
|
.theme-dark .list-item,
|
|
.theme-dark .record-item,
|
|
.theme-dark .task-item {
|
|
border-color: #364152 !important;
|
|
}
|
|
|
|
.theme-dark .summary-card,
|
|
.theme-dark .trend-card,
|
|
.theme-dark .progress-card,
|
|
.theme-dark .stat-item,
|
|
.theme-dark .bar-track,
|
|
.theme-dark .progress-track {
|
|
background: #1c2431 !important;
|
|
}
|
|
|
|
.theme-dark .hero-title,
|
|
.theme-dark .brand-title,
|
|
.theme-dark .panel-title,
|
|
.theme-dark .page-title,
|
|
.theme-dark .form-title,
|
|
.theme-dark .query-title,
|
|
.theme-dark .card-title,
|
|
.theme-dark .workspace-title,
|
|
.theme-dark .chart-title,
|
|
.theme-dark .chart-section-title,
|
|
.theme-dark .setting-label,
|
|
.theme-dark .menu-title,
|
|
.theme-dark .user-account,
|
|
.theme-dark .summary-value,
|
|
.theme-dark .progress-value,
|
|
.theme-dark .field-text,
|
|
.theme-dark .profile-name,
|
|
.theme-dark .info-value,
|
|
.theme-dark .action-left,
|
|
.theme-dark .list-title,
|
|
.theme-dark .record-title,
|
|
.theme-dark .task-title {
|
|
color: #f2f5fa !important;
|
|
}
|
|
|
|
.theme-dark .hero-subtitle,
|
|
.theme-dark .brand-subtitle,
|
|
.theme-dark .panel-desc,
|
|
.theme-dark .footer-link,
|
|
.theme-dark .page-subtitle,
|
|
.theme-dark .form-desc,
|
|
.theme-dark .query-subtitle,
|
|
.theme-dark .card-subtitle,
|
|
.theme-dark .setting-value,
|
|
.theme-dark .setting-desc,
|
|
.theme-dark .menu-desc,
|
|
.theme-dark .user-name,
|
|
.theme-dark .profile-account,
|
|
.theme-dark .info-label,
|
|
.theme-dark .stat-label,
|
|
.theme-dark .chart-subtitle,
|
|
.theme-dark .summary-label,
|
|
.theme-dark .bar-label,
|
|
.theme-dark .progress-label,
|
|
.theme-dark .footer-tip,
|
|
.theme-dark .list-desc,
|
|
.theme-dark .record-desc,
|
|
.theme-dark .task-desc {
|
|
color: #aeb9ca !important;
|
|
}
|
|
</style>
|