import WebSokcet from "./socket/WebSokcet.js"; import SocketEvent from "./Event/SocketEvent.js"; class Base { Vue = {}; //容器 Container = null; constructor(vue,container) { this.Vue = vue; this.Container = container; this.init(); } init() { //添加全局库 this.Vue.prototype.global = this.Container.make(require("@/config/global.js"),"global"); //添加com库 this.Vue.prototype.utils = this.Container.make(require("@/library/utils/Comm.js"),"utils"); //请求库 this.Vue.prototype.request = this.Container.make(require('@/library/Request.js')); //webSocket let websocket = new WebSokcet({wsUrl:this.Vue.prototype.global.wsSocketUrl}); websocket.setKey(this.Vue.prototype.global.putoken); this.Vue.prototype.$deviceType = 'web'; //#ifdef H5 var ua = navigator.userAgent.toLowerCase(); //判断登录模式 if (/MicroMessenger/i.test(ua)) { //var wx = require('jweixin-module'); //this.Vue.prototype.$wx = wx; this.Vue.prototype.$deviceType = 'weixin'; } //判断支付宝 if (/alipayclient/.test(ua)) { this.Vue.prototype.$deviceType = 'alipay'; } //#endif //小程序 // #ifdef MP-WEIXIN this.Vue.prototype.$deviceType = 'mp_weixin'; // #endif //APP // #ifdef APP-PLUS this.Vue.prototype.$deviceType = 'app'; // #endif //获取设备信息 uni.getSystemInfo({ success:(res) => { this.Vue.prototype.$device = res; } }); let socketEvent = new SocketEvent(this.Vue.prototype); websocket.setBackCall((type,res)=>{ if(type == 'onOpen'){ socketEvent.onOpen(res); } if(type == 'onMessage'){ socketEvent.onMessage(res); } if(type == 'onError'){ socketEvent.onError(res); } if(type == 'onStop'){ socketEvent.onStop(res); } if(type == 'onClose'){ socketEvent.onClose(res); } if(type == 'onSendError') { socketEvent.onSendError(res); } if(type == 'onSendSuccess') { socketEvent.onSendSuccess(res); } if(type == 'onHeartBeat') { socketEvent.onHeartBeat(res); } }); // websocket.connect(); this.Vue.prototype.webSocket = websocket; } /** * ipc全局拦截访问 * @param {Object} page 当前页面page * @param {Object} options 参数 */ ipc(page,options){ var tj_uid = options.tj_uid || ''; var ipc = options.ipc || ''; if(tj_uid != '' && tj_uid != null) { this.Vue.prototype.$store.commit('setTjuid',tj_uid); } if(ipc == '') { return ; } //微信登录ipc if(ipc == 'weixin_login') { var data = options.data || ''; try{ let dataAr = JSON.parse(data); this.Vue.prototype.$store.commit('setUser',dataAr); } catch(e){} } } } export default Base;