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(() => { Android.onJsFunctionCalled(2000); }, 2000); } var vm = new Vue({ el: '#appStates', data: { timer: new Timeout(), web: { info: true, error: false, }, }, methods: { setWeb: function(bool) { if(bool) { this.web.info = true; this.web.error = false; }else { this.web.info = false; this.web.error = true; } }, startCheck: function() { var self = this; this.timer.start(function() { self.checkServerStates(); }, 2000); }, checkServerStates: function() { var self = this; var searchParams = { num: 2 }; var json = JSON.stringify(searchParams); // 请求后台 ajax({ url: 'Batt_rtstateAction!serchByInfo', data: 'json='+json, success: function(res) { //console.log(res); self.setWeb(true); }, error: function() { // 设置服务器连接状态异常 self.setWeb(); }, complete: function() { // 开启计时器 self.timer.open(); }, }); } }, mounted() { // 开启检测是否连接正常 this.startCheck(); }, }); });