调整上传组件,视频的展示处理

This commit is contained in:
aixianling
2023-04-19 17:13:30 +08:00
parent da5082cde8
commit cb3ce7e729

View File

@@ -4,17 +4,18 @@
<div class="item" v-for="(item, i) in fileList" :key="i"> <div class="item" v-for="(item, i) in fileList" :key="i">
<template v-if="type == 'image'"> <template v-if="type == 'image'">
<ai-image :src="item.url" :preview="preview"/> <ai-image :src="item.url" :preview="preview"/>
<div class="info"> <u-icon v-if="!disabled" class="delBtn" color="#f46" name="close-circle-fill" size="40" @click="remove(i)"/>
<i>{{ item.fileSizeStr }}</i>
</div>
</template> </template>
<template v-else> <template v-else-if="type == 'video'">
<video :src="item.url" :poster="item.thumb"/>
<u-icon v-if="!disabled" class="delBtn" color="#f46" name="close-circle-fill" size="40" @click="remove(i)"/>
</template>
<div class="file" v-else>
<ai-image :preview="preview" :file="item"/> <ai-image :preview="preview" :file="item"/>
<div class="info"> <div class="info">
<span>{{ item.name }} </span> <span>{{ item.name }} </span>
<i>{{ item.fileSizeStr }}</i> <i>{{ item.fileSizeStr }}</i>
</div> </div>
</template>
<template v-if="!disabled"> <template v-if="!disabled">
<div btn @tap="handleReUpload(i)"> <div btn @tap="handleReUpload(i)">
重新上传 重新上传
@@ -24,6 +25,7 @@
</div> </div>
</template> </template>
</div> </div>
</div>
<div v-if="!disabled&&(fileList.length == 0 || (multiple && fileList.length < limit))" class="default" <div v-if="!disabled&&(fileList.length == 0 || (multiple && fileList.length < limit))" class="default"
@click="upload"> @click="upload">
<i class="iconfont iconfont-iconAdd"/> <i class="iconfont iconfont-iconAdd"/>
@@ -51,16 +53,23 @@ export default {
fileId: String, fileId: String,
mediaId: String, mediaId: String,
def: {default: () => []}, def: {default: () => []},
action: {default: '/app/wxcp/upload/uploadFile'}, action: String,
preview: Boolean, preview: Boolean,
size: {default: 10 * 1024 * 1024}, size: {default: 10 * 1024 * 1024},
disabled: Boolean, disabled: Boolean,
sourceType: {default: () => ['album', 'camera']} sourceType: {default: () => ['album', 'camera']}
}, },
computed: { computed: {
errorImage() { ...mapState(['token']),
return this.$cdn + 'file.png' errorImage: v => v.$cdn + 'file.png',
}, api() {
if (this.action) return this.action
else return {
image: '/admin/file/add',
file: '/admin/file/add',
video: '/admin/file/addVideo',
}[this.type]
}
}, },
watch: { watch: {
def: { def: {
@@ -74,6 +83,7 @@ export default {
} }
}, },
immediate: true, immediate: true,
deep: true
}, },
}, },
data() { data() {
@@ -99,10 +109,8 @@ export default {
if (count > this.limit && this.limit !== 1) { if (count > this.limit && this.limit !== 1) {
return this.$u.toast(`不能超过${this.limit}`) return this.$u.toast(`不能超过${this.limit}`)
} }
if (res.tempFiles) { if (res.tempFiles?.length > 0) {
res.tempFiles?.map((item) => { res.tempFiles.map(this.uploadFile)
this.uploadFile(item)
})
} else if (res?.tempFile) { } else if (res?.tempFile) {
this.uploadFile(res.tempFile) this.uploadFile(res.tempFile)
} }
@@ -118,7 +126,6 @@ export default {
} else { } else {
this.$u.toast(`不能超过${this.limit}`) this.$u.toast(`不能超过${this.limit}`)
} }
}, },
uploadFile(img) { uploadFile(img) {
if (this.size > 0 && img.size > this.size) { if (this.size > 0 && img.size > this.size) {
@@ -131,22 +138,29 @@ export default {
this.$emit('manual', img) this.$emit('manual', img)
uni.hideLoading() uni.hideLoading()
} else { } else {
this.$http.post(this.action, formData, { this.$http.post(this.api, formData, {
params: {type: this.type}, params: {type: this.type},
}).then((res) => { }).then((res) => {
uni.hideLoading()
if (res?.data) { if (res?.data) {
this.$emit('data', res.data) this.$emit('data', res.data)
this.$u.toast('上传成功!') this.$u.toast('上传成功!')
if (this.action == '/app/wxcp/upload/uploadFile') { if (!this.action) {
if (this.type == 'image') {
const [image = "",] = res.data
this.fileList.push({url: image.split(";")[0], id: image.split(";")?.[1]})
} else if (this.type == 'video') {
const [video = "", thumb = ""] = res.data
this.fileList.push({url: video.split(";")[0], id: video.split(";")?.[1], thumb: thumb.split(";")[0]})
}
} else if (this.api == '/app/wxcp/upload/uploadFile') {
this.$emit('update:mediaId', res.data?.media?.mediaId) this.$emit('update:mediaId', res.data?.media?.mediaId)
this.$emit('update:fileId', res.data.file.id) this.$emit('update:fileId', res.data.file.id)
this.fileList.push(res.data.file) this.fileList.push(res.data.file)
} else if (this.action == '/admin/file/add2') { } else if (this.api == '/admin/file/add2') {
let info = res.data let info = res.data
this.$emit('update:fileId', info?.id) this.$emit('update:fileId', info?.id)
this.fileList.push(res.data) this.fileList.push(res.data)
} else if (this.action == '/admin/file/add-portrait') { } else if (this.api == '/admin/file/add-portrait') {
this.fileList.push({url: res.data?.split(";")?.[0], id: res.data?.split(";")?.[1]}) this.fileList.push({url: res.data?.split(";")?.[0], id: res.data?.split(";")?.[1]})
} }
this.$emit("update:def", this.fileList) this.$emit("update:def", this.fileList)
@@ -156,8 +170,7 @@ export default {
} }
}).catch(err => { }).catch(err => {
this.$u.toast(err) this.$u.toast(err)
uni.hideLoading() }).finally(() => uni.hideLoading())
})
} }
}, },
@@ -174,15 +187,29 @@ export default {
line-height: normal; line-height: normal;
margin-bottom: 16px; margin-bottom: 16px;
.fileList { ::v-deep.fileList {
.item {
display: flex; display: flex;
align-items: center; flex-wrap: wrap;
margin-bottom: 10px;
image { .item {
width: 160px; width: initial;
height: 160px; padding: 0 10px 10px 0;
position: relative;
.delBtn {
position: absolute;
right: -8px;
top: -8px;
z-index: 2;
border-radius: 50%;
overflow: hidden;
background-color: #fff;
height: 40px;
}
image, video {
width: 29vw;
height: 29vw;
} }
i { i {
@@ -219,8 +246,8 @@ export default {
} }
.default { .default {
width: 240px; width: 30vw;
height: 240px; height: 30vw;
box-sizing: border-box; box-sizing: border-box;
border-radius: 8px; border-radius: 8px;
background: #f3f4f7; background: #f3f4f7;
@@ -240,6 +267,12 @@ export default {
font-size: 28px; font-size: 28px;
} }
} }
.file {
width: 100vw;
display: flex;
align-items: center;
}
} }
} }
</style> </style>