start.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. that.setData({
  44. popup: true
  45. })
  46. } else {
  47. this.getVersion(2000)
  48. }
  49. }
  50. })
  51. },
  52. getPoster: function (val) {
  53. poster = val.split('$')
  54. if (poster.length > 0) {
  55. invite = poster[2]
  56. }
  57. },
  58. getPosterProject: function (val) {
  59. project = val.split('$')
  60. if (project.length > 0) {
  61. invite = project[2]
  62. }
  63. },
  64. urlHandle: function (val) {
  65. if (val.url) {
  66. url = val.url + '?'
  67. for (var i in val) {
  68. if (i !== 'url') {
  69. url += i + '=' + val[i] + '&'
  70. }
  71. }
  72. }
  73. },
  74. getScene: function () {
  75. var that = this
  76. var url = 'v1/xcx/channel/info/' + scene
  77. var params = {}
  78. var success = function (res) {
  79. channel = res.data
  80. }
  81. _request.$get(url, params, success)
  82. },
  83. sceneCount: function () {
  84. var that = this
  85. var url = 'v1/xcx/channel/figure/' + channel.parent_id
  86. var params = {}
  87. var success = function (res) {
  88. }
  89. _request.$post(url, params, success)
  90. },
  91. getAnimation: function (val) {
  92. var animation = wx.createAnimation({
  93. duration: 500,
  94. timingFunction: 'linear'
  95. })
  96. setTimeout(function() {
  97. animation.translateY(-150).opacity(0).step()
  98. this.setData({
  99. animationData:animation.export()
  100. })
  101. }.bind(this), val)
  102. setTimeout(function() {
  103. console.log(channel)
  104. if (channel) {
  105. this.sceneCount()
  106. }
  107. if (channel && channel.channel_url) {
  108. this.urlType(channel.channel_url)
  109. } else if (url) {
  110. this.urlType(url)
  111. } else if (poster.length > 0) {
  112. this.scanPoster()
  113. wx.redirectTo({
  114. url: '/pages/helpfarm/helpfarm-detail/helpfarm-detail?id=' + poster[1]
  115. })
  116. } else if (project.length > 0) {
  117. this.scanPoster()
  118. wx.redirectTo({
  119. url: '/pages/projects/project-detail/project-detail?id=' + project[1]
  120. })
  121. } else {
  122. wx.switchTab({
  123. url: '/pages/home/home'
  124. })
  125. }
  126. }.bind(this), val + 1000)
  127. },
  128. scanPoster: function (val, type) {
  129. var that = this
  130. var url = 'v1/poster/scan'
  131. var params = {
  132. params: scene
  133. }
  134. var success = function (res) {
  135. }
  136. _request.$get(url, params, success)
  137. },
  138. urlType: function (val) {
  139. let type = [
  140. 'pages/projects/projects?',
  141. 'pages/helpfarm/helpfarm?',
  142. 'pages/customservice/customservice?',
  143. 'pages/user/all/all?',
  144. ]
  145. let i = -1
  146. for (let a in type) {
  147. if (type[a].indexOf(val) > -1) {
  148. i = a
  149. let str = type[i]
  150. wx.switchTab({
  151. url: '/' + str.substring(0, str.length - 1)
  152. })
  153. break
  154. }
  155. }
  156. if (i <= -1) {
  157. wx.redirectTo({
  158. url: '/' + val
  159. })
  160. }
  161. },
  162. getUserInfo: function (val) {
  163. var channel_id = 0
  164. if (channel && Number(channel.parent_id) > 0) {
  165. channel_id = Number(channel.parent_id)
  166. }
  167. var that = this
  168. if (val.detail.errMsg === 'getUserInfo:ok') {
  169. wx.showLoading({
  170. title: '加载中'
  171. })
  172. _request.sendInfo(val, channel_id, invite, that)
  173. }
  174. },
  175. getVersion: function (val) {
  176. this.check()
  177. this.getAnimation(val)
  178. // var that = this
  179. // var url = 'v1/xcx/version/' + version
  180. // var params = {}
  181. // var success = function (res) {
  182. // if (res.data && res.data.state === 0) {
  183. // getApp().globalData.vershow = false
  184. // }
  185. // that.check()
  186. // that.getAnimation(val)
  187. // }
  188. // _request.$get(url, params, success)
  189. },
  190. check: function () {
  191. var that = this
  192. var url = 'v1/user/check'
  193. var params = {
  194. }
  195. var success = function (res) {
  196. getApp().globalData.wx_id = res.data.wx_user_id
  197. }
  198. _request.$get(url, params, success)
  199. }
  200. })