article-category.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view>
  3. <!-- 分类 -->
  4. <scroll-view v-if="(category_list || null) != null && category_list.length > 0" class="nav-base scroll-view-horizontal bg-white oh" scroll-x="true">
  5. <view :class="'item cr-gray dis-inline-block padding-horizontal-main ' + (nav_active_value == 0 ? 'cr-main' : '')" @tap="nav_event" data-value="0">全部</view>
  6. <block v-for="(item, index) in category_list" :key="index">
  7. <view :class="'item cr-gray dis-inline-block padding-horizontal-main ' + (nav_active_value == item.id ? 'cr-main' : '')" @tap="nav_event" :data-value="item.id">{{item.name}}</view>
  8. </block>
  9. </scroll-view>
  10. <!-- 列表 -->
  11. <scroll-view :scroll-y="true" class="scroll-box scroll-box-ece-nav" @scrolltolower="scroll_lower" lower-threshold="60">
  12. <view v-if="(data_list || null) != null && data_list.length > 0" class="data-list padding-horizontal-main padding-top-main oh">
  13. <block v-for="(item, index) in data_list" :key="index">
  14. <view class="item padding-main border-radius-main bg-white oh spacing-mb">
  15. <navigator :url="item.url" hover-class="none">
  16. <view class="cr-base fw-b" :style="(item.title_color || null) != null ? 'color:'+item.title_color+' !important;' : ''">{{item.title}}</view>
  17. <view class="cr-grey oh margin-top-sm">
  18. <text class="fl">{{item.add_time}}</text>
  19. <text class="fr">浏览量 {{item.access_count}}</text>
  20. </view>
  21. </navigator>
  22. </view>
  23. </block>
  24. </view>
  25. <view v-else>
  26. <!-- 提示信息 -->
  27. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  28. </view>
  29. <!-- 结尾 -->
  30. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  31. </scroll-view>
  32. </view>
  33. </template>
  34. <script>
  35. const app = getApp();
  36. import componentNoData from "../../components/no-data/no-data";
  37. import componentBottomLine from "../../components/bottom-line/bottom-line";
  38. export default {
  39. data() {
  40. return {
  41. data_list_loding_status: 1,
  42. data_list_loding_msg: '',
  43. data_bottom_line_status: false,
  44. data_list: [],
  45. data_total: 0,
  46. data_page_total: 0,
  47. data_page: 1,
  48. params: null,
  49. category_list: [],
  50. nav_active_value: 0,
  51. // 自定义分享信息
  52. share_info: {}
  53. };
  54. },
  55. components: {
  56. componentNoData,
  57. componentBottomLine
  58. },
  59. props: {},
  60. onLoad(params) {
  61. this.setData({
  62. params: params,
  63. nav_active_value: params.id || 0
  64. });
  65. // 数据加载
  66. this.get_data();
  67. },
  68. // 下拉刷新
  69. onPullDownRefresh() {
  70. this.setData({
  71. data_page: 1
  72. });
  73. this.get_data_list(1);
  74. },
  75. methods: {
  76. // 初始化
  77. get_data() {
  78. uni.showLoading({
  79. title: '加载中...'
  80. });
  81. uni.request({
  82. url: app.globalData.get_request_url("index", "article"),
  83. method: 'POST',
  84. data: {},
  85. dataType: 'json',
  86. success: res => {
  87. uni.hideLoading();
  88. uni.stopPullDownRefresh();
  89. if (res.data.code == 0) {
  90. var data = res.data.data;
  91. this.setData({
  92. category_list: data.category_list || []
  93. });
  94. // 基础自定义分享
  95. this.setData({
  96. share_info: {
  97. path: '/pages/article-category/article-category',
  98. query: 'id='+this.nav_active_value
  99. }
  100. });
  101. // 获取列表数据
  102. this.get_data_list(1);
  103. } else {
  104. this.setData({
  105. data_list_loding_status: 0,
  106. data_list_loding_msg: res.data.msg
  107. });
  108. app.globalData.showToast(res.data.msg);
  109. }
  110. // 分享菜单处理
  111. app.globalData.page_share_handle(this.share_info);
  112. },
  113. fail: () => {
  114. uni.hideLoading();
  115. uni.stopPullDownRefresh();
  116. this.setData({
  117. data_list_loding_status: 2
  118. });
  119. app.globalData.showToast('服务器请求出错');
  120. }
  121. });
  122. },
  123. // 获取数据列表
  124. get_data_list(is_mandatory) {
  125. // 分页是否还有数据
  126. if ((is_mandatory || 0) == 0) {
  127. if (this.data_bottom_line_status == true) {
  128. uni.stopPullDownRefresh();
  129. return false;
  130. }
  131. }
  132. // 加载loding
  133. uni.showLoading({
  134. title: '加载中...'
  135. });
  136. // 获取数据
  137. uni.request({
  138. url: app.globalData.get_request_url("datalist", "article"),
  139. method: 'POST',
  140. data: {
  141. page: this.data_page,
  142. id: this.nav_active_value || 0
  143. },
  144. dataType: 'json',
  145. success: res => {
  146. uni.hideLoading();
  147. uni.stopPullDownRefresh();
  148. if (res.data.code == 0) {
  149. var data = res.data.data;
  150. if (data.data.length > 0) {
  151. if (this.data_page <= 1) {
  152. var temp_data_list = data.data;
  153. } else {
  154. var temp_data_list = this.data_list || [];
  155. var temp_data = data.data;
  156. for (var i in temp_data) {
  157. temp_data_list.push(temp_data[i]);
  158. }
  159. }
  160. this.setData({
  161. data_list: temp_data_list,
  162. data_total: data.total,
  163. data_page_total: data.page_total,
  164. data_list_loding_status: 3,
  165. data_page: this.data_page + 1
  166. });
  167. // 是否还有数据
  168. this.setData({
  169. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  170. });
  171. } else {
  172. this.setData({
  173. data_list_loding_status: 0
  174. });
  175. if (this.data_page <= 1) {
  176. this.setData({
  177. data_list: [],
  178. data_bottom_line_status: false
  179. });
  180. }
  181. }
  182. } else {
  183. this.setData({
  184. data_list_loding_status: 0,
  185. data_list_loding_msg: res.data.msg
  186. });
  187. app.globalData.showToast(res.data.msg);
  188. }
  189. },
  190. fail: () => {
  191. uni.hideLoading();
  192. uni.stopPullDownRefresh();
  193. this.setData({
  194. data_list_loding_status: 2
  195. });
  196. app.globalData.showToast('服务器请求出错');
  197. }
  198. });
  199. },
  200. // 滚动加载
  201. scroll_lower(e) {
  202. this.get_data_list();
  203. },
  204. // 导航事件
  205. nav_event(e) {
  206. this.setData({
  207. nav_active_value: e.currentTarget.dataset.value || 0,
  208. data_page: 1
  209. });
  210. this.get_data_list(1);
  211. }
  212. }
  213. };
  214. </script>
  215. <style>
  216. </style>