index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div
  3. class="bs-design-wrap theme-switcher-wrap"
  4. :class="`bs-theme-switcher-${customTheme}`"
  5. >
  6. <!-- <div class="label-box">-->
  7. <!-- 切换主题-->
  8. <!-- </div>-->
  9. <el-radio-group
  10. v-model="pageInfo.pageConfig.customTheme"
  11. size="medium "
  12. class="theme-radio"
  13. @change="handleChange"
  14. >
  15. <el-radio
  16. label="light"
  17. style="color: red!important;"
  18. :style="{color:config.customize.inactiveColor}"
  19. >
  20. 明亮
  21. </el-radio>
  22. <el-radio
  23. label="dark"
  24. :style="{color:config.customize.inactiveColor}"
  25. >
  26. 暗黑
  27. </el-radio>
  28. </el-radio-group>
  29. </div>
  30. </template>
  31. <script>
  32. import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
  33. import { themeToSetting } from 'data-room-ui/js/utils/themeFormatting'
  34. import { mapMutations, mapState } from 'vuex'
  35. export default {
  36. name: 'ThemeSwitcher',
  37. components: {},
  38. mixins: [paramsMixins],
  39. props: {
  40. // 卡片的属性
  41. config: {
  42. type: Object,
  43. default: () => ({})
  44. }
  45. },
  46. computed: {
  47. ...mapState({
  48. pageInfo: (state) => state.bigScreen.pageInfo
  49. }),
  50. isPreview () {
  51. return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
  52. }
  53. },
  54. data () {
  55. return {
  56. }
  57. },
  58. watch: {
  59. 'config.customize.activeColor': {
  60. handler (val) {
  61. document.documentElement.style.setProperty('--radio-label-color', val)
  62. },
  63. immediate: true
  64. }
  65. },
  66. mounted () {
  67. document.documentElement.style.setProperty('--radio-label-color', this.config.customize.activeColor)
  68. },
  69. methods: {
  70. ...mapMutations({
  71. changePageInfo: 'bigScreen/changePageInfo'
  72. }),
  73. // 由于静态组件没有混入公共函数,所以需要定义一个changeStyle方法,以免报错
  74. changeStyle (config) {
  75. },
  76. // 点击切换主题
  77. handleChange (val) {
  78. const pageInfo = this.pageInfo
  79. pageInfo.chartList = themeToSetting(pageInfo.chartList, val)
  80. this.changePageInfo(pageInfo)
  81. pageInfo.chartList.forEach(chart => {
  82. if (chart.type === 'remoteComponent') {
  83. this.$emit('styleHandler', chart)
  84. }
  85. })
  86. if (!this.isPreview) {
  87. const themeLabel = val === 'light' ? '明亮' : '暗黑'
  88. const htmlStr = `<span>当前已切换到<strong>${themeLabel}</strong>主题,颜色设置针对当前主题生效</span>`
  89. this.$notify({
  90. title: '注意',
  91. dangerouslyUseHTMLString: true,
  92. message: htmlStr,
  93. customClass: 'ds-el-notify',
  94. type: 'warning'
  95. })
  96. }
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .bs-design-wrap{
  103. width: 100%;;
  104. display: flex;
  105. align-items: center;
  106. justify-content: center;
  107. flex-wrap: nowrap;
  108. color: #fff;
  109. .label-box{
  110. padding: 10px;
  111. margin-right: 10px;
  112. font-size: 14px;
  113. }
  114. //.el-radio.is-checked {
  115. // color: red; /* 修改激活状态下的字体颜色 */
  116. //}
  117. //
  118. ///* 修改未激活状态下的字体颜色 */
  119. //.el-radio:not(.is-checked) {
  120. // color: #fff; /* 修改未激活状态下的字体颜色 */
  121. //}
  122. /deep/ .el-radio__input.is-checked+.el-radio__label {
  123. /* 使用 CSS 变量来设置字体颜色 */
  124. color: var(--radio-label-color);
  125. }
  126. /deep/ .el-radio__input.is-checked .el-radio__inner{
  127. background: var(--radio-label-color);
  128. border-color: var(--radio-label-color);
  129. }
  130. }
  131. </style>