广场帖子、专题页评论改为先交后台审核:审核中只自己可见并挂状态,通过后所有人可见,未通过显示原因(v26110242)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,8 @@
|
||||
'.tc-in textarea{flex:1;min-width:0;border:0;background:transparent;resize:none;font-size:14px;line-height:1.6;font-family:inherit;color:#1F2329;height:24px;max-height:96px;outline:0;padding:0}' +
|
||||
'.tc-in button{flex:0 0 auto;height:36px;padding:0 16px;border:0;border-radius:99px;background:var(--tt-c,#18A058);color:#fff;font-size:13.5px;font-weight:700}.tc-in button:disabled{opacity:.35}' +
|
||||
'.tc-it{display:flex;gap:10px;padding:14px 0;border-bottom:1px solid #F2F3F5}.tc-it:last-child{border-bottom:0}.tc-av{flex:0 0 34px;width:34px;height:34px;border-radius:50%;object-fit:cover;background:#F2F3F5}' +
|
||||
/* 11-03 用户评论先审核:自己的评论挂状态 */
|
||||
'.tc-st{display:inline-block;margin-top:6px;padding:0 7px;border-radius:4px;font-size:11px;line-height:18px;font-weight:600;background:#F2F3F5;color:#86909C}.tc-st.pending{background:#FFF4E5;color:#E08A00}.tc-it.rej .tc-t{color:#A0A6AE}' +
|
||||
'.tc-me{display:flex;align-items:center;justify-content:center;font-size:13px;font-weight:800;color:#fff;background:var(--tt-c,#18A058)}' +
|
||||
'.tc-b{flex:1;min-width:0}.tc-n{display:flex;align-items:center;gap:6px;font-size:13px;color:#86909C;line-height:1.4}.tc-n b{font-weight:600;color:#4E5969}.tc-n i{font-style:normal;font-size:11px;padding:0 6px;border-radius:99px;background:#F2F3F5}' +
|
||||
'.tc-t{margin-top:4px;font-size:14.5px;line-height:1.7;color:#1F2329;word-break:break-word}' +
|
||||
@@ -56,13 +58,14 @@
|
||||
function saveMe(st) { try { st.a[UK] = st.m; localStorage.setItem(SK, JSON.stringify(st.a)); } catch (e) {} }
|
||||
/* 11-02 用户:自己发的评论带上孕周(首页写进 mmbox.gcwk.v1) */
|
||||
function myStage() { try { var g = JSON.parse(localStorage.getItem('mmbox.gcwk.v1') || 'null'); return !g ? '' : g.pp ? '宝妈' : g.w ? '孕 ' + g.w + ' 周' : ''; } catch (e) { return ''; } }
|
||||
function avP(a) { return typeof a === 'number' ? '../../guangchang/av/' + ('000' + a).slice(-4) + '.webp' : a.indexOf('av:') === 0 ? '../../guangchang/av/' + a.slice(3) + '.webp' : a.charAt(0) === '/' ? a : '../../assets/img/mom/' + a + '.jpg'; }
|
||||
function avP(a) { if (/^https?:\/\//.test(a)) return a; if (a === '') a = 'av:q' + ('00' + (SLUG.length * 37 % 150)).slice(-3); /* 真实评论:用户自己的头像;没头像给个可爱卡通 */
|
||||
return typeof a === 'number' ? '../../guangchang/av/' + ('000' + a).slice(-4) + '.webp' : a.indexOf('av:') === 0 ? '../../guangchang/av/' + a.slice(3) + '.webp' : a.charAt(0) === '/' ? a : '../../assets/img/mom/' + a + '.jpg'; }
|
||||
function wan(n) { return n >= 1e4 ? (Math.round(n / 1e3) / 10) + '万' : String(n); }
|
||||
var HEART = '<svg viewBox="0 0 24 24"><path d="M12 20s-7-4.4-7-10a4 4 0 017-2.6A4 4 0 0119 10c0 5.6-7 10-7 10z"/></svg>';
|
||||
function getJSON(u) { return fetch(u, { cache: 'no-cache' }).then(function (r) { if (!r.ok) throw r.status; return r.json(); }); }
|
||||
|
||||
function related(box) {
|
||||
getJSON('../_shared/idx.json?v=26110241').then(function (idx) {
|
||||
getJSON('../_shared/idx.json?v=26110242').then(function (idx) {
|
||||
var me = null; idx.forEach(function (x) { if (x[0] === SLUG) me = x; });
|
||||
var tag = me ? me[2] : '', h = 0; for (var i = 0; i < SLUG.length; i++) h = (h * 31 + SLUG.charCodeAt(i)) >>> 0;
|
||||
var rest = idx.filter(function (x) { return x[0] !== SLUG; });
|
||||
@@ -78,22 +81,30 @@
|
||||
}
|
||||
|
||||
function comments(box) {
|
||||
var st = loadMe(), L = [], open = false;
|
||||
function mine() { return st.m.cm[SLUG] || []; }
|
||||
/* 11-03 用户:评论要后台审核通过才对外公开。服务器 /plaza/comments?kind=topic:list = 别人已通过的,mine = 我发的(含审核中/未通过);
|
||||
st.m.cm 里是 11-03 以前只存本机的旧评论,从没公开过,照旧只给自己看(标「仅自己可见」) */
|
||||
var st = loadMe(), L = [], open = false, RC = { list: [], mine: [] }, OID = UK === '_guest' ? '' : UK;
|
||||
var API = '/api/mp/public/mama-box/plaza';
|
||||
function mine() {
|
||||
var old = (st.m.cm[SLUG] || []).map(function (c) { return { t: c.t, ts: c.ts, s: c.s, st: 'local' }; });
|
||||
return old.concat(RC.mine.slice().reverse().map(function (c) { return { t: c.text, ts: c.at, s: c.stage, st: c.status, why: c.reason, id: c.id }; }));
|
||||
}
|
||||
function real() { return RC.list.map(function (c) { return [c.nickname || '孕妈', c.avatar || '', c.stage || '', c.text, 0, [], 'r:' + c.id]; }); }
|
||||
function item(c, key) {
|
||||
var lk = !!st.m.lk[key];
|
||||
return '<div class="tc-it">' + (c.me ? '<span class="tc-av tc-me">我</span>' : '<img class="tc-av" src="' + esc(avP(c[1])) + '" alt="" loading="lazy">') +
|
||||
var tag = !c.me ? '' : c.st === 'pending' ? '<span class="tc-st pending">审核中 · 通过后大家才能看到</span>' : c.st === 'rejected' ? '<span class="tc-st">未通过' + (c.why ? ':' + esc(c.why) : '') + '</span>' : c.st === 'local' ? '<span class="tc-st">仅自己可见</span>' : '';
|
||||
return '<div class="tc-it' + (c.me && c.st === 'rejected' ? ' rej' : '') + '">' + (c.me ? '<span class="tc-av tc-me">我</span>' : '<img class="tc-av" src="' + esc(avP(c[1])) + '" alt="" loading="lazy">') +
|
||||
'<div class="tc-b"><div class="tc-n"><b>' + esc(c.me ? '我' : c[0]) + '</b>' + (c.me ? '<i>' + esc(c.s || myStage() || '刚刚') + '</i>' : (c[2] ? '<i>' + esc(c[2]) + '</i>' : '')) + '</div>' +
|
||||
'<div class="tc-t">' + esc(c.me ? c.t : c[3]) + '</div>' +
|
||||
'<div class="tc-t">' + esc(c.me ? c.t : c[3]) + '</div>' + tag +
|
||||
(!c.me && c[5] && c[5].length ? '<div class="tc-r">' + c[5].map(function (r) { return '<p><b>' + esc(r[0]) + ':</b>' + esc(r[3]) + '</p>'; }).join('') + '</div>' : '') +
|
||||
'<div class="tc-f"><button type="button" class="tc-lk' + (lk ? ' on' : '') + '" data-k="' + esc(key) + '">' + HEART + '<span>' + ((c.me ? 0 : c[4]) + (lk ? 1 : 0) || '赞') + '</span></button></div></div></div>';
|
||||
}
|
||||
function paint() {
|
||||
var my = mine().slice().reverse(), n = L.length + my.length, show = open ? L : L.slice(0, 5);
|
||||
var my = mine().slice().reverse(), A = real().concat(L), n = A.length + my.filter(function (c) { return c.st !== 'rejected'; }).length, show = open ? A : A.slice(0, 5);
|
||||
box.innerHTML = '<div class="tt-h"><b>大家怎么说</b><span>' + n + ' 条评论</span></div>' +
|
||||
'<div class="tc-list">' + my.map(function (c, i) { return item({ me: 1, t: c.t, s: c.s }, 'me' + c.ts); }).join('') +
|
||||
show.map(function (c, i) { return item(c, SLUG + '#' + i); }).join('') + '</div>' +
|
||||
(!open && L.length > 5 ? '<button type="button" class="tc-more">展开全部 ' + n + ' 条评论</button>' : '');
|
||||
'<div class="tc-list">' + my.map(function (c, i) { return item({ me: 1, t: c.t, s: c.s, st: c.st, why: c.why }, 'me' + c.ts); }).join('') +
|
||||
show.map(function (c, i) { return item(c, c[6] || SLUG + '#' + (i - (A.length - L.length))); }).join('') + '</div>' +
|
||||
(!open && A.length > 5 ? '<button type="button" class="tc-more">展开全部 ' + n + ' 条评论</button>' : '');
|
||||
var mo = box.querySelector('.tc-more'); if (mo) mo.addEventListener('click', function () { open = true; paint(); });
|
||||
[].forEach.call(box.querySelectorAll('.tc-lk'), function (b) {
|
||||
b.addEventListener('click', function () { var k = b.dataset.k; if (st.m.lk[k]) delete st.m.lk[k]; else st.m.lk[k] = 1; saveMe(st); paint(); });
|
||||
@@ -109,12 +120,30 @@
|
||||
var ta = bar.querySelector('textarea'), bt = bar.querySelector('button');
|
||||
ta.addEventListener('input', function () { bt.disabled = !ta.value.trim(); ta.style.height = '24px'; ta.style.height = Math.min(96, ta.scrollHeight) + 'px'; });
|
||||
bt.addEventListener('click', function () {
|
||||
var v = ta.value.trim(); if (!v) return;
|
||||
(st.m.cm[SLUG] = mine()).push({ t: v.slice(0, 200), ts: Date.now(), s: myStage() }); saveMe(st);
|
||||
ta.value = ''; ta.style.height = '24px'; bt.disabled = true; ta.blur(); paint();
|
||||
box.scrollIntoView({ block: 'start', behavior: 'smooth' });
|
||||
var v = ta.value.trim(); if (!v || bt.busy) return;
|
||||
if (!OID) { toast('请在小程序里打开后再评论'); return; }
|
||||
/* 11-03:先交后台审核,通过后才公开;审核中只有自己看得到 */
|
||||
bt.busy = true; bt.disabled = true;
|
||||
var h1 = document.querySelector('h1');
|
||||
fetch(API + '/comment?openid=' + encodeURIComponent(OID), { method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ kind: 'topic', target: SLUG, title: (h1 && h1.textContent.trim()) || document.title, text: v.slice(0, 200), stage: myStage() }) })
|
||||
.then(function (r) { return r.json(); }).then(function (j) {
|
||||
bt.busy = false;
|
||||
if (!j || j.code !== 200) { bt.disabled = !ta.value.trim(); toast((j && j.message) || '没发出去,稍后再试'); return; }
|
||||
RC.mine.unshift(j.result);
|
||||
ta.value = ''; ta.style.height = '24px'; bt.disabled = true; ta.blur(); paint();
|
||||
box.scrollIntoView({ block: 'start', behavior: 'smooth' });
|
||||
toast('已提交,审核通过后大家就能看到');
|
||||
}).catch(function () { bt.busy = false; bt.disabled = !ta.value.trim(); toast('网络不太好,稍后再试'); });
|
||||
});
|
||||
getJSON('../_shared/cm/' + SLUG + '.json?v=26110241').then(function (d) { L = d.c || []; paint(); }).catch(function () { paint(); });
|
||||
function toast(m) {
|
||||
var t = document.createElement('div'); t.textContent = m;
|
||||
t.style.cssText = 'position:fixed;left:50%;bottom:96px;transform:translateX(-50%);z-index:40;max-width:80%;padding:9px 16px;border-radius:99px;background:rgba(31,35,41,.86);color:#fff;font-size:13.5px;line-height:1.4;text-align:center';
|
||||
document.body.appendChild(t); setTimeout(function () { t.remove(); }, 2000);
|
||||
}
|
||||
fetch(API + '/comments?kind=topic&target=' + encodeURIComponent(SLUG) + (OID ? '&openid=' + encodeURIComponent(OID) : ''))
|
||||
.then(function (r) { return r.json(); }).then(function (j) { if (j && j.code === 200) { RC = j.result; paint(); } }).catch(function () {});
|
||||
getJSON('../_shared/cm/' + SLUG + '.json?v=26110242').then(function (d) { L = d.c || []; paint(); }).catch(function () { paint(); });
|
||||
}
|
||||
|
||||
function extras(el) {
|
||||
|
||||
Reference in New Issue
Block a user