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 46 ifShow: ({ model }) => {
47 47 return model[PackageField.URL];
48 48 },
  49 + componentProps: {
  50 + maxLength: 255,
  51 + },
49 52 },
50 53 {
51 54 field: PackageField.CHECK_SUM_ALG,
... ...
... ... @@ -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="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 43 <div
44   - v-show="!item.emptyFlag"
  44 + v-show="!item.notFoundData"
45 45 :id="`chart-${item.device}`"
46 46 style="width: 100%; height: 400px"
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; emptyFlag?: boolean }[]
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,16 +265,8 @@
257 265 try {
258 266 loading.value = true;
259 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 270 const { xAxisData, series } = getChartsOption(result as unknown as ResponsData);
271 271
272 272 chartsInstance[device].setOption({
... ... @@ -280,15 +280,15 @@
280 280 };
281 281
282 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 294 const resize = () => {
... ...