threeList.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="lists" :style="{ backgroundColor: isImg ? '#f4f4f4' : '', border: isImg ? '1px solid #dfdfdf' : 'none' }">
  3. <el-image class="titleImg" :src="imgUrl" v-if="isImg"></el-image>
  4. <div class="title" v-else>
  5. <el-image class="titleImg" :src="imgUrl"></el-image>
  6. <h2 class="titleText">{{ title }}</h2>
  7. <div class="more" @click="moreClick">
  8. <span class="el-icon-plus plus"></span>
  9. 更多
  10. </div>
  11. </div>
  12. <div class="isList" v-for="(i, index) in data" :key="index" @click="itemClick(i)">
  13. <el-image class="isList-img" :src="icon"></el-image>
  14. <h4 class="isList-title">{{ i.title }}</h4>
  15. <span class="isList-date">{{ i.date | dates }}</span>
  16. </div>
  17. <div class="more more2" @click="moreClick" v-if="isImg">
  18. <span class="el-icon-plus plus"></span>
  19. 更多
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import moment from 'moment';
  25. import { mapState } from 'vuex';
  26. export default {
  27. props: {
  28. // 标题
  29. title: { type: String, default: '通知公告' },
  30. // 标题图片
  31. imgUrl: { type: String, default: '' },
  32. // 内容数据
  33. data: { type: Array, default: () => [] },
  34. isImg: { type: Boolean, default: true },
  35. code: { type: String, default: '' },
  36. parentCode: { type: String, default: null }
  37. },
  38. components: {},
  39. computed: {
  40. ...mapState(['menusall'])
  41. },
  42. data() {
  43. return {
  44. icon: require('../../assets/jt.png')
  45. };
  46. },
  47. mounted() {},
  48. methods: {
  49. itemClick(e) {
  50. this.$router.push(`/details/${e._id}`);
  51. },
  52. async moreClick() {
  53. // 获取最后一级菜单
  54. const item = this.$last({ menus: this.menusall, code: this.code });
  55. // 缓存写入当前一例菜单
  56. this.$setParentsetSession({ menus: this.menusall, iscode: item });
  57. if (this.parentCode !== null) this.$router.push(`/list/${this.code}?parentCode=${this.parentCode}`);
  58. if (this.parentCode == null) this.$router.push(`/list/${this.code}`);
  59. },
  60. // 递归第一级最后的菜单编码
  61. async setactiveIndex (code) {
  62. const isCode = this.menusall.filter(j => j.code == code);
  63. const children = this.menusall.filter(k => k.parentCode == isCode[0]?.code);
  64. if (children.length > 0) return this.setactiveIndex(children[0]?.code);
  65. return isCode[0];
  66. }
  67. },
  68. filters: {
  69. dates(e) {
  70. return moment(e).format('MM-DD');
  71. }
  72. }
  73. };
  74. </script>
  75. <style lang="scss" scoped>
  76. .lists {
  77. // margin-left: 5%;
  78. width: 30%;
  79. .titleImg {
  80. display: block;
  81. width: 100%;
  82. height: 20%;
  83. }
  84. .title {
  85. display: flex;
  86. // margin: 15px 0;
  87. .titleImg {
  88. width: 8%;
  89. height: 5%;
  90. margin-top: 1%;
  91. }
  92. .titleText {
  93. margin: 0 15px;
  94. color: #007ce2;
  95. width: 78%;
  96. }
  97. }
  98. .more {
  99. width: 35%;
  100. text-align: right;
  101. color: #999;
  102. cursor: pointer;
  103. margin-right: 3%;
  104. .plus {
  105. width: 15px;
  106. height: 15px;
  107. border-radius: 50%;
  108. text-align: center;
  109. background: #999;
  110. color: #fff;
  111. }
  112. }
  113. .more2 {
  114. width: 18%;
  115. margin-bottom: 2%;
  116. }
  117. .isList {
  118. width: 90%;
  119. display: flex;
  120. margin: 10px auto;
  121. border-bottom: 1px dashed #999;
  122. .isList-img {
  123. width: 10px;
  124. height: 10px;
  125. display: block;
  126. margin-top: 6%;
  127. }
  128. .isList-title {
  129. width: 80%;
  130. overflow: hidden;
  131. text-overflow: ellipsis;
  132. white-space: nowrap;
  133. margin: 0;
  134. margin-right: 5%;
  135. margin-left: 3%;
  136. cursor: pointer;
  137. line-height: 3em;
  138. font-size: 1.2em;
  139. }
  140. .isList-date {
  141. font-size: 1em;
  142. color: #999;
  143. line-height: 3.5em;
  144. text-align: right;
  145. width: 20%;
  146. }
  147. }
  148. }
  149. </style>