index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div
  3. class="bs-design-wrap"
  4. :class="`bs-chart-tab-${customTheme}`"
  5. >
  6. <div
  7. v-if="config.customize.tabList.length"
  8. class="tab-title-box"
  9. :style="{'justify-content':config.customize.position}"
  10. >
  11. <div
  12. v-for="(tab,index) in config.customize.tabList"
  13. :key="index"
  14. class="tab-title-item"
  15. :class="{active:currentIndex === index}"
  16. :style="
  17. 'font-size:' +
  18. config.customize.fontSize +
  19. 'px;color:' +
  20. config.customize.color +
  21. ';font-weight:' +
  22. config.customize.fontWeight
  23. "
  24. @click="changeTab(index)"
  25. >
  26. {{ tab.name }}
  27. </div>
  28. </div>
  29. <div
  30. class="line-box"
  31. :style="{'background-color':config.customize.lineColor}"
  32. />
  33. <div
  34. v-if="config.customize.tabList &&config.customize.tabList.length"
  35. class="chart-item-box"
  36. >
  37. <Configuration
  38. :config="config.customize.tabList[currentIndex].chart"
  39. @openRightPanel="openRightPanel"
  40. >
  41. <RenderCardInner
  42. :ref="'RenderCard' + config.customize.tabList[currentIndex].chartCode"
  43. :config="config.customize.tabList[currentIndex].chart"
  44. @click.native="currentChartHandler"
  45. />
  46. </Configuration>
  47. </div>
  48. <el-empty
  49. v-else-if="!config.customize.tabList.length"
  50. description="请在右侧面板选择图表加入"
  51. />
  52. </div>
  53. </template>
  54. <script>
  55. import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
  56. import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
  57. import cloneDeep from 'lodash/cloneDeep'
  58. import { mapMutations, mapState } from 'vuex'
  59. import RenderCardInner from 'data-room-ui/Render/RenderCard2.vue'
  60. import Configuration from 'data-room-ui/Render/Configuration.vue'
  61. import { EventBus } from 'data-room-ui/js/utils/eventBus'
  62. export default {
  63. name: 'ChartTab',
  64. components: { Configuration, RenderCardInner },
  65. mixins: [paramsMixins],
  66. props: {
  67. config: {
  68. type: Object,
  69. default: () => ({})
  70. }
  71. },
  72. computed: {
  73. ...mapState({
  74. pageCode: state => state.bigScreen.pageInfo.code,
  75. customTheme: state => state.bigScreen.pageInfo.pageConfig.customTheme,
  76. activeCode: state => state.bigScreen.activeCode,
  77. chartList: (state) => state.bigScreen.pageInfo.chartList
  78. })
  79. },
  80. data () {
  81. return {
  82. // currentChart: null
  83. currentIndex: 0
  84. }
  85. },
  86. mounted () {
  87. },
  88. // 销毁定时器
  89. destroyed () {
  90. if (this.timer) {
  91. clearInterval(this.timer) // 关闭
  92. }
  93. },
  94. methods: {
  95. ...mapMutations({
  96. changeChartConfig: 'bigScreen/changeChartConfig',
  97. changeActiveItemConfig: 'bigScreen/changeActiveItemConfig',
  98. changeActiveCode: 'bigScreen/changeActiveCode'
  99. }),
  100. changeStyle (config) {
  101. config = { ...this.config, ...config }
  102. // 样式改变时更新主题配置
  103. config.theme = settingToTheme(cloneDeep(config), this.customTheme)
  104. this.changeChartConfig(config)
  105. if (config.code === this.activeCode) {
  106. this.changeActiveItemConfig(config)
  107. }
  108. },
  109. // 切换tab页
  110. changeTab (index) {
  111. this.currentIndex = index
  112. },
  113. // 点击Tab中的某个组件
  114. currentChartHandler () {
  115. this.changeActiveCode(this.config.customize.tabList[this.currentIndex]?.chartCode)
  116. this.changeActiveItemConfig(this.config.customize.tabList[this.currentIndex]?.chart)
  117. console.log()
  118. },
  119. // 打开右侧面板
  120. openRightPanel () {
  121. // EventBus.$emit('openRightPanel', this.currentChart)
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .bs-design-wrap{
  128. width: 100%;
  129. .tab-title-box{
  130. height: 40px;
  131. display: flex;
  132. &:hover{
  133. cursor: pointer;
  134. }
  135. .tab-title-item{
  136. padding:10px;
  137. }
  138. }
  139. .chart-item-box{
  140. width: 100%;
  141. height: calc(100% - 40px);
  142. }
  143. .active{
  144. color: var(--bs-el-color-primary) !important;
  145. }
  146. .line-box{
  147. width: 98%;
  148. height: 1px;
  149. margin: 0 auto;
  150. //background-color: #d0d2d6;
  151. }
  152. }
  153. </style>