Skip to content

Commit 5bdd8b5

Browse files
committed
修改结构
1 parent 4fa8e51 commit 5bdd8b5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/components/EasyChart.vue

+11-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const chartInstance: Ref<HTMLElement | null> = ref(null)
4747
//属性
4848
const props = withDefaults(defineProps<{
4949
//echarts配置对象
50-
option: EChartsOption,
50+
option: any,
5151
//重置图表尺寸是否使用动画
5252
resizeAnimation?: boolean,
5353
//是否显示表格
@@ -78,17 +78,17 @@ const position = reactive({
7878
//表格
7979
const table: {
8080
size: string,
81-
height: number | undefined
81+
height: number
8282
} = reactive({
8383
size: 'small',
84-
height: undefined
84+
height: 100
8585
})
8686

8787
//在图表选项变化的时候更新图表
8888
watch(
8989
() => props.option,
9090
() => {
91-
instance!.setOption(props.option, true)
91+
instance!.setOption(props.option as EChartsOption, true)
9292
},
9393
{
9494
deep: true
@@ -107,7 +107,7 @@ const tableColumns = computed(() => {
107107
}
108108
}
109109
//如果序列里有饼图则最终以饼图出现的为最终列
110-
for (let series of <SeriesOption[]>option.series!) {
110+
for (let series of option.series!) {
111111
if (series.type === 'pie') {
112112
return ['类型', '值']
113113
}
@@ -122,7 +122,7 @@ const tableColumns = computed(() => {
122122
const tableRows = computed(() => {
123123
const option = props.option
124124
const rows = []
125-
for (let series of <SeriesOption[]>option.series!) {
125+
for (let series of option.series!) {
126126
if (series.type === 'pie') {
127127
const items = series.data as PieDataItemOption[]
128128
items.forEach((item) => {
@@ -183,14 +183,16 @@ const observerResize = () => {
183183
tableResize()
184184
}
185185

186+
const {destroy,handler} = debounce(observerResize, 300)
187+
186188
defineExpose({
187189
instance,
188190
container,
189191
downloadAsImage
190192
})
191193

192194
onMounted(() => {
193-
container = <HTMLElement>chartContainer.value!.parentElement
195+
container = chartContainer.value!.parentElement
194196
if (!container) {
195197
throw new Error('没有找到父元素')
196198
}
@@ -209,14 +211,15 @@ onMounted(() => {
209211
instance = echarts.init(chartInstance.value!)
210212
instance!.setOption(props.option, true)
211213
//监听尺寸变化以便重置图表尺寸
212-
observer = new ResizeObserver(debounce(observerResize,500))
214+
observer = new ResizeObserver(handler)
213215
observer.observe(container!)
214216
})
215217
})
216218

217219
onUnmounted(() => {
218220
observer?.disconnect()
219221
instance?.dispose()
222+
destroy()
220223
})
221224
</script>
222225

vue.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ module.exports = defineConfig({
2525
allowedHosts: ['all'],
2626
client: {
2727
progress: true,
28+
overlay: {
29+
runtimeErrors: false,
30+
},
2831
},
2932
proxy: {
3033
//接口路径和映射地址,不要修改此处,酌情修改 .env.development 文件

0 commit comments

Comments
 (0)