|
@@ -1,43 +1,181 @@
|
|
<template>
|
|
<template>
|
|
-<div class='SearchCollections'>SearchCollections</div>
|
|
|
|
|
|
+ <div class="null" v-if="data.length === 0">no information...</div>
|
|
|
|
+ <div class="SearchCollections" v-else>
|
|
|
|
+ <div
|
|
|
|
+ class="row"
|
|
|
|
+ v-for="(item, index) in data[pageSize - 1]"
|
|
|
|
+ :key="index"
|
|
|
|
+ @click="lookBig(item)"
|
|
|
|
+ >
|
|
|
|
+ <div class="left">
|
|
|
|
+ <img :src="item.cover" alt="" />
|
|
|
|
+ </div>
|
|
|
|
+ <div class="right">
|
|
|
|
+ <h3 v-html="item.h3"></h3>
|
|
|
|
+ <p v-html="item.p"></p>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <!-- 分页 -->
|
|
|
|
+ <div class="page">
|
|
|
|
+ <span
|
|
|
|
+ :class="{ active: pageSize === i }"
|
|
|
|
+ v-for="i in data.length"
|
|
|
|
+ :key="i"
|
|
|
|
+ @click="pageChange(i)"
|
|
|
|
+ >{{ i }}</span
|
|
|
|
+ >
|
|
|
|
+ </div>
|
|
|
|
+ <!-- 查看详情组件 -->
|
|
|
|
+ <CollectionsInfo v-if="isShow" :isShow.sync="isShow" :infoObj="infoObj" />
|
|
|
|
+ </div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
+import CollectionsInfo from "../Collections/component/info.vue";
|
|
|
|
+import { Collections } from "./data";
|
|
export default {
|
|
export default {
|
|
-name:'SearchCollections',
|
|
|
|
-components: {},
|
|
|
|
-data() {
|
|
|
|
-//这里存放数据
|
|
|
|
-return {
|
|
|
|
|
|
+ name: "SearchCollections",
|
|
|
|
+ props: {
|
|
|
|
+ txt: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: "",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ components: { CollectionsInfo },
|
|
|
|
+ data() {
|
|
|
|
+ //这里存放数据
|
|
|
|
+ return {
|
|
|
|
+ data: [],
|
|
|
|
+ pageSize: 1,
|
|
|
|
+ // 点击单个查看文物
|
|
|
|
+ isShow: false,
|
|
|
|
+ infoObj: {},
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ //监听属性 类似于data概念
|
|
|
|
+ computed: {},
|
|
|
|
+ //监控data中的数据变化
|
|
|
|
+ watch: {},
|
|
|
|
+ //方法集合
|
|
|
|
+ methods: {
|
|
|
|
+ // 切换分页
|
|
|
|
+ pageChange(val) {
|
|
|
|
+ this.pageSize = val;
|
|
|
|
+ window.scrollTo({ top: 0, behavior: "smooth" });
|
|
|
|
+ },
|
|
|
|
+ // 点击跳转,新窗口打开
|
|
|
|
+ lookBig(item) {
|
|
|
|
+ this.infoObj = item;
|
|
|
|
+ this.isShow = true;
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ // 获取body,防止滚动
|
|
|
|
+ let body = document.querySelector("body");
|
|
|
|
+ body.style.overflow = "hidden";
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ // 封装一个获取数据的方法
|
|
|
|
+ getData(txt) {
|
|
|
|
+ this.pageSize = 1;
|
|
|
|
+ let temp = [];
|
|
|
|
+ if (txt.trim() === "" || txt.trim().length < 4) {
|
|
|
|
+ temp = [...Collections];
|
|
|
|
+ } else {
|
|
|
|
+ temp = Collections.filter((v) => {
|
|
|
|
+ return v.h3.includes(txt) || v.p.includes(txt);
|
|
|
|
+ });
|
|
|
|
+ //
|
|
|
|
+ temp = temp.map((v) => {
|
|
|
|
+ return {
|
|
|
|
+ ...v,
|
|
|
|
+ h3: v.h3.replaceAll(txt, `<span style='color:red;'>${txt}</span>`),
|
|
|
|
+ p: v.p.replaceAll(txt, `<span style='color:red;'>${txt}</span>`),
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ // 把结果长度给父亲显示
|
|
|
|
+ this.$emit("update:num", temp.length);
|
|
|
|
|
|
|
|
+ // 手动处理格式分页
|
|
|
|
+ let pageNum = Math.ceil(temp.length / 10);
|
|
|
|
+ let tempArrAll = [];
|
|
|
|
+ for (let i = 0; i < pageNum; i++) {
|
|
|
|
+ tempArrAll.push(temp.slice(i * 10, (i + 1) * 10));
|
|
|
|
+ }
|
|
|
|
+ this.data = tempArrAll;
|
|
|
|
+ },
|
|
|
|
+ searchBtn(txt) {
|
|
|
|
+ this.getData(txt);
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ //生命周期 - 创建完成(可以访问当前this实例)
|
|
|
|
+ created() {
|
|
|
|
+ this.getData(this.txt);
|
|
|
|
+ },
|
|
|
|
+ //生命周期 - 挂载完成(可以访问DOM元素)
|
|
|
|
+ mounted() {},
|
|
|
|
+ beforeCreate() {}, //生命周期 - 创建之前
|
|
|
|
+ beforeMount() {}, //生命周期 - 挂载之前
|
|
|
|
+ beforeUpdate() {}, //生命周期 - 更新之前
|
|
|
|
+ updated() {}, //生命周期 - 更新之后
|
|
|
|
+ beforeDestroy() {}, //生命周期 - 销毁之前
|
|
|
|
+ destroyed() {}, //生命周期 - 销毁完成
|
|
|
|
+ activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
|
|
};
|
|
};
|
|
-},
|
|
|
|
-//监听属性 类似于data概念
|
|
|
|
-computed: {},
|
|
|
|
-//监控data中的数据变化
|
|
|
|
-watch: {},
|
|
|
|
-//方法集合
|
|
|
|
-methods: {
|
|
|
|
-
|
|
|
|
-},
|
|
|
|
-//生命周期 - 创建完成(可以访问当前this实例)
|
|
|
|
-created() {
|
|
|
|
-
|
|
|
|
-},
|
|
|
|
-//生命周期 - 挂载完成(可以访问DOM元素)
|
|
|
|
-mounted() {
|
|
|
|
-
|
|
|
|
-},
|
|
|
|
-beforeCreate() {}, //生命周期 - 创建之前
|
|
|
|
-beforeMount() {}, //生命周期 - 挂载之前
|
|
|
|
-beforeUpdate() {}, //生命周期 - 更新之前
|
|
|
|
-updated() {}, //生命周期 - 更新之后
|
|
|
|
-beforeDestroy() {}, //生命周期 - 销毁之前
|
|
|
|
-destroyed() {}, //生命周期 - 销毁完成
|
|
|
|
-activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
|
|
|
|
-}
|
|
|
|
</script>
|
|
</script>
|
|
<style lang='less' scoped>
|
|
<style lang='less' scoped>
|
|
-//@import url(); 引入公共css类
|
|
|
|
-
|
|
|
|
|
|
+.null {
|
|
|
|
+ font-size: 30px;
|
|
|
|
+ margin-top: 50px;
|
|
|
|
+ text-align: center;
|
|
|
|
+}
|
|
|
|
+.SearchCollections {
|
|
|
|
+ padding-bottom: 20px;
|
|
|
|
+ .row {
|
|
|
|
+ cursor: pointer;
|
|
|
|
+ background-color: #fff;
|
|
|
|
+ border: 1px solid #c8c8c8;
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
+ padding: 20px;
|
|
|
|
+ zoom: 1;
|
|
|
|
+ overflow: hidden;
|
|
|
|
+ display: flex;
|
|
|
|
+ .left {
|
|
|
|
+ width: 180px;
|
|
|
|
+ text-align: center;
|
|
|
|
+ & > img {
|
|
|
|
+ width: 150px;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ .right {
|
|
|
|
+ flex: 1;
|
|
|
|
+ & > h3 {
|
|
|
|
+ font-weight: 700;
|
|
|
|
+ font-size: 14px;
|
|
|
|
+ line-height: 30px;
|
|
|
|
+ }
|
|
|
|
+ & > p {
|
|
|
|
+ font-size: 14px;
|
|
|
|
+ color: #a6a6a6;
|
|
|
|
+ line-height: 24px;
|
|
|
|
+ }
|
|
|
|
+ /deep/.smImg {
|
|
|
|
+ width: 41px;
|
|
|
|
+ height: 32px;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ .page {
|
|
|
|
+ display: flex;
|
|
|
|
+ justify-content: center;
|
|
|
|
+ padding-bottom: 30px;
|
|
|
|
+ & > span {
|
|
|
|
+ margin-right: 8px;
|
|
|
|
+ cursor: pointer;
|
|
|
|
+ }
|
|
|
|
+ .active {
|
|
|
|
+ color: #bf2323;
|
|
|
|
+ pointer-events: none;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
</style>
|
|
</style>
|