大数据平台的小程序版本

index.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. // pages/sphRank/index.js
  2. const app = getApp()
  3. Page({
  4. data: {
  5. isShow: true,
  6. notice: '公告:“-”代表该视频号预估粉丝增量数据获取异常,对您造成的不便尽请谅解.',
  7. field_type: 7,
  8. buttonTop: wx.getMenuButtonBoundingClientRect().top,
  9. infoList: [],
  10. isIpx: app.data.systemInfo.isIpx ? true : false, //底部按钮适配Iphone X
  11. rankType:1,
  12. statusNavBarHeight:app.data.statusNavBarHeight,
  13. safeAreaTop:0,//距离上面的安全距离
  14. authorTypeList:[{
  15. id:'',
  16. top_label:'全部'
  17. }],
  18. authorType:{
  19. id:'',
  20. top_label:'全部'
  21. },
  22. authorTypeFlag:false,
  23. start_time:'',
  24. end_time:'',
  25. pagesize:20,
  26. cycleList:[
  27. {value:0,label:'日榜'},
  28. {value:1,label:'周榜'},
  29. {value:2,label:'月榜'},
  30. ],
  31. cycle:0,
  32. dayList:[app.func.getDay(-1,false),app.func.getDay(-2,false),app.func.getDay(-3,false),app.func.getDay(-4,false),app.func.getDay(-5,false),app.func.getDay(-6,false),app.func.getDay(-7,false)],
  33. weekList: [
  34. {end_time:app.func.getDay(-1,false),start_time:app.func.getDay(-7,false)},
  35. {end_time:app.func.getDay(-8,false),start_time:app.func.getDay(-15,false)},
  36. {end_time:app.func.getDay(-16,false),start_time:app.func.getDay(-23,false)},
  37. ],
  38. monthList:[
  39. {
  40. name: app.func.getDay(-30,false) + ' 至 ' + app.func.getDay(-1,false),
  41. end_time: app.func.getDay(-1,false),
  42. start_time: app.func.getDay(-30,false),
  43. }
  44. ],
  45. timeList:[],
  46. fanInfoListTree:[],
  47. fanInfoList:[],
  48. isScroll:true,
  49. timeFlag:false,
  50. choiceType:1,
  51. containerScrollTop:0,
  52. loading:true,
  53. page:1,
  54. total:0,
  55. isHaveMoreData:true,
  56. loading:true,
  57. scrollTop:0,
  58. },
  59. onLoad: function (options) {
  60. this.setData({
  61. rankType: options&&options.type?options.type:1,
  62. field_type: this.data.rankType==1?7:9,
  63. safeAreaTop:app.data.safeAreaTop,
  64. })
  65. if(this.data.cycle == 0){
  66. this.setData({
  67. start_time:this.data.dayList[0],
  68. end_time:this.data.dayList[0]
  69. })
  70. }
  71. this.setTime()
  72. this.getAuthorType()
  73. this.eventInit()
  74. },
  75. /**
  76. * 生命周期函数--监听页面显示
  77. */
  78. onShow: function () {
  79. this.setData({
  80. rankType: app.data.sph_type?app.data.sph_type:this.data.rankType,
  81. field_type: this.data.rankType==1?7:9,
  82. })
  83. if((this.data.rankType==1&&this.data.fanInfoList.length==0)||(this.data.rankType==2&&this.data.infoList.length==0)) {
  84. this.getAuthorType()
  85. this.eventInit()
  86. }
  87. },
  88. switchShow() {
  89. this.setData({
  90. isShow: false
  91. })
  92. },
  93. goScrolltop:function(e){//返回顶部
  94. if (wx.pageScrollTo) {
  95. wx.pageScrollTo({
  96. scrollTop: 0
  97. })
  98. } else {
  99. wx.showModal({
  100. title: '提示',
  101. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  102. })
  103. }
  104. },
  105. setTime() {
  106. var timeList = this.data.dayList,start_time = '';
  107. if(app.func.getDay(0,true).now.split(" ")[1].split(":")[0]<=8) {
  108. timeList = timeList.slice(1,timeList.length)
  109. start_time = app.func.getDay(-2,false)
  110. this.setData({
  111. end_time: app.func.getDay(-2,false)
  112. })
  113. }
  114. this.setData({
  115. timeList:timeList,
  116. start_time: start_time?start_time:app.func.getDay(-1,false)
  117. })
  118. },
  119. eventInit(){
  120. if(this.data.rankType==1){
  121. this.fansIncrIndex(1)
  122. }
  123. if(this.data.rankType == 2){
  124. this.goodVideoNumberList(1)
  125. }
  126. },
  127. // 互动榜
  128. goodVideoNumberList(page){
  129. wx.showLoading({
  130. title: '加载中',
  131. })
  132. this.setData({
  133. page:page,
  134. loading:true
  135. })
  136. app.func.req('/api/sphUserList/goodVideoNumberList', 'get', {
  137. page:page,
  138. label_id:this.data.authorType.id,
  139. sort: 'like_divided_by_fans',
  140. date:this.data.start_time,
  141. page_size:this.data.pagesize,
  142. type:this.data.cycle
  143. }, (res) => {
  144. wx.hideLoading()
  145. this.setData({
  146. loading:false
  147. })
  148. wx.stopPullDownRefresh();
  149. if(res && res.errno == 0){
  150. //成功
  151. if(page==1){
  152. this.setData({
  153. containerScrollTop:0,
  154. infoList:[],
  155. fanInfoListTree:[],
  156. total:0,
  157. })
  158. }
  159. this.setData({
  160. infoList:this.data.infoList.length==0?res.rst.data:(this.data.infoList.concat(res.rst.data)),
  161. })
  162. this.setData({
  163. fanInfoListTree:page==1?res.rst.data:this.data.fanInfoListTree,
  164. total:res.rst.pageInfo.total
  165. })
  166. if(this.data.page*this.data.pagesize>=this.data.total){
  167. this.setData({
  168. isHaveMoreData:false
  169. })
  170. }else{
  171. this.setData({
  172. isHaveMoreData:true
  173. })
  174. }
  175. }else{
  176. wx.showToast({
  177. title: res.err,
  178. icon: 'none',
  179. duration: 2000
  180. })
  181. }
  182. },()=>{
  183. wx.stopPullDownRefresh();
  184. this.setData({
  185. loading:false
  186. })
  187. wx.hideLoading()
  188. })
  189. },
  190. fansIncrIndex(page){
  191. wx.showLoading({
  192. title: '加载中',
  193. })
  194. this.setData({
  195. page:page,
  196. loading:true
  197. })
  198. app.func.req('/api/sphUserList/fansIncrIndex', 'get', {
  199. page:page,
  200. label_id:this.data.authorType.id,
  201. sort: 'fans_incr',
  202. start_time:this.data.start_time,
  203. end_time:this.data.end_time,
  204. page_size:this.data.pagesize,
  205. type:this.data.cycle
  206. }, (res) => {
  207. wx.stopPullDownRefresh();
  208. wx.hideLoading()
  209. this.setData({
  210. loading:false
  211. })
  212. if(res && res.errno == 0){
  213. //成功
  214. if(page==1){
  215. this.setData({
  216. containerScrollTop:0,
  217. fanInfoList:[],
  218. fanInfoListTree:[],
  219. total:0,
  220. })
  221. }
  222. this.setData({
  223. fanInfoList:this.data.fanInfoList.length==0?res.rst.data:(this.data.fanInfoList.concat(res.rst.data)),
  224. })
  225. this.setData({
  226. fanInfoListTree:page==1?res.rst.data:this.data.fanInfoListTree,
  227. total:res.rst.pageInfo.total
  228. })
  229. if(this.data.page*this.data.pagesize>=this.data.total){
  230. this.setData({
  231. isHaveMoreData:false
  232. })
  233. }else{
  234. this.setData({
  235. isHaveMoreData:true
  236. })
  237. }
  238. }else{
  239. wx.showToast({
  240. title: res.err,
  241. icon: 'none',
  242. duration: 2000
  243. })
  244. }
  245. },()=>{
  246. wx.stopPullDownRefresh();
  247. this.setData({
  248. loading:false
  249. })
  250. wx.hideLoading()
  251. })
  252. },
  253. getAuthorType(){//获取作者类别
  254. app.func.req('/api/sphUserList/labelList', 'get', {
  255. }, (res) => {
  256. if(res && res.errno == 0){
  257. var arr = [{
  258. id:'',
  259. top_label:'全部'
  260. }]
  261. this.setData({
  262. authorTypeList:arr.concat(res.rst)
  263. })
  264. }else{
  265. wx.showToast({
  266. title: res.err,
  267. icon: 'none',
  268. duration: 2000
  269. })
  270. }
  271. },()=>{
  272. })
  273. },
  274. cycleEvent(e){//点击日期类别筛选
  275. var data = e.currentTarget.dataset;
  276. if(this.data.cycle != data.info.value){
  277. if(data.info.value == 0){
  278. this.setData({
  279. timeList:this.data.dayList,
  280. start_time:this.data.dayList[0],
  281. end_time:this.data.dayList[0]
  282. })
  283. this.setTime()
  284. }
  285. if(data.info.value == 1){
  286. this.setData({
  287. timeList:this.data.weekList,
  288. start_time:this.data.weekList[0].start_time,
  289. end_time:this.data.weekList[0].end_time
  290. })
  291. }
  292. if(data.info.value == 2){
  293. this.setData({
  294. timeList:this.data.monthList,
  295. start_time:this.data.monthList[0].start_time,
  296. end_time:this.data.monthList[0].end_time
  297. })
  298. }
  299. this.setData({
  300. cycle: data.info.value
  301. })
  302. this.goScrolltop()
  303. this.eventInit()
  304. }
  305. },
  306. cycle_0_click(e){
  307. var data = e.currentTarget.dataset
  308. if(this.data.start_time != data.info || this.data.end_time != data.info){
  309. this.setData({
  310. start_time:e.currentTarget.dataset.info,
  311. end_time:e.currentTarget.dataset.info
  312. })
  313. this.goScrolltop()
  314. this.eventInit()
  315. }
  316. this.closeToast()
  317. },
  318. cycle_1_click(e){
  319. var data = e.currentTarget.dataset
  320. if(this.data.start_time != data.info.start_time || this.data.end_time != data.info.end_time){
  321. this.setData({
  322. start_time:e.currentTarget.dataset.info.start_time,
  323. end_time:e.currentTarget.dataset.info.end_time
  324. })
  325. this.goScrolltop()
  326. this.eventInit()
  327. }
  328. this.closeToast()
  329. },
  330. timeChoiceClick(e){
  331. var data = e.currentTarget.dataset;
  332. if((this.data.choiceType == 2 && data.type == 2)||(this.data.choiceType != data.type && data.type == 2)){
  333. this.setData({
  334. authorTypeFlag: !this.data.authorTypeFlag,
  335. timeFlag:false
  336. })
  337. }
  338. if((this.data.choiceType != data.type && data.type == 1) || (this.data.choiceType == 1 && data.type == 1)){
  339. this.setData({
  340. timeFlag: !this.data.timeFlag,
  341. authorTypeFlag:false
  342. })
  343. }
  344. this.setData({
  345. choiceType:data.type
  346. })
  347. if(!this.data.timeFlag && !this.data.authorTypeFlag){
  348. this.setData({
  349. isScroll:true
  350. })
  351. }
  352. if(this.data.timeFlag || this.data.authorTypeFlag){
  353. this.setData({
  354. isScroll:false
  355. })
  356. }
  357. },
  358. authorTypeClick(e){
  359. var data = e.currentTarget.dataset;
  360. if(data.info.id != this.data.authorType.id){
  361. this.setData({
  362. authorType:data.info
  363. })
  364. this.goScrolltop()
  365. this.eventInit()
  366. }
  367. this.closeToast()
  368. },
  369. closeToast(){
  370. this.setData({
  371. authorTypeFlag:false,
  372. timeFlag: false,
  373. isScroll:true
  374. })
  375. },
  376. rankTypeClick(e){//头部榜单type
  377. this.setTime();
  378. var data = e.currentTarget.dataset
  379. if(this.data.rankType == data.type){
  380. return;
  381. }
  382. if(data.type==2){
  383. this.setData({
  384. field_type: 9,
  385. cycle:0,
  386. timeList:this.data.dayList,
  387. start_time:this.data.dayList[0],
  388. end_time:this.data.dayList[0]
  389. })
  390. }else if(data.type==1) {
  391. this.setData({
  392. field_type: 7
  393. })
  394. }
  395. this.setData({
  396. rankType: data.type,
  397. fanInfoList: []
  398. })
  399. app.data.sph_type = this.data.rankType
  400. this.goScrolltop()
  401. this.eventInit()
  402. },
  403. bindscrolltolower(){//滚动到底部
  404. if(this.data.loading){
  405. return;
  406. }
  407. if(this.data.page * this.data.pagesize < this.data.total){
  408. this.setData({
  409. page:this.data.page+1,
  410. isHaveMoreData:true
  411. })
  412. if(this.data.rankType==1){
  413. this.fansIncrIndex(this.data.page)
  414. }
  415. if(this.data.rankType == 2){
  416. this.goodVideoNumberList(this.data.page)
  417. }
  418. }else{
  419. this.setData({
  420. isHaveMoreData:false
  421. })
  422. }
  423. },
  424. goSearch() {
  425. wx.navigateTo({
  426. url: '/pages/search/search',
  427. })
  428. },
  429. followEvent(e){
  430. var data = e.currentTarget.dataset;
  431. var Interface = '/api/sphUserConsole/createFollow'
  432. if(data.is_follow==1){
  433. Interface = '/api/sphUserConsole/cancelFollow'
  434. }
  435. this.setData({
  436. loading:true
  437. })
  438. wx.showLoading({
  439. title: '加载中',
  440. })
  441. app.func.req(Interface, 'post', {
  442. uid:data.user_id
  443. }, (res) => {
  444. wx.hideLoading()
  445. this.setData({
  446. loading:false
  447. })
  448. if(res && res.errno == 0){
  449. var info = this.data.fanInfoListTree,msg='';
  450. if(Interface == '/api/sphUserConsole/cancelFollow'){
  451. info[data.id].is_follow = 0;
  452. msg = '取消收藏成功!'
  453. }else{
  454. msg = '收藏成功'
  455. info[data.id].is_follow = 1;
  456. }
  457. wx.showToast({
  458. title:msg,
  459. icon: 'none',
  460. duration: 2000
  461. })
  462. this.setData({
  463. fanInfoListTree:info
  464. })
  465. }else{
  466. wx.showToast({
  467. title: res.err,
  468. icon: 'none',
  469. duration: 2000
  470. })
  471. }
  472. },()=>{
  473. this.setData({
  474. loading:false
  475. })
  476. wx.hideLoading()
  477. })
  478. },
  479. toUserDetail(e){
  480. wx.navigateTo({
  481. url: '/pages/userDrtail/index?user_id='+e.currentTarget.dataset.user_id,
  482. })
  483. },
  484. /**
  485. * 生命周期函数--监听页面初次渲染完成
  486. */
  487. onReady: function () {
  488. },
  489. /**
  490. * 生命周期函数--监听页面隐藏
  491. */
  492. onHide: function () {
  493. },
  494. /**
  495. * 生命周期函数--监听页面卸载
  496. */
  497. onUnload: function () {
  498. },
  499. /**
  500. * 页面相关事件处理函数--监听用户下拉动作
  501. */
  502. onPullDownRefresh: function () {
  503. this.eventInit()
  504. },
  505. /**
  506. * 页面上拉触底事件的处理函数
  507. */
  508. onReachBottom: function () {
  509. if(this.data.loading){
  510. return;
  511. }
  512. if(this.data.page * this.data.pagesize < this.data.total){
  513. this.setData({
  514. page:this.data.page+1,
  515. isHaveMoreData:true
  516. })
  517. if(this.data.rankType==1){
  518. this.fansIncrIndex(this.data.page)
  519. }
  520. if(this.data.rankType == 2){
  521. this.goodVideoNumberList(this.data.page)
  522. }
  523. }else{
  524. this.setData({
  525. isHaveMoreData:false
  526. })
  527. }
  528. },
  529. onPageScroll: function(res) {//获取滑动的距离
  530. this.setData({
  531. scrollTop:res.scrollTop
  532. })
  533. },
  534. goScrolltop:function(e){//返回顶部
  535. if (wx.pageScrollTo) {
  536. wx.pageScrollTo({
  537. scrollTop: 0
  538. })
  539. } else {
  540. wx.showModal({
  541. title: '提示',
  542. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  543. })
  544. }
  545. },
  546. /**
  547. * 用户点击右上角分享
  548. */
  549. onShareAppMessage: function (res) {
  550. if(this.data.rankType==1) {
  551. return {
  552. title:'【免费】视频号分析平台,盘点不同分类下涨粉最快的视频号',
  553. }
  554. }else {
  555. return {
  556. title:'【免费】视频号分析平台,盘点不同分类下互动最好的视频号',
  557. }
  558. }
  559. }
  560. })