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