login.js 2.2 KB

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