Commit 2a09b9acaec6a6a659010a0797ecb441c4fb9296

Authored by ww
1 parent 7912e010

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

... ... @@ -30,7 +30,7 @@
30 30 <Select
31 31 class="min-w-25"
32 32 v-model:value="item.active"
33   - @change="(value) => handleChangeChars(value, item.device)"
  33 + @change="(value) => handleChangeChars(value, item.device, item)"
34 34 placeholder="请选择设备属性"
35 35 >
36 36 <Select.Option v-for="attr in item.attributes" :key="attr" :value="attr">
... ... @@ -38,10 +38,10 @@
38 38 </Select.Option>
39 39 </Select>
40 40 </div>
41   - <div>
42   - <Empty v-show="notFoundData" />
  41 + <div class="w-full h-full flex justify-center items-center">
  42 + <Empty v-show="item.notFoundData" />
43 43 <div
44   - v-show="!notFoundData"
  44 + v-show="!item.notFoundData"
45 45 :id="`chart-${item.device}`"
46 46 :style="{ height, width }"
47 47 ></div>
... ... @@ -57,7 +57,7 @@
57 57 </div>
58 58 </template>
59 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 61 import { BasicModal, useModalInner } from '/@/components/Modal';
62 62 import * as echarts from 'echarts';
63 63 import { exportViewChartApi } from '/@/api/export/exportManager';
... ... @@ -70,6 +70,15 @@
70 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 82 defineProps({
74 83 width: {
75 84 type: String as PropType<string>,
... ... @@ -85,11 +94,7 @@
85 94
86 95 let currentRecord: ExecuteReportRecord = {} as unknown as ExecuteReportRecord;
87 96
88   - const chartInstance = ref<
89   - { device: string; name: string; attributes: string[]; active?: string }[]
90   - >([]);
91   -
92   - const notFoundData = ref(false);
  97 + const chartInstance = ref<ChartInstance[]>([]);
93 98
94 99 const chartsInstance = shallowReactive<{ [key: string]: echarts.ECharts }>({});
95 100 //生成随机颜色
... ... @@ -125,13 +130,14 @@
125 130 },
126 131 } as echarts.EChartsOption;
127 132 }) || ([] as echarts.EChartsOption[]);
  133 +
128 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 136 series: [chartDataConfig.at(0)?.series],
  137 + legend: {
  138 + data: Object.keys(result),
  139 + },
133 140 };
134   -
135 141 return chartOption;
136 142 };
137 143
... ... @@ -145,9 +151,11 @@
145 151 ...item,
146 152 active: item.attributes.at(0),
147 153 }));
148   - for (const item of deviceInfo) {
  154 + for (const item of unref(chartInstance)) {
149 155 const { attributes, device } = item;
  156 +
150 157 const keys = attributes.length ? attributes.at(0) : '';
  158 +
151 159 const sendParams = {
152 160 ...data.record.executeCondition.executeCondition,
153 161 ...{
... ... @@ -156,7 +164,7 @@
156 164 };
157 165
158 166 const result = await exportViewChartApi(device, sendParams);
159   - validateHasData(result);
  167 + item.notFoundData = validateHasData(result);
160 168 const { xAxisData, series } = getChartsOption(result as unknown as ResponsData);
161 169
162 170 await nextTick();
... ... @@ -179,7 +187,7 @@
179 187 },
180 188 },
181 189 legend: {
182   - data: attributes,
  190 + // data: attributes,
183 191 top: '20px',
184 192 },
185 193 toolbox: {},
... ... @@ -247,7 +255,7 @@
247 255 }
248 256 );
249 257 const loading = ref(false);
250   - const renderCharts = async (device: string, keys: string) => {
  258 + const renderCharts = async (device: string, keys: string, item: ChartInstance) => {
251 259 const sendParams = {
252 260 ...currentRecord.executeCondition.executeCondition,
253 261 ...{
... ... @@ -257,7 +265,8 @@
257 265 try {
258 266 loading.value = true;
259 267 const result = await exportViewChartApi(device, sendParams);
260   - validateHasData(result);
  268 +
  269 + item.notFoundData = validateHasData(result);
261 270 const { xAxisData, series } = getChartsOption(result as unknown as ResponsData);
262 271
263 272 chartsInstance[device].setOption({
... ... @@ -271,15 +280,15 @@
271 280 };
272 281
273 282 const validateHasData = (record: Recordable) => {
274   - notFoundData.value = true;
275   - const { val = [], attr } = (record as unknown as ResponsData) || {};
276   - if (!attr || !val.length) {
277   - notFoundData.value = false;
  283 + // const { val = [], attr } = (record as unknown as ResponsData) || {};
  284 + if (!Object.keys(record).length) {
  285 + return true;
278 286 }
  287 + return false;
279 288 };
280 289
281   - const handleChangeChars = (value: string, device: string) => {
282   - renderCharts(device, value);
  290 + const handleChangeChars = (value: string, device: string, item: ChartInstance) => {
  291 + renderCharts(device, value, item);
283 292 };
284 293
285 294 const resize = () => {
... ...