OpenWrt_Luci_Lua/Mi_Lua/luci/view/web/plugins/guest.htm
2015-05-09 18:48:46 +08:00

178 lines
6.1 KiB
HTML

<%
--[[
Info 迅雷插件
]]--
local ver = require("xiaoqiang.XQVersion").webVersion
%>
<%include('web/inc/head')%>
<title>小米路由器</title>
<!-- 插件样式 -->
<link rel="stylesheet" href="<%=resource%>/web/css/page.plugin.guest.css?v=<%=ver%>" type="text/css">
</head>
<body>
<div class="mod-plugin-guest">
<div class="msg" style="display:none;"></div>
<div class="item clearfix first">
<div class="con">
<h3>开启共享模式</h3>
<p>新连接的设备允许访问小米路由盘</p>
</div>
<div class="control">
<a href="#" id="guestnet" class="btn-offon btn-off"></a>
</div>
</div>
<div class="item clearfix">
<div class="con">
<h3>数据修改保护</h3>
<p>开启保护后,小米路由盘上的数据不可修改</p>
</div>
<div class="control">
<a href="#" id="guestdata" class="btn-offon btn-off"></a>
</div>
</div>
</div>
<%include('web/inc/g.js.base')%>
<script>
$(global_event).on('plugin:guestOpen', function(evt, data){
var guestEnableNet = function(){
$.when(
$.ajax( {
url: '<%=luci.dispatcher.build_url("api", "xqsystem", "set_mode")%>',
data :{'mode': 1},
dataType: "json"
})
).done(function( rsp ) {
if (rsp.code == 0){
$('#guestnet').attr('data-status', 'enabled');
$('#guestnet')[0].className = 'btn-offon btn-on';
}else{
$('.msg').html(rsp.msg).show();
setTimeout(function(){
$('.msg').hide();
}, 5000);
}
});
},
guestEnableData = function(){
$.when(
$.ajax( {
url: '<%=luci.dispatcher.build_url("api", "xqdatacenter", "request")%>',
data: {'payload':'{"api":31, "readonly":1}'},
dataType: "json"
})
).done(function( rsp ) {
if (rsp.code == 0){
$('#guestdata').attr('data-status', 'enabled');
$('#guestdata')[0].className = 'btn-offon btn-on';
}else{
$('.msg').html(rsp.msg).show();
setTimeout(function(){
$('.msg').hide();
}, 5000);
}
});
},
gutstDisableNet = function(){
$.when(
$.ajax( {
url: '<%=luci.dispatcher.build_url("api", "xqsystem", "set_mode")%>',
data: {'mode': 0},
dataType: "json"
})
).done(function( rsp ) {
if (rsp.code == 0){
$('#guestnet').attr('data-status', 'disabled');
$('#guestnet')[0].className = 'btn-offon btn-off';
}else{
$('.msg').html(rsp.msg).show();
setTimeout(function(){
$('.msg').hide();
}, 5000);
}
});
},
gutstDisableData = function(){
$.when(
$.ajax( {
url: '<%=luci.dispatcher.build_url("api", "xqdatacenter", "request")%>',
data: {'payload':'{"api":31, "readonly":0}'},
dataType: "json"
})
).done(function( rsp ) {
if (rsp.code == 0){
$('#guestdata').attr('data-status', 'disabled');
$('#guestdata')[0].className = 'btn-offon btn-off';
}else{
$('.msg').html(rsp.msg).show();
setTimeout(function(){
$('.msg').hide();
}, 5000);
}
});
},
getStatus = function(){
$.when(
$.ajax( {
url:'<%=luci.dispatcher.build_url("api", "xqsystem", "mode")%>',
data: {},
dataType: "json"
}),
$.ajax( {
url: '<%=luci.dispatcher.build_url("api", "xqdatacenter", "request")%>',
data: {'payload':'{"api":41}'},
dataType: "json"
})
).done(function( rsp1, rsp2 ) {
if (rsp1[0].code == 0 && rsp2[0].code == 0){
if (rsp1[0].mode == 1) {
$('#guestnet').attr('data-status', 'enabled');
$('#guestnet')[0].className = 'btn-offon btn-on';
}else{
$('#guestnet').attr('data-status', 'disabled');
$('#guestnet')[0].className = 'btn-offon btn-off';
}
if (rsp2[0].readonly == true) {
$('#guestdata').attr('data-status', 'enabled');
$('#guestdata')[0].className = 'btn-offon btn-on';
}else{
$('#guestdata').attr('data-status', 'disabled');
$('#guestdata')[0].className = 'btn-offon btn-off';
}
}else{
setTimeout(function(){
getStatus();
}, 200);
}
});
};
getStatus();
$('body').delegate('#guestnet', 'click', function(e){
e.preventDefault();
if ($(this).attr('data-status') == 'enabled') {
gutstDisableNet();
}
if ($(this).attr('data-status') == 'disabled') {
guestEnableNet();
}
});
$('body').delegate('#guestdata', 'click', function(e){
e.preventDefault();
if ($(this).attr('data-status') == 'enabled') {
gutstDisableData();
}
if ($(this).attr('data-status') == 'disabled') {
guestEnableData();
}
});
});
$(function(){
$(global_event).trigger('plugin:guestOpen');
});
</script>
</body>
</html>