index.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {extend name="public/container"}
  2. {block name="title"}{$title}{/block}
  3. {block name="content"}
  4. <style type="text/css">body{background:#f5f5f5;}</style>
  5. <div class="page-list" id="guide">
  6. <section>
  7. <div ref="bsDom">
  8. <div>
  9. <div class="new-list" v-show="type == 'article'" v-cloak="">
  10. <ul>
  11. <li class="clearfix" v-for="item in article.list">
  12. <a :href="getArticleUrl(item)">
  13. <div class="picture fl"><img :src="item.image_input" /></div>
  14. <div class="text-info fr flex">
  15. <p class="tit" v-text="item.title"></p>
  16. <p class="content" v-text="item.synopsis"></p>
  17. <div class="time-wrapper">
  18. <span class="time" v-text="item.add_time"></span>
  19. <span class="count">浏览: {{item.visit}}次</span>
  20. </div>
  21. </div>
  22. </a>
  23. </li>
  24. </ul>
  25. </div>
  26. <p class="loading-line" v-show="loading == true"><i></i><span>正在加载中</span><i></i></p>
  27. <p class="loading-line" v-show="loading == false && loaded == false" v-cloak=""><i></i><span>加载更多</span><i></i></p>
  28. <p class="loading-line" v-show="loading == false && loaded == true" v-cloak=""><i></i><span>没有更多了</span><i></i></p>
  29. </div>
  30. </div>
  31. </section>
  32. </div>
  33. <script>
  34. require(['vue','axios','better-scroll','helper','store'],function(Vue,axios,BScroll,$h,storeApi){
  35. $cid = '<?=$cid?>' || '';
  36. new Vue({
  37. el:"#guide",
  38. data:{
  39. type:'article',
  40. article:{
  41. first:0,
  42. limit:8,
  43. list:[],
  44. loaded:false,
  45. top:0
  46. },
  47. loading: false,
  48. scroll:null
  49. },
  50. watch:{
  51. type:function(v,old){
  52. this[old].top = this.scroll.startY;
  53. this[v].list.length || this.getList();
  54. this.$nextTick(function(){
  55. this.scroll.scrollTo(0,this[v].top);
  56. this.scroll.refresh();
  57. });
  58. }
  59. },
  60. computed:{
  61. loaded:function(){
  62. return this[this.type].loaded;
  63. }
  64. },
  65. methods:{
  66. getArticleUrl:function(article){
  67. return article.url ? article.url : $h.U({c:'article',a:'visit',p:{id:article.id}});
  68. },
  69. getList:function(){
  70. if(this.loading) return ;
  71. this.getArticleList();
  72. },
  73. getArticleList:function(){
  74. var that = this,type = this.type,group = that[type];
  75. if(group.loaded) return ;
  76. this.loading = true;
  77. storeApi.getArticleList({
  78. cid:$cid||0,
  79. first:group.first,
  80. limit:group.limit
  81. },function(res){
  82. var list = res.data.data;
  83. group.loaded = list.length < group.limit;
  84. group.first += list.length;
  85. group.list = group.list.concat(list);
  86. that.$set(that,type,group);
  87. that.loading = false;
  88. that.$nextTick(function(){
  89. if(list.length) that.bScrollInit();
  90. that.scroll.finishPullUp();
  91. });
  92. },function(){that.loading = false});
  93. },
  94. bScrollInit:function () {
  95. var that = this;
  96. if(this.scroll === null){
  97. this.$refs.bsDom.style.height = (document.documentElement.clientHeight)+'px';
  98. this.$refs.bsDom.style.overflow = 'hidden';
  99. this.scroll = new BScroll(this.$refs.bsDom,{click:true,probeType:1,cancelable:false,deceleration:0.005,snapThreshold:0.1});
  100. this.scroll.on('pullingUp',function(){
  101. that.loading == false && that.getList();
  102. })
  103. }else{
  104. this.scroll.refresh();
  105. }
  106. }
  107. },
  108. mounted:function(){
  109. this.getList();
  110. }
  111. })
  112. })
  113. </script>
  114. {/block}