Commit 3e5eb55b by zhangbin

gx:核酸结果模板替换

parent 22cd92fa
...@@ -44,6 +44,19 @@ export function getList(params) { ...@@ -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 // 导入excel
export function exportAdd(params) { export function exportAdd(params) {
return axios({ return axios({
......
...@@ -16,13 +16,19 @@ ...@@ -16,13 +16,19 @@
<el-form-item> <el-form-item>
<el-button type="primary" size="small" @click="addNucleicAcid">新增</el-button> <el-button type="primary" size="small" @click="addNucleicAcid">新增</el-button>
</el-form-item> </el-form-item>
<el-form-item> <!-- <el-form-item>
<el-button type="primary" size="small" @click="downLoad">下载Excel模板</el-button> <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-form-item> <el-form-item>
<el-upload class="mx-2" name="file" action="string" :before-upload="beforeAvatarUpload" :limit="1" <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"> 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-upload>
</el-form-item> </el-form-item>
</el-form> </el-form>
...@@ -93,6 +99,7 @@ import { queryCity } from "@/api/antigen.js"; ...@@ -93,6 +99,7 @@ import { queryCity } from "@/api/antigen.js";
import { import {
getList, getList,
exportAdd, exportAdd,
TemplateReplace,
getResultDetail, getResultDetail,
customAdd, customAdd,
update update
...@@ -253,25 +260,62 @@ export default { ...@@ -253,25 +260,62 @@ export default {
a.setAttribute("download", "核酸采样结果导入模板.xls") a.setAttribute("download", "核酸采样结果导入模板.xls")
a.click() 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) { beforeAvatarUpload(file) {
this.loading = true;
const extension = file.name.split(".")[file.name.split('.').length - 1] === "xls"; this.loading = true;
const extension2 = file.name.split(".")[file.name.split('.').length - 1] === "xlsx"; const extension = file.name.split(".")[file.name.split('.').length - 1] === "xls";
const isLt2M = file.size / 1024 / 1024 < 10; const extension2 = file.name.split(".")[file.name.split('.').length - 1] === "xlsx";
if (!extension && !extension2) { const isLt2M = file.size / 1024 / 1024 < 10;
this.$message({ if (!extension && !extension2) {
message: "上传模板只能是 xls、xlsx格式!", this.$message({
type: "error", message: "上传模板只能是 xls、xlsx格式!",
}); type: "error",
} });
if (!isLt2M) { }
this.$message({ if (!isLt2M) {
message: "上传模板大小不能超过 10MB!", this.$message({
type: "error", message: "上传模板大小不能超过 10MB!",
}); type: "error",
} });
return extension || extension2 || isLt2M; }
return extension || extension2 || isLt2M;
}, },
uploadFile(param) { uploadFile(param) {
const File = param.file; 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