lambo-design-bi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/bi/widget/README.md +18 -0
  2. package/bi/widget/api/data.js +48 -0
  3. package/bi/widget/atom/index.vue +36 -0
  4. package/bi/widget/atom/test.vue +36 -0
  5. package/bi/widget/config/config.js +7 -0
  6. package/bi/widget/container/card/card-widget.vue +46 -0
  7. package/bi/widget/container/card/comps/indicator-card/index.js +7 -0
  8. package/bi/widget/container/card/comps/indicator-card/src/indicator-card-bi-search.vue +132 -0
  9. package/bi/widget/container/card/comps/indicator-card/src/indicator-card-bi.vue +129 -0
  10. package/bi/widget/container/card/comps/indicator-card/src/indicator-card-item-bi.vue +97 -0
  11. package/bi/widget/container/card/comps/indicator-card/src/styles/css/card-search.less +108 -0
  12. package/bi/widget/container/card/comps/indicator-card/src/styles/css/card.less +114 -0
  13. package/bi/widget/layout/col.vue +35 -0
  14. package/bi/widget/layout/row.vue +40 -0
  15. package/bi/widget/num/index.vue +101 -0
  16. package/bi/widget/page/index.vue +38 -0
  17. package/bi/widget/search/search-form.vue +85 -0
  18. package/bi/widget/search/search-item.vue +205 -0
  19. package/bi/widget/table/detail-table.vue +65 -0
  20. package/bi/widget/table/paging-table.vue +188 -0
  21. package/bi/widget/util/widget-map.js +41 -0
  22. package/package.json +39 -0
  23. package/pub/charts/echarts.vue +57 -0
  24. package/pub/charts/factory/charts-factory.vue +58 -0
  25. package/pub/charts/factory/options.js +2351 -0
  26. package/pub/empty/index.vue +33 -0
  27. package/pub/helpbox/README.md +6 -0
  28. package/pub/helpbox/index.vue +363 -0
  29. package/pub/num-index/num-index.vue +120 -0
  30. package/pub/table/detail-table/index.vue +41 -0
  31. package/pub/table/paging-table/README.md +4 -0
  32. package/pub/table/paging-table/comps/export-data.vue +390 -0
  33. package/pub/table/paging-table/comps/export-drawer.vue +429 -0
  34. package/pub/table/paging-table/index.js +3 -0
  35. package/pub/table/paging-table/index.vue +1577 -0
  36. package/pub/table/paging-table/styles/css/index.less +190 -0
  37. package/pub/theme/color.js +3 -0
  38. package/util/math-util.js +71 -0
  39. package/util/num-util.js +16 -0
