index.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <div ref="chartElement" class="mtp-echarts" :style="{ width: width, height: height }">
  3. <template v-if="empty">
  4. <div class="mtp-echarts__empty">暂无数据</div>
  5. </template>
  6. <template v-else>
  7. <div class="mtp-echarts__container" v-for="i in options.length" :key="i"></div>
  8. </template>
  9. </div>
  10. </template>
  11. <script lang="ts">
  12. import { defineComponent, ref, onMounted, PropType, watch, watchEffect } from 'vue';
  13. import { EChartsOption } from 'echarts';
  14. export default defineComponent({
  15. props: {
  16. // 图表宽度
  17. width: {
  18. type: String,
  19. default: '100%',
  20. },
  21. // 图表高度
  22. height: {
  23. type: String,
  24. default: '100%',
  25. },
  26. // 图表配置项,支持多图表(待完善...)
  27. options: {
  28. type: Array as PropType<EChartsOption[]>,
  29. default: [],
  30. },
  31. loading: {
  32. type: Boolean,
  33. default: true,
  34. },
  35. empty: {
  36. type: Boolean,
  37. default: false,
  38. },
  39. },
  40. setup(props) {
  41. // 图表容器元素
  42. const chartElement = ref<HTMLElement>();
  43. return {
  44. chartElement,
  45. }
  46. }
  47. })
  48. </script>
  49. <style lang="less">
  50. @import './index.less';
  51. </style>