40 lines
993 B
JavaScript
40 lines
993 B
JavaScript
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();
|
||
}
|
||
}); |