江河导入

This commit is contained in:
weicw
2021-09-07 12:06:05 +08:00
parent addb91fb37
commit 39b8b8c34b
17 changed files with 2489 additions and 356 deletions

View File

@@ -21,7 +21,7 @@
</template>
<a-tabs v-model:activeKey="activeKey">
<a-tab-pane tab="噪声信息" key="noise">
<noise-bill ref="noise"></noise-bill>
<water-bill ref="noise"></water-bill>
</a-tab-pane>
</a-tabs>
</a-card>
@@ -31,13 +31,14 @@
<script>
import XLSX from "xlsx";
import utils from "./utils";
import { Modal } from "ant-design-vue";
import NoiseBill from "./noise-bill.vue";
import { saveZoneNoiseBill } from "@/api/ecology/zone-sound";
import {Modal} from "ant-design-vue";
import WaterBill from "./water-bill.vue";
import {saveRiverBill} from "@/api/ecology/river";
export default {
name: "ZoneCollectIndex",
name: "RiverCollectIndex",
components: {
NoiseBill,
WaterBill,
},
data() {
return {
@@ -62,31 +63,20 @@ export default {
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
header: 1,
});
let aoa2 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[1]], {
header: 1,
});
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
const reportDate2 = aoa2[1][0].replace(/[^\d]+/g, "-");
const zoneNoiseList = aoa.filter(
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
const riverList = aoa.filter(
(item) => {
return item.length >= 26 && typeof item[0] == "number"}
return item.length >= 30 && item[0] && item[0] != "断面编码"
}
);
const zoneNoiseList2 = aoa2.filter(
(item) => item.length >= 26 && typeof item[0] == "number"
);
// 解析成对象数组
const billName = aoa[0][0];
const billData = utils.toObjData(zoneNoiseList);
const billName2 = aoa2[0][0];
const billData2 = utils.toObjData(zoneNoiseList2);
if (
(!billData || billData.length == 0) &&
(!billData2 || billData2.length == 0)
) {
const billName = file.name;
const billData = utils.toObjData(riverList);
if (!billData || billData.length == 0) {
hide()
Modal.error({
title: "导入失败",
@@ -97,35 +87,33 @@ export default {
const tasks = [];
if (billData.length > 0) {
tasks.push(
saveZoneNoiseBill({
saveRiverBill({
reportTime: new Date(reportDate).getTime(),
billName: billName,
regionLevel: "市级",
zoneNoiseList: billData,
surfaceWaterSectionList: billData,
})
);
}
if (billData2.length > 0) {
tasks.push(
saveZoneNoiseBill({
reportTime: new Date(reportDate2).getTime(),
billName: billName2,
regionLevel: "市级",
zoneNoiseList: billData2,
})
);
}
// 上传到服务器
Promise.all(tasks)
.then(() => {
Modal.success({
title: "导入成功",
content: `成功导入${billData.length + billData2.length}条数据`,
});
this.$refs.noise && this.$refs.noise.reload();
.then((res) => {
if (res[0].data.code == 0) {
Modal.success({
title: "导入成功",
content: `成功导入${billData.length}条数据`,
});
this.$refs.noise && this.$refs.noise.reload();
} else {
Modal.error({
title: "导入失败",
content: "数据上传出错",
});
}
})
.catch(() => {
Modal.error({
@@ -149,95 +137,10 @@ export default {
return false;
},
importFileArea(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[1][0].replace(/[^\d]+/g, "-");
const zoneNoiseList = aoa.filter(
(item) => {
return item.length >= 35 && item[0] != "行政区划代码"
}
);
// 解析成对象数组
const billName = aoa[0][0];
const billData = utils.toAreaObjData(zoneNoiseList);
if (!billData || billData.length == 0) {
hide();
Modal.error({
title: "导入失败",
content: "找不到可用数据",
});
return;
}
if (billData.length > 0) {
// 上传到服务器
saveZoneNoiseBill({
reportTime: new Date(reportDate).getTime(),
billName: billName,
regionLevel: "县级",
zoneNoiseList: billData,
})
.then((res) => {
if (res.data.code == 0) {
Modal.success({
title: "导入成功",
content: `成功导入${
billData.length
}条数据`,
});
this.$refs.noise && this.$refs.noise.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;
},
},
};
</script>
<style scoped lang="less">
</style>
</style>