详情页评论改推荐列表

This commit is contained in:
谢宇宁
2026-09-29 16:45:18 +07:00
parent d546160cc7
commit 41a45c8975
16 changed files with 160 additions and 1207 deletions
+29
View File
@@ -1857,3 +1857,32 @@ a.play-synopsis__tag:hover {
line-height: 16px;
}
}
/* 猜你喜欢放在左栏(原评论位置),右栏为热门榜单 */
.play-dual > .play-like {
flex: 1;
min-width: 0;
padding: 0;
}
.play-dual .play-like__grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 20px 16px;
}
.play-dual .card--play {
width: auto;
min-width: 0;
}
@media (max-width: 768px) {
.play-dual > .play-like {
padding: 0;
}
.play-dual .play-like__grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 14px 8px;
}
}
-396
View File
@@ -1,396 +0,0 @@
/* 播放页评论区(含输入框、列表、内联回复) */
.play-comments {
flex: 1 1 0;
min-width: 0;
display: flex;
flex-direction: column;
gap: 16px;
}
.play-comments__head {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 14px;
}
.play-comments__title {
margin: 0;
font-size: 22px;
font-weight: 600;
line-height: 30px;
}
.play-comments__count {
color: var(--text-dim);
font-size: 14px;
line-height: 22px;
}
.play-composer {
display: flex;
align-items: center;
gap: 12px;
}
.play-composer__avatar {
width: 40px;
height: 40px;
flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
background: #232328;
border-radius: 999px;
overflow: hidden;
}
.play-composer__avatar-img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.play-composer__field {
flex: 1 1 0;
min-width: 0;
height: 44px;
padding: 0 16px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
background: rgba(255, 255, 255, 0.06);
border: 1px solid var(--line);
border-radius: var(--radius-md);
}
.play-composer__input {
flex: 1 1 0;
min-width: 0;
height: 100%;
padding: 0;
border: 0;
outline: none;
background: transparent;
color: var(--text);
font: inherit;
font-size: 15px;
line-height: 24px;
}
.play-composer__input::placeholder {
color: var(--text-dim);
}
.play-composer__count {
flex-shrink: 0;
color: var(--text-dim);
font-size: 14px;
line-height: 20px;
}
.play-composer__login,
.play-composer__send {
flex-shrink: 0;
}
.play-composer__send:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.play-comment-list {
margin: 0;
padding: 0;
list-style: none;
}
.play-comment {
display: flex;
align-items: flex-start;
gap: 12px;
padding: 16px 0;
border-bottom: 1px solid var(--line-soft);
}
.play-comment:last-child {
border-bottom: 0;
}
.play-comment__avatar {
width: 40px;
height: 40px;
flex-shrink: 0;
border-radius: 999px;
object-fit: cover;
}
.play-comment__body {
flex: 1 1 0;
min-width: 0;
display: flex;
flex-direction: column;
gap: 8px;
}
.play-comment__meta {
display: flex;
align-items: center;
gap: 10px;
}
.play-comment__name {
font-size: 14px;
font-weight: 500;
line-height: 20px;
}
.play-comment__time {
color: var(--text-dim);
font-size: 12px;
line-height: 18px;
}
.play-comment__text {
margin: 0;
color: var(--text-muted);
font-size: 14px;
line-height: 22px;
}
.play-comment--empty {
justify-content: center;
align-items: center;
border-bottom: 0;
}
.play-comment--empty .play-comment__text {
padding: 12px 0;
color: var(--muted, #888);
text-align: center;
width: 100%;
}
.play-comment__reply {
padding: 10px 14px;
color: var(--text-muted);
font-size: 13px;
line-height: 20px;
background: rgba(255, 255, 255, 0.04);
border-radius: var(--radius-sm);
}
.play-comment__actions {
display: flex;
align-items: center;
gap: 20px;
}
.play-comment__action {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 0;
border: 0;
background: transparent;
color: var(--text-dim);
font: inherit;
font-size: 12px;
line-height: 18px;
cursor: pointer;
}
.play-comment__action:disabled {
cursor: default;
opacity: 0.7;
}
.play-comment__action.is-active {
color: var(--brand, #e9c977);
}
.play-comment__action.is-active .icon {
opacity: 1;
filter: none;
}
.play-comment__action .icon {
width: 14px;
height: 14px;
opacity: 0.75;
}
.play-comment__inline {
width: 100%;
margin-top: 4px;
padding: 10px 12px;
display: flex;
flex-direction: column;
gap: 8px;
background: rgba(255, 255, 255, 0.04);
border: 1px solid var(--line-soft);
border-radius: var(--radius-sm);
box-sizing: border-box;
}
.play-comment__inline-hint {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
color: var(--text-dim);
font-size: 12px;
line-height: 18px;
}
.play-comment__inline-hint button {
flex-shrink: 0;
padding: 0;
border: 0;
background: transparent;
color: var(--brand, #e9c977);
font: inherit;
font-size: 12px;
line-height: 18px;
cursor: pointer;
}
.play-comment__inline-row {
display: flex;
align-items: center;
gap: 8px;
}
.play-comment__inline-input {
flex: 1 1 0;
min-width: 0;
height: 36px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(0, 0, 0, 0.35);
color: var(--text);
font: inherit;
font-size: 13px;
line-height: 20px;
outline: none;
}
.play-comment__inline-input::placeholder {
color: var(--text-dim);
}
.play-comment__inline-input:focus,
.play-comment__inline-input:focus-visible {
border-color: rgba(233, 201, 119, 0.55);
}
.play-comment__inline-send {
flex-shrink: 0;
height: 36px;
padding: 0 14px;
border: 0;
border-radius: 999px;
background: var(--brand, #e9c977);
color: #141417;
font: inherit;
font-size: 13px;
font-weight: 600;
line-height: 20px;
cursor: pointer;
}
.play-comment__inline-send:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.play-comments__more {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
padding-top: 12px;
color: var(--text-muted);
font-size: 14px;
line-height: 22px;
background: transparent;
border: 0;
cursor: pointer;
}
.play-comments__more[hidden] {
display: none;
}
.play-comments__more:disabled {
opacity: 0.6;
cursor: default;
}
.play-comments__more .icon {
width: 16px;
height: 16px;
transform: rotate(90deg);
}
@media (max-width: 768px) {
.play-comments {
width: 100%;
padding: 0;
gap: 16px;
}
.play-comments__head {
gap: 14px;
flex-wrap: nowrap;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
scrollbar-width: none;
}
.play-comments__head::-webkit-scrollbar {
display: none;
}
.play-comments__title {
flex-shrink: 0;
font-size: 22px;
line-height: 30px;
}
.play-comments__count {
flex-shrink: 0;
}
.play-composer {
width: 100%;
gap: 12px;
}
.play-composer__avatar {
flex-shrink: 0;
}
.play-composer__field {
min-width: 0;
}
.play-composer__login,
.play-composer__send {
flex-shrink: 0;
height: 40px;
padding: 0 16px;
}
.play-comment-list {
width: 100%;
}
.play-comments__more {
width: 100%;
}
}
+1 -1
View File
@@ -702,7 +702,7 @@
if (btn.getAttribute("data-play-bound") === "1") return;
btn.setAttribute("data-play-bound", "1");
btn.addEventListener("click", function (event) {
// 预告片免登录 / 免解锁;仅正片未解锁时拦充值
// 预告片直接播放;仅正片为 App 专享时弹下载提示
if (
btn.hasAttribute("data-play-coin-open") &&
!isPreviewMode()
-260
View File
@@ -1,260 +0,0 @@
// 播放页评论:只读列表 + 「查看更多评论」追加翻页
(function () {
var commentsRoot = document.querySelector("[data-play-comments]");
if (!commentsRoot) return;
var listEl = document.querySelector("[data-comment-list]");
var totalEl = document.querySelector("[data-comment-total-label]");
var moreBtn = document.querySelector("[data-comment-more]");
var loadingMore = false;
var PAGE_SIZE = 4;
function toast(message, type) {
if (typeof window.showToast === "function") {
window.showToast(message, type);
return;
}
}
function toInt(v, fallback) {
var n = parseInt(v, 10);
return isNaN(n) ? fallback || 0 : n;
}
function escapeHtml(s) {
return String(s == null ? "" : s)
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
}
function getPageSize() {
return Math.max(
1,
toInt(commentsRoot.getAttribute("data-comment-size"), PAGE_SIZE)
);
}
function getPage() {
return Math.max(
1,
toInt(commentsRoot.getAttribute("data-comment-page"), 1)
);
}
function getLoaded() {
if (!listEl) return 0;
return listEl.querySelectorAll(".play-comment:not(.play-comment--empty)").length;
}
function setPagerState(page, loaded, total) {
if (page != null) commentsRoot.setAttribute("data-comment-page", String(page));
if (loaded != null) commentsRoot.setAttribute("data-comment-loaded", String(loaded));
if (total != null) commentsRoot.setAttribute("data-comment-total", String(total));
syncMoreButton(total != null ? total : toInt(commentsRoot.getAttribute("data-comment-total"), 0));
}
function syncMoreButton(total) {
if (!moreBtn) return;
var loaded = getLoaded();
var hasMore = total > loaded;
if (hasMore) {
moreBtn.hidden = false;
moreBtn.removeAttribute("hidden");
} else {
moreBtn.hidden = true;
moreBtn.setAttribute("hidden", "");
}
}
function formatTime(raw) {
var s = String(raw || "").trim();
if (!s) return "刚刚";
var d = new Date(s);
if (isNaN(d.getTime())) return s;
return (
d.getFullYear() +
"/" +
(d.getMonth() + 1) +
"/" +
d.getDate() +
" " +
String(d.getHours()).padStart(2, "0") +
":" +
String(d.getMinutes()).padStart(2, "0")
);
}
function renderCommentItem(item) {
item = item || {};
var avatar = String(item.userAvatar || "").trim();
var name = escapeHtml(item.userName || "匿名用户");
var text = escapeHtml(item.text || "");
var time = escapeHtml(formatTime(item.createdAt));
var like = toInt(item.countLike, 0);
var avatarHtml = avatar
? '<img class="play-comment__avatar lazy" src="/static/images/placeholder.png?v=2" data-src="' +
escapeHtml(avatar) +
'" alt="" loading="lazy" decoding="async">'
: '<img class="play-comment__avatar" src="/static/images/placeholder.png?v=2" data-src="/static/images/profile/avatar.png" alt="" loading="lazy" decoding="async">';
var children = Array.isArray(item.children) ? item.children : [];
var replies = children
.map(function (child) {
var cName = escapeHtml(child.userName || "用户");
var replyTo = child.replyUserName
? " 回复 " + escapeHtml(child.replyUserName)
: "";
return (
'<div class="play-comment__reply">' +
cName +
replyTo +
":" +
escapeHtml(child.text || "") +
"</div>"
);
})
.join("");
var commentId = escapeHtml(item.id || "");
return (
'<li class="play-comment" data-comment-id="' +
commentId +
'">' +
avatarHtml +
'<div class="play-comment__body">' +
'<div class="play-comment__meta">' +
'<span class="play-comment__name">' +
name +
"</span>" +
'<span class="play-comment__time">' +
time +
"</span>" +
"</div>" +
'<p class="play-comment__text">' +
text +
"</p>" +
replies +
'<div class="play-comment__actions">' +
'<span class="play-comment__action">' +
'<img class="icon" src="/static/images/placeholder.png?v=2" data-src="/static/images/heart.svg" alt="" loading="lazy" decoding="async">' +
"<span>" +
escapeHtml(like) +
"</span>" +
"</span>" +
"</div></div></li>"
);
}
function getLoadedIds() {
var ids = Object.create(null);
if (!listEl) return ids;
listEl.querySelectorAll(".play-comment[data-comment-id]").forEach(function (el) {
var id = String(el.getAttribute("data-comment-id") || "").trim();
if (id) ids[id] = true;
});
return ids;
}
function updateTotal(n) {
if (!totalEl) return;
totalEl.textContent = n > 0 ? n + " 条" : "暂无评论";
}
// 下一页追加到现有列表底部,不替换已展示评论。
function appendList(list, totalCount) {
if (!listEl) return;
list = Array.isArray(list) ? list : [];
var total =
typeof totalCount === "number"
? totalCount
: toInt(commentsRoot.getAttribute("data-comment-total"), 0);
if (typeof totalCount === "number") {
updateTotal(totalCount);
}
if (!list.length) {
setPagerState(getPage(), getLoaded(), total);
return;
}
var empty = listEl.querySelector(".play-comment--empty");
if (empty) empty.remove();
var existing = getLoadedIds();
var fresh = list.filter(function (item) {
var id = String((item && item.id) || "").trim();
return id && !existing[id];
});
if (!fresh.length) {
setPagerState(getPage(), getLoaded(), total);
return;
}
var wrap = document.createElement("ul");
wrap.innerHTML = fresh.map(renderCommentItem).join("");
var nodes = [];
while (wrap.firstChild) {
nodes.push(wrap.firstChild);
listEl.appendChild(wrap.firstChild);
}
if (typeof window.initLazyImages === "function") {
nodes.forEach(function (node) {
if (node && node.nodeType === 1) window.initLazyImages(node);
});
window.initLazyImages(listEl);
}
setPagerState(getPage(), getLoaded(), total);
}
function fetchCommentPage(pageNum) {
if (!window.HttpRequest || typeof window.HttpRequest.get !== "function") {
return Promise.reject(new Error("评论服务未就绪"));
}
var objectId = toInt(commentsRoot.getAttribute("data-object-id"), 0);
var objectType = toInt(commentsRoot.getAttribute("data-object-type"), 10);
if (objectId <= 0) return Promise.reject(new Error("缺少评论对象"));
var pageSize = getPageSize();
return window.HttpRequest.get("/api/comment/list", {
params: {
objectId: objectId,
objectType: objectType,
pageNum: pageNum,
pageSize: pageSize,
sortOrder: 1,
},
}).then(function (res) {
if (!res || Number(res.code) !== 200 || !res.data) {
throw new Error((res && (res.tip || res.msg)) || "加载失败");
}
return res.data;
});
}
function loadMoreComments() {
if (loadingMore || !moreBtn) return;
var nextPage = getPage() + 1;
loadingMore = true;
moreBtn.disabled = true;
fetchCommentPage(nextPage)
.then(function (data) {
var list = data.list || [];
var total = toInt(data.totalCount, 0);
commentsRoot.setAttribute("data-comment-page", String(nextPage));
// 只追加,绝不 renderList 整表替换
appendList(list, total);
})
.catch(function (err) {
toast((err && err.message) || "加载失败,请稍后重试", "error");
})
.finally(function () {
loadingMore = false;
if (moreBtn) moreBtn.disabled = false;
});
}
if (moreBtn) {
moreBtn.addEventListener("click", function (event) {
event.preventDefault();
loadMoreComments();
});
}
})();