index.vue 7.5 KB

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