添加行政区划代码,行政区划等级

This commit is contained in:
weicw
2021-08-23 09:53:17 +08:00
parent bb7618242d
commit a409946a08
4 changed files with 187 additions and 11 deletions

View File

@@ -22,8 +22,9 @@ export default {
indexL10: item[10], indexL10: item[10],
indexL50: item[11], indexL50: item[11],
indexL90: item[12], indexL90: item[12],
indexLmin: item[13], indexLmax: item[13],
indexLmax: item[14], indexLmin: item[14],
} }
}) })

View File

@@ -4,11 +4,18 @@
<template #title> <template #title>
<a-space> <a-space>
<a-upload <a-upload
:before-upload="importFile" :before-upload="importFileCity"
:showUploadList="false" :showUploadList="false"
accept=".xls,.xlsx,.csv" accept=".xls,.xlsx,.csv"
> >
<a-button>导入excel</a-button> <a-button>市级导入</a-button>
</a-upload>
<a-upload
:before-upload="importFileArea"
:showUploadList="false"
accept=".xls,.xlsx,.csv"
>
<a-button>县级导入</a-button>
</a-upload> </a-upload>
</a-space> </a-space>
</template> </template>
@@ -39,7 +46,7 @@ export default {
}, },
methods: { methods: {
/* 导入本地excel文件 */ /* 导入本地excel文件 */
importFile(file) { importFileCity(file) {
const hide = this.$message.loading("导入中..", 0); const hide = this.$message.loading("导入中..", 0);
let reader = new FileReader(); let reader = new FileReader();
@@ -85,6 +92,7 @@ export default {
(!billData || billData.length == 0) && (!billData || billData.length == 0) &&
(!billData2 || billData2.length == 0) (!billData2 || billData2.length == 0)
) { ) {
hide()
Modal.error({ Modal.error({
title: "导入失败", title: "导入失败",
content: "找不到数据", content: "找不到数据",
@@ -104,6 +112,7 @@ export default {
saveRoadNoiseBill({ saveRoadNoiseBill({
reportTime: new Date(reportDate).getTime(), reportTime: new Date(reportDate).getTime(),
billName: billName, billName: billName,
regionLevel: "市级",
roadNoiseList: billData, roadNoiseList: billData,
}) })
); );
@@ -120,6 +129,7 @@ export default {
saveRoadNoiseBill({ saveRoadNoiseBill({
reportTime: new Date(reportDate2).getTime(), reportTime: new Date(reportDate2).getTime(),
billName: billName2, billName: billName2,
regionLevel: "市级",
roadNoiseList: billData2, roadNoiseList: billData2,
}) })
); );
@@ -130,7 +140,8 @@ export default {
Promise.all(tasks) Promise.all(tasks)
.then(() => { .then(() => {
Modal.success({ Modal.success({
title: "导入成功" title: "导入成功",
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();
@@ -145,7 +156,7 @@ export default {
hide(); hide();
}); });
} catch (error) { } catch (error) {
hide() hide();
Modal.error({ Modal.error({
title: "导入失败", title: "导入失败",
content: "表格格式有误,请检查后重新上传!", content: "表格格式有误,请检查后重新上传!",
@@ -157,6 +168,92 @@ export default {
return false; 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 roadNoiseList = aoa.filter(
(item) => {
return item.length >= 35 && item[0] != "行政区划代码"
}
);
// 解析成对象数组
const billName = aoa[0][0];
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: "表格格式有误,请检查后重新上传!",
});
}
// console.log(billData);
};
reader.readAsArrayBuffer(file);
return false;
},
}, },
}; };
</script> </script>

View File

@@ -137,6 +137,12 @@
customRender: 'billName', customRender: 'billName',
}, },
},
{
title: '行政等级',
dataIndex: 'regionLevel',
sorter: true,
}, },
{ {
title: '条目', title: '条目',

View File

@@ -8,11 +8,12 @@ export default {
monitorTime.setHours(item[12]); monitorTime.setHours(item[12]);
monitorTime.setMinutes(item[13]); monitorTime.setMinutes(item[13]);
let quarter = 1; let quarter = 1;
if ((item[10] - 1) < 4) { const month = item[10]
if (month < 4) {
quarter = 1 quarter = 1
} else if ((item[10] - 1) < 7) { } else if (month < 7) {
quarter = 2 quarter = 2
} else if ((item[10] - 1) < 10) { } else if (month < 10) {
quarter = 3 quarter = 3
} else{ } else{
quarter = 4 quarter = 4
@@ -24,6 +25,7 @@ export default {
road: item[3], road: item[3],
area: item[4], area: item[4],
city: '南宁', city: '南宁',
regionLevel: "市级",
roadLength: item[5], roadLength: item[5],
roadWidth: item[6], roadWidth: item[6],
smallTrafficFlow: item[7], smallTrafficFlow: item[7],
@@ -70,5 +72,75 @@ export default {
} }
}) })
},
// 解析县级数据
toAreaObjData(excelData){
return excelData.map(item => {
const monitorTime = new Date();
monitorTime.setFullYear(item[1]);
monitorTime.setMonth(item[14]-1);
monitorTime.setDate(item[15]);
monitorTime.setHours(item[16]);
monitorTime.setMinutes(item[17]);
let quarter = 1;
const month = item[14]
if (month < 4) {
quarter = 1
} else if (month < 7) {
quarter = 2
} else if (month < 10) {
quarter = 3
} else{
quarter = 4
}
let timeSlot = "夜";
if(item[16]>=6&&item[16]<=22){
timeSlot = "昼"
}
return {
regionCode:item[0],
regionLevel: "县级",
monitorYear: item[1],
placeCode: item[2],
place: item[3],
placeLng: item[4],
placeLat: item[5],
road: item[6],
roadLength: item[7],
roadWidth: item[8],
motorway: item[9],
motorwayType: item[10],
motorwayLevel: item[11],
refObj: item[12],
people: item[13],
monitorMonth: item[14],
monitorDay: item[15],
monitorHour: item[16],
monitorMinute: item[17],
smallTrafficFlow: item[18],
largeTrafficFlow: item[19],
indexLeq: item[20],
indexL10: item[21],
indexL50: item[22],
indexL90: item[23],
indexLmax: item[24],
indexLmin: item[25],
indexSd: item[26],
station: item[27],
monitorInstrumentModel: item[28],
monitorInstrumentCode: item[29],
beforeMonitorValue: item[30],
afterMonitorValue: item[31],
soundPressureValue: item[32],
soundInstrumentModel: item[33],
soundInstrumentCode: item[34],
remark: item[35],
city: '南宁',
timeSlot,
monitorTime: monitorTime.getTime(),
quarter
}
})
} }
} }