'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();
|
}
|
});
|