更换导入接口
This commit is contained in:
24
src/api/ecology/water/lake/import.js
Normal file
24
src/api/ecology/water/lake/import.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import axios from 'axios';
|
||||
const baseUri = '/api/lakeLibrary/lakeLibraryImport'
|
||||
|
||||
|
||||
export const cityOther = `${baseUri}/cityOther`
|
||||
export const appointCity = `${baseUri}/appointCity`
|
||||
export const special = `${baseUri}/special`
|
||||
|
||||
|
||||
// 城市内湖-其他内湖:/api/lakeLibrary/lakeLibraryImport/
|
||||
export const importCityOther = function (data) {
|
||||
return axios.post(cityOther,data)
|
||||
}
|
||||
|
||||
// 城市内湖-五象湖:/api/lakeLibrary/lakeLibraryImport/appointCity
|
||||
export const importCppointCity = function (data) {
|
||||
console.log('data',data)
|
||||
return axios.post(appointCity,data)
|
||||
}
|
||||
|
||||
// 专项湖库:/api/lakeLibrary/lakeLibraryImport/special
|
||||
export const importSpecial = function (data) {
|
||||
return axios.post(special,data)
|
||||
}
|
||||
@@ -61,13 +61,14 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import XLSX from "xlsx";
|
||||
import utils from "./utils";
|
||||
import {Modal} from "ant-design-vue";
|
||||
// import XLSX from "xlsx";
|
||||
// import utils from "./utils";
|
||||
// import {Modal} from "ant-design-vue";
|
||||
import WaterBill from "./water-bill.vue";
|
||||
import SpecialBill from "./special-bill.vue";
|
||||
import {saveLakeBill} from "@/api/ecology/lake";
|
||||
import {saveLakeBill as saveSpecialLake} from "@/api/ecology/special-lake";
|
||||
// import {saveLakeBill} from "@/api/ecology/lake";
|
||||
// import {saveLakeBill as saveSpecialLake} from "@/api/ecology/special-lake";
|
||||
import {importCityOther,importCppointCity,importSpecial} from "@/api/ecology/water/lake/import";
|
||||
|
||||
export default {
|
||||
name: "LakeCollectIndex",
|
||||
@@ -87,255 +88,275 @@ export default {
|
||||
/* 导入本地excel文件 */
|
||||
importFileInnerCity(file) {
|
||||
const hide = this.$message.loading("导入中..", 0);
|
||||
|
||||
let reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
let data = new Uint8Array(e.target.result);
|
||||
let workbook = XLSX.read(data, {
|
||||
type: "array",
|
||||
});
|
||||
//0.昼间数据 1.夜间数据 2.其他信息
|
||||
let sheetNames = workbook.SheetNames;
|
||||
// 解析成二维数组
|
||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
header: 1,
|
||||
});
|
||||
|
||||
const reportDate = aoa[2][0].replace(/[^\d]+/g, "-");
|
||||
|
||||
const lakeList = aoa.filter(
|
||||
(item) => {
|
||||
return item.length >= 24 && item[0] && !item[0].includes("点位名称");
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// 解析成对象数组
|
||||
const billName = file.name;
|
||||
const billData = utils.toInnerCityLakeObjData(lakeList, reportDate);
|
||||
if (!billData || billData.length == 0) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
importCityOther(formData).then(res=>{
|
||||
console.log(res)
|
||||
hide()
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "找不到数据",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const tasks = [];
|
||||
if (billData.length > 0) {
|
||||
tasks.push(
|
||||
saveLakeBill({
|
||||
reportTime: new Date(reportDate).getTime(),
|
||||
billName: billName,
|
||||
regionLevel: "市级",
|
||||
lakeLibraryInnerCityList: billData,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// let reader = new FileReader();
|
||||
// reader.onload = (e) => {
|
||||
// try {
|
||||
// let data = new Uint8Array(e.target.result);
|
||||
// let workbook = XLSX.read(data, {
|
||||
// type: "array",
|
||||
// });
|
||||
// //0.昼间数据 1.夜间数据 2.其他信息
|
||||
// let sheetNames = workbook.SheetNames;
|
||||
// // 解析成二维数组
|
||||
// let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
// header: 1,
|
||||
// });
|
||||
|
||||
// const reportDate = aoa[2][0].replace(/[^\d]+/g, "-");
|
||||
|
||||
// const lakeList = aoa.filter(
|
||||
// (item) => {
|
||||
// return item.length >= 24 && item[0] && !item[0].includes("点位名称");
|
||||
// }
|
||||
// );
|
||||
|
||||
|
||||
// 上传到服务器
|
||||
// // 解析成对象数组
|
||||
// const billName = file.name;
|
||||
// const billData = utils.toInnerCityLakeObjData(lakeList, reportDate);
|
||||
// if (!billData || billData.length == 0) {
|
||||
// hide()
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "找不到数据",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
// const tasks = [];
|
||||
// if (billData.length > 0) {
|
||||
// tasks.push(
|
||||
// saveLakeBill({
|
||||
// reportTime: new Date(reportDate).getTime(),
|
||||
// billName: billName,
|
||||
// regionLevel: "市级",
|
||||
// lakeLibraryInnerCityList: billData,
|
||||
// })
|
||||
// );
|
||||
// }
|
||||
|
||||
Promise.all(tasks)
|
||||
.then((res) => {
|
||||
if (res[0].data.code == 0) {
|
||||
Modal.success({
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData.length}条数据`,
|
||||
});
|
||||
this.$refs.water && this.$refs.water.reload();
|
||||
} else {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
});
|
||||
} catch (error) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: error.message,
|
||||
});
|
||||
}
|
||||
// console.log(billData);
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
// // 上传到服务器
|
||||
|
||||
// Promise.all(tasks)
|
||||
// .then((res) => {
|
||||
// if (res[0].data.code == 0) {
|
||||
// Modal.success({
|
||||
// title: "导入成功",
|
||||
// content: `成功导入${billData.length}条数据`,
|
||||
// });
|
||||
// this.$refs.water && this.$refs.water.reload();
|
||||
// } else {
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "数据上传出错",
|
||||
// });
|
||||
// }
|
||||
|
||||
// })
|
||||
// .catch(() => {
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "数据上传出错",
|
||||
// });
|
||||
// })
|
||||
// .finally(() => {
|
||||
// hide();
|
||||
// });
|
||||
// } catch (error) {
|
||||
// hide();
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: error.message,
|
||||
// });
|
||||
// }
|
||||
// // console.log(billData);
|
||||
// };
|
||||
// reader.readAsArrayBuffer(file);
|
||||
|
||||
return false;
|
||||
},
|
||||
importFileWuxiang(file) {
|
||||
const hide = this.$message.loading("导入中..", 0);
|
||||
|
||||
let reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
let data = new Uint8Array(e.target.result);
|
||||
let workbook = XLSX.read(data, {
|
||||
type: "array",
|
||||
});
|
||||
let sheetNames = workbook.SheetNames;
|
||||
// 解析成二维数组
|
||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
header: 1,
|
||||
});
|
||||
const lakeList = aoa.filter(
|
||||
(item) => {
|
||||
return item.length >= 24 && item[0] && !item[0].includes("点位名称");
|
||||
}
|
||||
);
|
||||
// 解析成对象数组
|
||||
const billName = file.name;
|
||||
const billData = utils.toWuxiangLakeObjData(lakeList);
|
||||
if (!billData || billData.length == 0) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
importCppointCity(formData).then(res=>{
|
||||
console.log(res)
|
||||
hide()
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "找不到数据",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const tasks = [];
|
||||
if (billData.length > 0) {
|
||||
tasks.push(
|
||||
saveLakeBill({
|
||||
billName: billName,
|
||||
lakeLibraryInnerCityList: billData,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// 上传到服务器
|
||||
// let reader = new FileReader();
|
||||
// reader.onload = (e) => {
|
||||
// try {
|
||||
// let data = new Uint8Array(e.target.result);
|
||||
// let workbook = XLSX.read(data, {
|
||||
// type: "array",
|
||||
// });
|
||||
// let sheetNames = workbook.SheetNames;
|
||||
// // 解析成二维数组
|
||||
// let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
// header: 1,
|
||||
// });
|
||||
// const lakeList = aoa.filter(
|
||||
// (item) => {
|
||||
// return item.length >= 24 && item[0] && !item[0].includes("点位名称");
|
||||
// }
|
||||
// );
|
||||
// // 解析成对象数组
|
||||
// const billName = file.name;
|
||||
// const billData = utils.toWuxiangLakeObjData(lakeList);
|
||||
// if (!billData || billData.length == 0) {
|
||||
// hide()
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "找不到数据",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
// const tasks = [];
|
||||
// if (billData.length > 0) {
|
||||
// tasks.push(
|
||||
// saveLakeBill({
|
||||
// billName: billName,
|
||||
// lakeLibraryInnerCityList: billData,
|
||||
// })
|
||||
// );
|
||||
// }
|
||||
|
||||
Promise.all(tasks)
|
||||
.then((res) => {
|
||||
if (res[0].data.code == 0) {
|
||||
Modal.success({
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData.length}条数据`,
|
||||
});
|
||||
this.$refs.water && this.$refs.water.reload();
|
||||
} else {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
});
|
||||
} catch (error) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: error.message,
|
||||
});
|
||||
}
|
||||
// console.log(billData);
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
// // 上传到服务器
|
||||
|
||||
// Promise.all(tasks)
|
||||
// .then((res) => {
|
||||
// if (res[0].data.code == 0) {
|
||||
// Modal.success({
|
||||
// title: "导入成功",
|
||||
// content: `成功导入${billData.length}条数据`,
|
||||
// });
|
||||
// this.$refs.water && this.$refs.water.reload();
|
||||
// } else {
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "数据上传出错",
|
||||
// });
|
||||
// }
|
||||
|
||||
// })
|
||||
// .catch(() => {
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "数据上传出错",
|
||||
// });
|
||||
// })
|
||||
// .finally(() => {
|
||||
// hide();
|
||||
// });
|
||||
// } catch (error) {
|
||||
// hide();
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: error.message,
|
||||
// });
|
||||
// }
|
||||
// // console.log(billData);
|
||||
// };
|
||||
// reader.readAsArrayBuffer(file);
|
||||
|
||||
return false;
|
||||
},
|
||||
importFileSpecial(file) {
|
||||
const hide = this.$message.loading("导入中..", 0);
|
||||
|
||||
let reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
let data = new Uint8Array(e.target.result);
|
||||
let workbook = XLSX.read(data, {
|
||||
type: "array",
|
||||
});
|
||||
let sheetNames = workbook.SheetNames;
|
||||
// 解析成二维数组
|
||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
header: 1,
|
||||
});
|
||||
const lakeList = aoa.filter(
|
||||
(item) => {
|
||||
return item.length >= 24 && item[1] && !item[1].includes("测站名称");
|
||||
}
|
||||
);
|
||||
// 解析成对象数组
|
||||
const billName = file.name;
|
||||
const billData = utils.toSpecialLakeData(lakeList);
|
||||
if (!billData || billData.length == 0) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
importSpecial(formData).then(res=>{
|
||||
console.log(res)
|
||||
hide()
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "找不到数据",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const tasks = [];
|
||||
if (billData.length > 0) {
|
||||
tasks.push(
|
||||
saveSpecialLake({
|
||||
billName: billName,
|
||||
lakeLibrarySpecialList: billData,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// let reader = new FileReader();
|
||||
// reader.onload = (e) => {
|
||||
// try {
|
||||
// let data = new Uint8Array(e.target.result);
|
||||
// let workbook = XLSX.read(data, {
|
||||
// type: "array",
|
||||
// });
|
||||
// let sheetNames = workbook.SheetNames;
|
||||
// // 解析成二维数组
|
||||
// let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
// header: 1,
|
||||
// });
|
||||
// const lakeList = aoa.filter(
|
||||
// (item) => {
|
||||
// return item.length >= 24 && item[1] && !item[1].includes("测站名称");
|
||||
// }
|
||||
// );
|
||||
// // 解析成对象数组
|
||||
// const billName = file.name;
|
||||
// const billData = utils.toSpecialLakeData(lakeList);
|
||||
// if (!billData || billData.length == 0) {
|
||||
// hide()
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "找不到数据",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
// const tasks = [];
|
||||
// if (billData.length > 0) {
|
||||
// tasks.push(
|
||||
// saveSpecialLake({
|
||||
// billName: billName,
|
||||
// lakeLibrarySpecialList: billData,
|
||||
// })
|
||||
// );
|
||||
// }
|
||||
|
||||
|
||||
// 上传到服务器
|
||||
// // 上传到服务器
|
||||
|
||||
Promise.all(tasks)
|
||||
.then((res) => {
|
||||
if (res[0].data.code == 0) {
|
||||
Modal.success({
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData.length}条数据`,
|
||||
});
|
||||
this.$refs.special && this.$refs.special.reload();
|
||||
} else {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
}
|
||||
// Promise.all(tasks)
|
||||
// .then((res) => {
|
||||
// if (res[0].data.code == 0) {
|
||||
// Modal.success({
|
||||
// title: "导入成功",
|
||||
// content: `成功导入${billData.length}条数据`,
|
||||
// });
|
||||
// this.$refs.special && this.$refs.special.reload();
|
||||
// } else {
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "数据上传出错",
|
||||
// });
|
||||
// }
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
});
|
||||
} catch (error) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: error.message,
|
||||
});
|
||||
}
|
||||
// console.log(billData);
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
// })
|
||||
// .catch(() => {
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: "数据上传出错",
|
||||
// });
|
||||
// })
|
||||
// .finally(() => {
|
||||
// hide();
|
||||
// });
|
||||
// } catch (error) {
|
||||
// hide();
|
||||
// Modal.error({
|
||||
// title: "导入失败",
|
||||
// content: error.message,
|
||||
// });
|
||||
// }
|
||||
// // console.log(billData);
|
||||
// };
|
||||
// reader.readAsArrayBuffer(file);
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user