增加 链接排序和批量操作

This commit is contained in:
LyLme 2022-05-12 02:17:40 +08:00
parent 72db086839
commit b0abfc39b8
4 changed files with 329 additions and 69 deletions

77
admin/ajax_link.php Normal file
View File

@ -0,0 +1,77 @@
<?php
include_once("../include/common.php");
if(isset($islogin)==1) {
} else exit("<script language='javascript'>window.location.href='./login.php';</script>");
$submit = isset($_GET['submit']) ? $_GET['submit'] : null;
switch($submit) {
//修改分组
case 'set_group':
foreach($_POST['links'] as $lk=> $lv) {
$sql = "UPDATE `lylme_links` SET `group_id` = '".$_POST['group_id']."' WHERE `lylme_links`.`id` = ".$lv.";";
$DB->query($sql);
}
break;
case 'allorder':
//拖拽排序
for ($i=0; $i<count($_POST["link_array"]); $i++) {
$sql = "UPDATE `lylme_links` SET `link_order` = '".$i."' WHERE `lylme_links`.`id` = ".$_POST["link_array"][$i].";";
$DB->query($sql);
}
break;
case 'on':
//链接启用
foreach($_POST['links'] as $lk=> $lv) {
$sql = "UPDATE `lylme_links` SET `link_status` = '1' WHERE `lylme_links`.`id` = ".$lv.";";
$DB->query($sql);
}
break;
case 'off':
//链接禁用
foreach($_POST['links'] as $lk=> $lv) {
$sql = "UPDATE `lylme_links` SET `link_status` = '0' WHERE `lylme_links`.`id` = ".$lv.";";
$DB->query($sql);
}
break;
case 'del':
//链接删除
foreach($_POST['links'] as $lk=> $lv) {
$sql = "DELETE FROM `lylme_links` WHERE `lylme_links`.`id` = ".$lv.";";
$DB->query($sql);
}
break;
//获取链接信息
case 'geturl':
function get_head($url) {
ini_set("user_agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36 Edg/101.0.1210.39 Lylme/11.24");
$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=>4
)
);
$contents = @file_get_contents("compress.zlib://".$url, false, stream_context_create($opts));
preg_match('/<title>(.*?)<\/title>/is',$contents,$title); // 获取网站标题
preg_match('/<link rel=".*?icon" * href="(.*?)".*?>/is', $contents,$icon); // 获取网站icon
preg_match('/<meta.+?charset=[^\w]?([-\w]+)/i', $contents,$charset); //获取网站编码
$get_heads = array();
$get_heads['charset']=$charset[1];
$get_heads['title'] = str_replace("'","\"",preg_replace("/\s/","",$title[1]));
$get_heads['icon'] = get_urlpath(preg_replace("/\s/","",$icon[1]),$url);
if(strtolower($get_heads['charset'])!="uft-8"){
// 将非UTF-8编码转换
$get_heads['title'] = iconv($get_heads['charset'], "UTF-8",$get_heads['title']);
$get_heads['icon'] = iconv($get_heads['charset'], "UTF-8",$get_heads['icon']);
}
return $get_heads;
}
$head = get_head($_POST['url']);
if(empty($head['title'])&&empty($head['icon']))exit('Unable to access');
header('Content-Type:application/json');
exit('{"title": "'.$head['title'].'", "icon": "'.$head['icon'].'","charset": "'.$head['charset'].'"}');
break;
default:
exit('error');
break;
}

View File

