chart-option.ts 962 B

123456789101112131415161718192021222324252627
  1. import { computed } from 'vue';
  2. import { EChartsOption } from 'echarts';
  3. import { useAppStore } from '@/store';
  4. // for code hints
  5. // import { SeriesOption } from 'echarts';
  6. // Because there are so many configuration items, this provides a relatively convenient code hint.
  7. // When using vue, pay attention to the reactive issues. It is necessary to ensure that corresponding functions can be triggered, TypeScript does not report errors, and code writing is convenient.
  8. interface optionsFn {
  9. (isDark: boolean): EChartsOption;
  10. }
  11. export default function useChartOption(sourceOption: optionsFn) {
  12. const appStore = useAppStore();
  13. const isDark = computed(() => {
  14. return appStore.theme === 'dark';
  15. });
  16. // echarts support https://echarts.apache.org/zh/theme-builder.html
  17. // It's not used here
  18. // TODO echarts themes
  19. const chartOption = computed<EChartsOption>(() => {
  20. return sourceOption(isDark.value);
  21. });
  22. return {
  23. chartOption,
  24. };
  25. }