e1d147c4ff5f1bc7f2bb48b80ca2119338ce7f32.svn-base 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="pane-container" style="position: relactive">
  3. <!-- 单独画出来的转换表格 -->
  4. <el-button v-if="isChart" type="text" style="z-index: 1;position: absolute;top:10px;right: 100px" @click="handleTable()">切换表格</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.currentType.matchRule.isUsable(store.state.dimensions, store.state.caculCols)) {
  91. this.$emit('update:chartType', 'table')
  92. }
  93. // this.reload()
  94. }
  95. }
  96. },
  97. methods: {
  98. // 切换表格
  99. handleTable() {
  100. console.log('切换表格')
  101. console.log('chartTypeList', this.chartTypeList)
  102. console.log('this.schema============', this.schema)
  103. console.log('this.data============', this.data)
  104. this.isTable = true
  105. this.isChart = false
  106. },
  107. handleChart() {
  108. console.log('切换图表')
  109. this.isChart = true
  110. this.isTable = false
  111. },
  112. isUsable(chart) {
  113. return chart.matchRule.isUsable(store.state.dimensions, store.state.caculCols)
  114. },
  115. switchChartType(chart) {
  116. if (!chart.matchRule.isUsable(store.state.dimensions, store.state.caculCols)) {
  117. return
  118. }
  119. this.$emit('update:chartType', chart.type)
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. .pane-container {
  126. display: flex;
  127. height: 100%;
  128. .visualize-window {
  129. width: 100%;
  130. }
  131. .chart-style-panel {
  132. width: 200px;
  133. flex-shrink: 0;
  134. padding: 10px;
  135. .chart-type-list {
  136. width: 100%;
  137. display: grid;
  138. justify-items: center;
  139. grid-template-columns: repeat(5, 1fr);
  140. grid-auto-rows: 1fr;
  141. grid-gap: 10px;
  142. span {
  143. line-height: initial;
  144. height: 100%;
  145. font-size: 22px;
  146. cursor: pointer;
  147. text-align: center;
  148. width: 100%;
  149. position: relative;
  150. .icon {
  151. position: absolute;
  152. top: 0;
  153. left: 0;
  154. right: 0;
  155. bottom: 0;
  156. margin: auto;
  157. }
  158. }
  159. span::before {
  160. content: "";
  161. width: 100%;
  162. padding-bottom: 100%;
  163. display: block;
  164. }
  165. .disabledIcon {
  166. cursor: not-allowed;
  167. }
  168. .activedIcon {
  169. background: #c9c9c9;
  170. }
  171. }
  172. }
  173. }
  174. </style>