Commit cad041d816ddaabbdbb77101fdbb680766f944f1

Authored by fengwotao
1 parent a84b13d9

feat(src/packages): 图表修改水球图改变数值,静态数据未跟着改变问题

  1 +import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
  2 +import { CreateComponentType } from '@/packages/index.d'
  3 +import { OverrideWaterPoloConfig } from './index'
  4 +import cloneDeep from 'lodash/cloneDeep'
  5 +
  6 +export const shapes = [
  7 + {
  8 + label: '圆形',
  9 + value: 'circle'
  10 + },
  11 + {
  12 + label: '正方形',
  13 + value: 'rect'
  14 + },
  15 + {
  16 + label: '带圆角的正方形',
  17 + value: 'roundRect'
  18 + },
  19 + {
  20 + label: '正三角形',
  21 + value: 'triangle'
  22 + },
  23 + {
  24 + label: '菱形',
  25 + value: 'diamond'
  26 + },
  27 + {
  28 + label: '水滴',
  29 + value: 'pin'
  30 + },
  31 + {
  32 + label: '箭头',
  33 + value: 'arrow'
  34 + },
  35 +]
  36 +
  37 +export const includes = []
  38 +
  39 +export const option = {
  40 + dataset: 0.5,
  41 + series: [
  42 + {
  43 + type: 'liquidFill',
  44 + shape: shapes[0].value,
  45 + radius: '90%',
  46 + data: [0],
  47 + center: ['50%', '50%'],
  48 + color: [
  49 + {
  50 + type: 'linear',
  51 + x: 0,
  52 + y: 0,
  53 + x2: 0,
  54 + y2: 1,
  55 + colorStops: [
  56 + {
  57 + offset: 0,
  58 + color: '#446bf5',
  59 + },
  60 + {
  61 + offset: 1,
  62 + color: '#2ca3e2',
  63 + },
  64 + ],
  65 + globalCoord: false,
  66 + },
  67 + ],
  68 + backgroundStyle: {
  69 + borderWidth: 1,
  70 + color: 'rgba(51, 66, 127, 0.7)',
  71 + },
  72 + label: {
  73 + normal: {
  74 + textStyle: {
  75 + fontSize: 50,
  76 + color: '#fff',
  77 + },
  78 + },
  79 + },
  80 + outline: {
  81 + show: false,
  82 + borderDistance: 10,
  83 + itemStyle: {
  84 + borderWidth: 2,
  85 + borderColor: '#112165'
  86 + }
  87 + }
  88 + }
  89 + ]
  90 +}
  91 +
  92 +export default class Config extends PublicConfigClass implements CreateComponentType
  93 +{
  94 + public key = OverrideWaterPoloConfig.key
  95 + public chartConfig = cloneDeep(OverrideWaterPoloConfig)
  96 + public option = echartOptionProfixHandle(option, includes)
  97 +}
... ...
  1 +<template>
  2 + <CollapseItem
  3 + v-for="(item, index) in seriesList"
  4 + :key="index"
  5 + name="水球"
  6 + :expanded="true"
  7 + >
  8 + <SettingItemBox name="内容">
  9 + <SettingItem name="数值">
  10 + <n-input-number
  11 + v-model:value="optionData.dataset"
  12 + :min="0"
  13 + :step="0.01"
  14 + size="small"
  15 + placeholder="水球数值"
  16 + ></n-input-number>
  17 + </SettingItem>
  18 + <SettingItem name="形状">
  19 + <n-select v-model:value="item.shape" :options="shapes" placeholder="选择形状" />
  20 + </SettingItem>
  21 + <SettingItem name="文本">
  22 + <n-input-number v-model:value="item.label.normal.textStyle.fontSize" :min="0" :step="1" size="small" placeholder="文字大小">
  23 + </n-input-number>
  24 + </SettingItem>
  25 + <SettingItem name="颜色1">
  26 + <n-color-picker
  27 + size="small"
  28 + :modes="['hex']"
  29 + v-model:value="item.color[0].colorStops[0].color"
  30 + ></n-color-picker>
  31 + </SettingItem>
  32 + <SettingItem name="颜色2">
  33 + <n-color-picker
  34 + size="small"
  35 + :modes="['hex']"
  36 + v-model:value="item.color[0].colorStops[1].color"
  37 + ></n-color-picker>
  38 + </SettingItem>
  39 + </SettingItemBox>
  40 + <SettingItemBox name="背景" :alone="true">
  41 + <SettingItem>
  42 + <n-color-picker
  43 + size="small"
  44 + :modes="['hex']"
  45 + v-model:value="item.backgroundStyle.color"
  46 + ></n-color-picker>
  47 + </SettingItem>
  48 + </SettingItemBox>
  49 + </CollapseItem>
  50 +</template>
  51 +
  52 +<script setup lang="ts">
  53 +import { PropType, computed } from 'vue'
  54 +import { option, shapes } from './config'
  55 +import {
  56 + CollapseItem,
  57 + SettingItemBox,
  58 + SettingItem,
  59 +} from '@/components/Pages/ChartItemSetting'
  60 +
  61 +const props = defineProps({
  62 + optionData: {
  63 + type: Object as PropType<typeof option>,
  64 + required: true,
  65 + },
  66 +})
  67 +
  68 +const seriesList = computed(() => {
  69 + return props.optionData.series
  70 +})
  71 +</script>
