Commit c747340d1ad53cebc7509ebe2249f1fe2b2ef348

Authored by xp.Huang
2 parents aae06a43 9b526b0e

Merge branch 'ww' into 'main'

fix: report export show report trend device not found data but not destory chart

See merge request huang/yun-teng-iot-front!429
@@ -46,6 +46,9 @@ export const formSchema: FormSchema[] = [ @@ -46,6 +46,9 @@ export const formSchema: FormSchema[] = [
46 ifShow: ({ model }) => { 46 ifShow: ({ model }) => {
47 return model[PackageField.URL]; 47 return model[PackageField.URL];
48 }, 48 },
  49 + componentProps: {
  50 + maxLength: 255,
  51 + },
49 }, 52 },
50 { 53 {
51 field: PackageField.CHECK_SUM_ALG, 54 field: PackageField.CHECK_SUM_ALG,
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 <Select 30 <Select
31 class="min-w-25" 31 class="min-w-25"
32 v-model:value="item.active" 32 v-model:value="item.active"
33 - @change="(value) => handleChangeChars(value, item.device)" 33 + @change="(value) => handleChangeChars(value, item.device, item)"
34 placeholder="请选择设备属性" 34 placeholder="请选择设备属性"
35 > 35 >
36 <Select.Option v-for="attr in item.attributes" :key="attr" :value="attr"> 36 <Select.Option v-for="attr in item.attributes" :key="attr" :value="attr">
@@ -38,10 +38,10 @@ @@ -38,10 +38,10 @@
38 </Select.Option> 38 </Select.Option>
39 </Select> 39 </Select>
40 </div> 40 </div>
41 - <div>  
42 - <Empty v-show="item.emptyFlag" /> 41 + <div class="w-full h-full flex justify-center items-center">
  42 + <Empty v-show="item.notFoundData" description="暂无数据" class="text-dark-50" />
43 <div 43 <div
44 - v-show="!item.emptyFlag" 44 + v-show="!item.notFoundData"
45 :id="`chart-${item.device}`" 45 :id="`chart-${item.device}`"
46 style="width: 100%; height: 400px" 46 style="width: 100%; height: 400px"
47 ></div> 47 ></div>
@@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
57 </div> 57 </div>
58 </template> 58 </template>
59 <script setup lang="ts"> 59 <script setup lang="ts">
60 - import { ref, PropType, nextTick, shallowReactive, onMounted, onUnmounted } from 'vue'; 60 + import { ref, PropType, nextTick, shallowReactive, onMounted, onUnmounted, unref } from 'vue';
61 import { BasicModal, useModalInner } from '/@/components/Modal'; 61 import { BasicModal, useModalInner } from '/@/components/Modal';
62 import * as echarts from 'echarts'; 62 import * as echarts from 'echarts';
63 import { exportViewChartApi } from '/@/api/export/exportManager'; 63 import { exportViewChartApi } from '/@/api/export/exportManager';
@@ -70,6 +70,15 @@ @@ -70,6 +70,15 @@
70 val: { ts: number; value: string }[]; 70 val: { ts: number; value: string }[];
71 } 71 }
72 72
  73 + interface ChartInstance {
  74 + device: string;
  75 + name: string;
  76 + attributes: string[];
  77 + active?: string;
  78 + notFoundData?: boolean;
  79 + loading?: boolean;
  80 + }
  81 +
73 defineProps({ 82 defineProps({
74 width: { 83 width: {
75 type: String as PropType<string>, 84 type: String as PropType<string>,
@@ -85,11 +94,7 @@ @@ -85,11 +94,7 @@
85 94
86 let currentRecord: ExecuteReportRecord = {} as unknown as ExecuteReportRecord; 95 let currentRecord: ExecuteReportRecord = {} as unknown as ExecuteReportRecord;
87 96
88 - const chartInstance = ref<  
89 - { device: string; name: string; attributes: string[]; active?: string; emptyFlag?: boolean }[]  
90 - >([]);  
91 -  
92 - const notFoundData = ref(false); 97 + const chartInstance = ref<ChartInstance[]>([]);
93 98
94 const chartsInstance = shallowReactive<{ [key: string]: echarts.ECharts }>({}); 99 const chartsInstance = shallowReactive<{ [key: string]: echarts.ECharts }>({});
95 //生成随机颜色 100 //生成随机颜色
@@ -125,13 +130,14 @@ @@ -125,13 +130,14 @@
125 }, 130 },
126 } as echarts.EChartsOption; 131 } as echarts.EChartsOption;
127 }) || ([] as echarts.EChartsOption[]); 132 }) || ([] as echarts.EChartsOption[]);
  133 +
