news.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <gui-page :fullPage="true" ref="guiPage" :customFooter="true" :isLoading="pageLoading" iphoneXButtomStyle="background:#F8F8F8" :footerSets="{height:150, zIndex:100, bg:'none'}">
  3. <view slot="gBody" class="gui-flex1" style="background-color:#F8F8F8;">
  4. <view class="gui-margin-top gui-bg-gray search-warp gui-border-box" style="display: none;">
  5. <gui-search @inputting="inputting" @confirm="confirm"></gui-search>
  6. </view>
  7. <!-- 分类导航 -->
  8. <view class="header gui-border-b gui-border-box gui-flex gui-columns gui-justify-content-center"
  9. id="myheader">
  10. <gui-switch-navigation :size="150"
  11. activeLineBg="linear-gradient(to right, #008AFF,#008AFF)"
  12. :items="fetch.cate" @change="navchange"></gui-switch-navigation>
  13. </view>
  14. <!-- 滚动区域高度 = gBody - 自定义区域高度 -->
  15. <scroll-view :scroll-y="true" :show-scrollbar="false"
  16. :style="{height:mainHeight+'px'}"
  17. @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend"
  18. @scrolltolower="loadmorefun" @scroll="scroll">
  19. <!-- 刷新组件 -->
  20. <gui-refresh @reload="reload" ref="refreshcom"></gui-refresh>
  21. <!-- 数据展示区域 -->
  22. <view>
  23. <gui-article-list :articles="newsList" @newstap="newstap"></gui-article-list>
  24. </view>
  25. <!-- 加载组件 -->
  26. <gui-loadmore ref="loadmorecom"></gui-loadmore>
  27. </scroll-view>
  28. </view>
  29. <foot ref="foot" slot="gFooter" :value="foot_value"></foot>
  30. </gui-page>
  31. </template>
  32. <script>
  33. var graceJs = require('@/lib/GraceUI5/js/grace.js');
  34. import foot from '@/pages/index/foot.vue';
  35. export default {
  36. data() {
  37. return {
  38. foot_value : 1,
  39. fetch : {
  40. cate : [],
  41. info : [],
  42. },
  43. // 主体高度
  44. mainHeight : 200,
  45. // 滚动区域滚动距离
  46. scrollTop : 0,
  47. // 加载更多延迟
  48. loadMoreTimer : null,
  49. // 当前展示的分类索引
  50. cate_index : 0,
  51. // 新闻列表数据, 分类切换重新获取第一页
  52. newsList : [],
  53. // 页码
  54. page : 1
  55. }
  56. },
  57. components:{
  58. foot
  59. },
  60. onShow() {
  61. this.$nextTick(function() {
  62. this.$refs.foot.cur = this.foot_value;
  63. });
  64. },
  65. onLoad:function(){
  66. this.getInfo();
  67. // 01. 获取页面主体高度
  68. graceJs.getRefs('guiPage', this, 0, (ref)=>{
  69. ref.getDomSize('guiPageBody', (e)=>{
  70. // 主体高度 = 页面高度 - 自定义区域高度
  71. graceJs.select('#myheader', (e2)=>{
  72. // 如果自定义区域有 margin 尺寸获取不到请加上这个值,可以利用 uni.upx2px() 转换
  73. this.mainHeight = e.height - e2.height;
  74. // 第一次加载数据
  75. this.getData();
  76. });
  77. });
  78. });
  79. },
  80. // 重新加载
  81. onPullDownRefresh: function() {
  82. this.getInfo();
  83. },
  84. methods : {
  85. navchange:function(index){
  86. // 刷新当前分类对应的数据
  87. if(this.cate_index != index){
  88. this.page = 1;
  89. this.cate_index = index;
  90. this.getData(false);
  91. // 重置加载组件状态
  92. this.$refs.loadmorecom.stoploadmore();
  93. }
  94. },
  95. getInfo : function() {
  96. var self = this;
  97. var data = {};
  98. this.Dever.get(this, 'package/article/?l=api.cate', data);
  99. },
  100. // 新闻加载函数
  101. // isReload 代表下拉刷新
  102. getData : function (isReload) {
  103. var self = this;
  104. var data = {};
  105. if (this.fetch.cate.length > 0) {
  106. data.cate = this.fetch.cate[this.cate_index].id;
  107. } else {
  108. data.cate = 0;
  109. }
  110. data.noloading = 1;
  111. this.Dever.get(this, 'package/article/?l=api.getList', data, function(t) {
  112. if(self.page >= 2){
  113. if(t.info.length <= 0){
  114. self.$refs.loadmorecom.nomore();
  115. } else {
  116. self.newsList = self.newsList.concat(t.info);
  117. // 加载完成后停止加载动画
  118. self.$refs.loadmorecom.stoploadmore();
  119. }
  120. } else{
  121. self.newsList = [];
  122. self.newsList = t.info;
  123. // 刷新
  124. if(isReload){self.$refs.refreshcom.endReload();}
  125. }
  126. self.page++;
  127. });
  128. },
  129. scroll : function(e){
  130. this.scrollTop = e.detail.scrollTop;
  131. },
  132. // 下拉刷新相关事件绑定
  133. touchstart : function (e){
  134. if(this.scrollTop > 0){return ;}
  135. this.$refs.refreshcom.touchstart(e);
  136. },
  137. touchmove : function(e){
  138. if(this.scrollTop > 0){return ;}
  139. this.$refs.refreshcom.touchmove(e);
  140. },
  141. touchend : function (e) {
  142. if(this.scrollTop > 0){return ;}
  143. this.$refs.refreshcom.touchend(e);
  144. },
  145. // 刷新事件
  146. reload : function(){
  147. this.page = 1;
  148. this.getData(true);
  149. // 刷新时重置加载组件状态
  150. this.$refs.loadmorecom.stoploadmore();
  151. },
  152. // 加载更多事件
  153. loadmorefun : function(){
  154. // 获取加载组件状态看一下是否还能继续加载
  155. // 保证触底只执行一次加载
  156. if(this.loadMoreTimer != null){clearTimeout(this.loadMoreTimer);}
  157. this.loadMoreTimer = setTimeout(() => {
  158. var status = this.$refs.loadmorecom.loadMoreStatus;
  159. if(status != 0){return null;}
  160. this.$refs.loadmorecom.loading();
  161. // 此处开启加载动画执行加载数据的函数
  162. this.getData(1);
  163. }, 80);
  164. },
  165. // 新闻点击
  166. newstap : function (e) {
  167. // 获取新闻 id
  168. var id = e;
  169. this.Dever.location('index/news_view?id=' + id);
  170. },
  171. // 监听输入
  172. inputting : function(e){
  173. console.log(e);
  174. },
  175. // 监听提交
  176. confirm : function (e) {
  177. console.log(e);
  178. },
  179. // 监听点击
  180. tapme:function(){
  181. uni.showToast({
  182. title:"被点了...."
  183. });
  184. }
  185. }
  186. }
  187. </script>
  188. <style>
  189. .header{padding:15rpx 30rpx; height:100rpx;}
  190. .search-warp{width:750rpx; padding:15rpx 50rpx;}
  191. </style>