feat: ai店铺添加柱状图

This commit is contained in:
2026-06-25 11:10:18 +08:00
parent c8eb96b64c
commit a7f80af1de
7 changed files with 329 additions and 120 deletions
+21 -7
View File
@@ -1,14 +1,15 @@
<template>
<l-echart ref="chartRef"></l-echart>
<l-echart ref="chartRef" class="chart"></l-echart>
</template>
<script setup lang="ts">
<script setup>
import { onMounted, ref, onBeforeUnmount, nextTick, watch } from 'vue';
import * as echarts from 'echarts';
const chartRef = ref(null)
const myChart = ref(null)
let hasSetOption = false
const props = defineProps({
options: {
@@ -21,14 +22,19 @@
const initChart = async () => {
if (!chartRef.value) return
// 初始化echart
myChart.value = await chartRef.value.init(echarts)
if (!myChart.value) {
myChart.value = await chartRef.value.init(echarts)
}
// 默认获取容器尺寸
myChart.value.resize();
// 设置true清空echart缓存
myChart.value?.setOption(props.options, true);
if (!hasSetOption) {
myChart.value?.setOption(props.options, true);
hasSetOption = true
return
}
myChart.value?.setOption(props.options);
}
@@ -55,6 +61,14 @@
onBeforeUnmount(() => {
if (myChart.value) {
echarts.dispose(myChart.value);
myChart.value = null;
}
});
</script>
</script>
<style scoped>
.chart {
width: 100%;
height: 100%;
}
</style>