前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >「小程序JAVA实战」小程序 loading 提示框与页面跳转(37)

「小程序JAVA实战」小程序 loading 提示框与页面跳转(37)

作者头像
IT架构圈
发布2019-07-08 10:09:15
6800
发布2019-07-08 10:09:15
举报
文章被收录于专栏:IT架构圈

登录注册都完成了,有可能会遇到一些问题,服务器繁忙的话,后台接口卡住了,也没任何提示,小程序端的用户比较暴力一直点击怎么办。源码:https://github.com/limingios/wxProgram.git 中的wx-springboot 和 No.15

加载提示框,隐藏加载中提示框,页面跳转

https://developers.weixin.qq.com/miniprogram/dev/api/api-react.html#wxshowtoastobject https://developers.weixin.qq.com/miniprogram/dev/api/api-react.html#wxhideloading

跳转实例

  • 用户登录
代码语言:javascript
复制
  • 用户注册
代码语言:javascript
复制
const app = getApp()

Page({
  data: {

  },

  doLogin: function (e) {
    var formObject = e.detail.value;
    var username = formObject.username;
    var password = formObject.password;

    // 简单验证
    if (username.length == 0 || password.length == 0) {
      wx.showToast({
        title: '用户名或密码不能为空',
        icon: 'none',
        duration: 3000
      })
    } else {
      wx.showLoading({
        title: '正在加载中。。。'
      });
      wx.request({
        url: app.serverUrl + "/login",
        method: "POST",
        data: {
          username: username,
          password: password
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function (res) {
          console.log(res.data);
          var status = res.data.status;
          wx.hideLoading();
          if (status == 200) {
            wx.showToast({
              title: "用户登陆成功~!",
              icon: 'none',
              duration: 3000
            })
            app.userinfo = res.data.data;
          } else if (status == 500) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 3000
            })
          }
        }
      })
    }
  },
  goLoginPage: function (e) {
    console.log("跳转到注册");
  }
})
  • 用户注册
代码语言:javascript
复制
const app = getApp()

Page({
    data: {

    },

    doRegist: function(e) {
      var formObject = e.detail.value;
      var username = formObject.username;
      var password = formObject.password;

      // 简单验证
      if (username.length == 0 || password.length == 0) {
        wx.showToast({
          title: '用户名或密码不能为空',
          icon: 'none',
          duration: 3000
        })
      }else{
        wx.showLoading({
          title: '正在加载中。。。'
        });
        wx.request({
          url: app.serverUrl +"/regist", 
          method:"POST",
          data: {
            username: username,
            password: password
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: function (res) {
            console.log(res.data);
            var status = res.data.status;
            wx.hideLoading();
            if(status == 200){
              wx.showToast({
                title: "用户注册成功~!",
                icon: 'none',
                duration: 3000
              })
              app.userinfo = res.data.data;
            }else if(status == 500){
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 3000
              })
            }
          }
        })
      }
    },
    goLoginPage:function(e){
      console.log("跳转到登录");
    }
})
  • 用户登录跳转
代码语言:javascript
复制
const app = getApp()

Page({
  data: {

  },

  doLogin: function (e) {
    var formObject = e.detail.value;
    var username = formObject.username;
    var password = formObject.password;

    // 简单验证
    if (username.length == 0 || password.length == 0) {
      wx.showToast({
        title: '用户名或密码不能为空',
        icon: 'none',
        duration: 3000
      })
    } else {
      wx.showLoading({
        title: '正在加载中。。。'
      });
      wx.request({
        url: app.serverUrl + "/login",
        method: "POST",
        data: {
          username: username,
          password: password
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function (res) {
          console.log(res.data);
          var status = res.data.status;
          wx.hideLoading();
          if (status == 200) {
            wx.showToast({
              title: "用户登陆成功~!",
              icon: 'none',
              duration: 3000
            })
            app.userinfo = res.data.data;
          } else if (status == 500) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 3000
            })
          }
        }
      })
    }
  },
  goRegisterPage: function (e) {
    wx.redirectTo({
      url: '../userRegister/userRegister',
    })
  }
})
  • 用户注册跳转 userRegister.js
代码语言:javascript
复制
const app = getApp()

Page({
    data: {

    },

    doRegist: function(e) {
      var formObject = e.detail.value;
      var username = formObject.username;
      var password = formObject.password;

      // 简单验证
      if (username.length == 0 || password.length == 0) {
        wx.showToast({
          title: '用户名或密码不能为空',
          icon: 'none',
          duration: 3000
        })
      }else{
        wx.showLoading({
          title: '正在加载中。。。'
        });
        wx.request({
          url: app.serverUrl +"/regist", 
          method:"POST",
          data: {
            username: username,
            password: password
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: function (res) {
            console.log(res.data);
            var status = res.data.status;
            wx.hideLoading();
            if(status == 200){
              wx.showToast({
                title: "用户注册成功~!",
                icon: 'none',
                duration: 3000
              })
              app.userinfo = res.data.data;
            }else if(status == 500){
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 3000
              })
            }
          }
        })
      }
    },
    goLoginPage:function(e){
      wx.redirectTo({
        url: '../userLogin/userLogin',
      })
    }
})

PS:这次就是我们的跳转和loading的介绍。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2018-12-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 编程坑太多 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 加载提示框,隐藏加载中提示框,页面跳转
  • 跳转实例
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档