lambo-design-bi 0.0.188 → 0.0.190

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.
@@ -14,7 +14,13 @@ import LamboQueryFilter from "@lambo-design/query-filter"
14
14
  import { deepCopy } from "@lambo-design/shared/utils/assist"
15
15
  import moment from 'moment'
16
16
  import BiSearchItem from "./search-item.vue"
17
- import { SEARCH_DICT, DATE_RANGE_PFIX, DEFAULT_DATE_FORMAT } from '../../../util/constants'
17
+ import {
18
+ SEARCH_DICT,
19
+ DATE_RANGE_PFIX,
20
+ DEFAULT_DATE_FORMAT,
21
+ DEFAULT_YEAR_FORMAT,
22
+ DEFAULT_MONTH_FORMAT
23
+ } from '../../../util/constants'
18
24
 
19
25
  export default {
20
26
  name: 'BiSearchForm',
@@ -53,7 +59,12 @@ export default {
53
59
  } else {
54
60
  if (item.options.searchType === SEARCH_DICT.SINGLE_DATE.id) {
55
61
  params[qKey] = moment(val).format(DEFAULT_DATE_FORMAT)
56
- } else {
62
+ }else if (item.options.searchType === SEARCH_DICT.SINGLE_YEAR.id) {
63
+ params[qKey] = moment(val).format(DEFAULT_YEAR_FORMAT)
64
+ }else if (item.options.searchType === SEARCH_DICT.SINGLE_MONTH.id) {
65
+ params[qKey] = moment(val).format(DEFAULT_MONTH_FORMAT)
66
+ }
67
+ else {
57
68
  params[qKey] = val
58
69
  }
59
70
  }
@@ -47,6 +47,14 @@
47
47
  <DatePicker v-model="widget.options.val" format="yyyy-MM-dd" placeholder="请选择" placement="bottom-end"
48
48
  class="lambo-query-class" type="daterange"></DatePicker>
49
49
  </div>
50
+ <div v-else-if="widget.options.searchType === searchDict.SINGLE_YEAR.id"> <!-- 年选择框 -->
51
+ <DatePicker v-model="widget.options.val" format="yyyy" placeholder="请选择" placement="bottom-end"
52
+ class="lambo-query-class" type="year"></DatePicker>
53
+ </div>
54
+ <div v-else-if="widget.options.searchType === searchDict.SINGLE_MONTH.id"> <!-- 月选择框 -->
55
+ <DatePicker v-model="widget.options.val" format="yyyy-MM" placeholder="请选择" placement="bottom-end"
56
+ class="lambo-query-class" type="month"></DatePicker>
57
+ </div>
50
58
  </div>
51
59
  </template>
52
60
  <script>
@@ -3,19 +3,14 @@
3
3
  <LamboPagingTableBi ref="table" :auto-search="false" :columns="columns" :dataUrl="widget.options.url"
4
4
  :export-batch-size="20000" :show-table-option="false" :exportName="widget.name"
5
5
  :page-disable="widget.options.isPaging === '0'" :page-size="widget.options.pageSize" :export-request-limit="200"
6
- :isSingleSelectModel="true" @on-data-load="onDataLoad" :searchParams="tableSearchParams">
6
+ :isSingleSelectModel="true" :showSummary="widget.options.isAllSum === '1'" :summary-method="handleSummary"
7
+ @on-data-load="onDataLoad" :searchParams="tableSearchParams">
7
8
  <div slot="search"></div>
8
- <div slot="footer">
9
- <Table class="ivu-table-summary" v-if="widget.options.isAllSum && allSumData && allSumData.length > 0"
10
- cellspacing="0" cellpadding="0" :columns="sumColumns" :data="allSumData" :border="true" :show-header="false">
11
- </Table>
12
- </div>
13
9
  </LamboPagingTableBi>
14
10
  </div>
15
11
  </template>
16
12
  <script>
17
13
  import biConfig from '../config/config'
18
- import { getListMapData } from '../api/data'
19
14
  import LamboPagingTableBi from '../../../pub/table/paging-table/index.vue'
20
15
  import { accAdd } from '../../../util/math-util'
21
16
 
@@ -57,81 +52,77 @@ export default {
57
52
  query: newQuery
58
53
  })
59
54
  },
