ny
22 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
 
import { inject, nextTick, onMounted, reactive, ref, toRefs } from 'vue';
 
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
 
import { getDataInterfaceRes } from '#/api/systemData/dataInterface';
import CardHeader from '#/components/VisualPortal/Portal/CardHeader/index.vue';
import { getParamList } from '#/utils/jnpf';
 
interface State {
  chart: any;
  currOption: any;
  chartData: any;
}
 
const props = defineProps(['activeData']);
const state = reactive<State>({
  chart: null,
  currOption: {},
  chartData: {},
});
const { chartData } = toRefs(state);
const emitter: any = inject('emitter');
const chartRef = ref<EchartsUIType>();
const { renderEcharts, resize } = useEcharts(chartRef);
 
function init() {
  if (props.activeData.dataType === 'dynamic') {
    if (!props.activeData.propsApi) return;
    const query = { paramList: getParamList(props.activeData.templateJson) };
    getDataInterfaceRes(props.activeData.propsApi, query).then((res) => {
      state.chartData = res.data || {};
      renderEcharts(state.chartData);
    });
  } else {
    state.chartData = props.activeData.option;
    renderEcharts(state.chartData);
  }
  emitter.on(`eChart${props.activeData.i}`, () => {
    nextTick(() => resize());
  });
}
 
onMounted(() => init());
</script>
<template>
  <a-card class="portal-card-box">
    <template #title v-if="activeData.title">
      <CardHeader :title="activeData.title" :card="activeData.card" />
    </template>
    <div class="portal-card-body h-full">
      <template v-if="chartData">
        <EchartsUI ref="chartRef" class="box-inherit !h-full w-full p-[10px]" />
      </template>
      <div class="portal-common-noData" v-else>
        <jnpf-empty />
      </div>
    </div>
  </a-card>
</template>