test-im

2022-11-11 13:27:20 阅读:1 编辑

mediaLim.js

import wx from './../../../common/wx.js';
var event = weex.requireModule('bmEvents');
module.exports = class  mediaLim {
    constructor() {
      this.resovle = null;
      this.reject = null;
      this.a = 13;
    }
    __invoke(...args){
       wx.alert("invoking Car as a function");
    }
   /* login(param){
        return new Promise((resovle, reject) => {
            this.resovle = resovle;
            this.reject = reject;
            event.on('w_in_out_ok',function(params){
                return resovle(params);
            });
            event.on('w_in_out_error',function(params){
                return reject(params);
            });
            event.emit('w_im_in',{method:"login",param:param});
        });
    }*/
}

/im/lim/login/login

<template>
  <div>
    <div style="margin-top: 100px;">
      <text class="text">第二页</text>
    </div>
    <div style="margin-top: 100px;">
      <text class="text">new_value:{{new_value}}</text>
    </div>
  </div>

</template>
<style scoped>
  .text{
    font-size: 50px;
  }
</style>
<script>
    import wx from './../../../common/wx'
    import mediaLim from './../../../im/resource/js/mediaLim'
    export default {
        data:function () {
            return {
                new_value:''
            };
        },
        mixins: [require('./../../../common/publish').publish],
        methods:{

        },
        mounted:function () {
            let m_lim = new mediaLim();
         //  wx.alert(m_lim);
            m_lim.login({
                userID: "123",
                userSig: ""
            }).then(res => {
                wx.alert("ok");

            }).catch(res => {
                wx.alert(res);

            });
        },
        created:function () {

        }
    }

</script>

home.js

<template>
    <div>

        <div style="margin-top: 100px;">
            <text class="text" @click="modify">修改</text>
        </div>
        <div style="margin-top: 100px;">
            <text class="text" @click="nextPage">进入第二页</text>
        </div>
        <div style="margin-top: 100px;">
            <text class="text">首页{{new_value}}</text>
        </div>
    </div>

</template>
<style scoped>
    .text{
        font-size: 50px;
    }
</style>
<script>
    import wx from './../../common/wx'
    export default {
        data:function () {
            return {
                new_value:''
            };
        },
        mixins: [require('./../../common/publish').publish],

        mounted:function () {
            //this.new_value = this.GLOBAL;

        },
        created:function () {

        },
        methods:{
            nextPage(){
                wx.navigateTo({
                    url:"/im/lim/login/login",
                })
            },
            modify(){
               // this.new_value = this.$router.imSet();
                /*this.new_value = this.$imCreate({
                    SDKAppID: '',
                    _type: '',
                    _sub_type: '',
                    base_url: 'http://im2.test'
                });*/
                //this.new_value = this.$getValue();
                //this.new_value = this.$router.imSet();
                /*this.$router.open({
                    name: 'live.aozhi.apply.apply',
                    type: 'PUSH'
                })*/
            }
        }

    }

</script>
mediator/index.js
<template>
    <div></div>
</template>

