Skip to content

Commit

Permalink
fix: 修复评论锚点值大于指定pageSize,即跳页,无法正常锚定Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yangrunkang committed Feb 17, 2023
1 parent a20f948 commit 226e192
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,8 @@ public static final class Page {
/**
* 每页条数
*/
public static final Integer SIZE = 15;
public static final Integer SIZE_HALF = 7;
public static final Integer SIZE_COMMENT = 30;
public static final Integer SIZE = 30;
public static final Integer SIZE_TEN = 10;
/**
* 最大条数
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.upupor.data.dao.entity.enhance.ContentEnhance;
import com.upupor.data.dto.page.comment.CommentDto;
import com.upupor.data.types.ContentType;
import com.upupor.framework.CcConstant;
import com.upupor.service.base.ContentService;
import com.upupor.service.business.comment.list.abstracts.AbstractCommentList;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -90,7 +91,7 @@ protected void createCommentDto(Map<String, Content> contentMap, CommentEnhance
return;
}
commentDtoList.add(CommentDto.create(comment.getCommentContent(),
"/u/" + content.getContentId(),
"/u/" + content.getContentId() + calcPageAnchor(comment.getFloorNum(), CcConstant.Page.SIZE),
content.getTitle(),
commentEnhance,
"文章"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.upupor.data.dao.entity.enhance.MemberEnhance;
import com.upupor.data.dto.page.comment.CommentDto;
import com.upupor.data.types.ContentType;
import com.upupor.framework.CcConstant;
import com.upupor.service.base.MemberService;
import com.upupor.service.business.comment.list.abstracts.AbstractCommentList;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -89,7 +90,7 @@ protected void createCommentDto(Map<String, Member> memberMap, CommentEnhance co
return;
}
commentDtoList.add(CommentDto.create(comment.getCommentContent(),
"/profile/" + member.getUserId() + "/message",
"/profile/" + member.getUserId() + "/message" + calcPageAnchor(comment.getFloorNum(), CcConstant.Page.SIZE),
member.getUserName(),
commentEnhance,
"留言板"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.upupor.data.dao.entity.enhance.CommentEnhance;
import com.upupor.data.dto.page.comment.CommentDto;
import com.upupor.data.types.ContentType;
import com.upupor.framework.CcConstant;
import com.upupor.service.base.RadioService;
import com.upupor.service.business.comment.list.abstracts.AbstractCommentList;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -85,7 +86,7 @@ protected void createCommentDto(Map<String, Radio> radioMap, CommentEnhance comm
return;
}
commentDtoList.add(CommentDto.create(comment.getCommentContent(),
"/r/" + radio.getRadioId(),
"/r/" + radio.getRadioId() + calcPageAnchor(comment.getFloorNum(), CcConstant.Page.SIZE),
radio.getRadioIntro(), commentEnhance,
"电台"
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public abstract class AbstractCommentList<T> {
*/
protected abstract Map<String, T> filteredIdConvertToTMap(List<String> filteredIdList);

/**
* 计算带页码的评论锚点
*
* @param floorNum
* @param perPageSize
* @return
*/
protected String calcPageAnchor(Long floorNum, Integer perPageSize) {
return "?pageNum=" + ((floorNum / perPageSize) + 1) + "#comment_" + floorNum;
}

public List<CommentDto> handle(List<CommentEnhance> commentEnhanceList) {
init(commentEnhanceList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

package com.upupor.task;

import com.upupor.data.dao.entity.Member;
import com.upupor.framework.CcConstant;
import com.upupor.framework.utils.CcUtils;
import com.upupor.service.base.MemberService;
import com.upupor.service.business.message.MessageSend;
import com.upupor.service.business.message.model.MessageModel;
import com.upupor.data.dao.entity.Member;
import com.upupor.service.base.MemberService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import java.util.List;
import java.util.Objects;

import static com.upupor.framework.CcConstant.Page.SIZE_COMMENT;
import static com.upupor.framework.CcConstant.Page.SIZE;
import static com.upupor.framework.CcConstant.ProfileView.BASE_PATH;
import static com.upupor.framework.CcConstant.ProfileView.PROFILE_MESSAGE;
import static com.upupor.framework.CcConstant.SeoKey;
Expand Down Expand Up @@ -101,8 +101,8 @@ public ModelAndView profile(@PathVariable("userId") String userId,
modelAndView.setViewName(abstractProfile.viewName());
// 如果是留言板,直接跳转到最新的一页
if (PROFILE_MESSAGE.replace(BASE_PATH, Strings.EMPTY).equals(path)) {
pageNum = isPageNumNull ? PageUtils.calcMaxPage(commentService.countByTargetId(userId), SIZE_COMMENT) : pageNum;
pageSize = CcConstant.Page.SIZE_COMMENT;
pageNum = isPageNumNull ? PageUtils.calcMaxPage(commentService.countByTargetId(userId), SIZE) : pageNum;
pageSize = CcConstant.Page.SIZE;
}

Query build = Query.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.Objects;

import static com.upupor.framework.CcConstant.ContentView.CONTENT_INDEX;
import static com.upupor.framework.CcConstant.Page.SIZE_COMMENT;
import static com.upupor.framework.CcConstant.Page.SIZE;

/**
* @author Yang Runkang (cruise)
Expand Down Expand Up @@ -116,11 +116,11 @@ protected void specifyPage() {
if (Objects.isNull(pageNum)) {
// 获取最新的评论
Integer count = commentService.countByTargetId(contentId);
pageNum = PageUtils.calcMaxPage(count, SIZE_COMMENT);
pageNum = PageUtils.calcMaxPage(count, SIZE);
query.setPageNum(pageNum);
}
if (Objects.isNull(pageSize)) {
pageSize = CcConstant.Page.SIZE_COMMENT;
pageSize = CcConstant.Page.SIZE;
query.setPageSize(pageSize);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

import java.util.Objects;

import static com.upupor.framework.CcConstant.Page.SIZE_COMMENT;
import static com.upupor.framework.CcConstant.Page.SIZE;
import static com.upupor.framework.CcConstant.RADIO_STATION_INDEX;

/**
Expand Down Expand Up @@ -111,12 +111,12 @@ protected void specifyPage() {
if (Objects.isNull(pageNum)) {
// 获取最新的评论
Integer count = commentService.countByTargetId(radioId);
pageNum = PageUtils.calcMaxPage(count, SIZE_COMMENT);
pageNum = PageUtils.calcMaxPage(count, SIZE);
query.setPageNum(pageNum);
}

if (Objects.isNull(pageSize)) {
pageSize = CcConstant.Page.SIZE_COMMENT;
pageSize = CcConstant.Page.SIZE;
query.setPageSize(pageSize);
}
}
Expand Down
2 changes: 1 addition & 1 deletion upupor-web/src/main/resources/templates/comment/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</div>
<div>
<a class="text-black-50 small"
th:href="${commentDto.targetUrl} + '#comment_' + ${commentDto.commentEnhance.comment.floorNum}"
th:href="${commentDto.targetUrl}"
th:title="${commentDto.targetTitle}">
<i class="bi bi-link-45deg"> 来自于&nbsp;</i>
<span class="badge rounded-3 fw-normal" style="border: 1px solid #DAEDE4;color: #3f7b5a;background-color: #EFF7ED;">[[${commentDto.sourceTag}]]</span> <strong>[[${commentDto.targetTitle}]]</strong>
Expand Down

0 comments on commit 226e192

Please sign in to comment.