Compare commits

..

No commits in common. "cfd88d6acb67581d00e0826f7f360897d4cd689d" and "5d1e1a15a38555f3066171e0162178a253dcfa31" have entirely different histories.

4 changed files with 75 additions and 23 deletions

1
components.d.ts vendored
View File

@ -16,6 +16,7 @@ declare module 'vue' {
CustomCarouselPicture: typeof import('./src/components/custom-carousel-picture/index.vue')['default'] CustomCarouselPicture: typeof import('./src/components/custom-carousel-picture/index.vue')['default']
CustomEchartBar: typeof import('./src/components/custom-echart-bar/index.vue')['default'] CustomEchartBar: typeof import('./src/components/custom-echart-bar/index.vue')['default']
CustomEchartBubble: typeof import('./src/components/custom-echart-bubble/index.vue')['default'] CustomEchartBubble: typeof import('./src/components/custom-echart-bubble/index.vue')['default']
CustomEchartHyaline: typeof import('./src/components/custom-echart-hyaline/index.vue')['default']
CustomEchartHyalineCake: typeof import('./src/components/custom-echart-hyaline-cake/index.vue')['default'] CustomEchartHyalineCake: typeof import('./src/components/custom-echart-hyaline-cake/index.vue')['default']
CustomEchartLine: typeof import('./src/components/custom-echart-line/index.vue')['default'] CustomEchartLine: typeof import('./src/components/custom-echart-line/index.vue')['default']
CustomEchartLineLine: typeof import('./src/components/custom-echart-line-line/index.vue')['default'] CustomEchartLineLine: typeof import('./src/components/custom-echart-line-line/index.vue')['default']

View File

@ -2,7 +2,7 @@
<div ref="chartRef" :style="{ height, width }"></div> <div ref="chartRef" :style="{ height, width }"></div>
</template> </template>
<script> <script>
import { ref, reactive, watchEffect } from 'vue'; import { ref, reactive, watchEffect, watch } from 'vue';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { useEcharts } from '@/hooks/useEcharts'; import { useEcharts } from '@/hooks/useEcharts';
@ -66,6 +66,18 @@ export default {
props.chartData && initCharts(); props.chartData && initCharts();
}); });
watch(
() => props.chartData,
() => {
console.info('props.chartData变化', props.chartData);
props.chartData && initCharts();
},
{
deep: true,
immediate: true,
}
);
function hexToRGBA(hex, alpha = 1) { function hexToRGBA(hex, alpha = 1) {
let hexCode = hex.replace('#', ''); let hexCode = hex.replace('#', '');
if (hexCode.length === 3) { if (hexCode.length === 3) {
@ -143,8 +155,8 @@ export default {
seriesIndex: 0, seriesIndex: 0,
showTooltip: true, showTooltip: true,
}); });
// getInstance()?.off('click', onClick); getInstance()?.off('click', onClick);
// getInstance()?.on('click', onClick); getInstance()?.on('click', onClick);
} }
function onClick(params) { function onClick(params) {

View File

@ -141,13 +141,14 @@ export const useEcharts = (elRef, theme = 'default') => {
function setOptions(options = {}, clear = true) { function setOptions(options = {}, clear = true) {
const mergedOptions = { const mergedOptions = {
animation: true, animation: true,
animationDuration: 1000, animationDuration: 3000,
animationEasing: 'cubicOut', animationEasing: 'cubicOut',
...unref(options), ...unref(options),
animationThreshold: 2000, // 数据量超过2000自动关闭动画 animationThreshold: 2000, // 数据量超过2000自动关闭动画
animationDelayUpdate: (idx) => idx * 50, // 数据项延迟 animationDelayUpdate: (idx) => idx * 50, // 数据项延迟
}; };
cacheOptions.value = mergedOptions; cacheOptions.value = mergedOptions;
cacheOptions.value = options;
if (unref(elRef)?.offsetHeight === 0) { if (unref(elRef)?.offsetHeight === 0) {
useTimeoutFn(() => { useTimeoutFn(() => {
setOptions(unref(getOptions)); setOptions(unref(getOptions));
@ -163,6 +164,7 @@ export const useEcharts = (elRef, theme = 'default') => {
} }
clear && chartInstance?.clear(); clear && chartInstance?.clear();
chartInstance?.setOption(unref(getOptions)); chartInstance?.setOption(unref(getOptions));
// 立即绑定事件 // 立即绑定事件
chartInstance.off('click'); chartInstance.off('click');
chartInstance.on('click', handleMapClick); chartInstance.on('click', handleMapClick);

View File

@ -1,16 +1,34 @@
<template> <template>
<custom-echart-line ref="lineCharts" :chart-data="state.data" height="100%" :option="state.option" /> <custom-echart-line :chart-data="dataList" height="100%" :option="state.option" />
</template> </template>
<script setup> <script setup>
import { reactive, ref } from 'vue'; import { reactive } from 'vue';
let dataList = [ let dataList = reactive([
{ value: 10, name: '2020' }, {
{ value: 66, name: '2021' }, value: 10,
{ value: 100, name: '2022' }, name: '2020',
{ value: 120, name: '2023' }, },
{ value: 150, name: '2024' }, {
{ value: 80, name: '2025' }, value: 66,
]; name: '2021',
},
{
value: 100,
name: '2022',
},
{
value: 120,
name: '2023',
},
{
value: 150,
name: '2024',
},
{
value: 80,
name: '2025',
},
]);
const state = reactive({ const state = reactive({
option: { option: {
color: ['#35D0C0'], color: ['#35D0C0'],
@ -58,16 +76,35 @@ const state = reactive({
}, },
data: dataList, data: dataList,
}); });
const lineCharts = ref(null);
const refresData = () => { const refresData = () => {
state.data = [ console.info('landPatrol********************refresData');
{ value: 5, name: '2020' }, state.data = dataList = reactive([
{ value: 36, name: '2021' }, {
{ value: 70, name: '2022' }, value: 20,
{ value: 56, name: '2023' }, name: '2020',
{ value: 70, name: '2024' }, },
{ value: 20, name: '2025' }, {
]; value: 86,
name: '2021',
},
{
value: 120,
name: '2022',
},
{
value: 140,
name: '2023',
},
{
value: 170,
name: '2024',
},
{
value: 100,
name: '2025',
},
]);
}; };
defineExpose({ defineExpose({