Commit b367419e authored by 蒋林's avatar 蒋林

评论列表显示

parent 887a7783
...@@ -12,8 +12,6 @@ $mod = isset($_GET['mod']) ? $_GET['mod']: ''; ...@@ -12,8 +12,6 @@ $mod = isset($_GET['mod']) ? $_GET['mod']: '';
$newsid = isset($_POST['newsid']) ? intval($_POST['newsid']) : 0; $newsid = isset($_POST['newsid']) ? intval($_POST['newsid']) : 0;
$content = isset($_POST['content']) ? addslashes(trim($_POST['content'])) : ''; $content = isset($_POST['content']) ? addslashes(trim($_POST['content'])) : '';
$plid = isset($_POST['plid']) ? intval($_POST['plid']) : 0; $plid = isset($_POST['plid']) ? intval($_POST['plid']) : 0;
$page = isset($_POST['p']) ? intval($_POST['p']) : 0;
$page = $page ? : 1;
if ($mod == 'create') { if ($mod == 'create') {
if (!$iscas) { if (!$iscas) {
...@@ -52,8 +50,9 @@ if ($mod == 'create') { ...@@ -52,8 +50,9 @@ if ($mod == 'create') {
if (!$newsid) { if (!$newsid) {
returnmsg(false, '内容ID参数错误'); returnmsg(false, '内容ID参数错误');
} }
$lastplid = intval($_POST['lastplid']);
comments($newsid,10, $page); comments($newsid, $lastplid, 10);
} }
//创建评论 //创建评论
...@@ -114,13 +113,17 @@ function replyComment($plid, $content) { ...@@ -114,13 +113,17 @@ function replyComment($plid, $content) {
} }
//评论列表 //评论列表
function comments($newsid, $num, $p=1) { function comments($newsid, $plid=0, $num=10) {
global $empire,$dbtbpre; global $empire,$dbtbpre;
$tablecomment = $dbtbpre.'ecms_comments'; $tablecomment = $dbtbpre.'ecms_comments';
$tablemember = $dbtbpre.'enewsmember'; $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); $query = $empire->query($sql);
$list = []; $list = [];
......
...@@ -35,7 +35,9 @@ $(".send-pl").click(function () { ...@@ -35,7 +35,9 @@ $(".send-pl").click(function () {
}); });
function comments(newsid) { 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)) { if (!$.isEmptyObject(e.data)) {
var comments = e.data; var comments = e.data;
var html = ''; var html = '';
...@@ -155,7 +157,6 @@ function pop(msg, islogin) { ...@@ -155,7 +157,6 @@ function pop(msg, islogin) {
layer.msg(msg); layer.msg(msg);
} }
var currentPage = 1;
var isLoading = false; var isLoading = false;
var scrollLoad = $("#scrollLoad"); var scrollLoad = $("#scrollLoad");
var spinner = "/skin/default/images/spinner-rosetta-blue-26x26.gif"; var spinner = "/skin/default/images/spinner-rosetta-blue-26x26.gif";
...@@ -169,9 +170,10 @@ function scrollLoading() { ...@@ -169,9 +170,10 @@ function scrollLoading() {
if (!isLoading) { if (!isLoading) {
isLoading = true; 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 + "'>"); 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)) { if (!$.isEmptyObject(e.data)) {
var comments = e.data; var comments = e.data;
var html = ''; var html = '';
...@@ -179,7 +181,6 @@ function scrollLoading() { ...@@ -179,7 +181,6 @@ function scrollLoading() {
html += tpl(comments[i]); html += tpl(comments[i]);
} }
$(".comment-list").append(html); $(".comment-list").append(html);
currentPage = nextPage;
} else { } else {
scrollLoad.html("全部加载完毕"); scrollLoad.html("全部加载完毕");
$(window).off("scroll", scrollLoading); $(window).off("scroll", scrollLoading);
...@@ -195,6 +196,7 @@ function scrollLoading() { ...@@ -195,6 +196,7 @@ function scrollLoading() {
} }
if (scrollLoad.length > 0) { if (scrollLoad.length > 0) {
comments();
$(window).on("scroll", scrollLoading); $(window).on("scroll", scrollLoading);
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