' +
item.children_count +
"条回复
"
: "";
// JSON.stringify(item).replaceAll("\"", "\'")
$newLi +=
'";
});
return $newLi;
};
// 渲染评论列表-whole
window.renderWholeCommentList = function (res) {
if (typeof res === "string") {
res = JSON.parse(
res
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
.replace(/\\/g, "\\\\")
);
}
let commentsArr = res;
if (platformOs == "androids" || platformOs == "ioses") {
commentsArr = res.result;
}
if (commentsArr.length <= 0) {
let $noComments = $wholeComments.find(".no-comments");
$wholeComments.find(".comment-more").hide();
last_from_pk.whole == 0 ? $noComments.show() : "";
if (Number($wholeComments.find(".title i").text()) >= 1) {
$noComments.find(".tip").text("内容等待审核中");
} else {
$noComments.find(".tip").text("这里还没有新评论~");
}
return false;
} else {
$wholeComments.find(".no-comments").hide();
}
if (commentsArr.length < limitPage) {
$wholeComments.find(".comment-full").show();
$wholeComments.find(".comment-more").hide();
} else {
$wholeComments.find(".comment-full").hide();
$wholeComments.find(".comment-more").show();
}
let $lis = setCommentCon(commentsArr, 0); //父级列表
if (last_from_pk.whole == 0) {
$wholeComments.find(".comment-list").empty(); //清空列表
}
$wholeComments.find(".comment-list").append($lis);
$wholeComments.find("time.timeago").timeago();
last_from_pk.whole = commentsArr.slice(-1)[0].id; //翻页用
isLoadingComment = false; //重置加载状态
};
// 渲染评论列表-hot
window.renderHotCommentList = function (res) {
if (typeof res === "string") {
res = JSON.parse(
res
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
.replace(/\\/g, "\\\\")
);
}
let commentsArr = res;
if (platformOs == "androids" || platformOs == "ioses") {
commentsArr = res.result;
}
if (commentsArr.length > 0) {
// let $noComments = $hotComments.find(".no-comments");
// $hotComments.find('.comment-more').hide();
// last_from_pk.hot == 0 ? $noComments.show() : '';
// if (Number($hotComments.find(".title i").text()) >= 1) {
// $noComments.find(".tip").text("内容等待审核中");
// } else {
// $noComments.find(".tip").text("这里还没有新评论~");
// }
$hotComments.show();
} else {
return false;
}
if (commentsArr.length < limitPage) {
$hotComments.find(".comment-full").show();
$hotComments.find(".comment-more").hide();
} else {
$hotComments.find(".comment-full").hide();
$hotComments.find(".comment-more").show();
}
let $lis = setCommentCon(commentsArr, 0); //父级列表
if (last_from_pk.hot == 0) {
$hotComments.find(".comment-list").empty(); //清空列表
}
$hotComments.find(".comment-list").append($lis);
$hotComments.find("time.timeago").timeago();
last_from_pk.hot = commentsArr.slice(-1)[0].id; //翻页用
isLoadingComment = false; //重置加载状态
};
// 渲染评论详情-查看更多的列表
let $curReply, //当前点击的更多回复按钮
$curReplyCon; //当前更多回复的节点盒子
window.renderCommentReply = function (res) {
if (typeof res === "string") {
res = JSON.parse(
res
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
.replace(/\\/g, "\\\\")
);
}
let replyArr = res;
if (platformOs == "androids" || platformOs == "ioses") {
replyArr = res.result;
}
if (replyArr.children.length == 0) {
if ($curReplyCon.html() == "") {
$curReplyCon.text("内容等待审核中").addClass("no-con");
}
}
$curReply.text("更多回复").addClass("active");
if (replyArr.children.length < limitChildPage) {
$curReply.hide();
}
let $childLis = setCommentCon(replyArr.children, 1); //子级列表
$curReplyCon.append($childLis);
$("time.timeago").timeago();
};
// 获取app评论列表-whole
let getAppWholeComments = function (callback) {
let data = $.extend({}, comParams, {
from_pk: last_from_pk.whole,
num: limitPage,
});
commonJs.callApi("/v2/comments/list/", data, callback);
};
// 获取web评论列表-whole
let getWebWholeComments = function (callback) {
let params = $.extend({}, comParams, {
appid: commonJs.webShareAppid,
from_pk: last_from_pk.whole,
limit: limitPage,
});
commonJs.postRequest(
"/__xh__/interaction-api.gzstv.com/commen-web/comments/list",
params,
renderWholeCommentList
);
};
// 获取app评论列表-hot
let getAppHotComments = function (callback) {
let data = $.extend({}, comParams, {
from_pk: last_from_pk.hot,
num: limitPage,
});
commonJs.callApi("/v2/comments/cream-list/", data, callback);
};
// 获取web评论列表-hot
let getWebHotComments = function (callback) {
let params = $.extend({}, comParams, {
appid: commonJs.webShareAppid,
from_pk: last_from_pk.hot,
limit: limitPage,
});
commonJs.postRequest(
"/__xh__/interaction-api.gzstv.com/commen-web/comments/cream-list",
params,
renderHotCommentList
);
};
// 评论列表的获取 —— app + web
function getallComments(type) {
// 客户端内的处理
if (platformOs == "androids" || platformOs == "ioses") {
if (allowCommentVar == "True" && showCommentsVar == "True") {
type != undefined
? type == "whole"
? getAppWholeComments("renderWholeCommentList")
: getAppHotComments("renderHotCommentList")
: getAppWholeComments("renderWholeCommentList") +
getAppHotComments("renderHotCommentList");
} else {
$(".comments-wrap").remove();
$(".recommend").css("border", "none");
}
}
// 分享页的处理 —— web||wx
else {
if (allowCommentVar == "True") {
type != undefined
? type == "whole"
? getWebWholeComments()
: getWebHotComments()
: getWebWholeComments() + getWebHotComments();
} else {
$(".comments-wrap").remove();
$(".recommend").css("border", "none");
}
}
}
getallComments();
// 刷新评论
let refreshComment = function (type) {
last_from_pk.hot = 0;
last_from_pk.whole = 0;
isAbleComment = true;
// 刷新评论
let timer = setTimeout(() => {
getallComments();
clearTimeout(timer);
if (type == "h5") {
getCommentData(); //分享页-更新底部评论数
}
}, 1000);
};
// 评论列表的操作
$commentsWrap
// 查看更多评论 - 下一页
.on(clickOrTouch, ".comment-more", function (event) {
event.preventDefault();
if(isLoadingComment) return;
isLoadingComment = true;
getallComments($(this).closest(".comments-wrap").data("type"));
})
// 查看评论详情 - 查看回复
.on(clickOrTouch, ".reply-more", function (event) {
event.preventDefault();
event.stopPropagation();
let $thisComment = $(this).closest(".comment-list-item");
$curReplyCon = $thisComment.find(".comment-list-children");
$curReply = $thisComment.find(".reply-more");
let data = {
comment_pk: $thisComment.data("id"),
from_pk:
$curReplyCon.find(".comment-list-item").length <= 0
? 0
: $curReplyCon.children(".comment-list-item").last().data("id"),
num: limitChildPage,
};
if (platformOs == "androids" || platformOs == "ioses") {
commonJs.callApi(
"/v2/comments/children/",
data,
"renderCommentReply"
);
} else {
data.appid = commonJs.webShareAppid;
commonJs.postRequest(
"/__xh__/interaction-api.gzstv.com/commen-web/comments/children",
data,
renderCommentReply
);
}
})
// 评论点赞
.on(clickOrTouch, ".like-btn", function (event) {
event.preventDefault();
event.stopPropagation();
let $this = $(this),
data = {
ctype: $this.data("type"),
object_pk: $this.data("id"),
};
commonJs.commentArticleLike(data, $this);
})
// 评论回复
.on(clickOrTouch, ".reply-btn", function (event) {
event.preventDefault();
event.stopPropagation();
let $this = $(this),
obj_pk = $this.data("id"),
curObj = JSON.parse(
$this.closest(".comment-list-item").attr("data-obj")
);
let replyCall = function (id) {
let user = commonJs.djUserInfor;
let replay_params = {
parent_pk: obj_pk,
parent_name: curObj.name,
};
// 分享页
if ($(".h5-wrap").length >= 1) {
$(".comment-modal").fadeIn("fast").attr({
"data-m": 1, // 1-评论的回复
"data-id": obj_pk,
});
$("#comment-textarea").focus();
}
// 客户端
if ($(".app-wrap").length >= 1) {
commonJs.showCommentEditorDialog(
Object.assign(comParams, replay_params)
);
}
};
commonJs.needUserAction(replyCall);
})
// 去评论
.on(clickOrTouch, ".no-comments .btn", function (event) {
event.preventDefault();
event.stopPropagation();
if (allowComment == "False" || allowComment == "Null") {
commonJs.toastMsg("该内容暂不支持评论");
return false;
}
let commentFunc = function () {
// 分享页
if ($(".h5-wrap").length >= 1) {
$(".comment-modal").fadeIn("fast").attr({
"data-m": 1, // 1-评论的回复
"data-id": obj_pk,
});
$("#comment-textarea").focus();
}
// 客户端
if ($(".app-wrap").length >= 1) {
commonJs.showCommentEditorDialog(comParams);
}
};
commonJs.needUserAction(commentFunc);
});
// 上拉加载更多评论
var lastScrollTop = 0; // 初始化上一次的滚动位置
$(window).scroll(function (e) {
if(isLoadingComment) return;
let scrollTop = $(this).scrollTop(),
scrollHeight = $(document).height(),
windowHeight = $(this).height(),
position = scrollTop + windowHeight,
st = $(this).scrollTop(); // 获取当前滚动位置
if (st > lastScrollTop) {
if (position >= scrollHeight - 10) {
if ($(".comment-more").is(":visible")) {
isLoadingComment = true;
getallComments(
$(".comment-more").closest(".comments-wrap").data("type")
);
}
}
}
lastScrollTop = st; // 更新上一次的滚动位置
});
// 评论框弹窗相关事件
let isAbleComment = true; // 限制重复评论
commonJs.autoHeight("#comment-textarea"); //输入框高度自适应
$(".comment-modal")
// 隐藏弹窗 影响安卓端按钮点击
// .on("touchstart", function (event) {
.on(clickOrTouch, function (event) {
// event.preventDefault();
event.stopPropagation();
if ($(event.target).hasClass("comment-modal")) {
$(this).fadeOut("fast");
}
})
// 提交评论-web端
.on(clickOrTouch, "button", function (event) {
event.preventDefault();
let self = this,
txt = $("#comment-textarea").val().trim();
if (txt.length <= 0) {
commonJs.toastMsg("最少输入一个字!");
return false;
}
if (!isAbleComment) {
return false;
}
isAbleComment = false;
let $curC = $(this).closest(".comment-modal"),
params = $.extend({}, comParams, {
appid: commonJs.webShareAppid,
comment: txt,
});
// 0-文章的评论 1-评论的回复
if ($curC.attr("data-m") == 1) {
params.parent_pk = $curC.attr("data-id");
}
commonJs.postRequest(
"/__xh__/interaction-api.gzstv.com/commen-web/comments/submit",
params,
function (res) {
$curC.fadeOut("fast");
$("#comment-textarea").val("");
commonJs.toastMsg("评论发送成功");
refreshComment("h5");
}
);
});
//实时检测输入框的输入字符个数
let $commentNum = $(".comment-modal").find(".t"),
$commentBtn = $(".comment-inp").find("button");
$("#comment-textarea").keyup(function () {
let len = $(this).val().length;
$commentNum.text(len);
if (len >= 1) {
$commentBtn.addClass("active");
} else {
$commentBtn.removeClass("active");
}
});
// 客户端:评论成功之后 刷新评论
window.commentSubmitCallback = function (res) {
// getNewestComments("showNewestComments");
refreshComment("app");
// 十周年活动弹窗控制
if ($(".year10").length > 0) {
$(".year10").hide();
activity10Pop("comment");
}
};
$("#comment-textarea").on("focus", () => {
setTimeout(() => {
// document.body.scrollTop = document.body.scrollHeight;
document.documentElement.scrollTop =
document.documentElement.scrollHeight - 100;
// window.scrollTo(0, document.body.scrollHeight - $('.comment-inp').height() - 100)
// document.documentElement.scrollTop=0;
// document.documentElement.scrollTop = window.visualViewport.height
}, 300);
});
document.body.addEventListener("focusin", () => {
//软键盘弹起事件
// console.log("键盘弹起");
});
document.body.addEventListener("focusout", () => {
//软键盘关闭事件
// console.log("键盘收起");
});
});
继续阅读
公开信息按发布时间滚动。阅读「韦德体育注册就送」后,可回到列表或查看相邻条目。
建议先扫读标题与摘要,再进入全文。同栏目条目通常按时间倒序排列。
继续浏览时优先选择同栏目或相近主题,避免被站外镜像带偏。
主题入口
评论 · live · 主页 · streams