index.vue 2.7 KB

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