@ -22,6 +22,7 @@ function listTable(query){
},
error:function(data){
layer.msg('服务器错误');
lightyear.loading('hide');
return false;
}
});
@ -34,7 +35,6 @@ $(document).ready(function(){
}
});
//获取选中
function get_check(){
var chk_value =[];
@ -44,29 +44,8 @@ function get_check(){
return chk_value;
}
//点击排序
function sort(id,order,gid){
lightyear.loading('show');
$.ajax({
url:"ajax_link.php?submit=order",
method:"POST",
data:{id:id,order:order,gid:gid},
success:function(data){
console.log(data);
lightyear.loading('hide');
lightyear.notify('操作成功!', 'success', 1000);
listTable();
return true;
},
error:function(data){
layer.msg('服务器错误');
return false;
}
});
}
//多选启用
function on_link(){
//多选启用
if(get_check().length == 0){
$.alert("未选择链接");
return false;
@ -77,7 +56,6 @@ function on_link(){
method:"POST",
data:{links:get_check()},
success:function(data){
console.log(data);
lightyear.loading('hide');
lightyear.notify('操作成功!', 'success', 1000);
listTable();
@ -85,12 +63,14 @@ function on_link(){
},
error:function(data){
layer.msg('服务器错误');
lightyear.loading('hide');
return false;
}
});
}
//多选禁用
function off_link(){
//多选禁用
if(get_check().length == 0){
$.alert("未选择链接");
return false;
@ -101,7 +81,6 @@ function off_link(){
method:"POST",
data:{links:get_check()},
success:function(data){
console.log(data);
lightyear.loading('hide');
lightyear.notify('操作成功!', 'success', 1000);
listTable();
@ -109,17 +88,51 @@ function off_link(){
},
error:function(data){
layer.msg('服务器错误');
lightyear.loading('hide');
return false;
}
});
}
//获取网站信息
function geturl(){
var url = $("input[name=\'url\']").val();
if(!url){
layer.msg('链接地址不能为空');
return false;
}
lightyear.loading("show");
if (!/^http[s]?:\/\/+/.test(url)&&url!="") {
var url = "http://"+url;
$("input[name=\'url\']").val(url);
}
$.ajax({
url:"ajax_link.php?submit=geturl",
type:"post",
dataType:"json",
data:{url:url},
success:function(data){
lightyear.loading("hide");
var head = eval(data);
$("input[name=\'name\']").val(head.title);
if(!head.icon){
layer.msg('未获取到网站图标');
}
$("textarea[name=\'icon\']").val(head.icon);
return true;
},
error:function(data){
lightyear.loading('hide');
layer.msg('获取失败,网站无法访问或防火墙限制!');
return false;
}
});
}
//多选删除
function del_link(id){
//多选删除
var link_id = [];
link_id.push(id);
link_id = id ? link_id :get_check();
console.log(link_id);
if(link_id.length == 0){
$.alert("未选择链接");
return false;
@ -140,17 +153,16 @@ function del_link(id){
links:link_id
},
success:function(data){
console.log(data);
lightyear.loading('hide');
lightyear.notify('操作成功!', 'success', 1000);
listTable();
return true;
}
});
},
error:function(data){
layer.msg('服务器错误');
lightyear.loading('hide');
return false;
}
},
@ -196,6 +208,75 @@ function save_order(){
url:"ajax_link.php?submit=allorder",
method:"POST",
data:{link_array:link_array},
success:function(data){
lightyear.loading('hide');
lightyear.notify('操作成功!', 'success', 1000);
listTable();
return true;
},
error:function(data){
layer.msg('服务器错误');
lightyear.loading('hide');
return false;
}
});
}
//点击排序
$(document).on('click', '.sort-up', function(){
//上移一行
if($(this).parents('tr').prevAll().length > 0){
$(this).parents('tr').prev().before($(this).parents('tr').prop('outerHTML'));
$(this).parents('tr').remove();
save_order();
}
}).on('click', '.sort-down', function(){
//下移一行
if($(this).parents('tr').nextAll().length > 0){
$(this).parents('tr').next().after($(this).parents('tr').prop('outerHTML'));
$(this).parents('tr').remove();
save_order();
}
}).on('click', '.sort-goup', function(){
//移到顶部
if($(this).parents('tr').prevAll().length > 0){
$(this).parents('tbody').children("tr:first-child").before($(this).parents('tr').prop('outerHTML'));
$(this).parents('tr').remove();
save_order();
}
}).on('click', '.sort-godown', function(){
//移到底部
if($(this).parents('tr').nextAll().length > 0){
$(this).parents('tbody').children("tr:last-child").after($(this).parents('tr').prop('outerHTML'));
$(this).parents('tr').remove();
save_order();
}
})
//移到分组
function edit_group(mv_group) {
if(get_check().length == 0){
$.alert("未选择链接");
return false;
}
$.confirm({
title: '移动分组',
content: mv_group,
buttons: {
formSubmit: {
text: '移动',
btnClass: 'btn-blue',
action: function () {
var group_id = this.$content.find('.group_id').val();
if(!group_id){
$.alert('未选择');
return false;
}
lightyear.loading('show');
$.ajax({
url:"ajax_link.php?submit=set_group",
method:"POST",
data:{links:get_check(),group_id:group_id},
success:function(data){
console.log(data);
lightyear.loading('hide');
@ -208,4 +289,31 @@ function save_order(){
return false;
}
});
}
}
},
cancel: {
text: '取消'
},
}
});
};
//点击排序(弃用)
// function sort(id,mod,gid){
// lightyear.loading('show');
// $.ajax({
// url:"ajax_link.php?submit=order",
// method:"POST",
// data:{id:id,mod:mod,gid:gid},
// success:function(data){
// lightyear.loading('hide');
// lightyear.notify('操作成功!', 'success', 1000);
// listTable();
// return true;
// },
// error:function(data){
// layer.msg('服务器错误');
// lightyear.loading('hide');
// return false;
// }
// });
// }

