List.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div class="ExhibitionsList">
  3. <div class="conten">
  4. <div class="search">
  5. <div class="left">
  6. <!-- 点击放大镜 -->
  7. <div class="clickSearch" @click="search"></div>
  8. <el-input
  9. style="margin-right: 30px"
  10. suffix-icon="el-icon-search"
  11. v-model="txt"
  12. >
  13. </el-input>
  14. <el-select
  15. v-model="year"
  16. clearable
  17. placeholder="Select Year"
  18. @change="selectChange"
  19. >
  20. <el-option value="2021" label="2021"></el-option>
  21. <el-option value="2020" label="2020"></el-option>
  22. <el-option value="2019" label="2019"></el-option>
  23. <el-option value="2018" label="2018"></el-option>
  24. <el-option value="2017" label="2017"></el-option>
  25. <el-option value="2016" label="2016"></el-option>
  26. <el-option value="2015" label="2015"></el-option>
  27. </el-select>
  28. </div>
  29. <div class="right">
  30. <img
  31. @click="cut = false"
  32. :src="
  33. require(`@/assets/images/Exhibitions/${
  34. cut ? 'cut1' : 'cut1Ac'
  35. }.png`)
  36. "
  37. alt=""
  38. />
  39. <img
  40. @click="cut = true"
  41. :src="
  42. require(`@/assets/images/Exhibitions/${
  43. cut ? 'cut2Ac' : 'cut2'
  44. }.png`)
  45. "
  46. alt=""
  47. />
  48. </div>
  49. </div>
  50. <div class="null" v-if="data.length === 0">no information...</div>
  51. <!-- 列表详情信息 -->
  52. <div class="list" v-if="!cut">
  53. <div class="row" v-for="item in dataShow" :key="item.id" @click="toInfo(item.id)">
  54. <img :src="item.cover" alt="" />
  55. <div class="txt">
  56. <h3>{{ item.h3 }}</h3>
  57. <p>{{ item.p }}</p>
  58. <span>{{ item.yrahTxt }}</span>
  59. </div>
  60. </div>
  61. </div>
  62. <!-- 列表图片信息 -->
  63. <div class="listImg" v-else>
  64. <div class="rowImg" v-for="item in dataShow" :key="item.id" @click="toInfo(item.id)">
  65. <img :src="item.cover" alt="" />
  66. <p>{{ item.h3 }}</p>
  67. </div>
  68. </div>
  69. <!-- 点击显示更多 -->
  70. <div class="more" v-show="data.length>9&&dataShow.length<data.length" @click="dataShowArr(dataShow.length+9)">Show More</div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import { dataAll } from "@/views/dataAll.js";
  76. export default {
  77. name: "ExhibitionsList",
  78. components: {},
  79. data() {
  80. //这里存放数据
  81. return {
  82. txt: "",
  83. year: "",
  84. // 切换图像信息或文章信息---默认详情
  85. cut: false,
  86. topId: null,
  87. data: [],
  88. dataShow: [],
  89. };
  90. },
  91. //监听属性 类似于data概念
  92. computed: {},
  93. //监控data中的数据变化
  94. watch: {
  95. // 监听地址栏参数变化
  96. $route() {
  97. // 改变数据
  98. this.getIdChangeData();
  99. this.dataShowArr(9);
  100. // 把试图变成详情
  101. this.cut = false;
  102. // 清空输入框和下拉框
  103. this.txt = this.year = "";
  104. },
  105. },
  106. //方法集合
  107. methods: {
  108. // 点击单个文章跳转详情
  109. toInfo(id){
  110. let k = this.$route.params.id;
  111. this.$router.push({
  112. name:'ExhibitionsInfo',
  113. query:{id,k}
  114. })
  115. },
  116. // 选择年份
  117. selectChange(val) {
  118. if (!val) {
  119. this.getIdChangeData();
  120. this.dataShowArr(9);
  121. return;
  122. }
  123. this.getIdChangeData();
  124. this.txt = "";
  125. this.data = this.data.filter((v) => {
  126. return v.year.includes(val) || v.year === "";
  127. });
  128. this.dataShowArr(9);
  129. },
  130. // 点击搜索
  131. search() {
  132. if (this.txt.trim() === "" || this.txt.trim().lenght < 3) {
  133. this.getIdChangeData();
  134. this.dataShowArr(9);
  135. return;
  136. }
  137. this.data = this.data.filter((v) => {
  138. return v.h3.includes(this.txt) || v.p.includes(this.txt);
  139. });
  140. this.dataShowArr(9);
  141. },
  142. // 封装通过地址栏参数改变数据的方法
  143. getIdChangeData() {
  144. // 拿到路由参数id
  145. let temp = this.$route.params.id;
  146. if (temp === "1") this.data = dataAll.Exhibitions.Current;
  147. else if (temp === "2") this.data = dataAll.Exhibitions.Permanent;
  148. else if (temp === "3") this.data = dataAll.Exhibitions.Past;
  149. else if (temp === "4") this.data = dataAll.Exhibitions.Overseas;
  150. },
  151. // 处理显示在页面的数组初始数据为9
  152. dataShowArr(val) {
  153. let temp = [];
  154. this.data.forEach((v, i) => {
  155. if (i < val) temp.push(v);
  156. });
  157. this.dataShow = temp;
  158. },
  159. },
  160. //生命周期 - 创建完成(可以访问当前this实例)
  161. created() {},
  162. //生命周期 - 挂载完成(可以访问DOM元素)
  163. mounted() {
  164. this.getIdChangeData();
  165. this.dataShowArr(9);
  166. },
  167. beforeCreate() {}, //生命周期 - 创建之前
  168. beforeMount() {}, //生命周期 - 挂载之前
  169. beforeUpdate() {}, //生命周期 - 更新之前
  170. updated() {}, //生命周期 - 更新之后
  171. beforeDestroy() {}, //生命周期 - 销毁之前
  172. destroyed() {}, //生命周期 - 销毁完成
  173. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  174. };
  175. </script>
  176. <style lang='less' scoped>
  177. .ExhibitionsList {
  178. .conten {
  179. width: 1180px;
  180. margin: 0 auto;
  181. .search {
  182. display: flex;
  183. justify-content: space-between;
  184. .left {
  185. position: relative;
  186. display: flex;
  187. width: 820px;
  188. height: 48px;
  189. /deep/.el-input {
  190. height: 48px;
  191. }
  192. /deep/.el-input__inner {
  193. height: 48px;
  194. border-radius: 24px;
  195. }
  196. /deep/.el-input__suffix {
  197. right: 10px;
  198. font-size: 24px;
  199. }
  200. /deep/.el-input__icon {
  201. line-height: 48px;
  202. color: black;
  203. }
  204. .clickSearch {
  205. cursor: pointer;
  206. z-index: 999;
  207. position: absolute;
  208. width: 48px;
  209. height: 48px;
  210. border-radius: 50%;
  211. right: 196px;
  212. top: 0;
  213. }
  214. }
  215. .right {
  216. & > img {
  217. cursor: pointer;
  218. width: 48px;
  219. height: 48px;
  220. }
  221. }
  222. }
  223. .null {
  224. font-size: 30px;
  225. margin-top: 50px;
  226. text-align: center;
  227. }
  228. .list {
  229. margin: 20px 0 40px;
  230. .row {
  231. cursor: pointer;
  232. display: flex;
  233. height: 240px;
  234. background-color: #fff;
  235. & > img {
  236. width: 240px;
  237. height: 240px;
  238. object-fit: cover;
  239. }
  240. .txt {
  241. flex: 1;
  242. border: 1px solid #c7c7c7;
  243. border-left: 0;
  244. padding: 0 25px;
  245. position: relative;
  246. & > h3 {
  247. font-size: 18px;
  248. line-height: 22px;
  249. padding: 16px 0;
  250. margin-bottom: 13px;
  251. font-weight: bold;
  252. }
  253. & > p {
  254. font-size: 14px;
  255. line-height: 20px;
  256. color: #666;
  257. }
  258. & > span {
  259. display: block;
  260. position: absolute;
  261. left: 25px;
  262. bottom: 15px;
  263. font-size: 14px;
  264. line-height: 20px;
  265. font-weight: bold;
  266. }
  267. }
  268. }
  269. }
  270. .listImg {
  271. margin: 20px 0 40px;
  272. display: flex;
  273. flex-wrap: wrap;
  274. .rowImg {
  275. overflow: hidden;
  276. position: relative;
  277. cursor: pointer;
  278. width: 393px;
  279. height: 393px;
  280. & > img {
  281. width: 393px;
  282. height: 393px;
  283. }
  284. & > p {
  285. font-weight: 700;
  286. width: 100%;
  287. font-size: 16px;
  288. line-height: 32px;
  289. color: #fff;
  290. overflow: hidden;
  291. transition: all 0.3s;
  292. position: absolute;
  293. left: 0;
  294. bottom: -300px;
  295. padding: 15px 25px;
  296. background-color: rgba(0, 0, 0, 0.8);
  297. }
  298. &:hover {
  299. & > p {
  300. bottom: 0;
  301. }
  302. }
  303. }
  304. }
  305. .more {
  306. height: 38px;
  307. width: 160px;
  308. margin: 0 auto 60px;
  309. border: 1px solid #000;
  310. font-size: 16px;
  311. line-height: 38px;
  312. text-align: center;
  313. font-weight: bold;
  314. cursor: pointer;
  315. }
  316. }
  317. }
  318. </style>