Commit b367419e authored by 蒋林's avatar 蒋林

评论列表显示

parent 887a7783
......@@ -12,8 +12,6 @@ $mod = isset($_GET['mod']) ? $_GET['mod']: '';
$newsid = isset($_POST['newsid']) ? intval($_POST['newsid']) : 0;
$content = isset($_POST['content']) ? addslashes(trim($_POST['content'])) : '';
$plid = isset($_POST['plid']) ? intval($_POST['plid']) : 0;
$page = isset($_POST['p']) ? intval($_POST['p']) : 0;
$page = $page ? : 1;
if ($mod == 'create') {
if (!$iscas) {
......@@ -52,8 +50,9 @@ if ($mod == 'create') {
if (!$newsid) {
returnmsg(false, '内容ID参数错误');
}
$lastplid = intval($_POST['lastplid']);
comments($newsid,10, $page);
comments($newsid, $lastplid, 10);
}
//创建评论
......@@ -114,13 +113,17 @@ function replyComment($plid, $content) {
}
//评论列表
function comments($newsid, $num, $p=1) {
function comments($newsid, $plid=0, $num=10) {
global $empire,$dbtbpre;
$tablecomment = $dbtbpre.'ecms_comments';
$tablemember = $dbtbpre.'enewsmember';
$offset = ($p - 1) * $num;
$sql = "select c.*,u.avatar,u.nickname,u.username from $tablecomment c left join {$tablemember} u on c.user_id=u.userid where newsid={$newsid} and c.reply_id=0 order by c.id desc limit {$offset},{$num}";
$where = '';
if ($plid) {
$where = "c.id<{$plid} and ";
}
$sql = "select c.*,u.avatar,u.nickname,u.username from $tablecomment c left join {$tablemember} u on c.user_id=u.userid where {$where} c.newsid={$newsid} and c.reply_id=0 order by c.id desc limit {$num}";
$query = $empire->query($sql);
$list = [];
......
......@@ -35,7 +35,9 @@ $(".send-pl").click(function () {
});
function comments(newsid) {
$.post("/e/action/news/comment.php", {newsid: newsid}, function (e) {
var lastplid = $(".comment-list li:last-child").attr('data-id');
lastplid = lastplid ? lastplid : 0;
$.post("/e/action/news/comment.php", {newsid: newsid, lastplid: lastplid}, function (e) {
if (!$.isEmptyObject(e.data)) {
var comments = e.data;
var html = '';
......@@ -155,7 +157,6 @@ function pop(msg, islogin) {
layer.msg(msg);
}
var currentPage = 1;
var isLoading = false;
var scrollLoad = $("#scrollLoad");
var spinner = "/skin/default/images/spinner-rosetta-blue-26x26.gif";
......@@ -169,9 +170,10 @@ function scrollLoading() {
if (!isLoading) {
isLoading = true;
var nextPage = currentPage + 1;
var lastplid = $(".comment-list li:last-child").attr('data-id');
lastplid = lastplid ? lastplid : 0;
scrollLoad.html("<img src='" + spinner + "'>");
$.post("/e/action/news/comment.php", {newsid: newsid, p:currentPage}, function (e) {
$.post("/e/action/news/comment.php", {newsid:newsid, lastplid:lastplid}, function (e) {
if (!$.isEmptyObject(e.data)) {
var comments = e.data;
var html = '';
......@@ -179,7 +181,6 @@ function scrollLoading() {
html += tpl(comments[i]);
}
$(".comment-list").append(html);
currentPage = nextPage;
} else {
scrollLoad.html("全部加载完毕");
$(window).off("scroll", scrollLoading);
......@@ -195,6 +196,7 @@ function scrollLoading() {
}
if (scrollLoad.length > 0) {
comments();
$(window).on("scroll", scrollLoading);
scrollLoading();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment