login.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. show: false,
  8. },
  9. //页面创建时执行
  10. onLoad: function (options) {
  11. app.setUcode(options);
  12. },
  13. //每次打开都获取要确人
  14. onShow: function () {
  15. this.getUcode();
  16. },
  17. /**
  18. * 获取邀请用户
  19. */
  20. getUcode: function () {
  21. if (!app.util().isNull(app.globalData.ucode)) {
  22. app.api().Get('openapi/v1/getCodeUser',{'ucode':app.globalData.ucode},(rel) => {
  23. if (rel.code == 200) {
  24. this.setData({
  25. ucode: app.globalData.ucode,
  26. ucode_user: rel.data,
  27. show:true,
  28. })
  29. }else{
  30. }
  31. })
  32. }
  33. },
  34. //输入邀请码
  35. inputCode: function (event) {
  36. var that = this;
  37. var cursor = event.detail.cursor, code = event.detail.value;
  38. if (cursor >= 4) {
  39. app.globalData.ucode = code;
  40. that.getUcode();
  41. } else {
  42. var user = {
  43. face: '/img/me.png'
  44. }
  45. that.setData({
  46. ucode_user: user
  47. })
  48. }
  49. },
  50. /**
  51. * 关闭弹出窗口
  52. */
  53. onClose: function () {
  54. this.setData({
  55. show:!this.data.show
  56. })
  57. },
  58. /**
  59. * 用户登录
  60. */
  61. authorLogin: function (e) {
  62. let that = this;
  63. if (e.detail.errMsg !== 'getUserInfo:ok') {
  64. return false;
  65. }
  66. wx.showLoading({
  67. title: '正在授权',
  68. })
  69. //登录返回上一页
  70. app.doLogin(e,function (isLogin){
  71. if (isLogin){
  72. app.globalData.ucode = '';
  73. wx.navigateBack({
  74. delta:1
  75. })
  76. }
  77. });
  78. }
  79. })