Commit 3e5eb55b by zhangbin

gx:核酸结果模板替换

parent 22cd92fa
......@@ -44,6 +44,19 @@ export function getList(params) {
}))
}
// 模板替换
export function TemplateReplace(params) {
return axios({
method: 'post',
data: params,
url: `${baseUrl}/admin-api/nucleicAcidResult/TemplateReplace`,
responseType: 'blob',
headers: {
"Authorization": getToken() ? ( 'Bearer ' + getToken()) : "",
}
})
}
// 导入excel
export function exportAdd(params) {
return axios({
......
......@@ -16,13 +16,19 @@
<el-form-item>
<el-button type="primary" size="small" @click="addNucleicAcid">新增</el-button>
</el-form-item>
<el-form-item>
<!-- <el-form-item>
<el-button type="primary" size="small" @click="downLoad">下载Excel模板</el-button>
</el-form-item> -->
<el-form-item>
<el-upload class="mx-2" name="file" action="string" :before-upload="beforeAvatarUpload" :limit="1"
accept=".xlsx,.xls" :show-file-list="false" :file-list="fileList" :http-request="uploadFile1">
<el-button type="primary" size="small">模板替换</el-button>
</el-upload>
</el-form-item>
<el-form-item>
<el-upload class="mx-2" name="file" action="string" :before-upload="beforeAvatarUpload" :limit="1"
accept=".xlsx,.xls" :show-file-list="false" :file-list="fileList" :http-request="uploadFile">
<el-button type="primary" size="small">导入Excel文件</el-button>
<el-button type="primary" size="small" @click="upload">导入Excel文件</el-button>
</el-upload>
</el-form-item>
</el-form>
......@@ -93,6 +99,7 @@ import { queryCity } from "@/api/antigen.js";
import {
getList,
exportAdd,
TemplateReplace,
getResultDetail,
customAdd,
update
......@@ -253,8 +260,43 @@ export default {
a.setAttribute("download", "核酸采样结果导入模板.xls")
a.click()
},
uploadFile1(param) {
const File = param.file;
let formData1 = new FormData();
formData1.append("file", File);
const link = document.createElement("a");
link.style.display = "none";
TemplateReplace(formData1).then((res) => {
console.log('res', res);
this.fileList = [];
if (res.status == 200) {
link.href = window.URL.createObjectURL(
new Blob([res.data], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8",
})
);
link.setAttribute("download", "");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
this.init();
this.$message.success("替换成功");
} else {
this.init();
this.$message.warning(res.msg || "替换失败");
}
}).catch(() => {
this.fileList = []
this.$message.warning("替换失败");
});
},
upload() {
this.$message.warning("请先进行模板替换");
},
// 上传前对文件的大小的判断
beforeAvatarUpload(file) {
this.loading = true;
const extension = file.name.split(".")[file.name.split('.').length - 1] === "xls";
const extension2 = file.name.split(".")[file.name.split('.').length - 1] === "xlsx";
......@@ -272,6 +314,8 @@ export default {
});
}
return extension || extension2 || isLt2M;
},
uploadFile(param) {
const File = param.file;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment