Commit f70f7c02 authored by “yiyousong”'s avatar “yiyousong”

perf: 优化上传组件

parent fe52ea32
...@@ -39,25 +39,34 @@ ...@@ -39,25 +39,34 @@
</div> </div>
</slot> </slot>
</a-upload> </a-upload>
<PrevieModal <!-- 视频、音频预览 -->
:previewVisible.sync="previewVisible" <div class="modal" v-if="previewVisible">
:previewData="previewData" <video
></PrevieModal> v-if="previewData.type == 'video'"
:src="previewData.url"
autoplay
muted
controls
></video>
<audio
v-if="previewData.type == 'audio'"
:src="previewData.url"
autoplay
controls
></audio>
<a-icon type="close-circle" @click="previewVisible = false" />
</div>
</div> </div>
</template> </template>
<script> <script>
// import { uploadFile } from "@/services/user"; // import { uploadFile } from "@/services/user";
import PrevieModal from "@/components/PrevieModal.vue";
export default { export default {
model: { model: {
prop: "value", prop: "value",
event: "onChange", event: "onChange",
}, },
components: { components: {},
PrevieModal,
},
props: { props: {
name: { name: {
type: String, type: String,
...@@ -86,7 +95,7 @@ export default { ...@@ -86,7 +95,7 @@ export default {
validator: (value) => { validator: (value) => {
return value >= 0; return value >= 0;
}, },
default: 0, // 0为不限制 default: 1, // 0为不限制
}, },
// 上传文件大小限制mb 0为不限制 // 上传文件大小限制mb 0为不限制
MB: { MB: {
...@@ -107,7 +116,32 @@ export default { ...@@ -107,7 +116,32 @@ export default {
FileList: [], FileList: [],
imageType: ["png", "jpg", "jpeg", "gif", "svg"], imageType: ["png", "jpg", "jpeg", "gif", "svg"],
videoType: ["mp4", "avi", "wmv", "rmvb", "flv", "mkv"], videoType: ["mp4", "avi", "wmv", "rmvb", "flv", "mkv"],
previewData: {}, audioType: [
"mp3",
"wav",
"amr",
"aac",
"ogg",
"wma",
"flac",
"ape",
"mid",
"wav",
"wma",
"mp3",
"m4a",
"m4r",
"m4p",
"m4b",
"wma",
"wav",
"wma",
"wma",
],
previewData: {
type: "",
url: "",
},
previewVisible: false, previewVisible: false,
}; };
}, },
...@@ -117,18 +151,22 @@ export default { ...@@ -117,18 +151,22 @@ export default {
if (newValue) { if (newValue) {
if (Array.isArray(newValue)) { if (Array.isArray(newValue)) {
this.FileList = newValue.map((v) => { this.FileList = newValue.map((v) => {
let index = v.lastIndexOf("/");
let name = v.slice(index + 1);
return { return {
uid: v, uid: v,
name: v, name,
status: "done", status: "done",
url: v, url: v,
}; };
}); });
} else { } else {
this.FileList = newValue.split(",").map((v) => { this.FileList = newValue.split(",").map((v) => {
let index = v.lastIndexOf("/");
let name = v.slice(index + 1);
return { return {
uid: v, uid: v,
name: v, name,
status: "done", status: "done",
url: v, url: v,
}; };
...@@ -189,7 +227,8 @@ export default { ...@@ -189,7 +227,8 @@ export default {
isType = fileType.includes(type); isType = fileType.includes(type);
} }
if (!isType) { if (!isType) {
this.$message.error(`请上传${this.accept}文件!`); let msg = this.accept.replaceAll(",", "或者");
this.$message.error(`请上传${msg}文件!`);
} }
if (this.MB) { if (this.MB) {
...@@ -214,15 +253,17 @@ export default { ...@@ -214,15 +253,17 @@ export default {
images: [url], images: [url],
}); });
} else if (this.videoType.includes(type)) { } else if (this.videoType.includes(type)) {
this.previewData = { this.previewData.type = "video";
type: "video", this.previewData.url = url;
url, this.previewVisible = true;
}; } else if (this.audioType.includes(type)) {
this.previewData.type = "audio";
this.previewData.url = url;
this.previewVisible = true; this.previewVisible = true;
} else { } else {
let a = document.createElement("a"); let a = document.createElement("a");
a.href = url; a.href = url;
a.download = new Date().getTime() + "." + type; a.download = file.name;
document.body.appendChild(a); document.body.appendChild(a);
a.click(); a.click();
document.body.removeChild(a); document.body.removeChild(a);
...@@ -240,4 +281,26 @@ export default { ...@@ -240,4 +281,26 @@ export default {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
} }
.modal {
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
background: rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
z-index: 999;
video {
height: 400px;
}
.anticon-close-circle {
font-size: 36px;
color: #fff;
cursor: pointer;
}
}
</style> </style>
...@@ -83,7 +83,8 @@ ...@@ -83,7 +83,8 @@
v-if="form.appType === 1" v-if="form.appType === 1"
> >
<YUpload <YUpload
accept=".zip" accept=".zip,.mp4"
:MB="150"
:limit="1" :limit="1"
v-model="form.filePath" v-model="form.filePath"
@onSuccess="appUpload" @onSuccess="appUpload"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment