添加行政区划代码,行政区划等级
This commit is contained in:
@@ -22,8 +22,9 @@ export default {
|
||||
indexL10: item[10],
|
||||
indexL50: item[11],
|
||||
indexL90: item[12],
|
||||
indexLmin: item[13],
|
||||
indexLmax: item[14],
|
||||
indexLmax: item[13],
|
||||
indexLmin: item[14],
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -4,11 +4,18 @@
|
||||
<template #title>
|
||||
<a-space>
|
||||
<a-upload
|
||||
:before-upload="importFile"
|
||||
:before-upload="importFileCity"
|
||||
:showUploadList="false"
|
||||
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-space>
|
||||
</template>
|
||||
@@ -39,7 +46,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
/* 导入本地excel文件 */
|
||||
importFile(file) {
|
||||
importFileCity(file) {
|
||||
const hide = this.$message.loading("导入中..", 0);
|
||||
|
||||
let reader = new FileReader();
|
||||
@@ -85,6 +92,7 @@ export default {
|
||||
(!billData || billData.length == 0) &&
|
||||
(!billData2 || billData2.length == 0)
|
||||
) {
|
||||
hide()
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "找不到数据",
|
||||
@@ -104,6 +112,7 @@ export default {
|
||||
saveRoadNoiseBill({
|
||||
reportTime: new Date(reportDate).getTime(),
|
||||
billName: billName,
|
||||
regionLevel: "市级",
|
||||
roadNoiseList: billData,
|
||||
})
|
||||
);
|
||||
@@ -120,6 +129,7 @@ export default {
|
||||
saveRoadNoiseBill({
|
||||
reportTime: new Date(reportDate2).getTime(),
|
||||
billName: billName2,
|
||||
regionLevel: "市级",
|
||||
roadNoiseList: billData2,
|
||||
})
|
||||
);
|
||||
@@ -129,8 +139,9 @@ export default {
|
||||
|
||||
Promise.all(tasks)
|
||||
.then(() => {
|
||||
Modal.success({
|
||||
title: "导入成功"
|
||||
Modal.success({
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData.length + billData2.length}条数据`,
|
||||
});
|
||||
this.$refs.noise && this.$refs.noise.reload();
|
||||
this.$refs.place && this.$refs.place.reload();
|
||||
@@ -145,7 +156,7 @@ export default {
|
||||
hide();
|
||||
});
|
||||
} catch (error) {
|
||||
hide()
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "表格格式有误,请检查后重新上传!",
|
||||
@@ -157,6 +168,92 @@ 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 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>
|
||||
|
||||
@@ -137,6 +137,12 @@
|
||||
customRender: 'billName',
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
title: '行政等级',
|
||||
dataIndex: 'regionLevel',
|
||||
sorter: true,
|
||||
|
||||
},
|
||||
{
|
||||
title: '条目',
|
||||
|
||||
@@ -8,11 +8,12 @@ export default {
|
||||
monitorTime.setHours(item[12]);
|
||||
monitorTime.setMinutes(item[13]);
|
||||
let quarter = 1;
|
||||
if ((item[10] - 1) < 4) {
|
||||
const month = item[10]
|
||||
if (month < 4) {
|
||||
quarter = 1
|
||||
} else if ((item[10] - 1) < 7) {
|
||||
} else if (month < 7) {
|
||||
quarter = 2
|
||||
} else if ((item[10] - 1) < 10) {
|
||||
} else if (month < 10) {
|
||||
quarter = 3
|
||||
} else{
|
||||
quarter = 4
|
||||
@@ -24,6 +25,7 @@ export default {
|
||||
road: item[3],
|
||||
area: item[4],
|
||||
city: '南宁',
|
||||
regionLevel: "市级",
|
||||
roadLength: item[5],
|
||||
roadWidth: item[6],
|
||||
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
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user