|
@@ -1,8 +1,7 @@
|
|
import Vue from 'vue'
|
|
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
import Vuex from 'vuex'
|
|
import WebSocketUtil from '@/utils/WebSocketUtil';
|
|
import WebSocketUtil from '@/utils/WebSocketUtil';
|
|
-// import Router from '@/router'
|
|
|
|
-import { Message, MessageBox } from 'element-ui';
|
|
|
|
|
|
+import { Toast, Dialog } from 'vant';
|
|
Vue.use(Vuex)
|
|
Vue.use(Vuex)
|
|
|
|
|
|
export default new Vuex.Store({
|
|
export default new Vuex.Store({
|
|
@@ -13,6 +12,7 @@ export default new Vuex.Store({
|
|
height: 0,
|
|
height: 0,
|
|
apiToken: "",
|
|
apiToken: "",
|
|
webSocket: WebSocketUtil,
|
|
webSocket: WebSocketUtil,
|
|
|
|
+ // wsUrl: "ws://192.168.0.19:9002/socket/flight",
|
|
wsUrl: "ws://192.168.0.151:9002/socket/flight",
|
|
wsUrl: "ws://192.168.0.151:9002/socket/flight",
|
|
userId: '', // 用户名称
|
|
userId: '', // 用户名称
|
|
orderInfo: null, // 订单信息
|
|
orderInfo: null, // 订单信息
|
|
@@ -20,9 +20,16 @@ export default new Vuex.Store({
|
|
loading: null, // loading
|
|
loading: null, // loading
|
|
taskNum: 0, // 重新创建任务次数
|
|
taskNum: 0, // 重新创建任务次数
|
|
takeOffShow: false, // 是否可以起飞
|
|
takeOffShow: false, // 是否可以起飞
|
|
- flightData: {
|
|
|
|
|
|
|
|
|
|
+ flightData: {
|
|
|
|
+ capacityPercent: 100, // 电池的总剩余电量
|
|
|
|
+ homeDistance: 0, //与起飞点的水平距离
|
|
|
|
+ height: 0, // 绝对高度
|
|
|
|
+ verticalSpeed: 0, // 垂直速度
|
|
|
|
+ horizontalSpeed: 0, // 水平速度
|
|
|
|
+ quality: 0, // 网络质量 0:无信号 1:差 2:较差 3:一般 4:较好 5:好
|
|
}, // 无人机飞行数据
|
|
}, // 无人机飞行数据
|
|
|
|
+
|
|
currentPage: 1, // 1: 订单详情页,2:无人机详情页
|
|
currentPage: 1, // 1: 订单详情页,2:无人机详情页
|
|
router: null, // 路由数据
|
|
router: null, // 路由数据
|
|
|
|
|
|
@@ -44,7 +51,7 @@ export default new Vuex.Store({
|
|
},
|
|
},
|
|
// 初始化WebSocket
|
|
// 初始化WebSocket
|
|
initWebSocketUtil({ commit }, value) {
|
|
initWebSocketUtil({ commit }, value) {
|
|
- console.log('初始化WebSocket', this.$router)
|
|
|
|
|
|
+ // console.log('初始化WebSocket', this.$router)
|
|
// console.log('初始化WebSocket', this.state.orderInfo)
|
|
// console.log('初始化WebSocket', this.state.orderInfo)
|
|
// return
|
|
// return
|
|
if (this.state.status != 0) return;
|
|
if (this.state.status != 0) return;
|
|
@@ -53,7 +60,7 @@ export default new Vuex.Store({
|
|
// console.log('11111');
|
|
// console.log('11111');
|
|
this.state.status = 1; // 标记为连接中
|
|
this.state.status = 1; // 标记为连接中
|
|
const url = `${this.state.wsUrl}/${this.state.orderInfo.businessProductId}/${this.state.userId}`
|
|
const url = `${this.state.wsUrl}/${this.state.orderInfo.businessProductId}/${this.state.userId}`
|
|
- console.log('初始化WebSocket_url', url)
|
|
|
|
|
|
+ // console.log('初始化WebSocket_url', url)
|
|
// 初始化WebSocket
|
|
// 初始化WebSocket
|
|
this.state.webSocket.init({
|
|
this.state.webSocket.init({
|
|
url,
|
|
url,
|
|
@@ -69,13 +76,14 @@ export default new Vuex.Store({
|
|
// 连接打开事件
|
|
// 连接打开事件
|
|
this.state.webSocket.addEventListener('open', (event) => {
|
|
this.state.webSocket.addEventListener('open', (event) => {
|
|
this.state.status = 2;
|
|
this.state.status = 2;
|
|
|
|
+ // Toast('WebSocket连接已打开');
|
|
// console.log('WebSocket连接已打开');
|
|
// console.log('WebSocket连接已打开');
|
|
// this.addMessage('system', '连接已建立');
|
|
// this.addMessage('system', '连接已建立');
|
|
});
|
|
});
|
|
|
|
|
|
// 消息接收事件
|
|
// 消息接收事件
|
|
this.state.webSocket.addEventListener('message', ({ data }) => {
|
|
this.state.webSocket.addEventListener('message', ({ data }) => {
|
|
- console.log('收到消息:', data);
|
|
|
|
|
|
+ // console.log('收到消息:', data);
|
|
// 如果是心跳消息
|
|
// 如果是心跳消息
|
|
if (data && data.type === 'heartbeat') {
|
|
if (data && data.type === 'heartbeat') {
|
|
// this.lastHeartbeat = this.formatTime(new Date());
|
|
// this.lastHeartbeat = this.formatTime(new Date());
|
|
@@ -84,72 +92,80 @@ export default new Vuex.Store({
|
|
}
|
|
}
|
|
// 排队完成可以起飞
|
|
// 排队完成可以起飞
|
|
if (data.msgType == 1) {
|
|
if (data.msgType == 1) {
|
|
- // if (this.state.loading) this.state.loading.close();
|
|
|
|
|
|
+ // Toast('可以起飞');
|
|
|
|
+ // if (this.state.loading) this.state.loading.clear();
|
|
// this.state.loading = null;
|
|
// this.state.loading = null;
|
|
// Router.push(`/droneOperation?flightTaskUuid=${this.state.flightTaskUuid}`);
|
|
// Router.push(`/droneOperation?flightTaskUuid=${this.state.flightTaskUuid}`);
|
|
- this.state.takeOffShow = true;
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ this.state.takeOffShow = true;
|
|
|
|
+ }, 1000);
|
|
}
|
|
}
|
|
// 飞行结束
|
|
// 飞行结束
|
|
if (data.msgType == 2) {
|
|
if (data.msgType == 2) {
|
|
- Message.success('飞行结束,即将退出');
|
|
|
|
|
|
+ Toast('飞行结束,即将退出');
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- this.state.router.replace(`/?orderNumber=${this.state.orderInfo.orderNumber}`);
|
|
|
|
|
|
+ this.state.router.replace(`/?orderNumber=${this.state.orderInfo.orderNumber}&t=${new Date().getTime()}`);
|
|
}, 1000);
|
|
}, 1000);
|
|
this.dispatch('disconnect');
|
|
this.dispatch('disconnect');
|
|
}
|
|
}
|
|
// 创建任务失败,是否重新创建
|
|
// 创建任务失败,是否重新创建
|
|
if (data.msgType == 3) {
|
|
if (data.msgType == 3) {
|
|
- console.log('当前页面', this.state.currentPage);
|
|
|
|
if (this.state.currentPage == 2) {
|
|
if (this.state.currentPage == 2) {
|
|
- // Message.error('飞行任务创建失败');
|
|
|
|
|
|
+ // Toast('飞行任务创建失败');
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- console.log('this.state.router===>', this.state.router);
|
|
|
|
- console.log('window.history===>', window.history.length);
|
|
|
|
- console.log('router.getRoutes===>', this.state.router.getRoutes());
|
|
|
|
try {
|
|
try {
|
|
- if (window.history.length > 1) {
|
|
|
|
- // this.state.router.go(-1);
|
|
|
|
- // this.state.router.back();
|
|
|
|
- // this.state.router.replace('/droneOperation')
|
|
|
|
- // window.location.back();
|
|
|
|
- this.state.router.replace(`/?orderNumber=${this.state.orderInfo.orderNumber}`);
|
|
|
|
- } else {
|
|
|
|
- this.state.router.replace(`/?orderNumber=${this.state.orderInfo.orderNumber}`);
|
|
|
|
- }
|
|
|
|
|
|
+ this.state.router.replace(`/?orderNumber=${this.state.orderInfo.orderNumber}&t=${new Date().getTime()}`);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log(e);
|
|
console.log(e);
|
|
}
|
|
}
|
|
}, 2000);
|
|
}, 2000);
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- MessageBox.confirm('飞行任务创建失败,是否重新创建飞行任务?', '提示', {
|
|
|
|
- confirmButtonText: '确定',
|
|
|
|
- cancelButtonText: '取消',
|
|
|
|
- type: 'warning'
|
|
|
|
|
|
+
|
|
|
|
+ Dialog.confirm({
|
|
|
|
+ title: '提示',
|
|
|
|
+ message: '飞行任务创建失败,是否重新创建飞行任务?',
|
|
}).then(() => {
|
|
}).then(() => {
|
|
this.state.taskNum++;
|
|
this.state.taskNum++;
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
this.state.taskNum = 0;
|
|
this.state.taskNum = 0;
|
|
if (this.state.currentPage == 2) {
|
|
if (this.state.currentPage == 2) {
|
|
// this.state.router.back();
|
|
// this.state.router.back();
|
|
- this.state.router.replace(`/?orderNumber=${this.state.orderInfo.orderNumber}`);
|
|
|
|
|
|
+ this.state.router.replace(`/?orderNumber=${this.state.orderInfo.orderNumber}&t=${new Date().getTime()}`);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
// 飞行任务创建结束,可以起飞
|
|
// 飞行任务创建结束,可以起飞
|
|
if (data.msgType == 4) {
|
|
if (data.msgType == 4) {
|
|
this.state.taskNum = 0;
|
|
this.state.taskNum = 0;
|
|
- if (this.state.loading) this.state.loading.close();
|
|
|
|
|
|
+ if (this.state.loading) this.state.loading.clear();
|
|
this.state.loading = null;
|
|
this.state.loading = null;
|
|
- // Message.success('飞行任务创建成功,即将起飞');
|
|
|
|
|
|
+ // Toast('飞行任务创建成功,即将起飞');
|
|
// this.state.router.replace(`/droneOperation?flightTaskUuid=${this.state.flightTaskUuid}&t=${new Date().getTime()}`);
|
|
// this.state.router.replace(`/droneOperation?flightTaskUuid=${this.state.flightTaskUuid}&t=${new Date().getTime()}`);
|
|
- console.log("flightTaskUuid===》", this.state.flightTaskUuid);
|
|
|
|
- console.log("跳转页面vuex====>")
|
|
|
|
- this.state.router.push(`/droneOperation?t=${new Date().getTime()}&flightTaskUuid=${this.state.flightTaskUuid}`);
|
|
|
|
|
|
+ if (this.state.flightTaskUuid == '') {
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ // console.log("flightTaskUuid===》", this.state.flightTaskUuid);
|
|
|
|
+ // console.log("跳转页面vuex====>")
|
|
|
|
+ this.state.router.replace(`/droneOperation?t=${new Date().getTime()}&flightTaskUuid=${this.state.flightTaskUuid}`);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 收到无人机数据
|
|
if (data.msgType == 10) {
|
|
if (data.msgType == 10) {
|
|
|
|
+ if (data.data) {
|
|
|
|
+ let obj = JSON.parse(data.data) || {};
|
|
|
|
+ // console.log('obj==>', obj);
|
|
|
|
+ let flightData = this.state.flightData;
|
|
|
|
+ if (obj.battery && obj.battery.capacityPercent != null) flightData.capacityPercent = obj.battery.capacityPercent;
|
|
|
|
+ if (obj.homeDistance) flightData.homeDistance = obj.homeDistance;
|
|
|
|
+ if (obj.height) flightData.height = obj.height;
|
|
|
|
+ if (obj.verticalSpeed) flightData.verticalSpeed = obj.verticalSpeed;
|
|
|
|
+ if (obj.horizontalSpeed) flightData.horizontalSpeed = obj.horizontalSpeed;
|
|
|
|
+ if (obj.networkState && obj.networkState.quality != null) flightData.quality = obj.networkState.quality;
|
|
|
|
|
|
|
|
+ this.state.flightData = flightData;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 普通消息
|
|
// 普通消息
|
|
@@ -160,11 +176,13 @@ export default new Vuex.Store({
|
|
this.state.webSocket.addEventListener('error', (event) => {
|
|
this.state.webSocket.addEventListener('error', (event) => {
|
|
this.status = 0;
|
|
this.status = 0;
|
|
console.log('WebSocket连接错误:', event);
|
|
console.log('WebSocket连接错误:', event);
|
|
|
|
+ // Toast('WebSocket连接错误');
|
|
});
|
|
});
|
|
|
|
|
|
// 关闭事件
|
|
// 关闭事件
|
|
this.state.webSocket.addEventListener('close', (event) => {
|
|
this.state.webSocket.addEventListener('close', (event) => {
|
|
this.state.status = 0;
|
|
this.state.status = 0;
|
|
|
|
+ // Toast('WebSocket连接关闭');
|
|
console.log('WebSocket连接关闭:', event);
|
|
console.log('WebSocket连接关闭:', event);
|
|
});
|
|
});
|
|
},
|
|
},
|