import {
    ApiModel
} from './utils/api';

App({
    onLaunch() {},
    initSocket() {
        let that = this;
        this.globalData.SocketTask = wx.connectSocket({
            url: 'wss://meida.cnyunl.com/yos/webSocket/' + wx.getStorageSync('userMsg').token,
            complete: (res) => {
                console.log(res)
            }
        })
        this.globalData.SocketTask.onOpen(function (res) {
            that.globalData.socketEstablish = true;
        })
        this.globalData.SocketTask.onMessage(function (res) {
            that.globalData.socket.callback(res)
        })
        this.globalData.SocketTask.onError(function (res) {
            that.globalData.socketEstablish = false;
        })
        this.globalData.SocketTask.onClose(function (res) {
            that.globalData.socketEstablish = false;
        })
    },
    globalData: {
        site: "美大1",//美大
        http: new ApiModel(), //接口文件
        queryPer: require("./utils/queryPermissions"), //权限查询
        socketEstablish: false, //是否已经建立socket
        SocketTask: '', // Socket方法
        socket: { // Socket回调
            that: null, //保存this
            callback: function () {}
        },
    },
})