You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.3 KiB
67 lines
1.3 KiB
// pages/register/register.js
|
|
Page({
|
|
data: {
|
|
ID: '',
|
|
password: '',
|
|
errorMessage: ''
|
|
},
|
|
|
|
// 处理ID输入
|
|
onIDInput(e) {
|
|
this.setData({
|
|
ID: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 处理密码输入
|
|
onPasswordInput(e) {
|
|
this.setData({
|
|
password: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 处理注册逻辑
|
|
submitUserInfo() {
|
|
const { ID, password } = this.data;
|
|
|
|
// 验证 ID 和密码是否为空
|
|
if (!ID || !password) {
|
|
this.setData({
|
|
errorMessage: '账号ID和密码不能为空'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// 发起注册请求,使用 x-www-form-urlencoded
|
|
wx.request({
|
|
header: {
|
|
'content-type': 'application/x-www-form-urlencoded' // 设置请求头
|
|
},
|
|
url: 'http://192.168.144.1:8080/user/register', // 替换为你的后端API地址
|
|
method: 'POST',
|
|
data: {
|
|
'username': ID,
|
|
'password': password
|
|
},
|
|
success(res) {
|
|
console.log('注册成功', res);
|
|
wx.showToast({
|
|
title: '注册成功',
|
|
icon: 'success'
|
|
});
|
|
// 注册成功后跳转到登录页面
|
|
wx.redirectTo({
|
|
url: '/pages/login/login'
|
|
});
|
|
},
|
|
});
|
|
},
|
|
|
|
// 跳转到登录页面
|
|
goToLogin() {
|
|
wx.redirectTo({
|
|
url: '/pages/login/login' // 登录页面的路径
|
|
});
|
|
}
|
|
});
|