index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. duration: 5000,
  93. type: 'warning'
  94. })
  95. }
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. .bs-design-wrap{
  102. width: 100%;
  103. }
  104. .content-box{
  105. text-align: center;
  106. /* 将背景设为渐变 */
  107. /*background-image: -webkit-linear-gradient(left, #6294F7, #C85D14);*/
  108. /* 规定背景绘制区域 */
  109. -webkit-background-clip: text;
  110. /* 将文字隐藏 */
  111. -webkit-text-fill-color: transparent;
  112. }
  113. </style>