login.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // pages/login/login.js
  2. import Notify from '../../miniprogram_npm/@vant/weapp/notify/notify';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. username:'',
  9. password:'',
  10. userInfo: {},
  11. hasUserInfo: false,
  12. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  13. canIUseGetUserProfile: false,
  14. canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  15. },
  16. onClickIcon(){
  17. },
  18. getPhoneNumber (e) {
  19. console.log(e,22)
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad(options) {
  25. },
  26. async getinfo(){
  27. await wx.p.request({
  28. url: 'http://124.71.176.88:882/api/login',
  29. method:'POST',
  30. data:{name: this.data.username,
  31. password:this.data.password}
  32. }).then(res=>{
  33. if(res.data.code==200){
  34. Notify({ type: 'success', message: '登录成功!' });
  35. wx.navigateTo({
  36. url: '../../StepPage/pages/first/first',
  37. })
  38. }else{
  39. Notify({ type: 'danger', message: '登录失败,请确定账号密码!' });
  40. }
  41. })
  42. },
  43. /**
  44. * 生命周期函数--监听页面初次渲染完成
  45. */
  46. onReady() {
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow() {
  52. },
  53. /**
  54. * 生命周期函数--监听页面隐藏
  55. */
  56. onHide() {
  57. },
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload() {
  62. },
  63. /**
  64. * 页面相关事件处理函数--监听用户下拉动作
  65. */
  66. onPullDownRefresh() {
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom() {
  72. },
  73. /**
  74. * 用户点击右上角分享
  75. */
  76. onShareAppMessage() {
  77. },
  78. onLoad() {
  79. if (wx.getUserProfile) {
  80. this.setData({
  81. canIUseGetUserProfile: true
  82. })
  83. }
  84. },
  85. getUserProfile(e) {
  86. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  87. wx.getUserProfile({
  88. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  89. success: (res) => {
  90. console.log(res)
  91. this.setData({
  92. userInfo: res.userInfo,
  93. hasUserInfo: true
  94. })
  95. }
  96. })
  97. },
  98. getUserInfo(e) {
  99. // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
  100. console.log(e)
  101. this.setData({
  102. userInfo: e.detail.userInfo,
  103. hasUserInfo: true
  104. })
  105. }
  106. })