首页接入统一兜豆账本新人欢迎礼 (v26101006)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 05:13:39 +00:00
parent e82a62771e
commit 7f1a7d5aaa
3 changed files with 52 additions and 2 deletions

View File

@@ -7,7 +7,7 @@
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
<title>兜爸心选 · 孕育陪伴</title> <title>兜爸心选 · 孕育陪伴</title>
<!-- V:26101005 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 --> <!-- V:26101006 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 -->
<link rel="stylesheet" href="mama-box.css"> <link rel="stylesheet" href="mama-box.css">
<link rel="stylesheet" href="night.css"> <link rel="stylesheet" href="night.css">
<!-- 夜晚模式:首屏绘制前就按上次的选择加 class,避免先白后黑闪一下(开关在首页右上角 #nightBtn,逻辑见 app.js) --> <!-- 夜晚模式:首屏绘制前就按上次的选择加 class,避免先白后黑闪一下(开关在首页右上角 #nightBtn,逻辑见 app.js) -->
@@ -1920,6 +1920,17 @@
<div class="modal-foot"><button class="dl-btn main" id="bxPrizeOk">太好了</button></div> <div class="modal-foot"><button class="dl-btn main" id="bxPrizeOk">太好了</button></div>
</section> </section>
<!-- 新人欢迎礼(2026-10-10):统一兜豆账本 welcome 规则首次发放时弹一次;豆数用接口返回的 granted -->
<section class="modal bx-prize wg-modal" id="modalWelcome" role="dialog" aria-modal="true" aria-labelledby="wgT">
<div class="bx-prize-ico" aria-hidden="true">🎁</div>
<h3 id="wgT">新人欢迎礼 <b class="wg-n">+<span id="wgN">50</span></b> 兜豆</h3>
<p>已经存进你的兜豆账户,可以去兑换好物啦</p>
<div class="modal-foot">
<button class="dl-btn ghost" data-modal="close">收下了</button>
<button class="dl-btn main" id="wgGo">去看看</button>
</div>
</section>
<section class="modal pf-modal" id="modalProfile" data-autofocus="off" role="dialog" aria-modal="true" aria-labelledby="modalProfileTitle"> <section class="modal pf-modal" id="modalProfile" data-autofocus="off" role="dialog" aria-modal="true" aria-labelledby="modalProfileTitle">
<div class="modal-head"> <div class="modal-head">
<h3 id="modalProfileTitle">我的资料</h3> <h3 id="modalProfileTitle">我的资料</h3>

View File

@@ -3,7 +3,7 @@
(function () { (function () {
'use strict'; 'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */ /* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26101005'; var VER = '26101006';
const $ = (s, c) => (c || document).querySelector(s); const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s)); const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -5254,6 +5254,40 @@
}).catch(function () {}); }).catch(function () {});
} }
loadDou(); loadDou();
/* ---------- 新人欢迎礼(2026-10-10 用户定,「首页 / 小程序后台」会话 375797cf 提供账本口径) ----------
进首页就调统一兜豆账本:/doudou-ledger/api/auth/login {app:'box-app', openid, unionid} 换 token →
/me/report {rule:'welcome'}。账本保证每人只发一次:
· granted>0 且 duplicate=false → 弹「新人欢迎礼 +N 兜豆」(N 用返回的 granted,不写死),再按账本余额刷新兑换条;
· duplicate=true → 什么都不显示;接口失败 → 静默,下次进来再调;没有 openid(匿名)→ 不调。
同源走 mp 反代(/doudou-ledger/ 已加进 nginx 统一反代),不跨域。 */
(function welcomeGift() {
const oid = hashParam('openid'), uid = hashParam('unionid');
if (!oid || DEMO) return;
const LEDGER = '/doudou-ledger/api';
fetch(LEDGER + '/auth/login', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ app: 'box-app', openid: oid, unionid: uid || null })
}).then(function (r) { return r.ok ? r.json() : null; }).then(function (j) {
if (!j || !j.token) return null;
return fetch(LEDGER + '/me/report', {
method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + j.token },
body: JSON.stringify({ rule: 'welcome' })
}).then(function (r) { return r.ok ? r.json() : null; });
}).then(function (res) {
if (!res || res.duplicate || !(res.granted > 0)) return;
loadDou(); // 余额以账本为准:领完立刻重拉,不在前端加减
const show = function () {
$('#wgN').textContent = res.granted;
/* 进页面时可能已经有别的弹窗(如完善资料引导)开着 → 不抢,改成一条 toast */
if (openedModal) toast('新人欢迎礼 +' + res.granted + ' 兜豆,已到账');
else openModal('modalWelcome');
};
setTimeout(show, 900);
}).catch(function () {});
})();
$('#wgGo').addEventListener('click', function () { closeModal(); openExchange(); });
document.addEventListener('visibilitychange', function () { document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'visible') loadDou(); if (document.visibilityState === 'visible') loadDou();
}); });

View File

@@ -4729,3 +4729,8 @@ a.skip:focus{left:16px;top:16px}
/* 「我的资料」弹窗里的退出登录(2026-10-10) */ /* 「我的资料」弹窗里的退出登录(2026-10-10) */
.pf-logout{display:block;width:100%;margin-top:14px;padding:12px;border-radius:14px;background:#FFF4F2;font-size:14px;font-weight:700;color:#C33A2E;text-align:center} .pf-logout{display:block;width:100%;margin-top:14px;padding:12px;border-radius:14px;background:#FFF4F2;font-size:14px;font-weight:700;color:#C33A2E;text-align:center}
/* 新人欢迎礼弹窗(2026-10-10) */
.wg-modal .wg-n{color:var(--brand)}
.wg-modal .modal-foot{display:flex;gap:10px}
.wg-modal .modal-foot .dl-btn{flex:1}