修改部分自写公共组件代码
This commit is contained in:
@@ -1,69 +1,103 @@
|
||||
<template>
|
||||
<up-upload :fileList="images" @afterRead="afterRead" @delete="deletePic" :multiple="multiple"
|
||||
:width="width" :height="height"
|
||||
:maxCount="10"></up-upload>
|
||||
<up-upload :fileList="images" @afterRead="afterRead" @delete="deletePic" :multiple="multiple" :width="width"
|
||||
:height="height" :maxCount="maxCount"></up-upload>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {$uploadFile} from '@/http/yskApi/file.js'
|
||||
import {
|
||||
ref, watch
|
||||
$uploadFile
|
||||
} from '@/http/yskApi/file.js'
|
||||
import {
|
||||
ref,
|
||||
watch
|
||||
} from 'vue';
|
||||
|
||||
const props=defineProps({
|
||||
modelValue:{
|
||||
type:Array,
|
||||
default:()=>[]
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
width:{
|
||||
type:[String,Number],
|
||||
default:60
|
||||
width: {
|
||||
type: [String, Number],
|
||||
default: 60
|
||||
},
|
||||
height:{
|
||||
type:[String,Number],
|
||||
default:60
|
||||
height: {
|
||||
type: [String, Number],
|
||||
default: 60
|
||||
},
|
||||
multiple:{
|
||||
type:Boolean,
|
||||
default:true
|
||||
maxCount: {
|
||||
type: [Number],
|
||||
default: 10
|
||||
},
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const emits=defineEmits(['update:modelValue'])
|
||||
|
||||
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const images = ref(props.modelValue)
|
||||
function afterRead(e){
|
||||
for(let i in e.file){
|
||||
const file=e.file[i].file
|
||||
|
||||
function afterRead(e) {
|
||||
console.log(e);
|
||||
if (Array.isArray(e)) {
|
||||
for (let i in e.file) {
|
||||
const file = e.file[i].file
|
||||
$uploadFile(file).then(res => {
|
||||
console.log(res);
|
||||
images.value.push({
|
||||
url: e.file[i].url,
|
||||
serveUrl: res.data[0]
|
||||
})
|
||||
}).catch(res => {
|
||||
console.log(res);
|
||||
if (res.errMsg) {
|
||||
images.value.splice(i, 1)
|
||||
uni.showToast({
|
||||
title: '图片大小超出限制',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}else{
|
||||
const i=0
|
||||
const file = e.file.file
|
||||
$uploadFile(file).then(res => {
|
||||
console.log(res);
|
||||
images.value.push({
|
||||
url: e.file[i].url,
|
||||
url: e.file.url,
|
||||
serveUrl: res.data[0]
|
||||
})
|
||||
}).catch(res=>{
|
||||
}).catch(res => {
|
||||
console.log(res);
|
||||
if(res.errMsg){
|
||||
images.value.splice(i,1)
|
||||
if (res.errMsg) {
|
||||
images.value.splice(i, 1)
|
||||
uni.showToast({
|
||||
title:'图片大小超出限制',
|
||||
icon:'error'
|
||||
title: '图片大小超出限制',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
function deletePic(e){
|
||||
const {index}=e
|
||||
images.value.splice(index,1)
|
||||
|
||||
function deletePic(e) {
|
||||
const {
|
||||
index
|
||||
} = e
|
||||
images.value.splice(index, 1)
|
||||
}
|
||||
|
||||
watch(()=>images.value,(newval)=>{
|
||||
emits('update:modelValue',newval)
|
||||
|
||||
watch(() => images.value, (newval) => {
|
||||
emits('update:modelValue', newval)
|
||||
})
|
||||
watch(()=>props.modelValue,(newval)=>{
|
||||
images.value=newval
|
||||
watch(() => props.modelValue, (newval) => {
|
||||
images.value = newval
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user