Merge pull request #224 from xyhcode/main

修复最新评论切换获取
This commit is contained in:
小孙同学 2023-06-30 17:45:54 +08:00 committed by GitHub
commit 831dad39cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 24 deletions

View File

@ -4,23 +4,21 @@
<div class="card-widget card-recent-post" th:fragment="comments"> <div class="card-widget card-recent-post" th:fragment="comments">
<div class="item-headline"><i class="iconfont icon-comment-dots"></i><span>最新评论</span></div> <div class="item-headline"><i class="iconfont icon-comment-dots"></i><span>最新评论</span></div>
<div class="aside-list" id="newcomm"> <div class="aside-list" id="newcomm">
<script th:src="@{/assets/libs/twikoo/twikoo.all.min.js}"></script>
</div> <script th:if="${theme.config.comments.twikoo && #strings.equals(theme.config.comments.use, 'Twikoo') && not #strings.isEmpty(theme.config.comments.envId)}">
</div> (()=>{
<script th:src="@{/assets/libs/twikoo/twikoo.all.min.js}"></script> const pagesize = [[${theme.config.sidebar.newcommentnumber}]];
<script th:if="${theme.config.comments.twikoo && #strings.equals(theme.config.comments.use, 'Twikoo') && not #strings.isEmpty(theme.config.comments.envId)}"> const defaultpagesize = 5;
const pagesize = [[${theme.config.sidebar.newcommentnumber}]]; const finalpagesize = pagesize <= 0 ? defaultpagesize : pagesize;
const defaultpagesize = 5; twikoo.getRecentComments({
const finalpagesize = pagesize <= 0 ? defaultpagesize : pagesize; envId: [[${ theme.config.comments.envId }]], // 环境 ID
twikoo.getRecentComments({ // region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai如果您的环境地域不是上海需传此参数
envId: [[${ theme.config.comments.envId }]], // 环境 ID pageSize: finalpagesize, // 获取多少条默认10最大100
// region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai如果您的环境地域不是上海需传此参数 includeReply: false // 是否包括最新回复默认false
pageSize: finalpagesize, // 获取多少条默认10最大100 }).then(function (res) {
includeReply: false // 是否包括最新回复默认false let commenthtml = '';
}).then(function (res) { res.forEach((items)=>{
let commenthtml = ''; commenthtml += `<div class="aside-list-item">
res.forEach((items)=>{
commenthtml += `<div class="aside-list-item">
<a class="thumbnail" href="${items.url}"> <a class="thumbnail" href="${items.url}">
<img loading="lazy" alt="dasda" src="${items.avatar}"> <img loading="lazy" alt="dasda" src="${items.avatar}">
</a> </a>
@ -34,11 +32,17 @@
</div> </div>
</div> </div>
</div>` </div>`
}); });
document.querySelector('#newcomm').innerHTML = commenthtml; let necomm = document.querySelector('#newcomm')
}).catch(function (err) { necomm.innerHTML = commenthtml;
// 发生错误 window.lazyLoadInstance && window.lazyLoadInstance.update()
console.error(err); window.pjax && window.pjax.refresh(necomm)
}); }).catch(function (err) {
</script> // 发生错误
console.error(err);
});
})();
</script>
</div>
</div>
</html> </html>