|
@@ -1,15 +1,17 @@
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
-import { onMounted, watch, reactive } from 'vue'
|
|
|
|
|
|
|
+import { onMounted, watch, reactive,PropType } from 'vue'
|
|
|
import merge from 'lodash/merge'
|
|
import merge from 'lodash/merge'
|
|
|
import cloneDeep from 'lodash/cloneDeep'
|
|
import cloneDeep from 'lodash/cloneDeep'
|
|
|
|
|
+import { useChartDataFetch } from '@/hooks'
|
|
|
|
|
+import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
|
|
|
|
+import config from './config'
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
chartConfig: {
|
|
chartConfig: {
|
|
|
- type: Object,
|
|
|
|
|
|
|
+ type: Object as PropType<config>,
|
|
|
default: () => ({})
|
|
default: () => ({})
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
-console.log(props.chartConfig.option)
|
|
|
|
|
type DataProps = {
|
|
type DataProps = {
|
|
|
name: string | number
|
|
name: string | number
|
|
|
value: string | number
|
|
value: string | number
|
|
@@ -18,7 +20,7 @@ type DataProps = {
|
|
|
|
|
|
|
|
interface StateProps {
|
|
interface StateProps {
|
|
|
defaultConfig: {
|
|
defaultConfig: {
|
|
|
- dataSet: {
|
|
|
|
|
|
|
+ dataset: {
|
|
|
dimensions: Array<string>
|
|
dimensions: Array<string>
|
|
|
source: Array<DataProps>
|
|
source: Array<DataProps>
|
|
|
}
|
|
}
|
|
@@ -36,7 +38,7 @@ interface StateProps {
|
|
|
|
|
|
|
|
const state = reactive<StateProps>({
|
|
const state = reactive<StateProps>({
|
|
|
defaultConfig: {
|
|
defaultConfig: {
|
|
|
- dataSet: { dimensions: ['name', 'value'], source: [] },
|
|
|
|
|
|
|
+ dataset: { dimensions: ['name', 'value'], source: [] },
|
|
|
colors: ['#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293'],
|
|
colors: ['#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293'],
|
|
|
unit: '',
|
|
unit: '',
|
|
|
showValue: false,
|
|
showValue: false,
|
|
@@ -52,31 +54,30 @@ const state = reactive<StateProps>({
|
|
|
watch(
|
|
watch(
|
|
|
() => props.chartConfig.option,
|
|
() => props.chartConfig.option,
|
|
|
newVal => {
|
|
newVal => {
|
|
|
- console.log(newVal)
|
|
|
|
|
- calcData()
|
|
|
|
|
|
|
+ calcData(newVal)
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
deep: true
|
|
deep: true
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-function calcData() {
|
|
|
|
|
- mergeConfig()
|
|
|
|
|
|
|
+function calcData(data:any) {
|
|
|
|
|
+ mergeConfig(props.chartConfig.option)
|
|
|
|
|
|
|
|
calcCapsuleLengthAndLabelData()
|
|
calcCapsuleLengthAndLabelData()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function mergeConfig() {
|
|
|
|
|
- state.mergedConfig = merge(cloneDeep(state.defaultConfig), props.chartConfig.option || {})
|
|
|
|
|
|
|
+function mergeConfig(data:any) {
|
|
|
|
|
+ state.mergedConfig = merge(cloneDeep(state.defaultConfig), data || {})
|
|
|
console.log('state.mergedConfig', state.mergedConfig)
|
|
console.log('state.mergedConfig', state.mergedConfig)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function calcCapsuleLengthAndLabelData() {
|
|
function calcCapsuleLengthAndLabelData() {
|
|
|
- const { source } = state.mergedConfig.dataSet
|
|
|
|
|
|
|
+ const { source } = state.mergedConfig.dataset
|
|
|
if (!source.length) return
|
|
if (!source.length) return
|
|
|
|
|
|
|
|
state.capsuleItemHeight = handle(state.mergedConfig.itemHeight)
|
|
state.capsuleItemHeight = handle(state.mergedConfig.itemHeight)
|
|
|
- const capsuleValue = source.map((item: DataProps) => item[state.mergedConfig.dataSet.dimensions[1]])
|
|
|
|
|
|
|
+ const capsuleValue = source.map((item: DataProps) => item[state.mergedConfig.dataset.dimensions[1]])
|
|
|
|
|
|
|
|
const maxValue = Math.max(...capsuleValue)
|
|
const maxValue = Math.max(...capsuleValue)
|
|
|
|
|
|
|
@@ -94,7 +95,12 @@ const handle = (val: string | number) => {
|
|
|
return val + 'px'
|
|
return val + 'px'
|
|
|
}
|
|
}
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
- calcData()
|
|
|
|
|
|
|
+ calcData(props.chartConfig.option)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+// 预览
|
|
|
|
|
+useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
|
|
|
|
|
+ calcData(newData)
|
|
|
})
|
|
})
|
|
|
</script>
|
|
</script>
|
|
|
<template>
|
|
<template>
|
|
@@ -102,11 +108,11 @@ onMounted(() => {
|
|
|
<template v-if="state.mergedConfig">
|
|
<template v-if="state.mergedConfig">
|
|
|
<div class="label-column">
|
|
<div class="label-column">
|
|
|
<div
|
|
<div
|
|
|
- v-for="item in state.mergedConfig.dataSet.source"
|
|
|
|
|
- :key="item[state.mergedConfig.dataSet.dimensions[0]]"
|
|
|
|
|
|
|
+ v-for="item in state.mergedConfig.dataset.source"
|
|
|
|
|
+ :key="item[state.mergedConfig.dataset.dimensions[0]]"
|
|
|
:style="{ height: state.capsuleItemHeight, lineHeight: state.capsuleItemHeight }"
|
|
:style="{ height: state.capsuleItemHeight, lineHeight: state.capsuleItemHeight }"
|
|
|
>
|
|
>
|
|
|
- {{ item[state.mergedConfig.dataSet.dimensions[0]] }}
|
|
|
|
|
|
|
+ {{ item[state.mergedConfig.dataset.dimensions[0]] }}
|
|
|
</div>
|
|
</div>
|
|
|
<div class="laset"> </div>
|
|
<div class="laset"> </div>
|
|
|
</div>
|
|
</div>
|