提交 eb08110e authored 作者: 刘旭's avatar 刘旭

优化上传

上级 956f2704
......@@ -32,13 +32,15 @@
<el-button :type="flag === 1 ? 'primary' : 'info'" icon="CircleClose" @click="handleClose">关闭同步
</el-button>
<el-button type="primary" icon="RefreshRight" @click="handleManual">手动同步</el-button>
<el-button type="primary" @click="handleSelected">导入 lic 文件</el-button>
<!-- <el-button type="primary" @click="handleMacAddress">获取mac地址</el-button> -->
<el-upload v-model:file-list="uploadData.fileList" :action="uploadData.action"
:headers="uploadData.headers" accept=".tmp" :show-file-list="false" style="width: 100px;"
:on-success="handleSuccess" :on-error="handleError">
<el-button type="primary">导入lic文件</el-button>
</el-upload>
<div v-show="macAddress" style="font-size: 14px; color: #ccc;">
mac地址:
{{ macAddress }}
</div>
<input ref="uploadInput" type="file" style="display: none;" accept=".tmp" @change="submitUpload">
</el-space>
</div>
<el-table :data="monitoringData" v-loading="loading" border stripe @filter-change="filterChange">
......@@ -102,6 +104,11 @@ import {
} from "@/services/api/systemApi/synchronization/synchronizationAPI";
const loading = ref(true)
const uploadData = reactive({
fileList: '' as any,
action: '/integrate/api/lic/info/file/import',
headers: { Authorization: sessionStorage.getItem("token") }
})
const monitoringData = ref()
const filterForm = ref({
......@@ -135,6 +142,15 @@ const onConfirm = () => {
)
}
const handleSuccess = (res: any, uploadFile: any, uploadFiles: any) => {
if (res.code === 200) ElMessage({ type: 'success', message: '导入成功!' })
else return ElMessage({ type: 'error', message: res.message })
}
const handleError = () => (res: any, uploadFile: any, uploadFiles: any) => {
console.log(res);
}
// 同步筛选
const filterChange = (value: any) => {
let i = ''
......@@ -262,9 +278,6 @@ const handleManual = async () => {
}
};
let uploadInput = ref()
// 点击导入文件
const handleSelected = () => uploadInput.value.click()
const handleMacAddress = () => {
getMacAddress().then((res: any) => {
......@@ -275,38 +288,6 @@ const handleMacAddress = () => {
}
handleMacAddress()
// //选好文件之后点击打开按钮
const submitUpload = (e: any) => {
const files = e.target.files
const rawFile = files[0]
console.log(rawFile);
if (!rawFile) return
upload(rawFile)
}
//上传
const upload = (rawFile: any) => {
uploadInput.value = null
uploadSectionFile(rawFile)
}
const uploadSectionFile = (file: any, params?: any) => {
// let data = params
let fromData = new FormData()// FormData 对象
let fileObj = file// 相当于input里取得的files
console.log('file', fileObj);
fromData.append('file', fileObj)// 文件对象
console.log(fromData);
importFile(fromData).then((res: any) => {
//调用上传接口
if (res.code === 200) {
ElMessage({ type: 'success', message: '导入成功!' })
}
})
}
// 监控数据
const initSMonitoring = (
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论