community.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view>
  3. <view class="nav">
  4. <scroll-view scroll-x="true" class="navs">
  5. <view :class="'li' + (currentTab == index ? ' active' : '')" v-for="(item,index) in cateList" :key="index" @click="tabClick(item.id,index)">{{item.name}}</view>
  6. </scroll-view>
  7. </view>
  8. <view style="height: 80rpx;"></view>
  9. <view class="list" v-if="contentList && contentList.length > 0">
  10. <navigator :url="'/topic/content/content?id=' + item.id" hover-class="none" class="li ddflex" v-for="(item,index) in contentList" :key="index">
  11. <view class="fflex">
  12. <view class="title tovers">{{item.title}}</view>
  13. <view class="sta">
  14. <text v-if="item.authorName">{{item.authorName}}</text>
  15. <text>{{item.browse}}人浏览</text>
  16. </view>
  17. </view>
  18. <image :src="item.pic" mode="aspectFill"></image>
  19. </navigator>
  20. </view>
  21. <view class="nodata" v-else>
  22. <image :src="picUrlss + 'empty_dd.png'"></image>
  23. <text>暂无记录~</text>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. const app = getApp();
  29. const req = require('../../utils/request.js');
  30. const util = require('../../utils/util.js');
  31. export default {
  32. data() {
  33. return {
  34. picUrlss: req.public.picUrls,
  35. currentTab: 0,
  36. cateList: [],
  37. cid: '',
  38. form: {
  39. page: 1,
  40. limit: 10
  41. },
  42. contentList: [],
  43. isLoad: true
  44. };
  45. },
  46. onLoad() {
  47. this.getCateList();
  48. },
  49. onReachBottom() {
  50. this.form.page++;
  51. this.getContentList(this.cid);
  52. },
  53. methods: {
  54. tabClick(id,index){
  55. if(this.currentTab == index) return false;
  56. this.currentTab = index;
  57. this.cid = id;
  58. this.form.page = 1;
  59. this.isLoad = true;
  60. this.getContentList(id);
  61. },
  62. getCateList() {
  63. req.getRequest('/api/v2/category/list',{},res => {
  64. this.cateList = res;
  65. this.isShowUI = true;
  66. this.cid = res[0].id;
  67. this.getContentList(res[0].id);
  68. },false);
  69. },
  70. //文章列表
  71. getContentList(id) {
  72. if(!this.isLoad) return false;
  73. this.isLoad = false;
  74. let form = this.form;
  75. form.cid = id;
  76. if(this.form.page == 1){
  77. uni.showLoading();
  78. }
  79. req.getRequest('/api/content/list', form, res => {
  80. if(res && res.length == this.form.limit) this.isLoad = true;
  81. if(this.form.page > 1) res = this.contentList.concat(res);
  82. this.contentList = res;
  83. uni.hideLoading();
  84. req.removeStorage('category');
  85. });
  86. },
  87. }
  88. };
  89. </script>
  90. <style>
  91. @import "./community.css";
  92. </style>