176 lines
4.6 KiB
Vue
176 lines
4.6 KiB
Vue
<template>
|
|
<s-pages title="版本号">
|
|
<view class="pages relative h100 p-t-50">
|
|
<view class="w_150 h_150 m-b-50" style="margin: 0 auto">
|
|
<image class="w100 h100" src="/static/logo.png" mode="scaleToFill" />
|
|
</view>
|
|
<view class="center"> 最新版本号: {{ newversion }} </view>
|
|
<view class="center m-t-50"> 当前版本号: {{ version }} </view>
|
|
<!-- #ifdef APP-PLUS -->
|
|
<view class="flex-center m-t-100 absolute b50 w100 p-x-32">
|
|
<view class="ai-button2 m-r-20" @click="onClickUpdate()">更新最新版本</view>
|
|
<view class="ai-button2" @click="copy()">复制APP下载链接</view>
|
|
</view>
|
|
<!-- #endif -->
|
|
</view>
|
|
|
|
<view v-if="showUpdateProgress" class="update-progress-mask">
|
|
<view class="update-progress-card">
|
|
<view class="update-progress-title">{{ updateProgressText }}</view>
|
|
<view class="update-progress-bar">
|
|
<view class="update-progress-bar__fill" :style="{ width: updateProgress + '%' }"></view>
|
|
</view>
|
|
<view class="update-progress-percent">{{ updateProgress }}%</view>
|
|
</view>
|
|
</view>
|
|
</s-pages>
|
|
</template>
|
|
<script setup>
|
|
import { ref, onMounted } from 'vue'
|
|
import { createHotUpdate, downloadAndOpenApk } from '@/utils/hotUpdate'
|
|
import { getAndroidAppUrl, gethotupdatelist } from '@/sheep/api/index/index'
|
|
|
|
const newversion = ref('')
|
|
const version = ref('')
|
|
const appVersion = ref('')
|
|
const wgtVersion = ref('')
|
|
const updateInfoRef = ref({})
|
|
const apkPath = ref('')
|
|
|
|
const showUpdateProgress = ref(false)
|
|
const updateProgress = ref(0)
|
|
const updateProgressText = ref('下载中...')
|
|
|
|
const progress = {
|
|
show: (text) => {
|
|
showUpdateProgress.value = true
|
|
updateProgress.value = 0
|
|
updateProgressText.value = String(text || '下载中...')
|
|
},
|
|
set: (p, text) => {
|
|
updateProgress.value = Math.max(0, Math.min(100, Number(p) || 0))
|
|
if (text) updateProgressText.value = String(text)
|
|
},
|
|
hide: () => {
|
|
showUpdateProgress.value = false
|
|
},
|
|
}
|
|
|
|
const hotUpdate = createHotUpdate({
|
|
progress,
|
|
apkMode: 'download',
|
|
getLatest: gethotupdatelist,
|
|
})
|
|
|
|
const wgtUp = async () => {
|
|
const payload = await hotUpdate.fetchLatest()
|
|
if (!payload) return
|
|
const { updateInfo, localWgtVersion, localAppVersion, localCompareVersion, latestVersion } = payload
|
|
updateInfoRef.value = updateInfo || {}
|
|
wgtVersion.value = String(localWgtVersion || '')
|
|
appVersion.value = String(localAppVersion || '')
|
|
version.value = String(localCompareVersion || localAppVersion || localWgtVersion || '')
|
|
newversion.value = String(latestVersion || '')
|
|
apkPath.value = String(updateInfo?.apkPath || '')
|
|
}
|
|
|
|
const onClickUpdate = async () => {
|
|
await wgtUp()
|
|
await hotUpdate.promptAndUpdate(updateInfoRef.value, { source: 'manual' })
|
|
}
|
|
|
|
const copy = async () => {
|
|
if (!apkPath.value) {
|
|
try {
|
|
const res = await getAndroidAppUrl({})
|
|
apkPath.value = String(res?.data || '')
|
|
} catch (e) {}
|
|
}
|
|
if (!apkPath.value) {
|
|
uni.showToast({ title: '暂无下载链接', icon: 'none' })
|
|
return
|
|
}
|
|
const url = apkPath.value
|
|
uni.setClipboardData({
|
|
data: url,
|
|
success: () => {
|
|
uni.showToast({ title: '链接已复制', icon: 'none' })
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '是否立即下载更新?',
|
|
confirmText: '立即下载',
|
|
cancelText: '暂不下载',
|
|
confirmColor: 'var(--color2)',
|
|
success: (res) => {
|
|
if (!res?.confirm) return
|
|
downloadAndOpenApk(apkPath.value, { progress })
|
|
},
|
|
})
|
|
},
|
|
})
|
|
}
|
|
|
|
onMounted(() => {
|
|
// #ifdef APP-PLUS
|
|
wgtUp()
|
|
// #endif
|
|
})
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
.pages {
|
|
}
|
|
|
|
.update-progress-mask {
|
|
position: fixed;
|
|
left: 0;
|
|
top: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background: rgba(0, 0, 0, 0.45);
|
|
z-index: 9999;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 40rpx;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.update-progress-card {
|
|
width: 100%;
|
|
max-width: 560rpx;
|
|
background: #fff;
|
|
border-radius: 16rpx;
|
|
padding: 32rpx;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.update-progress-title {
|
|
font-size: 28rpx;
|
|
color: #333;
|
|
text-align: center;
|
|
margin-bottom: 20rpx;
|
|
}
|
|
|
|
.update-progress-bar {
|
|
height: 18rpx;
|
|
background: rgba(0, 0, 0, 0.08);
|
|
border-radius: 999rpx;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.update-progress-bar__fill {
|
|
height: 100%;
|
|
background: var(--color2);
|
|
border-radius: 999rpx;
|
|
width: 0%;
|
|
transition: width 0.2s linear;
|
|
}
|
|
|
|
.update-progress-percent {
|
|
font-size: 28rpx;
|
|
color: #333;
|
|
text-align: center;
|
|
margin-top: 16rpx;
|
|
}
|
|
</style>
|