| | |
| | | ElForm: typeof import('element-plus/es')['ElForm'] |
| | | ElFormItem: typeof import('element-plus/es')['ElFormItem'] |
| | | ElIcon: typeof import('element-plus/es')['ElIcon'] |
| | | ElImage: typeof import('element-plus/es')['ElImage'] |
| | | ElInput: typeof import('element-plus/es')['ElInput'] |
| | | ElLink: typeof import('element-plus/es')['ElLink'] |
| | | ElOption: typeof import('element-plus/es')['ElOption'] |
| | |
| | | } |
| | | |
| | | // æçº¿å¾ |
| | | function smallLineOption(_xAxis, _series, yMinInterval) { |
| | | function smallLineOption( |
| | | _xAxis, |
| | | _series, |
| | | yMinInterval, |
| | | mode = 'dark', |
| | | tag, |
| | | animation = true, |
| | | defaultGrid, |
| | | title |
| | | ) { |
| | | var fontSize = fGetChartFontSize(); |
| | | const _grid = defaultGrid |
| | | ? defaultGrid |
| | | : { left: '12%', right: '2%', top: '7%', bottom: '30%' }; |
| | | return { |
| | | title: { |
| | | text: title, |
| | | textStyle: { |
| | | color: mode == 'dark' ? '#ffffff' : '#000000' |
| | | }, |
| | | left: 'center' |
| | | }, |
| | | animation: animation, |
| | | animationEasing: 'elasticOut', |
| | | animationDelayUpdate: function (idx) { |
| | | return idx * 5; |
| | |
| | | fontSize: fontSize |
| | | } |
| | | }, |
| | | grid: { |
| | | left: '12%', |
| | | right: '2%', |
| | | top: '7%', |
| | | bottom: '30%' |
| | | }, |
| | | grid: _grid, |
| | | legend: { |
| | | show: false |
| | | }, |
| | | xAxis: [ |
| | | { |
| | | show: true, |
| | | // name: 'æ¶é´', |
| | | name: tag ? 'æ¶é´' : '', |
| | | // type: 'time', |
| | | data: _xAxis, |
| | | axisLabel: { |
| | | textStyle: { |
| | | fontSize: fontSize |
| | | }, |
| | | color: '#ffffff', |
| | | textBorderColor: '#fff' |
| | | color: mode == 'dark' ? '#ffffff' : '#000000', |
| | | textBorderColor: mode == 'dark' ? '#fff' : '#000000' |
| | | }, |
| | | axisTick: { |
| | | lineStyle: { |
| | | color: 'white' |
| | | color: mode == 'dark' ? '#ffffff' : '#000000' |
| | | }, |
| | | intervel: 0, |
| | | inside: false |
| | | }, |
| | | |
| | | nameTextStyle: { |
| | | color: '#ffffff' |
| | | color: mode == 'dark' ? '#ffffff' : '#000000' |
| | | }, |
| | | axisLine: { |
| | | lineStyle: { |
| | | color: '#ffffff' |
| | | color: mode == 'dark' ? '#ffffff' : '#000000' |
| | | } |
| | | } |
| | | }, |
| | |
| | | ], |
| | | yAxis: [ |
| | | { |
| | | // name: 'æµåº¦(μg/m³)', |
| | | name: tag ? 'æµåº¦(μg/m³)' : '', |
| | | // type: 'time', |
| | | axisLabel: { |
| | | textStyle: { |
| | |
| | | axisLine: { |
| | | show: true, |
| | | lineStyle: { |
| | | color: 'white' |
| | | color: mode == 'dark' ? '#ffffff' : '#000000' |
| | | } |
| | | }, |
| | | axisTick: { |
| | | show: false, |
| | | lineStyle: { |
| | | color: 'white' |
| | | color: mode == 'dark' ? '#ffffff' : '#000000' |
| | | } |
| | | }, |
| | | splitLine: { |
| | |
| | | axisLine: { |
| | | show: true, |
| | | lineStyle: { |
| | | color: 'white' |
| | | color: mode == 'dark' ? '#ffffff' : '#000000' |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | import * as echarts from 'echarts'; |
| | | import { smallLineOption, baseVisualMap } from '@/utils/chart/chart-option'; |
| | | |
| | | /** |
| | | * 使ç¨echartsçæå¾è¡¨å¹¶è½¬æ¢ä¸ºbase64å¾ç |
| | | * @returns {string} å¾è¡¨çbase64ç¼ç å¾ç |
| | | */ |
| | | function generateEchartsImage(params, exceptionIndexArr, yMinInterval) { |
| | | // 1. å建临æ¶DOMå
ç´ |
| | | const div = document.createElement('div'); |
| | | // div.style.width = '330px'; |
| | | // div.style.height = '160px'; |
| | | div.style.width = '800px'; |
| | | div.style.height = '400px'; |
| | | document.body.appendChild(div); |
| | | |
| | | // 2. åå§åechartså®ä¾ |
| | | const myChart = echarts.init(div); |
| | | |
| | | // 3. å夿µè¯æ°æ® |
| | | const { xAxis, series } = params; |
| | | const option = smallLineOption( |
| | | xAxis, |
| | | series, |
| | | yMinInterval, |
| | | 'light', |
| | | true, |
| | | false, |
| | | { left: '7%', right: '7%', top: '10%', bottom: '10%' }, |
| | | series.name |
| | | ); |
| | | if (exceptionIndexArr) { |
| | | const visualMap = baseVisualMap(exceptionIndexArr); |
| | | option.visualMap = visualMap; |
| | | } |
| | | |
| | | // 4. 设置å¾è¡¨é
置项 |
| | | myChart.setOption(option); |
| | | |
| | | // 5. å°å¾è¡¨è½¬æ¢ä¸ºbase64å¾ç |
| | | const imageBase64 = myChart.getDataURL({ |
| | | type: 'png', |
| | | pixelRatio: 2, // æé«å¾çæ¸
æ°åº¦ |
| | | backgroundColor: '#fff' |
| | | }); |
| | | |
| | | // 6. 鿝å®ä¾å¹¶ç§»é¤ä¸´æ¶DOM |
| | | myChart.dispose(); |
| | | document.body.removeChild(div); |
| | | |
| | | return imageBase64; |
| | | } |
| | | |
| | | export default { generateEchartsImage }; |
| | |
| | | import FileSaver from 'file-saver'; |
| | | |
| | | /** |
| | | * å°base64æ ¼å¼å¾ç转æ¢ä¸ºArrayBuffer |
| | | * @param {string} base64Str - base64æ ¼å¼å¾çå符串ï¼å¯å
å«data URLåç¼ï¼ |
| | | * @returns {ArrayBuffer} 转æ¢åçArrayBuffer对象 |
| | | */ |
| | | function base64ToArrayBuffer(base64Str) { |
| | | // ç§»é¤data URLåç¼ï¼å¦æåå¨ï¼ |
| | | const base64Content = base64Str.replace(/^data:image\/\w+;base64,/, ''); |
| | | |
| | | // å¤çURLå®å
¨çbase64å符 |
| | | const safeBase64 = base64Content.replace(/-/g, '+').replace(/_/g, '/'); |
| | | |
| | | // è§£ç base64å符串 |
| | | const binaryStr = atob(safeBase64); |
| | | |
| | | // 转æ¢ä¸ºUint8Array |
| | | const byteLength = binaryStr.length; |
| | | const uint8Array = new Uint8Array(byteLength); |
| | | |
| | | for (let i = 0; i < byteLength; i++) { |
| | | uint8Array[i] = binaryStr.charCodeAt(i); |
| | | } |
| | | |
| | | // è¿åArrayBuffer |
| | | return uint8Array.buffer; |
| | | } |
| | | |
| | | /** |
| | | * çæ¯ä¾ç¼©æ¾å¾ç |
| | | * æ ¹æ®å¾ççé¿å®½æ¯è¿è¡ä¸åæ¹å¼çç¼©æ¾ |
| | | * å¦æå®½åº¦å¤§äºé«åº¦ï¼æ¨ªæå¾çï¼ï¼åæç
§è®¾å®é«åº¦çæ¯ç¼©æ¾ï¼ |
| | |
| | | getImage(tagValue) { |
| | | // In this case tagValue will be a URL tagValue = "https://docxtemplater.com/puffin.png" |
| | | return new Promise(function (resolve, reject) { |
| | | JSZipUtils.getBinaryContent(tagValue, function (error, content) { |
| | | if (error) { |
| | | return reject(error); |
| | | } |
| | | return resolve(content); |
| | | }); |
| | | if (tagValue.indexOf('http') == 0) { |
| | | JSZipUtils.getBinaryContent(tagValue, function (error, content) { |
| | | if (error) { |
| | | return reject(error); |
| | | } |
| | | return resolve(content); |
| | | }); |
| | | } else if (tagValue.indexOf('data:image') == 0) { |
| | | const buffer = base64ToArrayBuffer(tagValue); |
| | | return resolve(buffer); |
| | | } |
| | | }); |
| | | }, |
| | | |
| | |
| | | > |
| | | ä¸è½½æ¥å |
| | | </el-button> |
| | | <el-button |
| | | type="primary" |
| | | class="el-button-custom" |
| | | @click="handleGenerateImg" |
| | | :loading="docLoading" |
| | | > |
| | | çæå¾ç |
| | | </el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | <el-form-item> |
| | | <el-image :src="base64Url" fit="fill" :preview-src-list="[base64Url]" /> |
| | | </el-form-item> |
| | | </CardDialog> |
| | | </template> |
| | | <script setup> |
| | |
| | | import moment from 'moment'; |
| | | import dataAnalysisApi from '@/api/dataAnalysisApi'; |
| | | import { exportDocx } from '@/utils/doc'; |
| | | import { radioOptions } from '@/constant/radio-options'; |
| | | import { TYPE0 } from '@/constant/device-type'; |
| | | import { FactorDatas } from '@/model/FactorDatas'; |
| | | import factorDataParser from '@/utils/chart/factor-data-parser'; |
| | | import chartToImg from '@/utils/chart/chart-to-img'; |
| | | |
| | | const formObj = ref({ |
| | | timeArray: [new Date('2025-07-01T00:00:00'), new Date('2025-08-31T23:59:59')], |
| | |
| | | }); |
| | | |
| | | const docLoading = ref(false); |
| | | |
| | | const base64Url = ref(null); |
| | | |
| | | const params = computed(() => { |
| | | return { |
| | |
| | | ], |
| | | missionDetailList: [ |
| | | { |
| | | _index: 1, |
| | | _startTime: '2025å¹´07æ29æ¥', |
| | | _time: '09:00è³14:30', |
| | | _kilometres: '1000', |
| | | _keyScene: '1ä¸ªå½æ§ç¹ï¼éå®çæµç«ï¼å2ä¸ªå¸æ§ç¹ï¼åç°ä¸å¦ãå¸å髿°ï¼', |
| | | _dataStat: |
| | | 'PMâ.â
ï¼èå´30â35 μg/m³ï¼åå¼35.51 μg/m³ï¼ãPMââï¼èå´25â68 μg/m³ï¼åå¼38 μg/m³ï¼ãNOâï¼èå´22â54 μg/m³ï¼åå¼32 μg/m³ï¼ãCOï¼èå´2.08â6.39 mg/m³ï¼åå¼3.398 mg/m³ï¼åNOï¼èå´1â106 μg/m³ï¼åå¼20.97 μg/m³ï¼', |
| | | _dataStatistics: [ |
| | | { |
| | | factor: 'PM10', |
| | | minValue: 25, |
| | | maxValue: 68, |
| | | avgValue: 38 |
| | | } |
| | | ], |
| | | aqi: 30, |
| | | pollutionDegree: 'ä¼' |
| | | } |
| | | ], |
| | | clueByAreaList: [ |
| | | { |
| | | _index: 1, |
| | | _area: 'ææåºåå¨è¾¹', |
| | | clueByFactorList: [ |
| | | { |
| | | factor: 'PMâ.â
', |
| | | clues: [ |
| | | { |
| | | _factorNames: 'PM2.5', |
| | | _time: '10:22:28 - 10:22:34', |
| | | _riskRegion: 'é¿å®åºæ¸
溪路å¯ä¹ä¸è·¯', |
| | | _exceptionType: 'å¿«éä¸å', |
| | | _chart: '', |
| | | _conclusion: |
| | | 'å¨10:22:28è³10:22:34ä¹é´ï¼åºç°å¿«éä¸åï¼VOCæä½å¼ä¸º135.95μg/mÂ³ï¼æé«å¼ä¸º135.95μg/m³ï¼åå¼ä¸º135.95μg/m³ï¼åç°3个é£é©æºï¼å
å«2ä¸ªå æ²¹ç«ï¼1个汽修ã', |
| | | _scenes: |
| | | '1.䏿µ·ä¾å¾·æ±½è½¦ç»´ä¿®æéå
¬å¸ï¼æ±½ä¿®ä¼ä¸ï¼ä½äºä¸æµ·å¸é¿å®åºåè¹è·¯1079å·ï¼è·ä»éç«1887ç±³ã\r\nâ¦â¦' |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | }; |
| | | |
| | | const handleClick = () => { |
| | | generateMissionSummary(params.value).then((res) => { |
| | | // generateDocx(); |
| | | generateMissionList(params.value).then((res) => { |
| | | generateMissionDetail(params.value).then((res) => { |
| | | // generateClueByRiskArea(params.value).then((res) => {}); |
| | | docLoading.value = true; |
| | | generateMissionSummary(params.value).then(() => { |
| | | generateMissionList(params.value).then(() => { |
| | | generateMissionDetail(params.value).then(() => { |
| | | generateClueByRiskArea(params.value).then(() => { |
| | | generateDocx(); |
| | | }); |
| | | }); |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | const handleGenerateImg = () => { |
| | | generateClueByRiskArea(params.value).then(() => {}); |
| | | }; |
| | | |
| | | function generateMissionSummary(param) { |
| | |
| | | item._time = formatDateTimeRange(item.startTime, item.endTime); |
| | | item._airQulity = `AQIï¼${item.aqi}ï¼${item.pollutionDegree}ï¼`; |
| | | item._abnormalFactors = item.abnormalFactors |
| | | .map((factor) => factor.des) |
| | | .map((factor) => factor) |
| | | .join('ã'); |
| | | return item; |
| | | }); |
| | |
| | | |
| | | function generateMissionDetail(param) { |
| | | return dataAnalysisApi.fetchMissionDetail(param).then((res) => { |
| | | templateParam.missionDetailList = res.data.map((item) => { |
| | | templateParam.missionDetailList = res.data.map((item, index) => { |
| | | const t = formatDateTimeRange(item.startTime, item.endTime).split(' '); |
| | | item._index = index + 1; |
| | | item._startTime = t[0]; |
| | | item._time = t[1]; |
| | | item._kilometres = Math.round(item.kilometres / 1000); |
| | |
| | | if (!keySceneMap.has(e.type)) { |
| | | keySceneMap.set(e.type, { scenes: [], count: 0 }); |
| | | } |
| | | keySceneMap.get(e.type).scenes.push(e.scene); |
| | | keySceneMap.get(e.type).scenes.push(e); |
| | | keySceneMap.get(e.type).count++; |
| | | }); |
| | | item._keyScene = [...keySceneMap] |
| | |
| | | `${info.count}个${type}ï¼${info.scenes.map((s) => s.name).join('ã')}ï¼` |
| | | ) |
| | | .join('ã'); |
| | | item._dataStat = item.dataStatistic |
| | | item._dataStat = item.dataStatistics |
| | | .map( |
| | | (e) => |
| | | `${e.factor.des}ï¼èå´${e.minValue}â${e.maxValue}μg/m³ï¼åå¼${e.avgValue}μg/m³ï¼` |
| | | ) |
| | | .join('ã'); |
| | | |
| | | const factorNames = radioOptions(TYPE0).map((e) => e.name); |
| | | item._dataStatistics = item.dataStatistics.filter((e) => { |
| | | return factorNames.indexOf(e.factor) != -1; |
| | | }); |
| | | |
| | | return item; |
| | | }); |
| | |
| | | } |
| | | |
| | | function generateClueByRiskArea(param) { |
| | | return dataAnalysisApi.fetchClueByRiskArea(param).then((res) => {}); |
| | | return dataAnalysisApi.fetchClueByRiskArea(param).then((res) => { |
| | | templateParam.clueByAreaList = res.data.map((item, index) => { |
| | | return { |
| | | _index: index + 1, |
| | | _area: item.sceneInfo.name + 'å¨è¾¹', |
| | | clueByFactorList: item.clueByFactorList.map((cbf) => { |
| | | return { |
| | | factor: cbf.factor, |
| | | clues: cbf.clues.map((clue) => { |
| | | return { |
| | | _factorNames: Object.keys(clue.pollutedData.statisticMap) |
| | | .map((e) => e) |
| | | .join('ã'), |
| | | _time: |
| | | moment(clue.pollutedData.startTime).format('HH:mm:ss') + |
| | | ' - ' + |
| | | moment(clue.pollutedData.endTime).format('HH:mm:ss'), |
| | | _riskRegion: clue.pollutedArea.address |
| | | ? clue.pollutedArea.address |
| | | : '', |
| | | _exceptionType: clue.pollutedData.exception, |
| | | _images: generateChartImg(clue.pollutedData), |
| | | _conclusion: clue.pollutedSource.conclusion, |
| | | _scenes: |
| | | clue.pollutedSource.sceneList.length > 0 |
| | | ? clue.pollutedSource.sceneList |
| | | .map( |
| | | (s, index) => |
| | | `${index + 1}. ${s.name}ï¼${s.type}ï¼ä½äº${s.location}ï¼è·${s.closestStation.name}${parseInt(s.length)}ç±³ï¼` |
| | | ) |
| | | .join('\n') |
| | | : 'æ ' |
| | | }; |
| | | }) |
| | | }; |
| | | }) |
| | | }; |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | function generateChartImg(pollutedData) { |
| | | const exceptionIndexArr = []; |
| | | pollutedData.dataVoList.forEach((e) => { |
| | | const i = pollutedData.historyDataList.findIndex((v) => v.time == e.time); |
| | | exceptionIndexArr.push([i - 1 < 0 ? 0 : i - 1, i]); |
| | | }); |
| | | |
| | | const factorDatas = new FactorDatas(); |
| | | const images = []; |
| | | factorDatas.setData(pollutedData.historyDataList, 0, () => { |
| | | for (const key in pollutedData.statisticMap) { |
| | | const value = pollutedData.statisticMap[key]; |
| | | const _chartOptions = factorDataParser.parseData(factorDatas, [ |
| | | { |
| | | label: value.factorName, |
| | | name: value.factorName, |
| | | value: value.factorId + '' |
| | | } |
| | | ]); |
| | | _chartOptions.forEach((o) => { |
| | | images.push({ |
| | | url: chartToImg.generateEchartsImage(o, exceptionIndexArr, 20) |
| | | }); |
| | | }); |
| | | |
| | | if (base64Url.value == null) { |
| | | base64Url.value = images[0].url; |
| | | } |
| | | } |
| | | }); |
| | | return images; |
| | | } |
| | | |
| | | function generateDocx() { |
| | | docLoading.value = true; |
| | | exportDocx( |
| | | '/underway_season_report.docx', |
| | | templateParam, |
| | | `èµ°èªå£åº¦æ¥å.docx`, |
| | | { |
| | | horizontalHeight: 368, |
| | | verticalWidth: 266, |
| | | scale: 1.367 |
| | | horizontalHeight: 250, |
| | | verticalWidth: 568, |
| | | scale: 2 |
| | | } |
| | | ).finally(() => (docLoading.value = false)); |
| | | } |