start.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. var _request = require('../../utils/request.js')
  2. var version = getApp().globalData.version
  3. var channel // 渠道二维码信息
  4. var scene // 渠道二维码id
  5. var url = '' // 分享或模板落地页
  6. var invite = 0 //邀请id
  7. var poster = []
  8. var project = []
  9. Page({
  10. data: {
  11. animationData: {},
  12. popup: false
  13. },
  14. onLoad: function (options) {
  15. console.log('options',options)
  16. url = 0
  17. if (options.scene) {
  18. scene = decodeURIComponent(options.scene)
  19. if (scene.indexOf('invite_wx_') > -1) {
  20. invite = scene.slice(10)
  21. } else if (scene.indexOf('poster') > -1) {
  22. this.getPoster(scene)
  23. } else if (scene.indexOf('project') > -1) {
  24. this.getPosterProject(scene)
  25. } else {
  26. this.getScene(scene)
  27. }
  28. } else if (options.url) {
  29. this.urlHandle(options)
  30. }
  31. if (options.invite) {
  32. invite = options.invite
  33. }
  34. var that = this
  35. //2020
  36. wx.setStorageSync('invite', invite) //存入邀请
  37. this.getAnimation(2000);
  38. return false;
  39. wx.getSetting({
  40. success: res => {
  41. var auth = res.authSetting
  42. if (!auth['scope.userInfo']) {
  43. console.log("auth['scope.userInfo']",auth['scope.userInfo'])
  44. that.setData({
  45. popup: true
  46. })
  47. } else {
  48. this.getVersion(2000)
  49. }
  50. }
  51. })
  52. },
  53. getPoster: function (val) {
  54. poster = val.split('$')
  55. if (poster.length > 0) {
  56. invite = poster[2]
  57. }
  58. },
  59. getPosterProject: function (val) {
  60. project = val.split('$')
  61. if (project.length > 0) {
  62. invite = project[2]
  63. }
  64. },
  65. urlHandle: function (val) {
  66. if (val.url) {
  67. url = val.url + '?'
  68. for (var i in val) {
  69. if (i !== 'url') {
  70. url += i + '=' + val[i] + '&'
  71. }
  72. }
  73. }
  74. },
  75. getScene: function () {
  76. var that = this
  77. var url = 'v1/xcx/channel/info/' + scene
  78. var params = {}
  79. var success = function (res) {
  80. channel = res.data
  81. }
  82. _request.$get(url, params, success)
  83. },
  84. sceneCount: function () {
  85. var that = this
  86. var url = 'v1/xcx/channel/figure/' + channel.parent_id
  87. var params = {}
  88. var success = function (res) {
  89. }
  90. _request.$post(url, params, success)
  91. },
  92. getAnimation: function (val) {
  93. var animation = wx.createAnimation({
  94. duration: 500,
  95. timingFunction: 'linear'
  96. })
  97. setTimeout(function() {
  98. animation.translateY(-150).opacity(0).step()
  99. this.setData({
  100. animationData:animation.export()
  101. })
  102. }.bind(this), val)
  103. setTimeout(function() {
  104. console.log(channel)
  105. if (channel) {
  106. this.sceneCount()
  107. }
  108. if (channel && channel.channel_url) {
  109. this.urlType(channel.channel_url)
  110. } else if (url) {
  111. this.urlType(url)
  112. } else if (poster.length > 0) {
  113. this.scanPoster()
  114. wx.redirectTo({
  115. url: '/pages/helpfarm/helpfarm-detail/helpfarm-detail?id=' + poster[1]
  116. })
  117. } else if (project.length > 0) {
  118. this.scanPoster()
  119. wx.redirectTo({
  120. url: '/pages/projects/project-detail/project-detail?id=' + project[1]
  121. })
  122. } else {
  123. wx.switchTab({
  124. url: '/pages/home/home'
  125. })
  126. }
  127. }.bind(this), val + 1000)
  128. },
  129. scanPoster: function (val, type) {
  130. var that = this
  131. var url = 'v1/poster/scan'
  132. var params = {
  133. params: scene
  134. }
  135. var success = function (res) {
  136. }
  137. _request.$get(url, params, success)
  138. },
  139. urlType: function (val) {
  140. let type = [
  141. 'pages/projects/projects?',
  142. 'pages/helpfarm/helpfarm?',
  143. 'pages/customservice/customservice?',
  144. 'pages/user/all/all?',
  145. ]
  146. let i = -1
  147. for (let a in type) {
  148. if (type[a].indexOf(val) > -1) {
  149. i = a
  150. let str = type[i]
  151. wx.switchTab({
  152. url: '/' + str.substring(0, str.length - 1)
  153. })
  154. break
  155. }
  156. }
  157. if (i <= -1) {
  158. wx.redirectTo({
  159. url: '/' + val
  160. })
  161. }
  162. },
  163. getUserInfo: function (val) {
  164. var channel_id = 0
  165. if (channel && Number(channel.parent_id) > 0) {
  166. channel_id = Number(channel.parent_id)
  167. }
  168. var that = this
  169. if (val.detail.errMsg === 'getUserInfo:ok') {
  170. wx.showLoading({
  171. title: '加载中'
  172. })
  173. _request.sendInfo(val, channel_id, invite, that)
  174. }
  175. },
  176. getVersion: function (val) {
  177. // this.check()
  178. this.getAnimation(val)
  179. // var that = this
  180. // var url = 'v1/xcx/version/' + version
  181. // var params = {}
  182. // var success = function (res) {
  183. // if (res.data && res.data.state === 0) {
  184. // getApp().globalData.vershow = false
  185. // }
  186. // that.check()
  187. // that.getAnimation(val)
  188. // }
  189. // _request.$get(url, params, success)
  190. },
  191. check: function () {
  192. var that = this
  193. var url = 'v1/user/check'
  194. var params = {
  195. }
  196. var success = function (res) {
  197. getApp().globalData.wx_id = res.data.wx_user_id
  198. }
  199. _request.$get(url, params, success)
  200. }
  201. })