login.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // pages/login/login.ts;
  2. const app = getApp();
  3. const { register }=require('./../../utils/api.js')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. nvabarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '', //导航栏 中间的标题
  12. },
  13. isYs: false,
  14. isAgree: false,
  15. },
  16. egree() {
  17. this.setData({
  18. isAgree: !this.data.isAgree
  19. })
  20. },
  21. goabout(e) {
  22. wx.navigateTo({
  23. url: './../aboutInfo/aboutInfo?type=' + e.currentTarget.dataset.index,
  24. })
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad() {
  30. },
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady() {
  35. },
  36. /**
  37. * 生命周期函数--监听页面显示
  38. */
  39. onShow() {
  40. },
  41. /**
  42. * 生命周期函数--监听页面隐藏
  43. */
  44. onHide() {
  45. },
  46. /**
  47. * 生命周期函数--监听页面卸载
  48. */
  49. onUnload() {
  50. },
  51. /**
  52. * 页面相关事件处理函数--监听用户下拉动作
  53. */
  54. onPullDownRefresh() {
  55. },
  56. /**
  57. * 页面上拉触底事件的处理函数
  58. */
  59. onReachBottom() {
  60. },
  61. /**
  62. * 用户点击右上角分享
  63. */
  64. onShareAppMessage() {
  65. },
  66. getPhoneNumber (e) {
  67. console.log(e)
  68. if (e.detail.errMsg != "getPhoneNumber:ok") {
  69. wx.showToast({
  70. title: "获取手机号失败",
  71. icon: 'fail',
  72. duration: 2000
  73. });
  74. return;
  75. }
  76. if(e.detail.code) {
  77. register({
  78. openid: app.globalData.userInfo.openid,
  79. code: e.detail.code,
  80. }).then((res)=> {
  81. wx.showToast({
  82. title: "登陆成功",
  83. icon: 'success',
  84. duration: 2000
  85. });
  86. wx.setStorage({
  87. key:"userInfo",
  88. data: res,
  89. success() {
  90. setTimeout(()=> {
  91. // 重新登录
  92. getCurrentPages()[0].login();
  93. wx.redirectTo({
  94. url: './../deviceConnect0/deviceConnect0?isLognlink=0'
  95. });
  96. }, 2000);
  97. }
  98. });
  99. })
  100. }
  101. },
  102. notlogin() {
  103. wx.showToast({
  104. title: '请同意协议',
  105. icon: "none"
  106. })
  107. }
  108. })