index-card-news.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <index-card simple title="热门资讯" more-text="查看全部" @more="handleMore">
  3. <div class="bg-white pd20 rd8" style="height: 270px">
  4. <el-tabs v-model="activeName" type="card" @tab-click="handleTabChanged">
  5. <el-tab-pane v-for="type in newsTypes" :key="type" :name="type" :label="type">
  6. <el-row>
  7. <el-col v-for="news in getSafeNews(type)" :key="news.id" :span="8">
  8. <div class="fx-row fx-sta-cen pf f-333 pr40" style="line-height: 35px">
  9. <span class="text-ellipsis new-title pointer" :title="news.title" @click="goNewsWithType(type,news)">
  10. {{ news.title }}</span>
  11. </div>
  12. </el-col>
  13. </el-row>
  14. </el-tab-pane>
  15. </el-tabs>
  16. </div>
  17. </index-card>
  18. </template>
  19. <script>
  20. import IndexCard from '@/views/index/components/index-card'
  21. import loginCheckMixin from '@/views/index/blocks/index-login-interceptor-mixin'
  22. import transferMixin from '@/components/mx-transfer-mixin'
  23. import * as career from '@/api/webApi/career-news'
  24. export default {
  25. mixins: [transferMixin, loginCheckMixin],
  26. name: 'index-card-news',
  27. components: {IndexCard},
  28. data() {
  29. return {
  30. morePath: {name: 'NewsAll'},
  31. newsTypes: [],
  32. activeName: '',
  33. newsCache: {}
  34. }
  35. },
  36. mounted() {
  37. this.getTypes()
  38. },
  39. methods: {
  40. getTypes() {
  41. this.newsTypes = ['中考资讯','家长学校','中考学生辅导','心灵课堂']
  42. this.activeName = this.newsTypes.first()
  43. this.getList(this.activeName)
  44. },
  45. handleTabChanged() {
  46. this.getList(this.activeName)
  47. },
  48. getList(type) {
  49. if (!type) return
  50. if (this.newsCache.hasOwnProperty(type)) return
  51. career.listNoToken({
  52. pageNum: 1,
  53. pageSize: 15,
  54. type: type
  55. }).then(res => {
  56. this.$set(this.newsCache, type, res.rows)
  57. })
  58. },
  59. getSafeNews(type) {
  60. return this.newsCache[type] || []
  61. },
  62. async handleMore() {
  63. await this.loginCheck()
  64. this.transferTo(this.morePath)
  65. },
  66. async goNewsWithType(type, news) {
  67. await this.loginCheck()
  68. this.transferTo(this.morePath, {type, news})
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .new-title:hover {
  75. color: #47C6A2;
  76. }
  77. </style>