diff --git a/src/api/ecology/air.js b/src/api/ecology/air.js index 8625957..543ea6c 100644 --- a/src/api/ecology/air.js +++ b/src/api/ecology/air.js @@ -66,6 +66,15 @@ const statisticUrl = "/ambientAir/ambientAir/statistic"; //城区统计 const statisticAreaBase = "/ambientAir/ambientAir/statistic/areaBase"; const statisticArea = "/ambientAir/ambientAir/statistic/area"; + +// 排行 +const airDayRankUrl = "/zhenQiWang/ambientAirZhenqiCityDayAqiRankData"; +const airMonthRankUrl = "/zhenQiWang/ambientAirZhenqiCityMonthComprehensiveAqiRankData/page"; +const airMonthProvincialCapitalRankUrl = "/zhenQiWang/ambientAirZhenqiCityMonthComprehensiveAqiRankData/listProvincialCapitalRank"; +const airYearRankUrl = "/zhenQiWang/ambientAirZhenqiCityYearComprehensiveAqiRankData/page"; +const airYearProvincialCapitalRankUrl = "/zhenQiWang/ambientAirZhenqiCityYearComprehensiveAqiRankData/listProvincialCapitalRank"; +const airPm25YearRankUrl = "/zhenQiWang/ambientAirZhenqiCityYearPm25RankData/page"; +const airPm25YearProvincialCapitalRankUrl = "/zhenQiWang/ambientAirZhenqiCityYearPm25RankData/listProvincialCapitalRank"; export { pageBillUrl, saveAirBill, @@ -84,6 +93,13 @@ export { statisticAvg, statisticUrl, statisticAreaBase, - statisticArea + statisticArea, + airDayRankUrl, + airMonthRankUrl, + airYearRankUrl, + airPm25YearRankUrl, + airYearProvincialCapitalRankUrl, + airPm25YearProvincialCapitalRankUrl, + airMonthProvincialCapitalRankUrl } diff --git a/src/views/atmosphere/acid-rain/collect/index.vue b/src/views/atmosphere/acid-rain/collect/index.vue index 05f330a..e18d814 100644 --- a/src/views/atmosphere/acid-rain/collect/index.vue +++ b/src/views/atmosphere/acid-rain/collect/index.vue @@ -41,89 +41,89 @@ export default { }, methods: { /* 导入本地excel文件 */ - importFileCity(file) { + async importFileCity(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 reportDate = aoa[2][0].replace(/[^\d]+/g, "-"); - - const acidList = aoa.filter((item) => { - return item.length >= 16 && item[0] && !item[0].includes("编号"); - }); - // 解析成对象数组 - const billName = aoa[0][0] + aoa[1][0]; - const billData = utils.toObjData(acidList, new Date(reportDate).getFullYear()); - - if ( - !billData || - billData.length == 0 - // (!billData2 || billData2.length == 0) - ) { - hide(); - Modal.error({ - title: "导入失败", - content: "找不到数据", - }); - return; - } - - const tasks = []; - if (billData.length > 0) { - tasks.push( - saveAcidRainBill({ - // reportTime: new Date(reportDate).getTime(), - billName: billName, - regionLevel: "市级", - acidRainList: billData, - }) - ); - } - - // 上传到服务器 - Promise.all(tasks) - .then((res) => { - if (res[0].data.code == 0) { - Modal.success({ - title: "导入成功", - content: `成功导入${billData.length}条数据`, - }); - this.$refs.rain && this.$refs.rain.reload(); - } else { - Modal.error({ - title: "导入失败", - content: "数据上传出错", - }); - } - }) - .catch(() => { - Modal.error({ - title: "导入失败", - content: "数据上传出错", - }); - }) - .finally(() => { - hide(); + reader.onload = async (e) => { + try { + let data = new Uint8Array(e.target.result); + let workbook = XLSX.read(data, { + type: "array", }); - } catch (error) { - hide(); - Modal.error({ - title: "导入失败", - content: error.message, - }); - } - // console.log(billData); + 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 acidList = aoa.filter((item) => { + return item.length >= 16 && item[0] && !item[0].includes("编号"); + }); + // 解析成对象数组 + const billName = aoa[0][0] + aoa[1][0]; + const billData = await utils.toObjData(acidList, new Date(reportDate).getFullYear()); + + if ( + !billData || + billData.length == 0 + // (!billData2 || billData2.length == 0) + ) { + hide(); + Modal.error({ + title: "导入失败", + content: "找不到数据", + }); + return; + } + + const tasks = []; + if (billData.length > 0) { + tasks.push( + saveAcidRainBill({ + // reportTime: new Date(reportDate).getTime(), + billName: billName, + regionLevel: "市级", + acidRainList: billData, + }) + ); + } + + // 上传到服务器 + Promise.all(tasks) + .then((res) => { + if (res[0].data.code == 0) { + Modal.success({ + title: "导入成功", + content: `成功导入${billData.length}条数据`, + }); + this.$refs.rain && this.$refs.rain.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); diff --git a/src/views/atmosphere/acid-rain/collect/utils.js b/src/views/atmosphere/acid-rain/collect/utils.js index 3847089..7da0b86 100644 --- a/src/views/atmosphere/acid-rain/collect/utils.js +++ b/src/views/atmosphere/acid-rain/collect/utils.js @@ -1,6 +1,13 @@ -import moment from "moment"; +import moment from "moment" +import axios from "axios"; +import {listAllUrl} from "@/api/ecology/atmosphere/acid-rain-plcae" export default { - toObjData(excelData,monitorYear) { + async toObjData(excelData,monitorYear) { + const res = await axios.get(listAllUrl,{params:{year:monitorYear}}) + if(res.data.code !=0){ + return Promise.reject(monitorYear +"点位字典未设置"); + } + const dict = res.data.data; return excelData.map(item => { const monitorTime = moment(monitorYear + "."+item[1],"Y.M.D"); const monitorStartTime = moment(`${monitorYear}.${item[2]}.${item[3]} ${item[4]}:${item[5]}`,"Y.M.D H:m"); @@ -8,6 +15,7 @@ export default { console.log(item); const row = { city: "南宁市", + place: dict.find(p=>p.placeCode = item[0].split("~")[0]).place, code: item[0], precipitationType:item[10], precipitation:item[11], diff --git a/src/views/atmosphere/acid-rain/dict/place.vue b/src/views/atmosphere/acid-rain/dict/place.vue index 4bbe631..71ace84 100644 --- a/src/views/atmosphere/acid-rain/dict/place.vue +++ b/src/views/atmosphere/acid-rain/dict/place.vue @@ -44,13 +44,13 @@ :wrapper-col="{ md: { span: 18 }, sm: { span: 24 } }" > - + - + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -120,13 +90,13 @@