Commit 24548856 by yancanhua

fix: 上传图片预览及视频预览优化

1 parent 40614fc7
Pipeline #155 for 24548856 failed in 0 seconds
......@@ -95,54 +95,77 @@ function previewImage(url: string) {
imagePreview.value = true;
}
// 视频预览
const videoShow = ref(false);
const sourceUrl = ref([]);
function previewVideo(url: string) {
sourceUrl.value = [url];
console.log("sourceUrl.value", sourceUrl.value);
videoShow.value = true;
}
</script>
<template>
<div>
<van-overlay :show="uploading"
teleport="#vant-portal-host"
z-index="2000">
<div class="loadingBox">
<van-loading color="#1989fa" size="24px" vertical>上传中...</van-loading>
</div>
</van-overlay>
<div>
<van-overlay :show="uploading" teleport="#vant-portal-host" z-index="2000">
<div class="loadingBox">
<van-loading color="#1989fa" size="24px" vertical>上传中...</van-loading>
</div>
</van-overlay>
<van-image-preview v-model:show="imagePreview" :images="previewImagesList"></van-image-preview>
<!-- 图片预览 -->
<van-image-preview v-model:show="imagePreview" :images="previewImagesList"></van-image-preview>
<div class="buttonSelect">
<div class="title">
<div class="titleContent">
<span v-if="item.required === 1" class="isRequired">*</span>
<span>{{ item.nodeName }}</span>
</div>
<div v-if="validationRules.maxCount && validationRules.maxCount.length > 1 && item.interactionType == 'image_upload'"
class="titleTip">
有损伤请拍摄图片,无损伤请忽略
</div>
</div>
<input ref="fileInputRef" :accept="item.interactionType == 'image_upload' ? 'image/*' : 'video/*'"
class="hidden-input" type="file" @change="onFileChange">
<div class="uploadPage">
<div v-if="(validationRules.maxCount || 3) > pickerValue.length" class="uploadBox" @click="pickFile">
<van-icon class="plusBox" color="#999999" name="plus" size="24" />
<div class="uploadTxt">
{{ item.interactionType == 'image_upload' ? '添加照片' : '添加视频' }}
<!-- 视频预览 -->
<van-image-preview v-model:show="videoShow" :images="sourceUrl" :close-on-click-image="false">
<template #image="{ src }">
<video style="width: 100%;" :src="src" controls>
您的浏览器不支持 video 标签。
</video>
</template>
</van-image-preview>
<div class="buttonSelect">
<div class="title">
<div class="titleContent">
<span v-if="item.required === 1" class="isRequired">*</span>
<span>{{ item.nodeName }}</span>
</div>
<div v-if="validationRules.maxCount && validationRules.maxCount.length > 1 && item.interactionType == 'image_upload'"
class="titleTip">
有损伤请拍摄图片,无损伤请忽略
</div>
</div>
<div v-for="(url, index) in pickerValue" :key="index" class="uploadBox">
<div class="deleteBox" @click="handleDelete(url)">
<van-icon color="#999999" name="clear" size="20" />
<input ref="fileInputRef" :accept="item.interactionType == 'image_upload' ? 'image/*' : 'video/*'"
class="hidden-input" type="file" @change="onFileChange">
<div class="uploadPage">
<div v-if="(validationRules.maxCount || 3) > pickerValue.length" class="uploadBox" @click="pickFile">
<van-icon class="plusBox" color="#999999" name="plus" size="24" />
<div class="uploadTxt">
{{ item.interactionType == 'image_upload' ? '添加照片' : '添加视频' }}
</div>
</div>
<div v-for="(url, index) in pickerValue" :key="index" class="uploadBox">
<div class="deleteBox" @click="handleDelete(url)">
<van-icon color="#999999" name="clear" size="20" />
</div>
<!-- 图片 -->
<van-image v-if="item.interactionType == 'image_upload'" :src="url" class="uploadBoxImg" width="96"
height="96" radius="8px" @click="previewImage(url)" />
<!-- 视频 -->
<video v-if="item.interactionType == 'video_upload'" :src="url" class="uploadBoxImg" controls>
您的浏览器不支持 video 标签。
</video>
<!-- 点击视频预览 -->
<div v-if="item.interactionType == 'video_upload'" class="videoPreviewBox"
@click="previewVideo(url)"></div>
</div>
<!-- 图片 -->
<van-image v-if="item.interactionType == 'image_upload'" :src="url" class="uploadBoxImg" width="96" height="96" radius="8px" @click="previewImage(url)" />
<!-- 视频 -->
<video v-if="item.interactionType == 'video_upload'" :src="url" class="uploadBoxImg" controls>
您的浏览器不支持 video 标签。
</video>
</div>
</div>
</div>
</div>
</template>
<style lang="scss" scoped>
......@@ -240,7 +263,7 @@ function previewImage(url: string) {
position: absolute;
top: 2px;
right: 2px;
z-index: 99;
z-index: 999;
width: 20px;
height: 20px;
cursor: pointer;
......@@ -255,4 +278,14 @@ function previewImage(url: string) {
transform: translate(-50%, -50%);
}
.videoPreviewBox {
position: absolute;
top: 0px;
left: 0;
width: 96px;
height: 96px;
background: rgba(0, 0, 0, 0.5);
opacity: 0.1;
z-index: 9;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!