list.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="list">
  3. <breadcrumb ref="breadcrumb"></breadcrumb>
  4. <div class="listHome">
  5. <div class="listBoxLeft">
  6. <letnav ref="letnav" :menuTree="menu"></letnav>
  7. </div>
  8. <div class="box" v-if="!isnew">
  9. <div class="listBoxRight" v-if="listTotal > 0">
  10. <el-card class="listBox" v-for="(item, index) in contentList" :key="index">
  11. <el-image v-if="item && item.thumbnail" :src="item.thumbnail" class="listimg" @click="newClick(item)"></el-image>
  12. <el-image v-else :src="thumbnail" class="listimg" @click="newClick(item)"></el-image>
  13. <div class="text">
  14. <div class="title" @click="newClick(item)">{{ item.title }}</div>
  15. <span class="describe">{{ item.describe }}</span>
  16. <span class="date">{{ item.date | dates }}</span>
  17. </div>
  18. </el-card>
  19. <pagination ref="pagination" class="pagination" :total="listTotal" @query="filterQuery"></pagination>
  20. </div>
  21. <el-divider class="divider" v-else>暂无数据</el-divider>
  22. </div>
  23. <div class="isnewbox" v-if="isnew">
  24. <div class="titlebox" v-for="(item, index) in isnewcontentList" :key="index">
  25. <div class="left" v-for="i in item" :key="i._id">
  26. <img src="../assets/jt.png" class="jt">
  27. <span class="text" @click="newClick(i)">{{ i.title }}</span>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import _ from 'lodash';
  36. import moment from 'moment';
  37. import letnav from '../components/leftmenu/index.vue';
  38. import pagination from '../components/pagination';
  39. import breadcrumb from '../components/breadcrumb/index.vue';
  40. import { mapState, mapActions } from 'vuex';
  41. export default {
  42. name: 'listHome',
  43. components: {
  44. pagination,
  45. letnav,
  46. breadcrumb
  47. },
  48. computed: {
  49. ...mapState(['contentList', 'listTotal', 'menusall']),
  50. isnewcontentList() {
  51. return _.chunk(this.contentList, 2);
  52. }
  53. },
  54. data() {
  55. return {
  56. code: null,
  57. pageSize: 10,
  58. parentCode: null,
  59. menu: {},
  60. thumbnail: require('../assets/newimg.jpg'),
  61. isnew: false
  62. };
  63. },
  64. async mounted() {
  65. // 所有菜单
  66. await this.menusQueryAll();
  67. // 当前菜单参数
  68. this.code = this.$route.params.code;
  69. // 顶级菜单参数
  70. this.parentCode = this.$route.query.parentCode;
  71. const topahes = await this.topage();
  72. if (topahes) {
  73. // 获取一例菜单
  74. this.menu = this.$setChildrenSession({ menus: this.menusall, iscode: this.parentCode });
  75. // 控制左侧菜单当前选项
  76. this.$refs.letnav.setIndex();
  77. if (this.code == '033' || this.code == '0441' || this.code == '0442' || this.code == '0443') {
  78. this.isnew = true;
  79. await this.filterQuery({ filter: {}, paging: { page: 0, size: 100 } });
  80. return;
  81. }
  82. await this.filterQuery();
  83. }
  84. },
  85. methods: {
  86. ...mapActions(['contentsList', 'menusQueryAll']),
  87. // 查询函数
  88. async filterQuery ({ filter = {}, paging = { page: 0, size: 10 } } = {}) {
  89. filter.bind = this.code;
  90. if (this.code.length == 2 && this.menu.children) filter.parentCode = this.code;
  91. await this.contentsList({ filter, paging });
  92. },
  93. // 列表点击
  94. newClick(e) {
  95. // 获取最后一级菜单
  96. const item = this.$last({ menus: this.menusall, code: this.code });
  97. // 缓存写入当前一例菜单
  98. this.$setParentsetSession({ menus: this.menusall, iscode: item });
  99. this.menu = this.$setChildrenSession({ menus: this.menusall, iscode: this.parentCode });
  100. this.$router.push(`/details/${e._id}`);
  101. },
  102. topage() {
  103. const item = this.menusall.find(e => e.code == this.code);
  104. if (item?.type == '2') {
  105. this.$router.push(`/pages/${item.code}?parentCode=${this.parentCode}`);
  106. return false;
  107. }
  108. return true;
  109. }
  110. },
  111. filters: {
  112. dates(e) {
  113. return moment(e).format('YYYY-MM-DD');
  114. }
  115. }
  116. };
  117. </script>
  118. <style lang="scss" scoped>
  119. .divider {
  120. width: 70%;
  121. margin: 5% auto;
  122. }
  123. .list {
  124. width: 60%;
  125. margin: 0 auto;
  126. margin-bottom: 5%;
  127. .listHome {
  128. width: 100%;
  129. display: flex;
  130. .listBoxLeft {
  131. width: 20%;
  132. margin-top: 3%;
  133. margin-right: 5%;
  134. }
  135. .box, .isnewbox {
  136. width: 75%;
  137. margin-top: 3%;
  138. }
  139. .listBoxRight {
  140. width: 100%;
  141. .listBox {
  142. width: 100%;
  143. margin: 0 auto;
  144. margin-bottom: 3%;
  145. ::v-deep .el-card__body {
  146. display: flex;
  147. .listimg {
  148. display: block;
  149. width: 15%;
  150. height: 5%;
  151. cursor: pointer;
  152. }
  153. .text {
  154. width: 70%;
  155. margin-left: 5%;
  156. .title {
  157. cursor: pointer;
  158. width: 100%;
  159. overflow: hidden;
  160. text-overflow: ellipsis;
  161. white-space: nowrap;
  162. font-size: 16px;
  163. line-height: 35px;
  164. font-weight: 600;
  165. }
  166. .describe {
  167. width: 100%;
  168. overflow: hidden;
  169. text-overflow: ellipsis;
  170. display: -webkit-box;
  171. -webkit-line-clamp: 2;
  172. -webkit-box-orient: vertical;
  173. color: #999;
  174. font-size: 12px;
  175. }
  176. .date {
  177. width: 100%;
  178. color: #999;
  179. line-height: 3em;
  180. }
  181. }
  182. }
  183. }
  184. }
  185. }
  186. .pagination {
  187. margin-bottom: 5%;
  188. }
  189. }
  190. </style>
  191. <style lang="scss" scoped>
  192. .titlebox {
  193. display: flex;
  194. width: 100%;
  195. border-bottom: 1px dashed #999;
  196. flex-wrap: wrap;
  197. .left {
  198. width: 50%;
  199. line-height: 38px;
  200. .text {
  201. margin-left: 5px;
  202. }
  203. }
  204. .left span:hover {
  205. color: #018dff ;
  206. cursor: pointer;
  207. }
  208. }
  209. </style>