问星数据小程序

index.js 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. bringGoodsList:[],
  7. industryRankList:[],
  8. fansGrowthList:[],
  9. rewardInRankList:[],
  10. rewardOutRankList:[],
  11. start_time:app.func.getDay(-1,false),
  12. end_time:app.func.getDay(-1,false),
  13. reqLoading: {
  14. bringGoods:false,
  15. industryRank:false,
  16. fansGrowth:false,
  17. rewardInRank:false,
  18. rewardOutRank:false,
  19. hotDr:false,
  20. userMicroFollow:false
  21. },
  22. hotDrList:[],
  23. userMicroFollowList:[],
  24. swiperIndex:0
  25. },
  26. onShow: function (options) {
  27. if(!wx.getStorageSync('isLogin')){//解决未登录情况下,点击左上角home
  28. wx.redirectTo({
  29. url: '/pages/welcome/welcome',
  30. })
  31. }else{
  32. this.userMicroFollow();//首页关注列表
  33. }
  34. },
  35. onLoad: function () {
  36. //登录判断
  37. if(wx.getStorageSync('ttl')){
  38. this.getBringGoods();//带货达人
  39. this.getIndustryRank();//创作达人
  40. this.getFansGrowth();//涨粉达人
  41. this.getRewardInRank();//礼物收入
  42. this.getRewardOutRank();//土豪打赏
  43. this.getHotDr();
  44. this.userMicroFollow();//首页关注列表
  45. wx.showLoading({
  46. title: '加载中',
  47. })
  48. }
  49. },
  50. goHrDetail(e){
  51. wx.navigateTo({
  52. url: '/pages/hrDetail/hrDetail?user_id=' + e.currentTarget.dataset.userid ,
  53. })
  54. },
  55. swiper(e){
  56. this.setData({
  57. swiperIndex:e.detail.current
  58. })
  59. },
  60. goMyFollow(){//去我的关注页面
  61. wx.switchTab({
  62. url: '/pages/follow/follow',
  63. })
  64. },
  65. swiperGoPage(e){//点击轮播图去对应的页面
  66. console.log(e)
  67. var item = e.currentTarget.dataset.item;
  68. if(item.type == 2){
  69. if(item.is_live_now == 1){//直播中
  70. wx.navigateTo({
  71. url: '/pages/liveBoard/index?live_stream_id='+item.show_info.live_stream_id + '&user_id=' + item.user_id,
  72. })
  73. }else{//最近直播
  74. wx.navigateTo({
  75. url: '/pages/liveDetail/index?id='+item.show_info.live_stream_id + '&user_id=' + item.user_id,
  76. })
  77. }
  78. }else if(item.type == 1){//视频
  79. wx.navigateTo({
  80. url: '/pages/videoDetail/index?photoid=' + item.video_info.photo_id + '&userid=' + item.user_id,
  81. })
  82. }else{//暂无直播、视频数据
  83. wx.navigateTo({
  84. url: '/pages/hrDetail/hrDetail?user_id='+item.user_id,
  85. })
  86. }
  87. },
  88. goUserDetail(e){//去用户详情
  89. wx.navigateTo({
  90. url: '/pages/hrDetail/hrDetail?user_id='+e.currentTarget.dataset.user_id,
  91. })
  92. },
  93. userMicroFollow(){//首页关注列表
  94. app.func.req('/v2/api/kwai/userMicroFollow', 'get', {
  95. }, (res) => {
  96. this.loadingEvent('userMicroFollow')
  97. console.log(res)
  98. if(res && res.errno == 0){
  99. //成功
  100. this.setData({
  101. userMicroFollowList:res.rst
  102. })
  103. }else{
  104. wx.showToast({
  105. title: res.err,
  106. icon: 'none',
  107. duration: 2000
  108. })
  109. }
  110. },()=>{
  111. this.loadingEvent('userMicroFollow')
  112. })
  113. },
  114. getBringGoods(){//带货达人榜
  115. app.func.req('/api/bang/zhibodaihuo', 'post', {
  116. 'page': 1,
  117. 'pagesize':3,
  118. 'is_elite':1,
  119. 'starttime':this.data.start_time + ' 00:00:00',
  120. 'endtime':this.data.end_time + ' 23:59:59',
  121. 'sort_type':1
  122. }, (res) => {
  123. this.loadingEvent('bringGoods')
  124. if(res && res.errno == 0){
  125. //成功
  126. this.setData({
  127. bringGoodsList: res.rst.list
  128. })
  129. }else{
  130. wx.showToast({
  131. title: res.err,
  132. icon: 'none',
  133. duration: 2000
  134. })
  135. }
  136. },()=>{
  137. this.loadingEvent('bringGoods')
  138. })
  139. },
  140. getIndustryRank(){//创作达人榜
  141. app.func.req('/v2/api/kwaiUserTop/industryRank', 'get', {
  142. 'page': 1,
  143. 'pagesize':3,
  144. 'days':1
  145. }, (res) => {
  146. this.loadingEvent('industryRank')
  147. if(res && res.errno == 0){
  148. //成功
  149. this.setData({
  150. industryRankList: res.rst.data
  151. })
  152. }else{
  153. wx.showToast({
  154. title: res.err,
  155. icon: 'none',
  156. duration: 2000
  157. })
  158. }
  159. },()=>{
  160. this.loadingEvent('industryRank')
  161. })
  162. },
  163. getFansGrowth(){//涨粉达人榜
  164. app.func.req('/v2/api/kwaiUserTop/fansGrowth', 'get', {
  165. 'page': 1,
  166. 'pagesize':3,
  167. 'days':1
  168. }, (res) => {
  169. this.loadingEvent('fansGrowth')
  170. if(res && res.errno == 0){
  171. //成功
  172. this.setData({
  173. fansGrowthList: res.rst.data
  174. })
  175. }else{
  176. wx.showToast({
  177. title: res.err,
  178. icon: 'none',
  179. duration: 2000
  180. })
  181. }
  182. },()=>{
  183. this.loadingEvent('fansGrowth')
  184. })
  185. },
  186. getRewardInRank(){//礼物收入榜
  187. app.func.req('/v2/api/show/rewardInRank', 'get', {
  188. 'page': 1,
  189. 'pagesize':3,
  190. }, (res) => {
  191. this.loadingEvent('rewardInRank')
  192. if(res && res.errno == 0){
  193. //成功
  194. this.setData({
  195. rewardInRankList: res.rst.data.slice(0,3)
  196. })
  197. }else{
  198. wx.showToast({
  199. title: res.err,
  200. icon: 'none',
  201. duration: 2000
  202. })
  203. }
  204. },()=>{
  205. this.loadingEvent('rewardInRank')
  206. })
  207. },
  208. getRewardOutRank(){//土豪打赏榜
  209. app.func.req('/v2/api/show/rewardOutRank', 'get', {
  210. 'page': 1,
  211. 'pagesize':3,
  212. 'start_time':this.data.start_time,
  213. 'end_time':this.data.end_time
  214. }, (res) => {
  215. this.loadingEvent('rewardOutRank')
  216. if(res && res.errno == 0){
  217. //成功
  218. this.setData({
  219. rewardOutRankList: res.rst.data.slice(0,3)
  220. })
  221. }else{
  222. wx.showToast({
  223. title: res.err,
  224. icon: 'none',
  225. duration: 2000
  226. })
  227. }
  228. },()=>{
  229. this.loadingEvent('rewardOutRank')
  230. })
  231. },
  232. getHotDr(){//热门达人
  233. app.func.req('/api/kwaiUser/redUserList', 'get', {
  234. 'page': 1,
  235. 'pagesize':10,
  236. 'starttime':app.func.getDay(-30,false),
  237. 'endtime':app.func.getDay(-1,false)
  238. }, (res) => {
  239. this.loadingEvent('hotDr')
  240. if(res && res.errno == 0){
  241. //成功
  242. var list = res.rst.data;
  243. list.forEach((item)=>{
  244. if(item.categorys){
  245. item.categorys_arr = item.categorys.splice(',')
  246. }
  247. })
  248. this.setData({
  249. hotDrList: res.rst.data
  250. })
  251. }else{
  252. wx.showToast({
  253. title: res.err,
  254. icon: 'none',
  255. duration: 2000
  256. })
  257. }
  258. },()=>{
  259. this.loadingEvent('hotDr')
  260. })
  261. },
  262. loadingEvent(req){
  263. var data = `reqLoading.${req}`;
  264. this.setData({
  265. [data]:true
  266. })
  267. var flag = false;
  268. for(var i in this.data.reqLoading){
  269. if(!this.data.reqLoading[i]){
  270. flag = true;
  271. }
  272. }
  273. if(!flag){
  274. //接口全部加载完毕
  275. wx.hideLoading()
  276. }
  277. },
  278. goSearch(){
  279. wx.navigateTo({
  280. url: '/pages/search/search?type=1',
  281. })
  282. },
  283. onShareAppMessage: function () {
  284. var that = this;
  285. return {
  286. title: '酷炫网络',
  287. desc: '',
  288. path: 'pages/index/index',
  289. imageUrl: 'https://kx-bigdata.oss-cn-beijing.aliyuncs.com/Applet/shareImg.png?v=1.0.1',
  290. success: function (res) {
  291. // 转发成功
  292. wx.showToast({
  293. title: '分享成功',
  294. icon: "none"
  295. });
  296. },
  297. fail: function (res) {
  298. // 转发失败
  299. wx.showToast({
  300. title: '分享失败',
  301. icon: "none"
  302. })
  303. }
  304. }
  305. }
  306. })