feat:初步实现主题切换

main
liu.shiyi 2 years ago
parent 6addbba742
commit dca8d3cd68

@ -10,6 +10,16 @@
<span class="logo-text name-span">{{ pageInfo.name }}</span> <span class="logo-text name-span">{{ pageInfo.name }}</span>
</div> </div>
<div class="head-btn-group"> <div class="head-btn-group">
<el-switch
v-model="pageInfo.pageConfig.customTheme"
active-text="暗黑"
inactive-text="明亮"
class="bs-el-switch theme-switch"
active-color="#007aff"
active-value="dark"
inactive-value="light"
@change="changeTheme"
/>
<el-tooltip <el-tooltip
v-for="(mode,index) in alignList" v-for="(mode,index) in alignList"
:key="mode.value" :key="mode.value"
@ -113,6 +123,7 @@ import {
translateBlobToBase64 translateBlobToBase64
} from 'data-room-ui/js/utils/compressImg' } from 'data-room-ui/js/utils/compressImg'
import * as imageConversion from 'image-conversion' import * as imageConversion from 'image-conversion'
import { themeToSetting } from 'data-room-ui/js/utils/themeFormatting'
export default { export default {
name: 'PageTopSetting', name: 'PageTopSetting',
components: { components: {
@ -209,6 +220,11 @@ export default {
undoTimeLine: 'bigScreen/undoTimeLine', undoTimeLine: 'bigScreen/undoTimeLine',
saveTimeLine: 'bigScreen/saveTimeLine' saveTimeLine: 'bigScreen/saveTimeLine'
}), }),
//
changeTheme (val) {
//
this.$emit('updateTheme', val)
},
setAlign (command) { setAlign (command) {
const pageInfo = cloneDeep(this.pageInfo) const pageInfo = cloneDeep(this.pageInfo)
// //
@ -539,7 +555,7 @@ export default {
.head-btn-group { .head-btn-group {
display: flex; display: flex;
margin-left: 50px; margin-left: 50px;
align-items: center;
i { i {
font-size: 14px; font-size: 14px;
} }
@ -575,5 +591,14 @@ export default {
text-overflow: ellipsis; text-overflow: ellipsis;
} }
} }
.theme-switch{
margin-right: 10px;
/deep/.el-switch__label{
color: #bcc9d4!important;
}
/deep/.el-switch__label.is-active{
color: var(--bs-el-color-primary)!important;
}
}
} }
</style> </style>

@ -154,7 +154,7 @@ export default {
if (this.config.type === 'iframeChart') { if (this.config.type === 'iframeChart') {
this.debounce(500, { ...val, type: this.config.type, code: this.config.code }) this.debounce(500, { ...val, type: this.config.type, code: this.config.code })
} else { } else {
this.$emit('updateSetting', { ...val, type: this.config.type, code: this.config.code }) this.$emit('updateSetting', { ...val, type: this.config.type, code: this.config.code, theme: this.config.theme })
} }
} else { } else {
this.$emit('updateDataSetting', this.config) this.$emit('updateDataSetting', this.config)

@ -9,6 +9,7 @@
:right-fold="rightVisiable" :right-fold="rightVisiable"
@updateRightVisiable="updateRightVisiable" @updateRightVisiable="updateRightVisiable"
@showPageInfo="showPageInfo" @showPageInfo="showPageInfo"
@updateTheme="updateTheme"
@empty="empty" @empty="empty"
/> />
<div class="drag-wrap"> <div class="drag-wrap">
@ -136,6 +137,7 @@ import { isFirefox } from 'data-room-ui/js/utils/userAgent'
import { handleResData } from 'data-room-ui/js/store/actions.js' import { handleResData } from 'data-room-ui/js/store/actions.js'
import { EventBus } from 'data-room-ui/js/utils/eventBus' import { EventBus } from 'data-room-ui/js/utils/eventBus'
import NotPermission from 'data-room-ui/NotPermission' import NotPermission from 'data-room-ui/NotPermission'
import { themeToSetting } from 'data-room-ui/js/utils/themeFormatting'
export default { export default {
name: 'BigScreenDesign', name: 'BigScreenDesign',
components: { components: {
@ -216,7 +218,8 @@ export default {
hasGrid: (state) => state.bigScreen.hasGrid, hasGrid: (state) => state.bigScreen.hasGrid,
zoom: (state) => state.bigScreen.zoom, zoom: (state) => state.bigScreen.zoom,
fitZoom: (state) => state.bigScreen.fitZoom, fitZoom: (state) => state.bigScreen.fitZoom,
iframeDialog: (state) => state.bigScreen.iframeDialog iframeDialog: (state) => state.bigScreen.iframeDialog,
activeCode: state => state.bigScreen.activeCode
}), }),
pageCode () { pageCode () {
return this.code || this.$route.query.code return this.code || this.$route.query.code
@ -277,7 +280,9 @@ export default {
'changeZoom', 'changeZoom',
'clearTimeline', 'clearTimeline',
'saveTimeLine', 'saveTimeLine',
'changeIframeDialog' 'changeIframeDialog',
'changePageInfo',
'changeActiveItemConfig'
]), ]),
// //
permission () { permission () {
@ -404,6 +409,12 @@ export default {
}) })
.catch(() => {}) .catch(() => {})
}, },
//
updateTheme (theme) {
const pageInfo = this.pageInfo
pageInfo.chartList = themeToSetting(pageInfo.chartList, theme, this)
this.changePageInfo(pageInfo)
},
// //
updateSetting (config) { updateSetting (config) {
if (config.type === 'map' || config.type === 'video') { if (config.type === 'map' || config.type === 'video') {

@ -20,6 +20,7 @@ import { mapState, mapMutations } from 'vuex'
import * as g2Plot from '@antv/g2plot' import * as g2Plot from '@antv/g2plot'
import plotList, { getCustomPlots } from '../G2Plots/plotList' import plotList, { getCustomPlots } from '../G2Plots/plotList'
import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting' import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
import _ from 'lodash'
export default { export default {
name: 'PlotCustomComponent', name: 'PlotCustomComponent',
@ -40,7 +41,8 @@ export default {
computed: { computed: {
...mapState('bigScreen', { ...mapState('bigScreen', {
pageInfo: state => state.pageInfo, pageInfo: state => state.pageInfo,
customTheme: state => state.pageInfo.pageConfig.customTheme customTheme: state => state.pageInfo.pageConfig.customTheme,
activeCode: state => state.activeCode
}), }),
chatId () { chatId () {
let prefix = 'chart_' let prefix = 'chart_'
@ -69,9 +71,8 @@ export default {
} }
}, },
methods: { methods: {
...mapMutations('bigScreen', ['changeChartConfig']), ...mapMutations('bigScreen', ['changeChartConfig', 'changeActiveItemConfig']),
chartInit () { chartInit () {
let config = this.config let config = this.config
// keycodelist // keycodelist
if (this.config.code === this.config.key || this.isPreview) { if (this.config.code === this.config.key || this.isPreview) {
@ -81,7 +82,8 @@ export default {
this.changeDataByCode(config).then((res) => { this.changeDataByCode(config).then((res) => {
// //
this.newChart(res) this.newChart(res)
}).catch(() => {}) }).catch(() => {
})
} else { } else {
// changeStylekey,chart // changeStylekey,chart
this.changeData(config).then((res) => { this.changeData(config).then((res) => {
@ -179,13 +181,15 @@ export default {
console.error(e) console.error(e)
} }
} }
//
config.theme = settingToTheme(_.cloneDeep(config), this.customTheme)
this.changeChartConfig(config)
if (config.code === this.activeCode) {
this.changeActiveItemConfig(config)
}
if (this.chart) { if (this.chart) {
this.chart.update(config.option) this.chart.update(config.option)
} }
this.changeChartConfig(config)
//
console.log('changeStyle')
config.theme = settingToTheme(config, this.customTheme)
return config return config
} }
} }

@ -329,9 +329,8 @@ export default {
} }
config.key = config.code config.key = config.code
// TODO: // TODO:
console.log('add')
// 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')
} }

@ -1,9 +1,12 @@
import _ from 'lodash'
/** /**
* @Description: 主题设置格式化 * @Description: 主题设置格式化
* @author liu.shiyi * @author liu.shiyi
* @date 2023/8/17 14:47 * @date 2023/8/17 14:47
*/ */
// 将组件中的setting里面的主题设置颜色存放到theme里面 // 将组件中的setting里面的主题设置颜色存放到theme里面
export function settingToTheme (config, type) { export function settingToTheme (config, type) {
// 考虑与上一次保存过的主题进行合并 // 考虑与上一次保存过的主题进行合并
// 排除掉主题非暗黑非明亮的情况 // 排除掉主题非暗黑非明亮的情况
@ -20,12 +23,11 @@ export function settingToTheme (config, type) {
} }
} }
// 将保存的theme主题设置颜色存放到chartList // 将保存的theme主题设置颜色存放到chartList
export function themeToSetting (chartList, type) { export function themeToSetting (chartList, type, _this) {
// 排除掉主题非暗黑非明亮的情况 // 排除掉主题非暗黑非明亮的情况
if (['dark', 'light'].includes(type)) { if (['dark', 'light'].includes(type)) {
chartList.forEach(chart => { chartList.forEach(chart => {
chart.option.theme = type chart.option.theme = type
chart.key = new Date().getTime()
if (chart.theme && chart.theme[type]) { if (chart.theme && chart.theme[type]) {
for (const item of chart.setting) { for (const item of chart.setting) {
// 检查 obj 中是否存在与 item.field 相对应的属性 // 检查 obj 中是否存在与 item.field 相对应的属性
@ -35,6 +37,9 @@ export function themeToSetting (chartList, type) {
} }
} }
} }
if (_this && _this.$refs.Render?.$refs['RenderCard' + chart.code][0] && _this.$refs.Render.$refs['RenderCard' + chart.code][0].$refs[chart.code].changeStyle) {
_this.$refs.Render.$refs['RenderCard' + chart.code][0].$refs[chart.code].changeStyle(_.cloneDeep(chart))
}
}) })
} }
return chartList return chartList

Loading…
Cancel
Save