feat: 新增全局样式设置

This commit is contained in:
MTrun 2022-02-21 19:45:11 +08:00
parent 133c6bea6b
commit 8b890fb5e3
11 changed files with 162 additions and 61 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<VChart :theme="themeData" :option="option" autoresize /> <VChart :theme="themeColor" :option="option" autoresize />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -8,16 +8,22 @@ import VChart from 'vue-echarts'
import { use } from 'echarts/core' import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { BarChart } from 'echarts/charts' import { BarChart } from 'echarts/charts'
import config from './config'
import merge from 'lodash/merge'
import { import {
GridComponent, GridComponent,
TooltipComponent, TooltipComponent,
LegendComponent LegendComponent,
TitleComponent
} from 'echarts/components' } from 'echarts/components'
import config from './config'
const props = defineProps({ const props = defineProps({
themeData: { themeSetting: {
type: Object || String, type: Object,
required: true
},
themeColor: {
type: Object,
required: true required: true
}, },
chartData: { chartData: {
@ -31,10 +37,11 @@ use([
BarChart, BarChart,
GridComponent, GridComponent,
TooltipComponent, TooltipComponent,
LegendComponent LegendComponent,
TitleComponent
]) ])
const option = computed(() => { const option = computed(() => {
return props.chartData.option return merge(props.chartData.option, props.themeSetting)
}) })
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<VChart :theme="themeData" :option="option" autoresize /> <VChart :theme="themeColor" :option="option" autoresize />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -8,17 +8,22 @@ import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core' import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { BarChart } from 'echarts/charts' import { BarChart } from 'echarts/charts'
import merge from 'lodash/merge'
import config from './config'
import { import {
GridComponent, GridComponent,
TooltipComponent, TooltipComponent,
LegendComponent LegendComponent,
TitleComponent
} from 'echarts/components' } from 'echarts/components'
import config from './config'
const props = defineProps({ const props = defineProps({
themeData: { themeSetting: {
type: Object || String, type: Object,
default: 'dark', required: true
},
themeColor: {
type: Object,
required: true required: true
}, },
chartData: { chartData: {
@ -32,11 +37,12 @@ use([
BarChart, BarChart,
GridComponent, GridComponent,
TooltipComponent, TooltipComponent,
LegendComponent LegendComponent,
TitleComponent
]) ])
const option = computed(() => { const option = computed(() => {
return props.chartData.option return merge(props.chartData.option, props.themeSetting)
}) })
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<VChart :theme="themeData" :option="option" autoresize /> <VChart :theme="themeColor" :option="option" autoresize />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -8,17 +8,22 @@ import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core' import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts' import { LineChart } from 'echarts/charts'
import config from './config'
import merge from 'lodash/merge'
import { import {
GridComponent, GridComponent,
TooltipComponent, TooltipComponent,
LegendComponent LegendComponent,
TitleComponent
} from 'echarts/components' } from 'echarts/components'
import config from './config'
const props = defineProps({ const props = defineProps({
themeData: { themeSetting: {
type: Object || String, type: Object,
default: 'dark', required: true
},
themeColor: {
type: Object,
required: true required: true
}, },
chartData: { chartData: {
@ -32,10 +37,11 @@ use([
LineChart, LineChart,
GridComponent, GridComponent,
TooltipComponent, TooltipComponent,
LegendComponent LegendComponent,
TitleComponent
]) ])
const option = computed(() => { const option = computed(() => {
return props.chartData.option return merge(props.chartData.option, props.themeSetting)
}) })
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<VChart :theme="themeData" :option="option" autoresize /> <VChart :theme="themeColor" :option="option" autoresize />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -8,17 +8,22 @@ import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core' import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { PieChart } from 'echarts/charts' import { PieChart } from 'echarts/charts'
import merge from 'lodash/merge'
import config from './config'
import { import {
GridComponent, GridComponent,
TooltipComponent, TooltipComponent,
LegendComponent LegendComponent,
TitleComponent
} from 'echarts/components' } from 'echarts/components'
import config from './config'
const props = defineProps({ const props = defineProps({
themeData: { themeSetting: {
type: Object || String, type: Object,
default: 'dark', required: true
},
themeColor: {
type: Object,
required: true required: true
}, },
chartData: { chartData: {
@ -32,10 +37,11 @@ use([
PieChart, PieChart,
GridComponent, GridComponent,
TooltipComponent, TooltipComponent,
LegendComponent LegendComponent,
TitleComponent
]) ])
const option = computed(() => { const option = computed(() => {
return props.chartData.option return merge(props.chartData.option, props.themeSetting)
}) })
</script> </script>

View File

@ -0,0 +1,53 @@
{
"title": {
"textStyle": {
"color": "#464646"
},
"subtextStyle": {
"color": "#6e7079"
}
},
"xAxis": {
"nameTextStyle": {
"color": "#B9B8CE"
},
"axisLine": {
"lineStyle": {
"color": "#B9B8CE",
"width": 1
},
"onZero": true,
"onZeroAxisIndex": null
},
"splitLine": {
"lineStyle": {
"color": "#484753",
"width": 1
}
}
},
"yAxis": {
"nameTextStyle": {
"color": "#B9B8CE"
},
"axisLine": {
"lineStyle": {
"color": "#B9B8CE",
"width": 1
},
"onZero": true,
"onZeroAxisIndex": null
},
"splitLine": {
"lineStyle": {
"color": "#484753",
"width": 1
}
}
},
"legend": {
"textStyle": {
"color": "#B9B8CE"
}
}
}

View File

@ -10,6 +10,8 @@ import vintage from './themes/vintage.json'
import walden from './themes/walden.json' import walden from './themes/walden.json'
import westeros from './themes/westeros.json' import westeros from './themes/westeros.json'
import wonderland from './themes/wonderland.json' import wonderland from './themes/wonderland.json'
// 默认主题详细配置
import themeJson from './global.theme.json'
export const chartColors = { export const chartColors = {
dark, dark,
@ -26,8 +28,11 @@ export const chartColors = {
roma, roma,
} }
// 默认主题
export const defaultTheme = 'dark' export const defaultTheme = 'dark'
// 主题色列表
export type ChartColorsNameType = keyof typeof chartColorsName
export const chartColorsName = { export const chartColorsName = {
dark: '明亮', dark: '明亮',
customed: '暗淡', customed: '暗淡',
@ -43,6 +48,7 @@ export const chartColorsName = {
roma: '罗马红', roma: '罗马红',
} }
// 主题色列表
export const chartColorsshow = { export const chartColorsshow = {
dark: 'linear-gradient(to right, #4992ff 0%, #7cffb2 100%)', dark: 'linear-gradient(to right, #4992ff 0%, #7cffb2 100%)',
customed: 'linear-gradient(to right, #5470c6 0%, #91cc75 100%)', customed: 'linear-gradient(to right, #5470c6 0%, #91cc75 100%)',
@ -57,3 +63,7 @@ export const chartColorsshow = {
shine: 'linear-gradient(to right, #c12e34 0%, #0098d9 100%)', shine: 'linear-gradient(to right, #c12e34 0%, #0098d9 100%)',
roma: 'linear-gradient(to right, #e01f54 0%, #5e4ea5 100%)', roma: 'linear-gradient(to right, #e01f54 0%, #5e4ea5 100%)',
} }
// 默认主题详细配置
export type GlobalThemeJsonType = typeof themeJson
export const globalThemeJson = themeJson

View File

@ -1,5 +1,6 @@
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { HistoryActionTypeEnum } from '@/store/modules/chartHistoryStore/chartHistoryStore.d' import { HistoryActionTypeEnum } from '@/store/modules/chartHistoryStore/chartHistoryStore.d'
import { ChartColorsNameType, GlobalThemeJsonType } from '@/settings/chartThemes/index'
// 编辑画布属性 // 编辑画布属性
export enum EditCanvasTypeEnum { export enum EditCanvasTypeEnum {
@ -38,7 +39,8 @@ export enum EditCanvasConfigEnum {
BRIGHTNESS = 'brightness', BRIGHTNESS = 'brightness',
CONTRAST = 'contrast', CONTRAST = 'contrast',
UN_OPACITY = 'unOpacity', UN_OPACITY = 'unOpacity',
CHART_THEME = 'chartTheme', CHART_THEME_COLOR = 'chartThemeColor',
CHART_THEME_SETTING = 'chartThemeSetting',
BACKGROUND = 'background', BACKGROUND = 'background',
BACKGROUND_IAMGE = 'backgroundImage', BACKGROUND_IAMGE = 'backgroundImage',
SELECT_COLOR = 'selectColor' SELECT_COLOR = 'selectColor'
@ -63,7 +65,9 @@ export interface EditCanvasConfigType {
[EditCanvasConfigEnum.BACKGROUND]?: string [EditCanvasConfigEnum.BACKGROUND]?: string
[EditCanvasConfigEnum.BACKGROUND_IAMGE]?: string | null [EditCanvasConfigEnum.BACKGROUND_IAMGE]?: string | null
// 图表主题颜色 // 图表主题颜色
[EditCanvasConfigEnum.CHART_THEME]: string [EditCanvasConfigEnum.CHART_THEME_COLOR]: ChartColorsNameType
// 图表全局配置
[EditCanvasConfigEnum.CHART_THEME_SETTING]: GlobalThemeJsonType
// 图表主题颜色 // 图表主题颜色
[EditCanvasConfigEnum.SELECT_COLOR]: boolean [EditCanvasConfigEnum.SELECT_COLOR]: boolean
} }

View File

@ -3,7 +3,7 @@ import { getUUID, loadingStart, loadingFinish, loadingError } from '@/utils'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
import { defaultTheme } from '@/settings/chartThemes/index' import { defaultTheme, globalThemeJson } from '@/settings/chartThemes/index'
// 记录记录 // 记录记录
import { useChartHistoryStoreStore } from '@/store/modules/chartHistoryStore/chartHistoryStore' import { useChartHistoryStoreStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
import { HistoryActionTypeEnum, HistoryItemType, HistoryTargetTypeEnum } from '@/store/modules/chartHistoryStore/chartHistoryStore.d' import { HistoryActionTypeEnum, HistoryItemType, HistoryTargetTypeEnum } from '@/store/modules/chartHistoryStore/chartHistoryStore.d'
@ -38,6 +38,20 @@ export const useChartEditStoreStore = defineStore({
// 拖拽中 // 拖拽中
isDrag: false isDrag: false
}, },
// 右键菜单
rightMenuShow: false,
// 鼠标定位
mousePosition: {
x: 0,
y: 0
},
// 目标图表
targetChart: {
hoverId: undefined,
selectId: undefined
},
// 记录临时数据(复制等)
recordChart: undefined,
// 画布属性(需存储给后端) // 画布属性(需存储给后端)
editCanvasConfig: { editCanvasConfig: {
// 默认宽度 // 默认宽度
@ -60,22 +74,10 @@ export const useChartEditStoreStore = defineStore({
// 是否使用纯颜色 // 是否使用纯颜色
selectColor: true, selectColor: true,
// chart 主题色 // chart 主题色
chartTheme: defaultTheme || 'dark' chartThemeColor: defaultTheme || 'dark',
// 全局配置
chartThemeSetting: globalThemeJson
}, },
// 右键菜单
rightMenuShow: false,
// 鼠标定位
mousePosition: {
x: 0,
y: 0
},
// 目标图表
targetChart: {
hoverId: undefined,
selectId: undefined
},
// 记录临时数据(复制等)
recordChart: undefined,
// 图表数组(需存储给后端) // 图表数组(需存储给后端)
componentList: [] componentList: []
}), }),

View File

@ -34,7 +34,8 @@ import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditSt
import { import {
chartColors, chartColors,
chartColorsName, chartColorsName,
chartColorsshow chartColorsshow,
ChartColorsNameType
} from '@/settings/chartThemes/index' } from '@/settings/chartThemes/index'
import { useDesignStore } from '@/store/modules/designStore/designStore' import { useDesignStore } from '@/store/modules/designStore/designStore'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
@ -48,7 +49,7 @@ const designStore = useDesignStore()
const themeColor = ref(designStore.getAppTheme) const themeColor = ref(designStore.getAppTheme)
const selectName = computed(() => { const selectName = computed(() => {
return chartEditStoreStore.getEditCanvasConfig.chartTheme return chartEditStoreStore.getEditCanvasConfig.chartThemeColor
}) })
// //
@ -56,8 +57,9 @@ const fetchShowColors = (colors: Array<string>) => {
return cloneDeep(colors).splice(0, 6) return cloneDeep(colors).splice(0, 6)
} }
const selectTheme = (theme: string) => { // ContentEdit > List
chartEditStoreStore.setEditCanvasConfig(EditCanvasConfigEnum.CHART_THEME, theme) const selectTheme = (theme: ChartColorsNameType) => {
chartEditStoreStore.setEditCanvasConfig(EditCanvasConfigEnum.CHART_THEME_COLOR, theme)
} }
</script> </script>

View File

@ -142,7 +142,7 @@ const switchSelectColorLoading = ref(false)
const globalTabList = [ const globalTabList = [
{ {
key: 'ChartTheme', key: 'ChartTheme',
title: '主题', title: '主题颜色',
icon: ColorPaletteIcon, icon: ColorPaletteIcon,
render: ChartTheme render: ChartTheme
}, },

View File

@ -30,7 +30,8 @@
class="edit-content-chart" class="edit-content-chart"
:is="item.key" :is="item.key"
:chartData="item" :chartData="item"
:themeData="themeData" :themeSetting="themeSetting"
:themeColor="themeColor"
:style="useSizeStyle(item.attr)" :style="useSizeStyle(item.attr)"
/> />
</EditShapeBox> </EditShapeBox>
@ -69,12 +70,16 @@ useLayout()
const editRangeRef = ref<HTMLElement | null>(null) const editRangeRef = ref<HTMLElement | null>(null)
const { mouseenterHandle, mouseleaveHandle, mousedownHandle } = useMouseHandle() const { mouseenterHandle, mouseleaveHandle, mousedownHandle } = useMouseHandle()
// //
const themeData = computed(() => { const themeSetting = computed(() => {
const theme = chartEditStore.getEditCanvasConfig.chartTheme const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting
if(theme === 'dark') return 'dark' return chartThemeSetting
// @ts-ignore })
return chartColors[theme]
//
const themeColor = computed(() => {
const chartThemeColor = chartEditStore.getEditCanvasConfig.chartThemeColor
return chartColors[chartThemeColor]
}) })
// //