123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- Page({
- data: {
- name: '', // 用户名
- password: '', // 密码
- errorMessage: '', // 错误提示
- },
- // 输入用户名
- inputName: function (e) {
- this.setData({
- name: e.detail.value
- });
- },
- <<<<<<< HEAD:pages/b/b.js
- // 输入密码
- inputPassword: function (e) {
- =======
- // 取消登录弹窗
- potNo() {
- this.setData({
- isHidden: true
- });
- },
- // 确认登录弹窗
- popYes() {
- const { avatarUrl, nickName } = this.data;
- if (!avatarUrl || !nickName) {
- wx.showToast({
- icon: 'error',
- title: '请获取头像和昵称',
- });
- return;
- }
- this.setData({
- isLogin: true,
- isHidden: true,
- });
- // 登录成功后跳转到指定页面
- wx.switchTab({
- url: '/pages/Regular User/Home/Home',
- });
- },
- // 用户名密码登录
- inputUsername(e) {
- this.setData({
- username: e.detail.value
- });
- },
- inputPassword(e) {
- >>>>>>> origin/soligd:pages/Regular/Regular.js
- this.setData({
- password: e.detail.value
- });
- },
- // 注册逻辑
- register: function () {
- const { name, password } = this.data;
- // 检查用户名和密码是否为空
- if (!name || !password) {
- wx.showToast({
- title: '用户名和密码不能为空',
- icon: 'none',
- duration: 2000
- });
- return;
- }
- wx.showLoading({
- title: '注册中...'
- });
- setTimeout(() => {
- // 发送请求到后端,进行用户注册
- wx.request({
- url: 'https://soilgd.com:5000/register', // 后端注册接口
- method: 'POST',
- data: {
- name: name, // 修改为 name
- password: password,
- },
- success: (res) => {
- wx.hideLoading();
- if (res.data.success) {
- wx.showToast({
- title: '注册成功',
- icon: 'success',
- duration: 2000
- });
- // 清空输入框
- this.setData({
- name: '',
- password: '',
- errorMessage: ''
- });
- <<<<<<< HEAD:pages/b/b.js
- // 跳转到登录页面
- wx.switchTab({
- url: '/pages/Home/Home'
- });
- } else {
- wx.showToast({
- title: res.data.message || '注册失败',
- icon: 'none',
- duration: 2000
- });
- }
- },
- fail: (err) => {
- wx.hideLoading();
- wx.showToast({
- title: '网络错误,请重试',
- icon: 'none',
- duration: 2000
- });
- console.error('注册失败:', err);
- }
- });
- =======
- // 登录成功后跳转到指定页面
- wx.switchTab({
- url: '/pages/Regular User/Home/Home',
- });
- } else {
- this.setData({
- errorMessage: '用户名或密码错误'
- });
- wx.showToast({
- title: '用户名或密码错误',
- icon: 'none',
- duration: 2000
- });
- }
- >>>>>>> origin/soligd:pages/Regular/Regular.js
- }, 1500);
- },
- });
|