|
|
@ -101,6 +101,14 @@ |
|
|
|
<div class="m-table"> |
|
|
|
<div class="div_btn"> |
|
|
|
<el-button size="small" type="primary" @click="handleAdd">新增</el-button> |
|
|
|
<el-button class="diy-button--white" size="small" @click="handleExportModule('room')">下载模板</el-button> |
|
|
|
<el-upload :headers="$getElUploadHeaders()" ref="upload" class="upload-btn" action="uploadUlr" |
|
|
|
:limit="1" :accept="'.xls,.xlsx'" :with-credentials="true" :show-file-list="false" |
|
|
|
:auto-upload="true" :on-progress="handleProgress" :on-success="handleExcelSuccess" |
|
|
|
:before-upload="beforeExcelUpload" :http-request="uploadHttpRequest" |
|
|
|
style="display: inline-block;margin:0px 10px"> |
|
|
|
<el-button size="small" class="diy-button--white" :loading="importLoading">导入</el-button> |
|
|
|
</el-upload> |
|
|
|
<el-button @click="handleExport" class="diy-button--white" size="small">导出</el-button> |
|
|
|
<el-dropdown size="small" split-button type="primary" style="margin: 0 10px; height: 30px" |
|
|
|
@command="(command) => handleMarkDiffcult(command)"> |
|
|
@ -491,6 +499,113 @@ export default { |
|
|
|
this.$message.error(msg); |
|
|
|
} |
|
|
|
}, |
|
|
|
//下载模版 |
|
|
|
async handleExportModule() { |
|
|
|
let url = '/governance/icEvent/downloadTemplate'; |
|
|
|
let params = {}; |
|
|
|
await this.$http({ |
|
|
|
method: 'POST', |
|
|
|
url, |
|
|
|
responseType: 'blob', |
|
|
|
data: params |
|
|
|
}) |
|
|
|
.then(res => { |
|
|
|
if (res.headers['content-disposition']) { |
|
|
|
let fileName = window.decodeURI(res.headers['content-disposition'].split(';')[1].split('=')[1]); |
|
|
|
let blob = new Blob([res.data], { |
|
|
|
type: 'application/vnd.ms-excel' |
|
|
|
}); |
|
|
|
var url = window.URL.createObjectURL(blob); |
|
|
|
var aLink = document.createElement('a'); |
|
|
|
aLink.style.display = 'none'; |
|
|
|
aLink.href = url; |
|
|
|
aLink.setAttribute('download', fileName); |
|
|
|
document.body.appendChild(aLink); |
|
|
|
aLink.click(); |
|
|
|
document.body.removeChild(aLink); //下载完成移除元素 |
|
|
|
window.URL.revokeObjectURL(url); //释放掉blob对象 |
|
|
|
} else this.$message.error('下载失败'); |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.log('err', err); |
|
|
|
return this.$message.error('网络错误'); |
|
|
|
}); |
|
|
|
}, |
|
|
|
handleExcelSuccess(res, file) { |
|
|
|
if (!res.code === 0 && !res.msg === 'success') { |
|
|
|
this.$message.error(res.msg); |
|
|
|
} |
|
|
|
}, |
|
|
|
handleProgress(event, file, fileList) { |
|
|
|
|
|
|
|
}, |
|
|
|
beforeExcelUpload(file) { |
|
|
|
const isType = file.type === 'application/vnd.ms-excel'; |
|
|
|
const isTypeComputer = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; |
|
|
|
const fileType = isType || isTypeComputer; |
|
|
|
const isLt1M = file.size / 1024 / 1024 < 10; |
|
|
|
if (!fileType) { |
|
|
|
this.$message.error('上传文件只能是xls/xlsx格式!'); |
|
|
|
} |
|
|
|
|
|
|
|
if (!isLt1M) { |
|
|
|
this.$message.error('上传文件大小不能超过 10MB!'); |
|
|
|
} |
|
|
|
return fileType && isLt1M; |
|
|
|
}, |
|
|
|
async uploadHttpRequest(file) { |
|
|
|
this.importLoading = true; |
|
|
|
this.importBtnTitle = '正在上传中...'; |
|
|
|
this.$message({ |
|
|
|
showClose: true, |
|
|
|
dangerouslyUseHTMLString: true, |
|
|
|
message: "导入中,请到系统管理-<a id='clickA' style='cursor: pointer;'>导入记录</a>中查看进度", |
|
|
|
duration: 3000 |
|
|
|
}); |
|
|
|
let than = this; |
|
|
|
document.getElementById('clickA').addEventListener('click', function () { |
|
|
|
than.$router.replace('/main/importRecord-index'); |
|
|
|
}); |
|
|
|
const formData = new FormData(); //FormData对象,添加参数只能通过append('key', value)的形式添加 |
|
|
|
formData.append('file', file.file); //添加文件对象 |
|
|
|
formData.append('code', ''); //添加文件对象 |
|
|
|
await this.$http |
|
|
|
.post('/governance/icEvent/importEvent', formData) |
|
|
|
.then(res => { |
|
|
|
console.log('res-up', res); |
|
|
|
if (res.data.code == 0 && res.data.msg == 'success') { |
|
|
|
const data = res.data.data; |
|
|
|
this.dataList = [ |
|
|
|
...Object.keys(data.option.exist).map(k => { |
|
|
|
return { |
|
|
|
index: k, |
|
|
|
srcField: data.option.exist[k], |
|
|
|
exist: true, |
|
|
|
field: data.option.exist[k] |
|
|
|
}; |
|
|
|
}), |
|
|
|
...Object.keys(data.option.notExist).map(k => { |
|
|
|
return { |
|
|
|
index: k, |
|
|
|
srcField: data.option.notExist[k], |
|
|
|
exist: false, |
|
|
|
field: '' |
|
|
|
}; |
|
|
|
}) |
|
|
|
]; |
|
|
|
this.importOption = data.option; |
|
|
|
this.importCode = data.code; |
|
|
|
this.fileData = file; |
|
|
|
} else this.$message.error(res.data.msg); |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.log('失败', err); |
|
|
|
file.onError(); //上传失败的文件会从文件列表中删除 |
|
|
|
}); |
|
|
|
this.importLoading = false; |
|
|
|
this.importBtnTitle = '导入'; |
|
|
|
this.$refs.upload.clearFiles(); |
|
|
|
}, |
|
|
|
|
|
|
|
//显示语音窗口 |
|
|
|
handleShowVoice(url) { |
|
|
|