孕期档案头像:点保存资料后才同步到所有应用 v26101029

Co-Authored-By: AI 助手
This commit is contained in:
karlcarlo
2026-10-11 15:25:12 +00:00
parent b32bda8375
commit 02ac6a9a3d
2 changed files with 22 additions and 3 deletions

View File

@@ -7,7 +7,7 @@
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>兜爸心选 · 孕育陪伴</title>
<!-- V:26101028 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 -->
<!-- V:26101029 缓存版本标记:改 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) -->

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26101028';
var VER = '26101029';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -1873,7 +1873,7 @@
这里 avFile 排在 pfName 前面,所以 openModal 用的选择器只取 .modal-ta/input
可能命中 file input——用 :not([type=file]) 排除掉,见 openModal */
/* 2026-10-11 用户:点头像弹预设选项,也能从相册上传、用微信头像 → 走统一头像面板 avatarPicker
(/_bridge/avatar-picker.js:选完自己上传、写回共享资料、派发 mmbox:avatar)。
(/_bridge/avatar-picker.js:选完自己上传、派发 mmbox:avatar;共享资料改到保存时写)。
选中的是正式 URL,记在 pickedAvatar,保存时一起 PUT 进首页档案;面板没加载上才退回系统选图。 */
function openAvatarPanel() {
if (window.avatarPicker && window.avatarPicker.open) {
@@ -1881,6 +1881,15 @@
current: avBig.classList.contains('has-img') ? avPreview.src : '',
accent: '#F4593C', accentSoft: '#FDECE7',
onPick: function (url) {
/* 2026-10-11 用户:点「保存资料」后才让所有应用同步头像。面板 done() 里紧接着 onPick
会同步调 syncShared → wxAuth.identity(),这里让那一次拿到空身份,面板就不写共享资料;
真正的共享写入放到 #pfSave 里(syncSharedAvatar)。 */
var wa = window.wxAuth;
if (wa && wa.identity) {
var _id = wa.identity, _back = function () { wa.identity = _id; };
wa.identity = function () { _back(); return {}; };
setTimeout(_back, 0);
}
pickedAvatar = url;
avFile.value = '';
avPreview.src = url; avBig.classList.add('has-img');
@@ -1955,6 +1964,14 @@
上传失败则跳过头像字段(昵称/孕育照存)。断网/接口失败静默,本地已生效。 ---- */
var _oid = hashParam('openid');
var _wasEmpty = state.pregEmpty; /* 新用户完善资料后 → 重载拉真实孕周 */
/* 保存时才把头像写进共享资料(auth/profile),其它应用读 user-center/info 就会跟着换 */
function syncSharedAvatar(url) {
var id = (window.wxAuth && wxAuth.identity && wxAuth.identity()) || {};
if (!url || !id.openid) return;
var q = '?openid=' + encodeURIComponent(id.openid) + (id.unionid ? '&unionid=' + encodeURIComponent(id.unionid) : '');
fetch('/api/mp/public/auth/profile' + q + '&avatar=' + encodeURIComponent(url), { method: 'POST' }).catch(function () {});
try { window.dispatchEvent(new CustomEvent('mmbox:avatar', { detail: { url: url, source: 'save', for: 'mom' } })); } catch (e) {}
}
function _putProfile(avatarUrl) {
if (!_oid) return;
var body = {
@@ -1991,6 +2008,7 @@
/* 头像面板选的已经是正式 URL(预设图 / 面板自己上传过),直接写 */
$('#meAvatar').classList.add('has-img');
_putProfile(pickedAvatar);
syncSharedAvatar(pickedAvatar);
pickedAvatar = '';
} else if (newAvatarFile && avBig.classList.contains('has-img')) {
var fd = new FormData();
@@ -2000,6 +2018,7 @@
.then(function (res) {
var url = res && res.result && res.result.url;
_putProfile(url || '');
if (!_unauth) syncSharedAvatar(url);
})
.catch(function () { _putProfile(''); });
} else {