index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!--
  2. @name:数据预览弹窗
  3. @description:
  4. @author: liu.shiyi
  5. @time:
  6. -->
  7. <template>
  8. <div class="bs-data-view-dialog">
  9. <el-dialog
  10. :close-on-click-modal="false"
  11. title="数据查看"
  12. :visible.sync="formVisible"
  13. :append-to-body="false"
  14. class="bs-dialog-wrap bs-el-dialog"
  15. >
  16. <el-table
  17. ref="table"
  18. v-loading="loading"
  19. class="bs-table bs-el-table"
  20. height="300"
  21. :data="dataList"
  22. >
  23. <el-table-column
  24. v-for="(col,index) in columnData"
  25. :key="index"
  26. show-overflow-tooltip
  27. :prop="col.alias"
  28. :label="getLabel(col)"
  29. align="center"
  30. />
  31. </el-table>
  32. <div
  33. slot="footer"
  34. class="dialog-footer"
  35. >
  36. <el-button
  37. type="primary"
  38. :loading="sureLoading"
  39. @click="exportHandler"
  40. >
  41. 导出数据
  42. </el-button>
  43. </div>
  44. </el-dialog>
  45. </div>
  46. </template>
  47. <script>
  48. import { getChatInfo, getUpdateChartInfo } from 'data-room-ui/js/api/bigScreenApi'
  49. import { mapState } from 'vuex'
  50. export default {
  51. name: 'DataViewDialog',
  52. components: {},
  53. props: {
  54. },
  55. data () {
  56. return {
  57. formVisible: false,
  58. sureLoading: false,
  59. loading: false,
  60. dataList: [],
  61. columnData: []
  62. }
  63. },
  64. computed: {
  65. ...mapState({
  66. pageCode: state => state.bigScreen.pageInfo.code
  67. })
  68. },
  69. watch: {},
  70. created () {
  71. },
  72. mounted () {
  73. },
  74. methods: {
  75. init (config) {
  76. this.resetData()
  77. this.formVisible = true
  78. this.getDataList(config)
  79. },
  80. // 获取数据列表
  81. getDataList (config) {
  82. this.loading = true
  83. if (config.type === 'customComponent' && (!config.dataSource.businessKey)) {
  84. this.getDataByOption(config)
  85. this.loading = false
  86. } else {
  87. const params = {
  88. chart: {
  89. ...config,
  90. option: undefined
  91. },
  92. current: 1,
  93. pageCode: this.pageCode,
  94. type: config.type
  95. }
  96. getUpdateChartInfo(params).then(res => {
  97. this.loading = false
  98. if (Array.isArray(res.data)) {
  99. this.dataList = res.data || []
  100. } else {
  101. this.getDataByOption(config)
  102. }
  103. this.columnData = res.columnData || []
  104. }).catch(err => { console.log(err) }).finally(() => {
  105. this.loading = false
  106. })
  107. }
  108. },
  109. getDataByOption (config) {
  110. const list = config.option.data || []
  111. this.columnData = list && list.length ? (Object.keys(list[0])).map((key) => {
  112. return {
  113. aggregate: '',
  114. alias: key,
  115. originalColumn: key,
  116. remark: key,
  117. tableName: '',
  118. type: 'varchar'
  119. }
  120. }) : []
  121. this.dataList = list
  122. },
  123. getLabel (col) {
  124. return col.remark || col.originalColumn
  125. },
  126. // 数据重置
  127. resetData () {
  128. this.columnData = []
  129. this.dataList = []
  130. },
  131. // 导出数据
  132. exportHandler () {
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .bs-data-view-dialog{
  139. /deep/.el-dialog__body{
  140. background-color: var(--bs-background-2) !important;
  141. }
  142. .el-table th.el-table__cell.is-leaf, .el-table /deep/td.el-table__cell{
  143. border-bottom:none;
  144. }
  145. }
  146. </style>