6c45e23413a71fcbf4ae3f22bbc4293d83c782f9.svn-base 5.4 KB

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