83e49367fa109faa4c96381c94f6685046d221d2.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div ref="tableWarp" class="tableWarp">
  3. <!-- 操作按钮区域 -->
  4. <slot name="extra_" slot="extra"></slot>
  5. <div class="table-operator">
  6. <a-row type="flex" :gutter="24" justify="space-between">
  7. <a-col :xl="16" :lg="16" :md="16" :sm="16" >
  8. <a-button type="primary" icon="download" >导出</a-button>
  9. <h5 style="display:inline-block;">{{cggraphreportData.head.annotation}}</h5>
  10. </a-col>
  11. </a-row>
  12. </div>
  13. <a-table
  14. size="middle"
  15. bordered
  16. rowKey="id"
  17. :columns="columns"
  18. :data-source="getTableAddTotalRow"
  19. :pagination="false"
  20. :scroll="{x:getTableScroll}"
  21. >
  22. <template v-for="(key,i) in Object.keys(customRender)" :slot="key" slot-scope="text, record, index">
  23. <div class="custom-render" :key="i" @click="addComment(text,record,index,$event)" v-html="customRender[key](text, record)"></div>
  24. </template>
  25. </a-table>
  26. </div>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'GraphreportAutoTreeTable',
  31. computed: {
  32. getTableAddTotalRow() { // 根据配置获取表格数据
  33. let tableDataSource_
  34. if (this.cggraphreportData.head.dataType === 'json') {
  35. tableDataSource_ = JSON.parse(JSON.stringify(this.chartData))
  36. } else if (this.cggraphreportData.head.dataType === 'sql' || this.cggraphreportData.head.dataType === 'bean') {
  37. tableDataSource_ = JSON.parse(JSON.stringify(this.cggraphreportData.data.data))
  38. }
  39. return tableDataSource_
  40. },
  41. getTableScroll() {
  42. const width = this.columns.length * 100 - 40
  43. // 解决表格列分配宽度小于表格宽度时 多一列bug
  44. if (width < this.tableWarpWidth) {
  45. this.columns.forEach(function(item) {
  46. if (item.dataIndex !== 'rowIndex') {
  47. delete item.width
  48. }
  49. })
  50. }
  51. return width > this.tableWarpWidth ? width : false
  52. }
  53. },
  54. data() {
  55. return {
  56. columns: [], // 需要渲染的表头
  57. customRender: {},
  58. spinning: true,
  59. tableWarpWidth: 0, // 判断table是否超宽
  60. isTotal: false // 判断是否合计
  61. }
  62. },
  63. props: ['items', 'cggraphreportData', 'chartData'],
  64. watch: {
  65. items: {
  66. handler(val, oldVal) {
  67. this.getColunms()
  68. },
  69. deep: true // true 深度监听
  70. }
  71. },
  72. mounted() {
  73. this.$nextTick(() => {
  74. if (this.$refs.tableWarp) {
  75. this.tableWarpWidth = this.$refs.tableWarp.offsetWidth
  76. }
  77. this.getColunms()
  78. })
  79. },
  80. methods: {
  81. getColunms() { // 根据弹窗的数据获取表格的表头
  82. const that = this
  83. const items = JSON.parse(JSON.stringify(this.items))
  84. items.sort(function(a, b) {
  85. return a.orderNum - b.orderNum
  86. })
  87. items.forEach((item, i) => {
  88. if (item.isShow) {
  89. const column = {
  90. title: item.fieldTxt,
  91. dataIndex: item.fieldName,
  92. width: 100
  93. }
  94. if (i !== 0) {
  95. column.align = 'center'
  96. }
  97. if (item.jsEnhance) {
  98. column.scopedSlots = { customRender: column.dataIndex }
  99. var obj = eval('(' + item.jsEnhance + ')')
  100. that.customRender[column.dataIndex] = obj.customRender
  101. }
  102. that.columns.push(column)
  103. }
  104. })
  105. },
  106. addComment(text, record, index, $event) { // 处理js增强添加的方法 目前只支持click
  107. var domClick = $event.target.getAttribute('@click')
  108. if (domClick) {
  109. domClick = eval('(' + domClick + ')')
  110. domClick.call(this, text, record, index)
  111. }
  112. }
  113. }
  114. }
  115. </script>
  116. <style scoped>
  117. .ant-table td { white-space: nowrap; }
  118. </style>
  119. <style>
  120. .custom-render>*{
  121. display: inline-block;
  122. min-width: 20px;
  123. height: 100%;
  124. border-radius: 5px;
  125. }
  126. .custom-render{
  127. display: inline-block;
  128. }
  129. </style>