login.js 2.2 KB

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