广场帖子、专题页评论可以回复:点评论或「回复」即回复 TA,回复同样先审后发,楼里按时间排(v26110243)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -367,8 +367,8 @@ mark{background:linear-gradient(transparent 62%,var(--c20) 0);color:inherit;padd
|
||||
</div>
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
<script src="meta.js?v=26110242"></script>
|
||||
<script src="tests.js?v=26110242"></script>
|
||||
<script src="meta.js?v=26110243"></script>
|
||||
<script src="tests.js?v=26110243"></script>
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
@@ -418,6 +418,9 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
.ci-st{display:inline-block;margin-top:5px;padding:0 7px;border-radius:4px;font-size:11px;line-height:18px;font-weight:600}
|
||||
.ci-st.pending{background:#FFF4E5;color:#E08A00}.ci-st.rejected{background:#F2F3F5;color:#86909C}.ci-st.local{background:#F2F3F5;color:#A0A6AE}
|
||||
.ci.mine.rejected .ci-t{color:#A0A6AE}
|
||||
.ci-b[data-rk] .ci-t,.rp p[data-rk]{cursor:pointer}.ci-b[data-rk] .ci-t:active,.rp p[data-rk]:active{opacity:.6}
|
||||
.rp .au.me{background:#FFE7E0;color:#EC4D33}.rp p.rej{color:#A0A6AE}.rp .ci-st{margin-top:3px}
|
||||
.ci-s .rpy{margin-left:10px;color:#8C7B75;font-weight:600;cursor:pointer}
|
||||
.rp{margin-top:8px;padding:8px 10px;border-radius:10px;background:#F8F3EF;font-size:13px;line-height:1.65;color:#3A302C}
|
||||
.rp p{margin:0 0 4px}
|
||||
.rp p:last-child{margin-bottom:0}
|
||||
@@ -575,10 +578,10 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
<div id="sheet" role="dialog" aria-modal="true"><i class="sg"></i><div class="sbd" id="sbd"></div></div>
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
<script src="topics.js?v=26110242"></script>
|
||||
<script src="data.js?v=26110242"></script>
|
||||
<script src="feed.js?v=26110242"></script>
|
||||
<script src="ceshi/meta.js?v=26110242"></script>
|
||||
<script src="topics.js?v=26110243"></script>
|
||||
<script src="data.js?v=26110243"></script>
|
||||
<script src="feed.js?v=26110243"></script>
|
||||
<script src="ceshi/meta.js?v=26110243"></script>
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
@@ -644,7 +647,7 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
var CMD = null, CMERR = false;
|
||||
/* 头像编码:数字 = av/NNNN.webp(旧代码头像);'av:c012' = av/c012.webp(卡通/可爱卡通);'/…' = 站内绝对路径(内置头像库 /_bridge/avatars/);其余 = assets/img/mom/xxx.jpg */
|
||||
var avP = function (a) { return typeof a === 'number' ? 'av/' + ('000' + a).slice(-4) + '.webp' : a.indexOf('av:') === 0 ? 'av/' + a.slice(3) + '.webp' : a.charAt(0) === '/' ? a : '../assets/img/mom/' + a + '.jpg'; };
|
||||
fetch('cm.json?v=26110242').then(function (r) { return r.json(); }).then(function (j) {
|
||||
fetch('cm.json?v=26110243').then(function (r) { return r.json(); }).then(function (j) {
|
||||
CMD = j; if (openId && NBY[openId]) { renderComments(NBY[openId]); syncBar(NBY[openId]); }
|
||||
}).catch(function () { CMERR = true; if (openId && NBY[openId]) renderComments(NBY[openId]); });
|
||||
function commentsOf(n) {
|
||||
@@ -672,11 +675,25 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
var RC = {};
|
||||
var myCm = function (id) {
|
||||
var old = (ME.cm[id] || []).filter(function (c) { return !c.id; }).map(function (c) { return { t: c.t, ts: c.ts, s: c.s, st: 'local' }; });
|
||||
var srv = RC[id] ? RC[id].mine.map(function (c) { return { id: c.id, t: c.text, ts: c.at, s: c.stage, st: c.status, why: c.reason }; }) : [];
|
||||
var srv = RC[id] ? RC[id].mine.map(function (c) { return { id: c.id, t: c.text, ts: c.at, s: c.stage, st: c.status, why: c.reason, parent: c.parent, to: c.parentName }; }) : [];
|
||||
return old.concat(srv.reverse());
|
||||
};
|
||||
var realCm = function (id) { return RC[id] ? RC[id].list : []; };
|
||||
var cmN = function (n) { return commentsOf(n).length + realCm(n.id).length + myCm(n.id).filter(function (c) { return c.st !== 'rejected'; }).length; };
|
||||
/* 11-03 用户:可以回复别人的评论。回复也先审核;楼里只有一层,回复回复也挂在同一楼,写「回复 XX」 */
|
||||
var REPLY = null;
|
||||
function extraReplies(id, k) {
|
||||
var o = realCm(id).filter(function (c) { return c.parent === k; }).map(function (c) { return { n: c.nickname || '孕妈', t: c.text, to: c.parentName, ts: c.at }; });
|
||||
var m = myCm(id).filter(function (c) { return c.parent === k; }).map(function (c) { return { n: MYNAME, me: 1, t: c.t, to: c.to, st: c.st, why: c.why, ts: c.ts }; });
|
||||
return o.concat(m).sort(function (x, y) { return x.ts - y.ts; }); /* 楼里按时间先后 */
|
||||
}
|
||||
function stTag(c) { return c.st === 'pending' ? '<span class="ci-st pending">审核中 · 通过后大家才能看到</span>' : c.st === 'rejected' ? '<span class="ci-st rejected">未通过' + (c.why ? ':' + esc(c.why) : '') + '</span>' : c.st === 'local' ? '<span class="ci-st local">仅自己可见</span>' : ''; }
|
||||
function rpHTML(list, k, owner) {
|
||||
return list.length ? '<div class="rp">' + list.map(function (x) {
|
||||
return '<p' + (x.me ? ' class="rme' + (x.st === 'rejected' ? ' rej' : '') + '"' : ' data-rk="' + esc(k) + '" data-rn="' + esc(x.n) + '"') + '><b>' + esc(x.n) + '</b>' + (x.au ? '<span class="au">作者</span>' : '') + (x.me ? '<span class="au me">我</span>' : '') +
|
||||
(x.to && x.to !== owner ? ' 回复 <b>' + esc(x.to) + '</b>' : '') + ':' + esc(x.t) + (x.me && x.st && x.st !== 'approved' ? '<br>' + stTag(x) : '') + '</p>';
|
||||
}).join('') + '</div>' : '';
|
||||
}
|
||||
var cmN = function (n) { return commentsOf(n).length + realCm(n.id).length + myCm(n.id).filter(function (c) { return c.st !== 'rejected'; }).length; }; /* 含回复 */
|
||||
function loadRC(n) {
|
||||
var u = '/api/mp/public/mama-box/plaza/comments?kind=post&target=' + encodeURIComponent(n.id) + (OPENID ? '&openid=' + encodeURIComponent(OPENID) : '');
|
||||
fetch(u).then(function (r) { return r.json(); }).then(function (j) {
|
||||
@@ -1141,15 +1158,15 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
function commentHTML(c, mine) {
|
||||
if (mine) {
|
||||
var st = c.s || myStage();
|
||||
var tag = c.st === 'pending' ? '<span class="ci-st pending">审核中 · 通过后大家才能看到</span>' : c.st === 'rejected' ? '<span class="ci-st rejected">未通过' + (c.why ? ':' + esc(c.why) : '') + '</span>' : c.st === 'local' ? '<span class="ci-st local">仅自己可见</span>' : '';
|
||||
return '<div class="ci mine' + (c.st === 'rejected' ? ' rejected' : '') + '"><span class="me">我</span><div class="ci-b"><div class="ci-n"><b>' + esc(MYNAME) + '</b><span class="mt">我</span></div>' +
|
||||
'<p class="ci-t">' + esc(c.t) + '</p>' + (st ? '<div class="ci-s">' + esc(st) + '</div>' : '') + tag + '</div></div>'; /* 11-02 自己的评论也不显示时间 */
|
||||
var mk = c.id && c.st === 'approved' ? 'r:' + c.id : ''; /* 通过了的自己的评论,别人能回复,回复挂在这里 */
|
||||
return '<div class="ci mine' + (c.st === 'rejected' ? ' rejected' : '') + '"><span class="me">我</span><div class="ci-b"' + (mk ? ' data-rk="' + mk + '" data-rn="' + esc(MYNAME) + '"' : '') + '><div class="ci-n"><b>' + esc(MYNAME) + '</b><span class="mt">我</span></div>' +
|
||||
'<p class="ci-t">' + esc(c.t) + '</p>' + (st || mk ? '<div class="ci-s">' + esc(st) + (mk ? '<span class="rpy">回复</span>' : '') + '</div>' : '') + stTag(c) + (mk ? rpHTML(extraReplies(openId, mk), mk, MYNAME) : '') + '</div></div>'; /* 11-02 自己的评论也不显示时间 */
|
||||
}
|
||||
var on = !!ME.cl[c.key], n = c.likes + (on ? 1 : 0);
|
||||
var rp = c.r.length ? '<div class="rp">' + c.r.map(function (x) { return '<p><b>' + esc(x.n) + '</b>' + (x.au ? '<span class="au">作者</span>' : '') + ':' + esc(x.t) + '</p>'; }).join('') + '</div>' : '';
|
||||
return '<div class="ci"><img src="' + (c.av || avSrc(c.n)) + '" alt="" loading="lazy"><div class="ci-b"><div class="ci-n"><b>' + esc(c.n) + '</b>' +
|
||||
var rp = rpHTML(c.r.concat(extraReplies(openId, c.key)), c.key, c.n);
|
||||
return '<div class="ci"><img src="' + (c.av || avSrc(c.n)) + '" alt="" loading="lazy"><div class="ci-b" data-rk="' + esc(c.key) + '" data-rn="' + esc(c.n) + '"><div class="ci-n"><b>' + esc(c.n) + '</b>' +
|
||||
'<span class="lk' + (on ? ' on' : '') + '" data-cl="' + esc(c.key) + '" data-base="' + c.likes + '" role="button"><svg class="ic"><use href="#i-heart' + (on ? '-f' : '') + '"/></svg>' + n + '</span></div>' +
|
||||
'<p class="ci-t">' + esc(c.t) + '</p>' + (c.s ? '<div class="ci-s">' + esc(c.s) + '</div>' : '') /* 11-02 用户:评论时间先不显示 */ + rp + '</div></div>';
|
||||
'<p class="ci-t">' + esc(c.t) + '</p><div class="ci-s">' + (c.s ? esc(c.s) : '') + '<span class="rpy"' + (c.s ? '' : ' style="margin-left:0"') + '>回复</span></div>' /* 11-02 用户:评论时间先不显示 */ + rp + '</div></div>';
|
||||
}
|
||||
function agoOf(ts) {
|
||||
var s = Math.max(0, (Date.now() - ts) / 1000);
|
||||
@@ -1159,11 +1176,11 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
var d = new Date(ts); return (d.getMonth() + 1) + '-' + d.getDate();
|
||||
}
|
||||
function renderComments(n) {
|
||||
var mine = myCm(n.id).slice().reverse(), cs = commentsOf(n);
|
||||
var mine = myCm(n.id).filter(function (c) { return !c.parent; }).reverse(), cs = commentsOf(n);
|
||||
$('#cmh').innerHTML = '评论 <small>共 ' + cmN(n) + ' 条</small>';
|
||||
if (!CMD && !n.real && !CMERR) { $('#cml').innerHTML = mine.map(function (c) { return commentHTML(c, true); }).join('') + '<div class="cm-ld">评论加载中…</div>'; return; }
|
||||
/* 别人发的、已审核通过的真实评论排在模拟评论前面 */
|
||||
var rl = realCm(n.id).map(function (c) { return { key: 'r:' + c.id, n: c.nickname || '孕妈', av: c.avatar || '', s: c.stage, t: c.text, likes: 0, r: [] }; });
|
||||
var rl = realCm(n.id).filter(function (c) { return !c.parent; }).map(function (c) { return { key: 'r:' + c.id, n: c.nickname || '孕妈', av: c.avatar || '', s: c.stage, t: c.text, likes: 0, r: [] }; });
|
||||
$('#cml').innerHTML = mine.map(function (c) { return commentHTML(c, true); }).join('') + rl.concat(cs).map(function (c) { return commentHTML(c); }).join('');
|
||||
}
|
||||
function syncBar(n, popK) {
|
||||
@@ -1239,7 +1256,9 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
if (on) { cl.classList.remove('pop'); void cl.offsetWidth; cl.classList.add('pop'); }
|
||||
return;
|
||||
}
|
||||
if (e.target.closest('#cmgo')) $('#cin').focus();
|
||||
var rr = e.target.closest('[data-rk]');
|
||||
if (rr) { REPLY = { k: rr.dataset.rk, n: rr.dataset.rn }; cin.placeholder = '回复 ' + REPLY.n + ':'; cin.focus(); return; }
|
||||
if (e.target.closest('#cmgo')) { REPLY = null; cin.placeholder = '说点什么…'; $('#cin').focus(); }
|
||||
});
|
||||
$('#blk').addEventListener('click', function () {
|
||||
var n = NBY[openId]; if (!n) return;
|
||||
@@ -1256,7 +1275,7 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
});
|
||||
var cin = $('#cin');
|
||||
cin.addEventListener('focus', function () { $('#bar').classList.add('typing'); });
|
||||
cin.addEventListener('blur', function () { setTimeout(function () { if (!cin.value.trim()) $('#bar').classList.remove('typing'); }, 120); });
|
||||
cin.addEventListener('blur', function () { setTimeout(function () { if (!cin.value.trim()) { $('#bar').classList.remove('typing'); REPLY = null; cin.placeholder = '说点什么…'; } }, 120); });
|
||||
cin.addEventListener('input', function () { $('#csend').disabled = !cin.value.trim(); });
|
||||
cin.addEventListener('keydown', function (e) { if (e.key === 'Enter') { e.preventDefault(); send(); } });
|
||||
$('#csend').addEventListener('click', send);
|
||||
@@ -1267,16 +1286,17 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
/* 11-03:评论先交后台审核,通过后才公开;审核中只有自己看得到 */
|
||||
send.busy = true; $('#csend').disabled = true;
|
||||
fetch(API + '/comment?' + idq(), { method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ kind: 'post', target: n.id, title: n.title, text: v.slice(0, 200), stage: myStage() }) })
|
||||
body: JSON.stringify({ kind: 'post', target: n.id, title: n.title, text: v.slice(0, 200), stage: myStage(), parent: REPLY ? REPLY.k : '', parentName: REPLY ? REPLY.n : '' }) })
|
||||
.then(function (r) { return r.json(); }).then(function (j) {
|
||||
send.busy = false;
|
||||
if (!j || j.code !== 200) { $('#csend').disabled = !cin.value.trim(); toast((j && j.message) || '没发出去,稍后再试'); return; }
|
||||
var rc = RC[n.id] || (RC[n.id] = { list: [], mine: [] }); rc.mine.unshift(j.result);
|
||||
var wasReply = !!REPLY; REPLY = null; cin.placeholder = '说点什么…';
|
||||
haptic();
|
||||
cin.value = ''; $('#csend').disabled = true; cin.blur(); $('#bar').classList.remove('typing');
|
||||
if (openId === n.id) { renderComments(n); syncBar(n); }
|
||||
var w = $('#cmw'); if (w) $('#dsc').scrollTo({ top: w.offsetTop - 50, behavior: 'smooth' });
|
||||
toast('已提交,审核通过后大家就能看到');
|
||||
if (!wasReply) { var w = $('#cmw'); if (w) $('#dsc').scrollTo({ top: w.offsetTop - 50, behavior: 'smooth' }); }
|
||||
toast(wasReply ? '回复已提交,审核通过后大家就能看到' : '已提交,审核通过后大家就能看到');
|
||||
}).catch(function () { send.busy = false; $('#csend').disabled = !cin.value.trim(); toast('网络不太好,稍后再试'); });
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ main{padding:6px 16px 0}
|
||||
</div>
|
||||
<div class="wb"><button type="button" id="write"><svg class="ic" viewBox="0 0 24 24"><path d="M12 20h9M16.5 3.5a2.1 2.1 0 013 3L7 19l-4 1 1-4z"/></svg>写新的故事</button></div>
|
||||
|
||||
<script src="../topics.js?v=26110242"></script>
|
||||
<script src="../topics.js?v=26110243"></script>
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
Reference in New Issue
Block a user