feat: 完善双端演示注册与红娘服务闭环
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
const { authStore } = require('../../stores');
|
||||
|
||||
Page({
|
||||
data: { code: 'demo_user_01', displayName: '演示用户', phone: '', loading: false, error: '' },
|
||||
onCodeInput(e) { this.setData({ code: e.detail.value, error: '' }); },
|
||||
onNameInput(e) { this.setData({ displayName: e.detail.value, error: '' }); },
|
||||
onPhoneInput(e) { this.setData({ phone: e.detail.value, error: '' }); },
|
||||
async submit() {
|
||||
if (this.data.loading) return;
|
||||
const code = this.data.code.trim();
|
||||
const displayName = this.data.displayName.trim();
|
||||
const phone = this.data.phone.trim();
|
||||
if (!/^[a-zA-Z0-9_-]{1,100}$/.test(code) || !displayName || (phone && !/^1[3-9]\d{9}$/.test(phone))) {
|
||||
this.setData({ error: '请填写有效的演示编号、昵称和手机号' });
|
||||
return;
|
||||
}
|
||||
this.setData({ loading: true, error: '' });
|
||||
try {
|
||||
await authStore.loginWithDemo(`demo_openid_${code}`, displayName, phone);
|
||||
wx.reLaunch({ url: '/pages/index/index' });
|
||||
} catch (err) {
|
||||
this.setData({ error: err.message || '注册失败,请重试' });
|
||||
} finally {
|
||||
this.setData({ loading: false });
|
||||
}
|
||||
},
|
||||
async loginExisting() {
|
||||
if (this.data.loading) return;
|
||||
const code = this.data.code.trim();
|
||||
if (!/^[a-zA-Z0-9_-]{1,100}$/.test(code)) {
|
||||
this.setData({ error: '请输入有效的演示编号' });
|
||||
return;
|
||||
}
|
||||
this.setData({ loading: true, error: '' });
|
||||
try {
|
||||
await authStore.loginWithDemo(`demo_openid_${code}`);
|
||||
wx.reLaunch({ url: '/pages/index/index' });
|
||||
} catch (err) {
|
||||
this.setData({ error: err.message || '登录失败,请重试' });
|
||||
} finally {
|
||||
this.setData({ loading: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user