60
- onDataLoad(res) {
61
- console.log("onDataLoad res:", res)
62
- console.log("onDataLoad this.$refs.table.tableData:", this.$refs.table.tableData)
63
- if (this.widget.options.isAllSum === '1') {
64
- if (this.widget.options.isPaging === '1' && this.widget.options.sumApiId) {
65
- // 请求后端做合计
66
- getListMapData(this.widget.options.sumApiId, this.params).then(res => {
67
- if (res && res.data.code === 1) {
68
- if (res.data.data.rows.length > 0) {
69
- let sumRows = res.data.data.rows[0]
70
- let bakSumColumns = this.sumColumns
71
- console.log("onDataLoad this.sumColumns:", this.sumColumns)
72
- if (bakSumColumns && bakSumColumns.length > 0) {
73
- sumRows[bakSumColumns[0].key] = '总计'
74
- }
75
- this.allSumData = [sumRows]
76
- console.log("onDataLoad this.allSumData:", this.allSumData)
55
+ onDataLoad(dataRes) {
56
+ console.log("onDataLoad dataRes:", dataRes)
57
+ if (this.widget.options.isPaging === '1' && this.widget.options.isAllSum === '1') {
58
+ // 接收数据,并赋值
59
+ if (dataRes && dataRes.code === 1) {
60
+ this.allSumData = dataRes.data.sums || []
61
+ console.log("onDataLoad this.allSumData:", this.allSumData)
62
+ }
63
+ }
64
+ },
65
+ handleSummary({ columns, data }) {
66
+ console.log("handleSummary { columns, data }:", { columns, data })
67
+ const sums = {}
68
+ if (columns && columns.length > 0) {
69
+ sums[columns[0].key] = {
70
+ key: columns[0].key,
71
+ value: '总计'
72
+ }
73
+ // 如果是分页表格
74
+ if (this.widget.options.isPaging === '1') {
75
+ let allSumObj = {}
76
+ if (this.allSumData && this.allSumData.length > 0) {
77
+ allSumObj = this.allSumData[0] || {}
78
+ }
79
+ console.log("handleSummary allSumObj:", allSumObj)
80
+ for (let i = 1; i < columns.length; i++) {
81
+ let col = columns[i]
82
+ let colKey = col.key
83
+ if (Object.prototype.hasOwnProperty.call(allSumObj, colKey)) {
84
+ sums[colKey] = {
85
+ key: colKey,
86
+ value: allSumObj[colKey] || ''
77
87
  }
78
88
  } else {
79
- console.error("调用总计服务[" + this.widget.options.sumApiId + "]失败:" + res.data.message)
89
+ sums[colKey] = {
90
+ key: colKey,
91
+ value: ''
92
+ }
80
93
  }
81
- }).catch(err => {
82
- console.error("调用总计服务[" + this.widget.options.sumApiId + "]异常:", err)
83
- })
84
- } else {
85
- if (this.$refs.table.tableData && this.$refs.table.tableData.length > 0) {
86
- // 前端遍历求和
87
- let sumObj = {}
88
- let bakSumColumns = this.getLeafNodes(this.sumColumns)
89
- let tableData = this.$refs.table.tableData
90
- console.log("onDataLoad bakSumColumns:", bakSumColumns)
91
- if (bakSumColumns && bakSumColumns.length > 0 && tableData && tableData.length > 0) {
92
- bakSumColumns.forEach((column, index) => {
93
- const key = column.key
94
- if (index === 0) {
95
- sumObj[key] = "总计"
96
- } else {
97
- const values = tableData.map(item => Number(item[key]))
98
- console.log("onDataLoad values:", values)
99
- if (!values.every(value => isNaN(value))) {
100
- const v = values.reduce((prev, curr) => {
101
- const value = Number(curr)
102
- if (!isNaN(value)) {
103
- return accAdd(prev, curr)
104
- } else {
105
- return prev
106
- }
107
- }, 0)
108
- sumObj[key] = v
94
+ }
95
+ }
96
+ // 如果不是分页表格
97
+ else {
98
+ columns.forEach((column, index) => {
99
+ const key = column.key
100
+ if (index > 0) {
101
+ const values = data.map(item => Number(item[key]))
102
+ if (values && values.length > 0 && !values.every(value => isNaN(value))) {
103
+ const v = values.reduce((prev, curr) => {
104
+ const value = Number(curr)
105
+ if (!isNaN(value)) {
106
+ return accAdd(prev, curr)
107
+ } else {
108
+ return prev
109
109
  }
110
+ }, 0);
111
+ sums[key] = {
112
+ key,
113
+ value: v
110
114
  }
111
- })
112
- }
113
- if (sumObj) {
114
- this.allSumData = [sumObj]
115
+ } else {
116
+ sums[key] = {
117
+ key,
118
+ value: ''
119
+ }
120
+ }
115
121
  }
116
- console.log("onDataLoad this.allSumData:", this.allSumData)
117
- }
118
- }
119
- }
120
- },
121
- getLeafNodes(columns) {
122
- const leafNodes = [];
123
- function traverse(nodes) {
124
- if (!Array.isArray(nodes)) return;
125
- for (const node of nodes) {
126
- if (!node.children || !Array.isArray(node.children) || node.children.length === 0) {
127
- leafNodes.push(node);
128
- } else {
129
- traverse(node.children);
130
- }
122
+ })
131
123
  }
132
124
  }
133
- traverse(columns);
134
- return leafNodes;
125
+ return sums
135
126
  }
136
127
  },
137
128
  created() {
@@ -176,26 +167,6 @@ export default {
176
167
  }
177
168
  }
178
169
  return columns
179
- },
180
- sumColumns() {
181
- let sumColumnsStr = this.widget.options.columns
182
- let sumColumns = []
183
- if (this.widget && Object.prototype.hasOwnProperty.call(this.widget, "options") && Object.prototype.hasOwnProperty.call(this.widget.options, "columns")) {
184
- if (this.widget.options.columns) {
185
- try {
186
- sumColumns = JSON.parse(sumColumnsStr)
187
- if (sumColumns && sumColumns.length > 0) {
188
- sumColumns[0].type = '-'
189
- }
190
- } catch (e) {
191
- console.log("BiPagingTable -- sumColumns() -- this.widget.options.columns:", this.widget.options.columns)
192
- console.error("BiPagingTable -- sumColumns() JSON解析异常:", e)
193
- this.$Message.info("合计的表格头配置数据解析异常")
194
- sumColumns = []
195
- }
196
- }
197
- }
198
- return sumColumns
199
170
  }
200
171
  },
201
172
  watch: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambo-design-bi",
3
- "version": "0.0.188",
3
+ "version": "0.0.190",
4
4
  "description": "Vue2 BI 数据可视化组件库",
5
5
  "main": "index.js",
6
6
  "author": "finch",
@@ -96,7 +96,7 @@ function getLevelOption() {
96
96
  * 41 矩形树图
97
97
  * 42 桑基图
98
98
  * 43 仪表盘进度条)
99
- * 2A:单个柱状图以及多条折线,
99
+ * 2A:单个柱状图以及多条曲线,
100
100
  * 2B:单个柱状图以及左右 <br/>
101
101
  * 44:雷达图
102
102
  * 45:圆形进度图
@@ -2594,37 +2594,36 @@ export function getECharts(type, dataX, dataY, dataDim) {
2594
2594
  };
2595
2595
  }
2596
2596
  else if (type === '44') {
2597
+ const transData = transpose(dataY);
2597
2598
  const indicators = dataX.map((name, index) => {
2598
2599
  let maxValue = 0;
2599
- for (let i = 0; i < dataY.length; i++) {
2600
- if (dataY[i] && dataY[i][index] > maxValue) {
2601
- maxValue = dataY[i][index];
2600
+ for (let i = 0; i < dataY[index].length; i++) {
2601
+ if (dataY[index] && dataY[index][i] > maxValue) {
2602
+ maxValue = dataY[index][i];
2602
2603
  }
2603
2604
  }
2604
2605
  return {
2605
2606
  name: name,
2606
- max: Math.ceil(maxValue * 1.2)
2607
+ max: Math.ceil(maxValue )
2607
2608
  };
2608
2609
  });
2609
-
2610
2610
  const seriesData = [];
2611
-
2612
- dataY.forEach((data, index) => {
2613
- seriesData.push({
2614
- name: dataDim[index],
2615
- value: data,
2616
- lineStyle: {
2617
- width: 3,
2618
- color: colors[index % colors.length]
2619
- },
2620
- itemStyle: {
2621
- color: colors[index % colors.length]
2622
- },
2623
- areaStyle: {
2624
- color: areaColors[index % areaColors.length]
2625
- }
2626
- });
2611
+ transData.forEach((data, index) => {
2612
+ seriesData.push({
2613
+ name: dataDim[index],
2614
+ value: data,
2615
+ lineStyle: {
2616
+ width: 3,
2617
+ color: colors[index % colors.length]
2618
+ },
2619
+ itemStyle: {
2620
+ color: colors[index % colors.length]
2621
+ },
2622
+ areaStyle: {
2623
+ color: areaColors[index % areaColors.length]
2624
+ }
2627
2625
  });
2626
+ });
2628
2627
  opt = {
2629
2628
  legend: {
2630
2629
  data: seriesData.map(item => item.name),
@@ -2697,7 +2696,7 @@ export function getECharts(type, dataX, dataY, dataDim) {
2697
2696
  opt = {
2698
2697
  title: [
2699
2698
  {
2700
- text: dataDim[0] || '',
2699
+ text: dataX[0] || '',
2701
2700
  x: 'center',
2702
2701
  top: '32%',
2703
2702
  textStyle: {
package/util/constants.js CHANGED
@@ -31,6 +31,14 @@ export const SEARCH_DICT = Object.freeze({
31
31
  id: "51",
32
32
  name: "日期范围帮助框"
33
33
  },
34
+ SINGLE_YEAR: {
35
+ id: "52",
36
+ name: "年选择框"
37
+ },
38
+ SINGLE_MONTH: {
39
+ id: "53",
40
+ name: "月选择框"
41
+ },
34
42
  NOT_SHOW_INPUT: {
35
43
  id: "A0",
36
44
  name: "隐形输入框"
@@ -46,3 +54,5 @@ export const DEFAULT_DATE_FORMAT = "YYYYMMDD"
46
54
  export const DEFAULT_DATE_TIME_FORMAT = "YYYYMMDDHHmmss"
47
55
  export const DEFAULT_DISPLAY_DATE_FORMAT = "YYYY-MM-DD"
48
56
  export const DEFAULT_DISPLAY_DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss"
57
+ export const DEFAULT_YEAR_FORMAT = "YYYY"
58
+ export const DEFAULT_MONTH_FORMAT = "YYYYMM"