Files
juzi/taobao/pages/splash/splash.js
T
xsl 774376fa16 feat: 完善淘宝小程序拍照、报告与登录流程
接入本地实时识别和自动三连拍,调整报告裁切、商品跳转、分享标题及居中页眉;完善游客会话、后台渠道隔离、部署脚本与回归测试。
2026-11-04 15:07:51 +08:00

104 lines
4.2 KiB
JavaScript

/* ═════ 启动页:品牌底图 + Slogan + 开始检测/我的报告 + 隐私授权弹窗
对照 H5 index.html #s-splash(L43-58)、#p-privacy(L294-307)、#p-policy(L335-466)
交互保持:登录(必须勾选协议)、restore、历史入口、退出登录、政策全文。 ═════ */
var api = require('../../utils/api.js');
Page(require('../../utils/page-header').page({
onShareAppMessage: function () { return require('../../utils/share').message(); },
data: {
// 图片全部走 api.assetUrl(与 H5 h5/assets/ 同相对路径)
bgUrl: api.assetUrl('img/ui-20261009/bg-splash-h5.jpg'),
logoUrl: api.assetUrl('img/ui-20261012/brand-lockup.png'),
sloganUrl: api.assetUrl('img/ui-20261012/splash-slogan.png'),
startLabelUrl: api.assetUrl('img/ui-20261012/button-start-label.png'),
historyLabelUrl: api.assetUrl('img/ui-20261012/button-history-label.png'),
closeIconUrl: api.assetUrl('img/ui-20261009/icon-close.png'),
showPrivacy: false, // 隐私授权弹窗
agreed: false, // 隐私协议勾选
showPolicy: false,
busy: false,
signedIn: false,
guest: false,
accountLabel: '尚未登录', // H5 renderAccountStatus()
toastText: '', toastOn: false
},
onShow: function () {
var that = this;
this.alive = true;
api.restore().then(function (user) {
if (!that.alive) return;
if (!user) { my.redirectTo({ url: '/pages/login/login' }); return; }
var guest = user.kind === 'taobao_guest';
that.setData({ signedIn: !guest, guest: guest, accountLabel: guest ? '游客模式' : '淘宝已登录' });
}).catch(function (err) {
if (!that.alive) return;
that.setData({ signedIn: false, guest: false, accountLabel: '登录状态待确认' });
if (err.status === 401) my.redirectTo({ url: '/pages/login/login' });
else that.toast('网络异常,请重新登录或稍后重试');
});
},
onUnload: function () { this.alive = false; clearTimeout(this.toastTimer); },
// H5 .toast(自定义轻提示,替代系统 toast 以获得一致的视觉)
toast: function (msg) {
var that = this;
this.setData({ toastText: msg, toastOn: true });
clearTimeout(this.toastTimer);
this.toastTimer = setTimeout(function () {
that.setData({ toastOn: false });
}, Math.max(1800, String(msg).length * 130));
},
// 「开始检测」→ 隐私授权弹窗(H5 data-action="open-privacy")
onOpenPrivacy: function () {
if (!api.user()) { my.redirectTo({ url: '/pages/login/login' }); return; }
this.setData({ agreed: false });
this.setData({ showPrivacy: true });
},
onClosePrivacy: function () {
this.setData({ showPrivacy: false });
},
// 勾选/取消隐私协议(点链接不触发,由 catchTap 分隔)
onToggleAgree: function () {
this.setData({ agreed: !this.data.agreed });
},
onOpenPolicy: function () {
this.setData({ showPolicy: true });
},
onClosePolicy: function () {
this.setData({ showPolicy: false });
},
// 「继续」:必须已勾选协议
onAgreeContinue: function () {
var that = this;
if (this.data.busy) return;
if (!this.data.agreed) {
this.toast('请先阅读并同意隐私协议');
return;
}
this.setData({ busy: true });
if (!api.user()) { this.setData({ busy: false }); my.redirectTo({ url: '/pages/login/login' }); return; }
this.setData({ showPrivacy: false, busy: false });
my.navigateTo({ url: '/pages/profile/profile' });
},
// H5 data-action="history" / 「我的报告」
onHistory: function () {
if (!api.user()) { my.redirectTo({ url: '/pages/login/login' }); return; }
my.navigateTo({ url: '/pages/history/history' });
},
onLogout: function () {
var that = this;
(api.isGuest() ? api.endGuest() : api.logout()).then(function () {
that.setData({ signedIn: false, guest: false, agreed: false, accountLabel: '尚未登录' });
my.redirectTo({ url: '/pages/login/login' });
}).catch(function (err) { that.toast(err.message); });
},
onLogin: function () { my.navigateTo({ url: '/pages/login/login?switch=1' }); },
noop: function () {} // 弹窗卡片内点击拦截冒泡用
}, typeof my === 'undefined' ? {} : my));