Skip to content

Instantly share code, notes, and snippets.

@linkimfly
Last active February 8, 2021 15:23
Show Gist options
  • Save linkimfly/5952575bc484ebd2f2fece3f853f4cf4 to your computer and use it in GitHub Desktop.
Save linkimfly/5952575bc484ebd2f2fece3f853f4cf4 to your computer and use it in GitHub Desktop.
宝塔面板网站管理增强
var site_table = bt_tools.table({
el:'#bt_site_table',
url:'/data?action=getData',
param:{table:'sites'}, //参数
minWidth:'1000px',
autoHeight:true,
default:"站点列表为空",//数据为空时的默认提示
beforeRequest:function(param){
param.type = bt.get_cookie('site_type') || -1;
return param;
},
column:[
{type:'checkbox',class:'',width:20},
{fid:'id',title:'id',template:function(row,index){
return row.id;
}},
{fid:'name',title:'网站名',sort:true,sortValue:'asc',type:'link',event:function(row,index,ev){
site.web_edit(row,true);
}},
{fid:'status',title:'状态',sort:true,width:80,config:{icon:true,list:[['1','运行中','bt_success','glyphicon-play'],['0','已停止','bt_danger','glyphicon-pause']]},type:'status',event:function(row,index,ev,key,that){
var time = row.edate || row.endtime;
if(time != "0000-00-00"){
if(new Date(time).getTime() < new Date().getTime()){
layer.msg('当前站点已过期,请重新设置站点到期时间',{icon:2});
return false;
}
}
bt.site[parseInt(row.status)?'stop':'start'](row.id,row.name,function(res){
if(res.status) that.$modify_row_data({status:parseInt(row.status)?'0':'1'});
});
}},
{fid:'backup_count',title:'备份',width:80,type:'link',template:function(row,index){
var backup = lan.site.backup_no,_class = "bt_warning";
if (row.backup_count > 0) backup = lan.site.backup_yes,_class = "bt_success";
return '<a href="javascript:;" class="btlink '+ _class +'">'+ backup + (row.backup_count >0?('('+ row.backup_count +')'):'') +'</a>';
},event:function(row,index){
site.backup_site_view({id:row.id,name:row.name});
}},
{fid:'path',title:'根目录',tips:'打开目录',type:'link',event:function(row,index,ev){
openPath(row.path);
}},
{fid:'edate',title:'到期时间',width:85,class:'set_site_edate',sort:true,type:'link',template:function(row,index){
var _endtime = row.edate || row.endtime;
if(_endtime === "0000-00-00"){
return lan.site.web_end_time;
}else{
if(new Date(_endtime).getTime() < new Date().getTime()){
return '<a href="javscript:;" class="bt_danger">已过期</a>';
}else{
return _endtime;
}
}
},event:function(row){}}, //模拟点击误删
{fid:'ps',title:'备注',type:'input',blur:function(row,index,ev,key,that){
if(row.ps == ev.target.value) return false;
bt.pub.set_data_ps({id:row.id,table:'sites',ps:ev.target.value},function(res){
bt_tools.msg(res,{is_dynamic:true});
});
},keyup:function(row,index,ev){
if(ev.keyCode === 13){
$(this).blur();
}
}},
{fid:'php_version',title:'PHP',tips:'选择php版本',width:50,type:'link',template:function(row,index){
if(row.php_version.indexOf('静态') > -1) return row.php_version;
return row.php_version;
},event:function(row,index){
site.web_edit(row);
setTimeout(function(){
$('.site-menu p:eq(9)').click();
},500);
}},
{fid:'ssl',title:'SSL证书',tips:'部署证书',width:100,type:'text',template:function(row,index){
var _ssl = row.ssl,_info = '',_arry = [['issuer','证书品牌'],['notAfter','到期日期'],['notBefore','申请日期'],['dns','可用域名']];
try {
if(typeof row.ssl.endtime != 'undefined'){
if(row.ssl.endtime < -7){
return '<a class="btlink bt_warning" href="javascript:;">未部署</a>';
}else if(row.ssl.endtime < 0 && row.ssl.endtime > -7){
return '<a class="btlink bt_danger" href="javascript:;">已过期'+ Math. row.ssl.endtime +'天</a>';
}
}
} catch (error){}
for(var i=0;i<_arry.length;i++){
var item = _ssl[_arry[i][0]];
_info += _arry[i][1]+':'+ item + (_arry.length-1 != i?'\n':'');
}
return row.ssl === -1?'<a class="btlink bt_warning" href="javascript:;">未部署</a>':'<a class="btlink '+ (row.ssl.endtime < 7?'bt_danger':'') +'" href="javascript:;" title="'+ _info +'">剩余'+ row.ssl.endtime +'天</a>';
},event:function(row,index,ev,key,that){
site.web_edit(row);
setTimeout(function(){
$('.site-menu p:eq(8)').click();
},500);
}},
{title:'操作',type:'group',width:150,align:'right',group:[{
title:'防火墙',
event:function(row,index,ev,key,that){
site.site_waf(row.name);
}
},{
title:'设置',
event:function(row,index,ev,key,that){
site.web_edit(row,true);
}
},{
title:'删除',
event:function(row,index,ev,key,that){
site.del_site(row.id,row.name,function(){
that.$refresh_table_list(true);
});
}
}]}
],
sortParam:function(data){
return {'order':data.name +' '+ data.sort};
},
// 表格渲染完成后
success:function(that){
$('.event_edate_'+ that.random).each(function(){
var $this = $(this);
laydate.render({
elem: $this[0] //指定元素
, min: bt.get_date(1)
, max: '2099-12-31'
, vlue: bt.get_date(365)
, type: 'date'
, format: 'yyyy-MM-dd'
, trigger: 'click'
, btns: ['perpetual', 'confirm']
, theme: '#20a53a'
, ready:function(){
$this.click();
}
, done: function (date) {
var item = that.event_rows_model.rows;
bt.site.set_endtime(item.id, date,function(res){
if(res.status){
layer.msg(res.msg);
return false;
}
bt.msg(res);
});
}
});
});
},
// 渲染完成
tootls:[{ // 按钮组
type:'group',
positon:['left','top'],
list:[
{title:'添加站点',active:true, event:function(ev){ site.add_site(function(){
site_table.$refresh_table_list(true) });
bt.set_cookie('site_type','-1');
}},
{title:'修改默认页',event:function(ev){ site.set_default_page() }},
{title:'默认站点',event:function(ev){ site.set_default_site() }},
{title:'PHP命令行版本',event:function(ev){ site.get_cli_version()}}
]
},{ // 搜索内容
type:'search',
positon:['right','top'],
placeholder:'请输入域名或备注',
searchParam:'search', //搜索请求字段,默认为 search
value:'',// 当前内容,默认为空
},{ // 批量操作
type:'batch',//batch_btn
positon:['left','bottom'],
placeholder:'请选择批量操作',
buttonValue:'批量操作',
disabledSelectValue:'请选择需要批量操作的站点!',
selectList:[
{
group:[{title:'开启站点',param:{status:1}},{title:'停止站点',param:{status:0}}],
url:'/site?action=set_site_status_multiple',
confirmVerify:false, //是否提示验证方式
paramName:'sites_id', //列表参数名,可以为空
paramId:'id', // 需要传入批量的id
theadName:'站点名称',
refresh:true
},{
title:"备份站点",
url:'/site?action=ToBackup',
paramId:'id',
load:true,
theadName:'站点名称',
refresh:true,
callback:function(that){ // 手动执行,data参数包含所有选中的站点
that.start_batch({},function(list){
var html = '';
for(var i=0;i<list.length;i++){
var item = list[i];
html += '<tr><td><span>'+ item.name +'</span></td><td><div style="float:right;"><span style="color:'+ (item.request.status?'#20a53a':'red') +'">'+ item.request.msg +'</span></div></td></tr>';
}
site_table.$batch_success_table({title:'批量备份',th:'站点名称',html:html});
site_table.$refresh_table_list(true);
});
}
},{
title:"设置到期时间",
url:'/site?action=set_site_etime_multiple',
paramName:'sites_id', //列表参数名,可以为空
paramId:'id', // 需要传入批量的id
theadName:'站点名称',
refresh:true,
confirm:{
title:'批量设置到期时间',
content:'<div class="line"><span class="tname">到期时间</span><div class="info-r "><input name="edate" id="site_edate" class="bt-input-text mr5" placeholder="yyyy-MM-dd" type="text"></div></div>',
success:function(){
laydate.render({
elem: '#site_edate'
,min: bt.format_data(new Date().getTime(),'yyyy-MM-dd')
,max: '2099-12-31'
,vlue: bt.get_date(365)
,type: 'date'
,format: 'yyyy-MM-dd'
,trigger: 'click'
,btns: ['perpetual','confirm']
,theme: '#20a53a'
});
},
yes:function(index,layers,request){
var site_edate = $('#site_edate'),site_edate_val = site_edate.val();
if(site_edate_val != ''){
if(new Date(site_edate_val).getTime() < new Date().getTime()){
layer.tips('设置的到期时间不得小于当前时间','#site_edate',{tips:['1','red']});
return false;
}
request({'edate':site_edate_val==='永久'?'0000-00-00':site_edate_val});
}else{
layer.tips('请输入到期时间','#site_edate',{tips:['1','red']});
$('#site_edate').css('border-color','red');
$('#site_edate').click();
setTimeout(function(){
$('#site_edate').removeAttr('style');
},3000);
return false;
}
}
}
},{
title:"设置PHP版本",
url:'/site?action=set_site_php_version_multiple',
paramName:'sites_id', //列表参数名,可以为空
paramId:'id', // 需要传入批量的id
theadName:'站点名称',
refresh:true,
confirm:{
title:'批量设置PHP版本',
area:'420px',
content:'<div class="line"><span class="tname">PHP版本</span><div class="info-r"><select class="bt-input-text mr5 versions" name="versions" style="width:150px"></select></span></div><ul class="help-info-text c7" style="font-size:11px"><li>请根据您的程序需求选择版本</li><li>若非必要,请尽量不要使用PHP5.2,这会降低您的服务器安全性;</li><li>PHP7不支持mysql扩展,默认安装mysqli以及mysql-pdo。</li></ul></div>',
success:function(res,list,that){
bt.site.get_all_phpversion(function(res){
var html = '';
$.each(res,function(index,item){
html += '<option value="'+ item.version +'">'+ item.name +'</option>';
});
$('[name="versions"]').html(html);
});
},
yes:function(index,layers,request){
request({version:$('[name="versions"]').val()});
}
}
},{
title:"设置分类",
url:'/site?action=set_site_type',
paramName:'site_ids', //列表参数名,可以为空
paramId:'id', // 需要传入批量的id
refresh:true,
beforeRequest:function(list){
var arry = [];
$.each(list,function(index,item){
arry.push(item.id);
});
return JSON.stringify(arry);
},
confirm:{
title:'批量设置分类',
content:'<div class="line"><span class="tname">站点分类</span><div class="info-r"><select class="bt-input-text mr5 site_types" name="site_types" style="width:150px"></select></span></div></div>',
success:function(){
bt.site.get_type(function(res){
var html = '';
$.each(res,function(index,item){
html += '<option value="'+ item.id +'">'+ item.name +'</option>';
});
$('[name="site_types"]').html(html);
});
},
yes:function(index,layers,request){
request({id:$('[name="site_types"]').val()});
}
},
tips:false,
success:function(res,list,that){
var html = '';
$.each(list,function(index,item){
html += '<tr><td>'+ item.name +'</td><td><div style="float:right;"><span style="color:'+ (res.status?'#20a53a':'red') +'">'+ res.msg +'</span></div></td></tr>';
});
that.$batch_success_table({title:'批量设置分类',th:'站点名称',html:html});
that.$refresh_table_list(true);
}
},{
title:"删除站点",
url:'/site?action=delete_website_multiple',
paramName:'sites_id', //列表参数名,可以为空
paramId:'id', //需要传入批量的id
theadName:'站点名称',
refresh:true,
confirm:function(config,callback){
bt.show_confirm("批量删除站点","是否同时删除选中站点同名的FTP、数据库、根目录", function(){
var param = {};
$('.bacth_options input[type=checkbox]').each(function(){
var checked = $(this).is(":checked");
if(checked) param[$(this).attr('name')] = checked?1:0;
})
if(callback) callback(param);
},"<div class='options bacth_options'><span class='item'><label><input type='checkbox' name='ftp'><span>FTP</span></label></span><span class='item'><label><input type='checkbox' name='database'><span>" + lan.site.database + "</span></label></span><span class='item'><label><input type='checkbox' name='path'><span>" + lan.site.root_dir + "</span></label></span></div>");
}
}
],
},{ //分页显示
type:'page',
positon:['right','bottom'], // 默认在右下角
pageParam:'p', //分页请求字段,默认为 : p
page:1, //当前分页 默认:1
numberParam:'limit', //分页数量请求字段默认为 : limit
number:20, //分页数量默认 : 20条
numberList:[10,20,50,100,200], // 分页显示数量列表
numberStatus:true, // 是否支持分页数量选择,默认禁用
jump:true, //是否支持跳转分页,默认禁用
}]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment