发现新版本
This commit is contained in:
parent
d3fe6f39d2
commit
84d4792aca
11
App.vue
11
App.vue
|
|
@ -2,9 +2,6 @@
|
||||||
// #ifdef VUE3
|
// #ifdef VUE3
|
||||||
import { initDictData } from '@/utils/dict'
|
import { initDictData } from '@/utils/dict'
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef APP-PLUS
|
|
||||||
import { initVersionCheck } from '@/utils/update'
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function() {
|
onLaunch: function() {
|
||||||
|
|
@ -35,14 +32,6 @@
|
||||||
uni.$uv.toast('网络连接不可用,请检查网络设置')
|
uni.$uv.toast('网络连接不可用,请检查网络设置')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
|
||||||
// 检查应用版本更新(延迟 2 秒,避免影响启动速度)
|
|
||||||
initVersionCheck({
|
|
||||||
silent: false, // 显示提示
|
|
||||||
delay: 2000 // 延迟 2 秒检查
|
|
||||||
})
|
|
||||||
// #endif
|
|
||||||
},
|
},
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
console.log('App Show')
|
console.log('App Show')
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
* @returns {Promise} 返回版本信息
|
* @returns {Promise} 返回版本信息
|
||||||
*/
|
*/
|
||||||
export const checkAppVersion = (params) => {
|
export const checkAppVersion = (params) => {
|
||||||
return uni.$uv.http.post('/app/version/check', params, {
|
return uni.$uv.http.post('/bst/app/getLatestVersion', params, {
|
||||||
custom: {
|
custom: {
|
||||||
auth: false, // 版本检查可能不需要登录
|
auth: false, // 版本检查可能不需要登录
|
||||||
toast: false // 不自动提示错误
|
toast: false // 不自动提示错误
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,54 @@
|
||||||
<text class="setting-desc">开启后仅展示分配给我的客户和任务数据</text>
|
<text class="setting-desc">开启后仅展示分配给我的客户和任务数据</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 版本管理 -->
|
||||||
|
<view class="card version-card">
|
||||||
|
<view class="version-header">
|
||||||
|
<text class="version-title">版本管理</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="version-info">
|
||||||
|
<view class="version-item">
|
||||||
|
<text class="version-label">当前版本</text>
|
||||||
|
<text class="version-value">{{ currentVersion }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="version-item" v-if="latestVersion">
|
||||||
|
<text class="version-label">最新版本</text>
|
||||||
|
<text class="version-value" :class="{ 'new-version': hasUpdate }">
|
||||||
|
{{ latestVersion }}
|
||||||
|
<text v-if="hasUpdate" class="update-badge">有新版本</text>
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
<view class="version-item" v-else>
|
||||||
|
<text class="version-label">最新版本</text>
|
||||||
|
<text class="version-value">未检查</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="version-actions">
|
||||||
|
<uv-button
|
||||||
|
type="primary"
|
||||||
|
:plain="true"
|
||||||
|
size="small"
|
||||||
|
@click="checkUpdate"
|
||||||
|
:loading="checking"
|
||||||
|
>
|
||||||
|
{{ checking ? '检查中...' : '检查更新' }}
|
||||||
|
</uv-button>
|
||||||
|
|
||||||
|
<uv-button
|
||||||
|
v-if="hasUpdate && updateInfo"
|
||||||
|
type="error"
|
||||||
|
size="small"
|
||||||
|
@click="handleUpdate"
|
||||||
|
style="margin-left: 20rpx;"
|
||||||
|
>
|
||||||
|
立即更新
|
||||||
|
</uv-button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
<view class="card">
|
<view class="card">
|
||||||
|
|
||||||
<uv-button type="error" :plain="true" @click="onLogout" :loading="loading">
|
<uv-button type="error" :plain="true" @click="onLogout" :loading="loading">
|
||||||
|
|
@ -21,12 +69,22 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useUserStore } from '@/store/user'
|
import { useUserStore } from '@/store/user'
|
||||||
import { logout } from '@/api/user'
|
import { logout } from '@/api/user'
|
||||||
|
import { getCurrentVersion, checkForUpdate, showUpdateDialog, compareVersion } from '@/utils/update'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const checking = ref(false)
|
||||||
|
const currentVersion = ref('')
|
||||||
|
const latestVersion = ref('')
|
||||||
|
const updateInfo = ref(null)
|
||||||
|
const hasUpdate = computed(() => {
|
||||||
|
if (!latestVersion.value || !currentVersion.value) return false
|
||||||
|
return compareVersion(currentVersion.value, latestVersion.value) < 0
|
||||||
|
})
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const { privateView, userInfo } = storeToRefs(userStore)
|
const { privateView, userInfo } = storeToRefs(userStore)
|
||||||
const filterSelf = computed({
|
const filterSelf = computed({
|
||||||
|
|
@ -37,6 +95,63 @@ const showPrivateSwitch = computed(() =>
|
||||||
userInfo.value?.roles?.some(r => ['admin', 'sys_admin'].includes(r))
|
userInfo.value?.roles?.some(r => ['admin', 'sys_admin'].includes(r))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 获取当前版本
|
||||||
|
onMounted(() => {
|
||||||
|
const version = getCurrentVersion()
|
||||||
|
currentVersion.value = version.versionName || '未知'
|
||||||
|
})
|
||||||
|
|
||||||
|
// 检查更新
|
||||||
|
const checkUpdate = async () => {
|
||||||
|
if (checking.value) return
|
||||||
|
checking.value = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await checkForUpdate(true) // 静默检查,不显示提示
|
||||||
|
|
||||||
|
if (result && result.hasUpdate) {
|
||||||
|
latestVersion.value = result.versionName || ''
|
||||||
|
updateInfo.value = result
|
||||||
|
uni.showToast({
|
||||||
|
title: '发现新版本',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 2000
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
latestVersion.value = currentVersion.value
|
||||||
|
updateInfo.value = null
|
||||||
|
uni.showToast({
|
||||||
|
title: '已是最新版本',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 2000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('检查更新失败:', error)
|
||||||
|
uni.showToast({
|
||||||
|
title: '检查更新失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
checking.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理更新
|
||||||
|
const handleUpdate = () => {
|
||||||
|
if (!updateInfo.value || !updateInfo.value.downloadUrl) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '更新信息无效',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示更新确认对话框,用户确认后会自动下载和安装
|
||||||
|
showUpdateDialog(updateInfo.value)
|
||||||
|
}
|
||||||
|
|
||||||
const onLogout = async () => {
|
const onLogout = async () => {
|
||||||
if (loading.value) return
|
if (loading.value) return
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
@ -92,6 +207,69 @@ const onLogout = async () => {
|
||||||
color: #6b7280;
|
color: #6b7280;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.version-card {
|
||||||
|
margin-bottom: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-header {
|
||||||
|
margin-bottom: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-title {
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #111827;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-info {
|
||||||
|
margin-bottom: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 16rpx 0;
|
||||||
|
border-bottom: 1rpx solid #f3f4f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-label {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #6b7280;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-value {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #111827;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-value.new-version {
|
||||||
|
color: #ef4444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-badge {
|
||||||
|
font-size: 20rpx;
|
||||||
|
background: #fee2e2;
|
||||||
|
color: #dc2626;
|
||||||
|
padding: 4rpx 12rpx;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 30rpx;
|
font-size: 30rpx;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user