我的页兜豆余额改实心橘色胶囊;孕期档案点头像弹统一头像面板(预设 / 相册 / 微信头像) v26101027

Co-Authored-By: AI 助手
This commit is contained in:
karlcarlo
2026-10-11 15:10:20 +00:00
parent 77296cd1c4
commit ef73ea7463
3 changed files with 40 additions and 10 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26101026';
var VER = '26101027';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -1214,6 +1214,7 @@
};
}
let pickedAvatar = ''; /* 孕期档案里从头像面板选中的正式 URL,见 openAvatarPanel */
const pgName = $('#pgName'), pgDue = $('#pgDue'),
pgWeek = $('#pgWeek'), pgDay = $('#pgDay'), pgHint = $('#pgHint');
@@ -1255,6 +1256,7 @@
/* 打开资料弹窗时的表单回填:全部以服务端档案为准(最后写入者胜)。
新用户(未完善资料):昵称/小名/预产期/孕周全空 + 孕周锁定,只留 placeholder。 */
function fillProfileForm() {
pickedAvatar = '';
$('#pfName').value = state.userName || '';
/* 方案A(2026-10-10):未授权 → 妈妈栏换成授权提示,旧昵称/头像不露出 */
var _ua = state.authorized === false;
@@ -1870,12 +1872,29 @@
/* 点大圆 → 转交给隐藏的 file input。openModal 里会 focus 第一个输入框,
这里 avFile 排在 pfName 前面,所以 openModal 用的选择器只取 .modal-ta/input
可能命中 file input——用 :not([type=file]) 排除掉,见 openModal */
avBig.addEventListener('click', e => { e.stopPropagation(); avFile.click(); });
/* 2026-10-11 用户:点头像弹预设选项,也能从相册上传、用微信头像 → 走统一头像面板 avatarPicker
(/_bridge/avatar-picker.js:选完自己上传、写回共享资料、派发 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',
onPick: function (url) {
pickedAvatar = url;
avFile.value = '';
avPreview.src = url; avBig.classList.add('has-img');
haptic();
}
});
} else avFile.click();
}
avBig.addEventListener('click', e => { e.stopPropagation(); openAvatarPanel(); });
/* 孕期档案里头像是一整行,点行上任何地方都换头像 */
const pfMeRow = $('#pfMe');
if (pfMeRow) {
pfMeRow.addEventListener('click', e => { if (e.target !== avFile) avFile.click(); });
pfMeRow.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); avFile.click(); } });
pfMeRow.addEventListener('click', e => { if (e.target !== avFile) openAvatarPanel(); });
pfMeRow.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); openAvatarPanel(); } });
}
avFile.addEventListener('change', () => {
@@ -1885,6 +1904,7 @@
if (f.size > 8 * 1024 * 1024) { toast('图片太大了,换一张小于 8MB 的'); return; }
const r = new FileReader();
/* 读成 data URI 就地预览:产物是单文件、没有后端,不做真正的上传 */
pickedAvatar = '';
r.onload = () => { avPreview.src = r.result; avBig.classList.add('has-img'); haptic(); };
r.onerror = () => toast('这张图读不出来,换一张试试');
r.readAsDataURL(f);
@@ -1967,7 +1987,12 @@
});
}
var newAvatarFile = (avFile.files && avFile.files[0]) || null;
if (newAvatarFile && avBig.classList.contains('has-img')) {
if (pickedAvatar && !_unauth) {
/* 头像面板选的已经是正式 URL(预设图 / 面板自己上传过),直接写 */
$('#meAvatar').classList.add('has-img');
_putProfile(pickedAvatar);
pickedAvatar = '';
} else if (newAvatarFile && avBig.classList.contains('has-img')) {
var fd = new FormData();
fd.append('file', newAvatarFile, newAvatarFile.name || 'avatar.png');
fetch('/api/upload', { method: 'POST', body: fd })