mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-03-01 00:23:11 +08:00
Merge pull request #134 from xiangshu233/main
修复 useECharts Hooks 报错和暗色模式 bug
This commit is contained in:
@@ -10,23 +10,27 @@ import { useBreakpoint } from '@/hooks/event/useBreakpoint';
|
|||||||
|
|
||||||
import echarts from '@/utils/lib/echarts';
|
import echarts from '@/utils/lib/echarts';
|
||||||
|
|
||||||
// import { useRootSetting } from '@/hooks/setting/useRootSetting';
|
import { useDesignSetting } from '@/hooks/setting/useDesignSetting';
|
||||||
|
|
||||||
export function useECharts(
|
export function useECharts(
|
||||||
elRef: Ref<HTMLDivElement>,
|
elRef: Ref<HTMLDivElement>,
|
||||||
theme: 'light' | 'dark' | 'default' = 'light'
|
theme: 'light' | 'dark' | 'default' = 'default'
|
||||||
) {
|
) {
|
||||||
// const { getDarkMode } = useRootSetting();
|
const { getDarkTheme: getSysDarkTheme } = useDesignSetting();
|
||||||
const getDarkMode = 'light';
|
|
||||||
|
const getDarkTheme = computed(() => {
|
||||||
|
const sysTheme: string = getSysDarkTheme.value ? 'dark' : 'light';
|
||||||
|
return theme === 'default' ? sysTheme : theme;
|
||||||
|
});
|
||||||
|
|
||||||
let chartInstance: echarts.ECharts | null = null;
|
let chartInstance: echarts.ECharts | null = null;
|
||||||
let resizeFn: Fn = resize;
|
let resizeFn: Fn = resize;
|
||||||
const cacheOptions = ref<EChartsOption>({});
|
const cacheOptions = ref({});
|
||||||
let removeResizeFn: Fn = () => {};
|
let removeResizeFn: Fn = () => {};
|
||||||
|
|
||||||
resizeFn = useDebounceFn(resize, 200);
|
resizeFn = useDebounceFn(resize, 200);
|
||||||
|
|
||||||
const getOptions = computed((): EChartsOption => {
|
const getOptions = computed((): EChartsOption => {
|
||||||
if (getDarkMode !== 'dark') {
|
if (getDarkTheme.value !== 'dark') {
|
||||||
return cacheOptions.value;
|
return cacheOptions.value;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -67,7 +71,7 @@ export function useECharts(
|
|||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
useTimeoutFn(() => {
|
useTimeoutFn(() => {
|
||||||
if (!chartInstance) {
|
if (!chartInstance) {
|
||||||
initCharts(getDarkMode.value as 'default');
|
initCharts(getDarkTheme.value as 'default');
|
||||||
|
|
||||||
if (!chartInstance) return;
|
if (!chartInstance) return;
|
||||||
}
|
}
|
||||||
@@ -83,7 +87,7 @@ export function useECharts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => getDarkMode.value,
|
() => getDarkTheme.value,
|
||||||
(theme) => {
|
(theme) => {
|
||||||
if (chartInstance) {
|
if (chartInstance) {
|
||||||
chartInstance.dispose();
|
chartInstance.dispose();
|
||||||
@@ -102,7 +106,7 @@ export function useECharts(
|
|||||||
|
|
||||||
function getInstance(): echarts.ECharts | null {
|
function getInstance(): echarts.ECharts | null {
|
||||||
if (!chartInstance) {
|
if (!chartInstance) {
|
||||||
initCharts(getDarkMode.value as 'default');
|
initCharts(getDarkTheme.value as 'default');
|
||||||
}
|
}
|
||||||
return chartInstance;
|
return chartInstance;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user