index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div
  3. class="bs-design-wrap theme-switcher-wrap"
  4. :class="`bs-theme-switcher-${customTheme}`"
  5. >
  6. <el-dropdown
  7. trigger="click"
  8. @command="handleChange"
  9. >
  10. <div
  11. class="el-dropdown-link content-box"
  12. :style="{'font-size': config.customize.fontSize +'px','font-weight': +config.customize.fontWeight,'background-image': `-webkit-linear-gradient(${config.customize.color})`}"
  13. >
  14. 主题切换
  15. </div>
  16. <el-dropdown-menu
  17. slot="dropdown"
  18. class="theme-dropdown-menu"
  19. >
  20. <el-dropdown-item command="light">
  21. 明亮主题
  22. </el-dropdown-item>
  23. <el-dropdown-item command="dark">
  24. 暗黑主题
  25. </el-dropdown-item>
  26. </el-dropdown-menu>
  27. </el-dropdown>
  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. import { refreshComponentMixin } from 'data-room-ui/js/mixins/refreshComponent'
  35. export default {
  36. name: 'ThemeSwitcher',
  37. components: {},
  38. mixins: [paramsMixins, refreshComponentMixin],
  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. },
  60. mounted () {
  61. document.documentElement.style.setProperty('--radio-label-color', this.config.customize.activeColor)
  62. },
  63. methods: {
  64. ...mapMutations({
  65. changePageInfo: 'bigScreen/changePageInfo'
  66. }),
  67. // 点击切换主题
  68. handleChange (val) {
  69. const pageInfo = this.pageInfo
  70. this.pageInfo.pageConfig.customTheme = val
  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. duration: 5000,
  87. type: 'warning'
  88. })
  89. }
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .bs-design-wrap{
  96. width: 100%;
  97. display: flex;
  98. align-items: center;
  99. justify-content: center;
  100. }
  101. .content-box{
  102. text-align: center;
  103. /* 将背景设为渐变 */
  104. /*background-image: -webkit-linear-gradient(left, #6294F7, #C85D14);*/
  105. /* 规定背景绘制区域 */
  106. -webkit-background-clip: text;
  107. /* 将文字隐藏 */
  108. -webkit-text-fill-color: transparent;
  109. }
  110. // 自定义dropdown的样式
  111. .theme-dropdown-menu{
  112. background-color: var(--bs-background-2)!important;
  113. border: 1px solid var(--bs-border-1);
  114. ::v-deep .popper__arrow{
  115. //background-color: var(--bs-background-2)!important;
  116. background-color: transparent!important;
  117. border-bottom-color:transparent!important;
  118. &:after{
  119. border-bottom-color: var(--bs-background-2)!important;
  120. }
  121. }
  122. ::v-deep .el-dropdown-menu__item{
  123. background-color: var(--bs-background-2)!important;
  124. color: rgb(188, 201, 212)!important;
  125. &:hover {
  126. color: var(--bs-el-color-primary) !important;
  127. background-color: var(--bs-el-background-3) !important;
  128. }
  129. }
  130. }
  131. ::v-deep .el-input__inner,
  132. ::v-deep .el-color-picker__color-inner,
  133. ::v-deep .el-input-number--mini,
  134. ::v-deep .el-textarea__inner,
  135. ::v-deep .el-input-group__append {
  136. //background: var(--bs-el-background-1);
  137. //color: var(--bs-el-text);
  138. //border: 0 !important;
  139. //width: 100px;
  140. }
  141. </style>