Просмотр исходного кода

我的轨迹功能以及任务相关问题

yf_zhb 2 лет назад
Родитель
Сommit
7653a63ff0

+ 1 - 1
MingGaoApp/.hbuilderx/launch.json

@@ -16,7 +16,7 @@
             "type" : "uniCloud"
         },
         {
-            "playground" : "standard",
+            "playground" : "custom",
             "type" : "uni-app:app-android"
         }
     ]

+ 23 - 15
MingGaoApp/App.vue

@@ -1,6 +1,7 @@
 <script>
 	import config from '@/util/url.js';
-	
+	import HeartBeat from '@/util/HeartBeat.js'
+
 	export default {
 		globalData: {
 			token: "",
@@ -29,13 +30,13 @@
 			msgSetTime: null,
 			g_wakelock: null
 		},
-		onLoad() {
-
-		},
+		onLoad() {},
 		onLaunch: function() {
 			console.log('启动了')
+			HeartBeat.getInstance().destory();
 			// App启动
 
+
 			var that = this
 
 			// #ifdef APP-PLUS
@@ -59,6 +60,7 @@
 			this.$store.dispatch('updateTaskRecordRatio')
 			// App展示在前台
 			console.log('+++++++++++++++++++App Show-------------------------------------')
+
 			// this.msgInit(); // 再进行请求
 			uni.getStorage({
 				key: 'session_key',
@@ -66,7 +68,7 @@
 					that.globalData.token = res.data
 					// console.log('登录成功了')
 					console.log(res)
-					// that.msgInit(); // 文本初始化
+					that.msgInit(); // 文本初始化
 				},
 				fail: function(err) {
 					console.log(err)
@@ -78,6 +80,7 @@
 			// App不再再展示在前台
 			this.close(); // 关闭
 		},
+
 		methods: {
 			// 实时通信 - 初始化
 			msgInit() {
@@ -120,6 +123,7 @@
 					// console.log("收到服务器内容:");
 					var val = JSON.parse(res.data)
 					console.warn('这是返回的内容---------', val)
+
 					if (val.action == 'list') {
 						clearTimeout(that.globalData.msgSetTime); // 消息发送成功,清除发送失败定时器
 						console.log('这是发送人的ID', that.globalData.userId)
@@ -225,14 +229,18 @@
 						this.start(); // 心跳机制
 					} else if (val.action == 'error') {
 						if (val.data.errorCode == 403) {
-							uni.setStorageSync('session_key', '')
-							uni.$u.totast('用户在其他地方登陆,请重新登陆')
+
 							this.close();
-							setTimeout(() => {
-								uni.navigateTo({
-									url: "/pages/login/login"
-								})
-							}, 2000)
+							uni.setStorageSync('session_key', '')
+							if (!this.$store.state.isInLoginPage) {
+
+								uni.$u.totast('用户在其他地方登陆,请重新登陆')
+								setTimeout(() => {
+									uni.navigateTo({
+										url: "/pages/login/login"
+									})
+								}, 2000)
+							}
 						}
 					}
 
@@ -253,9 +261,9 @@
 				// 连接失败
 				that.globalData.socketTask.onError((res) => {
 					console.log(res, '连接错误');
-					uni.showLoading({
-						title: "通信异常,连接中..."
-					})
+					// uni.showLoading({
+					// 	title: "通信异常,连接中..."
+					// })
 					clearTimeout(this.globalData.timeoutObj);
 					setTimeout(() => {
 						that.reconnect();

+ 0 - 1
MingGaoApp/components/task-card/task-card.vue

@@ -132,7 +132,6 @@
 			}
 		},
 		mounted() {
-			console.warn(this.dataSource, 'mounted 1121331331ddd')
 		},
 		methods: {
 			handleClick() {

+ 8 - 0
MingGaoApp/pages.json

@@ -305,6 +305,14 @@
 				"navigationBarBackgroundColor": "#ffffff"
 			}
 
+		},
+		{
+			"path": "pages/my/map",
+			"style": {
+				"navigationBarTitleText": "我的轨迹",
+				"navigationBarBackgroundColor": "#ffffff"
+			}
+		
 		}
 	],
 	"globalStyle": {

+ 3 - 1
MingGaoApp/pages/index/index.vue

@@ -243,6 +243,7 @@
 				})
 			},
 			updateRecordLocation(type, taskID) {
+				console.warn('updateRecordLocation', type, taskID)
 				switch (type) {
 					case TASK_ACTION_TYPE.START:
 					case TASK_ACTION_TYPE.RESTART:
@@ -323,7 +324,8 @@
 					this.total = res.total_item;
 
 					res.page_list.forEach(item => {
-						if (item.walk_status === TASK_WALK_TYPE.IS_RECORDING) {
+						if (item.walk_status === TASK_WALK_TYPE.IS_RECORDING && task_status ===
+							'处理中') {
 							this.isUpdateLocation = true;
 							if (!this._heartBeat.hasType('record_' + item.task_id)) {
 								this._heartBeat.handle({

+ 5 - 0
MingGaoApp/pages/index/taskEdit.vue

@@ -278,6 +278,11 @@
 				console.log(res)
 				uni.$u.toast('提交成功')
 				HeartBeat.getInstance().clearByType('record_' + this.task_id);
+				taskService.updateTaskWalkStatus({
+					task_id: this.task_id,
+					action: 'stop'
+				})
+				
 				setTimeout(() => {
 					this.loading = false;
 					uni.switchTab({

+ 9 - 0
MingGaoApp/pages/login/login.vue

@@ -22,6 +22,7 @@
 </template>
 
 <script>
+	import {mapMutations} from 'vuex'
 	export default {
 		data() {
 			return {
@@ -48,6 +49,7 @@
 			}
 		},
 		methods: {
+			...mapMutations(['updateInLoginPageStatus']),
 			verify() {
 				this.$refs.uForm.validate().then(res => {
 					// uni.$u.toast('校验通过')
@@ -172,6 +174,7 @@
 			this.isloading = false
 		},
 		onLoad() {
+			this.updateInLoginPageStatus(true)
 			this.isloading = false
 			uni.getStorage({
 				key: 'logincheckbox',
@@ -208,6 +211,12 @@
 					}
 				},
 			})
+		},
+		mounted() {
+			this.updateInLoginPageStatus(true)
+		},
+		onHide(){
+			this.updateInLoginPageStatus(false)
 		}
 	}
 </script>

+ 9 - 2
MingGaoApp/pages/my/index.vue

@@ -28,6 +28,7 @@
 </template>
 
 <script>
+	import {mapMutations} from 'vuex';
 	export default {
 		data() {
 			return {
@@ -37,7 +38,7 @@
 					},
 					username: ""
 				},
-				tablist: ["个人中心", "监测日志", "监督记录", "版本信息"],
+				tablist: ["个人中心", "监测日志", "监督记录", "版本信息", "我的轨迹"],
 				newversion: false,
 				ids: plus.runtime.version
 			}
@@ -60,12 +61,14 @@
 			},
 		},
 		methods: {
+			...mapMutations(['updateUserInfo']),
 			async getinfo() {
 				const res = await this.$myRequest({
 					url: '/api/api_gateway?method=sysmenage.usermanager.user_info',
 				})
 				console.log(res)
 				this.userinfo = res
+				this.updateUserInfo(res);
 				this.getversions()
 			},
 			async getversions() {
@@ -104,7 +107,11 @@
 					uni.navigateTo({
 						url: './version',
 					});
-				} 
+				}else if (index == 4) {
+					uni.navigateTo({
+						url: '/pages/my/map',
+					});
+				}
 			}
 		},
 		onLoad() {

+ 337 - 0
MingGaoApp/pages/my/map.nvue

@@ -0,0 +1,337 @@
+<template>
+	<view class="content">
+		<map id="map" ref="map" :show-location="true" :style="{width:'750rpx',height:phoneHeight+'px'}"
+			:latitude="latitude" :longitude="longitude" :markers="covers" :polyline="polylines">
+		</map>
+		<view class="fixed-bottom">
+			<u-cell :title="date" isLink :border="false" @click="handleSelectDate"></u-cell>
+			<u-button style="margin-left: 20rpx;" text="播放" type="primary" @click="handlePlayWalkTrack" size="small">
+			</u-button>
+		</view>
+		<u-loading-page loading-text="加载中..." bgColor="transparent" :loading="loading" font-size="16"></u-loading-page>
+		<u-calendar :monthNum="monthNum" :defaultDate="date" :minDate="minDate" :maxDate="maxDate"
+			:show="calendarVisible" mode="single" @confirm="handleConfirmSelected" @close="handleCalendarClose">
+		</u-calendar>
+	</view>
+</template>
+
+<script>
+	import * as trackService from '@/service/track.js'
+	import {
+		mapState,
+		mapMutations,
+		mapGetters
+	} from 'vuex'
+	import {
+		forIn,
+		takeRight,
+		keys,
+		map,
+		first,
+		flatten,
+		uniqBy
+	} from 'lodash-es';
+	import dayjs from 'dayjs'
+
+	const markerPath = '/static/person.png';
+
+	export default {
+		data() {
+			return {
+				show: false,
+				isUpdateLocation: false,
+				title: 'Hello',
+				list: [{
+					text: '点赞',
+					color: 'blue',
+					fontSize: 28
+				}, {
+					text: '分享'
+				}, {
+					text: '评论'
+				}],
+				show: true,
+				id: 0, // 使用 marker点击事件 需要填写id
+				title: 'map',
+				latitude: 39.909,
+				longitude: 116.39742,
+				covers: [{
+					id: 1,
+					latitude: 39.909,
+					longitude: 116.39742,
+					iconPath: markerPath,
+					width: 20,
+					height: 20,
+				}],
+				// {
+				// 	points: [{
+				// 			latitude: 39.909,
+				// 			longitude: 116.39742
+				// 		},
+				// 		{
+				// 			latitude: 39.9,
+				// 			longitude: 116.39
+				// 		},
+				// 		{
+				// 			latitude: 39.88,
+				// 			longitude: 116.34
+				// 		},
+				// 		{
+				// 			latitude: 39.83,
+				// 			longitude: 116.31
+				// 		},
+				// 		{
+				// 			latitude: 39.8,
+				// 			longitude: 116.3
+				// 		},
+				// 	],
+
+				// }
+				logs: [],
+				polylines: [],
+				allLocationDatasource: {},
+				phoneHeight: 600,
+				loading: false,
+				userinfo: {},
+				page: 1,
+				pageSize: 10,
+				total: 0,
+				date: dayjs().format('YYYY-MM-DD'),
+				calendarVisible: false,
+				minDate: dayjs().subtract(5, 'months').format('YYYY-MM-DD'),
+				maxDate: dayjs().add(1, 'days').format('YYYY-MM-DD'),
+				monthNum: 12,
+			}
+		},
+		onLoad() {
+			const that = this;
+			uni.getSystemInfo({
+				//异步获取。
+				success(res) {
+					that.phoneHeight = res.windowHeight; //窗口高度
+					console.log(that.phoneHeight)
+				},
+			})
+
+		},
+		onReady() {
+
+			console.log(this.$refs.map, 'on ready')
+			this._mapContext = uni.createMapContext('map', this);
+
+			this.setCenterPosition()
+		},
+		computed: {
+			...mapGetters(['userUID']),
+			currentLogs() {
+				return takeRight(this.logs, 5)
+			},
+
+		},
+		mounted() {
+			this.init();
+		},
+		methods: {
+			init() {
+				this.getTrackList();
+			},
+			getTrackList() {
+				this.loading = true;
+				const payload = {
+					page: this.page,
+					page_item: this.pageSize,
+					uid: this.userUID,
+					create_time: this.date
+				}
+
+				trackService.fetchTrackListWithDate(payload).then(res => {
+					console.warn(res, '------------ track list')
+					this.total = res.total_item;
+					this.allLocationDatasource = first(res.page_list);
+					this.updatePolylines();
+				}).finally(() => {
+					this.loading = false;
+				})
+			},
+			updatePolylines() {
+				const walkList = this.allLocationDatasource['walk_list'] || [];
+
+				const groupWalkDataList = uniqBy(flatten(walkList), item => item.create_time.trim()).sort((a, b) => +dayjs(
+					a.create_time) - (+dayjs(b.create_time)))
+
+				this.polylines = map([groupWalkDataList], (singleWalkList, index) => {
+
+					return {
+						points: map(singleWalkList, item => {
+							return {
+								latitude: item.lat,
+								longitude: item.lng
+							}
+						}),
+						color: '#44b449',
+						arrowLine: true,
+					}
+				})
+
+
+
+				const startData = first(first(walkList));
+
+				const startLocation = {
+					latitude: startData.lat,
+					longitude: startData.lng
+				}
+
+				this._mapContext.moveToLocation(startLocation);
+			},
+			setCenterPosition() {
+				uni.getLocation({
+					type: 'gcj02',
+					altitude: true,
+					success: (res) => {
+						console.warn(res, 'get location')
+						console.log('当前位置的经度1:' + res.longitude);
+						console.log('当前位置的纬度1:' + res.latitude);
+
+						this.logs.push(`center-position:当前位置的经度${res.longitude};当前位置的纬度${res.latitude}`)
+
+						this.latitude = res.latitude;
+						this.longitude = res.longitude;
+
+						this._mapContext.moveToLocation({
+							latitude: res.latitude,
+							longitude: res.longitude
+						})
+
+						this.covers = [{
+							id: 1,
+							latitude: res.latitude,
+							longitude: res.longitude,
+							iconPath: markerPath,
+							width: 40,
+							height: 40,
+						}]
+					},
+					fail(err) {
+						console.warn(err, 'get location error')
+					}
+				});
+			},
+			startGetLocation() {
+				this.isUpdateLocation = true
+				this.setCenterPosition()
+			},
+			endGetLocation() {
+				this.isUpdateLocation = false
+			},
+			getLocation() {
+				return new Promise((resolve, reject) => {
+					console.log('getlocation start', this.isUpdateLocation)
+					if (!this.isUpdateLocation) {
+						console.log('getlocation start 1 close')
+						resolve(true)
+						return
+					}
+
+					console.log('getlocation start 2 exec')
+
+					uni.getLocation({
+						type: 'gcj02',
+						success: (res) => {
+							console.log('当前位置的经度:' + res.longitude);
+							console.log('当前位置的纬度:' + res.latitude);
+							this.logs.push(`记录中:当前位置的经度${res.longitude};当前位置的纬度${res.latitude}`)
+
+							resolve(false)
+						},
+						fail(err) {
+							console.warn(err, 'get location error')
+						}
+					});
+				})
+
+			},
+			handleTransformHistory() {
+				if (!this.polylines.length) {
+					return
+				}
+
+				const startData = first(this.polylines[0].points)
+
+				this._mapContext.moveToLocation({
+					latitude: startData.latitude,
+					longitude: startData.longitude
+				})
+
+				this.execMoveQueueList(map(this.polylines, item => item.points))
+
+			},
+			execMoveQueueList(queueList = []) {
+				const markerID = this.covers[0] && this.covers[0].id;
+				let index = 0;
+				const that = this;
+
+				const exec = function() {
+					const linePointDataList = queueList[index] || [];
+					const path =
+						that._mapContext.moveAlong({
+							markerId: markerID,
+							path: linePointDataList,
+							duration: 30000,
+							autoRotation: false,
+							success() {
+								if (index < queueList.length - 1) {
+									index++;
+									exec();
+								}
+							},
+							fail(err) {
+								console.error(err)
+							},
+							complete() {
+								console.log('move complete ----------------------')
+							}
+						})
+				}
+
+				exec();
+			},
+			handlePlayWalkTrack() {
+				this.handleTransformHistory();
+			},
+			handleClearStorage() {
+				console.log('clear storage')
+				uni.clearStorage()
+			},
+			handleSelectDate() {
+				this.calendarVisible = true;
+			},
+			handleConfirmSelected(dateList) {
+				this.date = first(dateList) || dayjs().format('YYYY-MM-DD');
+				this.handleCalendarClose();
+				this.getTrackList();
+			},
+			handleCalendarClose() {
+				this.calendarVisible = false;
+			}
+		}
+	}
+</script>
+
+<style>
+	.content {
+		padding-top: 100rpx;
+	}
+
+	.fixed-bottom {
+		position: fixed;
+		left: 0;
+		right: 0;
+		top: 0;
+		padding: 24rpx;
+		background-color: #fff;
+		display: flex;
+		flex-direction: row;
+		align-items: center;
+	}
+</style>

+ 1 - 0
MingGaoApp/pages/supervise/supetask.vue

@@ -62,6 +62,7 @@
 		onLoad(option) {
 			this.taskid = Number(option.id)
 			let pages = getCurrentPages();
+			console.log(pages.length,'--------------- onload')
 			var page = pages[pages.length - 1];
 			var currentWebview = page.$getAppWebview();
 			if(this.istask==1){

+ 12 - 0
MingGaoApp/service/track.js

@@ -0,0 +1,12 @@
+
+import {
+	myRequest
+} from '@/util/api.js';
+
+// 我的轨迹 //monitor_manage.home_map.user_walk_list
+export function fetchTrackListWithDate(data) {
+	return myRequest({
+		url: '/api/api_gateway?method=monitor_manage.home_map.user_walk_list',
+		data
+	})
+}

BIN
MingGaoApp/static/person.png


BIN
MingGaoApp/static/person1.png


+ 14 - 1
MingGaoApp/store/index.js

@@ -21,6 +21,8 @@ const store = new Vuex.Store({
 		pendingVideoConnect: false,
 		isVideoTalking: false,
 		isVideoCallRefused: false,
+		userInfo: {},
+		isInLoginPage:false
 	},
 	mutations: {
 		updateVideoInfo(state, payload) {
@@ -41,15 +43,26 @@ const store = new Vuex.Store({
 		},
 		updateIsRefusedCall(state, flag) {
 			state.isVideoCallRefused = flag
+		},
+		updateUserInfo(state,payload){
+			console.log(payload,'update user info')
+			state.userInfo = payload
+		},
+		updateInLoginPageStatus(state,flag){
+			state.isInLoginPage = flag;
 		}
 	},
 	actions: {},
 	getters: {
 		list: () => {
 
+		},
+		userUID(state) {
+			console.log(state.userInfo,'store user uid')
+			return state.userInfo.myuid || ''
 		}
 	},
-	modules:{
+	modules: {
 		task
 	}
 })

+ 1 - 1
MingGaoApp/store/modules/task.js

@@ -75,7 +75,7 @@ export default {
 		}, ) {
 			taskService.fetchTaskRecordRatio().then(res=>{
 				console.warn('task record ratio',res)
-				// commit('updateTaskRecordRatio', data);
+				commit('updateTaskRecordRatio', res.upload_rate);
 				// console.warn('add record location', payload)
 			})
 		}

Разница между файлами не показана из-за своего большого размера
+ 2 - 2
MingGaoApp/unpackage/dist/dev/app-plus/app-config-service.js


Разница между файлами не показана из-за своего большого размера
+ 28756 - 28756
MingGaoApp/unpackage/dist/dev/app-plus/app-service.js


Разница между файлами не показана из-за своего большого размера
+ 1187 - 1187
MingGaoApp/unpackage/dist/dev/app-plus/app-view.js


Разница между файлами не показана из-за своего большого размера
+ 8550 - 8457
MingGaoApp/unpackage/dist/dev/app-plus/pages/response/video.js


+ 17 - 10
MingGaoApp/util/api.js

@@ -1,17 +1,22 @@
 import config from "./url.js"
+import store from '@/store/index.js';
 
 export const myRequest = (options) => {
 	let BASE_URL = config.baseUrl
-	console.log(BASE_URL)
+	console.log(BASE_URL, options.url)
 	var session_key = ""
 	session_key = uni.getStorageSync('session_key')
 	let url = options.url
 	let data = options.data || {}
-	if (url != 'sysmenage.usermanager.user_login' && url != 'pest.pests.insect_discern') {
+	if (!url.includes('sysmenage.usermanager.user_login') && !url.includes('pest.pests.insect_discern')) {
 		data.token = session_key
+
+		if (!session_key) {
+			return Promise.reject('请重新登录');
+		}
 	}
-	
-	console.log(data,'---------- my request')
+
+	console.log(data, '---------- my request')
 
 	return new Promise((resolve, reject) => {
 		uni.request({
@@ -30,12 +35,14 @@ export const myRequest = (options) => {
 						icon: "none"
 					})
 					if (res.data.errorCode == 403) {
-						uni.setStorageSync('session_key', '')
-						setTimeout(() => {
-							uni.navigateTo({
-								url: "/pages/login/login"
-							})
-						}, 2000)
+						if (!store.state.isInLoginPage) {
+							uni.setStorageSync('session_key', '')
+							setTimeout(() => {
+								uni.navigateTo({
+									url: "/pages/login/login"
+								})
+							}, 2000)
+						}
 					}
 				}
 				resolve(res.data.data)

+ 4 - 4
MingGaoApp/util/url.js

@@ -4,10 +4,10 @@ export default {
 	// baseUrl:"https://yfznscd.com"
 	// baseUrl:"https://www.toreskj.com"
 	// baseUrl:"https://www.yhswjc.com"
-	// baseUrl:"http://192.168.1.52:12345",
-	// wsUrl:"ws://192.168.1.52:12345",
+	baseUrl:"http://192.168.1.52:12345",
+	wsUrl:"ws://192.168.1.52:12345",
 	// baseUrl:"http://192.168.1.77:12345",
 	// baseUrl:"https://www.toreskj.com",
-	baseUrl:"http://114.115.147.140:12345",
-	wsUrl:"ws://114.115.147.140:12345",
+	// baseUrl:"http://114.115.147.140:12345",
+	// wsUrl:"ws://114.115.147.140:12345",
 }