index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. <DownloadExcel
  37. :data="dataList"
  38. :fields="fields"
  39. :name="chartTitle+'数据导出'"
  40. class="output-excel"
  41. :before-finish="exportHandler"
  42. >
  43. <el-button
  44. type="primary"
  45. :loading="exportLoading"
  46. >
  47. 导出数据
  48. </el-button>
  49. </DownloadExcel>
  50. </div>
  51. </el-dialog>
  52. </div>
  53. </template>
  54. <script>
  55. import { getUpdateChartInfo } from 'data-room-ui/js/api/bigScreenApi'
  56. import { mapState } from 'vuex'
  57. import Vue from 'vue'
  58. import JsonExcel from 'vue-json-excel'
  59. Vue.component('DownloadExcel', JsonExcel)
  60. export default {
  61. name: 'DataViewDialog',
  62. components: {},
  63. props: {
  64. },
  65. data () {
  66. return {
  67. chartTitle: '',
  68. fields: {},
  69. formVisible: false,
  70. exportLoading: false,
  71. loading: false,
  72. dataList: [],
  73. columnData: {}
  74. }
  75. },
  76. computed: {
  77. ...mapState({
  78. pageCode: state => state.bigScreen.pageInfo.code
  79. })
  80. },
  81. watch: {},
  82. created () {
  83. },
  84. mounted () {
  85. },
  86. methods: {
  87. init (config) {
  88. this.resetData()
  89. this.chartTitle = config.title
  90. this.formVisible = true
  91. this.getDataList(config)
  92. },
  93. // 获取数据列表
  94. getDataList (config) {
  95. this.loading = true
  96. // 如果是G2组件则需要从option里面取数据
  97. if (config.type === 'customComponent' && (!config.dataSource.businessKey)) {
  98. this.getDataByOption(config)
  99. this.fieldsFormat()
  100. this.loading = false
  101. } else {
  102. const params = {
  103. chart: {
  104. ...config,
  105. option: undefined
  106. },
  107. current: 1,
  108. pageCode: this.pageCode,
  109. type: config.type
  110. }
  111. // 调接口获取数据
  112. getUpdateChartInfo(params).then(res => {
  113. this.loading = false
  114. if (Array.isArray(res.data)) {
  115. this.dataList = res.data || []
  116. } else {
  117. // 如果返回的data不是数组,则是js数据集或者是http前端数据集,则直接从option中获取
  118. this.getDataByOption(config)
  119. }
  120. this.columnData = res.columnData || {}
  121. this.fieldsFormat()
  122. }).catch(err => { console.log(err) }).finally(() => {
  123. this.loading = false
  124. })
  125. }
  126. },
  127. // 通过option获取数据
  128. getDataByOption (config) {
  129. const list = config.option.data || []
  130. for (const key of Object.keys(list[0])) {
  131. this.columnData[key] = {
  132. aggregate: '',
  133. alias: key,
  134. originalColumn: key,
  135. remark: key,
  136. tableName: '',
  137. type: 'varchar'
  138. }
  139. }
  140. console.log(this.columnData)
  141. this.dataList = list
  142. },
  143. // 获取表格的表头
  144. getLabel (col) {
  145. return col.remark || col.originalColumn
  146. },
  147. // 数据重置
  148. resetData () {
  149. this.columnData = {}
  150. this.dataList = []
  151. this.fields = {}
  152. this.chartTitle = ''
  153. },
  154. // 格式化fields
  155. fieldsFormat () {
  156. for (const item in this.columnData) {
  157. this.fields[this.columnData[item].remark || this.columnData[item].originalColumn] = this.columnData[item].originalColumn
  158. }
  159. },
  160. // 导出数据
  161. exportHandler () {
  162. this.$message.success('导出数据')
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .bs-data-view-dialog{
  169. /deep/.el-dialog__body{
  170. background-color: var(--bs-background-2) !important;
  171. max-height: unset!important;
  172. min-height: unset!important;
  173. }
  174. .el-table th.el-table__cell.is-leaf, .el-table /deep/td.el-table__cell{
  175. border-bottom:none;
  176. }
  177. /deep/.el-loading-mask{
  178. background-color: var(--bs-background-2) !important;
  179. }
  180. /* 自定义滚动条样式 */
  181. /deep/.el-table__body-wrapper::-webkit-scrollbar {
  182. width: 6px; /* 滚动条宽度 */
  183. }
  184. /deep/.el-table__body-wrapper::-webkit-scrollbar-thumb {
  185. background-color: #888; /* 滚动条拖动块颜色 */
  186. height: 30px;
  187. border-radius: 5px;
  188. }
  189. /deep/.el-table__body-wrapper::-webkit-scrollbar-track {
  190. background-color: transparent; /* 滚动条轨道颜色 */
  191. }
  192. /* 鼠标悬停在滚动条上时的样式 */
  193. /deep/.el-table__body-wrapper::-webkit-scrollbar-thumb:hover {
  194. background-color: #555;
  195. cursor: pointer;
  196. }
  197. }
  198. </style>