feat: 完善淘宝小程序拍照、报告与登录流程

接入本地实时识别和自动三连拍,调整报告裁切、商品跳转、分享标题及居中页眉;完善游客会话、后台渠道隔离、部署脚本与回归测试。
This commit is contained in:
xsl
2026-11-04 15:07:51 +08:00
parent 381da60ae4
commit 774376fa16
147 changed files with 17420 additions and 597 deletions
+4
View File
@@ -31,6 +31,7 @@ page { background: #EFEFEF; }
position: relative;
z-index: 1;
padding: 56rpx 34rpx 72rpx; /* calc(28*u) calc(17*u) calc(36*u) */
padding-top: max(56rpx, env(safe-area-inset-top));
box-sizing: border-box;
}
@@ -157,6 +158,7 @@ page { background: #EFEFEF; }
background: #F5F078;
border-radius: 10rpx; /* calc(5 * var(--u)) */
width: 160rpx; /* calc(80 * var(--u)) */
height: 46rpx; /* 覆盖小程序 button 默认高度,与 H5 23 设计像素一致 */
min-height: 46rpx; /* calc(23 * var(--u)) */
font-size: 12px;
color: #282828;
@@ -206,3 +208,5 @@ page { background: #EFEFEF; }
box-sizing: border-box;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.session-guard { position: relative; z-index: 10; padding: 120rpx 40rpx; text-align: center; font-size: 13px; line-height: 1.8; color: #707070; }
.session-guard .btn-primary { margin: 32rpx auto 0; }
+10 -3
View File
@@ -1,10 +1,16 @@
<import src="../../components/brand-header.axml" />
<template is="brand-header" data="{{brandHeader: brandHeader}}" />
<!-- ═════ 历史报告 —— 对照 H5 index.html #s-history(L32-42) 与 app.js renderHistoryList()(L1956-1985) ═════ -->
<view class="history">
<view class="history" style="padding-top:{{brandHeader.height}}px;">
<view class="session-guard" a:if="{{identityChecking || identityError}}">
<view>{{identityChecking ? '正在确认当前淘宝账号…' : identityError}}</view>
<button a:if="{{identityError}}" class="btn-primary" onTap="onRetryIdentity">重新验证</button>
</view>
<!-- H5 #s-history{background:#efefef url(bg-history-h5) center/cover fixed} -->
<image class="history-bg" src="{{bgUrl}}" mode="aspectFill" />
<!-- H5 .history-content -->
<view class="history-content">
<view class="history-content" hidden="{{identityChecking || identityError}}">
<view class="report-title">您的报告</view>
<!-- H5 .account-status.account-status-history -->
@@ -31,7 +37,8 @@
<view class="history-list-note" a:if="{{!loading && error}}">{{error}},请刷新列表重试。</view>
<view class="history-empty" a:if="{{!loading && !error && !items.length}}">
<view>暂无检测报告</view>
<view>完成一次检测后,报告会自动保存在这里。</view>
<view>{{guest ? '游客报告不保存,淘宝登录后可保存之后生成的报告。' : '完成一次检测后,报告会自动保存在这里。'}}</view>
<button a:if="{{guest}}" class="history-retry" onTap="onLogin">淘宝账号登录</button>
</view>
<view class="card history-item" a:for="{{items}}" a:key="id" data-id="{{item.id}}" onTap="onOpen">
<view class="history-item-line"><text class="history-item-label">测试时间</text> {{item.date}}</view>
+57 -16
View File
@@ -10,21 +10,49 @@ function formatDate(value) {
return d.getFullYear() + '-' + pad2(d.getMonth() + 1) + '-' + pad2(d.getDate());
}
Page({
Page(require('../../utils/page-header').page({
onShareAppMessage: function () { return require('../../utils/share').message(); },
data: {
bgUrl: api.assetUrl('img/ui-20261009/bg-history-h5.jpg'),
items: [], loading: false, error: '',
signedIn: false, accountLabel: '尚未登录',
signedIn: false, guest: false, accountLabel: '尚未登录',
countText: '正在读取报告…', // H5 #history-count 初值
identityNote: '',
toastText: '', toastOn: false
toastText: '', toastOn: false, identityChecking: true, identityError: ''
},
onShow: function () {
if (!api.user()) { this.setData({ items: [] }); my.redirectTo({ url: '/pages/splash/splash' }); return; }
this.setData({ signedIn: true, accountLabel: '淘宝已登录' });
this.load();
this.visible = true;
if (!api.user()) { this.setData({ items: [] }); my.redirectTo({ url: '/pages/login/login' }); return; }
this.ownerId = api.user().id;
if (api.user().kind === 'taobao_guest') { this.showGuest(); return; }
var that = this, owner = this.ownerId, seq = this.identitySeq = (this.identitySeq || 0) + 1;
this.identityPending = true; this.setData({ identityChecking: true, identityError: '' });
return (typeof api.restore === 'function' ? api.restore() : Promise.resolve(api.user())).then(function (user) {
if (!that.visible || seq !== that.identitySeq) return;
if (!user || user.id !== owner) { that.setData({ items: [], countText: '', identityNote: '' }); my.redirectTo({ url: '/pages/login/login' }); return; }
that.identityPending = false;
that.setData({ identityChecking: false, signedIn: true, guest: false, accountLabel: '淘宝已登录' });
that.load();
}).catch(function (err) {
if (!that.visible || seq !== that.identitySeq) return;
if (err.status === 401 || !api.user() || api.user().id !== owner) {
that.setData({ items: [], countText: '', identityNote: '' }); my.redirectTo({ url: '/pages/login/login' }); return;
}
that.setData({ identityChecking: false, identityError: '网络异常,暂时无法确认当前账号,请重试。' });
});
},
onUnload: function () { this.closed = true; },
onHide: function () {
this.visible = false; this.closed = true; this.loadSeq = (this.loadSeq || 0) + 1; this.identitySeq = (this.identitySeq || 0) + 1;
if (api.user() && api.user().kind !== 'taobao_guest') { this.identityPending = true; this.setData({ identityChecking: true, identityError: '' }); }
},
onUnload: function () { this.onHide(); clearTimeout(this.toastTimer); },
showGuest: function () {
this.identityPending = false;
this.setData({ guest: true, signedIn: false, accountLabel: '游客体验', items: [], loading: false, error: '',
identityChecking: false, identityError: '', countText: '游客报告不计入历史记录', identityNote: '游客报告仅供本次查看,不保存照片、档案或历史报告。' });
},
onRetryIdentity: function () { return this.onShow(); },
onLogin: function () { my.navigateTo({ url: '/pages/login/login?switch=1' }); },
// H5 .toast
toast: function (msg) {
@@ -37,11 +65,16 @@ Page({
},
load: function () {
if (this.identityPending) return;
var that = this;
if (!api.user()) { my.redirectTo({ url: '/pages/login/login' }); return; }
if (api.user().kind === 'taobao_guest') { this.showGuest(); return; }
var owner = api.user().id, seq = this.loadSeq = (this.loadSeq || 0) + 1;
this.closed = false;
this.setData({ loading: true, error: '' });
this.setData({ guest: false, loading: true, error: '', items: [] });
function current() { return !that.closed && seq === that.loadSeq && api.user() && api.user().id === owner; }
api.request('reports').then(function (data) {
if (that.closed) return;
if (!current()) return;
that.setData({
countText: '您最近已进行过' + data.total + '次面部问题检测',
identityNote: '保留最近 5 份报告,同一淘宝账号可跨手机查看。',
@@ -50,24 +83,32 @@ Page({
})
});
}).catch(function (err) {
if (!that.closed) that.setData({ error: err.message, countText: '暂时无法读取' });
}).then(function () { if (!that.closed) that.setData({ loading: false }); });
if (current()) that.setData({ error: err.message, countText: '暂时无法读取' });
else if (!api.user() && err.status === 401 && that.visible) my.redirectTo({ url: '/pages/login/login' });
}).then(function () { if (current()) that.setData({ loading: false }); });
},
onOpen: function (e) {
if (this.identityPending) return;
if (this.data.loading) return;
if (!api.user() || api.user().kind === 'taobao_guest') return;
var id = e.currentTarget.dataset.id;
if (!id) return;
var that = this;
var owner = api.user().id, seq = this.loadSeq = (this.loadSeq || 0) + 1;
this.closed = false;
this.setData({ loading: true });
api.request('reports', { id: id }).then(function (data) {
if (that.closed) return;
if (that.closed || seq !== that.loadSeq || !api.user() || api.user().id !== owner) return;
getApp().globalData.photos = data.report.photos;
getApp().globalData.payload = Object.assign({}, data.report.payload, { vm: data.report.vm, presentation: data.report.presentation });
my.navigateTo({ url: '/pages/report/report' });
}).catch(function (err) { that.toast(err.message); })
.then(function () { if (!that.closed) that.setData({ loading: false }); });
}).catch(function (err) {
if (that.closed || seq !== that.loadSeq) return;
if (err.status === 401) { that.setData({ items: [] }); my.redirectTo({ url: '/pages/login/login' }); }
else that.toast(err.message);
})
.then(function () { if (!that.closed && seq === that.loadSeq) that.setData({ loading: false }); });
},
// H5 data-action="logout-wechat"(历史页右上角)
@@ -75,7 +116,7 @@ Page({
var that = this;
api.logout().then(function () {
that.setData({ signedIn: false, accountLabel: '尚未登录', items: [], countText: '', identityNote: '' });
my.redirectTo({ url: '/pages/splash/splash' });
my.redirectTo({ url: '/pages/login/login' });
}).catch(function (err) { that.toast(err.message); });
}
});
}, typeof my === 'undefined' ? {} : my));
+9 -1
View File
@@ -1 +1,9 @@
{ "defaultTitle": "历史报告", "titleBarColor": "#FFFFFF", "backgroundColor": "#EFEFEF" }
{
"defaultTitle": "​",
"titleBarColor": "#FFFFFF",
"backgroundColor": "#EFEFEF",
"navigationBarForceEnable": true,
"transparentTitle": "always",
"navigationBarTextStyle": "black",
"gestureBack": "NO"
}