96 lines
2.2 KiB
Vue
96 lines
2.2 KiB
Vue
<template>
|
|
<el-upload :action="uploadFileUrl"
|
|
:headers="headers"
|
|
:limit="maxSize"
|
|
with-credentials
|
|
:multiple="multiple"
|
|
:data="uploadParams"
|
|
:auto-upload="true"
|
|
:before-upload="beforeUpload"
|
|
:on-success="handleUploadSuccess"
|
|
:on-error="uploadError"
|
|
:before-remove="beforeRemove"
|
|
:on-remove="handleRemove"
|
|
>
|
|
<el-button color="#DED0B2" style="margin-left: 10px; margin-right: 10px;" :loading="loading" :disabled="disabled">导入</el-button>
|
|
</el-upload>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ElMessageBox, ElNotification} from "element-plus";
|
|
import {getToken} from '@/utils/auth'
|
|
|
|
const baseURL = import.meta.env.VITE_BASE_URL
|
|
const uploadFileUrl = ref(baseURL + "/workflow/mosr/expense/ledger/import")
|
|
const headers = reactive({
|
|
authorization: getToken()
|
|
})
|
|
const loading = ref(false)
|
|
const uploadParams = ref({})
|
|
const props = defineProps({
|
|
value: {
|
|
type: Array,
|
|
default: () => {
|
|
return []
|
|
}
|
|
},
|
|
maxSize: {
|
|
type: Number,
|
|
default: 30
|
|
},
|
|
disabled: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
multiple: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
})
|
|
|
|
const emit = defineEmits(["input", "getFile", "delete"])
|
|
const beforeRemove = (file) => {
|
|
return ElMessageBox.confirm(`确认删除名称为${file.name}的文件吗?`, '系统提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(() => true)
|
|
}
|
|
|
|
const handleRemove = (file) => {
|
|
emit("delete", file.response.data.id)
|
|
}
|
|
const beforeUpload = () => {
|
|
loading.value = true
|
|
return true
|
|
}
|
|
const handleUploadSuccess = (res) => {
|
|
ElNotification({
|
|
title: '提示',
|
|
message: res.code === 1000 ? '上传成功' : '上传失败',
|
|
type: res.code === 1000 ? 'success' : 'error'
|
|
})
|
|
loading.value = false
|
|
emit("success")
|
|
}
|
|
const uploadError = (error) => {
|
|
loading.value = false
|
|
ElNotification({
|
|
title: '提示',
|
|
message: "上传失败,请稍后再试!",
|
|
type: 'error'
|
|
})
|
|
}
|
|
defineExpose({
|
|
handleRemove
|
|
})
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
a {
|
|
font-size: 14px;
|
|
color: #2a99ff;
|
|
}
|
|
|
|
</style>
|