No Description

app.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Initialize your app
  2. var myApp = new Framework7({
  3. animateNavBackIcon: true,
  4. modalButtonOk: '确定',
  5. modalButtonCancel: '取消'
  6. });
  7. var $$ = Dom7;
  8. var mainView = myApp.addView('.view-main', {
  9. dynamicNavbar: true
  10. });
  11. function getCategory(package_id){
  12. var cate_id = '';
  13. var html = '', res = null, className = '';
  14. $$.post('/user/information/getclassification', { package_id: package_id}, function (data) {
  15. console.log(JSON.parse(data))
  16. res = JSON.parse(data);
  17. if (res.errno == 0 && res.rst != []) {
  18. html += '<li><a data-label="'+ res.rst[0] +'" href="#nav1" class="tab-link active">'+ res.rst[0] +'</a></li><li><a data-label="'+ res.rst[1] +'" href="#nav2" class="tab-link">'+ res.rst[1] +'</a></li>';
  19. $$('#nav').html(html);
  20. }
  21. });
  22. }
  23. function getList(package_id, classification_id, id, page){
  24. var html = '', res = null, className = '';
  25. $$.post('/user/information/getinformationsbypackage', { package_id: package_id, classification_id: classification_id, page: page}, function (data) {
  26. // 请求成功
  27. res = JSON.parse(data);
  28. var pageInfo = res.rst.listdata.pageinfo;
  29. if (res.errno == 0) {
  30. // 添加banner
  31. // if (res.rst.banner !== null) {
  32. // $$('.swiper-slide').html('<a class="external" href="details.html?id='+ res.rst.banner.id +'"><img src="'+ res.rst.banner.thumbnail +'"></a>');
  33. // }
  34. // list 循环
  35. if (pageInfo.page == 1) {
  36. $$(id).html('');
  37. $$('.infinite-scroll-preloader').remove();
  38. // loading = false;
  39. }
  40. if (pageInfo.page == 1 && pageInfo.hasNext) {
  41. $$('.infinite-scroll').append('<div class="infinite-scroll-preloader"><div class="preloader"></div></div>');
  42. }
  43. if(!pageInfo.hasNext){
  44. // myApp.detachInfiniteScroll($$('.infinite-scroll'));
  45. // console.log('test');
  46. $$('.infinite-scroll-preloader').remove();
  47. }else{
  48. loading = false;
  49. }
  50. console.log(res.rst.listdata.data)
  51. $$.each(res.rst.listdata.data , function(index, el) {
  52. html += '<li><a class="external" href="details.html?id='+el.id+'"> <div class="content fl"> <h5 class="elli">'+ el.title +'</h5> <div class="label"> <span class="fl" style="max-width: 30%;">'+ el.source +'</span> <span class="zixun_number" style="max-width: 60%; padding-left:0.4rem">'+ el.page_views +'人阅读</span></div></div> <div class="img-box fr"><img src="'+ el.thumbnail +'"></div> </a></li>';
  53. });
  54. $$(id).append(html);
  55. }else if(res.errno == 40044){
  56. myApp.detachInfiniteScroll($$('.infinite-scroll'));
  57. $$('.infinite-scroll-preloader').remove();
  58. // if (pageInfo.page == 1) {
  59. // $$(id).html('<li class="nomore"><p>没有数据了~</p></li>');
  60. // }else{
  61. // if ($$(id + ' li.nomore').length == 0) {
  62. // // $$(id).append('<li class="nomore"><p>已全部加载完成</p></li>');
  63. // }
  64. // }
  65. }
  66. });
  67. }
  68. var loading = true, page = 1;
  69. var cate_id = '推荐',timer, index = 1;
  70. timer = setInterval( function(){
  71. // cate_id = $$('#nav li a.active').attr('data-label');
  72. if (cate_id != '' && cate_id != null ) {clearInterval(timer); getList('package_9',cate_id, '#nav1'); }
  73. $$('.infinite-scroll').on('infinite', function () {
  74. console.log(loading);
  75. if (loading) return;
  76. loading = true;
  77. setTimeout(function () {
  78. var nav = '';
  79. getList('package_9',cate_id, '#nav'+index, ++page);
  80. console.log(index);
  81. }, 500);
  82. });
  83. // 点击tab请求list接口
  84. $$('#nav li a').on('click', function(e){
  85. cate_id = $$(this).attr('data-label');
  86. index = $$(this).parent('li').index() + 1;
  87. page = 1;
  88. if (cate_id != '' && cate_id != null ) {getList('package_9', cate_id, '#nav'+index); }
  89. });
  90. },100);
  91. $$('.external img').click(function () {
  92. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  93. window.location.href='https://itunes.apple.com/cn/app/%E9%87%91%E7%89%9B%E8%AE%B0%E8%B4%A6/id1398141686?mt=8';
  94. }
  95. if(navigator.userAgent.match(/android/i)){
  96. window.location.href='http://android.myapp.com/myapp/detail.htm?apkName=com.kuxuan.jinniunote&ADTAG=mobile';
  97. }
  98. })