131 lines
2.8 KiB
JavaScript
131 lines
2.8 KiB
JavaScript
/**
|
||
* Copyright (c) 2013-Now http://aidex.vip All rights reserved.
|
||
*/
|
||
import Vue from 'vue';
|
||
import App from './App';
|
||
|
||
Vue.config.productionTip = false;
|
||
|
||
App.mpType = 'app';
|
||
|
||
// 引入全局 uView 框架
|
||
import uView from 'uview-ui';
|
||
Vue.use(uView);
|
||
|
||
|
||
// 全局存储 vuex 的封装
|
||
import store from '@/store';
|
||
|
||
// 引入 uView 提供的对 vuex 的简写法文件
|
||
let vuexStore = require('@/store/$u.mixin.js');
|
||
Vue.mixin(vuexStore);
|
||
|
||
// 引入 uView 对小程序分享的 mixin 封装
|
||
let mpShare = require('uview-ui/libs/mixin/mpShare.js');
|
||
Vue.mixin(mpShare);
|
||
|
||
// Vue i18n 国际化
|
||
import VueI18n from '@/common/vue-i18n.min.js';
|
||
Vue.use(VueI18n);
|
||
//引入websocket文件
|
||
// import wsRequest from '@/utils/GlobalWebSocket.js'
|
||
|
||
|
||
|
||
Vue.prototype.socketTask = null;
|
||
|
||
Vue.prototype.$webSocketInit = function() {
|
||
const socketUrl =
|
||
'ws://183.230.235.66:11010/api/resource/websocket?clientid=dab457a1ea14411787c240db05bb0832&Authorization=Bearer ' +
|
||
this.$store.state.vuex_token;
|
||
console.log("url",socketUrl)
|
||
this.socketTask = uni.connectSocket({
|
||
url: socketUrl, // socket链接IP
|
||
success(res) {
|
||
console.log('webSocket链接成功',res)
|
||
},
|
||
fail(err){
|
||
console.log("失败",err)
|
||
}
|
||
})
|
||
console.log(this.socketTask)
|
||
this.socketTask.onMessage(res => {
|
||
console.log('收到服务器内容:' + res.data)
|
||
try{
|
||
// let message=JSON.parse(res);
|
||
uni.$emit(`ws_qrcode`, res.data);
|
||
}catch(err){
|
||
console.log(err)
|
||
console.log(res)
|
||
}
|
||
|
||
|
||
|
||
// this.$store.state.wslist.add(res.data)
|
||
});
|
||
|
||
}
|
||
|
||
|
||
|
||
Vue.prototype.$webSocketSend = function(data) {
|
||
this.socketTask.send({
|
||
data,
|
||
success(res) {
|
||
console.log('webSocket消息发送成功')
|
||
}
|
||
})
|
||
}
|
||
|
||
Vue.prototype.$closeWebSocket = function() {
|
||
if (!this.socketTask) {
|
||
return
|
||
}
|
||
this.socketTask.close({
|
||
success(res) {
|
||
console.log('webSocket关闭成功', res)
|
||
},
|
||
fail(err) {
|
||
console.log('webSocket关闭失败', err)
|
||
}
|
||
})
|
||
}
|
||
|
||
|
||
|
||
// i18n 部分的配置,引入语言包,注意路径
|
||
import lang_zh_CN from '@/common/locales/zh_CN.js';
|
||
import lang_en from '@/common/locales/en.js';
|
||
|
||
const i18n = new VueI18n({
|
||
// 默认语言
|
||
locale: 'zh_CN',
|
||
// 引入语言文件
|
||
messages: {
|
||
'zh_CN': lang_zh_CN,
|
||
'en': lang_en,
|
||
}
|
||
});
|
||
|
||
// 由于微信小程序的运行机制问题,需声明如下一行,H5和APP非必填
|
||
Vue.prototype._i18n = i18n;
|
||
const app = new Vue({
|
||
i18n,
|
||
store,
|
||
...App
|
||
});
|
||
|
||
import {
|
||
replaceAll
|
||
} from '@/common/common.js'
|
||
Vue.prototype.replaceAll = replaceAll
|
||
|
||
// http 拦截器,将此部分放在 new Vue() 和 app.$mount() 之间,才能 App.vue 中正常使用
|
||
import httpInterceptor from '@/common/http.interceptor.js';
|
||
Vue.use(httpInterceptor, app);
|
||
|
||
// http 接口 API 抽离,免于写 url 或者一些固定的参数
|
||
import httpApi from '@/common/http.api.js';
|
||
Vue.use(httpApi, app);
|
||
|
||
app.$mount(); |