index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="style">
  5. <el-col :span="24" class="top">
  6. <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
  7. </el-col>
  8. <el-col :span="24" class="down">
  9. <el-col :span="24" class="search">
  10. <el-col :span="6" class="type">
  11. <el-select v-model="type" placeholder="请选择" clearable @change="typeChange">
  12. <el-option v-for="(item, index) in column" :key="index" :label="item.title" :value="item.id"> </el-option>
  13. </el-select>
  14. </el-col>
  15. <el-col :span="18" class="input">
  16. <van-search v-model="name" @search="onSearch" placeholder="请输入信息标题" />
  17. </el-col>
  18. </el-col>
  19. <el-col :span="24" class="data">
  20. <van-tabs v-model="active">
  21. <van-tab title="科技资讯">
  22. <kjzxList :list="kjzxLists" @detailBtn="detailBtn"></kjzxList>
  23. </van-tab>
  24. <van-tab title="工作动态">
  25. <kjzxList :list="gzdtLists" @detailBtn="detailBtn"></kjzxList>
  26. </van-tab>
  27. <van-tab title="通知通告">
  28. <kjzxList :list="tztgLists" @detailBtn="detailBtn"></kjzxList>
  29. </van-tab>
  30. <van-tab title="技术前沿">
  31. <kjzxList :list="jsqyLists" @detailBtn="detailBtn"></kjzxList>
  32. </van-tab>
  33. </van-tabs>
  34. </el-col>
  35. </el-col>
  36. </el-col>
  37. </el-row>
  38. </div>
  39. </template>
  40. <script>
  41. import { mapState, createNamespacedHelpers } from 'vuex';
  42. const { mapActions: journcolumn } = createNamespacedHelpers('journcolumn');
  43. const { mapActions: journnews } = createNamespacedHelpers('journnews');
  44. import NavBar from '@/layout/common/topInfo.vue';
  45. import footInfo from '@/layout/common/footInfo.vue';
  46. import kjzxList from './parts/kjzxList.vue';
  47. export default {
  48. metaInfo() {
  49. return { title: this.$route.meta.title };
  50. },
  51. name: 'index',
  52. props: {},
  53. components: {
  54. NavBar,
  55. // footInfo,
  56. kjzxList,
  57. },
  58. data: function() {
  59. return {
  60. // 头部标题
  61. title: '',
  62. // meta为true
  63. isleftarrow: '',
  64. // 返回
  65. navShow: true,
  66. //菜单显示
  67. active: 0,
  68. //科技资讯
  69. kjzxLists: [],
  70. //科技动态
  71. gzdtLists: [],
  72. //通知通告
  73. tztgLists: [],
  74. //技术前沿
  75. jsqyLists: [],
  76. //栏目
  77. column: [],
  78. // 类型
  79. name: '',
  80. type: '',
  81. };
  82. },
  83. async created() {
  84. await this.searchColumn();
  85. await this.searchList();
  86. },
  87. methods: {
  88. ...journcolumn({ columnquery: 'query' }),
  89. ...journnews({ newsquery: 'query' }),
  90. async searchColumn() {
  91. const res = await this.columnquery();
  92. if (this.$checkRes(res)) {
  93. console.log(_.orderBy(res.data, ['meta.createdAt'], ['asc']));
  94. this.$set(this, `column`, _.orderBy(res.data, ['meta.createdAt'], ['asc']));
  95. }
  96. },
  97. async searchList() {
  98. let col = this.column.find(i => i.site == 'kjzx');
  99. if (col) {
  100. const res = await this.newsquery({ column_id: col.id });
  101. if (this.$checkRes(res)) {
  102. this.$set(this, `kjzxLists`, _.orderBy(res.data, ['publish_time'], ['desc']));
  103. }
  104. }
  105. let col2 = this.column.find(i => i.site == 'gzdt');
  106. if (col2) {
  107. const res = await this.newsquery({ column_id: col2.id });
  108. if (this.$checkRes(res)) {
  109. this.$set(this, `gzdtLists`, _.orderBy(res.data, ['publish_time'], ['desc']));
  110. }
  111. }
  112. let col3 = this.column.find(i => i.site == 'tztg');
  113. if (col3) {
  114. const res = await this.newsquery({ column_id: col3.id });
  115. if (this.$checkRes(res)) {
  116. this.$set(this, `tztgLists`, _.orderBy(res.data, ['publish_time'], ['desc']));
  117. }
  118. }
  119. let col4 = this.column.find(i => i.site == 'jsqy');
  120. if (col4) {
  121. const res = await this.newsquery({ column_id: col4.id });
  122. if (this.$checkRes(res)) {
  123. this.$set(this, `jsqyLists`, _.orderBy(res.data, ['publish_time'], ['desc']));
  124. }
  125. }
  126. },
  127. async search({ ...info } = {}) {
  128. info.column_id = this.type;
  129. if (this.name) {
  130. info.title = this.name;
  131. const res = await this.newsquery({ ...info });
  132. if (this.$checkRes(res)) {
  133. let col = this.column.find(i => i.id == this.type);
  134. if (col.site == 'kjzx') this.$set(this, `kjzxLists`, _.orderBy(res.data, ['publish_time'], ['desc']));
  135. else if (col.site == 'gzdt') this.$set(this, `gzdtLists`, _.orderBy(res.data, ['publish_time'], ['desc']));
  136. else if (col.site == 'tztg') this.$set(this, `tztgLists`, _.orderBy(res.data, ['publish_time'], ['desc']));
  137. else if (col.site == 'jsqy') this.$set(this, `jsqyLists`, _.orderBy(res.data, ['publish_time'], ['desc']));
  138. }
  139. } else {
  140. this.searchList();
  141. }
  142. },
  143. // 选择类型
  144. typeChange(value) {
  145. if (value) {
  146. this.active = '';
  147. this.$set(this, `type`, value);
  148. let index = this.column.findIndex(i => i.id == value);
  149. if (index) {
  150. this.$set(this, `active`, index);
  151. }
  152. }
  153. },
  154. // 输入框查询
  155. onSearch(data) {
  156. this.$set(this, `name`, data);
  157. if (this.type) {
  158. this.search();
  159. } else {
  160. this.$notify({
  161. message: '请选择信息类型',
  162. type: 'danger',
  163. });
  164. }
  165. },
  166. detailBtn(data) {
  167. this.$router.push({ path: '/journ/detail', query: { id: data.id } });
  168. },
  169. },
  170. computed: {
  171. ...mapState(['user']),
  172. },
  173. mounted() {
  174. this.title = this.$route.meta.title;
  175. this.isleftarrow = this.$route.meta.isleftarrow;
  176. },
  177. metaInfo() {
  178. return { title: this.$route.meta.title };
  179. },
  180. };
  181. </script>
  182. <style lang="less" scoped>
  183. .style {
  184. width: 100%;
  185. height: 100%;
  186. position: relative;
  187. background-color: #f9fafc;
  188. .down {
  189. position: relative;
  190. .search {
  191. position: fixed;
  192. width: 100%;
  193. z-index: 999;
  194. border-bottom: 1px solid #ccc;
  195. background-color: #fff;
  196. .type {
  197. /deep/.el-input__inner {
  198. border: none;
  199. padding: 0;
  200. height: 30px;
  201. line-height: 30px;
  202. }
  203. .el-select {
  204. padding: 10px 0px 0px 5px;
  205. }
  206. /deep/.el-input__icon {
  207. line-height: 30px;
  208. }
  209. }
  210. .input {
  211. .van-search {
  212. padding: 10px 12px 10px 0;
  213. }
  214. }
  215. }
  216. .data {
  217. position: absolute;
  218. width: 100%;
  219. top: 54px;
  220. background: #f9fafc;
  221. }
  222. }
  223. }
  224. .top {
  225. height: 46px;
  226. overflow: hidden;
  227. }
  228. .foot {
  229. position: absolute;
  230. bottom: 0;
  231. }
  232. /deep/.van-tabs__line {
  233. width: 60px;
  234. }
  235. </style>