碧桂园
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

124 строки
3.1 KiB

  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. token: '',
  7. userInfo: null,
  8. paramsid: ''// 邀请人ID
  9. },
  10. onLoad(option) {
  11. console.log(option.id)
  12. this.setData({
  13. paramsid: option.id
  14. })
  15. this.loginGettoken()
  16. },
  17. // 判断是跳转游戏还是静态页
  18. panduanFun(){
  19. let that = this
  20. wx.request({
  21. url: getApp().globalData.httpurl + 'ar/game/getOne',
  22. method: "get",
  23. data: {},
  24. header: {
  25. Authorization: 'bearer '+ that.data.token
  26. },
  27. success(res) {
  28. console.log(res)
  29. if (res.data.code == 0) {
  30. let data = res.data.data
  31. // gameVersion为指定发版,和后台是否保持一致,方便提审通过,后续只需更改1为2,3,4,5...
  32. if(data.miniType==0&&data.gameVersion==1){
  33. getApp().globalData.gameurl = data.linkUrl
  34. that.tabindex(data.linkUrl)
  35. }else{
  36. wx.navigateTo({
  37. url: '/pages/guodu/index'
  38. })
  39. }
  40. }else{
  41. wx.navigateTo({
  42. url: '/pages/guodu/index'
  43. })
  44. wx.showToast({
  45. icon: 'none',
  46. title: res.data.msg
  47. })
  48. return ;
  49. }
  50. }
  51. })
  52. },
  53. inviteFun(id){
  54. let that = this
  55. wx.request({
  56. url: getApp().globalData.httpurl + 'ar/user/bindNShareUserId?shareUserId='+ id,
  57. method: "get",
  58. data: {},
  59. header: {
  60. Authorization: 'bearer '+ that.data.token
  61. },
  62. success(res) {
  63. console.log(res)
  64. if (res.data.code == 0) {
  65. }else{
  66. wx.showToast({
  67. icon: 'none',
  68. title: res.data.msg
  69. })
  70. return ;
  71. }
  72. }
  73. })
  74. },
  75. tabindex(url) {
  76. let id = 0
  77. if(this.data.userInfo.phone){
  78. id = this.data.userInfo.id
  79. }
  80. wx.navigateTo({
  81. url: '/pages/out/index?index=1&userid=' + id+ '&gameid=1&type=1&url='+url
  82. })
  83. },
  84. saoma() {
  85. wx.navigateTo({
  86. url: '/pages/AR/index'
  87. })
  88. },
  89. //登录-获取token
  90. loginGettoken(){
  91. let that = this
  92. wx.login({
  93. success (res) {
  94. if (res.code) {
  95. //发起网络请求
  96. wx.request({
  97. url: getApp().globalData.httpurl+ 'auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@'+res.code+'@'+'',
  98. method: "POST",
  99. data: {
  100. },
  101. header: {
  102. Authorization: "Basic YXBwbGV0OmFwcGxldA==",
  103. },
  104. success(res1) {
  105. if (res1.statusCode == 200) {
  106. that.setData({
  107. token: res1.data.access_token,
  108. userInfo: res1.data.user_info
  109. })
  110. if(that.data.paramsid){ // 有ID则是通过分享链接进来的
  111. that.inviteFun(that.data.paramsid)
  112. }
  113. getApp().globalData.token = res1.data.access_token
  114. getApp().globalData.userInfo = res1.data.user_info
  115. }
  116. }
  117. })
  118. } else {
  119. console.log('登录失败!' + res.errMsg)
  120. }
  121. }
  122. })
  123. }
  124. })