feat:修改部分基础组件的主题设置

main
liu.shiyi 2 years ago
parent d5d9312c5d
commit 86883e6627

@ -30,6 +30,9 @@
<script> <script>
import moment from 'moment' import moment from 'moment'
import paramsMixins from 'data-room-ui/js/mixins/paramsMixins' import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
import _ from 'lodash'
import {mapMutations, mapState} from 'vuex'
export default { export default {
name: 'CurrentTime', name: 'CurrentTime',
mixins: [paramsMixins], mixins: [paramsMixins],
@ -39,6 +42,12 @@ export default {
default: () => ({}) default: () => ({})
} }
}, },
computed: {
...mapState({
customTheme: state => state.bigScreen.pageInfo.pageConfig.customTheme,
activeCode: state => state.bigScreen.activeCode
})
},
data () { data () {
return { return {
nowTime: '', nowTime: '',
@ -56,8 +65,19 @@ export default {
} }
}, },
methods: { methods: {
...mapMutations({
changeChartConfig: 'bigScreen/changeChartConfig',
changeActiveItemConfig: 'bigScreen/changeActiveItemConfig'
}),
changeStyle (config) { changeStyle (config) {
this.getCurrentTime(config.dateFormat) this.getCurrentTime(config.dateFormat)
config = { ...this.config, ...config }
//
config.theme = settingToTheme(_.cloneDeep(config), this.customTheme)
this.changeChartConfig(config)
if (config.code === this.activeCode) {
this.changeActiveItemConfig(config)
}
}, },
// //
getCurrentTime (dateFormat) { getCurrentTime (dateFormat) {

@ -60,7 +60,7 @@ export default {
}, },
computed: { computed: {
option () { option () {
let str=this.config.option.data let str = this.config.option.data
if (!this.config.option.data) return { ...this.config.customize, data: [] } if (!this.config.option.data) return { ...this.config.customize, data: [] }
if ( if (
this.config.option.data.toString().split('').length < this.config.option.data.toString().split('').length <

@ -49,9 +49,6 @@ export default {
watch: {}, watch: {},
mounted () {}, mounted () {},
methods: { methods: {
// changeStyle
changeStyle () {
}
} }
} }
</script> </script>

@ -35,6 +35,8 @@
<script> <script>
import commonMixins from 'data-room-ui/js/mixins/commonMixins' import commonMixins from 'data-room-ui/js/mixins/commonMixins'
import linkageMixins from 'data-room-ui/js/mixins/linkageMixins' import linkageMixins from 'data-room-ui/js/mixins/linkageMixins'
import {settingToTheme} from "data-room-ui/js/utils/themeFormatting";
import _ from "lodash";
export default { export default {
name: 'BasicComponentInput', name: 'BasicComponentInput',
mixins: [commonMixins, linkageMixins], mixins: [commonMixins, linkageMixins],
@ -61,8 +63,8 @@ export default {
}, },
methods: { methods: {
changeStyle (config) { changeStyle (config) {
config = { ...this.config, ...config }
const input = document.querySelector(`#el-input-${config.code}`) const input = document.querySelector(`#el-input-${config.code}`)
// const inputIcon = input.querySelector(`.${this.config.customize.icon.name}`) // const inputIcon = input.querySelector(`.${this.config.customize.icon.name}`)
input.style.backgroundColor = config.customize.backgroundStyle.backgroundColor input.style.backgroundColor = config.customize.backgroundStyle.backgroundColor
input.style.fontSize = config.customize.inputStyle.fontSize + 'px' input.style.fontSize = config.customize.inputStyle.fontSize + 'px'
@ -76,6 +78,12 @@ export default {
const inputIcon = document.querySelector(`.${config.customize.icon.name}`) const inputIcon = document.querySelector(`.${config.customize.icon.name}`)
inputIcon.style.fontSize = config.customize.inputStyle.fontSize + 'px' inputIcon.style.fontSize = config.customize.inputStyle.fontSize + 'px'
} }
//
config.theme = settingToTheme(_.cloneDeep(config), this.customTheme)
this.changeChartConfig(config)
if (config.code === this.activeCode) {
this.changeActiveItemConfig(config)
}
} }
} }
} }

@ -23,9 +23,12 @@
</div> </div>
</template> </template>
<script> <script>
import { refreshComponentMixin } from 'data-room-ui/js/mixins/refreshComponent'
export default { export default {
name: 'PictureChart', name: 'PictureChart',
components: {}, components: {},
mixins: [refreshComponentMixin],
props: { props: {
config: { config: {
type: Object, type: Object,
@ -41,9 +44,7 @@ export default {
watch: {}, watch: {},
mounted () {}, mounted () {},
methods: { methods: {
// changeStyle
changeStyle () {
}
} }
} }
</script> </script>

@ -65,7 +65,7 @@ export default {
}, },
handleChange (val) { handleChange (val) {
const pageInfo = this.pageInfo const pageInfo = this.pageInfo
pageInfo.chartList = themeToSetting(pageInfo.chartList, val, this) pageInfo.chartList = themeToSetting(pageInfo.chartList, val)
this.changePageInfo(pageInfo) this.changePageInfo(pageInfo)
} }
} }

@ -49,9 +49,6 @@ export default {
watch: {}, watch: {},
mounted () {}, mounted () {},
methods: { methods: {
// changeStyle
changeStyle () {
}
} }
} }
</script> </script>

@ -412,7 +412,7 @@ export default {
// //
updateTheme (theme) { updateTheme (theme) {
const pageInfo = this.pageInfo const pageInfo = this.pageInfo
pageInfo.chartList = themeToSetting(pageInfo.chartList, theme, this) pageInfo.chartList = themeToSetting(pageInfo.chartList, theme)
this.changePageInfo(pageInfo) this.changePageInfo(pageInfo)
}, },
// //

@ -330,10 +330,10 @@ export default {
config.key = config.code config.key = config.code
// TODO: // TODO:
// g2 // g2
if (['customComponent'].includes(_chart.type)) { // if (['customComponent'].includes(_chart.type)) {
config.theme = settingToTheme(config, 'dark') config.theme = settingToTheme(config, 'dark')
config.theme = settingToTheme(config, 'light') config.theme = settingToTheme(config, 'light')
} // }
this.addItem(config) this.addItem(config)
}, },
addSourceChart (chart, position) { addSourceChart (chart, position) {

@ -9,6 +9,8 @@ import { mapMutations, mapState } from 'vuex'
import { EventBus } from 'data-room-ui/js/utils/eventBus' import { EventBus } from 'data-room-ui/js/utils/eventBus'
import { getChatInfo, getUpdateChartInfo } from '../api/bigScreenApi' import { getChatInfo, getUpdateChartInfo } from '../api/bigScreenApi'
import axiosFormatting from '../../js/utils/httpParamsFormatting' import axiosFormatting from '../../js/utils/httpParamsFormatting'
import {settingToTheme} from "data-room-ui/js/utils/themeFormatting";
import _ from "lodash";
export default { export default {
data () { data () {
return { return {
@ -19,7 +21,9 @@ export default {
}, },
computed: { computed: {
...mapState({ ...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 () { isPreview () {
return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview') return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
@ -33,7 +37,8 @@ export default {
}, },
methods: { methods: {
...mapMutations({ ...mapMutations({
changeChartConfig: 'bigScreen/changeChartConfig' changeChartConfig: 'bigScreen/changeChartConfig',
changeActiveItemConfig: 'bigScreen/changeActiveItemConfig'
}), }),
/** /**
* 初始化组件 * 初始化组件
@ -184,8 +189,13 @@ export default {
// 覆盖 // 覆盖
}, },
changeStyle (config) { changeStyle (config) {
// this.changeChartConfig(config) config = { ...this.config, ...config }
// return config // 样式改变时更新主题配置
config.theme = settingToTheme(_.cloneDeep(config), this.customTheme)
this.changeChartConfig(config)
if (config.code === this.activeCode) {
this.changeActiveItemConfig(config)
}
}, },
// 缓存组件数据监听 // 缓存组件数据监听
watchCacheData () { watchCacheData () {

@ -1,3 +1,7 @@
import { mapMutations, mapState } from 'vuex'
import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
import _ from 'lodash'
const refreshComponentMixin = { const refreshComponentMixin = {
data () { data () {
return { return {
@ -5,6 +9,10 @@ const refreshComponentMixin = {
} }
}, },
computed: { computed: {
...mapState({
customTheme: state => state.bigScreen.pageInfo.pageConfig.customTheme,
activeCode: state => state.bigScreen.activeCode
}),
Data () { Data () {
return JSON.parse(JSON.stringify(this.config)) return JSON.parse(JSON.stringify(this.config))
} }
@ -22,8 +30,19 @@ const refreshComponentMixin = {
} }
}, },
methods: { methods: {
// 由于静态组件没有混入公共函数所以需要定义一个changeStyle方法以免报错 ...mapMutations({
changeStyle () { 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)
}
} }
} }
} }

@ -12,28 +12,55 @@ export function settingToTheme (config, type) {
// 排除掉主题非暗黑非明亮的情况 // 排除掉主题非暗黑非明亮的情况
if (['dark', 'light'].includes(type)) { if (['dark', 'light'].includes(type)) {
const theme = { dark: { ...config?.theme?.dark }, light: { ...config?.theme?.light } } const theme = { dark: { ...config?.theme?.dark }, light: { ...config?.theme?.light } }
config.setting.forEach((setItem) => { // 根据组件的type来判断主题的转化方式
if (['gradual', 'colorPicker', 'colorSelect'].includes(setItem.type)) { // 如果是g2组件或者远程组件
theme[type][setItem.field] = setItem.value 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 return theme
} else { } else {
return {} return {}
} }
} }
// 将保存的theme主题设置颜色存放到chartList // 将保存的theme主题设置颜色存放到chartList
export function themeToSetting (chartList, type, _this) { export function themeToSetting (chartList, type) {
// 排除掉主题非暗黑非明亮的情况 // 排除掉主题非暗黑非明亮的情况
if (['dark', 'light'].includes(type)) { if (['dark', 'light'].includes(type)) {
chartList.forEach(chart => { chartList.forEach(chart => {
chart.option.theme = type chart.option.theme = type
if (chart.theme && chart.theme[type]) { if (chart.theme && chart.theme[type]) {
for (const item of chart.setting) { // 如果是g2组件或者远程组件
// 检查 obj 中是否存在与 item.field 相对应的属性 if (['customComponent', 'remoteComponent'].includes(chart.type)) {
if (Object.prototype.hasOwnProperty.call(chart.theme[type], item.field)) { for (const item of chart.setting) {
// 更新 setting 中对应项的 value 值为 theme 中的属性值 // 检查 obj 中是否存在与 item.field 相对应的属性
item.value = chart.theme[type][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]
}
}
} }
} }
} }

Loading…
Cancel
Save