index.vue 4.8 KB

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