32 lines
1.4 KiB
JavaScript
32 lines
1.4 KiB
JavaScript
const { authService } = require('../../services');
|
|
|
|
Page({
|
|
data: { name: '演示红娘', username: 'demo_matchmaker_02', password: '', loading: false, error: '' },
|
|
onNameInput(e) { this.setData({ name: e.detail.value, error: '' }); },
|
|
onUsernameInput(e) { this.setData({ username: e.detail.value, error: '' }); },
|
|
onPasswordInput(e) { this.setData({ password: e.detail.value, error: '' }); },
|
|
async submit() {
|
|
if (this.data.loading) return;
|
|
const name = this.data.name.trim();
|
|
const username = this.data.username.trim();
|
|
const password = this.data.password;
|
|
if (!name || !/^[a-zA-Z][a-zA-Z0-9_]{3,29}$/.test(username) || password.length < 8) {
|
|
this.setData({ error: '请输入姓名、4 至 30 位用户名和至少 8 位密码' });
|
|
return;
|
|
}
|
|
this.setData({ loading: true, error: '' });
|
|
try {
|
|
await authService.operatorDemoRegister({ name, username, password });
|
|
const result = await authService.operatorLogin({ username, password });
|
|
wx.setStorageSync('operatorToken', result.accessToken);
|
|
wx.setStorageSync('operatorName', result.name);
|
|
wx.setStorageSync('operatorId', result.operatorId);
|
|
wx.reLaunch({ url: '/pages/matchmaker-workbench/matchmaker-workbench' });
|
|
} catch (err) {
|
|
this.setData({ error: err.message || '注册失败,请重试' });
|
|
} finally {
|
|
this.setData({ loading: false });
|
|
}
|
|
},
|
|
});
|