2025-09-03 12:05:17 +08:00
|
|
|
|
<template>
|
2025-09-05 14:27:29 +08:00
|
|
|
|
<Background :title-text="titleText" :select-option-mode="selectOptionMode" :select-options="selectOptions"
|
|
|
|
|
:in-select-options="inSelectOptions" @mode1-2-select="handleHeaderSelectChange" @mode3-select="handleInSelect">
|
|
|
|
|
<div class="go-energy-box">
|
|
|
|
|
<div class="content">
|
|
|
|
|
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option" :update-options="{
|
|
|
|
|
replaceMerge: replaceMergeArr
|
|
|
|
|
}" autoresize>
|
|
|
|
|
</v-chart>
|
|
|
|
|
</div>
|
2025-09-03 12:05:17 +08:00
|
|
|
|
</div>
|
2025-09-05 14:27:29 +08:00
|
|
|
|
</Background>
|
|
|
|
|
|
2025-09-03 12:05:17 +08:00
|
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2025-09-03 21:17:52 +08:00
|
|
|
|
import { PropType, computed, onMounted, ref, watch } from 'vue'
|
2025-09-03 12:05:17 +08:00
|
|
|
|
import VChart from 'vue-echarts'
|
|
|
|
|
import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook'
|
|
|
|
|
import * as echarts from 'echarts'
|
|
|
|
|
import { use } from 'echarts/core'
|
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
|
|
import { BarChart } from 'echarts/charts'
|
|
|
|
|
import { TitleComponent, GridComponent } from 'echarts/components'
|
|
|
|
|
import config, { includes } from './config'
|
|
|
|
|
import { mergeTheme } from '@/packages/public/chart'
|
|
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
|
|
|
|
import { useChartDataFetch } from '@/hooks'
|
2025-09-05 14:27:29 +08:00
|
|
|
|
import Background from '../Background/index.vue'
|
2025-09-03 12:05:17 +08:00
|
|
|
|
const props = defineProps({
|
|
|
|
|
themeSetting: {
|
|
|
|
|
type: Object,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
themeColor: {
|
|
|
|
|
type: Object,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
chartConfig: {
|
|
|
|
|
type: Object as PropType<config>,
|
|
|
|
|
required: true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
const initOptions = useCanvasInitOptions(props.chartConfig.option, props.themeSetting)
|
|
|
|
|
|
2025-09-05 14:27:29 +08:00
|
|
|
|
|
2025-09-03 12:05:17 +08:00
|
|
|
|
use([
|
|
|
|
|
CanvasRenderer,
|
|
|
|
|
BarChart,
|
|
|
|
|
TitleComponent,
|
|
|
|
|
GridComponent
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
const replaceMergeArr = ref<string[]>([])
|
|
|
|
|
|
2025-09-03 21:17:52 +08:00
|
|
|
|
const updataUnit = () => {
|
|
|
|
|
option.value.title.text = '单位:' + option.value.unit;
|
|
|
|
|
}
|
|
|
|
|
const option = computed(() => {
|
|
|
|
|
return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
|
|
|
|
})
|
2025-09-03 12:05:17 +08:00
|
|
|
|
|
2025-09-05 14:27:29 +08:00
|
|
|
|
const titleText = computed(() => {
|
|
|
|
|
return props.chartConfig.option.titleText;
|
|
|
|
|
});
|
|
|
|
|
const selectOptionMode = computed(() => {
|
|
|
|
|
return props.chartConfig.option.selectOptionMode;
|
|
|
|
|
});
|
|
|
|
|
const selectOptions = computed(() => {
|
|
|
|
|
return props.chartConfig.option.selectOptions;
|
|
|
|
|
});
|
|
|
|
|
const inSelectOptions = computed(() => {
|
|
|
|
|
return props.chartConfig.option.inSelectOptions;
|
|
|
|
|
});
|
2025-09-03 21:17:52 +08:00
|
|
|
|
watch(
|
|
|
|
|
() => props.chartConfig.option.dataset,
|
|
|
|
|
(newData: any) => {
|
|
|
|
|
updataUnit();
|
|
|
|
|
option.value.dataset = newData
|
2025-09-03 12:05:17 +08:00
|
|
|
|
}, {
|
2025-09-03 21:17:52 +08:00
|
|
|
|
immediate: true,
|
|
|
|
|
deep: false
|
|
|
|
|
}
|
|
|
|
|
)
|
2025-09-03 12:05:17 +08:00
|
|
|
|
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
|
|
|
|
|
props.chartConfig.option.dataset = newData
|
|
|
|
|
})
|
2025-09-05 14:27:29 +08:00
|
|
|
|
const handleHeaderSelectChange = (value: string) => {
|
|
|
|
|
console.log('模式1/2选中值:', value);
|
|
|
|
|
}
|
|
|
|
|
const handleInSelect = (value: string) => {
|
|
|
|
|
console.log('模式3选中值:', value);
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-03 12:05:17 +08:00
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
2025-09-03 21:17:52 +08:00
|
|
|
|
// 更新显示单位
|
|
|
|
|
updataUnit();
|
2025-09-03 12:05:17 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
@include go('energy-box') {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
|
|
.content {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|