feat(): 自动更新功能

master
李神峰 2024-11-12 17:58:06 +08:00
parent b9e2563c8e
commit e6cafe2e6a
9 changed files with 539 additions and 325 deletions

View File

@ -3,7 +3,7 @@
"appid" : "__UNI__7573222",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"versionCode" : 1,
"transformPx" : false,
"app-plus" : {
/* 5+App */

View File

@ -2,20 +2,32 @@
"easycom": {
"^u-(.*)": "@/uni_modules/uview-ui/components/u-$1/u-$1.vue"
},
"pages": [
{
"pages": [{
"path": "pages/login/login",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/upgrade/index",
"style": {
"navigationBarTitleText": "",
"navigationStyle": "custom",
"app-plus": {
"bounce": "none",
"animationType": "none",
"background": "transparent"
}
}
},
{
"path": "pages/xcrw/index",
"style": {
"navigationBarTitleText": ""
}
},
{
{
"path": "pages/xcrw/detail/index",
"style": {
"navigationBarTitleText": ""
@ -27,7 +39,7 @@
"navigationBarTitleText": ""
}
},
{
{
"path": "pages/spjk/index",
"style": {
"navigationBarTitleText": ""
@ -45,14 +57,6 @@
"navigationBarTitleText": ""
}
},
{
"path": "pages/rain/rain",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/homeIndex/index",
"style": {
@ -67,102 +71,49 @@
}
}
},
{
"path": "pages/xxsb/index",
"style": {
"navigationBarTitleText": "信息上报"
}
},
{
"path": "pages/xxsb/from",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/xxsb/fromSeverity",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/xxsb/dsfrom",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/xxsb/map",
"style": {
"navigationBarTitleText": "地图示例"
}
},
{
"path": "pages/gqzq/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/gqxx",
"style": {
"navigationBarTitleText": "工情信息"
}
},
{
"path": "pages/gqzq/zqxx",
"style": {
"navigationBarTitleText": "灾情信息"
}
},
{
"path": "pages/gqzq/detail/index",
"style": {
"navigationBarTitleText": "查看"
}
},
{
"path": "pages/mypage/mypage",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/wtcl/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/wxyh/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/wxyh/formZdy/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/xcrw/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/wtcl/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/xcrw/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/wtcl/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/wxyh/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/wxyh/formZdy/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/xcrw/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/wtcl/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mypage/compents/xcrw/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/personInfo/personInfo",
"style": {
@ -175,204 +126,80 @@
"navigationBarTitleText": ""
}
},
{
"path": "pages/forewarning/forewarning",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/forewarning/sh",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/forewarning/shInformation/shInformation",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/addressBook/addressBook",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/water/water",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
},
"onMessage": "handleMessage"
},
{
"path": "pages/rainDetail/rainDetail",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/hdDetail/hdDetail",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/skDetail/skDetail",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/addressBook/follow",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/addressBook/myDept",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/orderFeedback/orderFeedback",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/orderFeedback/orderInformation",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/gqxx/gqxx",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/gqxx/qk",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/gqxx/xq",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/gqxx/qkForm",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/gqxx/xqForm",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/zqxx/zqxx",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/zqxx/table",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/gqzq/zqxx/form",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/wxyh/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/wtcl/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/wtcl/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/yj/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/yj/detail/qxyj",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/yj/detail/wyyj",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/yj/detail/aiyj",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/messageList/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/messageList/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/skInfo/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/skInfo/waterDatail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/ylzList/detail/index",
"style": {
"navigationBarTitleText": ""
}
}
{
"path": "pages/wtcl/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/wtcl/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/yj/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/yj/detail/qxyj",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/yj/detail/wyyj",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/yj/detail/aiyj",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/messageList/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/messageList/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/skInfo/detail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/skInfo/waterDatail/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/ylzList/detail/index",
"style": {
"navigationBarTitleText": ""
}
}
],
"usingComponents": {
"map": "/uni_modules/@dcloudio/uni-map/components/uni-map/uni-map"
@ -381,8 +208,7 @@
"tabBar": {
"color": "#333333",
"selectedColor": "#59A7FF",
"list": [
{
"list": [{
"pagePath": "pages/homeIndex/index",
"iconPath": "/static/tabs/home.png",
"selectedIconPath": "static/tabs/home2.png",
@ -407,16 +233,12 @@
"background": "#efeff4"
}
},
"subPackages": [
{
"root": "subpkg",
"pages": [
{
"path": "rainDetail/rainDetail"
}
]
}
],
"subPackages": [{
"root": "subpkg",
"pages": [{
"path": "rainDetail/rainDetail"
}]
}],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
@ -428,4 +250,4 @@
"background": "#efeff4"
}
}
}
}

View File

@ -46,6 +46,40 @@
}
},
methods: {
//
init(){
this.checkVersion();
},
//
async checkVersion(){
try {
const {data} = await uni.$http.get("/gunshiApp/xyt/appVersionRecord/latest");
if(data.code == 200){
const selfVersionCode = uni.getSystemInfoSync().appWgtVersion//App
const newVersionCode = data.data.version; //线
if (selfVersionCode != newVersionCode) {
let platform = uni.getSystemInfoSync().platform //
//
if (platform === 'android') {
uni.navigateTo({
url: `/pages/upgrade/index?info=${encodeURIComponent(JSON.stringify(data.data))}`
})
}
//IOS线
else {
uni.showModal({
title: '发现新版本 ' +'V' + newVersionCode,
content: '请到App store进行升级',
showCancel: false
})
}
}
}
} catch (error) {
uni.$showMsg()
}
},
handleChange(formData) {
formData.checked = !formData.checked
},
@ -136,6 +170,9 @@
}
},
},
onLoad(){
this.init();
}
}
</script>

