login.js 2.2 KB

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