|
|
@@ -10,12 +10,14 @@ import { useBreakpoint } from '@/hooks/event/useBreakpoint';
|
|
|
|
|
|
import echarts from '@/utils/lib/echarts';
|
|
|
import { useDesignSetting } from '@/hooks/setting/useDesignSetting';
|
|
|
+import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
|
|
|
|
|
export function useECharts(
|
|
|
elRef: Ref<HTMLDivElement>,
|
|
|
theme: 'light' | 'dark' | 'default' = 'light',
|
|
|
) {
|
|
|
const { getDarkTheme } = useDesignSetting();
|
|
|
+ const { getMenuSetting } = useProjectSetting();
|
|
|
|
|
|
const getDarkMode = computed(() => {
|
|
|
const appTheme = getDarkTheme.value ? 'dark' : 'light';
|
|
|
@@ -62,23 +64,26 @@ export function useECharts(
|
|
|
|
|
|
function setOptions(options: EChartsOption, clear = true) {
|
|
|
cacheOptions.value = options;
|
|
|
- if (unref(elRef)?.offsetHeight === 0) {
|
|
|
- useTimeoutFn(() => {
|
|
|
- setOptions(unref(getOptions));
|
|
|
- }, 30);
|
|
|
- return;
|
|
|
- }
|
|
|
- nextTick(() => {
|
|
|
- useTimeoutFn(() => {
|
|
|
- if (!chartInstance) {
|
|
|
- initCharts(getDarkMode.value as 'default');
|
|
|
-
|
|
|
- if (!chartInstance) return;
|
|
|
- }
|
|
|
- clear && chartInstance?.clear();
|
|
|
-
|
|
|
- chartInstance?.setOption(unref(getOptions));
|
|
|
- }, 30);
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ if (unref(elRef)?.offsetHeight === 0) {
|
|
|
+ useTimeoutFn(() => {
|
|
|
+ setOptions(unref(getOptions));
|
|
|
+ resolve(null);
|
|
|
+ }, 30);
|
|
|
+ }
|
|
|
+ nextTick(() => {
|
|
|
+ useTimeoutFn(() => {
|
|
|
+ if (!chartInstance) {
|
|
|
+ initCharts(getDarkMode.value as 'default');
|
|
|
+
|
|
|
+ if (!chartInstance) return;
|
|
|
+ }
|
|
|
+ clear && chartInstance?.clear();
|
|
|
+
|
|
|
+ chartInstance?.setOption(unref(getOptions));
|
|
|
+ resolve(null);
|
|
|
+ }, 30);
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -111,6 +116,12 @@ export function useECharts(
|
|
|
return chartInstance;
|
|
|
}
|
|
|
|
|
|
+ watch(getMenuSetting.value, (_) => {
|
|
|
+ useTimeoutFn(() => {
|
|
|
+ resizeFn();
|
|
|
+ }, 300);
|
|
|
+ });
|
|
|
+
|
|
|
return {
|
|
|
setOptions,
|
|
|
resize,
|