@@ -0,0 +1,390 @@
1
+ <template>
2
+ <div class="export-data">
3
+ <Row type="flex" justify="center">
4
+ <Form v-model="form" :label-width="80">
5
+ <FormItem label="导出格式">
6
+ <Select v-model="form.fileFormat" style="width:270px">
7
+ <Option key="xlsx" value="xlsx">xlsx</Option>
8
+ <Option key="csv" value="csv">csv</Option>
9
+ </Select>
10
+ </FormItem>
11
+ <FormItem label="文件名">
12
+ <Input v-model="form.fileName" icon="document" placeholder="自定义文件名" style="width:270px" />
13
+ </FormItem>
14
+ </Form>
15
+ </Row>
16
+ <Row type="flex" justify="center">
17
+ <Col>
18
+ <Button type="primary" :loading="exportCurrentLoading" @click="exportCurrentPage"
19
+ style="margin-right: 10px">导出当前页</Button>
20
+ <Poptip v-if="exportBatchSize > 0" trigger="hover" title="提示" :content="'单次最大导出' + exportBatchSize + '条数据'"
21
+ placement="top">
22
+ <Button type="default" :loading="exportAllLoading" @click="exportBatch" style="margin-left: 8px">
23
+ 导出全部
24
+ </Button>
25
+ </Poptip>
26
+ <Button v-else :loading="exportAllLoading" type="default" @click="exportAllData">导出全部</Button>
27
+ </Col>
28
+ </Row>
29
+ <Row class="ivu-upload-list-file">
30
+ <LamboPercentProgress v-model="showProgress" :progress="progress" :status="status"></LamboPercentProgress>
31
+ </Row>
32
+ <export-drawer v-model="showFileList" :file-list="fileList" :export-mode="exportMode" :request-url="requestUrl"
33
+ :request-limit="exportRequestLimit" :requestMethod="reqMethod" :request-success-codes="requestSuccessCodes"
34
+ :searchParams="searchParams" :sortParams="sortParams" :tableColumns="tableColumns" :parsed-columns="parsedColumns"
35
+ :show-summary="showSummary" :summary-method="summaryMethod"></export-drawer>
36
+ </div>
37
+ </template>
38
+ <script>
39
+ import ajax from '@lambo-design/shared/utils/ajax'
40
+ import excel from '@lambo-design/shared/utils/excel'
41
+ import { deepCopy } from '@lambo-design/shared/utils/assist'
42
+ import LamboPercentProgress from '@lambo-design/percent-progress'
43
+ import ExportDrawer from "./export-drawer.vue"
44
+
45
+ export default {
46
+ name: 'export-data',
47
+ components: {
48
+ LamboPercentProgress,
49
+ ExportDrawer
50
+ },
51
+ props: {
52
+ tableName: {
53
+ type: String,
54
+ default: '表格数据'
55
+ },
56
+ tableColumns: {
57
+ type: Array,
58
+ default() {
59
+ return [];
60
+ }
61
+ },
62
+ dataUrl: {
63
+ type: String,
64
+ default() {
65
+ return "";
66
+ }
67
+ },
68
+ exportUrl: {
69
+ type: String,
70
+ default() {
71
+ return "";
72
+ }
73
+ },
74
+ exportMode: {
75
+ type: String,
76
+ default() {
77
+ return "front";
78
+ }
79
+ },
80
+ exportBatchSize: {
81
+ type: Number,
82
+ default: -1
83
+ },
84
+ exportRequestLimit: {
85
+ type: Number,
86
+ default: -1
87
+ },
88
+ exportSpanColumns: {
89
+ type: Array,
90
+ default() {
91
+ return [];
92
+ }
93
+ },
94
+ requestMethod: {
95
+ type: String,
96
+ default: 'GET',
97
+ },
98
+ requestSuccessCodes: {
99
+ type: Array,
100
+ default: function () {
101
+ return [1, "000"]
102
+ },
103
+ validator(value) {
104
+ if (value != null && [...value].sort().toString() !== [1, "1", "000"].sort().toString()) {
105
+ console.warn("不推荐单独设置请求成功返回码");
106
+ }
107
+ return value instanceof Array;
108
+ }
109
+ },
110
+ searchParams: {
111
+ type: Object,
112
+ default() {
113
+ return {};
114
+ }
115
+ },
116
+ sortParams: {
117
+ type: Object,
118
+ default() {
119
+ return {};
120
+ }
121
+ },
122
+ paginationParams: {
123
+ type: Object,
124
+ default() {
125
+ return {};
126
+ }
127
+ },
128
+ showSummary: {
129
+ type: Boolean,
130
+ default: false
131
+ },
132
+ summaryMethod: {
133
+ type: Function,
134
+ default: () => {
135
+ }
136
+ },
137
+ parsedColumns: {
138
+ type: Array,
139
+ default() {
140
+ return [];
141
+ }
142
+ },
143
+ exportName: String,
144
+ total: {
145
+ type: Number,
146
+ default: 100000
147
+ }
148
+ },
149
+ data() {
150
+ return {
151
+ showFileList: false,
152
+ fileList: [],
153
+ showProgress: false,
154
+ progress: 0,
155
+ status: 'fail',
156
+ timer: null,
157
+ exportCurrentLoading: false,
158
+ exportAllLoading: false,
159
+ form: {
160
+ fileFormat: "xlsx",
161
+ fileName: this.tableName,
162
+ exportType: ""
163
+ },
164
+ tableParsedColumns: []
165
+ }
166
+ },
167
+ computed: {
168
+ requestUrl: function () {
169
+ return this.exportUrl || this.dataUrl;
170
+ },
171
+ limitTotal: function () {
172
+ return this.total >= 100000 ? 100000 : this.total;
173
+ },
174
+ reqMethod: function () {
175
+ return this.requestMethod
176
+ },
177
+ },
178
+ created() {
179
+ this.tableParsedColumns = this.parsedColumns
180
+ },
181
+ methods: {
182
+ exportCurrentPage() {
183
+ this.exportCurrentLoading = true
184
+ this.form.exportType = "current"
185
+ let exportParams = Object.assign({}, this.paginationParams, this.sortParams, this.searchParams)
186
+ this.getDataFromServer(exportParams)
187
+ },
188
+ exportAllData() {
189
+ if (!this.tableColumns || this.tableColumns.length === 0) {
190
+ this.$Message.info('当前显示列为空,无法导出!');
191
+ return;
192
+ }
193
+ this.exportAllLoading = true
194
+ this.form.exportType = "all"
195
+ if (!this.limitTotal) {
196
+ this.$Message.info('暂无数据,无法导出!')
197
+ return;
198
+ }
199
+ let paginationParams = { offset: 0, limit: this.limitTotal }
200
+ let exportParams = Object.assign({}, paginationParams, this.sortParams, this.searchParams)
201
+ this.getDataFromServer(exportParams)
202
+ },
203
+ exportBatch: function () {
204
+ let self = this;
205
+ self.$emit("close-drop-down")
206
+ self.showFileList = true;
207
+ self.fileList = [];
208
+ const total = self.total;
209
+ const filename = self.form.fileName;
210
+ const fileFormat = self.form.fileFormat;
211
+ let limit = self.exportBatchSize;
212
+ for (let i = 0; i < total / limit; i++) {
213
+ let uid = Date.now() + i;
214
+ let offset = i * limit;
215
+ let start = i * limit + 1;
216
+ let end = (i + 1) * limit
217
+ const _file = {
218
+ status: 'active',
219
+ name: filename + '第' + start + '到' + end + '条数据',
220
+ filename: filename + (i + 1),
221
+ format: fileFormat,
222
+ percentage: 0,
223
+ uid: uid,
224
+ offset: offset,
225
+ limit: limit,
226
+ timer: null,
227
+ showProgress: true
228
+ };
229
+ self.fileList.push(_file);
230
+ }
231
+ },
232
+ getDataFromServer(params) {
233
+ let self = this;
234
+ if (self.exportMode == 'front') {
235
+ self.dealWithJson(params)
236
+ } else if (self.exportMode == 'back') {
237
+ self.dealWithStream(params)
238
+ }
239
+ },
240
+ dealWithStream(params) {
241
+ let self = this;
242
+ let exportParams = {
243
+ fileFormat: self.form.fileFormat,
244
+ fileName: self.form.fileName + new Date().Format('yyyyMMddHHmmss'),
245
+ exportType: self.form.exportType,
246
+ tableColumns: self.tableParsedColumns
247
+ }
248
+ ajax.request({
249
+ url: self.requestUrl,
250
+ method: self.reqMethod,
251
+ params: Object.assign({}, params, { exportParams: JSON.stringify(exportParams) }),
252
+ responseType: 'blob'
253
+ }).then((resp) => {
254
+ let blob = new Blob([resp.data], {
255
+ type: "application/vnd.ms-excel"
256
+ });
257
+ excel.saveAs(blob, self.form.fileName + '.' + self.form.fileFormat);
258
+ this.exportCurrentLoading = false
259
+ this.exportAllLoading = false
260
+ }).catch((e) => {
261
+ console.error(e)
262
+ })
263
+ },
264
+ dealWithJson(params) {
265
+ let self = this;
266
+ let options = {
267
+ url: self.requestUrl,
268
+ method: self.reqMethod
269
+ }
270
+ if (self.reqMethod === 'GET') {
271
+ options = Object.assign({}, options,
272
+ {
273
+ params: params
274
+ }
275
+ )
276
+ } else if (self.reqMethod === 'POST') {
277
+ options = Object.assign({}, options,
278
+ {
279
+ data: params
280
+ }
281
+ )
282
+ }
283
+ ajax.request(options).then(function (resp) {
284
+ if (self.requestSuccessCodes.includes(resp.data.code)) {
285
+ let resultData = deepCopy(resp.data.data.rows)
286
+ if (self.showSummary && resultData) {
287
+ let sum = self.summaryData(resultData)
288
+ resultData.push(sum)
289
+ }
290
+ self.exportExcel(resultData)
291
+ } else {
292
+ self.$Message.error(resp.data.data)
293
+ }
294
+ })
295
+ },
296
+ summaryData(data) {
297
+ let sums = {};
298
+ if (this.summaryMethod) {
299
+ sums = this.summaryMethod({ columns: this.tableParsedColumns, data: data });
300
+ } else {
301
+ this.cloneColumns.forEach((column, index) => {
302
+ const key = column.key;
303
+ if (index === 0) {
304
+ sums[key] = {
305
+ key: column.key,
306
+ value: '合计'
307
+ };
308
+ return;
309
+ }
310
+ const values = data.map(item => Number(item[column.key]));
311
+ const precisions = [];
312
+ let notNumber = true;
313
+ values.forEach(value => {
314
+ if (!isNaN(value)) {
315
+ notNumber = false;
316
+ let decimal = ('' + value).split('.')[1];
317
+ precisions.push(decimal ? decimal.length : 0);
318
+ }
319
+ });
320
+ const precision = Math.max.apply(null, precisions);
321
+ if (!notNumber) {
322
+ const currentValue = values.reduce((prev, curr) => {
323
+ const value = Number(curr);
324
+ if (!isNaN(value)) {
325
+ return parseFloat((prev + curr).toFixed(Math.min(precision, 20)));
326
+ } else {
327
+ return prev;
328
+ }
329
+ }, 0);
330
+ sums[key] = {
331
+ key: column.key,
332
+ value: currentValue
333
+ };
334
+ } else {
335
+ sums[key] = {
336
+ key: column.key,
337
+ value: ''
338
+ };
339
+ }
340
+ });
341
+ }
342
+ let total = {}
343
+ Object.keys(sums).forEach(item => {
344
+ if (item) {
345
+ total[item] = sums[item].value
346
+ }
347
+ })
348
+ return total;
349
+ },
350
+ exportExcel(tableDatas) {
351
+ if (tableDatas.length) {
352
+ let titles = excel.title_transform(this.tableColumns)
353
+ let keys = excel.key_transform(this.tableColumns)
354
+ let enums = excel.enums_transform(this.tableColumns)
355
+ let data = excel.enums_to_value(enums, deepCopy(tableDatas))
356
+ const params = {
357
+ title: titles,
358
+ key: keys,
359
+ data: data,
360
+ autoWidth: true,
361
+ filename: this.form.fileName + new Date().Format('yyyyMMddHHmmss'),
362
+ format: this.form.fileFormat,
363
+ spanColumns: this.exportSpanColumns,
364
+ }
365
+ excel.export_array_to_excel(params)
366
+ } else {
367
+ this.$Message.info('表格数据不能为空!')
368
+ }
369
+ this.exportCurrentLoading = false
370
+ this.exportAllLoading = false
371
+ },
372
+ },
373
+ watch: {
374
+ exportName: {
375
+ handler() {
376
+ this.form.fileName = this.exportName;
377
+ },
378
+ immediate: true
379
+ },
380
+ parsedColumns(val) {
381
+ this.tableParsedColumns = val
382
+ }
383
+ }
384
+ };
385
+ </script>
386
+ <style>
387
+ .export-data .ivu-form-item .ivu-form-item-label:before {
388
+ margin-right: auto;
389
+ }
390
+ </style>