Commit 344d8d620ab253a11f438c3f8bf683ababdedd28

Authored by fengtao
1 parent ed905973

feat(src/packages/components): 大屏新增图表组件可以进行自定义颜色,每个图表都可以自定义自己的颜色,使用方法文档已经更新

@@ -298,6 +298,36 @@ @@ -298,6 +298,36 @@
298 </setting-item-box> 298 </setting-item-box>
299 </collapse-item> 299 </collapse-item>
300 300
  301 + <!-- 颜色 -->
  302 + <collapse-item name="颜色" expanded>
  303 + <n-card
  304 + v-for="(value, key) in chartCustomColor"
  305 + :key="key"
  306 + class="card-box"
  307 + size="small"
  308 + hoverable
  309 + embedded
  310 + >
  311 + <div class="go-flex-items-center">
  312 + <n-ellipsis style="text-align: left; width: 60px">{{ value?.name }} </n-ellipsis>
  313 + <span
  314 + class="theme-color-item"
  315 + v-for="colorItem in fetchShowColors(value!.color)"
  316 + :key="colorItem"
  317 + :style="{ backgroundColor: colorItem }"
  318 + ></span>
  319 + <div @click="createCustomColorHandle">
  320 + <n-icon size="18">
  321 + <add-icon></add-icon>
  322 + </n-icon>
  323 + </div>
  324 + </div>
  325 + <div class="theme-bottom" :style="{ backgroundImage: colorBackgroundImage(value!) }"></div>
  326 + </n-card>
  327 + <!-- 自定义颜色 modal -->
  328 + <create-color v-model:modelShow="createColorModelShow" :applicationGroup="applicationGroup"></create-color>
  329 + </collapse-item>
  330 +
301 <collapse-item v-if="visualMap" name="视觉映射"> 331 <collapse-item v-if="visualMap" name="视觉映射">
302 <template #header> 332 <template #header>
303 <n-switch v-model:value="visualMap.show" size="small"></n-switch> 333 <n-switch v-model:value="visualMap.show" size="small"></n-switch>
@@ -343,15 +373,19 @@ @@ -343,15 +373,19 @@
343 </template> 373 </template>
344 374
345 <script setup lang="ts"> 375 <script setup lang="ts">
346 -import { PropType, computed, watch } from 'vue' 376 +import { PropType, computed, watch, ref } from 'vue'
347 import { GlobalThemeJsonType } from '@/settings/chartThemes/index' 377 import { GlobalThemeJsonType } from '@/settings/chartThemes/index'
348 import { axisConfig, legendConfig } from '@/packages/chartConfiguration/echarts/index' 378 import { axisConfig, legendConfig } from '@/packages/chartConfiguration/echarts/index'
349 import { CollapseItem, SettingItemBox, SettingItem, GlobalSettingPosition } from '@/components/Pages/ChartItemSetting' 379 import { CollapseItem, SettingItemBox, SettingItem, GlobalSettingPosition } from '@/components/Pages/ChartItemSetting'
350 import { icon } from '@/plugins' 380 import { icon } from '@/plugins'
351 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' 381 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
352 import EchartsRendererSetting from './EchartsRendererSetting.vue' 382 import EchartsRendererSetting from './EchartsRendererSetting.vue'
  383 +import cloneDeep from 'lodash/cloneDeep'
  384 +import { loadAsyncComponent, colorCustomMerge } from '@/utils'
  385 +import { useDesignStore } from '@/store/modules/designStore/designStore'
  386 +import { useTargetData } from "@/views/chart/ContentConfigurations/components/hooks/useTargetData.hook"
