From d1ccf7e1835b3c583da16d90a286e749d5e27c84 Mon Sep 17 00:00:00 2001 From: zmc <zmc_li@foxmail.com> Date: 星期四, 07 十二月 2023 14:15:20 +0800 Subject: [PATCH] 修改无数据时段的算法 --- src/views/risk_assessment/riskModel/components/CompDailyStatistic.vue | 40 +++++----- src/api/exceptionApi.js | 12 +- src/utils/time.js | 34 +++++++- src/views/risk_assessment/components/CompDataRiskModel.vue | 65 +++++----------- src/views/data_management/HistoryData.vue | 4 src/utils/chartFunction/lineChart.js | 36 --------- src/views/exception/components/CompFlightInspection.vue | 1 7 files changed, 75 insertions(+), 117 deletions(-) diff --git a/src/api/exceptionApi.js b/src/api/exceptionApi.js index 18133e5..37dcea9 100644 --- a/src/api/exceptionApi.js +++ b/src/api/exceptionApi.js @@ -16,7 +16,11 @@ endTime: endTime, type:type } - }) + }).then(res=>{ return res.data.data.sort((a,b)=>{ + const dateA = new Date(a.lst) + const dateB = new Date(b.lst) + return dateA - dateB + })}) }, // 鏍规嵁鏈堜唤鍜岀被鍨嬫煡鎵惧垎鏋愭暟鎹� @@ -39,12 +43,6 @@ } }) }, - - - - - - /** * diff --git a/src/utils/chartFunction/lineChart.js b/src/utils/chartFunction/lineChart.js index e43ead8..1c4bc2e 100644 --- a/src/utils/chartFunction/lineChart.js +++ b/src/utils/chartFunction/lineChart.js @@ -79,42 +79,6 @@ }, /** - * 杩斿洖鏃犳暟鎹殑鏃堕棿娈� - * @param锛� - * @returns锛� - */ - backNoDataInteval(dataBeginTime, dataEndTime) { - const result = [] - // 鏁版嵁寮�濮嬫椂闂� - const start = dayjs(dataBeginTime) - // 鏁版嵁缁撴潫鏃堕棿 - const end = dayjs(dataEndTime) - // 璇ユ湀鐨�1鍙� - const monthStart = start.startOf('month') - // 璇ユ湀鏈�鍚庝竴澶� - const monthEnd = start.endOf('month') - - // 鏁版嵁璧峰涓嶇瓑浜庢湀鍒� 涓� 鏁版嵁缁撴潫涓嶇瓑浜庢湀鏈� - if (!start.isSame(monthStart, 'day') && !end.isSame(monthEnd, 'day')) { - result.push([monthStart.format('YYYY-MM-DD'), start.format('YYYY-MM-DD')]) - result.push([end.format('YYYY-MM-DD'), monthEnd.format('YYYY-MM-DD')]) - } - - // 鏁版嵁璧峰绛変簬鏈堝垵 涓� 鏁版嵁缁撴潫涓嶇瓑浜庢湀鏈� - if (start.isSame(monthStart, 'day') && !end.isSame(monthEnd, 'day')) { - result.push([end.format('YYYY-MM-DD'), monthEnd.format('YYYY-MM-DD')]) - } - - // 鏁版嵁璧峰涓嶇瓑浜庢湀鍒� 涓� 鏁版嵁缁撴潫绛変簬鏈堟湯 - if (!start.isSame(monthStart, 'day') && end.isSame(monthEnd, 'day')) { - result.push([monthStart.format('YYYY-MM-DD'), start.format('YYYY-MM-DD')]) - } - - // 鏁版嵁璧峰绛変簬鏈堝垵 涓� 鏁版嵁缁撴潫绛変簬鏈堟湯 (杩欑鎯呭喌娌℃湁绌烘暟鎹殑鏃堕棿闂撮殧) - return result - }, - - /** * 缁勬垚鏃犳暟鎹尯鍩� * @param锛� 2缁存暟缁� * @returns锛� diff --git a/src/utils/time.js b/src/utils/time.js index 7a42a2b..738e1d9 100644 --- a/src/utils/time.js +++ b/src/utils/time.js @@ -145,13 +145,35 @@ }, /** - * 鏍规嵁瀵硅薄鏁扮粍涓璴st瀛楁鎸夊崌搴忔帓鍒� - * @param锛� + * 鎵惧埌鍦ㄧ粰瀹氱殑寮�濮嬫椂闂碽t鍜岀粨鏉熸椂闂磂t涔嬮棿缂哄け鐨勬椂闂村尯闂� + * @param锛氬紑濮嬫椂闂达紝缁撴潫鏃堕棿锛屽湪杩欎釜鏃堕棿鑼冨洿鍐呭凡鏈夌殑鏃堕棿锛堟椂闂村瓧绗︿覆鏁扮粍锛� * @returns锛� */ - compareByScore(a, b) { - const dateA = new Date(a.lst) - const dateB = new Date(b.lst) - return dateA - dateB + getMissingDays(bt, et, timeArr) { + // 瀛樺偍缂哄け鐨勬椂闂村尯闂� + const r = [] + const begin = dayjs(bt) + const end = dayjs(et) + // 寮�濮嬫椂闂� + let current = begin + + for (const time of timeArr) { + const currentTime = dayjs(time) + if (currentTime.isBefore(current)) { + continue + } + + if (currentTime.isAfter(current)) { + r.push([current.format('YYYY-MM-DD'), currentTime.format('YYYY-MM-DD')]) + } + + current = currentTime.add(1, 'day') + } + + if (end.isAfter(current)) { + r.push([current.format('YYYY-MM-DD'), end.format('YYYY-MM-DD')]) + } + + return r } } diff --git a/src/views/data_management/HistoryData.vue b/src/views/data_management/HistoryData.vue index 9679a7f..df6f031 100644 --- a/src/views/data_management/HistoryData.vue +++ b/src/views/data_management/HistoryData.vue @@ -194,14 +194,14 @@ // 淇濆瓨杩斿洖鐨� this.tableData = response.data.data.rows; this.displayData = this.tableData; - + this.loading = false; if (response.data.data.total == 0) { ElMessage('璇ユ椂娈垫棤鏁版嵁'); this.isNoData = true; return; } this.total = response.data.data.total; - this.loading = false; + }); } } diff --git a/src/views/exception/components/CompFlightInspection.vue b/src/views/exception/components/CompFlightInspection.vue index b2dbd4f..c327a46 100644 --- a/src/views/exception/components/CompFlightInspection.vue +++ b/src/views/exception/components/CompFlightInspection.vue @@ -923,7 +923,6 @@ params['beginTime'] = this.beginTime params['endTime'] = this.endTime - console.log('name',this.siteName) this.$http.get('/dust/exceptiondata', { params: params }).then((response) => { // 淇濆瓨杩斿洖鐨� // this.tableData = response.data.data.rows; diff --git a/src/views/risk_assessment/components/CompDataRiskModel.vue b/src/views/risk_assessment/components/CompDataRiskModel.vue index 5a8cdaf..d30dcb1 100644 --- a/src/views/risk_assessment/components/CompDataRiskModel.vue +++ b/src/views/risk_assessment/components/CompDataRiskModel.vue @@ -3,17 +3,13 @@ import InputSearch from '@/sfc/InputSearch.vue' import AreaAndmonitorType from '@/sfc/AreaAndmonitorType.vue' import exceptionApi from '@/api/exceptionApi.js' - import DustRadarChart from '@/views/risk_assessment/components/DustRadarChart.vue' -import FYLineChart from '@/components/chart/FYLineChart.vue' -import time from '@/utils/time.js' import index from '@/utils/risk_estimate_common_function/index.js' import ButtonClick from '@/sfc/ButtonClick.vue' import dayjs from 'dayjs' import MonthSelect from '@/sfc/MonthSelect.vue' import riskApi from '@/api/risk/riskApi.js' import riskValue from '@/utils/risk_estimate_common_function/riskValue.js' -import lineChart from '@/utils/chartFunction/lineChart.js' import siteInfo from '@/api/site/siteInfo.js' import CompDailyStatistic from '@/views/risk_assessment/riskModel/components/CompDailyStatistic.vue' export default { @@ -35,7 +31,6 @@ } }, components: { - FYLineChart, InputSearch, AreaAndmonitorType, DustRadarChart, @@ -59,9 +54,9 @@ form: { // 绔欑偣鍚嶇О - name: '', + siteName: '', // 璁惧缂栧彿 - number: '3234', + mnCode: '3234', // 寮�濮嬫椂闂� beginTime: '', // 缁撴潫鏃堕棿 @@ -119,29 +114,20 @@ } }, watch: { - // showAll() { - // console.log('1111') - // // 椤甸潰鍔犺浇鏃秙howAll鎵嶄細鍙樺寲涓�娆� - // // 涓簍rue琛ㄧず鐨勯闄╂ā鍨嬮〉闈� - // if (this.showAll) { - // // 鍔犺浇椋庨櫓鍊兼渶楂樼殑绔欑偣鏁版嵁 - // this.ShowDefaultData() - // } - // }, siteName() { if (this.siteName != '') { // 鏇存柊绔欑偣鍚嶅瓧鍜屾椂闂� - this.form.name = this.siteName + this.form.siteName = this.siteName this.screenLoading = true siteInfo.queryMnCode(this.siteName).then((response) => { - this.form.number = response.data.data[0].mnCode + this.form.mnCode = response.data.data[0].mnCode this.month = this.time // 鍚屾椂鏇存柊鏈堣捣濮嬫椂闂� this.form.beginTime = dayjs(this.month).startOf().format('YYYY-MM-DD HH:mm:ss') this.form.endTime = dayjs(this.month).endOf('month').format('YYYY-MM-DD HH:mm:ss') // 鏇存柊璇ョ珯鐐圭殑鎵�灞炲満鏅拰杩愮淮鍟� - this.getSiteInfo(this.form.number) + this.getSiteInfo(this.form.mnCode) // 鏇存柊缁熻鏁版嵁 this.getAnalysisData() // 璁$畻椋庨櫓鍊� @@ -167,7 +153,7 @@ methods: { // 鏌ヨ绔欑偣缁熻淇℃伅 async querySiteStaticsInfo(row) { - this.form.name = row.siteName + this.form.siteName = row.siteName // 鏇存柊缁熻鏁版嵁 await this.getAnalysisData() // 璁$畻椋庨櫓鍊� @@ -192,7 +178,7 @@ // 鏇存柊鎺掑悕娓呭崟 this.getRiskRank() // 鏇存柊璇ョ珯鐐圭殑鎵�灞炲満鏅拰杩愮淮鍟� - this.getSiteInfo(this.form.number) + this.getSiteInfo(this.form.mnCode) // 鏇存柊鍒嗘瀽鏁版嵁 this.getAnalysisData() // 璁$畻椋庨櫓鍊� @@ -222,12 +208,12 @@ this.screenLoading = true // 鏇存柊鎺掑悕娓呭崟锛屽苟寰楀埌椋庨櫓鍊兼渶楂樼珯鐐� let arr = await this.getRiskRank() - this.form.name = arr[0] - this.form.number = arr[1] + this.form.siteName = arr[0] + this.form.mnCode = arr[1] this.screenLoading = false // 鏇存柊璇ョ珯鐐圭殑鎵�灞炲満鏅拰杩愮淮鍟� - this.getSiteInfo(this.form.number) + this.getSiteInfo(this.form.mnCode) // 鏇存柊鏃ョ粺璁℃暟鎹� this.getAnalysisData() // 璁$畻椋庨櫓鍊� @@ -240,7 +226,7 @@ * @returns锛� */ calRiskValue() { - riskApi.queryRiskValue(this.form.number, this.month, 'month').then((response) => { + riskApi.queryRiskValue(this.form.mnCode, this.month, 'month').then((response) => { const rValue = response.data.data[0] this.exceptionRisk.onlineRisk = rValue.onlineRisk this.exceptionRisk.validRisk = rValue.validRisk @@ -254,29 +240,18 @@ // 鏍规嵁鐩墠绔欑偣锛屾湀浠斤紝鏌ユ姌绾垮浘鏃ョ粺璁℃暟鎹� fetchDayAnalysisData() { - let params = {} - if (this.form.name) { - params['siteName'] = this.form.name - } - if (this.form.beginTime) { - params['beginTime'] = this.form.beginTime - } - if (this.form.endTime) { - params['endTime'] = this.form.endTime - } this.loading = true this.queryButton = true exceptionApi - .analysisdata(this.form.name, this.form.beginTime, this.form.endTime, 'day') + .analysisdata(this.form.siteName, this.form.beginTime, this.form.endTime, 'day') .then((response) => { - this.chartData = response.data.data + this.chartData = response this.loading = false this.queryButton = false - if (response.data.data.length == 0) { + if (response.length == 0) { this.isNoData = true return } - this.chartData.sort(time.compareByScore) // 鍒嗘瀽鏁版嵁涓殑鏈�鏃╂椂闂� let begin = this.chartData[0].lst // 鍒嗘瀽鏁版嵁涓殑鏈�鏅氭椂闂� @@ -300,7 +275,7 @@ fetchExceptionAnalysisData() { exceptionApi .exceptiondata1({ - siteName: this.form.name, + siteName: this.form.siteName, beginTime: this.form.beginTime, endTime: this.form.endTime }) @@ -357,7 +332,7 @@ }, openDetail() { - const encodedSiteName = encodeURIComponent(this.form.name) + const encodedSiteName = encodeURIComponent(this.form.siteName) const timeType = '1' const jumpPage = '2' this.$router.push(`/exceptionDetail/${encodedSiteName}/${this.month}/${timeType}/${jumpPage}`) @@ -374,10 +349,10 @@ <el-form-item class="form-item"> <InputSearch - :site-name="form.name" + :site-name="form.siteName" isNeedDefaultSite="0" - @submit-value="(n) => (form.name = n)" - @submit-mncode="(n) => (form.number = n)" + @submit-value="(n) => (form.siteName = n)" + @submit-mncode="(n) => (form.mnCode = n)" ></InputSearch> </el-form-item> @@ -398,7 +373,7 @@ <div v-loading="screenLoading" class="wait-name"> <div class="chart-container" v-show="!isNoData && !screenLoading"> <el-card class="time-text"> - <h4>{{ form.name }}</h4> + <h4>{{ form.siteName }}</h4> <br /> <br /> diff --git a/src/views/risk_assessment/riskModel/components/CompDailyStatistic.vue b/src/views/risk_assessment/riskModel/components/CompDailyStatistic.vue index fc5d996..a59fbd2 100644 --- a/src/views/risk_assessment/riskModel/components/CompDailyStatistic.vue +++ b/src/views/risk_assessment/riskModel/components/CompDailyStatistic.vue @@ -1,16 +1,16 @@ <script> import exceptionApi from '@/api/exceptionApi.js' import lineChart from '@/utils/chartFunction/lineChart.js' -import index from '@/utils/risk_estimate_common_function/index.js' import time from '@/utils/time.js' +// import time from '@/utils/time.js' import FYLineChart from '@/components/chart/FYLineChart.vue' export default { props: { fetchParams: { type: Object, default: { - name: null, - number: null, + siteName: null, + mnCode: null, beginTime: null, endTime: null } @@ -34,7 +34,7 @@ watch: { fetchParams: { handler() { - if(this.fetchParams.name != '' && this.fetchParams.name != null){ + if(this.fetchParams.siteName != '' && this.fetchParams.siteName != null){ this.fetchDayAnalysisData() } }, @@ -46,40 +46,40 @@ methods: { // 鏍规嵁鐩墠绔欑偣锛屾湀浠斤紝鏌ユ姌绾垮浘鏃ョ粺璁℃暟鎹� fetchDayAnalysisData() { - exceptionApi - .analysisdata( - this.fetchParams.name, + exceptionApi.analysisdata( + this.fetchParams.siteName, this.fetchParams.beginTime, this.fetchParams.endTime, 'day' ) - .then((response) => { - const chartData = response.data.data - console.log('鏁版嵁涓�',chartData); - if (response.data.data.length == 0) { + .then(response => { + const chartData = response + if (chartData.length == 0) { return } - chartData.sort(time.compareByScore) - // 鍒嗘瀽鏁版嵁涓殑鏈�鏃╂椂闂� - let begin = chartData[0].lst - // 鍒嗘瀽鏁版嵁涓殑鏈�鏅氭椂闂� - let end = chartData[chartData.length - 1].lst + const timeArr = chartData.map(item => { + return item.lst + }) + // 鏃犳暟鎹殑鏃堕棿娈� - let noDataTimeInteval = lineChart.backNoDataInteval(begin, end) + let noDataTimeInterval = time.getMissingDays(this.fetchParams.beginTime, this.fetchParams.endTime,timeArr) // 鏃犳暟鎹厤缃椂闂存 - this.chart.areaColor = lineChart.getMarkArea(noDataTimeInteval) + this.chart.areaColor = lineChart.getMarkArea(noDataTimeInterval) this.setChart(chartData, this.fetchParams.beginTime, this.fetchParams.endTime) }) }, - // 閫夋嫨鍏朵粬鍊肩被鍨嬫椂 + /** + * 缁勪欢鎶樼嚎鍥剧殑閰嶇疆椤� + * @param锛� + * @returns锛� + */ setChart(cData, bt, et) { if (cData.length!=0) { // 鏋勫缓鎶樼嚎鍥緓,y鏁版嵁 let obj = lineChart.getLineChartXYData(cData, bt, et) - console.log('璁剧疆锛�',obj); this.chart.chartDataAvg = { x: obj.xData, y: obj.yAvg -- Gitblit v1.9.3