index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="">
  3. <!-- 顶部导航 -->
  4. <fa-navbar :title="vuex_table_title || '首页'"></fa-navbar>
  5. <!-- 搜索 -->
  6. <view class="u-p-20 u-bg-white u-flex u-col-center" v-if="is_show">
  7. <view class="u-flex-1">
  8. <fa-search :mode="2"></fa-search>
  9. </view>
  10. <view class="u-p-l-15 u-p-r-5 u-flex u-col-center" v-if="is_order">
  11. <fa-orderby-select :filterList="filterList" :orderList="orderList" :multiple="true" @change="goOrderBy"></fa-orderby-select>
  12. </view>
  13. </view>
  14. <!-- 轮播图 -->
  15. <view class="" v-if="is_show">
  16. <u-swiper :title="true" border-radius="0" height="320" :list="bannerList" @click="openPage"></u-swiper>
  17. </view>
  18. <!-- 分类 -->
  19. <view class="u-border-top" v-if="isTab">
  20. <!-- #ifdef MP-BAIDU -->
  21. <fa-u-tabs
  22. :list="tabList"
  23. :active-color="theme.bgColor"
  24. :bar-width="tabwidth"
  25. name="title"
  26. :is-scroll="true"
  27. :current="current"
  28. @change="change"
  29. ></fa-u-tabs>
  30. <!-- #endif -->
  31. <!-- #ifndef MP-BAIDU -->
  32. <u-tabs :list="tabList" :active-color="theme.bgColor" :bar-width="tabwidth" name="title" :is-scroll="true" :current="current" @change="change"></u-tabs>
  33. <!-- #endif -->
  34. </view>
  35. <!-- 列表 -->
  36. <fa-article-item :archives-list="archivesList"></fa-article-item>
  37. <!-- 为空 -->
  38. <view class="u-m-t-60 u-p-t-60" v-if="is_empty">
  39. <u-empty text="暂无内容展示" mode="list"></u-empty>
  40. </view>
  41. <!-- 加载更多 -->
  42. <view class="u-p-30" v-if="archivesList.length"><u-loadmore bg-color="#f4f6f8" :status="status" /></view>
  43. <!-- 回到顶部 -->
  44. <u-back-top :scroll-top="scrollTop" :icon-style="{ color: theme.bgColor }" :custom-style="{ backgroundColor: lightColor }"></u-back-top>
  45. <!-- 底部导航 -->
  46. <fa-tabbar></fa-tabbar>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. computed: {
  52. bannerList() {
  53. if (this.vuex_config.bannerList) {
  54. return this.vuex_config.bannerList;
  55. }
  56. return [];
  57. },
  58. is_order(){
  59. return this.filterList.length >0 || this.orderList.length>0;
  60. }
  61. },
  62. data() {
  63. return {
  64. tabwidth: 40,
  65. current: 0,
  66. status: 'nomore',
  67. page: 1,
  68. channel_id: 0,
  69. filterList:[],
  70. orderList:[],
  71. archivesList: [],
  72. is_show:false,
  73. has_more: false,
  74. scrollTop: 0,
  75. is_update: false,
  76. params: {},
  77. query:{},
  78. isTab: false,
  79. tabList: [],
  80. is_empty:false,
  81. channel:{},
  82. tabList: [],
  83. };
  84. },
  85. onLoad(e) {
  86. let query = this.$Route.query;
  87. if (JSON.stringify(query) == '{}') {
  88. query = e;
  89. }
  90. if(query && JSON.stringify(query) != '{}'){
  91. this.params = query;
  92. }else{
  93. this.params = {
  94. channel:27,
  95. model:1
  96. }
  97. }
  98. this.getCategory();
  99. this.getArchives();
  100. },
  101. onShow() {
  102. // #ifdef MP-BAIDU
  103. if(this.channel){
  104. this.setPagesInfo();
  105. }
  106. // #endif
  107. },
  108. methods: {
  109. change(index) {
  110. //重设Bar宽度
  111. this.tabwidth = this.$util.strlen(this.tabList[index].title) * 30;
  112. this.current = index;
  113. this.channel_id = this.tabList[index].id;
  114. this.is_update = true;
  115. this.page = 1;
  116. this.getArchives();
  117. },
  118. goOrderBy(e){
  119. this.page = 1;
  120. this.is_update = true;
  121. this.query = e;
  122. this.getArchives();
  123. },
  124. getArchives: async function() {
  125. let data = {
  126. page: this.page,
  127. ...this.params,
  128. ...this.query
  129. };
  130. if (this.channel_id) {
  131. data.channel = this.channel_id;
  132. }
  133. let res = await this.$api.getArchives(data);
  134. this.status = 'nomore';
  135. uni.stopPullDownRefresh();
  136. if (!res.code) {
  137. return;
  138. }
  139. let {filterList,orderList,pageList,channel} = res.data;
  140. this.filterList = filterList;
  141. this.orderList = orderList;
  142. this.channel = channel;
  143. // #ifdef MP-BAIDU
  144. if(this.channel){
  145. this.setPagesInfo();
  146. }
  147. // #endif
  148. if (this.is_update) {
  149. this.is_update = false;
  150. this.archivesList = [];
  151. }
  152. this.is_show = true;
  153. this.has_more = pageList.current_page<pageList.last_page;
  154. this.archivesList = [...this.archivesList, ...pageList.data];
  155. this.is_empty = !this.archivesList.length;
  156. },
  157. // #ifdef MP-BAIDU
  158. setPagesInfo() {
  159. swan.setPageInfo({
  160. title:this.channel.seotitle,
  161. keywords: this.channel.keywords,
  162. description:this.channel.description,
  163. releaseDate: this.$u.timeFormat(this.channel.createtime, 'yyyy-mm-dd hh:MM:ss'),
  164. image: this.channel.image,
  165. success: res => {
  166. console.log('setPageInfo success', res);
  167. },
  168. fail: err => {
  169. console.log('setPageInfo fail', err);
  170. }
  171. });
  172. },
  173. // #endif
  174. getCategory() {
  175. this.$api.getCategory({ ...this.params }).then(res => {
  176. if (res.code == 1) {
  177. this.tabList = res.data;
  178. this.isTab = true; //百度小程序要先有值
  179. } else {
  180. this.$u.toast(res.msg);
  181. }
  182. });
  183. },
  184. openPage(index) {
  185. let path = this.bannerList[index].url;
  186. if (path == '/' || !path) {
  187. return;
  188. }
  189. if (path.substr(0, 1) == 'p') {
  190. path = '/' + path;
  191. }
  192. if (path.indexOf('http') != -1) {
  193. this.$u.vuex('vuex_webs', this.bannerList[index]);
  194. this.$u.route('/pages/webview/webview');
  195. return;
  196. }
  197. this.$Router.push({
  198. path: path
  199. });
  200. },
  201. },
  202. onPageScroll(e) {
  203. this.scrollTop = e.scrollTop;
  204. },
  205. //下拉刷新
  206. onPullDownRefresh() {
  207. this.is_update = true;
  208. this.page = 1;
  209. this.getArchives();
  210. },
  211. onReachBottom() {
  212. if (this.has_more) {
  213. this.status = 'loading';
  214. this.page = ++this.page;
  215. this.getArchives();
  216. }
  217. }
  218. };
  219. </script>
  220. <style lang="scss">
  221. page {
  222. background-color: #f4f6f8;
  223. }
  224. </style>