index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. import { refreshComponentMixin } from 'data-room-ui/js/mixins/refreshComponent'
  36. export default {
  37. name: 'ThemeSwitcher',
  38. components: {},
  39. mixins: [paramsMixins, refreshComponentMixin],
  40. props: {
  41. // 卡片的属性
  42. config: {
  43. type: Object,
  44. default: () => ({})
  45. }
  46. },
  47. computed: {
  48. ...mapState({
  49. pageInfo: (state) => state.bigScreen.pageInfo
  50. }),
  51. isPreview () {
  52. return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
  53. }
  54. },
  55. data () {
  56. return {
  57. }
  58. },
  59. watch: {
  60. 'config.customize.activeColor': {
  61. handler (val) {
  62. document.documentElement.style.setProperty('--radio-label-color', val)
  63. },
  64. immediate: true
  65. }
  66. },
  67. mounted () {
  68. document.documentElement.style.setProperty('--radio-label-color', this.config.customize.activeColor)
  69. },
  70. methods: {
  71. ...mapMutations({
  72. changePageInfo: 'bigScreen/changePageInfo'
  73. }),
  74. // 点击切换主题
  75. handleChange (val) {
  76. const pageInfo = this.pageInfo
  77. pageInfo.chartList = themeToSetting(pageInfo.chartList, val)
  78. this.changePageInfo(pageInfo)
  79. pageInfo.chartList.forEach(chart => {
  80. if (chart.type === 'remoteComponent') {
  81. this.$emit('styleHandler', chart)
  82. }
  83. })
  84. if (!this.isPreview) {
  85. const themeLabel = val === 'light' ? '明亮' : '暗黑'
  86. const htmlStr = `<span>当前已切换到<strong>${themeLabel}</strong>主题,颜色设置针对当前主题生效</span>`
  87. this.$notify({
  88. title: '注意',
  89. dangerouslyUseHTMLString: true,
  90. message: htmlStr,
  91. customClass: 'ds-el-notify',
  92. type: 'warning'
  93. })
  94. }
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .bs-design-wrap{
  101. width: 100%;;
  102. display: flex;
  103. align-items: center;
  104. justify-content: center;
  105. flex-wrap: nowrap;
  106. color: #fff;
  107. .label-box{
  108. padding: 10px;
  109. margin-right: 10px;
  110. font-size: 14px;
  111. }
  112. //.el-radio.is-checked {
  113. // color: red; /* 修改激活状态下的字体颜色 */
  114. //}
  115. //
  116. ///* 修改未激活状态下的字体颜色 */
  117. //.el-radio:not(.is-checked) {
  118. // color: #fff; /* 修改未激活状态下的字体颜色 */
  119. //}
  120. /deep/ .el-radio__input.is-checked+.el-radio__label {
  121. /* 使用 CSS 变量来设置字体颜色 */
  122. color: var(--radio-label-color);
  123. }
  124. /deep/ .el-radio__input.is-checked .el-radio__inner{
  125. background: var(--radio-label-color);
  126. border-color: var(--radio-label-color);
  127. }
  128. }
  129. </style>