index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. width="60%"
  13. :visible.sync="formVisible"
  14. :append-to-body="false"
  15. class="bs-dialog-wrap bs-el-dialog"
  16. >
  17. <div class="table-box">
  18. <el-table
  19. ref="table"
  20. v-loading="loading"
  21. class="bs-table bs-el-table"
  22. :data="dataList"
  23. >
  24. <el-table-column
  25. v-for="(col,index) in columnData"
  26. :key="index"
  27. show-overflow-tooltip
  28. :prop="col.alias"
  29. :label="getLabel(col)"
  30. align="center"
  31. />
  32. </el-table>
  33. </div>
  34. <div
  35. slot="footer"
  36. class="dialog-footer"
  37. >
  38. <el-button
  39. class="bs-el-button-default cancel"
  40. @click="cancel"
  41. >
  42. 取消
  43. </el-button>
  44. <DownloadExcel
  45. :data="dataList"
  46. :fields="fields"
  47. :name="chartTitle+'数据导出'"
  48. class="output-excel"
  49. :before-finish="exportHandler"
  50. :before-generate="generate"
  51. >
  52. <el-button
  53. type="primary"
  54. :loading="exportLoading"
  55. >
  56. 导出数据
  57. </el-button>
  58. </DownloadExcel>
  59. </div>
  60. </el-dialog>
  61. </div>
  62. </template>
  63. <script>
  64. import { getUpdateChartInfo } from 'data-room-ui/js/api/bigScreenApi'
  65. import { mapState } from 'vuex'
  66. import Vue from 'vue'
  67. import JsonExcel from 'vue-json-excel'
  68. Vue.component('DownloadExcel', JsonExcel)
  69. export default {
  70. name: 'DataViewDialog',
  71. components: {},
  72. props: {
  73. },
  74. data () {
  75. return {
  76. chartTitle: '',
  77. fields: {},
  78. formVisible: false,
  79. exportLoading: false,
  80. loading: false,
  81. dataList: [],
  82. columnData: {}
  83. }
  84. },
  85. computed: {
  86. ...mapState({
  87. pageCode: state => state.bigScreen.pageInfo.code
  88. })
  89. },
  90. watch: {},
  91. created () {
  92. },
  93. mounted () {
  94. },
  95. methods: {
  96. init (config) {
  97. this.resetData()
  98. this.chartTitle = config.title
  99. this.formVisible = true
  100. this.getDataList(config)
  101. },
  102. // 获取数据列表
  103. getDataList (config) {
  104. this.loading = true
  105. // 如果是G2组件则需要从option里面取数据
  106. if (['customComponent', 'remoteComponent', 'echartsComponent'].includes(config.type) && (!config.dataSource.businessKey)) {
  107. this.getDataByOption(config)
  108. this.fieldsFormat()
  109. this.loading = false
  110. } else {
  111. const params = {
  112. chart: {
  113. ...config,
  114. option: undefined
  115. },
  116. current: 1,
  117. pageCode: this.pageCode,
  118. type: config.type
  119. }
  120. // 调接口获取数据
  121. getUpdateChartInfo(params).then(res => {
  122. this.loading = false
  123. if (Array.isArray(res.data)) {
  124. this.dataList = res.data || []
  125. } else {
  126. // 如果返回的data不是数组,存在以下几种情况:则直接从option中获取
  127. // 1、是组件绑定的是js数据集或者是http前端数据集,
  128. // 2、是组件返回的模拟数据为null
  129. this.getDataByOption(config)
  130. }
  131. this.columnData = res.columnData || {}
  132. this.fieldsFormat()
  133. }).catch(err => { console.log(err) }).finally(() => {
  134. this.loading = false
  135. })
  136. }
  137. },
  138. // 通过option获取数据
  139. getDataByOption (config) {
  140. let list = []
  141. if (config.chartType === 'Treemap') {
  142. list = config.option.data.children
  143. } else if (config.type === 'tables') {
  144. list = config.option.tableData
  145. } else {
  146. list = config.option.data
  147. }
  148. let keyList = []
  149. if (list && list.length) {
  150. // 如果list[0]是对象
  151. if (typeof list[0] === 'object' && list[0] !== null) {
  152. keyList = Object.keys(list[0])
  153. } else {
  154. keyList = list
  155. }
  156. for (const key of keyList) {
  157. const _key = key + ''
  158. this.columnData[_key] = {
  159. aggregate: '',
  160. alias: _key,
  161. originalColumn: _key,
  162. remark: _key,
  163. tableName: '',
  164. type: 'varchar'
  165. }
  166. }
  167. } else {
  168. this.columnData = {}
  169. }
  170. this.dataList = list || []
  171. },
  172. // 获取表格的表头
  173. getLabel (col) {
  174. return col.remark || col.alias
  175. },
  176. // 数据重置
  177. resetData () {
  178. this.columnData = {}
  179. this.dataList = []
  180. this.fields = {}
  181. this.chartTitle = ''
  182. },
  183. // 格式化fields
  184. fieldsFormat () {
  185. if (this.columnData && Object.keys(this.columnData).length) {
  186. for (const item in this.columnData) {
  187. this.fields[this.columnData[item].remark || this.columnData[item].alias] = this.columnData[item].alias
  188. }
  189. } else {
  190. this.fields = {}
  191. }
  192. },
  193. // 取消
  194. cancel () {
  195. this.formVisible = false
  196. },
  197. generate (val) {
  198. if (!Object.keys(this.fields).length) {
  199. this.$message.warning('数据为空')
  200. }
  201. this.formVisible = false
  202. this.exportLoading = true
  203. },
  204. // 导出数据
  205. exportHandler () {
  206. this.exportLoading = false
  207. if (Object.keys(this.fields).length) {
  208. this.$message.success('数据导出成功')
  209. }
  210. this.formVisible = false
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .bs-data-view-dialog{
  217. /deep/.el-dialog__body{
  218. background-color: var(--bs-background-2) !important;
  219. overflow-y: auto!important;
  220. max-height: calc(90vh - 500px) !important;
  221. }
  222. .table-box{
  223. height: 100%;
  224. overflow-y: auto; /* 当内容溢出时显示垂直滚动条 */
  225. }
  226. .dialog-footer{
  227. display: flex;
  228. justify-content: flex-end;
  229. .cancel{
  230. margin-right: 10px;
  231. overflow-y: hidden;
  232. }
  233. }
  234. .el-table th.el-table__cell.is-leaf, .el-table /deep/td.el-table__cell{
  235. border-bottom:none;
  236. }
  237. /deep/.el-loading-mask{
  238. background-color: var(--bs-background-2) !important;
  239. }
  240. .el-table /deep/thead{
  241. color: var(--bs-el-title);
  242. }
  243. .bs-el-table /deep/td.el-table__cell{
  244. color: #bcc9d4;
  245. }
  246. .el-table--scrollable-y /deep/.el-table__body-wrapper{
  247. //overflow-y: hidden;
  248. }
  249. /* 修改滚动条的样式 */
  250. /deep/.el-dialog__body::-webkit-scrollbar {
  251. width: 8px; /* 滚动条宽度 */
  252. }
  253. /deep/.el-dialog__body::-webkit-scrollbar-thumb {
  254. background-color: #888; /* 滚动条拖动块颜色 */
  255. height: 30px;
  256. border-radius: 5px;
  257. }
  258. /deep/.el-dialog__body::-webkit-scrollbar-track {
  259. background-color: transparent; /* 滚动条轨道颜色 */
  260. }
  261. /* 鼠标悬停在滚动条上时的样式 */
  262. /deep/.el-dialog__body::-webkit-scrollbar-thumb:hover {
  263. background-color: #555;
  264. }
  265. }
  266. </style>