Commit fc7652ad by liangjianmin

feat(app): 添加下拉刷新及应用版本更新功能

- 在首页开启下拉刷新功能 enablePullDownRefresh
- 新增 UpdateModal 组件用于版本更新提示弹窗
- 实现下拉刷新时自动检查最新应用版本并请求数据
- 通过 compareVersion 比较本地与线上版本号
- 弹窗提示新版本更新及下载链接
- 添加更新确认和取消的回调方法
- 更新失败时停止下拉刷新并打印错误日志
parent 01e9aab5
Showing with 69 additions and 2 deletions
......@@ -7,7 +7,8 @@
}, {
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "wms"
"navigationBarTitleText": "wms",
"enablePullDownRefresh": true
}
}, {
"path": "pages/arrivalRegister/index",
......
<template>
<view class="index">
<!-- 更新弹窗 -->
<UpdateModal ref="updateModal" @confirm="onUpdateConfirm" @cancel="onUpdateCancel" />
<view class="head row bothSide">
<view class="column">
<text class="t1">{{ org_name }}</text>
......@@ -116,7 +118,13 @@
<script>
import { API } from '@/util/api.js';
import { compareVersion } from '@/util/util.js';
import UpdateModal from '@/components/UpdateModal.vue';
export default {
components: {
UpdateModal
},
data() {
return {
org_name: '',
......@@ -129,6 +137,13 @@
onShow() {
this.org_name = uni.getStorageSync('org_name');
},
/**
* 下拉刷新
*/
onPullDownRefresh() {
this.checkAppUpdate();
this.getData();
},
methods: {
getData() {
this.request(API.getStatisticsInfo, 'POST', {}, false).then(res => {
......@@ -138,6 +153,58 @@
}
});
},
/**
* 检查应用更新
*/
checkAppUpdate() {
// #ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, (info) => {
var localVersion = info.version || '1.0.0';
this.doCheckUpdate(localVersion);
});
// #endif
// #ifndef APP-PLUS
this.doCheckUpdate('1.0.0');
// #endif
},
/**
* 执行版本检查
* @param {string} localVersion 本地版本号
*/
doCheckUpdate(localVersion) {
this.request(API.getLatestAppInfo, 'POST', {}, false).then(res => {
uni.stopPullDownRefresh();
if (res.code === 0) {
var onlineVersion = res.data.latest_app_info.wms_version || '0.0.0';
var downloadUrl = res.data.latest_app_info.download_url || '';
var remark = res.data.latest_app_info.remark || '发现新版本,是否更新?';
console.log(`[版本检查] 本地版本: ${localVersion}, 线上版本: ${onlineVersion}`);
if (!compareVersion(localVersion, onlineVersion)) {
this.$refs.updateModal.show(remark, downloadUrl, onlineVersion);
} else {
uni.showToast({
title: '已是最新版本',
icon: 'none'
});
}
}
}).catch(err => {
uni.stopPullDownRefresh();
console.log('检查更新失败:', err);
});
},
/**
* 更新确认回调
*/
onUpdateConfirm() {
console.log('用户确认更新');
},
/**
* 更新取消回调
*/
onUpdateCancel() {
console.log('用户取消更新');
},
exit() {
uni.showModal({
title: '提示',
......@@ -154,7 +221,6 @@
url: '/pages/mine/login'
});
} else if (res.cancel) {
// 用户点击取消操作
console.log('用户点击取消');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment