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