广场帖子、专题页评论改为先交后台审核:审核中只自己可见并挂状态,通过后所有人可见,未通过显示原因(v26110242)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -188,5 +188,5 @@
|
||||
}
|
||||
/* feed.js 首页默认不加载(index.html 只引了 topics.js),这里按需拉一次 */
|
||||
if (window.GC_FEED) init();
|
||||
else { var fs = document.createElement('script'); fs.src = 'guangchang/feed.js?v=26110241'; fs.onload = fs.onerror = init; document.body.appendChild(fs); }
|
||||
else { var fs = document.createElement('script'); fs.src = 'guangchang/feed.js?v=26110242'; fs.onload = fs.onerror = init; document.body.appendChild(fs); }
|
||||
})();
|
||||
|
||||
@@ -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=26110241"></script>
|
||||
<script src="tests.js?v=26110241"></script>
|
||||
<script src="meta.js?v=26110242"></script>
|
||||
<script src="tests.js?v=26110242"></script>
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
@@ -414,6 +414,10 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
.ci-n .lk{margin-left:auto}
|
||||
.ci-t{margin:3px 0 0;font-size:14.5px;line-height:1.65;color:#2F2624;word-break:break-word}
|
||||
.ci-s{margin-top:3px;font-size:11.5px;color:#B8A49E}
|
||||
/* 11-03 用户评论要后台审核:自己的评论挂状态 */
|
||||
.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}
|
||||
.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}
|
||||
@@ -571,10 +575,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=26110241"></script>
|
||||
<script src="data.js?v=26110241"></script>
|
||||
<script src="feed.js?v=26110241"></script>
|
||||
<script src="ceshi/meta.js?v=26110241"></script>
|
||||
<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>
|
||||
(function () {
|
||||
'use strict';
|
||||
@@ -640,7 +644,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=26110241').then(function (r) { return r.json(); }).then(function (j) {
|
||||
fetch('cm.json?v=26110242').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) {
|
||||
@@ -663,8 +667,24 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
var liked = function (id) { return !!ME.like[id]; };
|
||||
var likeN = function (n) { return n.likes + (liked(n.id) ? 1 : 0); };
|
||||
var favN = function (n) { return Math.round(n.likes * .38) + 3 + (ME.fav[n.id] ? 1 : 0); };
|
||||
var myCm = function (id) { return ME.cm[id] || []; };
|
||||
var cmN = function (n) { return commentsOf(n).length + myCm(n.id).length; };
|
||||
/* 11-03 用户:评论要后台审核通过才对外公开。服务器 /plaza/comments:list = 别人已通过的;mine = 我在这篇下发的(含审核中 / 未通过)。
|
||||
ME.cm 里没有 id 的是 11-03 以前只存本机的旧评论,从没公开过,照旧只给自己看(标「仅自己可见」)。 */
|
||||
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 }; }) : [];
|
||||
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; };
|
||||
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) {
|
||||
if (!j || j.code !== 200) return;
|
||||
RC[n.id] = j.result;
|
||||
if (openId === n.id) { renderComments(n); syncBar(n); }
|
||||
}).catch(function () {});
|
||||
}
|
||||
|
||||
function toast(msg) {
|
||||
var t = $('#toast'); t.textContent = msg; t.classList.add('show');
|
||||
@@ -1121,8 +1141,9 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
function commentHTML(c, mine) {
|
||||
if (mine) {
|
||||
var st = c.s || myStage();
|
||||
return '<div class="ci mine"><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>' : '') + '</div></div>'; /* 11-02 自己的评论也不显示时间 */
|
||||
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 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>' : '';
|
||||
@@ -1141,7 +1162,9 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
var mine = myCm(n.id).slice().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; }
|
||||
$('#cml').innerHTML = mine.map(function (c) { return commentHTML(c, true); }).join('') + cs.map(function (c) { return commentHTML(c); }).join('');
|
||||
/* 别人发的、已审核通过的真实评论排在模拟评论前面 */
|
||||
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: [] }; });
|
||||
$('#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) {
|
||||
var lv = $('#blk'), fv = $('#bfv'), on = liked(n.id), fo = !!ME.fav[n.id];
|
||||
@@ -1170,7 +1193,7 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
'<div class="cm" id="cmw"><div class="cm-h" id="cmh"></div>' +
|
||||
'<div class="cm-in"><span class="me">我</span><button type="button" id="cmgo">留下你的温柔一句…</button></div>' +
|
||||
'<div id="cml"></div><div class="cm-end">— 没有更多评论了 —</div></div>';
|
||||
renderComments(n); syncBar(n);
|
||||
renderComments(n); syncBar(n); loadRC(n);
|
||||
$('#cin').value = ''; $('#bar').classList.remove('typing'); $('#csend').disabled = true;
|
||||
$('#dsc').scrollTop = 0; $('#dnav').classList.remove('on');
|
||||
var dt = $('#dt'); dt.classList.add('show'); dt.setAttribute('aria-hidden', 'false');
|
||||
@@ -1239,13 +1262,22 @@ button{font:inherit;color:inherit;border:0;background:none;padding:0;cursor:poin
|
||||
$('#csend').addEventListener('click', send);
|
||||
function send() {
|
||||
var n = NBY[openId], v = cin.value.trim();
|
||||
if (!n || !v) return;
|
||||
(ME.cm[n.id] = myCm(n.id)).push({ t: v.slice(0, 200), ts: Date.now(), s: myStage() });
|
||||
save(); haptic();
|
||||
cin.value = ''; $('#csend').disabled = true; cin.blur(); $('#bar').classList.remove('typing');
|
||||
renderComments(n); syncBar(n);
|
||||
var w = $('#cmw'); if (w) $('#dsc').scrollTo({ top: w.offsetTop - 50, behavior: 'smooth' });
|
||||
toast('评论已发出');
|
||||
if (!n || !v || send.busy) return;
|
||||
if (!OPENID) { toast('请在小程序里打开后再评论'); return; }
|
||||
/* 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() }) })
|
||||
.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);
|
||||
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('已提交,审核通过后大家就能看到');
|
||||
}).catch(function () { send.busy = false; $('#csend').disabled = !cin.value.trim(); toast('网络不太好,稍后再试'); });
|
||||
}
|
||||
|
||||
/* ================= 投稿(2026-11-01) =================
|
||||
|
||||
@@ -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=26110241"></script>
|
||||
<script src="../topics.js?v=26110242"></script>
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<title>兜爸心选 · 孕育陪伴</title>
|
||||
<!-- V:26110241 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 -->
|
||||
<!-- V:26110242 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 -->
|
||||
<link rel="stylesheet" href="mama-box.css">
|
||||
<link rel="stylesheet" href="night.css">
|
||||
<!-- 夜晚模式:首屏绘制前就按上次的选择加 class,避免先白后黑闪一下(开关在首页右上角 #nightBtn,逻辑见 app.js) -->
|
||||
@@ -2519,7 +2519,7 @@
|
||||
<script src="/_bridge/avatar-picker.js?v=26101105"></script>
|
||||
<script src="/_bridge/hand-icons.js?v=26101202"></script>
|
||||
<script src="js/zodiac-art.js"></script>
|
||||
<script src="guangchang/topics.js?v=26110241"></script>
|
||||
<script src="guangchang/topics.js?v=26110242"></script>
|
||||
<script src="js/app.js"></script>
|
||||
<script>
|
||||
/* 11-02 首页「孕妈广场」效果稿:地址带 ?gcv=1~6 时,把 #gcHome 换成 demo/gch/vN.css + vN.js 的版式并滚到这一块。
|
||||
@@ -2527,7 +2527,7 @@
|
||||
(function () {
|
||||
var m = location.search.match(/[?&]gcv=([1-6])(?:&|$)/);
|
||||
if (!m) window.__gcDefault = 1;
|
||||
var n = m ? m[1] : '6', l = document.createElement('link'), s = document.createElement('script'), q = m ? Date.now() : 'v=26110241';
|
||||
var n = m ? m[1] : '6', l = document.createElement('link'), s = document.createElement('script'), q = m ? Date.now() : 'v=26110242';
|
||||
l.rel = 'stylesheet'; l.href = 'demo/gch/v' + n + '.css?' + q;
|
||||
s.src = 'demo/gch/v' + n + '.js?' + q;
|
||||
if (m) s.onload = function () { setTimeout(function () { var el = document.getElementById('gcHome'); if (el) el.scrollIntoView({ block: 'center' }); }, 900); };
|
||||
@@ -2535,7 +2535,7 @@
|
||||
/* 11-02 品牌露出(用户定 4 处都要):默认加载,?brand=0 可关掉对比;⚠️ 上正式前和 V6 一起并进正式代码,别依赖 demo/ */
|
||||
if (!/[?&]brand=0/.test(location.search)) {
|
||||
var bl = document.createElement('link'), bs = document.createElement('script');
|
||||
bl.rel = 'stylesheet'; bl.href = 'demo/brand/brand.css?v=26110241'; bs.src = 'demo/brand/brand.js?v=26110241';
|
||||
bl.rel = 'stylesheet'; bl.href = 'demo/brand/brand.css?v=26110242'; bs.src = 'demo/brand/brand.js?v=26110242';
|
||||
document.head.appendChild(bl); document.body.appendChild(bs);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
|
||||
var VER = '26110241';
|
||||
var VER = '26110242';
|
||||
const $ = (s, c) => (c || document).querySelector(s);
|
||||
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
|
||||
|
||||
|
||||
@@ -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