feat(rednote): add isolated persistent browser H5 entry
This commit is contained in:
+26
-10
@@ -3,6 +3,8 @@
|
||||
'use strict';
|
||||
|
||||
var $ = function (sel, root) { return (root || document).querySelector(sel); };
|
||||
var REDNOTE = !!(window.JuziEntry && window.JuziEntry.mode === 'rednote');
|
||||
function savedAccount(user) { return !!(user && (user.kind === 'wechat' || (REDNOTE && user.kind === 'browser_persistent'))); }
|
||||
|
||||
var captureJourney = null;
|
||||
function beginCaptureJourney() {
|
||||
@@ -96,13 +98,13 @@
|
||||
function renderAccountStatus() {
|
||||
var user = AccountClient.user();
|
||||
document.querySelectorAll('[data-auth-status]').forEach(function (label) {
|
||||
label.textContent = user ? (user.kind === 'wechat' ? '微信已登录' : '游客模式') : '尚未登录';
|
||||
label.textContent = user ? (user.kind === 'wechat' ? '微信已登录' : REDNOTE ? (savedAccount(user) ? '浏览器已登录' : '浏览器体验') : '游客模式') : '尚未登录';
|
||||
label.parentElement.dataset.kind = user ? user.kind : '';
|
||||
});
|
||||
document.querySelectorAll('[data-action="logout-wechat"]').forEach(function (button) {
|
||||
button.hidden = !user || user.kind !== 'wechat';
|
||||
button.hidden = !savedAccount(user);
|
||||
button.disabled = logoutBusy;
|
||||
button.textContent = logoutBusy ? '正在退出…' : '退出登录';
|
||||
button.textContent = logoutBusy ? '正在退出…' : REDNOTE ? '清除本机身份' : '退出登录';
|
||||
});
|
||||
}
|
||||
function loginSucceeded() {
|
||||
@@ -1208,7 +1210,7 @@
|
||||
}
|
||||
renderReport(vm, photos[0], photos[1], payload, photos); // photos 已统一为正/左/右
|
||||
if (IS_MOCK) toast('演示报告,不保存至我的报告');
|
||||
else if (AccountClient.user() && AccountClient.user().kind !== 'wechat') toast('游客报告仅供本次查看,不保存历史记录');
|
||||
else if (AccountClient.user() && !savedAccount(AccountClient.user())) toast('游客报告仅供本次查看,不保存历史记录');
|
||||
else if (!payload.report_saved) toast('报告生成成功,但保存失败,请勿关闭页面并联系管理员');
|
||||
photos = []; // 报告已渲染(图片 src 已挂):释放三连拍 dataURL 内存
|
||||
showScreen('s-report', 'replace'); // 报告顶替拍照页:返回键回档案页,不再回到相机
|
||||
@@ -1934,6 +1936,7 @@
|
||||
'history-retry': function () { renderHistoryList(); },
|
||||
'logout-wechat': logoutWechat,
|
||||
'open-wechat-login': function () {
|
||||
if (REDNOTE) return;
|
||||
historySeq++;
|
||||
$('#login-consent').checked = false;
|
||||
$('#login-message').textContent = '微信登录后,后续检测报告可保存和跨手机查看。';
|
||||
@@ -1952,7 +1955,12 @@
|
||||
var historySeq = 0;
|
||||
function renderHistoryList() {
|
||||
var seq = ++historySeq, box = $('#history-list');
|
||||
if (!AccountClient.user() || AccountClient.user().kind !== 'wechat') {
|
||||
if (!savedAccount(AccountClient.user())) {
|
||||
if (REDNOTE) {
|
||||
$('#history-count').textContent = '暂无历史报告';
|
||||
$('#identity-note').textContent = '同意隐私说明并完成检测后,将在此浏览器保留最近 5 份报告。';
|
||||
box.textContent = '请返回首页开始检测。'; return;
|
||||
}
|
||||
$('#history-count').textContent = '游客模式不保存检测记录';
|
||||
$('#identity-note').textContent = '游客不保存个人信息和检测记录,报告仅供本次查看。微信登录后可保留历史报告。';
|
||||
box.innerHTML = '<p class="history-empty">暂无历史报告<br>请使用微信登录,后续检测报告会自动保存。<br><button class="history-retry" data-action="open-wechat-login">微信登录,保存报告</button></p>';
|
||||
@@ -1962,7 +1970,7 @@
|
||||
AccountClient.request('api/reports').then(function (data) {
|
||||
if (seq !== historySeq) return;
|
||||
$('#history-count').textContent = '您最近已进行过' + data.total + '次面部问题检测';
|
||||
$('#identity-note').textContent = '保留最近 5 份报告,同一微信账号可跨手机查看。';
|
||||
$('#identity-note').textContent = REDNOTE ? '保留最近 5 份报告。请使用同一浏览器查看;清除浏览器数据或更换设备后无法恢复。' : '保留最近 5 份报告,同一微信账号可跨手机查看。';
|
||||
if (!data.items.length) { box.innerHTML = '<p class="history-empty">暂无报告<br>完成一次检测后,报告会自动保存在这里。</p>'; return; }
|
||||
box.innerHTML = data.items.map(function (item) {
|
||||
var date = new Date(item.created_at).toLocaleDateString('sv-SE');
|
||||
@@ -1995,13 +2003,17 @@
|
||||
var loginBusy = false;
|
||||
function logoutWechat() {
|
||||
var user = AccountClient.user();
|
||||
if (logoutBusy || !user || user.kind !== 'wechat') return;
|
||||
if (!window.confirm('确认退出微信登录?\n历史报告将保留,重新微信登录后可查看。')) return;
|
||||
if (logoutBusy || !savedAccount(user)) return;
|
||||
if (!window.confirm(REDNOTE ? '确认清除本机浏览器身份?\n清除后将无法恢复该身份的历史报告,下次体验会生成新身份。' : '确认退出微信登录?\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;
|
||||
if (REDNOTE) {
|
||||
agreed = false; $('#privacy-check').classList.remove('checked');
|
||||
AccountClient.guest(); showScreen('s-splash', 'replace'); return;
|
||||
}
|
||||
$('#login-message').textContent = '已退出微信登录,历史报告已保留。';
|
||||
showScreen('s-login', 'replace');
|
||||
$('[data-action="login-wechat"]').focus({ preventScroll: true });
|
||||
@@ -2020,6 +2032,7 @@
|
||||
showScreen('s-splash', 'replace');
|
||||
}
|
||||
function loginWechat() {
|
||||
if (REDNOTE) return;
|
||||
if (!loginAllowed()) return;
|
||||
if (!/MicroMessenger/i.test(navigator.userAgent)) {
|
||||
$('#login-message').textContent = '请在微信内打开本页面,或选择免登录体验。';
|
||||
@@ -2074,11 +2087,14 @@
|
||||
history.replaceState({ screen: 's-login' }, ''); // 刷新后从启动页开始,历史栈的屏标记与之对齐
|
||||
renderCamStep();
|
||||
if (!(/[?&]mock=1/.test(location.search) && /[?&]screen=report/.test(location.search))) {
|
||||
var loginError = /[?&]login_error=([^&#]*)/.exec(location.search);
|
||||
var loginSuccess = /[?&]login=success(?:&|$)/.test(location.search);
|
||||
var loginError = REDNOTE ? null : /[?&]login_error=([^&#]*)/.exec(location.search);
|
||||
var loginSuccess = !REDNOTE && /[?&]login=success(?:&|$)/.test(location.search);
|
||||
var oauthReturn = !!loginError || loginSuccess;
|
||||
loginBusy = true;
|
||||
AccountClient.init({ restoreBrowser: !oauthReturn }).then(function () {
|
||||
if (REDNOTE && !AccountClient.user()) {
|
||||
AccountClient.guest(); showScreen('s-splash', 'replace'); return;
|
||||
}
|
||||
if (loginError) {
|
||||
var code = loginError[1];
|
||||
$('#login-message').textContent = code === 'state'
|
||||
|
||||
Reference in New Issue
Block a user