Files
xingque/pages/phone-auth/phone-auth.js

40 lines
993 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { submit } from '../../utils/phone-auth';
Page({
data: {
show: false,
avatar: '',
avatarFile: null,
phoneCode: '',
phoneGot: false
},
onLoad() {
setTimeout(() => this.setData({ show: true }), 100);
},
onAvatar(e) {
const p = e.detail.avatarUrl;
this.setData({ avatar: p, avatarFile: p });
},
onPhone(e) {
if (e.detail.code) {
this.setData({ phoneCode: e.detail.code, phoneGot: true });
}
},
async submit() {
const { phoneCode, avatarFile } = this.data;
if (!avatarFile || !phoneCode) return;
try {
wx.showLoading({ title: '认证中...', mask: true });
await submit(phoneCode, avatarFile);
wx.hideLoading();
// 成功重启小程序此时check返回false用户无感进入
wx.reLaunch({ url: '/pages/index/index' });
} catch (e) {
wx.hideLoading();
wx.showToast({ title: e.message, icon: 'none' });
}
},
exit() {
wx.exitMiniProgram();
}
});