孕期档案头像改用面板 sync:false + commit 正式写法 v26101032

Co-Authored-By: AI 助手
This commit is contained in:
karlcarlo
2026-10-11 15:49:52 +00:00
parent a55a4e26c8
commit b0b0469983
2 changed files with 8 additions and 19 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26101031';
var VER = '26101032';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -1878,23 +1878,16 @@
这里 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:sync:false 选完只回调;保存时 commit 写共享资料、派发 mmbox:avatar)。
选中的是正式 URL,记在 pickedAvatar,保存时一起 PUT 进首页档案;面板没加载上才退回系统选图。 */
function openAvatarPanel() {
if (window.avatarPicker && window.avatarPicker.open) {
window.avatarPicker.open({
current: avBig.classList.contains('has-img') ? avPreview.src : '',
accent: '#F4593C', accentSoft: '#FDECE7',
/* 2026-10-11 用户:点「保存资料」后才让所有应用同步头像 → 面板只回调,保存时 commit */
sync: false,
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');
@@ -1969,13 +1962,9 @@
上传失败则跳过头像字段(昵称/孕育照存)。断网/接口失败静默,本地已生效。 ---- */
var _oid = hashParam('openid');
var _wasEmpty = state.pregEmpty; /* 新用户完善资料后 → 重载拉真实孕周 */
/* 保存时才把头像写进共享资料(auth/profile),其它应用读 user-center/info 就会跟着换 */
/* 保存时才把头像写进共享资料:avatarPicker.commit 已授权才写 auth/profile,并派发 mmbox:avatar */
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) {}
if (url && window.avatarPicker && window.avatarPicker.commit) window.avatarPicker.commit(url);
}
function _putProfile(avatarUrl) {
if (!_oid) return;