Brak opisu

index.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. const app = getApp()
  2. Page({
  3. data: {
  4. safeAreaTop:0,//距离上面的安全距离
  5. userMicroFollowList:[],
  6. hotVideoList:[],//热门视频
  7. statusNavBarHeight:app.data.statusNavBarHeight,
  8. videoTopicsList:[],//标签话题
  9. },
  10. onLoad() {
  11. this.init()
  12. this.getFollow()
  13. this.getVideoHotList()
  14. this.videoTopics()
  15. },
  16. onShow(){
  17. this.getFollow()
  18. this.getVideoHotList()
  19. },
  20. onPullDownRefresh: function () {//下拉加载
  21. this.getFollow()
  22. this.getVideoHotList()
  23. this.videoTopics()
  24. },
  25. goPageClaim(){
  26. swan.navigateTo({
  27. url: '/pages/claim/index/index',
  28. })
  29. },
  30. goSearch() {
  31. swan.navigateTo({
  32. url: '/pages/search/search',
  33. })
  34. },
  35. gpLivePage(){
  36. swan.navigateTo({
  37. url: '/pages/live/index/index',
  38. })
  39. },
  40. goUserDetail(e){
  41. swan.navigateTo({
  42. url: '/pages/userDrtail/index?user_id='+e.currentTarget.dataset.user_id,
  43. })
  44. },
  45. goVideoDetail(e){
  46. swan.navigateTo({
  47. url: '/pages/videoDetail/videoDetail?video_id='+e.currentTarget.dataset.item.video_id+'&user_id='+e.currentTarget.dataset.item.user_id,
  48. })
  49. },
  50. switchPlatform(){//平台切换
  51. var _this = this;
  52. swan.showActionSheet({
  53. itemList: ['快手版', '抖音版'],
  54. success (res) {
  55. if(res.tapIndex == 1||res.tapIndex == 0){
  56. swan.navigateToMiniProgram({
  57. appId: 'wx187b26eedae4ad85',
  58. path: '/pages/index/index?platform='+(res.tapIndex+1),
  59. success(res) {
  60. swan.showToast({
  61. title: '跳转成功',
  62. })
  63. },
  64. fail(err) {
  65. }
  66. })
  67. }
  68. },
  69. fail (res) {
  70. }
  71. })
  72. },
  73. init(){//初始化
  74. this.setData({
  75. safeAreaTop:app.data.safeAreaTop,
  76. })
  77. },
  78. getFollow(){//我的收藏
  79. app.func.req('/api/sphUserConsole/followList', 'get', {
  80. page:1,
  81. page_size:10,
  82. start_time:app.func.getDay(-1,false),
  83. end_time: app.func.getDay(-1,false),
  84. sort:'fans_count'
  85. }, (res) => {
  86. swan.stopPullDownRefresh();
  87. if(res && res.errno == 0){
  88. //成功
  89. this.setData({
  90. userMicroFollowList:res.rst.data.slice(0,6)
  91. })
  92. }else{
  93. swan.showToast({
  94. title: res.err,
  95. icon: 'none',
  96. duration: 2000
  97. })
  98. }
  99. },()=>{
  100. swan.stopPullDownRefresh();
  101. })
  102. },
  103. getVideoHotList(){//热门视频
  104. app.func.req('/api/sphVideo/hotList', 'get', {
  105. page:1,
  106. pagesize:10,
  107. }, (res) => {
  108. if(res && res.errno == 0){
  109. //成功
  110. this.setData({
  111. hotVideoList:res.rst.data
  112. })
  113. }else{
  114. swan.showToast({
  115. title: res.err,
  116. icon: 'none',
  117. duration: 2000
  118. })
  119. }
  120. },()=>{
  121. })
  122. },
  123. videoTopics(){//标签话题
  124. app.func.req('/api/sphVideo/videoTopics', 'get', {
  125. type:3,
  126. sort:'like_count_avg'
  127. }, (res) => {
  128. if(res && res.errno == 0){
  129. //成功
  130. var arr = res.rst.slice(0,6)
  131. arr.forEach((item)=>{
  132. item.like_count_avg = app.func.NumberHandle(item.like_count_avg)
  133. item.red_count = app.func.NumberHandle(item.red_count)
  134. })
  135. this.setData({
  136. videoTopicsList:res.rst.slice(0,6)
  137. })
  138. }else{
  139. swan.showToast({
  140. title: res.err,
  141. icon: 'none',
  142. duration: 2000
  143. })
  144. }
  145. },()=>{
  146. })
  147. },
  148. goPageSwitch(e){
  149. var data = e.currentTarget.dataset;
  150. if(data.page == '/pages/cyRank/index'){
  151. app.data.cyRank_type = data.type
  152. }
  153. swan.switchTab({
  154. url: data.page,
  155. })
  156. },
  157. toTopic(e) {
  158. swan.navigateTo({
  159. url: '/pages/topicDetail/topicDetail?name='+e.currentTarget.dataset.item.topic_name,
  160. })
  161. },
  162. goLogin(){
  163. swan.redirectTo({
  164. url: '/pages/welcome/welcome',
  165. })
  166. },
  167. goSphRank(){
  168. swan.switchTab({
  169. url: '/pages/sphRank/index',
  170. })
  171. },
  172. onShareAppMessage: function (res) {
  173. return app.shareEvent(res,'/pages/index/index')
  174. }
  175. })