Swanky 2 years ago
parent cb409b86f8
commit 944ddf8d66
  1. 93
      common/upgrade.js
  2. 4
      manifest.json
  3. 93
      pages/index/index.vue
  4. 98
      pages/mine/mine.vue
  5. BIN
      static/jwd.png

@ -0,0 +1,93 @@
/**
* @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) => {
console.log(status, '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) {
console.log(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); //注册广播
}

@ -2,8 +2,8 @@
"name" : "草原管理",
"appid" : "__UNI__BBBC950",
"description" : "",
"versionName" : "1.0.1",
"versionCode" : 101,
"versionName" : "1.0.2",
"versionCode" : 102,
"transformPx" : false,
"app-plus" : {
/* 5+App */

@ -10,18 +10,27 @@
<view class="right-actions">
<view class="btn-tcdj right-btn" @click="showLayerModal">
<image src="/static/tcdj.png" class="btn-img"></image>
<view>图层</view>
</view>
<view class="btn-mjcl right-btn" @click="toggleMeasure">
<image :src="measureStatus==='mjcl'?'/static/mjcl-sel.png':'/static/mjcl.png'" class="btn-img"></image>
<view>测量</view>
</view>
<view class="btn-xzgj right-btn" @click="toggleXzgj">
<image :src="measureStatus==='xzgj'?'/static/xzgj-sel.png':'/static/xzgj.png'" class="btn-img"></image>
<view>绕地</view>
</view>
<view class="btn-location right-btn" @click="location">
<image src="/static/dw.png" class="img-location" />
<view>定位</view>
</view>
<view class="btn-mjcl right-btn" @click="showJwdPopup">
<image src="/static/jwd.png" class="img-jwd" />
<view>经纬度</view>
</view>
<view class="btn-clear right-btn" @click="mapModule.clear">
<image src="/static/clear.png" class="img-clear" />
<view>清除</view>
</view>
<!-- <view class="btn-logout right-btn" @click="logout">
<image src="/static/logout.png" class="img-logout" />
@ -32,7 +41,24 @@
<div>工作台</div>
</button>
<view>
<!-- 普通弹窗 -->
<!-- 经纬度输入弹窗 -->
<uni-popup ref="jwdPopup" background-color="#fff">
<view class="popup-detail-title">
<text style="flex:1;font-size: 18px; font-weight: bold;">经纬度定位</text>
<button type="primary" size="mini" @click="navWithJwd">确定</button>
</view>
<view class="popup-content uni-flex uni-row" style="align-items: center;justify-content: center;">
<uni-forms ref="jwdForm" :modelValue="jwdData">
<uni-forms-item label="经度" name="longitude" required>
<uni-easyinput type="number" v-model="jwdData.longitude" placeholder="请输入经度" />
</uni-forms-item>
<uni-forms-item label="纬度" name="latitude" required>
<uni-easyinput type="number" v-model="jwdData.latitude" placeholder="请输入纬度" />
</uni-forms-item>
</uni-forms>
</view>
</uni-popup>
<!-- 图层叠加弹窗 -->
<uni-popup ref="popup" background-color="#fff" @change="popupChange">
<view class="popup-title">图层叠加</view>
<view class="popup-content uni-flex uni-row" style="align-items: center;justify-content: center;">
@ -43,7 +69,7 @@
</view>
</view>
</uni-popup>
<!-- 普通弹窗 -->
<!-- 图层详情弹窗 -->
<uni-popup ref="popupDetail" background-color="#fff">
<view class="popup-detail-title">
<text
@ -124,7 +150,38 @@
measureStatus: '',
currentClickLayerItem: null,
xzgjPoints: [],
compassNum: 0
compassNum: 0,
jwdData: {},
rules: {
longitude: {
rules: [{
required: true,
errorMessage: '经度不能为空',
}, {
format: "number",
validateFunction: function(rule, value, data, callback) {
if (value < 0 || value > 180) {
callback('经度范围应在 0 到 180 之间')
}
return true
}
}]
},
latitude: {
rules: [{
required: true,
errorMessage: '纬度不能为空',
}, {
format: "number",
validateFunction: function(rule, value, data, callback) {
if (value < -90 || value > 90) {
callback('纬度范围应在 -90 到 90 之间')
}
return true
}
}]
}
}
}
},
watch: {
@ -186,6 +243,28 @@
uni.stopCompass();
},
methods: {
navWithJwd() {
this.$refs.jwdForm.validate((err, formData) => {
// err null
if (!err) {
console.log('success', formData)
this.mapData = {
center: [formData.longitude, formData.latitude, Math.random()]
}
this.$refs.jwdPopup.close();
return
}
console.log('error', err, formData)
}).then(res => {
// res null
})
},
showJwdPopup() {
this.$refs.jwdPopup.open('bottom');
setTimeout(() => {
this.$refs.jwdForm.setRules(this.rules)
}, 500)
},
loadLayerItems() {
uni.request({
url: `${helper.mgServerUrl}/app/config/layer`,
@ -735,6 +814,11 @@
}
.img-clear,
.img-jwd {
width: 26px;
height: 26px;
}
.img-logout,
.img-message,
.img-search,
@ -789,10 +873,13 @@
width: 48px;
height: 48px;
background-color: #fff;
flex-direction: column;
display: flex;
align-items: center;
padding: 0;
justify-content: center;
font-size: 12px;
padding: 2px 0;
}
.btn-location {

@ -9,23 +9,68 @@
<uni-list-item title="手机号" :rightText="userInfo.phonenumber"></uni-list-item>
</uni-list>
</uni-card>
<view style="padding-left: 16px;color: rgba(0,0,0,0.5);font-size: 12px;margin-bottom: -10px;margin-top: 16px;">
版本信息</view>
<uni-card padding="0">
<uni-list :border="false">
<uni-list-item title="版本号" :rightText="version">
</uni-list-item>
<uni-list-item clickable title="检查更新" :showBadge="!!versionName" :badgeText="versionName"
badgeType="error" showArrow @click="checkUpdate">
</uni-list-item>
</uni-list>
</uni-card>
<button class="submit" type="warn" @click="logout" :loading="submiting">退出登录</button>
</view>
</template>
<script>
import helper from '../../common/helper'
import {
downloadApp, installApp
} from '../../common/upgrade'
export default {
data() {
return {
userInfo: {},
submiting: false,
version: null,
versionCode: null,
versionName: null,
downloadUrl: '',
hasNewVersion: false,
isDownloadFinish: false, //
hasProgress: false, //
currentPercent: 0, //
isStartDownload: false, //
fileName: '', //app
}
},
onShow() {
const systemImfo = uni.getSystemInfoSync()
this.versionCode = systemImfo.appVersionCode
console.log(systemImfo)
this.version = systemImfo.appVersion;
uni.request({
url: `${helper.mgServerUrl}/app/config/version`,
header: {
Authorization: `Bearer ${helper.tempToken}`
},
success: (resp) => {
const data = resp.data.data;
console.log(data.versionCode, this.versionCode)
if (data.versionCode > this.versionCode) {
this.versionName = data.versionName;
this.downloadUrl = data.downloadUrl;
}
},
fail() {
}
})
},
onLoad() {
console.log(1)
uni.getStorage({
key: 'tempUserInfo',
success: (resp) => {
@ -35,11 +80,56 @@
fail: (err) => {
console.log(err)
}
})
});
},
onShow() {},
methods: {
checkUpdate() {
if (this.versionName) {
uni.showModal({
title: '提示',
content: `是否更新到 ${this.versionName} 版本`,
success: (e) => {
if (e.confirm) {
plus.runtime.openURL(this.downloadUrl);
// downloadApp(this.downloadUrl, current => {
// //
// this.hasProgress = true
// this.currentPercent = current
// uni.showToast({
// duration: 0,
// title: '' + current
// })
// }).then(fileName => {
// //
// uni.hideToast()
// this.isDownloadFinish = true
// this.fileName = fileName
// if (fileName) {
// //App
// this.handleInstallApp()
// }
// }).catch(e => {
// console.log(e, 'e')
// })
}
}
})
} else {
uni.showToast({
icon:'none',
title: '当前已是最新版本'
})
}
},
handleInstallApp() {
//
if (this.isDownloadFinish && this.fileName) {
installApp(this.fileName, () => {
})
}
},
logout() {
const toLogin = (token) => {
uni.request({

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Loading…
Cancel
Save