feat(SingleUpload.vue): 上传组件添加删除图片功能
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div >
|
||||||
<el-upload
|
<el-upload
|
||||||
class="avatar-uploader"
|
|
||||||
action=""
|
action=""
|
||||||
|
class="avatar-uploader"
|
||||||
list-type="picture-card"
|
list-type="picture-card"
|
||||||
:show-file-list="false"
|
:show-file-list="false"
|
||||||
:before-upload="handleBeforeUpload"
|
:before-upload="handleBeforeUpload"
|
||||||
@@ -16,15 +16,25 @@
|
|||||||
<el-icon v-else class="avatar-uploader-icon">
|
<el-icon v-else class="avatar-uploader-icon">
|
||||||
<Plus/>
|
<Plus/>
|
||||||
</el-icon>
|
</el-icon>
|
||||||
|
|
||||||
|
<el-icon
|
||||||
|
v-if="imgUrl"
|
||||||
|
class="remove-icon"
|
||||||
|
@click.stop="handleRemove(imgUrl)"
|
||||||
|
>
|
||||||
|
<Close/>
|
||||||
|
</el-icon>
|
||||||
|
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {computed, reactive, toRefs} from "vue";
|
import {computed, reactive, toRefs} from "vue";
|
||||||
import {Plus} from '@element-plus/icons-vue'
|
import {Plus, Close} from '@element-plus/icons-vue'
|
||||||
import {ElMessage} from "element-plus"
|
import {ElMessage} from "element-plus"
|
||||||
import {deleteFile, uploadFile} from "@/api/system/file";
|
import {uploadFile, deleteFile} from "@/api/system/file";
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue']);
|
const emit = defineEmits(['update:modelValue']);
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -55,10 +65,10 @@ const imgUrl = computed({
|
|||||||
function handleBeforeUpload(file: any) {
|
function handleBeforeUpload(file: any) {
|
||||||
const isJPG = file.type === 'image/jpeg'
|
const isJPG = file.type === 'image/jpeg'
|
||||||
const isLt2M = file.size / 1024 / 1024 < 2
|
const isLt2M = file.size / 1024 / 1024 < 2
|
||||||
/* if (!isJPG) {
|
/* if (!isJPG) {
|
||||||
ElMessage.warning("此文件非图片文件")
|
ElMessage.warning("此文件非图片文件")
|
||||||
return false
|
return false
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (!isLt2M) {
|
if (!isLt2M) {
|
||||||
ElMessage.warning("上传图片不能大于2M")
|
ElMessage.warning("上传图片不能大于2M")
|
||||||
@@ -83,10 +93,9 @@ function handleExceed(file: any) {
|
|||||||
ElMessage.warning('最多只能上传' + props.maxCount)
|
ElMessage.warning('最多只能上传' + props.maxCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleRemove(imgUrl: string) {
|
||||||
function handleRemove(file: any, fileList: Array<any>) {
|
deleteFile(imgUrl)
|
||||||
deleteFile(file.url)
|
emit('update:modelValue', '')
|
||||||
emit('update:modelValue', fileList)
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -116,4 +125,14 @@ function handleRemove(file: any, fileList: Array<any>) {
|
|||||||
height: 148px;
|
height: 148px;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.remove-icon {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #ff4d51 !important;
|
||||||
|
margin-top: 0px !important;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
color: #409eff;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user