feat: 重构评论点赞系统,支持取消点赞
- 改用 IP + User-Agent 哈希识别用户,登录用户使用 user_id - 服务端存储点赞用户列表,而非简单计数 - 同一用户只能点赞一次,再次点击可取消点赞 - 移除 Cookie 依赖,避免 IP 变化导致重复点赞 - 已点赞按钮 hover 时显示可点击状态
This commit is contained in:
@@ -1905,25 +1905,35 @@ if (argonConfig.waterflow_columns != "1") {
|
||||
});
|
||||
}();
|
||||
/*评论点赞*/
|
||||
$(document).on("click" , ".comment-upvote" , function(){
|
||||
$this = $(this);
|
||||
ID = $this.attr("data-id");
|
||||
$this.addClass("comment-upvoting");
|
||||
$(document).on('click', '.comment-upvote', function(){
|
||||
let $this = $(this);
|
||||
let ID = $this.attr('data-id');
|
||||
|
||||
// 防止重复点击
|
||||
if ($this.hasClass('comment-upvoting')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this.addClass('comment-upvoting');
|
||||
$.ajax({
|
||||
url : argonConfig.wp_path + "wp-admin/admin-ajax.php",
|
||||
type : "POST",
|
||||
dataType : "json",
|
||||
data : {
|
||||
action: "upvote_comment",
|
||||
comment_id : ID,
|
||||
url: argonConfig.wp_path + 'wp-admin/admin-ajax.php',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'upvote_comment',
|
||||
comment_id: ID,
|
||||
},
|
||||
success : function(result){
|
||||
$this.removeClass("comment-upvoting");
|
||||
if (result.status == "success"){
|
||||
$(".comment-upvote-num" , $this).html(result.total_upvote);
|
||||
$this.addClass("upvoted");
|
||||
}else{
|
||||
$(".comment-upvote-num" , $this).html(result.total_upvote);
|
||||
success: function(result){
|
||||
$this.removeClass('comment-upvoting');
|
||||
if (result.status === 'success'){
|
||||
$('.comment-upvote-num', $this).html(result.total_upvote);
|
||||
if (result.upvoted) {
|
||||
$this.addClass('upvoted');
|
||||
} else {
|
||||
$this.removeClass('upvoted');
|
||||
}
|
||||
} else {
|
||||
$('.comment-upvote-num', $this).html(result.total_upvote);
|
||||
iziToast.show({
|
||||
title: result.msg,
|
||||
class: 'shadow-sm',
|
||||
@@ -1938,10 +1948,10 @@ $(document).on("click" , ".comment-upvote" , function(){
|
||||
});
|
||||
}
|
||||
},
|
||||
error : function(xhr){
|
||||
$this.removeClass("comment-upvoting");
|
||||
error: function(xhr){
|
||||
$this.removeClass('comment-upvoting');
|
||||
iziToast.show({
|
||||
title: __("点赞失败"),
|
||||
title: __('点赞失败'),
|
||||
class: 'shadow-sm',
|
||||
position: 'topRight',
|
||||
backgroundColor: '#f5365c',
|
||||
|
||||
Reference in New Issue
Block a user