fix(h5): show raw skin age, support Harmony touch pickers and add WeChat logout

This commit is contained in:
xsl
2026-10-13 16:12:54 +08:00
parent 4e42e33994
commit e71368db6d
23 changed files with 1984 additions and 1325 deletions
+30 -4
View File
@@ -64,7 +64,7 @@
}
/* ─── 屏幕管理:页面内不放返回按钮,前进时 pushState,微信/浏览器返回键经 popstate 回到上一屏 ─── */
var currentScreen = 's-login';
var currentScreen = 's-login', reportOwner = null, logoutBusy = false;
var fontStylesLoaded = false;
function loadAppFont() {
if (fontStylesLoaded) return;
@@ -79,6 +79,11 @@
label.textContent = user ? (user.kind === 'wechat' ? '微信已登录' : '游客模式') : '尚未登录';
label.parentElement.dataset.kind = user ? user.kind : '';
});
document.querySelectorAll('[data-action="logout-wechat"]').forEach(function (button) {
button.hidden = !user || user.kind !== 'wechat';
button.disabled = logoutBusy;
button.textContent = logoutBusy ? '正在退出…' : '退出登录';
});
}
function loginSucceeded() {
showScreen('s-splash', 'replace');
@@ -94,6 +99,7 @@
}
function showScreen(id, nav) { // nav: 'push' 新增历史 | 'replace' 替换当前历史 | 缺省不动历史
if (id !== 's-login' && !AccountClient.user() && !(/[?&]mock=1/.test(location.search))) id = 's-login';
if (id === 's-report' && !IS_MOCK && reportOwner !== (AccountClient.user() && AccountClient.user().id)) id = 's-splash';
if (id === 's-profile' || profileOwner !== ProfileStore.key(AccountClient.user())) restoreProfile();
if (['s-profile', 's-cam', 's-report'].includes(id)) loadAppFont();
if (id === 's-profile' || id === 's-cam') prepareScanArtwork();
@@ -1401,6 +1407,7 @@
}
function renderReport(vm, frontPhoto, sidePhoto, payload) {
reportOwner = AccountClient.user() && AccountClient.user().id;
// 头部:综合评分(vm.total 缺失时回退三维度 S 均分×10)
var total = vm.total;
if (total == null) {
@@ -1412,10 +1419,11 @@
$('#stat-score').innerHTML = total != null ? '<b>' + total + '</b><i>分</i>' : '<b>--</b><i>分</i>';
var ring = $('#ring-fg');
ring.style.strokeDashoffset = total != null ? 326.73 * (1 - Math.max(0, Math.min(100, total)) / 100) : 326.73;
$('#stat-age').innerHTML = vm.skinAgeDisplay != null ? '<b>' + vm.skinAgeDisplay + '</b><i>岁</i>' : '<b>--</b><i>岁</i>';
var displayedAge = SkinScore.reportSkinAge(vm, payload && payload.result);
$('#stat-age').innerHTML = displayedAge != null ? '<b>' + displayedAge + '</b><i>岁</i>' : '<b>--</b><i>岁</i>';
// 肌龄对比胶囊(新版设计「比实际年龄年轻2岁」);缺实际年龄或肌龄时不展示
var pill = $('#stat-age-note');
var diff = vm.skinAgeDisplay != null && vm.realAge ? vm.skinAgeDisplay - vm.realAge : null;
var diff = displayedAge != null && vm.realAge ? displayedAge - vm.realAge : null;
pill.hidden = diff == null;
pill.textContent = diff == null ? '' : diff < 0 ? '比实际年龄年轻' + (-diff) + '岁' : diff > 0 ? '比实际年龄大' + diff + '岁' : '与实际年龄相当';
@@ -1618,6 +1626,7 @@
},
'history': function () { openHistory(); },
'history-retry': function () { renderHistoryList(); },
'logout-wechat': logoutWechat,
'open-wechat-login': function () {
historySeq++;
$('#login-consent').checked = false;
@@ -1668,8 +1677,9 @@
var btn = event.target.closest('[data-report-id]');
if (!btn || btn.disabled) return;
btn.disabled = true;
var seq = historySeq, owner = AccountClient.user() && AccountClient.user().id;
AccountClient.request('api/reports/' + encodeURIComponent(btn.dataset.reportId)).then(function (data) {
if (currentScreen !== 's-history') return;
if (currentScreen !== 's-history' || seq !== historySeq || owner !== (AccountClient.user() && AccountClient.user().id)) return;
var entry = data.report;
renderReport(entry.vm, entry.photos[0], entry.photos[1], Object.assign({}, entry.payload, { presentation: entry.presentation }));
showScreen('s-report', 'push');
@@ -1677,6 +1687,22 @@
});
var loginBusy = false;
function logoutWechat() {
var user = AccountClient.user();
if (logoutBusy || !user || user.kind !== 'wechat') return;
if (!window.confirm('确认退出微信登录?\n历史报告将保留,重新微信登录后可查看。')) return;
logoutBusy = true; renderAccountStatus();
AccountClient.logout().then(function () {
historySeq++; reportOwner = null;
$('#history-list').textContent = ''; $('#history-count').textContent = ''; $('#identity-note').textContent = '';
$('#login-consent').checked = false;
$('#login-message').textContent = '已退出微信登录,历史报告已保留。';
showScreen('s-login', 'replace');
$('[data-action="login-wechat"]').focus({ preventScroll: true });
}).catch(function (e) { toast('退出失败:' + e.message); }).finally(function () {
logoutBusy = false; renderAccountStatus();
});
}
function loginAllowed() {
if (loginBusy) return false;
if (!$('#login-consent').checked) { toast('请先阅读并同意用户协议和隐私政策'); return false; }