添加噪声导入模板下载
This commit is contained in:
BIN
public/template/功能区噪声-县.xlsx
Normal file
BIN
public/template/功能区噪声-县.xlsx
Normal file
Binary file not shown.
BIN
public/template/功能区噪声-市.xlsx
Normal file
BIN
public/template/功能区噪声-市.xlsx
Normal file
Binary file not shown.
BIN
public/template/区域噪声-县.xlsx
Normal file
BIN
public/template/区域噪声-县.xlsx
Normal file
Binary file not shown.
BIN
public/template/区域噪声-市.xlsx
Normal file
BIN
public/template/区域噪声-市.xlsx
Normal file
Binary file not shown.
BIN
public/template/道路交通噪声-县.xlsx
Normal file
BIN
public/template/道路交通噪声-县.xlsx
Normal file
Binary file not shown.
BIN
public/template/道路交通噪声-市.xlsx
Normal file
BIN
public/template/道路交通噪声-市.xlsx
Normal file
Binary file not shown.
@@ -3,20 +3,22 @@
|
|||||||
<a-card style="width: 100%" :bordered="false">
|
<a-card style="width: 100%" :bordered="false">
|
||||||
<template #title>
|
<template #title>
|
||||||
<a-space>
|
<a-space>
|
||||||
|
<a-select
|
||||||
|
ref="select"
|
||||||
|
v-model:value="regionLevel"
|
||||||
|
style="width: 120px"
|
||||||
|
>
|
||||||
|
<a-select-option value="city">市</a-select-option>
|
||||||
|
<a-select-option value="county">县</a-select-option>
|
||||||
|
</a-select>
|
||||||
<a-upload
|
<a-upload
|
||||||
:before-upload="importFileCity"
|
:before-upload="importFile"
|
||||||
:showUploadList="false"
|
:showUploadList="false"
|
||||||
accept=".xls,.xlsx,.csv"
|
accept=".xls,.xlsx,.csv"
|
||||||
>
|
>
|
||||||
<a-button>市级导入</a-button>
|
<a-button type="primary">数据导入</a-button>
|
||||||
</a-upload>
|
|
||||||
<a-upload
|
|
||||||
:before-upload="importFileArea"
|
|
||||||
:showUploadList="false"
|
|
||||||
accept=".xls,.xlsx,.csv"
|
|
||||||
>
|
|
||||||
<a-button>县级导入</a-button>
|
|
||||||
</a-upload>
|
</a-upload>
|
||||||
|
<a-button @click="download">模板下载</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
</template>
|
</template>
|
||||||
<a-tabs v-model:activeKey="activeKey">
|
<a-tabs v-model:activeKey="activeKey">
|
||||||
@@ -31,9 +33,11 @@
|
|||||||
<script>
|
<script>
|
||||||
import XLSX from "xlsx";
|
import XLSX from "xlsx";
|
||||||
import utils from "./utils";
|
import utils from "./utils";
|
||||||
import { Modal } from "ant-design-vue";
|
import {Modal} from "ant-design-vue";
|
||||||
import NoiseBill from "./noise-bill.vue";
|
import NoiseBill from "./noise-bill.vue";
|
||||||
import { saveFunctionNoiseBill } from "@/api/ecology/noise/function-sound";
|
import {saveFunctionNoiseBill} from "@/api/ecology/noise/function-sound";
|
||||||
|
import {downloadTemplate} from "@/utils/excel-util";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "FunctionCollectIndex",
|
name: "FunctionCollectIndex",
|
||||||
components: {
|
components: {
|
||||||
@@ -42,9 +46,28 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
activeKey: "noise",
|
activeKey: "noise",
|
||||||
|
regionLevel: "city"
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
download() {
|
||||||
|
let filename = "功能区噪声-"
|
||||||
|
if (this.regionLevel == "city") {
|
||||||
|
filename += "市"
|
||||||
|
} else if (this.regionLevel == "county") {
|
||||||
|
filename += "县"
|
||||||
|
} else {
|
||||||
|
filename += "站点"
|
||||||
|
}
|
||||||
|
downloadTemplate(filename)
|
||||||
|
},
|
||||||
|
importFile(file) {
|
||||||
|
if (this.regionLevel == "city") {
|
||||||
|
this.importFileCity(file);
|
||||||
|
} else {
|
||||||
|
this.importFileCounty(file);
|
||||||
|
}
|
||||||
|
},
|
||||||
/* 导入本地excel文件 */
|
/* 导入本地excel文件 */
|
||||||
importFileCity(file) {
|
importFileCity(file) {
|
||||||
const hide = this.$message.loading("导入中..", 0);
|
const hide = this.$message.loading("导入中..", 0);
|
||||||
@@ -62,7 +85,7 @@ export default {
|
|||||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||||
header: 1,
|
header: 1,
|
||||||
});
|
});
|
||||||
let aoa2= XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[1]], {
|
let aoa2 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[1]], {
|
||||||
header: 1,
|
header: 1,
|
||||||
});
|
});
|
||||||
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
|
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
|
||||||
@@ -70,15 +93,15 @@ export default {
|
|||||||
const functionNoiseList = aoa.filter((item) => {
|
const functionNoiseList = aoa.filter((item) => {
|
||||||
return item.length >= 15 && item[0] != "年";
|
return item.length >= 15 && item[0] != "年";
|
||||||
});
|
});
|
||||||
|
|
||||||
const functionNoiseList2 = aoa2.filter(
|
const functionNoiseList2 = aoa2.filter(
|
||||||
(item) => item.length >= 13 && item[1] != "点位名称"
|
(item) => item.length >= 13 && item[1] != "点位名称"
|
||||||
);
|
);
|
||||||
|
|
||||||
// 解析成对象数组
|
// 解析成对象数组
|
||||||
const billName = file.name;
|
const billName = file.name;
|
||||||
const billData = utils.toObjData(functionNoiseList);
|
const billData = utils.toObjData(functionNoiseList);
|
||||||
|
|
||||||
const billData2 = utils.toPlaceData(functionNoiseList2);
|
const billData2 = utils.toPlaceData(functionNoiseList2);
|
||||||
if (!billData || billData.length == 0) {
|
if (!billData || billData.length == 0) {
|
||||||
hide();
|
hide();
|
||||||
@@ -139,7 +162,7 @@ export default {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
importFileArea(file) {
|
importFileCounty(file) {
|
||||||
const hide = this.$message.loading("导入中..", 0);
|
const hide = this.$message.loading("导入中..", 0);
|
||||||
|
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
@@ -161,7 +184,7 @@ export default {
|
|||||||
const functionNoiseList = aoa.filter((item) => {
|
const functionNoiseList = aoa.filter((item) => {
|
||||||
return item.length >= 28 && typeof item[0] != "string";
|
return item.length >= 28 && typeof item[0] != "string";
|
||||||
});
|
});
|
||||||
|
|
||||||
// 解析成对象数组
|
// 解析成对象数组
|
||||||
const billName = file.name;
|
const billName = file.name;
|
||||||
const billData = utils.toAreaObjData(functionNoiseList);
|
const billData = utils.toAreaObjData(functionNoiseList);
|
||||||
@@ -225,4 +248,4 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,31 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="ele-body">
|
<div class="ele-body">
|
||||||
<a-card style="width: 100%" :bordered="false">
|
<a-card style="width: 100%" :bordered="false">
|
||||||
<template #title>
|
<template #title>
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-upload
|
<a-select
|
||||||
:before-upload="importFileCity"
|
ref="select"
|
||||||
:showUploadList="false"
|
v-model:value="regionLevel"
|
||||||
accept=".xls,.xlsx,.csv"
|
style="width: 120px"
|
||||||
>
|
>
|
||||||
<a-button>市级导入</a-button>
|
<a-select-option value="city">市</a-select-option>
|
||||||
</a-upload>
|
<a-select-option value="county">县</a-select-option>
|
||||||
<a-upload
|
</a-select>
|
||||||
:before-upload="importFileArea"
|
<a-upload
|
||||||
:showUploadList="false"
|
:before-upload="importFile"
|
||||||
accept=".xls,.xlsx,.csv"
|
:showUploadList="false"
|
||||||
>
|
accept=".xls,.xlsx,.csv"
|
||||||
<a-button>县级导入</a-button>
|
>
|
||||||
</a-upload>
|
<a-button type="primary">数据导入</a-button>
|
||||||
</a-space>
|
</a-upload>
|
||||||
</template>
|
<a-button @click="download">模板下载</a-button>
|
||||||
<a-tabs v-model:activeKey="activeKey">
|
</a-space>
|
||||||
<a-tab-pane tab="噪声信息" key="noise">
|
</template>
|
||||||
<noise-bill ref="noise"></noise-bill>
|
<a-tabs v-model:activeKey="activeKey">
|
||||||
</a-tab-pane>
|
<a-tab-pane tab="噪声信息" key="noise">
|
||||||
</a-tabs>
|
<noise-bill ref="noise"></noise-bill>
|
||||||
</a-card>
|
</a-tab-pane>
|
||||||
</div>
|
</a-tabs>
|
||||||
|
</a-card>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -34,233 +36,253 @@ import utils from "./utils";
|
|||||||
import {Modal} from "ant-design-vue";
|
import {Modal} from "ant-design-vue";
|
||||||
import NoiseBill from "./noise-bill.vue";
|
import NoiseBill from "./noise-bill.vue";
|
||||||
import {saveRoadNoiseBill} from "@/api/ecology/noise/road-sound";
|
import {saveRoadNoiseBill} from "@/api/ecology/noise/road-sound";
|
||||||
|
import {downloadTemplate} from "@/utils/excel-util";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "RoadCollectIndex",
|
name: "RoadCollectIndex",
|
||||||
components: {
|
components: {
|
||||||
NoiseBill,
|
NoiseBill,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
activeKey: "noise",
|
||||||
|
regionLevel: "city"
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
download(){
|
||||||
|
let filename = "道路交通噪声-"
|
||||||
|
if (this.regionLevel == "city") {
|
||||||
|
filename += "市"
|
||||||
|
} else if (this.regionLevel == "county") {
|
||||||
|
filename += "县"
|
||||||
|
} else {
|
||||||
|
filename += "站点"
|
||||||
|
}
|
||||||
|
downloadTemplate(filename)
|
||||||
},
|
},
|
||||||
data() {
|
importFile(file){
|
||||||
return {
|
if(this.regionLevel == "city"){
|
||||||
activeKey: "noise",
|
this.importFileCity(file);
|
||||||
};
|
}else {
|
||||||
|
this.importFileCounty(file);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
/* 导入本地excel文件 */
|
||||||
/* 导入本地excel文件 */
|
importFileCity(file) {
|
||||||
importFileCity(file) {
|
const hide = this.$message.loading("导入中..", 0);
|
||||||
const hide = this.$message.loading("导入中..", 0);
|
|
||||||
|
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
try {
|
try {
|
||||||
let data = new Uint8Array(e.target.result);
|
let data = new Uint8Array(e.target.result);
|
||||||
let workbook = XLSX.read(data, {
|
let workbook = XLSX.read(data, {
|
||||||
type: "array",
|
type: "array",
|
||||||
});
|
});
|
||||||
//0.昼间数据 1.夜间数据 2.其他信息
|
//0.昼间数据 1.夜间数据 2.其他信息
|
||||||
let sheetNames = workbook.SheetNames;
|
let sheetNames = workbook.SheetNames;
|
||||||
// 解析成二维数组
|
// 解析成二维数组
|
||||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||||
header: 1,
|
header: 1,
|
||||||
});
|
});
|
||||||
let aoa2 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[1]], {
|
let aoa2 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[1]], {
|
||||||
header: 1,
|
header: 1,
|
||||||
});
|
});
|
||||||
let aoa3 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[2]], {
|
let aoa3 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[2]], {
|
||||||
header: 1,
|
header: 1,
|
||||||
});
|
});
|
||||||
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
|
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
|
||||||
const reportDate2 = aoa2[1][0].replace(/[^\d]+/g, "-");
|
const reportDate2 = aoa2[1][0].replace(/[^\d]+/g, "-");
|
||||||
|
|
||||||
const roadNoiseList = aoa.filter(
|
const roadNoiseList = aoa.filter(
|
||||||
(item) => {
|
(item) => {
|
||||||
console.log(item.length)
|
console.log(item.length)
|
||||||
return item.length >= 21 && typeof item[0] == "number"
|
return item.length >= 21 && typeof item[0] == "number"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const roadNoiseList2 = aoa2.filter(
|
const roadNoiseList2 = aoa2.filter(
|
||||||
(item) => item.length >= 21 && typeof item[0] == "number"
|
(item) => item.length >= 21 && typeof item[0] == "number"
|
||||||
);
|
);
|
||||||
const roadNoiseList3 = aoa3.filter(
|
const roadNoiseList3 = aoa3.filter(
|
||||||
(item) => item.length >= 16 && typeof item[1] == "number"
|
(item) => item.length >= 16 && typeof item[1] == "number"
|
||||||
);
|
);
|
||||||
|
|
||||||
// 解析成对象数组
|
// 解析成对象数组
|
||||||
const billName = file.name;
|
const billName = file.name;
|
||||||
const billData = utils.toObjData(roadNoiseList);
|
const billData = utils.toObjData(roadNoiseList);
|
||||||
const billName2 = file.name;
|
const billName2 = file.name;
|
||||||
const billData2 = utils.toObjData(roadNoiseList2);
|
const billData2 = utils.toObjData(roadNoiseList2);
|
||||||
// 其他信息
|
// 其他信息
|
||||||
const billData3 = utils.toPlaceData(roadNoiseList3);
|
const billData3 = utils.toPlaceData(roadNoiseList3);
|
||||||
if (
|
if (
|
||||||
(!billData || billData.length == 0) &&
|
(!billData || billData.length == 0) &&
|
||||||
(!billData2 || billData2.length == 0)
|
(!billData2 || billData2.length == 0)
|
||||||
) {
|
) {
|
||||||
hide()
|
hide()
|
||||||
Modal.error({
|
Modal.error({
|
||||||
title: "导入失败",
|
title: "导入失败",
|
||||||
content: "找不到数据",
|
content: "找不到数据",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
if (billData.length > 0) {
|
if (billData.length > 0) {
|
||||||
billData.forEach((item) => {
|
billData.forEach((item) => {
|
||||||
Object.assign(
|
Object.assign(
|
||||||
item,
|
item,
|
||||||
billData3.find((b3Item) => b3Item.place == item.place)
|
billData3.find((b3Item) => b3Item.place == item.place)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
tasks.push(
|
tasks.push(
|
||||||
saveRoadNoiseBill({
|
saveRoadNoiseBill({
|
||||||
reportTime: new Date(reportDate).getTime(),
|
reportTime: new Date(reportDate).getTime(),
|
||||||
billName: billName,
|
billName: billName,
|
||||||
regionLevel: "市级",
|
regionLevel: "市级",
|
||||||
roadNoiseList: billData,
|
roadNoiseList: billData,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (billData2.length > 0) {
|
if (billData2.length > 0) {
|
||||||
billData.forEach((item) => {
|
billData.forEach((item) => {
|
||||||
Object.assign(
|
Object.assign(
|
||||||
item,
|
item,
|
||||||
billData3.find((b3Item) => b3Item.place == item.place)
|
billData3.find((b3Item) => b3Item.place == item.place)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
tasks.push(
|
tasks.push(
|
||||||
saveRoadNoiseBill({
|
saveRoadNoiseBill({
|
||||||
reportTime: new Date(reportDate2).getTime(),
|
reportTime: new Date(reportDate2).getTime(),
|
||||||
billName: billName2,
|
billName: billName2,
|
||||||
regionLevel: "市级",
|
regionLevel: "市级",
|
||||||
roadNoiseList: billData2,
|
roadNoiseList: billData2,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传到服务器
|
// 上传到服务器
|
||||||
|
|
||||||
Promise.all(tasks)
|
Promise.all(tasks)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
Modal.success({
|
Modal.success({
|
||||||
title: "导入成功",
|
title: "导入成功",
|
||||||
content: `成功导入${billData.length + billData2.length}条数据`,
|
content: `成功导入${billData.length + billData2.length}条数据`,
|
||||||
});
|
});
|
||||||
this.$refs.noise && this.$refs.noise.reload();
|
this.$refs.noise && this.$refs.noise.reload();
|
||||||
this.$refs.place && this.$refs.place.reload();
|
this.$refs.place && this.$refs.place.reload();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
Modal.error({
|
Modal.error({
|
||||||
title: "导入失败",
|
title: "导入失败",
|
||||||
content: "数据上传出错",
|
content: "数据上传出错",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
hide();
|
hide();
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
hide();
|
hide();
|
||||||
Modal.error({
|
Modal.error({
|
||||||
title: "导入失败",
|
title: "导入失败",
|
||||||
content: error.message,
|
content: error.message,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
// console.log(billData);
|
||||||
|
};
|
||||||
|
reader.readAsArrayBuffer(file);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
importFileCounty(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 roadNoiseList = aoa.filter(
|
||||||
|
(item) => {
|
||||||
|
return item.length >= 35 && item[0] && !item[0].toString().includes("行政区划代码")
|
||||||
|
// return item.length >= 35 && item[0] != "行政区划代码"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 解析成对象数组
|
||||||
|
const billName = file.name;
|
||||||
|
const billData = utils.toAreaObjData(roadNoiseList);
|
||||||
|
|
||||||
|
if (!billData || billData.length == 0) {
|
||||||
|
hide();
|
||||||
|
Modal.error({
|
||||||
|
title: "导入失败",
|
||||||
|
content: "找不到可用数据",
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (billData.length > 0) {
|
||||||
|
// 上传到服务器
|
||||||
|
saveRoadNoiseBill({
|
||||||
|
// reportTime: new Date(reportDate).getTime(),
|
||||||
|
billName: billName,
|
||||||
|
regionLevel: "县级",
|
||||||
|
roadNoiseList: 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: "数据上传出错",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// console.log(billData);
|
})
|
||||||
};
|
.catch(() => {
|
||||||
reader.readAsArrayBuffer(file);
|
Modal.error({
|
||||||
|
title: "导入失败",
|
||||||
return false;
|
content: "数据上传出错",
|
||||||
},
|
});
|
||||||
importFileArea(file) {
|
})
|
||||||
const hide = this.$message.loading("导入中..", 0);
|
.finally(() => {
|
||||||
|
hide();
|
||||||
let reader = new FileReader();
|
});
|
||||||
|
}
|
||||||
reader.onload = (e) => {
|
} catch (error) {
|
||||||
try {
|
hide();
|
||||||
let data = new Uint8Array(e.target.result);
|
Modal.error({
|
||||||
let workbook = XLSX.read(data, {
|
title: "导入失败",
|
||||||
type: "array",
|
content: error.message,
|
||||||
});
|
});
|
||||||
//0.昼间数据 1.夜间数据 2.其他信息
|
}
|
||||||
let sheetNames = workbook.SheetNames;
|
// console.log(billData);
|
||||||
// 解析成二维数组
|
};
|
||||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
reader.readAsArrayBuffer(file);
|
||||||
header: 1,
|
return false;
|
||||||
});
|
|
||||||
|
|
||||||
// const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
|
|
||||||
const roadNoiseList = aoa.filter(
|
|
||||||
(item) => {
|
|
||||||
return item.length >= 35 && item[0] && !item[0].toString().includes("行政区划代码")
|
|
||||||
// return item.length >= 35 && item[0] != "行政区划代码"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// 解析成对象数组
|
|
||||||
const billName = file.name;
|
|
||||||
const billData = utils.toAreaObjData(roadNoiseList);
|
|
||||||
|
|
||||||
if (!billData || billData.length == 0) {
|
|
||||||
hide();
|
|
||||||
Modal.error({
|
|
||||||
title: "导入失败",
|
|
||||||
content: "找不到可用数据",
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (billData.length > 0) {
|
|
||||||
// 上传到服务器
|
|
||||||
saveRoadNoiseBill({
|
|
||||||
// reportTime: new Date(reportDate).getTime(),
|
|
||||||
billName: billName,
|
|
||||||
regionLevel: "县级",
|
|
||||||
roadNoiseList: 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>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,31 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="ele-body">
|
<div class="ele-body">
|
||||||
<a-card style="width: 100%" :bordered="false">
|
<a-card style="width: 100%" :bordered="false">
|
||||||
<template #title>
|
<template #title>
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-upload
|
<a-select
|
||||||
:before-upload="importFileCity"
|
ref="select"
|
||||||
:showUploadList="false"
|
v-model:value="regionLevel"
|
||||||
accept=".xls,.xlsx,.csv"
|
style="width: 120px"
|
||||||
>
|
>
|
||||||
<a-button>市级导入</a-button>
|
<a-select-option value="city">市</a-select-option>
|
||||||
</a-upload>
|
<a-select-option value="county">县</a-select-option>
|
||||||
<a-upload
|
</a-select>
|
||||||
:before-upload="importFileArea"
|
<a-upload
|
||||||
:showUploadList="false"
|
:before-upload="importFile"
|
||||||
accept=".xls,.xlsx,.csv"
|
:showUploadList="false"
|
||||||
>
|
accept=".xls,.xlsx,.csv"
|
||||||
<a-button>县级导入</a-button>
|
>
|
||||||
</a-upload>
|
<a-button type="primary">数据导入</a-button>
|
||||||
</a-space>
|
</a-upload>
|
||||||
</template>
|
<a-button @click="download">模板下载</a-button>
|
||||||
<a-tabs v-model:activeKey="activeKey">
|
</a-space>
|
||||||
<a-tab-pane tab="噪声信息" key="noise">
|
</template>
|
||||||
<noise-bill ref="noise"></noise-bill>
|
<a-tabs v-model:activeKey="activeKey">
|
||||||
</a-tab-pane>
|
<a-tab-pane tab="噪声信息" key="noise">
|
||||||
</a-tabs>
|
<noise-bill ref="noise"></noise-bill>
|
||||||
</a-card>
|
</a-tab-pane>
|
||||||
</div>
|
</a-tabs>
|
||||||
|
</a-card>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -34,213 +36,233 @@ import utils from "./utils";
|
|||||||
import {Modal} from "ant-design-vue";
|
import {Modal} from "ant-design-vue";
|
||||||
import NoiseBill from "./noise-bill.vue";
|
import NoiseBill from "./noise-bill.vue";
|
||||||
import {saveZoneNoiseBill} from "@/api/ecology/noise/zone-sound";
|
import {saveZoneNoiseBill} from "@/api/ecology/noise/zone-sound";
|
||||||
|
import {downloadTemplate} from "@/utils/excel-util";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ZoneCollectIndex",
|
name: "ZoneCollectIndex",
|
||||||
components: {
|
components: {
|
||||||
NoiseBill,
|
NoiseBill,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
activeKey: "noise",
|
||||||
|
regionLevel: "city"
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
download() {
|
||||||
|
let filename = "区域噪声-"
|
||||||
|
if (this.regionLevel == "city") {
|
||||||
|
filename += "市"
|
||||||
|
} else if (this.regionLevel == "county") {
|
||||||
|
filename += "县"
|
||||||
|
} else {
|
||||||
|
filename += "站点"
|
||||||
|
}
|
||||||
|
downloadTemplate(filename)
|
||||||
},
|
},
|
||||||
data() {
|
importFile(file) {
|
||||||
return {
|
if (this.regionLevel == "city") {
|
||||||
activeKey: "noise",
|
this.importFileCity(file);
|
||||||
};
|
} else {
|
||||||
|
this.importFileCounty(file);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
/* 导入本地excel文件 */
|
||||||
/* 导入本地excel文件 */
|
importFileCity(file) {
|
||||||
importFileCity(file) {
|
const hide = this.$message.loading("导入中..", 0);
|
||||||
const hide = this.$message.loading("导入中..", 0);
|
|
||||||
|
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
try {
|
try {
|
||||||
let data = new Uint8Array(e.target.result);
|
let data = new Uint8Array(e.target.result);
|
||||||
let workbook = XLSX.read(data, {
|
let workbook = XLSX.read(data, {
|
||||||
type: "array",
|
type: "array",
|
||||||
});
|
});
|
||||||
//0.昼间数据 1.夜间数据 2.其他信息
|
//0.昼间数据 1.夜间数据 2.其他信息
|
||||||
let sheetNames = workbook.SheetNames;
|
let sheetNames = workbook.SheetNames;
|
||||||
// 解析成二维数组
|
// 解析成二维数组
|
||||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||||
header: 1,
|
header: 1,
|
||||||
});
|
});
|
||||||
let aoa2 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[1]], {
|
let aoa2 = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[1]], {
|
||||||
header: 1,
|
header: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
|
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
|
||||||
const reportDate2 = aoa2[1][0].replace(/[^\d]+/g, "-");
|
const reportDate2 = aoa2[1][0].replace(/[^\d]+/g, "-");
|
||||||
|
|
||||||
const zoneNoiseList = aoa.filter(
|
const zoneNoiseList = aoa.filter(
|
||||||
(item) => {
|
(item) => {
|
||||||
return item.length >= 26 && typeof item[0] == "number"
|
return item.length >= 26 && typeof item[0] == "number"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const zoneNoiseList2 = aoa2.filter(
|
const zoneNoiseList2 = aoa2.filter(
|
||||||
(item) => item.length >= 26 && typeof item[0] == "number"
|
(item) => item.length >= 26 && typeof item[0] == "number"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// 解析成对象数组
|
// 解析成对象数组
|
||||||
const billName = file.name;
|
const billName = file.name;
|
||||||
const billData = utils.toObjData(zoneNoiseList);
|
const billData = utils.toObjData(zoneNoiseList);
|
||||||
const billName2 = file.name;
|
const billName2 = file.name;
|
||||||
const billData2 = utils.toObjData(zoneNoiseList2);
|
const billData2 = utils.toObjData(zoneNoiseList2);
|
||||||
if (
|
if (
|
||||||
(!billData || billData.length == 0) &&
|
(!billData || billData.length == 0) &&
|
||||||
(!billData2 || billData2.length == 0)
|
(!billData2 || billData2.length == 0)
|
||||||
) {
|
) {
|
||||||
hide()
|
hide()
|
||||||
Modal.error({
|
Modal.error({
|
||||||
title: "导入失败",
|
title: "导入失败",
|
||||||
content: "找不到数据",
|
content: "找不到数据",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
if (billData.length > 0) {
|
if (billData.length > 0) {
|
||||||
tasks.push(
|
tasks.push(
|
||||||
saveZoneNoiseBill({
|
saveZoneNoiseBill({
|
||||||
reportTime: new Date(reportDate).getTime(),
|
reportTime: new Date(reportDate).getTime(),
|
||||||
billName: billName,
|
billName: billName,
|
||||||
regionLevel: "市级",
|
regionLevel: "市级",
|
||||||
zoneNoiseList: billData,
|
zoneNoiseList: billData,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (billData2.length > 0) {
|
if (billData2.length > 0) {
|
||||||
tasks.push(
|
tasks.push(
|
||||||
saveZoneNoiseBill({
|
saveZoneNoiseBill({
|
||||||
reportTime: new Date(reportDate2).getTime(),
|
reportTime: new Date(reportDate2).getTime(),
|
||||||
billName: billName2,
|
billName: billName2,
|
||||||
regionLevel: "市级",
|
regionLevel: "市级",
|
||||||
zoneNoiseList: billData2,
|
zoneNoiseList: billData2,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传到服务器
|
// 上传到服务器
|
||||||
|
|
||||||
Promise.all(tasks)
|
Promise.all(tasks)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
Modal.success({
|
Modal.success({
|
||||||
title: "导入成功",
|
title: "导入成功",
|
||||||
content: `成功导入${billData.length + billData2.length}条数据`,
|
content: `成功导入${billData.length + billData2.length}条数据`,
|
||||||
});
|
});
|
||||||
this.$refs.noise && this.$refs.noise.reload();
|
this.$refs.noise && this.$refs.noise.reload();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
Modal.error({
|
Modal.error({
|
||||||
title: "导入失败",
|
title: "导入失败",
|
||||||
content: "数据上传出错",
|
content: "数据上传出错",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
hide();
|
hide();
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
hide();
|
hide();
|
||||||
Modal.error({
|
Modal.error({
|
||||||
title: "导入失败",
|
title: "导入失败",
|
||||||
content: error.message,
|
content: error.message,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
// console.log(billData);
|
||||||
|
};
|
||||||
|
reader.readAsArrayBuffer(file);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
importFileCounty(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 >= 28 && item[0] && !item[0].toString().includes("行政区划代码")
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 解析成对象数组
|
||||||
|
const billName = file.name;
|
||||||
|
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: "数据上传出错",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// console.log(billData);
|
})
|
||||||
};
|
.catch(() => {
|
||||||
reader.readAsArrayBuffer(file);
|
Modal.error({
|
||||||
|
title: "导入失败",
|
||||||
return false;
|
content: "数据上传出错",
|
||||||
},
|
});
|
||||||
importFileArea(file) {
|
})
|
||||||
const hide = this.$message.loading("导入中..", 0);
|
.finally(() => {
|
||||||
|
hide();
|
||||||
let reader = new FileReader();
|
});
|
||||||
|
}
|
||||||
reader.onload = (e) => {
|
} catch (error) {
|
||||||
try {
|
hide();
|
||||||
let data = new Uint8Array(e.target.result);
|
Modal.error({
|
||||||
let workbook = XLSX.read(data, {
|
title: "导入失败",
|
||||||
type: "array",
|
content: error.message,
|
||||||
});
|
});
|
||||||
//0.昼间数据 1.夜间数据 2.其他信息
|
}
|
||||||
let sheetNames = workbook.SheetNames;
|
// console.log(billData);
|
||||||
// 解析成二维数组
|
};
|
||||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
reader.readAsArrayBuffer(file);
|
||||||
header: 1,
|
return false;
|
||||||
});
|
|
||||||
|
|
||||||
const reportDate = aoa[1][0].replace(/[^\d]+/g, "-");
|
|
||||||
const zoneNoiseList = aoa.filter(
|
|
||||||
(item) => {
|
|
||||||
|
|
||||||
return item.length >= 28 && item[0] && !item[0].toString().includes("行政区划代码")
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// 解析成对象数组
|
|
||||||
const billName = file.name;
|
|
||||||
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>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user