110 lines
2.9 KiB
JavaScript
110 lines
2.9 KiB
JavaScript
import 'babel-polyfill'
|
||
import Vue from 'vue'
|
||
import App from './App'
|
||
import router from './router'
|
||
import store from './store'
|
||
import 'element-ui/lib/theme-chalk/index.css'
|
||
import util from './utils/util'
|
||
import './assets/fonts/fonts.css'
|
||
// import '@/styles/index.scss' // global css
|
||
import * as echarts from 'echarts'
|
||
import ElementUI from 'element-ui'
|
||
import mqttConfig from './utils/mqttConfig';
|
||
// main.js
|
||
import VScaleScreen from 'v-scale-screen'
|
||
import axios from 'axios'
|
||
|
||
Vue.prototype.$axios = axios
|
||
Vue.use(VScaleScreen)
|
||
|
||
Vue.use(ElementUI)
|
||
Vue.prototype.$echarts = echarts
|
||
// 挂在全局 通用工具集
|
||
Vue.prototype.$util = util
|
||
|
||
import {
|
||
Flexbox,
|
||
FlexboxItem
|
||
} from '@/components/Flexbox'
|
||
Vue.component('flexbox', Flexbox)
|
||
Vue.component('flexbox-item', FlexboxItem)
|
||
|
||
import * as filters from './filters' // global filters
|
||
// 注册全局过滤器
|
||
Object.keys(filters).forEach(key => {
|
||
Vue.filter(key, filters[key])
|
||
})
|
||
|
||
import moment from 'moment'
|
||
//定义一个全局过滤器实现日期格式化
|
||
Vue.filter('datefmt',function (input,fmtstring) {//当input为时间戳时,需转为Number类型
|
||
// 使用momentjs这个日期格式化类库实现日期的格式化功能
|
||
return moment(input).format(fmtstring);
|
||
});
|
||
|
||
Vue.prototype.$moment = moment
|
||
Vue.config.productionTip = false
|
||
|
||
//引入video
|
||
import videojs from "video.js";
|
||
import "video.js/dist/video-js.css";
|
||
Vue.prototype.$video = videojs;
|
||
//MQTT订阅
|
||
var currentTopics = null;
|
||
var client = null;
|
||
var callback = null;
|
||
let mqtt = new mqttConfig(currentTopics);
|
||
window.PubScribe = function (topic, _callback,) {
|
||
callback = _callback;
|
||
if (currentTopics != null) {
|
||
//取消currentTopics主题订阅
|
||
if (client != null) {
|
||
client.unsubscribe(currentTopics);
|
||
currentTopics = null;
|
||
}
|
||
}
|
||
if (client == null) {
|
||
|
||
client = mqtt.createConnect(() => {
|
||
client.subscribe(['/SC/pub/uwb','/SC/pub/env'], {
|
||
qos: 0
|
||
}, (err) => {
|
||
if (!err) {
|
||
console.log("订阅成功0", ['/SC/pub/uwb','/SC/pub/env']);
|
||
}
|
||
});
|
||
|
||
client.on("message", (topic, message) => {
|
||
//数据分类
|
||
try {
|
||
callback(topic, message);
|
||
} catch (error) {
|
||
|
||
}
|
||
});
|
||
});
|
||
} else {
|
||
if (topic != null) {
|
||
console.log("topic",topic)
|
||
currentTopics = topic;
|
||
client.subscribe(currentTopics, {
|
||
qos: 0
|
||
}, (err) => {
|
||
if (!err) {
|
||
console.log("订阅成功1");
|
||
} else {
|
||
console.log('消息订阅失败!')
|
||
}
|
||
|
||
});
|
||
}
|
||
}
|
||
}
|
||
/* eslint-disable no-new */
|
||
new Vue({
|
||
el: '#app',
|
||
router,
|
||
store,
|
||
render: h => h(App)
|
||
})
|