<script>
    import  wx from "./../pages/common/wx";
    import  siteinfo from "./../pages/siteinfo";
    // 这个vue的实例我们在app启动的时候就执行并常驻app内存,在app关闭时候销毁,所以data中的数据每次重启都会被初始化
    // 而我们在app运行期间都可以任意改变data中的数据,然后推送给订阅者

    // 如果想要持久化存储,可以配合storage来完成,每次启动app时候都从本地取数据,当data改变的时候异步的更新一下即可
    // 住: 不能再app退出的时候来持久化存储,退出时间很短,无法保证存储成功

    // 我们不建议在这里存储大量的数据 这里仅仅希望用作一个中介者 来提供给其他页面实例来通信 他无法替代storage 读取速度也远远慢与storage
    export default {
        data () {
            return {
                ws_open: false,
                address:'',
                console_type: 'console', //console,websocket
                lim:null,
            }
        },
        methods: {
            bindEvent () {
                this.$event.on('refresh', resData => {
                    this.$router.refresh()
                })
            },
            enableLog(address){
                this.address = address;
                this.console_type = "websocket";
                this.openWebSocket();
                this.bindLogEvent();
            },
            openWebSocket(callback) {
                var that = this;
                if (this.console_type == "websocket") {
                    var bmWebSocket = weex.requireModule('bmWebSocket')
                    bmWebSocket.webSocket('ws://' + this.address, '');
                    var self = this;
                    bmWebSocket.onopen(function (e) {
                        self.ws_open = true;
                        if(callback != undefined){
                            return callback();
                        }
                    });
                    bmWebSocket.onerror(function(e) {
                        self.ws_open = false;
                    });
                }
            },
            bindLogEvent() {
                var self = this;
                this.$event.on('log', resData => {
                    if (self.console_type == "websocket") {
                        var bmWebSocket = weex.requireModule('bmWebSocket')
                        if (!self.ws_open) {
                            self.openWebSocket(function () {
                                bmWebSocket.send(JSON.stringify(resData));
                            })
                        }else{
                            bmWebSocket.send(JSON.stringify(resData));
                        }

                    } else {
                        console.log(resData.msg);
                    }

                })
            },
            bindWebSocketEvent() {
                var self = this;
                var bmWebSocket = weex.requireModule('bmWebSocket')
                this.$event.on('w_websocket_connect', resData => {

                    bmWebSocket.webSocket(resData.url,'');
                    bmWebSocket.onopen(function (e) {
                        self.$event.emit("w_websocket_onoppen",{});
                    });
                    bmWebSocket.onmessage(function (e) {
                        self.$event.emit("w_websocket_onmessage",{data: e.data});
                    });
                    bmWebSocket.onerror(function (e) {
                        self.$event.emit("w_websocket_onerror",{errMsg: e.data});
                    });
                    bmWebSocket.onclose(function (e) {
                        self.$event.emit("w_websocket_onclose",{errMsg: e.data});
                    });
                })
                this.$event.on('w_websocket_send', resData => {
                    bmWebSocket.send(resData.data);
                })
                this.$event.on('w_websocket_close', resData => {
                    bmWebSocket.close(resData.code, resData.reason);
                })
            },
            bindImEvent(){
                let LIM = require('./../pages/im/resource/js/lim');
                let  param = {
                    SDKAppID: '',
                    _type: '',
                    _sub_type: '',
                };
                this.lim = LIM.create(param);
                this.$event.on('w_im_in', resData => {
                    let method = resData.method;
                    let param = resData.param;
                    this.lim[method](param).then(res => {
                      //  wx.alert("ok");
                        this.$event.emit("w_in_out_ok",res);
                    }).catch(res => {
                      //  wx.alert("fail");
                        this.$event.emit("w_in_out_error",res);
                    });
                });
            }
        },

        created () {
           // this.enableLog("192.168.1.161:8090");
            this.bindEvent();
            this.bindWebSocketEvent();
            this.bindImEvent();
            wx.getAppConfig(function (config) {
                var bmWXShare = weex.requireModule('bmWXShare');
                bmWXShare.initUM(config.meng);
                bmWXShare.initWX({
                    appKey: config.wx_app_id, // 微信开发平台申请的appkey
                    appSecret: config.wx_app_secret, // appKey对应的appSecret,
                    redirectURL: '' // 授权回调页面
                });
            });
            wx.removeStorageSync("w_system_globalData");
            const app = wx.getApp();
            if(app.globalData){
                wx.setStorageSync("w_system_globalData", app.globalData);
            }
            wx.removeStorageSync("w_system_lnglat");
            wx.removeStorageSync("w_system_app_config");
            wx.removeStorageSync("w_system_navigation_bar");
            wx.removeStorageSync("w_sys_page_level");
            wx.removeStorageSync("w_system_has_tabbar");
            wx.removeStorageSync("w_system_tabbar_index");
            wx.setStorageSync("w_system_tabbar_params",wx.getStorageSync("w_system_tabbar_params_backup"));
            if(!wx.getStorageSync('userInfo')){
                var userInfo =  {
                    avatarUrl:"",
                    nickName: "",
                }
                wx.setStorageSync('userInfo', userInfo);
            }
            var home = "/pages/" + siteinfo.app_set.setting.home  + ".js";
            var w_system_pages = {};
            w_system_pages[home] = 1;
            wx.setStorageSync('w_system_pages', w_system_pages);
            wx.setStorageSync('w_system_prev_page_flag', siteinfo.app_set.setting.home.replace(/\//g,"_"));
            var params = {
                path:siteinfo.app_set.setting.home,
                scene:1001,
                query:{},
                shareTicket:"",
                referrerInfo:{},
            };
            if(app.onLaunch){
                app.onLaunch(params);
            }
            if(app.onShow){
                app.onShow(params);
            }
            //wx.setStorageSync("zhyshopInfo", {"id":59,"openid":"o3W0Y44N24Gch-EuzJ_dofaoAqZs","avatar":"https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIDFTH6RR3nzGNfk82p9Cy3zibqLnYtGm61iaVvQmu9glEBgApFPic8JVFy6sbVjED5lJLrjIMrSOsibA/132","uniacid":1023,"tel":"18888888888","address":null,"nickname":"success","birthday":null,"gender":1,"email":null,"create_time":"2019-06-14 14:32:10","update_time":"2019-10-14 14:59:21","login_time":1569721726,"login_ip":null,"integral":41582,"now_integral":40942,"balance":"176.18","is_member":0,"total_consume":"151.67","memberconf_id":0,"discount":"0.0","share_user_id":0,"last_share_user_id":null,"first_share_user_id":null,"vip_cardnum":"10000059","vip_endtime":1764231061,"parents_id":8,"parents_name":null,"usercenter_id":null,"user_type":1,"phone":"13333333333","password":null,"error_login":0,"applogin_time":null,"total_own_order_num":5,"sign_days":1,"last_sign_time":1571036361,"coins":35,"need_use_coins":0,"used_coins":114,"allcommission":"60.94","canwithdraw":"60.94","freezemoney":"0.00"});

        }
    }
</script>