login.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const {
  2. login,
  3. register
  4. } = require('../../../utils/apiUtil.js')
  5. import routePath from '../../../utils/routePath.js';
  6. import routeUtil from '../../../utils/routeUtil.js';
  7. Page({
  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. var param = '?type=' + e.currentTarget.dataset.index;
  23. routeUtil.jumpParam(routePath.aboutInfo, param);
  24. },
  25. getPhoneNumber(e) {
  26. if (e.detail.errMsg != "getPhoneNumber:ok") {
  27. wx.showToast({
  28. title: "获取手机号失败",
  29. icon: 'fail',
  30. duration: 2000
  31. });
  32. return;
  33. }
  34. var phoneCode = e.detail.code;
  35. if (phoneCode) {
  36. wx.login({
  37. success: res1 => {
  38. wx.showLoading({
  39. title: '加载中',
  40. });
  41. // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","unionid":null,"userId":null,"deviceUid":null,"accessToken":null,"phone":null,"headUrl":"","nickname":"","isNewUser":true}
  42. login({
  43. code: res1.code,
  44. unShowLoad: true,
  45. }).then((res2) => {
  46. register({
  47. openid: res2.openid,
  48. code: phoneCode,
  49. unShowLoad: true,
  50. }).then((res3) => {
  51. var phone = res3.phone;
  52. getCurrentPages()[0].loginReset(phone, function () {
  53. wx.showToast({
  54. title: "登录成功",
  55. icon: 'success',
  56. duration: 2000
  57. });
  58. }, function () {
  59. setTimeout(() => {
  60. routeUtil.redirectTo(routePath.deviceList);
  61. }, 2000);
  62. }, function () {
  63. wx.hideLoading();
  64. });
  65. });
  66. });
  67. },
  68. fail(fail1) {
  69. wx.hideLoading();
  70. },
  71. });
  72. }
  73. },
  74. notlogin() {
  75. wx.showToast({
  76. title: '请同意协议',
  77. icon: "none"
  78. })
  79. }
  80. })
  81. // 需要用授权登录
  82. // if ((res.isNewUser && res.isNewUser === true) || !phone) {
  83. // return;
  84. // };