index.vue 3.9 KB

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