index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. this.dataList = list
  141. },
  142. // 获取表格的表头
  143. getLabel (col) {
  144. return col.remark || col.originalColumn
  145. },
  146. // 数据重置
  147. resetData () {
  148. this.columnData = {}
  149. this.dataList = []
  150. this.fields = {}
  151. this.chartTitle = ''
  152. },
  153. // 格式化fields
  154. fieldsFormat () {
  155. for (const item in this.columnData) {
  156. this.fields[this.columnData[item].remark || this.columnData[item].originalColumn] = this.columnData[item].originalColumn
  157. }
  158. },
  159. // 导出数据
  160. exportHandler () {
  161. this.$message.success('导出数据')
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .bs-data-view-dialog{
  168. /deep/.el-dialog__body{
  169. background-color: var(--bs-background-2) !important;
  170. max-height: unset!important;
  171. min-height: unset!important;
  172. }
  173. .el-table th.el-table__cell.is-leaf, .el-table /deep/td.el-table__cell{
  174. border-bottom:none;
  175. }
  176. /deep/.el-loading-mask{
  177. background-color: var(--bs-background-2) !important;
  178. }
  179. .el-table /deep/thead{
  180. color: var(--bs-el-title);
  181. }
  182. .bs-el-table /deep/td.el-table__cell{
  183. color: #bcc9d4;
  184. }
  185. /* 自定义滚动条样式 */
  186. /deep/.el-table__body-wrapper::-webkit-scrollbar {
  187. width: 6px; /* 滚动条宽度 */
  188. }
  189. /deep/.el-table__body-wrapper::-webkit-scrollbar-thumb {
  190. background-color: #888; /* 滚动条拖动块颜色 */
  191. height: 30px;
  192. border-radius: 5px;
  193. }
  194. /deep/.el-table__body-wrapper::-webkit-scrollbar-track {
  195. background-color: transparent; /* 滚动条轨道颜色 */
  196. }
  197. /* 鼠标悬停在滚动条上时的样式 */
  198. /deep/.el-table__body-wrapper::-webkit-scrollbar-thumb:hover {
  199. background-color: #555;
  200. cursor: pointer;
  201. }
  202. }
  203. </style>