View File

@ -80,7 +80,7 @@
userList: uni.getStorageSync('value'),
username: '',
userresponse: '防汛办',
version: '011.14.23',
version: uni.getSystemInfoSync().appWgtVersion,
func: func,
xjxList:xjxList,
default_src: uni.getStorageSync('avatar'),
@ -247,7 +247,7 @@
justify-content: center;
flex-direction: column-reverse;
width: 92%;
height: 6vh;
height: 8vh;
font-size: 20px;
color: white;
background-color: #007afd;

276
pages/upgrade/index.vue Normal file
View File

@ -0,0 +1,276 @@
<template>
<view class="upgrade-popup">
<image class="header-bg" src="../../static/images/upgrade.png" mode="widthFix"></image>
<view class="main">
<view class="version">发现新版本{{"v" + info.version}}</view>
<view class="content">
<text class="title">更新内容</text>
<view class="desc" v-html="info.versionDesc"></view>
</view>
<!--下载状态-进度条显示 -->
<view class="footer" v-if="isStartDownload">
<view class="progress-view" :class="{'active':!hasProgress}" @click="handleInstallApp">
<!-- 进度条 -->
<view v-if="hasProgress" style="height: 100%;">
<view class="txt">{{percentText}}</view>
<view class="progress" :style="setProStyle"></view>
</view>
<view v-else>
<view class="btn upgrade force">{{ isDownloadFinish ? '立即安装' :'下载中...'}}</view>
</view>
</view>
</view>
<!-- 强制更新 -->
<view class="footer" v-else-if="isForceUpdate">
<view class="btn upgrade force" @click="handleUpgrade"></view>
</view>
<!-- 可选择更新 -->
<view class="footer" v-else>
<view class="btn close" @click="handleClose"></view>
<view class="btn upgrade" @click="handleUpgrade"></view>
</view>
</view>
</view>
</template>
<script>
import {
downloadApp,
installApp
} from '../utils/upgrade.js'
import {
fileChange
} from '../utils/tool.js'
export default {
data() {
return {
isForceUpdate: false, //
isDownloadFinish: false, //
hasProgress: false, //
currentPercent: 0, //
isStartDownload: false, //
fileName: '', //app
info: {},
downloadUrl:''
}
},
computed: {
//
setProStyle() {
return {
width: (510 * this.currentPercent / 100) + 'rpx' //510
}
},
//
percentText() {
let percent = this.currentPercent;
if (typeof percent !== 'number' || isNaN(percent)) return '下载中...'
if (percent < 100) return `下载中${percent}%`
return '立即安装'
}
},
onLoad(options) {
this.info = JSON.parse(decodeURIComponent(options.info));
},
onBackPress(options) {
//
if (options.from == 'backbutton') {
return true;
}
},
methods: {
//
handleUpgrade() {
if (this.info.url) {
this.isStartDownload = true
//App
const baseUrl = `http://local.gunshiiot.com:18083/gunshiApp/xyt/common/download/resource?resource=${this.info.url}`
downloadApp(baseUrl, current => {
//
this.hasProgress = true
this.currentPercent = current
}).then(fileName => {
//
this.isDownloadFinish = true
this.fileName = fileName
if (fileName) {
//App
this.handleInstallApp()
}
}).catch(e => {
console.log(e, 'e')
})
} else {
uni.showToast({
title: '下载链接不存在',
icon: 'none'
})
}
},
//app
handleInstallApp() {
//
if (this.isDownloadFinish && this.fileName) {
installApp(this.fileName, () => {
//,
uni.navigateBack()
})
}
},
//
handleClose() {
uni.navigateBack()
},
}
}
</script>
<style>
page {
background: rgba(0, 0, 0, 0.5);
/**设置窗口背景半透明*/
}
</style>
<style lang="scss" scoped>
.upgrade-popup {
width: 580rpx;
height: auto;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #fff;
border-radius: 20rpx;
box-sizing: border-box;
border: 1px solid #eee;
}
.header-bg {
width: 70%;
margin-top: -112rpx;
margin-left: 10px;
}
.main {
padding: 10rpx 30rpx 30rpx;
box-sizing: border-box;
.version {
font-size: 36rpx;
color: #026DF7;
font-weight: 700;
width: 100%;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
letter-spacing: 1px;
}
.content {
margin-top: 60rpx;
.title {
font-size: 28rpx;
font-weight: 700;
color: #000000;
}
.desc {
box-sizing: border-box;
margin-top: 20rpx;
font-size: 28rpx;
color: #6A6A6A;
max-height: 80vh;
overflow-y: auto;
}
}
.footer {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
position: relative;
flex-shrink: 0;
margin-top: 100rpx;
.btn {
width: 246rpx;
display: flex;
justify-content: center;
align-items: center;
position: relative;
z-index: 999;
height: 96rpx;
box-sizing: border-box;
font-size: 32rpx;
border-radius: 10rpx;
letter-spacing: 2rpx;
&.force {
width: 500rpx;
}
&.close {
border: 1px solid #E0E0E0;
margin-right: 25rpx;
color: #000;
}
&.upgrade {
background-color: #026DF7;
color: white;
}
}
.progress-view {
width: 510rpx;
height: 90rpx;
display: flex;
position: relative;
align-items: center;
border-radius: 6rpx;
background-color: #dcdcdc;
display: flex;
justify-content: flex-start;
padding: 0px;
box-sizing: border-box;
border: none;
overflow: hidden;
&.active {
background-color: #026DF7;
}
.progress {
height: 100%;
background-color: #026DF7;
padding: 0px;
box-sizing: border-box;
border: none;
border-top-left-radius: 10rpx;
border-bottom-left-radius: 10rpx;
}
.txt {
font-size: 28rpx;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
}
}
}
}
</style>

