Skip to content

Commit 5cbfb2a

Browse files
committed
fix(charts): fix echarts does not display after refresh #140
1 parent f69aaea commit 5cbfb2a

File tree

6 files changed

+37
-35
lines changed

6 files changed

+37
-35
lines changed

src/components/Container/index.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { withInstall } from '../util';
2-
2+
import CollapseContainer from './src/collapse/CollapseContainer.vue';
33
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
44
export const ScrollContainer = createAsyncComponent(() => import('./src/ScrollContainer.vue'));
5-
export const CollapseContainer = createAsyncComponent(
6-
() => import('./src/collapse/CollapseContainer.vue')
7-
);
5+
6+
// export const CollapseContainer = createAsyncComponent(
7+
// () => import('./src/collapse/CollapseContainer.vue')
8+
// );
89
export const LazyContainer = createAsyncComponent(() => import('./src/LazyContainer.vue'));
910

1011
withInstall(ScrollContainer, CollapseContainer, LazyContainer);
1112

13+
export { CollapseContainer };
1214
export * from './src/types';

src/hooks/web/useApexCharts.ts

+16-20
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import { unref, Ref, nextTick } from 'vue';
44

55
import ApexCharts from 'apexcharts';
66

7+
interface CallBackFn {
8+
(instance: Nullable<ApexCharts>): void;
9+
}
10+
711
export function useApexCharts(elRef: Ref<HTMLDivElement>) {
812
let chartInstance: Nullable<ApexCharts> = null;
913

10-
function setOptions(options: any, callback) {
14+
function setOptions(options: any, callback?: CallBackFn) {
1115
nextTick(() => {
1216
useTimeoutFn(() => {
1317
const el = unref(elRef);
@@ -16,37 +20,29 @@ export function useApexCharts(elRef: Ref<HTMLDivElement>) {
1620
chartInstance = new ApexCharts(el, options);
1721

1822
chartInstance && chartInstance.render();
19-
23+
2024
// setOptions增加callback方法,返回chartInstance,以便于对图表进行再操作,例如调用updateOptions方法更新图表
2125
callback && callback(chartInstance);
22-
2326
}, 30);
2427
});
2528
}
26-
29+
2730
// 新增调用ApexCharts的updateOptions方法更新图表
2831
function updateOptions(
29-
chartInstance: Nullable<ApexCharts>,
30-
options,
31-
redraw = false,
32-
animate = true,
33-
updateSyncedCharts = true,
34-
overwriteInitialConfig = true,
35-
callback) {
32+
chartInstance: Nullable<ApexCharts>,
33+
options: any,
34+
redraw = false,
35+
animate = true,
36+
updateSyncedCharts = true,
37+
callback: CallBackFn
38+
) {
3639
nextTick(() => {
3740
useTimeoutFn(() => {
41+
chartInstance && chartInstance.updateOptions(options, redraw, animate, updateSyncedCharts);
3842

39-
chartInstance && chartInstance.updateOptions(
40-
options,
41-
redraw,
42-
animate,
43-
updateSyncedCharts,
44-
overwriteInitialConfig);
45-
4643
callback && callback(chartInstance);
47-
4844
}, 30);
49-
});
45+
});
5046
}
5147

5248
tryOnUnmounted(() => {

src/hooks/web/useECharts.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export function useECharts(
2121

2222
function init() {
2323
const el = unref(elRef);
24-
2524
if (!el || !unref(el)) {
2625
return;
2726
}
27+
2828
chartInstance = echarts.init(el, theme);
2929
const { removeEvent } = useEventListener({
3030
el: window,
@@ -33,31 +33,36 @@ export function useECharts(
3333
});
3434
removeResizeFn = removeEvent;
3535
const { widthRef, screenEnum } = useBreakpoint();
36-
if (unref(widthRef) <= screenEnum.MD) {
36+
if (unref(widthRef) <= screenEnum.MD || el.offsetHeight === 0) {
3737
useTimeoutFn(() => {
3838
resizeFn();
3939
}, 30);
4040
}
4141
}
4242

4343
function setOptions(options: any, clear = true) {
44+
if (unref(elRef)?.offsetHeight === 0) {
45+
useTimeoutFn(() => {
46+
setOptions(options);
47+
}, 30);
48+
return;
49+
}
4450
nextTick(() => {
4551
useTimeoutFn(() => {
4652
if (!chartInstance) {
4753
init();
4854

4955
if (!chartInstance) return;
5056
}
51-
clear && chartInstance.clear();
57+
clear && chartInstance?.clear();
5258

53-
chartInstance && chartInstance.setOption(options);
59+
chartInstance?.setOption(options);
5460
}, 30);
5561
});
5662
}
5763

5864
function resize() {
59-
if (!chartInstance) return;
60-
chartInstance.resize();
65+
chartInstance?.resize();
6166
}
6267

6368
tryOnUnmounted(() => {

src/layouts/default/sider/MixSider.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
getCanDrag,
111111
getCloseMixSidebarOnChange,
112112
getMenuTheme,
113-
getMixSidebarTheme,
114113
} = useMenuSetting();
115114
const { title } = useGlobSetting();
116115
@@ -193,7 +192,6 @@
193192
title,
194193
openMenu,
195194
getMenuTheme,
196-
getMixSidebarTheme,
197195
};
198196
},
199197
});
@@ -290,9 +288,12 @@
290288
}
291289
}
292290
291+
> .scrollbar {
292+
height: calc(100% - @header-height) !important;
293+
}
294+
293295
&-module {
294296
position: relative;
295-
height: calc(100% - @header-height) !important;
296297
padding-top: 1px;
297298
298299
&__item {

src/views/dashboard/analysis/components/AnalysisPie.vue

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
{ value: 234, name: '其他', itemStyle: { color: '#7dd9b9' } },
1616
];
1717
export default defineComponent({
18-
name: 'AnalysisLine',
1918
props: basicProps,
2019
setup() {
2120
const chartRef = ref<HTMLDivElement | null>(null);

src/views/dashboard/analysis/components/TrendLine.vue

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
99
import { basicProps } from './props';
1010
export default defineComponent({
11-
name: 'AnalysisLine',
1211
props: basicProps,
1312
setup() {
1413
const chartRef = ref<HTMLDivElement | null>(null);

0 commit comments

Comments
 (0)