163 lines
4.7 KiB
Vue
163 lines
4.7 KiB
Vue
![]() |
<template>
|
||
|
<el-container id="layoutBox">
|
||
|
<el-aside class="animation" :class="isCollapse ? 'menuW' : 'menuS'">
|
||
|
<Menubar />
|
||
|
</el-aside>
|
||
|
<el-container>
|
||
|
<el-header>
|
||
|
<Headbar />
|
||
|
</el-header>
|
||
|
<el-main>
|
||
|
<router-view :key="rouKey" />
|
||
|
</el-main>
|
||
|
<el-footer>
|
||
|
<BlogBox />
|
||
|
</el-footer>
|
||
|
</el-container>
|
||
|
</el-container>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import mqtt from '@/utils/mqtt'
|
||
|
import Menubar from '@/views/layout/components/menubar'
|
||
|
import Headbar from '@/views/layout/components/headbar'
|
||
|
import BlogBox from '@/views/layout/components/BlogBox'
|
||
|
|
||
|
export default {
|
||
|
name: 'Layout',
|
||
|
data () {
|
||
|
return {
|
||
|
frequencySetTimeout: null // 对频信息保持
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
},
|
||
|
components: {
|
||
|
Menubar,
|
||
|
Headbar,
|
||
|
BlogBox
|
||
|
},
|
||
|
computed: {
|
||
|
rouKey () {
|
||
|
return this.$route.path
|
||
|
},
|
||
|
isCollapse () {
|
||
|
return this.$store.state.app.isCollapse
|
||
|
},
|
||
|
shop_id () {
|
||
|
return this.$store.state.user.shop_id
|
||
|
},
|
||
|
airList () {
|
||
|
return this.$store.state.airList
|
||
|
}
|
||
|
},
|
||
|
created () {
|
||
|
},
|
||
|
mounted () {
|
||
|
/* init */
|
||
|
this.$store.commit('app/setIsMobile')// 获取客户端平台类型
|
||
|
this.$store.dispatch('fetchAdminList')// 获取管理员列表
|
||
|
this.$store.dispatch('fetchSiteList')// 获取站点列表
|
||
|
this.$store.dispatch('fetchRouteList')// 获取航线列表
|
||
|
this.$store.dispatch('fetchQuestList')// 获取订单列表 ps:待发货及待收货 并且不是退款成功状态
|
||
|
this.$store.dispatch('fetchAirList')// 获取飞机列表
|
||
|
},
|
||
|
watch: {
|
||
|
/**
|
||
|
* @description: 异步拿到飞机列表之后 再进行一些初始化操作
|
||
|
* @param {*} res 飞机列表
|
||
|
*/
|
||
|
airList (res) {
|
||
|
/* mqtt */
|
||
|
mqtt.mqttConf()// 连接mqtt
|
||
|
// 订阅飞机信息
|
||
|
mqtt.doSubscribe('planeState/+', (mqttRes) => {
|
||
|
res.forEach(plane => {
|
||
|
if (mqttRes.topic.indexOf(plane.macadd) > -1) {
|
||
|
// 反序列化 mqtt信息
|
||
|
const jsonData = JSON.parse(mqttRes.msg.trim())
|
||
|
// 更新mqtt信息 选择性更新状态
|
||
|
for (const key in jsonData) {
|
||
|
if (key === 'heartBeat') { // 每次接收到心跳 heartRandom属性 创建一个随机数 用于watch监听
|
||
|
plane.planeState.heartRandom = Math.random()
|
||
|
}
|
||
|
if (key === 'position') { // 如果是飞机位置信息 则不是直接刷新状态 而是累计 到数组 以便于画出飞机路径
|
||
|
let position = jsonData.position
|
||
|
position = position.replace(/([a-zA-Z0-9]+):/g, '"$1":')// mcu过来的json格式修正一下 键没有引号 改成"lng":
|
||
|
position = JSON.parse(position)
|
||
|
plane.planeState.position.push([position.lng / 10e6, position.lat / 10e6, Number(position.alt)])
|
||
|
if (plane.planeState.position.length > 1000) {
|
||
|
plane.planeState.position.shift()// 删除最早的经纬度
|
||
|
}
|
||
|
} else {
|
||
|
plane.planeState[key] = jsonData[key]// 按订阅信息 刷新飞机状态
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
// 订阅对频
|
||
|
mqtt.doSubscribe('crosFrequency/+', (res) => {
|
||
|
if (res.topic.indexOf('crosFrequency') > -1) {
|
||
|
this.$store.commit('setCrosFrequency', res.msg)// 设置对频信息
|
||
|
clearTimeout(this.frequencySetTimeout)// 接收到新的订阅信息 清除之前的倒计时
|
||
|
this.frequencySetTimeout = setTimeout(() => { // 倒计时10秒 随之清除缓存中对频信息
|
||
|
this.$store.commit('setCrosFrequency', null)
|
||
|
}, 10000)
|
||
|
}
|
||
|
})
|
||
|
// 订阅游客下单频道
|
||
|
mqtt.doSubscribe(`refreshQuestList/${this.shop_id}`, (res) => {
|
||
|
if (res.topic.indexOf(`refreshQuestList/${this.shop_id}`) > -1) {
|
||
|
this.$store.dispatch('fetchSiteList')// 刷新站点列表
|
||
|
this.$store.dispatch('fetchQuestList')// 刷新订单列表 ps:待发货及待收货 并且不是退款成功状态
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
destroyed () {
|
||
|
mqtt.mqttDestroy()// 断开mqtt
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style lang="scss" scoped>
|
||
|
@import "@/styles/theme.scss";
|
||
|
|
||
|
#layoutBox {
|
||
|
height: 100%;
|
||
|
}
|
||
|
|
||
|
.el-aside {
|
||
|
background-color: #304156;
|
||
|
overflow: hidden !important;
|
||
|
}
|
||
|
|
||
|
.menuW {
|
||
|
width: 60px !important;
|
||
|
}
|
||
|
|
||
|
.menuS {
|
||
|
width: 210px !important;
|
||
|
}
|
||
|
|
||
|
.el-header {
|
||
|
padding: 0 !important;
|
||
|
height: 50px !important;
|
||
|
line-height: 50px !important;
|
||
|
overflow: hidden;
|
||
|
z-index: 99;
|
||
|
box-shadow: 0 0px 4px rgba(0, 21, 41, .08);
|
||
|
}
|
||
|
|
||
|
.el-main {
|
||
|
padding: 0 !important;
|
||
|
height: 100%;
|
||
|
background-color: $white-color;
|
||
|
}
|
||
|
|
||
|
.el-footer {
|
||
|
height: 24px !important;
|
||
|
}
|
||
|
</style>
|