128 const chartOption = { 134 const chartOption = {
129 - xAxisData: chartDataConfig.at(0)?.xAxis?.map(function (str) {  
130 - return str.replace(' ', '\n');  
131 - }), 135 + xAxisData: (chartDataConfig.at(0)?.xAxis as string[])?.map((str) => str.replace(' ', '\n')),
132 series: [chartDataConfig.at(0)?.series], 136 series: [chartDataConfig.at(0)?.series],
  137 + legend: {
  138 + data: Object.keys(result),
  139 + },
133 }; 140 };
134 -  
135 return chartOption; 141 return chartOption;
136 }; 142 };
137 143
@@ -145,9 +151,11 @@ @@ -145,9 +151,11 @@
145 ...item, 151 ...item,
146 active: item.attributes.at(0), 152 active: item.attributes.at(0),
147 })); 153 }));
148 - for (const item of deviceInfo) { 154 + for (const item of unref(chartInstance)) {
149 const { attributes, device } = item; 155 const { attributes, device } = item;
  156 +
150 const keys = attributes.length ? attributes.at(0) : ''; 157 const keys = attributes.length ? attributes.at(0) : '';
  158 +
151 const sendParams = { 159 const sendParams = {
152 ...data.record.executeCondition.executeCondition, 160 ...data.record.executeCondition.executeCondition,
153 ...{ 161 ...{
@@ -156,7 +164,7 @@ @@ -156,7 +164,7 @@
156 }; 164 };
157 165
158 const result = await exportViewChartApi(device, sendParams); 166 const result = await exportViewChartApi(device, sendParams);
159 - validateHasData(result); 167 + item.notFoundData = validateHasData(result);
160 const { xAxisData, series } = getChartsOption(result as unknown as ResponsData); 168 const { xAxisData, series } = getChartsOption(result as unknown as ResponsData);
161 169
162 await nextTick(); 170 await nextTick();
@@ -179,7 +187,7 @@ @@ -179,7 +187,7 @@
179 }, 187 },
180 }, 188 },
181 legend: { 189 legend: {
182 - data: attributes, 190 + // data: attributes,
183 top: '20px', 191 top: '20px',
184 }, 192 },
185 toolbox: {}, 193 toolbox: {},
@@ -247,7 +255,7 @@ @@ -247,7 +255,7 @@
247 } 255 }
248 ); 256 );
249 const loading = ref(false); 257 const loading = ref(false);
250 - const renderCharts = async (device: string, keys: string) => { 258 + const renderCharts = async (device: string, keys: string, item: ChartInstance) => {
251 const sendParams = { 259 const sendParams = {
252 ...currentRecord.executeCondition.executeCondition, 260 ...currentRecord.executeCondition.executeCondition,
253 ...{ 261 ...{
@@ -257,16 +265,8 @@ @@ -257,16 +265,8 @@
257 try { 265 try {
258 loading.value = true; 266 loading.value = true;
259 const result = await exportViewChartApi(device, sendParams); 267 const result = await exportViewChartApi(device, sendParams);
260 - chartInstance.value.forEach((f) => {  
261 - if (f.device === device) {  
262 - if (Object.keys(result).length === 0) {  
263 - f.emptyFlag = true;  
264 - } else {  
265 - f.emptyFlag = false;  
266 - }  
267 - }  
268 - });  
269 - validateHasData(result); 268 +
  269 + item.notFoundData = validateHasData(result);
270 const { xAxisData, series } = getChartsOption(result as unknown as ResponsData); 270 const { xAxisData, series } = getChartsOption(result as unknown as ResponsData);
271 271
272 chartsInstance[device].setOption({ 272 chartsInstance[device].setOption({
@@ -280,15 +280,15 @@ @@ -280,15 +280,15 @@
280 }; 280 };
281 281
282 const validateHasData = (record: Recordable) => { 282 const validateHasData = (record: Recordable) => {
283 - notFoundData.value = true;  
284 - const { val = [], attr } = (record as unknown as ResponsData) || {};  
285 - if (!attr || !val.length) {  
286 - notFoundData.value = false; 283 + // const { val = [], attr } = (record as unknown as ResponsData) || {};
  284 + if (!Object.keys(record).length) {
  285 + return true;
287 } 286 }
  287 + return false;
288 }; 288 };
289 289
290 - const handleChangeChars = (value: string, device: string) => {  
291 - renderCharts(device, value); 290 + const handleChangeChars = (value: string, device: string, item: ChartInstance) => {
  291 + renderCharts(device, value, item);
292 }; 292 };
293 293
294 const resize = () => { 294 const resize = () => {