feat : 需求征集新增/编辑/详情页面初始化
This commit is contained in:
67
src/components/FileUpload.vue
Normal file
67
src/components/FileUpload.vue
Normal file
@@ -0,0 +1,67 @@
|
||||
<template>
|
||||
<el-upload :file-list="_value"
|
||||
:action="uploadFileUrl"
|
||||
:headers="headers"
|
||||
:limit="maxSize"
|
||||
with-credentials
|
||||
:multiple="maxSize > 0"
|
||||
:data="uploadParams"
|
||||
:auto-upload="true"
|
||||
:before-upload="beforeUpload"
|
||||
:on-success="handleUploadSuccess"
|
||||
>
|
||||
<el-button color="#DED0B2">上传文件</el-button>
|
||||
</el-upload>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {defineProps, computed, ref} from "vue";
|
||||
import {ElMessage} from "element-plus";
|
||||
import { getToken } from '@/utils/auth'
|
||||
const baseURL = import.meta.env.VITE_BASE_URL
|
||||
const uploadFileUrl = ref(baseURL + "/workflow/process/file")
|
||||
const headers = reactive({
|
||||
authorization: getToken()
|
||||
})
|
||||
const disabled = ref(false)
|
||||
const uploadParams = ref({})
|
||||
const props = defineProps({
|
||||
value: {
|
||||
type: Array,
|
||||
default: () => {
|
||||
return []
|
||||
}
|
||||
},
|
||||
maxSize: {
|
||||
type: Number,
|
||||
default: 5
|
||||
}
|
||||
})
|
||||
const emit = defineEmits(["input","getFile"])
|
||||
const fileList = ref([])
|
||||
const _value = computed({
|
||||
get() {
|
||||
return props.value;
|
||||
},
|
||||
set(val) {
|
||||
emit("input", val);
|
||||
}
|
||||
})
|
||||
|
||||
const beforeUpload = (file) => {
|
||||
// if (props.maxSize > 0 && file.size / 1024 / 1024 > props.maxSize) {
|
||||
// ElMessage.warning(`每个文件最大不超过 ${props.maxSize}MB`)
|
||||
// } else {
|
||||
return true
|
||||
// }
|
||||
}
|
||||
const handleUploadSuccess = (res, file) => {
|
||||
if (res.code !== 1000) {
|
||||
ElMessage.error("上传失败")
|
||||
}
|
||||
let data = res.data
|
||||
fileList.value.push(data)
|
||||
emit("getFile", fileList.value)
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user