b581be3f0b1bbe632fc897aa2a334a81f09b8c65.svn-base 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="pane-container" style="position: relactive">
  3. <!-- 单独画出来的转换表格 -->
  4. <el-button v-if="isChart1" type="text" style="z-index: 1;position: absolute;top:10px;right: 100px" @click="handleTable()">切换表格111</el-button>
  5. <div v-if="isTable" class="table" style="width: 100%;height:100%;z-index: 1;position: absolute;top:0px;right: 0px;">
  6. <el-button type="text" style="float: right;margin-right: 100px;" @click="handleChart()">切换图表</el-button>
  7. <el-table style="width: 100%" border="true" fit highlight-current-row :data="data">
  8. <template v-for="(item,index) in schema">
  9. <el-table-column :key="index" :prop="item.Column" :label="item.Comment" />
  10. </template>
  11. </el-table>
  12. </div>
  13. <component :is="currentType.componentName" :data="chartData" :schema="schema" :chart-style="chartStyle" class="visualize-window" />
  14. <div v-if="isEditMode" class="chart-style-panel">
  15. <el-form label-position="top" size="mini">
  16. <el-form-item :label="$t('chart.chartType')+':'">
  17. <div class="chart-type-list">
  18. <span v-for="item in chartTypeList" :key="item.type" :class="{activedIcon :item.type===chartType, disabledIcon: !isUsable(item)}" @click="switchChartType(item)">
  19. <el-tooltip :content="item.name +': '+item.matchRule.desc" placement="top">
  20. <svg-icon class="icon" :icon-class="isUsable(item)? item.icon : (item.icon + '_disabled')" />
  21. </el-tooltip>
  22. </span>
  23. </div>
  24. </el-form-item>
  25. </el-form>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import lineChart from '@/widgets/lineChart'
  31. import DataTable from '@/widgets/DataTable'
  32. import BarChart from '@/widgets/BarChart'
  33. import StackBarChart from '@/widgets/StackBarChart'
  34. import HorizontalBar from '@/widgets/horizontalBar'
  35. import PieChart from '@/widgets/PieChart'
  36. import BarLineChart from '@/widgets/BarLineChart'
  37. import LineBarChart from '@/widgets/LineBarChart'
  38. import chartTypeList from '@/utils/chartTypeList'
  39. import store from '../store'
  40. export default {
  41. inject: ['reload'],
  42. components: { lineChart, DataTable, BarChart, StackBarChart, PieChart, HorizontalBar, BarLineChart, LineBarChart },
  43. props: {
  44. data: {
  45. type: Array,
  46. required: true
  47. },
  48. schema: {
  49. type: Array,
  50. required: true
  51. },
  52. chartStyle: {
  53. require: false,
  54. type: Object
  55. },
  56. chartType: {
  57. type: String,
  58. default: 'table'
  59. },
  60. isEditMode: {
  61. type: Boolean,
  62. default: true
  63. }
  64. },
  65. data() {
  66. return {
  67. chartTypeList,
  68. isTable: false,
  69. isChart: true
  70. }
  71. },
  72. computed: {
  73. allSelected() {
  74. return store.state.caculCols.concat(store.state.dimensions)
  75. },
  76. chartData() {
  77. console.log('this.schema============', this.schema)
  78. return this.currentType.dataTransfer ? this.currentType.dataTransfer(this.data, this.schema) : this.data
  79. },
  80. currentType() {
  81. return chartTypeList.find(item => item.type === this.chartType)
  82. }
  83. },
  84. watch: {
  85. allSelected: {
  86. deep: true,
  87. immediate: true,
  88. handler(newVal) {
  89. console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!', this.chartType)
  90. if(this.chartType == 'table'){
  91. this.isChart1 = false
  92. }else{
  93. this.isChart1 = true
  94. }
  95. if (!this.currentType.matchRule.isUsable(store.state.dimensions, store.state.caculCols)) {
  96. this.$emit('update:chartType', 'table')
  97. }
  98. // this.reload()
  99. }
  100. }
  101. },
  102. methods: {
  103. // 切换表格
  104. handleTable() {
  105. console.log('切换表格')
  106. console.log('chartTypeList', this.chartTypeList)
  107. console.log('this.schema============', this.schema)
  108. console.log('this.data============', this.data)
  109. this.isTable = true
  110. this.isChart = false
  111. },
  112. handleChart() {
  113. console.log('切换图表')
  114. this.isChart = true
  115. this.isTable = false
  116. },
  117. isUsable(chart) {
  118. return chart.matchRule.isUsable(store.state.dimensions, store.state.caculCols)
  119. },
  120. switchChartType(chart) {
  121. if (!chart.matchRule.isUsable(store.state.dimensions, store.state.caculCols)) {
  122. return
  123. }
  124. this.$emit('update:chartType', chart.type)
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .pane-container {
  131. display: flex;
  132. height: 100%;
  133. .visualize-window {
  134. width: 100%;
  135. }
  136. .chart-style-panel {
  137. width: 200px;
  138. flex-shrink: 0;
  139. padding: 10px;
  140. .chart-type-list {
  141. width: 100%;
  142. display: grid;
  143. justify-items: center;
  144. grid-template-columns: repeat(5, 1fr);
  145. grid-auto-rows: 1fr;
  146. grid-gap: 10px;
  147. span {
  148. line-height: initial;
  149. height: 100%;
  150. font-size: 22px;
  151. cursor: pointer;
  152. text-align: center;
  153. width: 100%;
  154. position: relative;
  155. .icon {
  156. position: absolute;
  157. top: 0;
  158. left: 0;
  159. right: 0;
  160. bottom: 0;
  161. margin: auto;
  162. }
  163. }
  164. span::before {
  165. content: "";
  166. width: 100%;
  167. padding-bottom: 100%;
  168. display: block;
  169. }
  170. .disabledIcon {
  171. cursor: not-allowed;
  172. }
  173. .activedIcon {
  174. background: #c9c9c9;
  175. }
  176. }
  177. }
  178. }
  179. </style>