View File

@ -64,20 +64,9 @@ export const adnmZhen = adcd => {
}
export const fileChange = (file) => {
let target= ''
let blob = new Blob([file]);
console.log("blobblob",blob);
let url = window.URL.createObjectURL(blob);
// let reader = new FileReader(blob);
// console.log("reader",reader);
// reader.readAsDataURL(url);
// reader.onload = function (e) {
// target=e.target.result
// }
console.log("target",url);
console.log("url",url);
return url
}

90
pages/utils/upgrade.js Normal file
View File

@ -0,0 +1,90 @@
/**
* @description H5+下载App
* @param downloadUrl:App下载链接
* @param progressCallBack:下载进度回调
*/
export const downloadApp = (downloadUrl, progressCallBack = () => { },) => {
return new Promise((resolve, reject) => {
//创建下载任务
const downloadTask = plus.downloader.createDownload(downloadUrl, {
method: "GET"
}, (task, status) => {
if (status == 200) { //下载成功
resolve(task.filename)
} else {
reject('fail')
uni.showToast({
title: '下载失败',
duration: 1500,
icon: "none"
});
}
})
//监听下载过程
downloadTask.addEventListener("statechanged", (task, status) => {
switch (task.state) {
case 1: // 开始
break;
case 2: //已连接到服务器
break;
case 3: // 已接收到数据
let hasProgress = task.totalSize && task.totalSize > 0 //是否能获取到App大小
if (hasProgress) {
let current = parseInt(100 * task.downloadedSize / task.totalSize); //获取下载进度百分比
progressCallBack(current)
}
break;
case 4: // 下载完成
break;
}
});
//开始执行下载
downloadTask.start();
})
}
/**
* @description H5+安装APP
* @param fileName:app文件名
* @param callBack:安装成功回调
*/
export const installApp = (fileName, callBack = () => {}) => {
//注册广播监听app安装情况
onInstallListening(callBack);
//开始安装
plus.runtime.install(plus.io.convertLocalFileSystemURL(fileName), {}, () => {
//成功跳转到安装界面
}, function(error) {
uni.showToast({
title: '安装失败',
duration: 1500,
icon: "none"
});
})
}
/**
* @description 注册广播监听APP是否安装成功
* @param callBack:安装成功回调函数
*/
const onInstallListening = (callBack = () => {}) => {
let mainActivity = plus.android.runtimeMainActivity(); //获取activity
//生成广播接收器
let receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
onReceive: (context, intent) => { //接收广播回调
plus.android.importClass(intent);
mainActivity.unregisterReceiver(receiver); //取消监听
callBack()
}
});
let IntentFilter = plus.android.importClass('android.content.IntentFilter');
let Intent = plus.android.importClass('android.content.Intent');
let filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED); //监听APP安装
filter.addDataScheme("package");
mainActivity.registerReceiver(receiver, filter); //注册广播
}

View File

@ -113,9 +113,9 @@
"handleUserId": uni.getStorageSync('value').userId
}
console.log(params,'dsd');
// uni.$http.post('/gunshiApp/xyt/inspect/detail/page', params).then(res => {
// this.list=res.data.data.records
// })
uni.$http.post('/gunshiApp/xyt/inspect/detail/page', params).then(res => {
this.list=res.data.data.records
})
},
confirm(e) {
console.log(e);

BIN
static/images/upgrade.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB