/* ═════ 启动页:品牌底图 + Slogan + 开始检测/我的报告 + 隐私授权弹窗 对照 H5 index.html #s-splash(L43-58)、#p-privacy(L294-307)、#p-policy(L335-466) 交互保持:登录(必须勾选协议)、restore、历史入口、退出登录、政策全文、开发版入口。 ═════ */ var api = require('../../utils/api.js'); var development = require('../../utils/development'); var config = require('../../config'); Page({ 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, accountLabel: '尚未登录', // H5 renderAccountStatus() toastText: '', toastOn: false, showCameraDebug: development.cameraDebugEnabled(), showMvpDebug: config.mvpLocal === true || (config.transport === 'cloud' && config.environment !== 'production'), showDiagnose: config.environment !== 'production', diagText: '' }, onShow: function () { var that = this; api.restore().then(function (user) { that.setData({ signedIn: !!user, accountLabel: user ? '淘宝已登录' : '尚未登录' }); }) .catch(function () {}); }, // 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.navigateTo({ url: '/pages/profile/profile' }); return; } 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 }); api.login(true).then(function () { that.setData({ showPrivacy: false, signedIn: true, accountLabel: '淘宝已登录' }); my.navigateTo({ url: '/pages/profile/profile' }); }).catch(function (err) { that.toast(err.message); }).then(function () { that.setData({ busy: false }); }); }, // H5 data-action="history" / 「我的报告」 onHistory: function () { if (!api.user()) { this.onOpenPrivacy(); return; } my.navigateTo({ url: '/pages/history/history' }); }, onLogout: function () { var that = this; api.logout().then(function () { that.setData({ signedIn: false, agreed: false, accountLabel: '尚未登录' }); }).catch(function (err) { that.toast(err.message); }); }, onCameraDebug: function () { if (!development.cameraDebugEnabled()) return; my.navigateTo({ url: '/pages/camera/camera?debug=camera' }); }, onMvpDebug: function () { if (!config.mvpLocal && !(config.transport === 'cloud' && config.environment !== 'production')) return; my.navigateTo({ url: '/pages/mvp/mvp' }); }, // 相机/相册权限诊断:相机页可能整页崩掉,所以在启动页也能点 onDiagnose: function () { var that = this; this.setData({ diagText: '检测中…' }); require('../../utils/permissions').diagnose().then(function (info) { that.setData({ diagText: info.join('\n') }); }).catch(function (err) { that.setData({ diagText: 'diagnose error: ' + (err && err.message ? err.message : String(err)) }); }); }, onCloseDiagnose: function () { this.setData({ diagText: '' }); }, // 相机组件冒烟测试:单独一页只放 ,用来判断淘宝真机是否支持该组件 onCamTest: function () { my.navigateTo({ url: '/pages/camtest/camtest' }); }, noop: function () {} // 弹窗卡片内点击拦截冒泡用 });