login.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const {
  2. login,
  3. register
  4. } = require('../../../utils/api.js')
  5. import route_constant from '../../../utils/route_constant.js';
  6. import route_util from '../../../utils/route_util.js';
  7. Page({
  8. data: {
  9. nvabarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '', //导航栏 中间的标题
  12. },
  13. isYs: false,
  14. isAgree: false,
  15. },
  16. onLoad(options) {
  17. const pages = getCurrentPages(); // 获取当前页面栈
  18. const pageCount = pages.length; // 页面栈中的页面数量
  19. for (var i = pageCount - 1; i > -1; i--) {
  20. console.log("gasdfqwerqwerq====" + JSON.stringify(pages[i]));
  21. }
  22. },
  23. egree() {
  24. this.setData({
  25. isAgree: !this.data.isAgree
  26. })
  27. },
  28. goabout(e) {
  29. wx.navigateTo({
  30. url: './../aboutInfo/aboutInfo?type=' + e.currentTarget.dataset.index,
  31. })
  32. },
  33. getPhoneNumber(e) {
  34. if (e.detail.errMsg != "getPhoneNumber:ok") {
  35. wx.showToast({
  36. title: "获取手机号失败",
  37. icon: 'fail',
  38. duration: 2000
  39. });
  40. return;
  41. }
  42. var phoneCode = e.detail.code;
  43. if (phoneCode) {
  44. wx.login({
  45. success: res1 => {
  46. wx.showLoading({
  47. title: '加载中',
  48. });
  49. // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","unionid":null,"userId":null,"deviceUid":null,"accessToken":null,"phone":null,"headUrl":"","nickname":"","isNewUser":true}
  50. login({
  51. code: res1.code,
  52. unShowLoad: true,
  53. }).then((res2) => {
  54. register({
  55. openid: res2.openid,
  56. code: phoneCode,
  57. unShowLoad: true,
  58. }).then((res3) => {
  59. var phone = res3.phone;
  60. getCurrentPages()[0].loginReset(phone, function () {
  61. wx.showToast({
  62. title: "登录成功",
  63. icon: 'success',
  64. duration: 2000
  65. });
  66. }, function () {
  67. setTimeout(() => {
  68. route_util.redirectTo(route_constant.deviceList);
  69. }, 2000);
  70. }, function () {
  71. wx.hideLoading();
  72. });
  73. });
  74. });
  75. },
  76. fail(fail1) {
  77. wx.hideLoading();
  78. },
  79. });
  80. }
  81. },
  82. notlogin() {
  83. wx.showToast({
  84. title: '请同意协议',
  85. icon: "none"
  86. })
  87. }
  88. })
  89. // 需要用授权登录
  90. // if ((res.isNewUser && res.isNewUser === true) || !phone) {
  91. // return;
  92. // };