<el-upload
ref="uploadRef"
:limit="1"
:on-exceed="handleExceed"
accept=".doc,.docx,.pdf"
:action="upload.url"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:show-file-list="true"
:auto-upload="true"
:file-list="fileList"
multiple
>
<el-button type="primary">上传</el-button>
<template #tip>
<div class="el-upload__tip">
<span>仅允许导入word、pdf格式文件。</span>
<!-- <el-link
type="primary"
:underline="false"
style="font-size: 12px; vertical-align: baseline"
@click="importTemplate"
>下载模板</el-link
> -->
</div>
</template>
</el-upload>
ts
<script setup name="cpglnew">
import { reactive, ref } from 'vue'
const { proxy } = getCurrentInstance()
/*** 导入参数 */
const upload = reactive({
// 是否显示弹出层(导入)
open: false,
// 弹出层标题(导入)
title: '',
// 是否禁用上传
isUploading: false,
// 是否更新已经存在的用户数据
// updateSupport: 0,
// 设置上传的请求头部
// headers: { Authorization: 'Bearer ' + getToken() },
// 上传的地址
url: import.meta.env.VITE_APP_BASE_API + '/common/upload' // 上传文件服务器地址
})
const fileList=ref([])
/** 修改按钮操作 */
function handleUpdateforecast(row) {
fileList.value=[]
getList()
resetforecast()
// console.log('row',row)
// Object.keys(forecastform.value).forEach((key) => {
// forecastform.value[key] = row[key]
// })
const forecastId = row.forecastId
getForecastListinfo(forecastId).then((response) => {
forecastform.value = response.data
console.log('forecastform.value',forecastform.value.filePath)
//文件名显示,替换上个文件
let file={}
file.name=forecastform.value.fileName
file.url=forecastform.value.filePath
if(forecastform.value!==''){
fileList.value.push(file)
}
// open.value = true
forecastitle.value = '修改'
})
//替换文件
const handleExceed = (file, fileList) => {
// console.log('file',file)
if(file){
proxy.$refs['uploadRef'].clearFiles()
}
proxy.$refs['uploadRef'].handleStart(file[0])
// 替换掉fileList中的第一个文件
// proxy.$refs["uploadRef"].handleRemove(file);
// fileList.value = [file];
proxy.$refs["uploadRef"].submit();
};
/** 下载模板操作 没做*/
function importTemplate() {
proxy.download("/common/download", {
}, `ceshi_template_${new Date().getTime()}.xlsx`);
};
/**文件上传中处理 */
const handleFileUploadProgress = (event, file, fileList) => {
upload.isUploading = true;
console.log('event',event)
console.log('file',file)
};
/** 文件上传成功处理 */
const handleFileSuccess = (response, file, fileList) => {
upload.open = false;
upload.isUploading = false;
forecastform.value.filePath = response.url
// proxy.$refs["uploadRef"].handleRemove(file);
proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
getList();
};
/** 提交上传文件 */
function submitFileForm() {
proxy.$refs["uploadRef"].submit();
};