... ...
  1 +import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d'
  2 +import { ChatCategoryEnum, ChatCategoryEnumName } from '@/packages/components/Charts/index.d'
  3 +import { useWidgetKey } from '@/packages/external/useWidgetKey'
  4 +
  5 +const { key, conKey, chartKey } = useWidgetKey('OverrideWaterPolo', true)
  6 +
  7 +export const OverrideWaterPoloConfig: ConfigType = {
  8 + key,
  9 + chartKey,
  10 + conKey,
  11 + title: '自定义水球图',
  12 + category: ChatCategoryEnum.MORE,
  13 + categoryName: ChatCategoryEnumName.MORE,
  14 + package: PackagesCategoryEnum.CHARTS,
  15 + chartFrame: ChartFrameEnum.COMMON,
  16 + image: 'water_WaterPolo.png'
  17 +}
... ...
  1 +<template>
  2 + <v-chart :theme="themeColor" :init-options="initOptions" :option="option.value" autoresize></v-chart>
  3 +</template>
  4 +
  5 +<script setup lang="ts">
  6 +import { PropType, watch, reactive } from 'vue'
  7 +import VChart from 'vue-echarts'
  8 +import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook'
  9 +import { use } from 'echarts/core'
  10 +import 'echarts-liquidfill/src/liquidFill.js'
  11 +import { CanvasRenderer } from 'echarts/renderers'
  12 +import { GridComponent } from 'echarts/components'
  13 +import config from './config'
  14 +import { isPreview, isString, isNumber, colorGradientCustomMerge } from '@/utils'
  15 +import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
  16 +import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  17 +import { useChartDataFetch } from '@/hooks'
  18 +
  19 +const props = defineProps({
  20 + themeSetting: {
  21 + type: Object,
  22 + required: true
  23 + },
  24 + themeColor: {
  25 + type: Object,
  26 + required: true
  27 + },
  28 + chartConfig: {
  29 + type: Object as PropType<config>,
  30 + required: true
  31 + }
  32 +})
  33 +
  34 +const initOptions = useCanvasInitOptions(props.chartConfig.option, props.themeSetting)
  35 +
  36 +use([CanvasRenderer, GridComponent])
  37 +
  38 +const chartEditStore = useChartEditStore()
  39 +
  40 +const option = reactive({
  41 + value: {}
  42 +})
  43 +
  44 +// 渐变色处理
  45 +watch(
  46 + () => chartEditStore.getEditCanvasConfig.chartThemeColor,
  47 + (newColor: keyof typeof chartColorsSearch) => {
  48 + try {
  49 + if (!isPreview()) {
  50 + const themeColor =
  51 + colorGradientCustomMerge(chartEditStore.getEditCanvasConfig.chartCustomThemeColorInfo)[newColor] ||
  52 + colorGradientCustomMerge(chartEditStore.getEditCanvasConfig.chartCustomThemeColorInfo)[defaultTheme]
  53 + // 背景颜色
  54 + props.chartConfig.option.series[0].backgroundStyle.color = themeColor[2]
  55 + // 水球颜色
  56 + props.chartConfig.option.series[0].color[0].colorStops = [
  57 + {
  58 + offset: 0,
  59 + color: themeColor[0]
  60 + },
  61 + {
  62 + offset: 1,
  63 + color: themeColor[1]
  64 + }
  65 + ]
  66 + }
  67 + option.value = props.chartConfig.option
  68 + } catch (error) {
  69 + console.log(error)
  70 + }
  71 + },
  72 + {
  73 + immediate: true
  74 + }
  75 +)
  76 +
  77 +// 数据处理
  78 +const dataHandle = (newData: number | string) => {
  79 + newData = isString(newData) ? parseFloat(newData) : newData
  80 + return parseFloat(newData.toFixed(2))
  81 +}
  82 +
  83 +// 编辑
  84 +watch(
  85 + () => props.chartConfig.option.dataset,
  86 + newData => {
  87 + if (!isString(newData) && !isNumber(newData)) return
  88 + props.chartConfig.option.series[0].data = [dataHandle(newData)]
  89 + option.value = props.chartConfig.option
  90 + },
  91 + {
  92 + immediate: true,
  93 + deep: false
  94 + }
  95 +)
  96 +
  97 +// 预览
  98 +useChartDataFetch(props.chartConfig, useChartEditStore, (newData: number) => {
  99 + // @ts-ignore
  100 + option.value.series[0].data = [dataHandle(newData)]
  101 +})
  102 +</script>
... ...
... ... @@ -21,6 +21,7 @@ import { OverridePieCircleConfig } from '@/packages/components/external/Charts/P
21 21 import { OverrideMapBaseConfig } from '@/packages/components/external/Charts/Maps/OverrideMapBase'
22 22 import { OverrideILoadConfigurationframeConfig } from '@/packages/components/external/Informations/Mores/OverrideILoadConfigurationframe'
23 23 import { OverrideVideoConfig } from '@/packages/components/external/Informations/Mores/OverrideVideo'
  24 +import { OverrideWaterPoloConfig } from '@/packages/components/external/Charts/Mores/OverrideWaterPolo'
24 25
25 26 export function useInjectLib(packagesList: EPackagesType) {
26 27 packagesList[EPackagesCategoryEnum.COMPOSES] = ComposesList
... ... @@ -43,8 +44,13 @@ export function useInjectLib(packagesList: EPackagesType) {
43 44 addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideProcessConfig)
44 45 addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverridePieCircleConfig)
45 46 addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideMapBaseConfig)
46   - addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideILoadConfigurationframeConfig)
  47 + addWidgetToCategoryByCategoryName(
  48 + packagesList,
  49 + PackagesCategoryEnum.INFORMATIONS,
  50 + OverrideILoadConfigurationframeConfig
  51 + )
47 52 addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideVideoConfig)
  53 + addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideWaterPoloConfig)
48 54 }
49 55
50 56 /**
... ...