login.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. toDeviceList: false,
  11. },
  12. onLoad(options) {
  13. var that = this;
  14. var toDeviceList = options.toDeviceList;
  15. that.data.toDeviceList = toDeviceList;
  16. },
  17. egree() {
  18. this.setData({
  19. isAgree: !this.data.isAgree
  20. })
  21. },
  22. goabout(e) {
  23. var param = '?type=' + e.currentTarget.dataset.index;
  24. constant.routeUtil.jumpParam(constant.routePath.aboutInfo, param);
  25. },
  26. getPhoneNumber(e) {
  27. var that = this;
  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. constant.apiUtil.login({
  45. code: res1.code,
  46. unShowLoad: true,
  47. }).then((res2) => {
  48. constant.apiUtil.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. if (that.data.toDeviceList) {
  63. constant.routeUtil.redirectTo(constant.routePath.deviceList);
  64. } else {
  65. constant.routeUtil.goBack(1);
  66. }
  67. }, 2000);
  68. }, function () {
  69. wx.hideLoading();
  70. });
  71. });
  72. });
  73. },
  74. fail(fail1) {
  75. wx.hideLoading();
  76. },
  77. });
  78. }
  79. },
  80. notlogin() {
  81. wx.showToast({
  82. title: '请同意协议',
  83. icon: "none"
  84. })
  85. }
  86. })
  87. // 需要用授权登录
  88. // if ((res.isNewUser && res.isNewUser === true) || !phone) {
  89. // return;
  90. // };