whychdw
2019-10-10 20e9ed291e6ff2eceed90ee41e0a9cb4ccb2a28b
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
"use strict";
 
window.router = bui.router();
 
bui.ready(function () {
    // 初始化路由
    router.init({
        id: "#bui-router",
        progress: true,
        hash: true
    });
 
    // 绑定事件
    bind();
 
    // 事件类定义
    function bind() {
        // 绑定页面的所有按钮有href跳转
        bui.btn({ id: "#bui-router", handle: ".bui-btn" }).load();
 
        // 统一绑定页面所有的后退按钮
        $("#bui-router").on("click", ".btn-back", function (e) {
            // 支持后退多层,支持回调
            bui.back();
        });
    }
    var timer;
    // 向后台发送心跳包
    if (typeof Android != 'undefined') {
        clearInterval(timer);
        timer = setInterval(function () {
            Android.onJsFunctionCalled(2000);
        }, 2000);
    }
 
    var vm = new Vue({
        el: '#appStates',
        data: {
            timer: new Timeout(),
            web: {
                info: true,
                error: false
            }
        },
        methods: {
            setWeb: function setWeb(bool) {
                if (bool) {
                    this.web.info = true;
                    this.web.error = false;
                } else {
                    this.web.info = false;
                    this.web.error = true;
                }
            },
            startCheck: function startCheck() {
                var self = this;
                this.timer.start(function () {
                    self.checkServerStates();
                }, 2000);
            },
            checkServerStates: function checkServerStates() {
                var self = this;
                var searchParams = {
                    num: 2
                };
                var json = JSON.stringify(searchParams);
                // 请求后台
                ajax({
                    url: 'Batt_rtstateAction!serchByInfo',
                    data: 'json=' + json,
                    success: function success(res) {
                        //console.log(res);
                        self.setWeb(true);
                    },
                    error: function error() {
                        // 设置服务器连接状态异常
                        self.setWeb();
                    },
                    complete: function complete() {
                        // 开启计时器
                        self.timer.open();
                    }
                });
            }
        },
        mounted: function mounted() {
            // 开启检测是否连接正常
            this.startCheck();
        }
    });
});