View File

@ -18,16 +18,20 @@ if ($set == 'add') {
<div class="panel-body">
<form action="./link.php?set=add_submit" method="POST">
<div class="form-group">
<label>*名称:</label><br>
<input type="text" class="form-control" name="name" value="" required>
</div>
<label>*URL链接地址:</label>
<div class="input-group">
<input type="text" class="form-control" name="url" placeholder="链接" value="" required>
<span class="input-group-btn">
<button class="btn btn-default" onclick="geturl()" type="button">获取</button>
</span>
</div></div>
<div class="form-group">
<label>*URL链接地址:</label><br>
<input type="text" class="form-control" name="url" value="" required>
<label>*网站名称:</label><br>
<input type="text" class="form-control" placeholder="网站名称" name="name" value="" required>
</div>
<div class="form-group">
<label>链接图标:</label><br>
<textarea type="text" class="form-control" name="icon"></textarea>
<textarea type="text" class="form-control" name="icon" placeholder="网站图标"></textarea>
<small class="help-block">方式1填写图标的<code>URL</code>地址,如<code>/img/logo.png</code><code>http://www.xxx.com/img/logo.png</code><br>
方式2粘贴图标的<code>SVG</code>代码,<a href="./help.php?doc=icon" target="_blank">查看教程</a><br>方式3留空使用默认图标</small>
</div>
@ -56,12 +60,16 @@ if ($set == 'add') {
<div class="panel-body">
<form action="./link.php?set=edit_submit&id=' . $id . '" method="POST">
<div class="form-group">
<label>*名称:</label><br>
<input type="text" class="form-control" name="name" value="' . $row['name'] . '" required>
</div>
<label>*URL链接地址:</label>
<div class="input-group">
<input type="text" class="form-control" name="url" placeholder="链接" value="' . $row['url'] . '" required>
<span class="input-group-btn">
<button class="btn btn-default" onclick="geturl()" type="button">获取</button>
</span>
</div></div>
<div class="form-group">
<label>*链接URL地址:</label><br>
<input type="text" class="form-control" name="url" value="' . $row['url'] . '" required>
<label>*网站名称:</label><br>
<input type="text" class="form-control" name="name" value="' . $row['name'] . '" required>
</div>
<div class="form-group">
<label>链接图标:</label><br>
@ -118,29 +126,13 @@ if ($set == 'add') {
if ($DB->query($sql)) echo '<script>alert("修改链接 ' . $name . ' 成功!");window.location.href="./link.php";</script>';
else echo '<script>alert("修改链接失败!");history.go(-1);</script>';
}
} elseif ($set == 'delete') {
$id = $_GET['id'];
$sql = "DELETE FROM lylme_links WHERE id='$id'";
if ($DB->query($sql)) echo '<script>alert("删除成功!");window.location.href="./link.php";</script>';
else echo '<script>alert("删除失败!");history.go(-1);</script>';
// } elseif ($set == 'delete') {
// $id = $_GET['id'];
// $sql = "DELETE FROM lylme_links WHERE id='$id'";
// if ($DB->query($sql)) echo '<script>alert("删除成功!");window.location.href="./link.php";</script>';
// else echo '<script>alert("删除失败!");history.go(-1);</script>';
} else {
echo '<div class="alert alert-info">系统共有 <b>' . $linksrows . '</b> 个链接<br/><a href="./link.php?set=add" class="btn btn-primary">新增链接</a></div>
<div class="table-responsive">
<table class="table table-striped">
<thead><tr><th>序号</th><th>名称</th><th>链接</th><th>分组</th><th>操作</th></tr></thead>
<tbody>';
$i = 0;
$rs = $DB->query("SELECT * FROM `lylme_links` ORDER BY `lylme_links`.`id` ASC");
while ($res = $DB->fetch($rs)) {
$i = $i + 1;
echo '<tr><td><b>' . $i . '</b></td><td>' . $res['name'] . '</td><td>' . $res['url'] . '</td><td>';
echo $DB->fetch($DB->query("SELECT * FROM `lylme_groups` WHERE `group_id` = " . $res['group_id'])) ["group_name"];
echo '</td><td><a href="./link.php?set=edit&id=' . $res['id'] . '" class="btn btn-info btn-xs">编辑</a>&nbsp;<a href="./link.php?set=delete&id=' . $res['id'] . '" class="btn btn-xs btn-danger" onclick="return confirm(\'删除 ' . $res['name'] . ' \');">删除</a></td></tr>';
}
?>
</tbody>
</table>
</div>
echo '<div id="listTable"></div>
</div>
</div>
</div>
@ -150,7 +142,21 @@ if ($set == 'add') {
</div>
</main>
<?php
';
}
include './footer.php';
?>
<script type="text/javascript" src="js/jquery.dragsort-0.5.2.min.js"></script>
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery-confirm/3.3.0/jquery-confirm.min.css" type="text/css" rel="stylesheet" />
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/layer/3.1.1/layer.min.js" type="application/javascript"></script>
<script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery-confirm/3.3.0/jquery-confirm.min.js" type="application/javascript"></script>
<!--消息提示-->
<script src="js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="js/lightyear.js"></script>
<script type="text/javascript" src="js/link.js"></script>
<script type="text/javascript">
var mv_group ='<form action="" class="formName">' + '<select class="form-control group_id" required>'+'<?php while ($grouplist = $DB->fetch($grouplists)) {
if ($grouplist["group_id"] == $row['group_id']) { $select = 'selected="selected"';} else {$select = '';}
echo '<option value="' . $grouplist["group_id"] . '">' . $grouplist["group_id"] . ' - ' . $grouplist["group_name"] . '</option>';}?>'+ '</select>';
</script>

69
admin/table_link.php Normal file
View File

@ -0,0 +1,69 @@
<?php
include_once("../include/common.php");
if(isset($islogin)==1) {
} else exit("<script language='javascript'>window.location.href='./login.php';</script>");
$page = isset($_GET['page'])? $_GET['page'] : 1;
$groups = $DB->query("SELECT * FROM `lylme_groups` ORDER BY `group_order` ASC"); //获取分组
$rs = $DB->query("SELECT * FROM `lylme_links` WHERE `group_id` = ".$page." ORDER BY `lylme_links`.`id` ASC"); //获取链接
$grouprows=$DB->num_rows($rs);
echo '<div class="alert alert-info">系统收录: <b>' . $linksrows . '</b> 个链接 / 当前分组: <b>'.$grouprows.'</b>个链接
</div>
<nav><ul class="pagination">';
while ($group = $DB->fetch($groups)) {
echo '<li ';
if($page ==$group["group_id"]){echo 'class="active"';}
echo '><a href="?page='.$group["group_id"].'">'.$group["group_name"].'</a></li>';
}
echo '</ul>
</nav>
<!-- 功能按钮 S-->
<div id="toolbar" class="toolbar-btn-action">
<a href="./link.php?set=add" class="btn btn-primary btn-label">
<label><i class="mdi mdi-plus" aria-hidden="true"></i></label>新增</a>
<button id="btn_edit" type="button" class="btn btn-success btn-label" onclick="on_link()">
<label><i class="mdi mdi-check" aria-hidden="true"></i></label>启用</button>
<button id="btn_edit" type="button" class="btn btn-warning btn-label" onclick="off_link()">
<label><i class="mdi mdi-block-helper" aria-hidden="true"></i></label>禁用 </button>
<button id="btn_delete" type="button" class="btn btn-danger btn-label" onclick="del_link()">
<label><i class="mdi mdi-window-close" aria-hidden="true"></i></label>删除</button>
<button id="edit_group" type="button" class="btn btn-info btn-label" onclick="edit_group(mv_group)">
<label><i class="mdi mdi-account-edit" aria-hidden="true"></i></label>移动</button>
<button class="btn btn-label btn btn-purple" id="save_order" style="display:none" onclick="save_order()">
<label><i class="mdi mdi-checkbox-marked-circle-outline"></i></label> 保存排序</button>
</div>
<!-- 功能按钮 E -->
<div class="table-responsive">
<table class="table table-striped" id="classlisttbody">
<thead><tr style="cursor: pointer">
<th><input type="checkbox" class="checkbox-parent" id="check_all" onclick="check_all()"></th>
<th>排序</th><th>名称</th><th>链接</th><th>分组</th><th>启用</th><th>操作</th></tr></thead>
<tbody id="link">';
$rs = $DB->query("SELECT * FROM `lylme_links` WHERE `group_id` = ".$page." ORDER BY `lylme_links`.`link_order` ASC");
while ($res = $DB->fetch($rs)) {
echo '<tr><td><input type="checkbox" name="link-check" value="'.$res['id'].'"></td>
<!-- 链接排序 S -->
<td><a class="btn btn-success btn-xs sort-goup" data-toggle="tooltip" data-placement="top" title="移到顶部"><i class="mdi mdi-arrow-collapse-up"></i></a>
<a class="btn btn-info btn-xs sort-godown" data-toggle="tooltip" data-placement="top" title="移到底部"><i class="mdi mdi-arrow-collapse-down"></i></a>
<a class="btn btn-primary btn-xs sort-up" data-toggle="tooltip" data-placement="top" title="移到上一行"><i class="mdi mdi-arrow-up"></i></a>
<a class="btn btn-cyan btn-xs sort-down" data-toggle="tooltip" data-placement="top" title="移到下一行"><i class="mdi mdi-arrow-down"></i></a></td>
<!-- 链接排序 E -->
<td>' . $res['name'] . '</td><td>' . $res['url'] . '</td><td>';
echo $DB->fetch($DB->query("SELECT * FROM `lylme_groups` WHERE `group_id` = " . $res['group_id'])) ["group_name"];
echo '</td>
<td>';
if($res['link_status']=="0"){ echo '<font color="red">禁用</font>';}else{echo '<font color="green">启用</font>';}
$de_llink = "del_link('".$res['id']."')";
echo'</td>
<td><a href="./link.php?set=edit&id=' . $res['id'] . '" class="btn btn-info btn-primary">编辑</a>&nbsp;<button class="btn btn-primary btn-danger" onclick="'.$de_llink.'">删除</button></td></tr>';
;
}
echo '
</tbody>
</table>
</div>
</div>';
?>