Pre Merge pull request !173 from lingdeng/dev

This commit is contained in:
lingdeng 2022-05-07 07:21:55 +00:00 committed by Gitee
commit e5db944c30
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -1,25 +1,47 @@
<template> <template>
<div class="component-upload-image"> <div class="component-upload-image">
<el-upload <vuedraggable
multiple v-model="fileList"
:action="uploadImgUrl" class="vue-draggable"
list-type="picture-card" draggable=".draggable-item"
:on-success="handleUploadSuccess" tag="ul"
:before-upload="handleBeforeUpload" @end="onDragEnd"
:limit="limit" @start="onDragStart"
:on-error="handleUploadError"
:on-exceed="handleExceed"
name="file"
:on-remove="handleRemove"
:show-file-list="true"
:headers="headers"
:file-list="fileList"
:on-preview="handlePictureCardPreview"
:class="{hide: this.fileList.length >= this.limit}"
> >
<i class="el-icon-plus"></i> <!-- 拖拽元素 -->
</el-upload> <li
v-for="item in fileList"
:key="item.ossId"
:style="{ width: '120px', height: '120px' }"
class="draggable-item"
>
<el-image :preview-src-list="[item.url]" :src="item.url"></el-image>
<div class="shadow" @click="handleRemove(item)">
<i class="el-icon-delete"></i>
</div>
</li>
<!-- 上传按钮 -->
<el-upload
multiple
:action="uploadImgUrl"
list-type="picture-card"
:on-success="handleUploadSuccess"
:before-upload="handleBeforeUpload"
:limit="limit"
:on-error="handleUploadError"
:on-exceed="handleExceed"
name="file"
:show-file-list="false"
:style="{ width: '120px', height: '120px' }"
:headers="headers"
:file-list="fileList"
slot="footer"
:class="{hide: this.fileList.length >= this.limit}"
>
<i class="el-icon-plus"></i>
</el-upload>
</vuedraggable>
<!-- 上传提示 --> <!-- 上传提示 -->
<div class="el-upload__tip" slot="tip" v-if="showTip"> <div class="el-upload__tip" slot="tip" v-if="showTip">
请上传 请上传
@ -45,8 +67,10 @@
<script> <script>
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
import { delOss } from "@/api/system/oss"; import { delOss } from "@/api/system/oss";
import vuedraggable from "vuedraggable";
export default { export default {
components: {vuedraggable},
props: { props: {
value: [String, Object, Array], value: [String, Object, Array],
// //
@ -56,7 +80,7 @@ export default {
}, },
// (MB) // (MB)
fileSize: { fileSize: {
type: Number, type: Number,
default: 5, default: 5,
}, },
// , ['png', 'jpg', 'jpeg'] // , ['png', 'jpg', 'jpeg']
@ -113,6 +137,15 @@ export default {
}, },
}, },
methods: { methods: {
//
onDragStart(e) {
e.target.classList.add('hideShadow');
},
//
onDragEnd(e) {
e.target.classList.remove('hideShadow');
this.$emit("input", this.fileList);
},
// //
handleRemove(file, fileList) { handleRemove(file, fileList) {
const findex = this.fileList.map(f => f.name).indexOf(file.name); const findex = this.fileList.map(f => f.name).indexOf(file.name);
@ -190,17 +223,105 @@ export default {
<style scoped lang="scss"> <style scoped lang="scss">
// .el-upload--picture-card // .el-upload--picture-card
::v-deep.hide .el-upload--picture-card { ::v-deep.hide .el-upload--picture-card {
display: none; display: none;
} }
// //
::v-deep .el-list-enter-active, ::v-deep .el-list-enter-active,
::v-deep .el-list-leave-active { ::v-deep .el-list-leave-active {
transition: all 0s; transition: all 0s;
} }
::v-deep .el-list-enter, .el-list-leave-active { ::v-deep .el-list-enter, .el-list-leave-active {
opacity: 0; opacity: 0;
transform: translateY(0); transform: translateY(0);
} }
::v-deep .el-upload {
width: 100%;
height: 100%;
}
//
.uploadIcon {
width: 100%;
height: 100%;
position: relative;
display: flex;
align-items: center;
justify-content: center;
border: 1px dashed #c0ccda;
background-color: #fbfdff;
border-radius: 6px;
font-size: 20px;
color: #999;
.limitTxt,
.uploading {
position: absolute;
bottom: 10%;
left: 0;
width: 100%;
font-size: 14px;
text-align: center;
}
}
//
.vue-draggable {
display: flex;
flex-wrap: wrap;
.draggable-item {
margin-right: 5px;
margin-bottom: 5px;
border: 1px solid #ddd;
border-radius: 6px;
position: relative;
overflow: hidden;
.el-image {
width: 100%;
height: 100%;
}
.shadow {
position: absolute;
top: 0;
right: 0;
background-color: rgba(0, 0, 0, .5);
opacity: 0;
transition: opacity .3s;
color: #fff;
font-size: 20px;
line-height: 20px;
padding: 2px;
cursor: pointer;
}
&:hover {
.shadow {
opacity: 1;
}
}
}
&.hideShadow {
.shadow {
display: none;
}
}
}
// el-image
.el-image-viewer__wrapper {
.el-image-viewer__mask {
opacity: .8;
}
.el-icon-circle-close {
color: #fff;
}
}
</style> </style>