login.js 2.1 KB

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