提交 91b8e7d8 编写于 作者: zhaosheng.zhang's avatar zhaosheng.zhang

Merge branch 'task/reservation/video' into 'release'

fix: 优化预约单上传图片和视频

See merge request com.pica.cloud.education.frontend/pica-admin-consultation!289
<template> <template>
<div> <div>
<el-upload <el-upload
:action="actionurl" action="#"
:headers="headers" :headers="headers"
:disabled="isDisable" :disabled="isDisable"
list-type="picture-card" list-type="picture-card"
...@@ -12,178 +12,112 @@ ...@@ -12,178 +12,112 @@
:on-exceed="handleExceed" :on-exceed="handleExceed"
:file-list="imgArr" :file-list="imgArr"
:accept="accept" :accept="accept"
:before-upload="beforeUpload" :before-upload="beforeUploadFile"
> >
<i class="el-icon-plus" /> <i class="el-icon-plus" />
</el-upload> </el-upload>
<el-dialog :visible.sync="dialogVisible"> <el-dialog :visible.sync="dialogVisible">
<img <img
v-if="isImage"
width="100%" width="100%"
:src="dialogImageUrl" :src="dialogImageUrl"
alt="" alt=""
> >
<video
v-if="isVideo"
id="video"
:src="dialogVideoUrl"
style="width: 100%;height: 80vh;object-fit: fill;"
autoplay
controls
loop
/>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { getBaseUrl } from '@/utils/index'; import { doUpload, getFilePath } from '@/utils/qiniu-util';
export default { import { openLoading, closeLoading } from '@/utils/utils';
props: { let _this = null;
isDisable: {
type: Boolean, export default {
default: false, props: {
}, isDisable: {
imgList: { type: Boolean,
type: Array, default: false,
default: () => {
return [];
}, },
}, imgList: {
}, type: Array,
data() { default: () => {
return { return [];
dialogImageUrl: '', },
dialogVisible: false,
imgArr: [],
headers: {
token: localStorage.getItem('token'),
}, },
actionurl: '#',
accept: '.png,.jpeg,.mp4',
isImage: false,
isVideo: false,
dialogVideoUrl: ''
};
},
watch: {
imgList(newv) {
this.imgArr = newv;
},
},
created() {
this.actionurl = getBaseUrl('/diagnose/illness/file');
},
methods: {
handleRemove(file, fileList) {
console.log(file);
this.imgArr = fileList;
}, },
handlePictureCardPreview(file) { data() {
this.dialogVisible = true; return {
if (file?.raw) { dialogImageUrl: '',
const isImage = this.isImageURL(file?.raw?.name); dialogVisible: false,
const isVideo = this.isVideoFormat(file?.raw?.name); imgArr: [],
if (isVideo) { headers: {
this.isVideoStatus(file); token: localStorage.getItem('token'),
} },
accept: '.png,.jpeg',
if (isImage) { };
this.isImageStatus(file);
}
return;
}
if (this.isImageURL(file?.url)) {
this.isImageStatus(file);
} else {
this.isVideoStatus(file);
}
},
isImageStatus(file) {
this.isImage = true;
this.isVideo = false;
this.dialogImageUrl = file?.url;
},
isVideoStatus(file) {
this.isVideo = true;
this.isImage = false;
this.dialogVideoUrl = file.url;
// this.getVideoCover(file);
},
isImageURL(url) {
return /\.(jpg|jpeg|png)$/i.test(url);
},
isVideoFormat(url) {
const videoExtensions = /\.(mp4)$/i;
return videoExtensions.test(url);
}, },
handleExceed(files, fileList) { watch: {
this.$message.warning( imgList(newv) {
`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${ this.imgArr = newv;
files.length + fileList.length },
} 个文件`
);
}, },
sucess(response, file, fileList) { created() {
console.log(response); _this = this;
// this.getVideoCover(file);
this.imgArr = fileList;
}, },
setNewArr() { methods: {
const newArr = []; handleRemove(file, fileList) {
if (this.imgArr && this.imgArr.length) { console.log(file);
this.imgArr.forEach((item) => { this.imgArr = fileList;
if (item.response) { },
newArr.push(item.response.data); handlePictureCardPreview(file) {
} else if (item.url && item.from) { this.dialogImageUrl = file.url;
newArr.push(item.url); this.dialogVisible = true;
} },
handleExceed(files, fileList) {
this.$message.warning(
`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
files.length + fileList.length
} 个文件`
);
},
sucess(response, file, fileList) {
console.log(response);
console.log(file);
this.imgArr = fileList;
},
setNewArr() {
const newArr = [];
if (this.imgArr && this.imgArr.length) {
this.imgArr.forEach((item) => {
if (item.url && item.status === 'success') {
newArr.push(item.url);
}
});
}
return newArr;
},
beforeUploadFile(file) {
openLoading(_this);
doUpload(
_this,
file,
getFilePath(file, null),
null,
null,
1
).then(function(res) {
closeLoading(_this);
const fileItem = {
name: res.name,
size: res.size,
status: 'success',
url: res.fullPath
};
_this.imgArr.push(fileItem);
_this.$message.success('上传成功');
}); });
} },
return newArr;
},
beforeUpload(file) {
const isImage = this.isImageURL(file?.name);
const isVideo = this.isVideoFormat(file?.name);
if (isImage) {
this.isImage = true;
this.isVideo = false;
}
if (isVideo) {
this.isVideo = true;
this.isImage = false;
}
}, },
/** };
* 获取视频第一帧作为回显封面
* @param file 至少应包含url信息,即 {url: ""}
*/
getVideoCover(file) {
const video = document.createElement('video'); // 也可以自己创建video
video.src = file.url; // url地址 url跟 视频流是一样的
var canvas = document.createElement('canvas'); // 获取 canvas 对象
const ctx = canvas.getContext('2d'); // 绘制2d
video.crossOrigin = 'anonymous'; // 解决跨域问题,也就是提示污染资源无法转换视频
video.currentTime = 1; // 第一帧
video.oncanplay = () => {
canvas.width = video.clientWidth ? video.clientWidth : 320; // 获取视频宽度
canvas.height = video.clientHeight ? video.clientHeight : 320; // 获取视频高度
// 利用canvas对象方法绘图
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
// 转换成base64形式
const videoFirstimgsrc = canvas.toDataURL('image/*'); // 截取后的视频封面
const videoUrl = file.url;
file.url = videoFirstimgsrc; // file的url储存封面图片
this.dialogVideoUrl = videoUrl;
video.remove();
canvas.remove();
};
}
},
};
</script> </script>
<style></style> <style></style>
<template>
<div class="upload">
<el-upload
action="#"
:headers="headers"
:disabled="isDisable"
:on-remove="handleRemove"
:on-success="sucess"
:on-exceed="handleExceed"
:file-list="imgArr"
accept="video/mp4"
:limit="15"
:before-upload="beforeUploadFile"
multiple
>
<el-button
size="small"
type="primary"
>
点击上传
</el-button>
</el-upload>
<div class="upload-main">
<video
v-for="(value, index) in imgArr"
:key="index"
:src="value.url"
class="upload-main__video"
controls
preload
/>
</div>
</div>
</template>
<script>
import { doUpload, getFilePath } from '@/utils/qiniu-util';
import { openLoading, closeLoading } from '@/utils/utils';
let _this = null;
export default {
props: {
isDisable: {
type: Boolean,
default: false,
},
imgList: {
type: Array,
default: () => {
return [];
},
},
},
data() {
return {
dialogImageUrl: '',
imgArr: [],
headers: {
token: localStorage.getItem('token'),
},
};
},
watch: {
imgList(newv) {
const newList = newv?.map(item => {
const suffixUrl = item?.url.substring(item?.url.lastIndexOf('/') + 1); // 接口不返回name,上传数据列表名称展示为截取url最后“/”后面的内容
item.name = suffixUrl;
return item;
});
this.imgArr = newList;
},
},
created() {
_this = this;
},
methods: {
handleRemove(file, fileList) {
console.log(file);
this.imgArr = fileList;
},
handleExceed(files, fileList) {
this.$message.warning(
`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
files.length + fileList.length
} 个文件`
);
},
sucess(response, file, fileList) {
console.log(response);
console.log(file);
this.imgArr = fileList;
},
setNewArr() {
const newArr = [];
if (this.imgArr && this.imgArr.length) {
this.imgArr.forEach((item) => {
if (item.url && item.status === 'success') {
newArr.push(item.url);
}
});
}
return newArr;
},
beforeUploadFile(file) {
openLoading(_this);
doUpload(
_this,
file,
getFilePath(file, null),
null,
null,
''
).then(function(res) {
closeLoading(_this);
const fileItem = {
name: res.name ? res.name : res.fullPath,
size: res.size,
status: 'success',
url: res.fullPath
};
_this.imgArr.push(fileItem);
_this.$message.success('上传成功');
});
}
},
};
</script>
<style lang="scss" scoped>
.upload {
&-main {
overflow-y: scroll;
&__video {
margin-top: 5px;
margin-right: 25px;
width: 200px;
height: 200px;
object-fit: fill;
}
}
}
/* 隐藏滚动条 */
::-webkit-scrollbar {
display: none;
}
</style>
...@@ -675,7 +675,21 @@ ...@@ -675,7 +675,21 @@
:is-disable="editorType == 2" :is-disable="editorType == 2"
:img-list=" :img-list="
formData.illnessImageUrls.filter((i) => { formData.illnessImageUrls.filter((i) => {
return i && !i.url.includes('.pdf'); return i && isImageUrl(i.url) && !i.url.includes('.pdf');
})
"
/>
</el-form-item>
<el-form-item label="病情视频">
<p class="img-title">
请上传患处视频、所用药品、与病情相关的线上诊疗记录视频、检查检测报告,请保证视频清晰完整,以便医生确认病情
</p>
<upload-video
ref="videoComponent"
:is-disable="editorType == 2"
:img-list="
formData.illnessImageUrls.filter((i) => {
return i && isVideoUrl(i.url) && !i.url.includes('.pdf');
}) })
" "
/> />
...@@ -989,6 +1003,7 @@ import { ...@@ -989,6 +1003,7 @@ import {
} from '@/api/diagnosis'; } from '@/api/diagnosis';
import uploadImg from '@/components/editor/upload-img'; import uploadImg from '@/components/editor/upload-img';
import uploadMusic from '@/components/editor/upload-music'; import uploadMusic from '@/components/editor/upload-music';
import uploadVideo from '@/components/editor/upload-video';
import { import {
CAR_LIST, CAR_LIST,
D_S_LIST, D_S_LIST,
...@@ -1010,6 +1025,7 @@ export default { ...@@ -1010,6 +1025,7 @@ export default {
components: { components: {
uploadImg, uploadImg,
uploadMusic, uploadMusic,
uploadVideo
}, },
data() { data() {
return { return {
...@@ -1417,9 +1433,13 @@ export default { ...@@ -1417,9 +1433,13 @@ export default {
this.formData.birthday = new Date(this.formData.birthdayStr); this.formData.birthday = new Date(this.formData.birthdayStr);
// this.formData.birthday = this.formData.birthdayStr; // this.formData.birthday = this.formData.birthdayStr;
const params = JSON.parse(JSON.stringify(this.formData)); const params = JSON.parse(JSON.stringify(this.formData));
params.illnessImageUrls = this.$refs.imgComponent const newImageList = this.$refs.imgComponent
? [...this.$refs.imgComponent.setNewArr()] ? [...this.$refs.imgComponent.setNewArr()]
: []; : [];
const newVideoList = this.$refs.videoComponent
? [...this.$refs.videoComponent.setNewArr()]
: [];
params.illnessImageUrls = newImageList.concat(newVideoList);
params.illnessAudioUrls = this.$refs.musicComponent params.illnessAudioUrls = this.$refs.musicComponent
? [...this.$refs.musicComponent.setNewArr()] ? [...this.$refs.musicComponent.setNewArr()]
: []; : [];
...@@ -1462,6 +1482,15 @@ export default { ...@@ -1462,6 +1482,15 @@ export default {
openPdf(item) { openPdf(item) {
window.open(item.url); window.open(item.url);
}, },
// 正则匹配图片格式
isImageUrl(url) {
return /\.(jpg|jpeg|png)$/i.test(url);
},
// 正则匹配视频格式
isVideoUrl(url) {
const videoExtensions = /\.(mp4)$/i;
return videoExtensions.test(url);
},
}, },
}; };
</script> </script>
...@@ -1475,7 +1504,6 @@ export default { ...@@ -1475,7 +1504,6 @@ export default {
margin-bottom: 30px; margin-bottom: 30px;
} }
.img-title { .img-title {
margin-top: 20px;
font-size: 14px; font-size: 14px;
color: #6d8bc7; color: #6d8bc7;
line-height: 40px; line-height: 40px;
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册