353 387
354 -const { HelpOutlineIcon } = icon.ionicons5 388 +const { HelpOutlineIcon, AddIcon } = icon.ionicons5
355 389
356 const props = defineProps({ 390 const props = defineProps({
357 optionData: { 391 optionData: {
@@ -365,6 +399,10 @@ const props = defineProps({ @@ -365,6 +399,10 @@ const props = defineProps({
365 } 399 }
366 }) 400 })
367 401
  402 +const { targetData } = useTargetData()
  403 +
  404 +const CreateColor = loadAsyncComponent(() => import('@/views/chart/ContentConfigurations/components/CanvasPage/components/CreateColor/index.vue'))
  405 +
368 const chartEditStore = useChartEditStore() 406 const chartEditStore = useChartEditStore()
369 const themeSetting = computed(() => { 407 const themeSetting = computed(() => {
370 const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting 408 const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting
@@ -415,4 +453,85 @@ watch(() => legend.value && legend.value.textStyle.color, (newVal) => { @@ -415,4 +453,85 @@ watch(() => legend.value && legend.value.textStyle.color, (newVal) => {
415 immediate: true, 453 immediate: true,
416 deep: true, 454 deep: true,
417 }) 455 })
  456 +
  457 +// 底色
  458 +const colorBackgroundImage = (item: { color: string[] }) => {
  459 + return `linear-gradient(to right, ${item.color[0]} 0%, ${item.color[5]} 100%)`
  460 +}
  461 +
  462 +// 获取用来展示的色号
  463 +const fetchShowColors = (colors: Array<string>) => {
  464 + return cloneDeep(colors).splice(0, 6)
  465 +}
  466 +
  467 +// 自定义颜色
  468 +const chartCustomColor = computed(() => {
  469 + const colorCustomMergeData = colorCustomMerge(chartEditStore.getEditCanvasConfig.chartCustomThemeColorInfo)
  470 + if(Reflect.has(targetData.value, 'colors')){
  471 + return {
  472 + 'chartCustom': targetData.value?.colors
  473 + }
  474 + } else {
  475 + return {
  476 + 'chartCustom': colorCustomMergeData[chartEditStore.getEditCanvasConfig.chartThemeColor]
  477 + }
  478 + }
  479 +})
  480 +
  481 +// 全局颜色
  482 +const designStore = useDesignStore()
  483 +
  484 +// 颜色
  485 +const themeColor = computed(() => {
  486 + return designStore.getAppTheme
  487 +})
  488 +
  489 +const createColorModelShow = ref(false)
  490 +
  491 +const applicationGroup = ref(false)
  492 +
  493 +const createCustomColorHandle = () => {
  494 + createColorModelShow.value = true
  495 + applicationGroup.value = true
  496 +}
418 </script> 497 </script>
  498 +
  499 +<style lang="scss" scoped>
  500 +$radius: 10px;
  501 +$itemRadius: 6px;
  502 +
  503 +.card-box {
  504 + cursor: pointer;
  505 + margin-top: 15px;
  506 + padding: 0;
  507 + @include fetch-bg-color('background-color4-shallow');
  508 + border-radius: $radius;
  509 + overflow: hidden;
  510 +
  511 + &.selected {
  512 + border: 2px solid v-bind('themeColor');
  513 + border-bottom: 1px solid rgba(0, 0, 0, 0);
  514 + }
  515 + &:first-child {
  516 + margin-top: 5px;
  517 + }
  518 + .go-flex-items-center {
  519 + justify-content: space-between;
  520 + align-items: center;
  521 + margin-top: -4px;
  522 + }
  523 + .theme-color-item {
  524 + display: inline-block;
  525 + width: 20px;
  526 + height: 20px;
  527 + border-radius: $itemRadius;
  528 + }
  529 + .theme-bottom {
  530 + position: absolute;
  531 + left: 0;
  532 + bottom: 0px;
  533 + width: 100%;
  534 + height: 3px;
  535 + }
  536 +}
  537 +</style>
@@ -185,6 +185,12 @@ export interface PublicConfigType { @@ -185,6 +185,12 @@ export interface PublicConfigType {
185 } 185 }
186 } 186 }
187 187
  188 +export interface ChartCustomColor {
  189 + name: string
  190 + color: string[]
  191 +}
  192 +
  193 +
188 export interface CreateComponentType extends PublicConfigType, requestConfig { 194 export interface CreateComponentType extends PublicConfigType, requestConfig {
189 key: string 195 key: string
190 chartConfig: ConfigType 196 chartConfig: ConfigType
@@ -192,6 +198,7 @@ export interface CreateComponentType extends PublicConfigType, requestConfig { @@ -192,6 +198,7 @@ export interface CreateComponentType extends PublicConfigType, requestConfig {
192 groupList?: Array<CreateComponentType> 198 groupList?: Array<CreateComponentType>
193 saveHistoryInput?: string // THINGS_KIT 新增一个接口字段 saveHistoryInput,用于记录当前组件id和输入框的内容,这里不能重写,有很多地方引用到的,这里升级版本有冲突 199 saveHistoryInput?: string // THINGS_KIT 新增一个接口字段 saveHistoryInput,用于记录当前组件id和输入框的内容,这里不能重写,有很多地方引用到的,这里升级版本有冲突
194 wsOriginalMessage?: any 200 wsOriginalMessage?: any
  201 + colors?: ChartCustomColor // THINGS_KIT 新增一个接口字段 用于组件自定义颜色,一般是图表组件
195 } 202 }
196 203
197 // 组件成组实例类 204 // 组件成组实例类
@@ -40,7 +40,7 @@ import { ref, computed } from 'vue' @@ -40,7 +40,7 @@ import { ref, computed } from 'vue'
40 import cloneDeep from 'lodash/cloneDeep' 40 import cloneDeep from 'lodash/cloneDeep'
41 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' 41 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
42 import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditStore.d' 42 import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
43 -import { chartColors, ChartColorsNameType } from '@/settings/chartThemes/index' 43 +import { ChartColorsNameType } from '@/settings/chartThemes/index'
44 import { useDesignStore } from '@/store/modules/designStore/designStore' 44 import { useDesignStore } from '@/store/modules/designStore/designStore'
45 import { loadAsyncComponent, colorCustomMerge } from '@/utils' 45 import { loadAsyncComponent, colorCustomMerge } from '@/utils'
46 import { icon } from '@/plugins' 46 import { icon } from '@/plugins'
@@ -93,7 +93,8 @@ @@ -93,7 +93,8 @@
93 <!-- 底部 --> 93 <!-- 底部 -->
94 <template #action> 94 <template #action>
95 <n-space justify="end"> 95 <n-space justify="end">
96 - <n-button @click="closeHandle">操作完成</n-button> 96 + <n-button @click="applicationGroupHandle" v-if="applicationGroup">应用此分组</n-button>
  97 + <n-button v-if="!applicationGroup" @click="closeHandle">操作完成</n-button>
97 </n-space> 98 </n-space>
98 </template> 99 </template>
99 </n-card> 100 </n-card>
@@ -101,22 +102,27 @@ @@ -101,22 +102,27 @@
101 </template> 102 </template>
102 103
103 <script setup lang="ts"> 104 <script setup lang="ts">
104 -import { ref, watch, computed, reactive, nextTick, onMounted } from 'vue' 105 +import { ref, watch, computed, reactive, nextTick } from 'vue'
105 import cloneDeep from 'lodash/cloneDeep' 106 import cloneDeep from 'lodash/cloneDeep'
106 import noData from '@/assets/images/canvas/noData.png' 107 import noData from '@/assets/images/canvas/noData.png'
107 import { getUUID, goDialog } from '@/utils' 108 import { getUUID, goDialog } from '@/utils'
108 import { icon } from '@/plugins' 109 import { icon } from '@/plugins'
109 -import { UvIndex } from '@vicons/carbon'  
110 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' 110 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
111 import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditStore.d' 111 import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
112 import { CreateColorRender } from '../CreateColorRender/index' 112 import { CreateColorRender } from '../CreateColorRender/index'
  113 +import { useTargetData } from "@/views/chart/ContentConfigurations/components/hooks/useTargetData.hook"
  114 +
  115 +
113 116
114 const props = defineProps({ 117 const props = defineProps({
115 - modelShow: Boolean 118 + modelShow: Boolean,
  119 + applicationGroup: Boolean,
116 }) 120 })
117 const emit = defineEmits(['update:modelShow', 'editSaveHandle']) 121 const emit = defineEmits(['update:modelShow', 'editSaveHandle'])
118 const { DuplicateOutlineIcon, TrashIcon, ArrowDownIcon } = icon.ionicons5 122 const { DuplicateOutlineIcon, TrashIcon, ArrowDownIcon } = icon.ionicons5
119 123
  124 +const { targetData } = useTargetData()
  125 +
120 type ColorType = { 126 type ColorType = {
121 id: string 127 id: string
122 name: string 128 name: string
@@ -161,6 +167,7 @@ const selectThemeColor = computed(() => chartEditStore.getEditCanvasConfig.chart @@ -161,6 +167,7 @@ const selectThemeColor = computed(() => chartEditStore.getEditCanvasConfig.chart
161 167
162 // 选择 168 // 选择
163 const selectHandle = (item: ColorType) => { 169 const selectHandle = (item: ColorType) => {
  170 + targetData.value.colors = item
164 if (item.id === selectColorId.value) return 171 if (item.id === selectColorId.value) return
165 if (updateColor.value !== undefined) { 172 if (updateColor.value !== undefined) {
166 goDialog({ 173 goDialog({
@@ -281,6 +288,11 @@ const closeHandle = () => { @@ -281,6 +288,11 @@ const closeHandle = () => {
281 const colorBackgroundImage = (item: ColorType) => { 288 const colorBackgroundImage = (item: ColorType) => {
282 return `linear-gradient(to right, ${item.color[0]} 0%, ${item.color[5]} 100%)` 289 return `linear-gradient(to right, ${item.color[0]} 0%, ${item.color[5]} 100%)`
283 } 290 }
  291 +
  292 +//应用此分组
  293 +const applicationGroupHandle = () => {
  294 + closeHandle()
  295 +}
284 </script> 296 </script>
285 297
286 <style scoped lang="scss"> 298 <style scoped lang="scss">
@@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
38 :is="item.chartConfig.chartKey" 38 :is="item.chartConfig.chartKey"
39 :chartConfig="item" 39 :chartConfig="item"
40 :themeSetting="themeSetting" 40 :themeSetting="themeSetting"
41 - :themeColor="themeColor" 41 + :themeColor="item.colors ? item.colors : themeColor"
42 :style="{ 42 :style="{
43 ...useSizeStyle(item.attr), 43 ...useSizeStyle(item.attr),
44 ...getFilterStyle(item.styles), 44 ...getFilterStyle(item.styles),
@@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
28 @contextmenu="handleContextMenu($event, item, optionsHandle)"> 28 @contextmenu="handleContextMenu($event, item, optionsHandle)">
29 <component class="edit-content-chart" :class="animationsClass(item.styles.animations)" 29 <component class="edit-content-chart" :class="animationsClass(item.styles.animations)"
30 :is="item.chartConfig.chartKey" :chartConfig="item" :themeSetting="themeSetting" 30 :is="item.chartConfig.chartKey" :chartConfig="item" :themeSetting="themeSetting"
31 - :themeColor="themeColor" :style="{ 31 + :themeColor="item.colors ? item.colors : themeColor" :style="{
32 ...useSizeStyle(item.attr), 32 ...useSizeStyle(item.attr),
33 ...getFilterStyle(item.styles), 33 ...getFilterStyle(item.styles),
34 ...getTransformStyle(item.styles), 34 ...getTransformStyle(item.styles),
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 :id="item.id" 24 :id="item.id"
25 :chartConfig="item" 25 :chartConfig="item"
26 :themeSetting="themeSetting" 26 :themeSetting="themeSetting"
27 - :themeColor="themeColor" 27 + :themeColor="item.colors ? item.colors : themeColor"
28 :style="{ 28 :style="{
29 ...getSizeStyle(item.attr), 29 ...getSizeStyle(item.attr),
30 ...getFilterStyle(item.styles), 30 ...getFilterStyle(item.styles),
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 :groupData="(item as CreateComponentGroupType)" 20 :groupData="(item as CreateComponentGroupType)"
21 :groupIndex="index" 21 :groupIndex="index"
22 :themeSetting="themeSetting" 22 :themeSetting="themeSetting"
23 - :themeColor="themeColor" 23 + :themeColor="item.colors ? item.colors : themeColor"
24 ></preview-render-group> 24 ></preview-render-group>
25 25
26 <!-- 单组件 --> 26 <!-- 单组件 -->
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 :id="item.id" 30 :id="item.id"
31 :chartConfig="item" 31 :chartConfig="item"
32 :themeSetting="themeSetting" 32 :themeSetting="themeSetting"
33 - :themeColor="themeColor" 33 + :themeColor="item.colors ? item.colors : themeColor"
34 :style="{ 34 :style="{
35 ...getSizeStyle(item.attr), 35 ...getSizeStyle(item.attr),
36 ...getFilterStyle(item.styles), 36 ...getFilterStyle(item.styles),