Commit 344d8d620ab253a11f438c3f8bf683ababdedd28
1 parent
ed905973
feat(src/packages/components): 大屏新增图表组件可以进行自定义颜色,每个图表都可以自定义自己的颜色,使用方法文档已经更新
Showing
8 changed files
with
150 additions
and
12 deletions
| ... | ... | @@ -298,6 +298,36 @@ |
| 298 | 298 | </setting-item-box> |
| 299 | 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 | 331 | <collapse-item v-if="visualMap" name="视觉映射"> |
| 302 | 332 | <template #header> |
| 303 | 333 | <n-switch v-model:value="visualMap.show" size="small"></n-switch> |
| ... | ... | @@ -343,15 +373,19 @@ |
| 343 | 373 | </template> |
| 344 | 374 | |
| 345 | 375 | <script setup lang="ts"> |
| 346 | -import { PropType, computed, watch } from 'vue' | |
| 376 | +import { PropType, computed, watch, ref } from 'vue' | |
| 347 | 377 | import { GlobalThemeJsonType } from '@/settings/chartThemes/index' |
| 348 | 378 | import { axisConfig, legendConfig } from '@/packages/chartConfiguration/echarts/index' |
| 349 | 379 | import { CollapseItem, SettingItemBox, SettingItem, GlobalSettingPosition } from '@/components/Pages/ChartItemSetting' |
| 350 | 380 | import { icon } from '@/plugins' |
| 351 | 381 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
| 352 | 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 | 390 | const props = defineProps({ |
| 357 | 391 | optionData: { |
| ... | ... | @@ -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 | 406 | const chartEditStore = useChartEditStore() |
| 369 | 407 | const themeSetting = computed(() => { |
| 370 | 408 | const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting |
| ... | ... | @@ -415,4 +453,85 @@ watch(() => legend.value && legend.value.textStyle.color, (newVal) => { |
| 415 | 453 | immediate: true, |
| 416 | 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 | 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 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | +export interface ChartCustomColor { | |
| 189 | + name: string | |
| 190 | + color: string[] | |
| 191 | +} | |
| 192 | + | |
| 193 | + | |
| 188 | 194 | export interface CreateComponentType extends PublicConfigType, requestConfig { |
| 189 | 195 | key: string |
| 190 | 196 | chartConfig: ConfigType |
| ... | ... | @@ -192,6 +198,7 @@ export interface CreateComponentType extends PublicConfigType, requestConfig { |
| 192 | 198 | groupList?: Array<CreateComponentType> |
| 193 | 199 | saveHistoryInput?: string // THINGS_KIT 新增一个接口字段 saveHistoryInput,用于记录当前组件id和输入框的内容,这里不能重写,有很多地方引用到的,这里升级版本有冲突 |
| 194 | 200 | wsOriginalMessage?: any |
| 201 | + colors?: ChartCustomColor // THINGS_KIT 新增一个接口字段 用于组件自定义颜色,一般是图表组件 | |
| 195 | 202 | } |
| 196 | 203 | |
| 197 | 204 | // 组件成组实例类 | ... | ... |
| ... | ... | @@ -40,7 +40,7 @@ import { ref, computed } from 'vue' |
| 40 | 40 | import cloneDeep from 'lodash/cloneDeep' |
| 41 | 41 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
| 42 | 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 | 44 | import { useDesignStore } from '@/store/modules/designStore/designStore' |
| 45 | 45 | import { loadAsyncComponent, colorCustomMerge } from '@/utils' |
| 46 | 46 | import { icon } from '@/plugins' | ... | ... |
| ... | ... | @@ -93,7 +93,8 @@ |
| 93 | 93 | <!-- 底部 --> |
| 94 | 94 | <template #action> |
| 95 | 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 | 98 | </n-space> |
| 98 | 99 | </template> |
| 99 | 100 | </n-card> |
| ... | ... | @@ -101,22 +102,27 @@ |
| 101 | 102 | </template> |
| 102 | 103 | |
| 103 | 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 | 106 | import cloneDeep from 'lodash/cloneDeep' |
| 106 | 107 | import noData from '@/assets/images/canvas/noData.png' |
| 107 | 108 | import { getUUID, goDialog } from '@/utils' |
| 108 | 109 | import { icon } from '@/plugins' |
| 109 | -import { UvIndex } from '@vicons/carbon' | |
| 110 | 110 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
| 111 | 111 | import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditStore.d' |
| 112 | 112 | import { CreateColorRender } from '../CreateColorRender/index' |
| 113 | +import { useTargetData } from "@/views/chart/ContentConfigurations/components/hooks/useTargetData.hook" | |
| 114 | + | |
| 115 | + | |
| 113 | 116 | |
| 114 | 117 | const props = defineProps({ |
| 115 | - modelShow: Boolean | |
| 118 | + modelShow: Boolean, | |
| 119 | + applicationGroup: Boolean, | |
| 116 | 120 | }) |
| 117 | 121 | const emit = defineEmits(['update:modelShow', 'editSaveHandle']) |
| 118 | 122 | const { DuplicateOutlineIcon, TrashIcon, ArrowDownIcon } = icon.ionicons5 |
| 119 | 123 | |
| 124 | +const { targetData } = useTargetData() | |
| 125 | + | |
| 120 | 126 | type ColorType = { |
| 121 | 127 | id: string |
| 122 | 128 | name: string |
| ... | ... | @@ -161,6 +167,7 @@ const selectThemeColor = computed(() => chartEditStore.getEditCanvasConfig.chart |
| 161 | 167 | |
| 162 | 168 | // 选择 |
| 163 | 169 | const selectHandle = (item: ColorType) => { |
| 170 | + targetData.value.colors = item | |
| 164 | 171 | if (item.id === selectColorId.value) return |
| 165 | 172 | if (updateColor.value !== undefined) { |
| 166 | 173 | goDialog({ |
| ... | ... | @@ -281,6 +288,11 @@ const closeHandle = () => { |
| 281 | 288 | const colorBackgroundImage = (item: ColorType) => { |
| 282 | 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 | 296 | </script> |
| 285 | 297 | |
| 286 | 298 | <style scoped lang="scss"> | ... | ... |
| ... | ... | @@ -38,7 +38,7 @@ |
| 38 | 38 | :is="item.chartConfig.chartKey" |
| 39 | 39 | :chartConfig="item" |
| 40 | 40 | :themeSetting="themeSetting" |
| 41 | - :themeColor="themeColor" | |
| 41 | + :themeColor="item.colors ? item.colors : themeColor" | |
| 42 | 42 | :style="{ |
| 43 | 43 | ...useSizeStyle(item.attr), |
| 44 | 44 | ...getFilterStyle(item.styles), | ... | ... |
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | @contextmenu="handleContextMenu($event, item, optionsHandle)"> |
| 29 | 29 | <component class="edit-content-chart" :class="animationsClass(item.styles.animations)" |
| 30 | 30 | :is="item.chartConfig.chartKey" :chartConfig="item" :themeSetting="themeSetting" |
| 31 | - :themeColor="themeColor" :style="{ | |
| 31 | + :themeColor="item.colors ? item.colors : themeColor" :style="{ | |
| 32 | 32 | ...useSizeStyle(item.attr), |
| 33 | 33 | ...getFilterStyle(item.styles), |
| 34 | 34 | ...getTransformStyle(item.styles), | ... | ... |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | :groupData="(item as CreateComponentGroupType)" |
| 21 | 21 | :groupIndex="index" |
| 22 | 22 | :themeSetting="themeSetting" |
| 23 | - :themeColor="themeColor" | |
| 23 | + :themeColor="item.colors ? item.colors : themeColor" | |
| 24 | 24 | ></preview-render-group> |
| 25 | 25 | |
| 26 | 26 | <!-- 单组件 --> |
| ... | ... | @@ -30,7 +30,7 @@ |
| 30 | 30 | :id="item.id" |
| 31 | 31 | :chartConfig="item" |
| 32 | 32 | :themeSetting="themeSetting" |
| 33 | - :themeColor="themeColor" | |
| 33 | + :themeColor="item.colors ? item.colors : themeColor" | |
| 34 | 34 | :style="{ |
| 35 | 35 | ...getSizeStyle(item.attr), |
| 36 | 36 | ...getFilterStyle(item.styles), | ... | ... |