|
|
|
@ -1,9 +1,9 @@
|
|
|
|
|
<template>
|
|
|
|
|
<view class="ch-image-uploader">
|
|
|
|
|
<ch-flex class="img-list" justify="center" items="center" @click.native="handleSelect">
|
|
|
|
|
<block v-for="item in imageList" key="item.name">
|
|
|
|
|
<block v-for="item in imageList" key="item.path">
|
|
|
|
|
<view class="img-item" data-type="img">
|
|
|
|
|
<uni-icons type="clear" class="del-btn" size="50" v-if="showClose" data-type="delete" @click="delImg(item.name)"></uni-icons>
|
|
|
|
|
<uni-icons type="clear" class="del-btn" size="50" v-if="showClose" data-type="delete" @click="delImg(item.path)"></uni-icons>
|
|
|
|
|
<image :src="item.path" mode="aspectFit"></image>
|
|
|
|
|
</view>
|
|
|
|
|
</block>
|
|
|
|
@ -78,6 +78,7 @@ function handleSelect (e) {
|
|
|
|
|
extension: props.extList,
|
|
|
|
|
sourceType: props.sourceType,
|
|
|
|
|
success: (res) => {
|
|
|
|
|
console.log(res)
|
|
|
|
|
if (props.limit > 1) {
|
|
|
|
|
const newImageList = filterImage(res.tempFiles)
|
|
|
|
|
imageList.value = [...imageList.value, ...newImageList]
|
|
|
|
@ -122,8 +123,9 @@ function upload () {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delImg (delName) {
|
|
|
|
|
imageList.value = imageList.value.filter(item => item.name !== delName)
|
|
|
|
|
function delImg (path) {
|
|
|
|
|
imageList.value = imageList.value.filter(item => item.path !== path)
|
|
|
|
|
emit('update:modelValue', imageList.value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 格式化image列表
|
|
|
|
@ -141,7 +143,7 @@ function formatImageFiles (fileList) {
|
|
|
|
|
// 过滤重复的图片
|
|
|
|
|
function filterImage (images) {
|
|
|
|
|
return images.filter(item => {
|
|
|
|
|
const result = imageList.value.find(img => img.name === item.name );
|
|
|
|
|
const result = imageList.value.find(img => img.path === item.path );
|
|
|
|
|
return !result;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|