whychdw
2019-10-24 580c89bcdececce0e6cba37e235116bb4a4e48c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict';
 
/**
 * 首页模块
 * 默认模块名: main
 * @return {[object]}  [ 返回一个对象 ]
 */
loader.define({
    data: {
        vm: ''
    },
    loaded: function loaded(require, exports, module) {
        // 设置页面中的Worker线程(需要再workers.js先定义)
        testIpWorker = new Worker('worker/data.worker.js');
        getIpWorker = new Worker('worker/data.worker.js');
        // 引入vue
        this.vm = new Vue({
            el: getPageRoot(module),
            data: {
                loading: bui.loading(),
                ip: '127.0.0.1',
                states: true,
                getIpWorker: getIpWorker,
                testIpWorker: testIpWorker,
            },
            watch: {
                ip: function(val) {
                    this.states = true;
                }
            },
            methods: {
                enterIndex: function() {
                    // 进入首页后
                    this.states = true;
                    var url = getRouteUrl('index');
                    router.load({
                        url: url,
                        param: {}
                    });
                },
                visitorLogin: function() {
                    var self = this;
                    // 游客模式访问
                    bui.confirm('游客模式访问!', function(e){
                        var text = $(e.target).text();
                        if( text == "确定" ){
                            if(typeof(JSInterface) != 'undefined') {
                                JSInterface.setUpDeviceIp('127.0.0.1');
                            }
                            //do something
                            self.enterIndex();
                        }
                        this.close();
                    });
                },
                getIp: function() {
                    var ip = localStorage.getItem('ip');
                    if(ip) {
                        this.ip = ip;
                    }else {
                        this.ip = '127.0.0.1';
                    }
                },
                setIp: function() {
                    var self = this;
                    if(typeof(JSInterface) != 'undefined') {
                        JSInterface.setUpDeviceIp(this.ip);
                        // 将ip添加到本地,下一次登陆自动填充ip
                        localStorage.setItem('ip', this.ip);
                        self.enterIndex();
                    }else {
                        bui.alert('请使用手机端登陆!');
                    }
                },
                testIp: function() {
                    var self = this;
                    if(typeof(JSInterface) != 'undefined') {
                        // 开启等待框
                        self.loading.show();
                        JSInterface.testDeviceIp(this.ip);
                    }else {
                        bui.alert('请使用手机端登陆!');
                    }
                },
                openAndroidWifiUI: function() {
                    if(typeof(JSInterface) != 'undefined') {
                        JSInterface.openAndroidWifiUI();
                    }else {
                        bui.alert('请使用手机端登陆!');
                    }
                }
            },
            computed: {
                getDisabled: function() {
                    return this.states?false:true;
                }
            },
            mounted() {
                var self = this;
                this.getIp();
                // 获取Ip监听
                this.getIpWorker.onmessage = function(res) {
                    if(res.data.code == 1) {
                        self.ip = res.data.data;
                    }
                };
                
                // 测试Ip
                this.testIpWorker.onmessage = function(res) {
                    // 关闭等待框
                    self.loading.hide();
                    
                    if(res.data.code == 1) {
                        self.states = false;
                    }else {
                        bui.alert('测试连接失败!');
                    }
                }
            },
            destroyed: function destroyed() {
 
            }
        });
    },
    show: function() {
        // 关闭后台Android链接
        if(typeof(JSInterface) != 'undefined') {
            JSInterface.exitDeiviceConn();
        }
    },
    destroyed: function destroyed() {
        this.vm.$destroy();
    }
});