<template>
  <div ref="chartElement" class="mtp-echarts" :style="{ width: width, height: height }">
    <template v-if="empty">
      <div class="mtp-echarts__empty">暂无数据</div>
    </template>
    <template v-else>
      <div class="mtp-echarts__container" v-for="i in options.length" :key="i"></div>
    </template>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted, PropType, watch, watchEffect } from 'vue';
import { EChartsOption } from 'echarts';

export default defineComponent({
  props: {
    // 图表宽度
    width: {
      type: String,
      default: '100%',
    },
    // 图表高度
    height: {
      type: String,
      default: '100%',
    },
    // 图表配置项，支持多图表(待完善...)
    options: {
      type: Array as PropType<EChartsOption[]>,
      default: [],
    },
    loading: {
      type: Boolean,
      default: true,
    },
    empty: {
      type: Boolean,
      default: false,
    },
  },
  setup(props) {
    // 图表容器元素
    const chartElement = ref<HTMLElement>();

    return {
      chartElement,
    }
  }
})
</script>

<style lang="less">
@import './index.less';
</style>