diff --git a/data-room-ui/packages/BasicComponents/CurrentTime/index.vue b/data-room-ui/packages/BasicComponents/CurrentTime/index.vue index 3cff55ee..388282b5 100644 --- a/data-room-ui/packages/BasicComponents/CurrentTime/index.vue +++ b/data-room-ui/packages/BasicComponents/CurrentTime/index.vue @@ -30,6 +30,9 @@ diff --git a/data-room-ui/packages/BasicComponents/Input/index.vue b/data-room-ui/packages/BasicComponents/Input/index.vue index 5f03cb3d..2c49e835 100644 --- a/data-room-ui/packages/BasicComponents/Input/index.vue +++ b/data-room-ui/packages/BasicComponents/Input/index.vue @@ -35,6 +35,8 @@ diff --git a/data-room-ui/packages/BasicComponents/ThemeSwitcher/index.vue b/data-room-ui/packages/BasicComponents/ThemeSwitcher/index.vue index d9b8b76d..d484fc0a 100644 --- a/data-room-ui/packages/BasicComponents/ThemeSwitcher/index.vue +++ b/data-room-ui/packages/BasicComponents/ThemeSwitcher/index.vue @@ -65,7 +65,7 @@ export default { }, handleChange (val) { const pageInfo = this.pageInfo - pageInfo.chartList = themeToSetting(pageInfo.chartList, val, this) + pageInfo.chartList = themeToSetting(pageInfo.chartList, val) this.changePageInfo(pageInfo) } } diff --git a/data-room-ui/packages/BasicComponents/VerticalLine/index.vue b/data-room-ui/packages/BasicComponents/VerticalLine/index.vue index b75ec3b6..b187515c 100644 --- a/data-room-ui/packages/BasicComponents/VerticalLine/index.vue +++ b/data-room-ui/packages/BasicComponents/VerticalLine/index.vue @@ -49,9 +49,6 @@ export default { watch: {}, mounted () {}, methods: { - // 由于静态组件没有混入公共函数,所以需要定义一个changeStyle方法,以免报错 - changeStyle () { - } } } diff --git a/data-room-ui/packages/BigScreenDesign/index.vue b/data-room-ui/packages/BigScreenDesign/index.vue index c7906394..e0ffa30c 100644 --- a/data-room-ui/packages/BigScreenDesign/index.vue +++ b/data-room-ui/packages/BigScreenDesign/index.vue @@ -412,7 +412,7 @@ export default { // 切换主题时更新主题配置 updateTheme (theme) { const pageInfo = this.pageInfo - pageInfo.chartList = themeToSetting(pageInfo.chartList, theme, this) + pageInfo.chartList = themeToSetting(pageInfo.chartList, theme) this.changePageInfo(pageInfo) }, // 自定义属性更新 diff --git a/data-room-ui/packages/Render/index.vue b/data-room-ui/packages/Render/index.vue index cce8539f..c2fa2b5d 100644 --- a/data-room-ui/packages/Render/index.vue +++ b/data-room-ui/packages/Render/index.vue @@ -330,10 +330,10 @@ export default { config.key = config.code // TODO:新添加一个组件时应该有默认的两套主题 // 先暂时只考虑g2组件 - if (['customComponent'].includes(_chart.type)) { - config.theme = settingToTheme(config, 'dark') - config.theme = settingToTheme(config, 'light') - } + // if (['customComponent'].includes(_chart.type)) { + config.theme = settingToTheme(config, 'dark') + config.theme = settingToTheme(config, 'light') + // } this.addItem(config) }, addSourceChart (chart, position) { diff --git a/data-room-ui/packages/js/mixins/commonMixins.js b/data-room-ui/packages/js/mixins/commonMixins.js index 8e1565f2..6a2c6bd8 100644 --- a/data-room-ui/packages/js/mixins/commonMixins.js +++ b/data-room-ui/packages/js/mixins/commonMixins.js @@ -9,6 +9,8 @@ import { mapMutations, mapState } from 'vuex' import { EventBus } from 'data-room-ui/js/utils/eventBus' import { getChatInfo, getUpdateChartInfo } from '../api/bigScreenApi' import axiosFormatting from '../../js/utils/httpParamsFormatting' +import {settingToTheme} from "data-room-ui/js/utils/themeFormatting"; +import _ from "lodash"; export default { data () { return { @@ -19,7 +21,9 @@ export default { }, computed: { ...mapState({ - pageCode: state => state.bigScreen.pageInfo.code + pageCode: state => state.bigScreen.pageInfo.code, + customTheme: state => state.bigScreen.pageInfo.pageConfig.customTheme, + activeCode: state => state.bigScreen.activeCode }), isPreview () { return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview') @@ -33,7 +37,8 @@ export default { }, methods: { ...mapMutations({ - changeChartConfig: 'bigScreen/changeChartConfig' + changeChartConfig: 'bigScreen/changeChartConfig', + changeActiveItemConfig: 'bigScreen/changeActiveItemConfig' }), /** * 初始化组件 @@ -184,8 +189,13 @@ export default { // 覆盖 }, changeStyle (config) { - // this.changeChartConfig(config) - // return config + config = { ...this.config, ...config } + // 样式改变时更新主题配置 + config.theme = settingToTheme(_.cloneDeep(config), this.customTheme) + this.changeChartConfig(config) + if (config.code === this.activeCode) { + this.changeActiveItemConfig(config) + } }, // 缓存组件数据监听 watchCacheData () { diff --git a/data-room-ui/packages/js/mixins/refreshComponent.js b/data-room-ui/packages/js/mixins/refreshComponent.js index 44ae3a23..c358325b 100644 --- a/data-room-ui/packages/js/mixins/refreshComponent.js +++ b/data-room-ui/packages/js/mixins/refreshComponent.js @@ -1,3 +1,7 @@ +import { mapMutations, mapState } from 'vuex' +import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting' +import _ from 'lodash' + const refreshComponentMixin = { data () { return { @@ -5,6 +9,10 @@ const refreshComponentMixin = { } }, computed: { + ...mapState({ + customTheme: state => state.bigScreen.pageInfo.pageConfig.customTheme, + activeCode: state => state.bigScreen.activeCode + }), Data () { return JSON.parse(JSON.stringify(this.config)) } @@ -22,8 +30,19 @@ const refreshComponentMixin = { } }, methods: { - // 由于静态组件没有混入公共函数,所以需要定义一个changeStyle方法,以免报错 - changeStyle () { + ...mapMutations({ + changeChartConfig: 'bigScreen/changeChartConfig', + changeActiveItemConfig: 'bigScreen/changeActiveItemConfig' + }), + // 修改样式 + changeStyle (config) { + config = { ...this.config, ...config } + // 样式改变时更新主题配置 + config.theme = settingToTheme(_.cloneDeep(config), this.customTheme) + this.changeChartConfig(config) + if (config.code === this.activeCode) { + this.changeActiveItemConfig(config) + } } } } diff --git a/data-room-ui/packages/js/utils/themeFormatting.js b/data-room-ui/packages/js/utils/themeFormatting.js index feb948b1..166b63af 100644 --- a/data-room-ui/packages/js/utils/themeFormatting.js +++ b/data-room-ui/packages/js/utils/themeFormatting.js @@ -12,28 +12,55 @@ export function settingToTheme (config, type) { // 排除掉主题非暗黑非明亮的情况 if (['dark', 'light'].includes(type)) { const theme = { dark: { ...config?.theme?.dark }, light: { ...config?.theme?.light } } - config.setting.forEach((setItem) => { - if (['gradual', 'colorPicker', 'colorSelect'].includes(setItem.type)) { - theme[type][setItem.field] = setItem.value + // 根据组件的type来判断主题的转化方式 + // 如果是g2组件或者远程组件 + if (['customComponent', 'remoteComponent'].includes(config.type)) { + config.setting.forEach((setItem) => { + if (['gradual', 'colorPicker', 'colorSelect'].includes(setItem.type)) { + theme[type][setItem.field] = setItem.value + } + }) + } else { + // 如果是普通组件 + if (config.customize && Object.keys(config.customize).length) { + for (const item in config.customize) { + if (item.includes('color') || item.includes('Color')) { + theme[type][item] = config.customize[item] + } + } } - }) + } return theme } else { return {} } } // 将保存的theme主题设置(颜色)存放到chartList -export function themeToSetting (chartList, type, _this) { +export function themeToSetting (chartList, type) { // 排除掉主题非暗黑非明亮的情况 if (['dark', 'light'].includes(type)) { chartList.forEach(chart => { chart.option.theme = type if (chart.theme && chart.theme[type]) { - for (const item of chart.setting) { - // 检查 obj 中是否存在与 item.field 相对应的属性 - if (Object.prototype.hasOwnProperty.call(chart.theme[type], item.field)) { - // 更新 setting 中对应项的 value 值为 theme 中的属性值 - item.value = chart.theme[type][item.field] + // 如果是g2组件或者远程组件 + if (['customComponent', 'remoteComponent'].includes(chart.type)) { + for (const item of chart.setting) { + // 检查 obj 中是否存在与 item.field 相对应的属性 + if (Object.prototype.hasOwnProperty.call(chart.theme[type], item.field)) { + // 更新 setting 中对应项的 value 值为 theme 中的属性值 + item.value = chart.theme[type][item.field] + } + } + } else { + // 如果是普通组件 + if (chart.customize && Object.keys(chart.customize).length) { + for (const item in chart.customize) { + // 检查 obj 中是否存在与 customize 相对应的属性 + if (Object.prototype.hasOwnProperty.call(chart.theme[type], item)) { + // 更新 customize 中对应项的值为 theme 中的属性值 + chart.customize[item] = chart.theme[type][item] + } + } } } }