提交 6c241513 authored 作者: 龙菲's avatar 龙菲

暂时修改以图搜图页面UI

上级 96e9c6bc
...@@ -275,22 +275,6 @@ export default { ...@@ -275,22 +275,6 @@ export default {
defImg(e) { defImg(e) {
e.target.src = require("@/assets/404_images/no-pic.png"); e.target.src = require("@/assets/404_images/no-pic.png");
}, },
// handleTypeChange(value) {
// this.type = value;
// this.list.current = 1;
// this.loadData();
// },
// handleYearsChange(value) {
// if (value && value instanceof Array) {
// this.years = value[value.length - 1];
// } else {
// this.years = value;
// }
// this.list.current = 1;
// this.loadData();
// this.$refs.years.dropDownVisible = false;
// },
handleKeyWordChange(value) { handleKeyWordChange(value) {
this.keyword = value; this.keyword = value;
this.loadData(); this.loadData();
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
:gap="30" :gap="30"
@click="handleClickImg" @click="handleClickImg"
> >
<div class="img-info" slot-scope="props"> <!-- <div class="img-info" slot-scope="props">
<div class="name">{{ props.value.sourceName }}</div> <div class="name">{{ props.value.sourceName }}</div>
<div class="year">{{ props.value.yearsLabel }}</div> <div class="year">{{ props.value.yearsLabel }}</div>
<div class="deptName">{{ props.value.deptName }}</div> <div class="deptName">{{ props.value.deptName }}</div>
</div> </div> -->
<div slot="waterfall-over" class="load-over">已加载完全部</div> <div slot="waterfall-over" class="load-over">已加载完全部</div>
</vue-waterfall-easy> </vue-waterfall-easy>
<el-empty v-else></el-empty> <el-empty v-else></el-empty>
...@@ -68,10 +68,10 @@ export default { ...@@ -68,10 +68,10 @@ export default {
}, },
// 给父组件调用的 // 给父组件调用的
getWaterfallHeight() { getWaterfallHeight() {
const emptySpace = 300; const emptySpace = 340;
this.waterfallHeight = "100vh"; this.waterfallHeight = "120vh";
this.waterfallHeight = const { offsetHeight } = this.$refs.ImgList;
this.$refs.ImgList.offsetHeight + emptySpace + "px"; this.waterfallHeight = offsetHeight + emptySpace + "px";
}, },
handleClickImg(event, { index, value }) { handleClickImg(event, { index, value }) {
// 阻止a标签跳转 // 阻止a标签跳转
...@@ -98,6 +98,11 @@ $box-shadow: 0 2px 8px rgba(28, 31, 35, 0.03), ...@@ -98,6 +98,11 @@ $box-shadow: 0 2px 8px rgba(28, 31, 35, 0.03),
box-shadow: none; box-shadow: none;
transition: all ease 0.3s; transition: all ease 0.3s;
cursor: pointer; cursor: pointer;
img {
border-radius: 8px;
box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 3px 0px,
rgba(0, 0, 0, 0.06) 0px 1px 2px 0px;
}
&:hover { &:hover {
transform: translateY(-10px); transform: translateY(-10px);
...@@ -105,7 +110,7 @@ $box-shadow: 0 2px 8px rgba(28, 31, 35, 0.03), ...@@ -105,7 +110,7 @@ $box-shadow: 0 2px 8px rgba(28, 31, 35, 0.03),
} }
::v-deep .vue-waterfall-easy-scroll { ::v-deep .vue-waterfall-easy-scroll {
overflow: auto !important; overflow: hidden !important;
} }
.load-over { .load-over {
......
<template>
<div
:class="['app-container', 'search-pic', showResult ? 'show-result' : '']"
>
<div class="banner">
<div class="text" v-if="!showResult">
<div class="title">以图搜图</div>
<div class="subtitle">
以图搜图是一种方便快捷的搜索方式,它可以帮助您在海量的图片信息中快速找到您需要的图片。
<br />
通过上传或直接输入图片,以图搜图可以为您匹配相似的图片,或者根据图片内容找到相关的图片,让您可以更轻松地获取所需图片。
</div>
</div>
<div class="left-pic"></div>
<div class="right-pic"></div>
</div>
<div class="upload-wrapper">
<div class="upload-bar" @click="handleClickUpload">
<div class="left-area" title="点击此处上传图片">
<div class="text">点击此处上传图片</div>
<div class="camera">
<i class="el-icon-picture-outline" title="点击此处上传图片"></i>
</div>
</div>
<div class="right-button">以图搜图</div>
</div>
<el-upload
v-show="false"
ref="uploader"
class="upload-area"
accept=".jpg,.png"
action
:before-upload="handleBeforeUpload"
:show-file-list="false"
:on-success="handleSuccess"
:disabled="loading"
>
<el-button ref="uploadButton" class="upload-button">上传</el-button>
</el-upload>
</div>
<div class="current-pic" v-if="currentImg && showResult">
<div class="img-container">
<img :src="currentImg" alt="" />
</div>
根据您上传的图片,为您推荐相似图片{{ imgList.length }}
</div>
<ImgList v-if="showResult" :imgList="imgList" ref="List" />
</div>
</template>
<script>
import ImgList from "./components/imgList";
import { searchImageByUpload, searchImageByImg } from "@/api/culturalRelic";
export default {
components: {
ImgList,
},
data() {
return {
showResult: false, //是否展示图片结果
currentImg: "", //当前搜索的图片
loading: false, //是否正在上传
imgList: [],
size: 20,
};
},
mounted() {
const { fileId, fileUrl } = this.$route.query;
this.search(fileId, fileUrl);
},
methods: {
async search(fileId, fileUrl) {
if (!fileId || !fileUrl) {
return;
}
const formData = new FormData();
formData.append("size", this.size);
formData.append("fileId", fileId);
this.showResult = false; //先清空之前imgList已有的高度
const res = await searchImageByImg(formData);
if (res.code == 0) {
this.currentImg = fileUrl;
this.imgList = res.data;
this.showResult = true;
this.$nextTick(() => {
this.$refs["List"].getWaterfallHeight();
});
}
},
// 上传前钩子,处理文件类型
async handleBeforeUpload(file) {
let reg = /(?<=\.)[a-z]+$/g;
let fileType = file.name.match(reg) + "";
let typeArr = ["png", "jpg", "jpeg"];
if (!typeArr.includes(fileType)) {
this.$message.warning("上传文件格式错误!");
return;
}
let formData = new FormData();
formData.append("file", file);
formData.append("size", this.size);
const loading = this.$loading({
lock: true,
text: "正在海量的图库中搜索...",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
});
this.showResult = false; //先清空之前imgList已有的高度
const res = await searchImageByUpload(formData);
if (res.code == 0) {
const length = res.data.length;
this.$message.success(`上传成功并获得${length}张相似图片`);
this.imgList = res.data;
this.showResult = true;
loading.close();
this.showCurrentImg(file);
this.clearRouterQuery();
this.$nextTick(() => {
this.$refs["List"].getWaterfallHeight();
});
}
},
clearRouterQuery() {
if (this.$route.query.fileId) {
const query = {};
this.$router.replace({ query });
}
},
showCurrentImg(file) {
const that = this;
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
that.currentImg = this.result; //显示缩略图
};
},
// 上传成功之后的钩子
handleSuccess(res) {
this.loading = false;
},
// 关闭已上传的图片
handleCloseImg() {
this.currentImg = "";
},
// 点击上传
handleClickUpload() {
if (this.loading) {
this.$message.warning("当前有图片正在上传,请稍等~");
return;
}
this.$refs.uploader.$el.querySelector(".upload-button").click();
},
},
};
</script>
<style scoped lang="scss">
$box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
$box-shadow-hover: rgba(0, 0, 0, 0.16) 0px 3px 6px,
rgba(0, 0, 0, 0.23) 0px 3px 6px;
$transition-ease-03s: all ease 0.3s;
.app-container {
width: 100%;
background-image: url("@/assets/imgs/home-new/all-bg.png");
}
.search-pic {
min-height: 70vh !important;
}
.show-result {
.banner {
height: 40px;
.text {
padding: 80px 12%;
}
}
}
.banner {
height: 400px;
width: 100%;
position: relative;
.left-pic {
transition: all ease 0.5s;
position: absolute;
left: -300px;
top: 100px;
height: 400px;
width: 700px;
background-size: contain;
background-image: url("@/assets/imgs/line-draft/6.png");
background-repeat: no-repeat;
z-index: 0;
}
.right-pic {
position: absolute;
right: 0;
bottom: 0;
height: 200px;
width: 300px;
background-size: contain;
background-image: url("@/assets/imgs/line-draft/3.png");
background-repeat: no-repeat;
z-index: 0;
}
.text {
width: 100%;
height: 100%;
z-index: 4;
color: #fff;
padding: 200px 12%;
opacity: 1;
transition: $transition-ease-03s;
color: $deep-blue;
.title {
font-size: 48px;
font-family: "SourceHanSerifCN-Bold";
text-align: center;
margin-bottom: 8px;
}
.subtitle {
text-align: center;
text-indent: 28px;
letter-spacing: 2px;
}
}
}
.upload-wrapper {
display: flex;
justify-content: center;
padding: 0 16%;
position: relative;
margin-bottom: 16px;
font-size: 18px;
.upload-bar {
box-shadow: $box-shadow;
background: #fff;
border-radius: 12px;
width: 100%;
display: flex;
justify-content: space-between;
padding: 10px 20px;
border: 1px solid $deep-blue;
position: relative;
cursor: pointer;
transition: $transition-ease-03s;
&:hover {
box-shadow: $box-shadow-hover;
}
.left-area {
display: flex;
justify-content: space-between;
padding-right: 16px;
width: 80%;
color: #999;
.text {
display: flex;
align-items: center;
}
i {
font-size: 30px;
color: $deep-blue;
}
}
.right-button {
width: 20%;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
background: $deep-blue;
height: 100%;
position: absolute;
right: 0;
top: 0;
border-radius: 0 12px 12px 0;
}
}
}
.current-pic {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 20px 16%;
position: relative;
z-index: 2;
.img-container {
display: flex;
position: relative;
transition: all ease 0.3s;
margin-right: 16px;
width: 130px;
height: 130px;
background-color: #fff;
img {
width: 100%;
height: 100%;
object-fit: contain;
}
}
}
.img-wrapper {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
::v-deep .el-loading-mask {
border-radius: 12px;
}
</style>
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<el-button ref="uploadButton" class="upload-button">上传</el-button> <el-button ref="uploadButton" class="upload-button">上传</el-button>
</el-upload> </el-upload>
</div> </div>
<div class="current-pic" v-if="currentImg"> <div class="current-pic" v-if="currentImg && showResult">
<div class="img-container"> <div class="img-container">
<img :src="currentImg" alt="" /> <img :src="currentImg" alt="" />
</div> </div>
...@@ -73,14 +73,18 @@ export default { ...@@ -73,14 +73,18 @@ export default {
if (!fileId || !fileUrl) { if (!fileId || !fileUrl) {
return; return;
} }
const params = { const formData = new FormData();
size: this.size, formData.append("size", this.size);
fileId, formData.append("fileId", fileId);
}; this.showResult = false; //先清空之前imgList已有的高度
const res = await searchImageByImg(params); const res = await searchImageByImg(formData);
if (res.code == 0) { if (res.code == 0) {
this.currentImg = fileUrl; this.currentImg = fileUrl;
this.imgList = res.data; this.imgList = res.data;
this.showResult = true;
this.$nextTick(() => {
this.$refs["List"].getWaterfallHeight();
});
} }
}, },
// 上传前钩子,处理文件类型 // 上传前钩子,处理文件类型
...@@ -101,6 +105,7 @@ export default { ...@@ -101,6 +105,7 @@ export default {
spinner: "el-icon-loading", spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)", background: "rgba(0, 0, 0, 0.7)",
}); });
this.showResult = false; //先清空之前imgList已有的高度
const res = await searchImageByUpload(formData); const res = await searchImageByUpload(formData);
if (res.code == 0) { if (res.code == 0) {
const length = res.data.length; const length = res.data.length;
...@@ -109,11 +114,20 @@ export default { ...@@ -109,11 +114,20 @@ export default {
this.showResult = true; this.showResult = true;
loading.close(); loading.close();
this.showCurrentImg(file); this.showCurrentImg(file);
this.clearRouterQuery();
this.$nextTick(() => { this.$nextTick(() => {
this.$refs["List"].getWaterfallHeight(); this.$refs["List"].getWaterfallHeight();
}); });
} }
}, },
clearRouterQuery() {
if (this.$route.query.fileId) {
const query = {};
this.$router.replace({ query });
}
},
showCurrentImg(file) { showCurrentImg(file) {
const that = this; const that = this;
var reader = new FileReader(); var reader = new FileReader();
...@@ -155,16 +169,29 @@ $transition-ease-03s: all ease 0.3s; ...@@ -155,16 +169,29 @@ $transition-ease-03s: all ease 0.3s;
} }
.show-result { .show-result {
.banner { .banner {
height: 40px; height: 200px;
.text { .text {
padding: 80px 12%; padding: 80px 12%;
} }
} }
.upload-bar {
transform: translateY(-141px) !important;
.right-button {
border: 1px solid #fff;
}
}
.current-pic,
.img-list {
transform: translateY(-136px);
}
} }
.banner { .banner {
height: 400px; height: 300px;
width: 100%; width: 100%;
position: relative; position: relative;
overflow: hidden;
background-color: $deep-blue;
color: #fff;
.left-pic { .left-pic {
transition: all ease 0.5s; transition: all ease 0.5s;
position: absolute; position: absolute;
...@@ -192,11 +219,10 @@ $transition-ease-03s: all ease 0.3s; ...@@ -192,11 +219,10 @@ $transition-ease-03s: all ease 0.3s;
width: 100%; width: 100%;
height: 100%; height: 100%;
z-index: 4; z-index: 4;
color: #fff; padding: 80px 12% 120px;
padding: 200px 12%;
opacity: 1; opacity: 1;
transition: $transition-ease-03s; transition: $transition-ease-03s;
color: $deep-blue; color: #fff;
.title { .title {
font-size: 48px; font-size: 48px;
font-family: "SourceHanSerifCN-Bold"; font-family: "SourceHanSerifCN-Bold";
...@@ -217,6 +243,7 @@ $transition-ease-03s: all ease 0.3s; ...@@ -217,6 +243,7 @@ $transition-ease-03s: all ease 0.3s;
position: relative; position: relative;
margin-bottom: 16px; margin-bottom: 16px;
font-size: 18px; font-size: 18px;
.upload-bar { .upload-bar {
box-shadow: $box-shadow; box-shadow: $box-shadow;
background: #fff; background: #fff;
...@@ -229,6 +256,7 @@ $transition-ease-03s: all ease 0.3s; ...@@ -229,6 +256,7 @@ $transition-ease-03s: all ease 0.3s;
position: relative; position: relative;
cursor: pointer; cursor: pointer;
transition: $transition-ease-03s; transition: $transition-ease-03s;
transform: translateY(-34px);
&:hover { &:hover {
box-shadow: $box-shadow-hover; box-shadow: $box-shadow-hover;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论