Commit 06978b88 authored by 黄同智's avatar 黄同智

文件上传组件

parent dcfda87a
<template> <template>
<div> <div class="upload-demo" :style="{
<div> 'border': `1px dashed ${borderColor}`,
</div>
<el-upload class="upload-demo" :multiple="multiple" :show-file-list="false" :limit="limit" :accept="accept"
:style="{
'border': borderColor ? `1px dashed ${borderColor}` : 'none',
'background-color': `${backgroundColor}` 'background-color': `${backgroundColor}`
}" drag action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"> }">
<div class="h-200 flex-center flex-col" v-if="fileList.length > 0">
<div class="flex-align-center rounded-6 px-10 py-6 file">
<el-icon size="36" color="#3461f3"><Document /></el-icon>
<div class="ml-4">
<div>文件名文件名文件名</div>
<div class="text-999 fs-12 mt-6">pdf</div>
</div>
</div>
<el-button class="mt-20" round :icon="Upload" @click="fileList=[]">重新上传</el-button>
</div>
<el-upload v-else :show-file-list="false" :accept="accept" drag
action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15">
<slot /> <slot />
</el-upload> </el-upload>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { Document, Upload } from '@element-plus/icons-vue'
const emit = defineEmits(['changeFiles'])
const props = defineProps({ const props = defineProps({
borderColor: { borderColor: {
type: String, type: String,
...@@ -24,24 +33,18 @@ const props = defineProps({ ...@@ -24,24 +33,18 @@ const props = defineProps({
type: String, type: String,
default: '#fff' default: '#fff'
}, },
multiple: {
type: Boolean,
default: false
},
showFileList: { showFileList: {
type: Boolean, type: Boolean,
default: false default: false
}, },
limit: {
type: Number,
default: 1
},
accept: { accept: {
type: String, type: String,
default: 'img' default: 'img'
} }
}) })
const fileList = ref([])
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.upload-demo { .upload-demo {
...@@ -49,7 +52,7 @@ const props = defineProps({ ...@@ -49,7 +52,7 @@ const props = defineProps({
transition: all 0.2s; transition: all 0.2s;
&:hover { &:hover {
border-color: #5337C7; border-color: #5337C7 !important;
} }
:deep(.el-upload-dragger) { :deep(.el-upload-dragger) {
...@@ -60,5 +63,9 @@ const props = defineProps({ ...@@ -60,5 +63,9 @@ const props = defineProps({
.el-upload__text { .el-upload__text {
color: #00000063; color: #00000063;
} }
.file {
border: 1px solid #eee;
background-color: #f9f9f9;
}
} }
</style> </style>
\ No newline at end of file
<template>
<div class="upload-demo" :style="{
'border': `1px dashed ${borderColor}`,
'background-color': `${backgroundColor}`
}">
<div class="flex-center flex-col relative" style="height: 270px;" v-if="fileList.length == 0">
<div class="h-b100 overflow-hidden">
<img src="https://res.volccdn.com/obj/volc-console-fe/dramart/static/image/PIC3.22e42366.png"
class="w-b100 h-b100 object-cover" />
</div>
<div class="absolute bottom-0 left-0 top-0 w-b100 flex-center rounded-14 bg-099">
<el-button class="mt-20" round :icon="Upload" @click="fileList=[]">重新上传</el-button>
</div>
</div>
<el-upload v-else :show-file-list="false" :accept="accept" drag
action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15">
<slot />
</el-upload>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { Upload } from '@element-plus/icons-vue'
const emit = defineEmits(['changeFiles'])
const props = defineProps({
borderColor: {
type: String,
default: '#ddd'
},
backgroundColor: {
type: String,
default: '#fff'
},
showFileList: {
type: Boolean,
default: false
},
accept: {
type: String,
default: 'img'
}
})
const fileList = ref([])
</script>
<style scoped lang="scss">
.upload-demo {
border-radius: 16px;
transition: all 0.2s;
:deep(.el-upload) {
border: 2px dashed #ddd;
width: 100%;
height: 240px;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
transition: all 0.3s;
&:hover {
border-color: #c5c5c5;
}
}
:deep(.el-upload-dragger) {
background-color: transparent;
border: none;
}
.el-upload__text {
color: #00000063;
}
.bg-099 {
background-color: #00000020;
}
}
</style>
\ No newline at end of file
...@@ -27,19 +27,12 @@ ...@@ -27,19 +27,12 @@
<div class="flex-center fs-40 pt-82">翻开剧本,创作<span class="c-5337C7">精品短剧</span></div> <div class="flex-center fs-40 pt-82">翻开剧本,创作<span class="c-5337C7">精品短剧</span></div>
<section class="card mt-44 bg-fff rounded-20 p-12"> <section class="card mt-44 bg-fff rounded-20 p-12">
<!-- <el-upload class="upload-demo" drag action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" <UploadSingleFile backgroundColor="#F8F9FC" accept=".doc,.docx,.pdf,.txt,.md" @changeFiles="changeFiles">
:on-change="handleChange" :show-file-list="false" accept=".doc,.docx,.pdf,.txt,.md">
<img src="@/static/imgs/fileupload.png" class="w-120" alt=""> <img src="@/static/imgs/fileupload.png" class="w-120" alt="">
<div class="el-upload__text mt-24"> <div class="el-upload__text mt-24">
点击或拖拽剧本文件到这里,支持 doc、docx、txt、pdf、md,大小不超过 20M;也可以先跳过,下一页手动输入刷本 点击或拖拽剧本文件到这里,支持 doc、docx、txt、pdf、md,大小不超过 20M;也可以先跳过,下一页手动输入刷本
</div> </div>
</el-upload> --> </UploadSingleFile>
<UploadFile backgroundColor="#F8F9FC" accept=".doc,.docx,.pdf,.txt,.md">
<img src="@/static/imgs/fileupload.png" class="w-120" alt="">
<div class="el-upload__text mt-24">
点击或拖拽剧本文件到这里,支持 doc、docx、txt、pdf、md,大小不超过 20M;也可以先跳过,下一页手动输入刷本
</div>
</UploadFile>
<section class="mt-12"> <section class="mt-12">
<el-dropdown> <el-dropdown>
...@@ -164,7 +157,7 @@ import { ref } from 'vue'; ...@@ -164,7 +157,7 @@ import { ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { ArrowDownBold, SwitchFilled } from '@element-plus/icons-vue' import { ArrowDownBold, SwitchFilled } from '@element-plus/icons-vue'
import UploadFile from '@/components/UploadFile.vue' import UploadSingleFile from '@/components/UploadSingleFile.vue'
const router = useRouter(); const router = useRouter();
...@@ -184,6 +177,10 @@ const handleChange = (uploadFile: any, uploadFiles: any) => { ...@@ -184,6 +177,10 @@ const handleChange = (uploadFile: any, uploadFiles: any) => {
console.log(11, uploadFile, uploadFiles) console.log(11, uploadFile, uploadFiles)
} }
const changeFiles = (file: any) => {
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
...@@ -197,26 +194,6 @@ const handleChange = (uploadFile: any, uploadFiles: any) => { ...@@ -197,26 +194,6 @@ const handleChange = (uploadFile: any, uploadFiles: any) => {
.card { .card {
width: 800px; width: 800px;
.upload-demo {
background-color: #F8F9FC;
border: 1px dashed #ddd;
border-radius: 16px;
transition: all 0.2s;
&:hover {
border-color: #5337C7;
}
:deep(.el-upload-dragger) {
background-color: transparent;
border: none;
}
.el-upload__text {
color: #00000063;
}
}
} }
.btnjb { .btnjb {
......
...@@ -14,10 +14,8 @@ ...@@ -14,10 +14,8 @@
<el-button type="primary" @click="close">确定</el-button> <el-button type="primary" @click="close">确定</el-button>
</div> </div>
</template> </template>
<el-upload class="avatar-uploader mt-20" action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" <UploadSingleImg @changeFiles="changeFiles">
:show-file-list="false"> <div class="flex-center flex-col line-h24 fs-12">
<img v-if="imageUrl" :src="imageUrl" class="avatar" />
<div v-else class="flex-center flex-col line-h24 fs-12">
<el-icon size="20"> <el-icon size="20">
<Plus /> <Plus />
</el-icon> </el-icon>
...@@ -25,7 +23,7 @@ ...@@ -25,7 +23,7 @@
<span>仅支持 JPG, PNG 格式</span> <span>仅支持 JPG, PNG 格式</span>
<span>最大文件限制在 20MB 内</span> <span>最大文件限制在 20MB 内</span>
</div> </div>
</el-upload> </UploadSingleImg>
<div class="text-center mt-20 mb-40">支持 JPG、PNG 格式,单个文件不超过 20MB</div> <div class="text-center mt-20 mb-40">支持 JPG、PNG 格式,单个文件不超过 20MB</div>
</el-dialog> </el-dialog>
</template> </template>
...@@ -34,6 +32,7 @@ ...@@ -34,6 +32,7 @@
import { ref } from 'vue' import { ref } from 'vue'
import { Plus } from '@element-plus/icons-vue' import { Plus } from '@element-plus/icons-vue'
import IconType from './IconType.vue'; import IconType from './IconType.vue';
import UploadSingleImg from '@/components/UploadSingleImg.vue';
const props = defineProps({ const props = defineProps({
title: { title: {
...@@ -53,6 +52,10 @@ const close = () => { ...@@ -53,6 +52,10 @@ const close = () => {
visible.value = false visible.value = false
} }
defineExpose({ open }) defineExpose({ open })
const changeFiles = (val: any) => {
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.cirir { .cirir {
......
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