51 lines
3.1 KiB
JavaScript
51 lines
3.1 KiB
JavaScript
var api = require('../../utils/api');
|
|
Page(require('../../utils/page-header').page({
|
|
onShareAppMessage: function () { return require('../../utils/share').message(); },
|
|
data: {
|
|
// Keep the original H5 pixels, but avoid public-network requests for the
|
|
// first screen's background, brand and guest icon.
|
|
bgUrl: '../../assets/startup/bg-login-h5.webp',
|
|
brandUrl: '../../assets/startup/brand-login.png',
|
|
guestIconUrl: '../../assets/startup/icon-guest.png',
|
|
agreed: false, busy: false, checking: true, showPolicy: false,
|
|
message: '正在检查登录状态…'
|
|
},
|
|
onLoad: function (query) { this.chooseAccount = !!(query && query.switch === '1'); this.alive = true; this.entrySeq = 0; },
|
|
onShow: function () {
|
|
var that = this;
|
|
this.alive = true;
|
|
if (this.data.busy) return;
|
|
var seq = this.entrySeq = (this.entrySeq || 0) + 1;
|
|
if (this.chooseAccount) { this.setData({ checking: false, message: '淘宝登录可保存报告;游客仅限本次体验。' }); return; }
|
|
this.setData({ checking: true });
|
|
api.restore().then(function (user) {
|
|
if (!that.alive || seq !== that.entrySeq) return;
|
|
if (user) { my.redirectTo({ url: '/pages/splash/splash' }); return; }
|
|
that.setData({ message: '淘宝登录可保存报告;游客仅限本次体验。' });
|
|
}).catch(function (err) {
|
|
if (that.alive && seq === that.entrySeq) that.setData({ message: err.status === 401 ? '登录已过期,请重新登录或选择游客体验。' : '暂时无法检查登录状态,请重试或选择游客体验。' });
|
|
}).then(function () { if (that.alive && seq === that.entrySeq) that.setData({ checking: false }); });
|
|
},
|
|
onUnload: function () { this.alive = false; this.entrySeq++; },
|
|
onToggleAgree: function () { if (!this.data.busy) this.setData({ agreed: !this.data.agreed }); },
|
|
onOpenPolicy: function () { this.setData({ showPolicy: true }); },
|
|
onClosePolicy: function () { this.setData({ showPolicy: false }); },
|
|
enter: function (guest) {
|
|
if (this.data.busy || (!guest && this.data.checking)) return;
|
|
if (!this.data.agreed) { this.setData({ message: '请先阅读并同意用户协议和隐私政策' }); return; }
|
|
var that = this, seq = this.entrySeq = (this.entrySeq || 0) + 1;
|
|
this.setData({ busy: true, checking: false, message: guest ? '正在开始游客体验…' : '正在登录淘宝账号…' });
|
|
var task;
|
|
try { task = guest ? api.loginGuest(true) : api.login(true); } catch (error) { task = Promise.reject(error); }
|
|
Promise.resolve(task).then(function () {
|
|
if (that.alive && seq === that.entrySeq) my.redirectTo({ url: '/pages/splash/splash' });
|
|
}).catch(function (err) { if (that.alive && seq === that.entrySeq && !(err && err.canceled)) {
|
|
that.setData({ message: err && err.message || '暂时无法进入,请重试' });
|
|
} })
|
|
.then(function () { if (that.alive && seq === that.entrySeq) that.setData({ busy: false }); });
|
|
},
|
|
onTaobaoLogin: function () { this.enter(false); },
|
|
onGuest: function () { this.enter(true); },
|
|
noop: function () {}
|
|
}, typeof my === 'undefined' ? {} : my, { nativeTitleFallback: true }));
|