@ecan-bi/tools 1.0.6 → 1.0.8

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.
package/src/indicator.ts DELETED
@@ -1,1228 +0,0 @@
1
- import { unref } from 'vue'
2
- import dayjs from 'dayjs'
3
- import { cloneDeep } from 'lodash-es'
4
- import { hasOwn, lowerCaseIncludes, getConditions, getFormatStep } from './utils/util'
5
- import { MODEL_KEY_LIST } from './utils/constant'
6
-
7
- let modelValue = new Map()
8
- const excludeAttr = [
9
- 'keyValue',
10
- 'conditionKey',
11
- 'conditionLabel',
12
- 'conditionName',
13
- 'conditionValueType',
14
- 'customValue',
15
- 'id',
16
- 'keyName'
17
- ]
18
-
19
- const getGlobalModel = (key: string) => {
20
- return modelValue.get(key)
21
- }
22
-
23
- // 日期计算
24
- const getCalcWays = (data: { [key:string]:any }, props: { [key:string]: any } = {}) => {
25
- const { around, unit, id } = data
26
- let result = ''
27
- const { pageMode = '', componentList = [] } = props?.graphicConfig || {}
28
- let sTime: any = null
29
- let eTime: any = null
30
- if (pageMode === 'design') {
31
- const component: any = componentList?.find((v: { [key:string]:any }) => v.id === id)
32
- if (!component) {
33
- return []
34
- }
35
- const { interval, intervalUnit, startTime, endTime, operate, useCurrentTime } = component || {}
36
- if (useCurrentTime) {
37
- sTime = dayjs().subtract(interval, intervalUnit)
38
- eTime = dayjs()
39
- }
40
- if (startTime) {
41
- sTime = dayjs(startTime)
42
- }
43
- if (endTime) {
44
- eTime = dayjs(endTime)
45
- }
46
- if (operate) {
47
- const { type, value, mode } = operate
48
- switch (type) {
49
- case 'add':
50
- sTime = sTime ? sTime.add(value, mode) : sTime
51
- eTime = eTime ? eTime.add(value, mode) : eTime
52
- break
53
- case 'minus':
54
- sTime = sTime ? sTime.subtract(value, mode) : sTime
55
- eTime = eTime ? eTime.subtract(value, mode) : eTime
56
- }
57
- }
58
- } else {
59
- const model = getGlobalModel(id) || {}
60
- if (unref(model.startTime)) {
61
- sTime = dayjs(unref(model.startTime))
62
- }
63
- if (unref(model.endTime)) {
64
- eTime = dayjs(unref(model.endTime))
65
- }
66
- }
67
- if (sTime && eTime) {
68
- const diffValue = eTime.diff(sTime, unit.toLowerCase())
69
- result = `${around === 'before' ? '-' : ''}${diffValue + 1}`
70
- }
71
- return result ? [result] : []
72
- }
73
-
74
- const handleParams = (params: any, type: string | undefined) => {
75
- if (type) {
76
- // 处理sqlConditions中的sqlConditon
77
- if (hasOwn(params, 'indexCode')) {
78
- params.hrpIndexCode = params.indexCode
79
- delete params.indexCode
80
- }
81
- if (hasOwn(params, 'indexCodeNum')) {
82
- params.hrpIndexCodeNum = params.indexCodeNum
83
- delete params.indexCodeNum
84
- }
85
- if (hasOwn(params, 'dataType')) {
86
- delete params.dataType
87
- }
88
- } else {
89
- const { calcWays = [], dateCalcTypes = [], activeKey, componentId = '' } = params
90
- if (activeKey === 5 && calcWays?.length && dateCalcTypes?.length && componentId) {
91
- const vals = calcWays[0].split('-')
92
- if (vals?.length > 1) {
93
- if (vals[0] === 'rangeValue') {
94
- // 范围差值
95
- params.calcWays = getCalcWays({
96
- around: vals[1],
97
- unit: dateCalcTypes[0],
98
- id: componentId
99
- })
100
- }
101
- }
102
- delete params.radioValue
103
- }
104
- if (hasOwn(params, 'dataType')) {
105
- if (params.fieldType === 'DATE') {
106
- params.label = params.fieldName
107
- }
108
- if (params.dataType === 'component') {
109
- if (params.fieldValue === 'PARENT') {
110
- let fieldVal = params.modelKey
111
- if (fieldVal && params.prop) {
112
- fieldVal += `-${params.prop}`
113
- }
114
- params.fieldValue = '${' + fieldVal + '}'
115
- } else {
116
- params.fieldValue = '${' + params.fieldValue + '}'
117
- }
118
- }
119
- delete params.dataType
120
- }
121
- if (hasOwn(params, 'activeKey')) {
122
- delete params.activeKey
123
- }
124
- if (hasOwn(params, 'radioValue')) {
125
- delete params.radioValue
126
- }
127
- if (hasOwn(params, 'indexCode')) {
128
- params.hrpIndexCode = params.indexCode
129
- delete params.indexCode
130
- }
131
- if (hasOwn(params, 'indexCodeNum')) {
132
- params.hrpIndexCodeNum = params.indexCodeNum
133
- delete params.indexCodeNum
134
- }
135
- if (params.dataType !== 'component' && params.useCurrentTime) {
136
- // 时间值为当前时间
137
- params.fieldValue = dayjs().format(params.dateFormat)
138
- }
139
- if (hasOwn(params, 'modelKey')) {
140
- delete params.modelKey
141
- }
142
- if (hasOwn(params, 'prop')) {
143
- delete params.prop
144
- }
145
- delete params.useCurrentTime
146
- }
147
- }
148
-
149
- // 递归格式化conditions的数据
150
- const handleConditions = (list: { [key: string]: any } [], type?: string) => {
151
- const result: any = []
152
- if (list?.length) {
153
- cloneDeep(list).forEach((item) => {
154
- if (item.join && item.conditions) {
155
- const isSameLevel = !item.conditions.some((v: any) => v.join && v.conditions)
156
- item.conditions.forEach((cs: any, index: number) => {
157
- handleParams(cs, type)
158
- const joinParams: { [key: string]: any } = {}
159
- if (index < item.conditions.length - 1) {
160
- joinParams.join = item.join
161
- }
162
- if (isSameLevel) {
163
- result.push({
164
- ...joinParams,
165
- ...cs
166
- })
167
- } else {
168
- if (cs.join && cs.conditions) {
169
- const conKey = type ? 'sqlConditions' : 'conditions'
170
- result.push({
171
- [conKey]: handleConditions([cs], type),
172
- ...joinParams
173
- })
174
- } else {
175
- result.push({
176
- ...joinParams,
177
- ...cs
178
- })
179
- }
180
- }
181
- })
182
- } else {
183
- handleParams(item, type)
184
- result.push(item)
185
- }
186
- })
187
- }
188
- return result
189
- }
190
-
191
- const handleIndicator = (indicator: { [key:string]: any } = {}, classification: any) => {
192
- if (indicator?.sortCpnts && classification) {
193
- const sortData = getCpntSortData(indicator)
194
- if (sortData) {
195
- classification.sort = sortData
196
- }
197
- }
198
- const {
199
- label,
200
- name,
201
- location,
202
- show,
203
- indexCode,
204
- indexCodeNum,
205
- calcType = 'COLUMN',
206
- builtInFormula,
207
- builtInValueSource,
208
- builtInCalcWay,
209
- formula,
210
- conditions,
211
- aggregate,
212
- distinct,
213
- dimByCount,
214
- dataTo
215
- } = indicator
216
- let conditionData
217
- if (conditions) {
218
- conditionData = handleConditions(conditions)
219
- }
220
- if (calcType === 'COMPONENT') {
221
- const componentField: any = {}
222
- setFieldValue(componentField, builtInValueSource)
223
- return {
224
- label: label.trim(),
225
- columnName: name,
226
- show,
227
- calcType,
228
- componentAlias: builtInCalcWay,
229
- componentValue: componentField.fieldValue || null
230
- }
231
- }
232
- const itemObj: any = {
233
- label: label.trim(),
234
- columnName: name,
235
- location,
236
- show,
237
- calcType: dataTo === '1' ? 'VIEW' : calcType,
238
- hrpIndexCode: indexCode,
239
- hrpIndexCodeNum: indexCodeNum,
240
- aggregate,
241
- builtInFormula,
242
- builtInValueSource,
243
- formula,
244
- conditions: conditionData
245
- }
246
- if (builtInFormula === 'DATE_OFFSET') {
247
- const list = builtInCalcWay.split('-')
248
- if (list?.length === 3) {
249
- let calcWays = list[0]
250
- if (list[2] === 'before' && list[0] !== '0') {
251
- calcWays = `-${list[0]}`
252
- }
253
- return {
254
- ...itemObj,
255
- calcWays: [calcWays],
256
- dateCalcTypes: [list[1]]
257
- }
258
- }
259
- } else {
260
- if (name === 'the_count') {
261
- itemObj.calcType = 'AGGREGATE'
262
- itemObj.distinct = !!distinct
263
- itemObj.typeGuid = dimByCount
264
- }
265
- return {
266
- ...itemObj,
267
- builtInCalcWay
268
- }
269
- }
270
- }
271
-
272
- const handleSqlConditions = (graphicConfig: { [key:string]: any }) => {
273
- if (!graphicConfig) {
274
- return []
275
- }
276
- const controlList = cloneDeep(graphicConfig?.controlList || [])
277
- .filter((v: any) => v.conditionKey !== 'parentCode')
278
- const {
279
- classificationList = [],
280
- rowHeaderList = [],
281
- dimensionList = [],
282
- seriesList = [],
283
- leftAxisList = [],
284
- rightAxisList = [],
285
- queryColumnList = [],
286
- indicators = []
287
- } = graphicConfig
288
- handleControlList(controlList)
289
- const otherList = [
290
- ...classificationList,
291
- ...rowHeaderList,
292
- ...dimensionList,
293
- ...seriesList,
294
- ...leftAxisList,
295
- ...rightAxisList,
296
- ...queryColumnList,
297
- ...indicators
298
- ]
299
- const conditionList: any = []
300
- for (const ol of otherList) {
301
- const conditions = getConditions(ol?.conditions || [])
302
- if (conditions?.length) {
303
- const list = conditions
304
- .filter((v: any) => v?.dataType === 'component')
305
- .map((item: any) => {
306
- const params: any = {}
307
- if (item?.dateFormat) {
308
- params.format = item.dateFormat
309
- }
310
- if (item.fieldValue === 'PARENT') {
311
- // 使用父页面的组件
312
- params.id = 'PARENT'
313
- params.keyName = item.modelKey
314
- params.modelKey = item.modelKey
315
- params.prop = item.prop
316
- }
317
- return {
318
- conditionKey: item.fieldName,
319
- conditionLabel: item.fieldName,
320
- conditionName: item.fieldName,
321
- conditionValueType: item.fieldType,
322
- id: item.componentId,
323
- keyName: item.fieldValue,
324
- rule: item.rule,
325
- notGlobal: true,
326
- indexCode: item.indexCode,
327
- typeGuid: item.typeGuid,
328
- indexCodeNum: item.indexCodeNum,
329
- ...params
330
- }
331
- })
332
- if (list?.length) {
333
- for (const l of list) {
334
- if (!conditionList.find((cItem: any) => cItem.keyName === l.keyName)) {
335
- conditionList.push(l)
336
- }
337
- }
338
- }
339
- }
340
- }
341
- const len = conditionList.length
342
- const sqlConditions = controlList
343
- for (let i = 0; i < len; i++) {
344
- const control = conditionList[i]
345
- if (control?.conditionKey === 'parentCode') {
346
- continue
347
- }
348
- const {
349
- id,
350
- keyName,
351
- prop,
352
- format: dateFormat,
353
- modelKey,
354
- dataType = 'component',
355
- customValue
356
- } = control
357
- const sqlCondition: { [key:string]: any } = getConditionItem(control)
358
- // console.log('model', model)
359
- setFieldValue(sqlCondition, id, { prop, dateFormat, modelKey, keyName })
360
- if (dataType === '') {
361
- sqlCondition.fieldValue = customValue || ''
362
- }
363
- sqlConditions.push(sqlCondition)
364
- }
365
- for (let j = sqlConditions.length - 1; j >= 0; j--) {
366
- const item = sqlConditions[j]
367
- if (!item.globalCondition) {
368
- const cond = getConditions(sqlConditions).find(v => v.alias === item.alias && v.globalCondition)
369
- if (cond) {
370
- sqlConditions.splice(j, 1)
371
- }
372
- }
373
- }
374
- return sqlConditions
375
- }
376
-
377
- function getConditionItem (control: { [key:string]:any }) {
378
- const {
379
- id,
380
- keyName,
381
- conditionLabel,
382
- conditionKey,
383
- conditionValueType,
384
- prop,
385
- rule = 'NONE',
386
- notGlobal = false,
387
- indexCode,
388
- typeGuid,
389
- indexCodeNum,
390
- dataType = 'component'
391
- } = control
392
- let alias = keyName || id
393
- if (alias && prop) {
394
- alias += `-${prop}`
395
- }
396
- let ruleValue = rule
397
- if (ruleValue === 'NONE') {
398
- if (['startTime', 'endTime'].includes(prop)) {
399
- ruleValue = prop === 'startTime' ? 'GREATER_EQUAL' : 'LESS_EQUAL'
400
- } else if (keyName?.includes('startTime')) {
401
- ruleValue = prop === 'GREATER_EQUAL'
402
- } else if (keyName?.includes('endTime')) {
403
- ruleValue = prop === 'LESS_EQUAL'
404
- } else {
405
- ruleValue = 'EQUAL'
406
- }
407
- }
408
- if (id === 'PARENT') {
409
- alias = control.modelKey
410
- if (alias && prop) {
411
- alias += `-${prop}`
412
- }
413
- ruleValue = rule
414
- }
415
- return {
416
- rule: ruleValue,
417
- label: conditionLabel,
418
- fieldName: conditionKey,
419
- fieldValue: '', // 在关联控件中取
420
- // dateFormat: 'YYYY-MM',
421
- valueType: conditionValueType,
422
- alias,
423
- globalCondition: !notGlobal,
424
- indexCode,
425
- typeGuid,
426
- indexCodeNum,
427
- dataType
428
- }
429
- }
430
-
431
- function handleControlList (controlList: { [key:string]:any }[]) {
432
- if (controlList?.length) {
433
- for (const control of controlList) {
434
- if (control?.conditions) {
435
- handleControlList(control.conditions)
436
- } else {
437
- const {
438
- id,
439
- keyName,
440
- prop,
441
- modelKey,
442
- format: dateFormat,
443
- dataType = 'component',
444
- customValue
445
- } = control
446
- let alias = keyName || id
447
- if (alias && prop) {
448
- alias += `-${prop}`
449
- }
450
- const sqlCondition: { [key:string]: any } = getConditionItem(control)
451
- setFieldValue(sqlCondition, id, { prop, dateFormat, modelKey, keyName })
452
- if (dataType === '') {
453
- sqlCondition.fieldValue = customValue || ''
454
- }
455
- for (const key in sqlCondition) {
456
- control[key] = sqlCondition[key]
457
- }
458
- for (const attr of excludeAttr) {
459
- delete control[attr]
460
- }
461
- }
462
- }
463
- }
464
- }
465
-
466
- function handleVariableList (variableList: { [key: string]: any }[]) {
467
- const handleVarList: any = []
468
- if (variableList?.length) {
469
- for (const item of variableList) {
470
- if (item.variableName) {
471
- const variableItem: any = {
472
- variateName: item.variableName,
473
- globalCondition: false,
474
- valueType: item.variableType,
475
- alias: item.keyName || ''
476
- }
477
- setFieldValue(variableItem, item.id, {
478
- dateFormat: item.format,
479
- prop: item.dateTypeValue,
480
- keyName: item.keyName,
481
- operateType: item.operateType,
482
- operateMode: item.operateMode,
483
- operateValue: item.operateValue
484
- })
485
- if (item.dataType === '') {
486
- variableItem.fieldValue = item.variableValue
487
- }
488
- if (item.format) {
489
- // 日期格式化
490
- variableItem.dateFormat = item.format
491
- }
492
- if (item.label) {
493
- variableItem.label = item.label
494
- }
495
- handleVarList.push(variableItem)
496
- }
497
- }
498
- }
499
- return handleVarList
500
- }
501
-
502
- // 设置sqlCondition的fieldValue值
503
- function setFieldValue (data: any, id: string, params?: any) {
504
- const { prop = '', dateFormat = '', modelKey = '', keyName = '', operateValue, operateMode, operateType } = params || {}
505
- const rKey = modelKey || keyName
506
- if (id === 'PARENT' && rKey && prop) {
507
- // @ts-ignore
508
- const record = window.config.record
509
- let propKey = prop
510
- let format = dateFormat
511
- const variables = (prop).match(/\{(.+?)\}/g)
512
- if (variables?.length) {
513
- const variable = variables[0].slice(1, -1).trim()
514
- propKey = prop.replace(variables[0], '')
515
- format = variable
516
- data.dateFormat = format
517
- }
518
- if (record && record[rKey]) {
519
- const recordValue = unref(record[rKey][propKey])
520
- if (dayjs.isDayjs(recordValue)) {
521
- data.fieldValue = recordValue.format(format || 'YYYY-MM-DD')
522
- } else {
523
- data.fieldValue = recordValue
524
- }
525
- }
526
- return
527
- }
528
- // 获取组件属性
529
- const model = getGlobalModel(id) || {}
530
- // console.log('model', model)
531
- const { value, format = 'YYYY-MM-DD', type = '', useCurrentTime, RECORD } = model || {}
532
- const customFormat = dateFormat || format
533
- if (lowerCaseIncludes(model.type, 'date')) {
534
- let dateValue
535
- if (useCurrentTime) {
536
- if (value) {
537
- dateValue = unref(value)
538
- } else {
539
- dateValue = dayjs()
540
- }
541
- } else {
542
- dateValue = unref(value)
543
- }
544
- if (operateValue && operateMode && operateType) {
545
- switch (operateType) {
546
- case 'add':
547
- dateValue = dateValue.add(operateValue, operateMode)
548
- break
549
- case 'minus':
550
- dateValue = dateValue.subtract(operateValue, operateMode)
551
- break
552
- }
553
- }
554
- data.fieldValue = dateValue?.format(customFormat)
555
- data.dateFormat = customFormat
556
- } else if (type === 'ecanRangePicker') {
557
- let propValue = prop
558
- if (!prop) {
559
- const knList = keyName && keyName.split('-')
560
- if (knList?.length) {
561
- propValue = knList[knList.length - 1]
562
- }
563
- }
564
- if (!propValue) {
565
- return
566
- }
567
- let _time: any = null
568
- if (unref(model[propValue])) {
569
- _time = dayjs(unref(model[propValue]))
570
- }
571
-
572
- if (operateValue && operateMode && operateType) {
573
- if (operateValue === 'rangeValue') {
574
- // 自定义偏移,目前只有范围差
575
- if (model.startTime && model.endTime) {
576
- const interval = unref(model.endTime).diff(unref(model.startTime), operateMode) + 1
577
- switch (operateType) {
578
- case 'add':
579
- _time = _time ? _time.add(interval, operateMode) : _time
580
- break
581
- case 'minus':
582
- _time = _time ? _time.subtract(interval, operateMode) : _time
583
- }
584
- }
585
- } else if (!isNaN(+operateValue)) {
586
- switch (operateType) {
587
- case 'add':
588
- _time = _time ? _time.add(operateValue, operateMode) : _time
589
- break
590
- case 'minus':
591
- _time = _time ? _time.subtract(operateValue, operateMode) : _time
592
- }
593
- }
594
- }
595
-
596
- if (_time) {
597
- data.fieldValue = _time?.format(customFormat)
598
- }
599
- if (propValue === 'rangeValue') {
600
- // 全局变量的日期范围间隔值计算
601
- if (model.startTime && model.endTime) {
602
- const step: any = getFormatStep(customFormat)
603
- if (step) {
604
- data.fieldValue = unref(model.endTime).diff(unref(model.startTime), step) + 1
605
- }
606
- }
607
- }
608
- data.dateFormat = customFormat
609
- } else if (lowerCaseIncludes(type, MODEL_KEY_LIST)) {
610
- if (modelKey && RECORD) {
611
- data.fieldValue = RECORD[modelKey]
612
- } else if (!modelKey && RECORD) {
613
- data.fieldValue = RECORD.value
614
- } else {
615
- data.fieldValue = unref(value)
616
- }
617
- } else {
618
- data.fieldValue = unref(value)
619
- }
620
- }
621
-
622
- const handleSort = (sort: any) => {
623
- if (sort) {
624
- const sortData: any = Array.isArray(sort) ? cloneDeep(sort) : [cloneDeep(sort)]
625
- let type = ''
626
- let customOrderColumns = []
627
- const labels: any = []
628
- const columnNames: any = []
629
- const orders: any = []
630
- for (const item of sortData) {
631
- if (item.defaultCode) {
632
- item.label = item.columnName
633
- delete item.defaultCode
634
- }
635
- if (item.type === 'CUSTOM') {
636
- customOrderColumns = item.customOrderColumns
637
- }
638
- type = item.type
639
- labels.push(item.label)
640
- if (item.columnName?.includes('_ecanrepeat_')) {
641
- // 处理多个一样的指标或维度
642
- const list = item.columnName.split('_ecanrepeat_')
643
- columnNames.push(list[0])
644
- } else {
645
- columnNames.push(item.columnName)
646
- }
647
- orders.push(item.order)
648
- }
649
- if (type !== 'CUSTOM' && labels?.length > 1) {
650
- type = 'COMBINATION'
651
- }
652
- if (type === 'CUSTOM') {
653
- return {
654
- label: labels.join(','),
655
- columnName: columnNames.join(','),
656
- type,
657
- customOrderColumns
658
- }
659
- } else {
660
- return {
661
- label: labels.join(','),
662
- columnName: columnNames.join(','),
663
- order: orders.join(','),
664
- type
665
- }
666
- }
667
- } else {
668
- return sort
669
- }
670
- }
671
-
672
- // 获取关联控件排序的排序信息
673
- const getCpntSortData = (data: any) => {
674
- const { sortCpnts = [] } = data
675
- let customSort: any
676
- let order = ''
677
- for (const id of sortCpnts) {
678
- const model = getGlobalModel(id) || {}
679
- const { type, RECORD } = model
680
- if (lowerCaseIncludes(type, 'image') && lowerCaseIncludes(RECORD?.value, ['asc', 'desc'])) {
681
- order = RECORD.value.toUpperCase()
682
- break
683
- }
684
- }
685
- if (order) {
686
- customSort = {
687
- label: data.label,
688
- columnName: data.name,
689
- order,
690
- type: 'NORMAL'
691
- }
692
- }
693
- return customSort
694
- }
695
-
696
- export const formatIndicatorParams = (props: any, otherParams: any = {}) => {
697
- const { graphicConfig, type, globalModel, isGroupTable = false } = props
698
- if (globalModel) {
699
- modelValue = globalModel
700
- }
701
- let pageId = props.pageId
702
- const isPivotTable = lowerCaseIncludes(type, 'pivottable')
703
-
704
- let {
705
- source,
706
- dataViewId,
707
- plugin = '1', // 插件类型
708
- layer, // 后台图表类型,值分0,1
709
- chartType, // 前端图表类型
710
- classificationList = [],
711
- rowHeaderList = [],
712
- dimensionList = [], // 文本组件的维度列表
713
- seriesList = [],
714
- leftAxisList = [],
715
- rightAxisList = [],
716
- queryColumnList = [],
717
- indicators = [],
718
- controlList = [],
719
- formFields = {},
720
- variableList = [],
721
- variableConditions = [],
722
- // dataSourceId, // 所属数据源ID
723
- idxLibMode, // 指标库模式, source= INDICATOR_LIB时候必填, NORMAL_YEAR_TABLE = 普通年表, WITH_DATE_DIM_TABLE = 带有时间维度表
724
- preview = false, // 预览开关
725
- edvDataSetId // 数据集id
726
- } = graphicConfig || {}
727
-
728
- let sqlConditions: any = []
729
- if (graphicConfig?.pageMode === 'design') {
730
- // relativeList 在设计模式下,由于联动无法直接获取,已经处理好数据直接获取
731
- sqlConditions = (graphicConfig.sqlConditions ?? []).map((v: any) => {
732
- const gParams: any = {}
733
- if (!hasOwn(v, 'globalCondition') && !v.join) {
734
- gParams.globalCondition = true
735
- }
736
- if (!v.join) {
737
- const ruleVaule = v.rule || 'EQUAL'
738
- gParams.rule = ruleVaule === 'NONE' ? 'EQUAL' : ruleVaule
739
- }
740
- return {
741
- ...v,
742
- ...gParams
743
- }
744
- })
745
- if (variableConditions?.length) {
746
- sqlConditions = sqlConditions.concat(variableConditions)
747
- }
748
- } else {
749
- sqlConditions = handleSqlConditions(graphicConfig)
750
- if (variableList?.length) {
751
- sqlConditions = sqlConditions.concat(handleVariableList(variableList))
752
- }
753
- }
754
-
755
- if (sqlConditions?.length) {
756
- const globalList = sqlConditions.filter((v: any) => v.globalCondition)
757
- const notGlobalList = sqlConditions.filter((v: any) => !v.globalCondition)
758
- if (globalList?.length > 1) {
759
- sqlConditions = [
760
- {
761
- join: '&&',
762
- conditions: globalList
763
- },
764
- ...notGlobalList
765
- ]
766
- }
767
- }
768
-
769
- // 把sqlConditions转成接口要求的数据格式
770
- if (sqlConditions?.length) {
771
- sqlConditions = handleConditions(sqlConditions, '1')
772
- }
773
-
774
- // 图类型,1=表 2=图
775
- if (layer == null) {
776
- if (lowerCaseIncludes(type, ['table', 'card']) || (lowerCaseIncludes(type, ['list', 'circulate']) && classificationList?.length > 1)) {
777
- layer = '1'
778
- } else if (lowerCaseIncludes(type, ['select', 'checkbox', 'radio'])) {
779
- layer = '3'
780
- } else {
781
- layer = '2'
782
- }
783
- }
784
-
785
- let classification
786
- const classifications: any = []
787
- let typeGuidString = ''
788
- if (
789
- Array.isArray(classificationList) &&
790
- classificationList.length > 0 &&
791
- (!['ecanList', 'ecanCirculate'].includes(type) || classificationList?.length === 1)
792
- ) {
793
- const len = classificationList.length
794
- for (let i = 0; i < len; i++) {
795
- const item = classificationList[i] || {}
796
- const {
797
- label = '',
798
- name = '',
799
- show = false,
800
- sort,
801
- customGroup,
802
- conditions,
803
- dateFormat,
804
- typeGuid = '',
805
- truncations = []
806
- } = item
807
- // 如果是 show 直接提取 classification,停止遍历
808
- if (show || len === 1) {
809
- typeGuidString = typeGuid
810
- classification = {
811
- label: label.trim(),
812
- columnName: name,
813
- show,
814
- sort: getCpntSortData(item) || handleSort(sort) || sort,
815
- customGroup,
816
- conditions: handleConditions(conditions),
817
- typeGuid
818
- }
819
- if (dateFormat) {
820
- classification.dateFormat = dateFormat
821
- }
822
- if (name === 'the_date' && !classification.dateFormat) {
823
- classification.dateFormat = 'YYYY-MM'
824
- }
825
- // truncation
826
- const truncation: any = {}
827
- if (Array.isArray(truncations) && truncations.length > 0) {
828
- const len = truncations.length
829
- for (let i = 0; i < len; i++) {
830
- const item = truncations[i] || {}
831
- const { rule = '', num = 0, name = '' } = item
832
- if (rule && num) {
833
- truncation.num = num
834
- truncation.rule = rule
835
- if (name) {
836
- truncation.otherGroupName = name
837
- }
838
- }
839
- }
840
- }
841
- if (Object.keys(truncation)?.length) {
842
- classification.truncation = truncation
843
- }
844
- if (lowerCaseIncludes(type, ['scatter', 'valueline'])) {
845
- classifications.push(classification)
846
- } else {
847
- break
848
- }
849
- }
850
- }
851
- }
852
- // seriesList (取第一项) => series
853
- let series
854
- if (Array.isArray(seriesList) && seriesList.length > 0) {
855
- const len = seriesList.length
856
- for (let i = 0; i < len; i++) {
857
- const item = seriesList[i] || {}
858
- const { label = '', name = '', show = false, sort, customGroup, conditions, typeGuid } = item
859
- // 如果是 show 直接提取 seriesList,停止遍历
860
- if (show || len === 1) {
861
- series = {
862
- label: label.trim(),
863
- columnName: name,
864
- show,
865
- sort: handleSort(sort),
866
- customGroup,
867
- conditions: handleConditions(conditions),
868
- typeGuid
869
- }
870
- break
871
- }
872
- }
873
- }
874
-
875
- // leftAxisList + rightAxisList + indicators => indicatorList
876
- const indicatorList: any = []
877
- leftAxisList?.forEach((leftAxis: { [key:string]: any }) => {
878
- leftAxis.location = 'LEFT'
879
- indicatorList.push(handleIndicator(leftAxis, classification))
880
- })
881
- rightAxisList?.forEach((rightAxis: { [key:string]: any }) => {
882
- rightAxis.location = 'RIGHT'
883
- indicatorList.push(handleIndicator(rightAxis, classification))
884
- })
885
-
886
- let indicatorsData = indicators
887
- if (otherParams?.pivotTableCal?.indicators?.length) {
888
- // 透视表全设计模式,替换设计态拖拽的指标
889
- indicatorsData = otherParams.pivotTableCal.indicators
890
- }
891
- indicatorsData?.forEach((indicator: { [key:string]: any }) => {
892
- indicator.location = 'LEFT'
893
- indicatorList.push(handleIndicator(indicator, classification))
894
- })
895
-
896
- // queryColumnList => queryColumns
897
- const queryColumns: any = []
898
- if (['ecanList', 'ecanCirculate'].includes(type) && classificationList?.length > 1) {
899
- queryColumnList = classificationList
900
- }
901
- if (otherParams?.pivotTableCal?.dimensions?.length) {
902
- // 透视表全设计模式,替换设计态拖拽的维度
903
- queryColumnList = otherParams.pivotTableCal.dimensions
904
- }
905
- queryColumnList?.forEach((queryColumn: { [key:string]: any }) => {
906
- const { label, name, location, show, indexCode, sort, typeGuid, indexCodeNum, dateFormat, conditions } = queryColumn
907
- let customSort = handleSort(sort)
908
- if (otherParams.sort) {
909
- // 表格的表头排序
910
- const { field, order } = otherParams.sort
911
- let indicator = indicatorList.find(v => v.label === field)
912
- if (!indicator && label === field) {
913
- indicator = queryColumn
914
- }
915
- if (indicator) {
916
- customSort = {
917
- columnName: indicator.columnName,
918
- label: otherParams.sort.field,
919
- order: order.toUpperCase(),
920
- type: 'NORMAL'
921
- }
922
- }
923
- }
924
- const itemObj: any = {
925
- label,
926
- columnName: name,
927
- location,
928
- show,
929
- sort: customSort,
930
- calcType: 'COLUMN',
931
- hrpIndexCode: indexCode,
932
- hrpIndexCodeNum: indexCodeNum,
933
- conditions: handleConditions(conditions),
934
- typeGuid
935
- }
936
- if (dateFormat) {
937
- itemObj.dateFormat = dateFormat
938
- }
939
- if (name === 'the_date' && !itemObj.dateFormat) {
940
- itemObj.dateFormat = 'YYYY-MM'
941
- }
942
- queryColumns.push(itemObj)
943
- })
944
-
945
- // 行表头
946
- let rowHeaders: any = []
947
- let resultRowHeaderList: any = []
948
- if (Array.isArray(rowHeaderList) && rowHeaderList.length > 0) {
949
- resultRowHeaderList = rowHeaderList
950
- } else if (Array.isArray(dimensionList) && dimensionList.length > 0) {
951
- resultRowHeaderList = dimensionList
952
- }
953
- if (resultRowHeaderList?.length) {
954
- const len = resultRowHeaderList.length
955
- for (let i = 0; i < len; i++) {
956
- const item = resultRowHeaderList[i] || {}
957
- const { label = '', name = '', show = false, sort, customGroup, conditions, truncations, typeGuid = '', dateFormat } = item
958
- let customSort = handleSort(sort)
959
- if (otherParams.sort) {
960
- // 表格的表头排序
961
- const { field, order } = otherParams.sort
962
- let indicator = indicatorList.find(v => v.label === field)
963
- if (!indicator && item.label === field) {
964
- indicator = item
965
- }
966
- if (indicator) {
967
- customSort = {
968
- columnName: indicator.columnName,
969
- label: otherParams.sort.field,
970
- order: order.toUpperCase(),
971
- type: 'NORMAL'
972
- }
973
- }
974
- }
975
- const itemObj: any = {
976
- label: label.trim(),
977
- columnName: name,
978
- show,
979
- sort: customSort,
980
- customGroup,
981
- conditions: handleConditions(conditions),
982
- typeGuid
983
- }
984
- if (dateFormat) {
985
- itemObj.dateFormat = dateFormat
986
- }
987
- if (name === 'the_date' && !itemObj.dateFormat) {
988
- itemObj.dateFormat = 'YYYY-MM'
989
- }
990
- // truncation
991
- const truncation: any = {}
992
- if (Array.isArray(truncations) && truncations.length > 0) {
993
- const len = truncations.length
994
- for (let i = 0; i < len; i++) {
995
- const item = truncations[i] || {}
996
- const { rule = '', num = 0, name = '' } = item
997
- if (rule && num) {
998
- truncation.num = num
999
- truncation.rule = rule
1000
- if (name) {
1001
- truncation.otherGroupName = name
1002
- }
1003
- }
1004
- }
1005
- }
1006
- if (Object.keys(truncation)?.length) {
1007
- itemObj.truncation = truncation
1008
- }
1009
- rowHeaders.push(itemObj)
1010
- }
1011
- }
1012
-
1013
- // 透视表指标排序要用到的
1014
- let pivotColumnHeader: any = []
1015
- let pivotColumnData: any
1016
- // 透视表
1017
- if (otherParams?.pivotTableCal) {
1018
- let resultList: any = []
1019
- const {
1020
- calc = [],
1021
- filter = [],
1022
- truncations = [],
1023
- sorts = [],
1024
- aggregateMethod = [],
1025
- rowDimensionKeys = [],
1026
- colDimensionKeys = []
1027
- } = otherParams.pivotTableCal
1028
- // 计算
1029
- indicatorList.push(...calc)
1030
- // 筛选
1031
- if (filter?.length) {
1032
- for (const fl of filter) {
1033
- const { type, ...flParams } = fl
1034
- if (type === 'indicators') {
1035
- // 指标筛选
1036
- resultList = indicatorList
1037
- } else if (type === 'dimension') {
1038
- // 维度筛选
1039
- resultList = queryColumns
1040
- }
1041
- const target = resultList.find((v: any) => v.columnName === fl.fieldName)
1042
- if (target) {
1043
- if (!target.conditions) {
1044
- target.conditions = []
1045
- }
1046
- target.conditions.push(flParams)
1047
- }
1048
- }
1049
- }
1050
- // 取top
1051
- if (truncations?.length) {
1052
- for (const item of truncations) {
1053
- const target = queryColumns.find(v => v.columnName === item.key)
1054
- if (target) {
1055
- target.truncation = {
1056
- num: item.num,
1057
- rule: item.rule
1058
- }
1059
- }
1060
- }
1061
- }
1062
-
1063
- // 维度/指标排序
1064
- if (sorts?.length) {
1065
- for (const item of sorts) {
1066
- const { fieldType, columnData, ...sortParams } = item
1067
- if (fieldType === 'indicators') {
1068
- // 指标排序
1069
- resultList = indicatorList
1070
- pivotColumnData = columnData
1071
- } else if (fieldType === 'dimension') {
1072
- // 维度排序
1073
- resultList = queryColumns
1074
- }
1075
- const target = resultList.find(v => v.label === sortParams.label)
1076
- if (target) {
1077
- target.sort = {
1078
- ...sortParams,
1079
- columnName: target.columnName
1080
- }
1081
- }
1082
- }
1083
- }
1084
-
1085
- // 聚合
1086
- if (Object.keys(aggregateMethod)?.length) {
1087
- for (const key in aggregateMethod) {
1088
- const target = queryColumns.find(v => v.label === key)
1089
- if (target && aggregateMethod[key]?.length) {
1090
- target.aggregateMethod = aggregateMethod[key]
1091
- }
1092
- }
1093
- }
1094
-
1095
- rowHeaders = []
1096
- pivotColumnHeader = []
1097
- for (const q of queryColumns) {
1098
- if (rowDimensionKeys.includes(q.columnName)) {
1099
- rowHeaders.push(q)
1100
- } else if (colDimensionKeys.includes(q.columnName)) {
1101
- pivotColumnHeader.push(q)
1102
- }
1103
- }
1104
- }
1105
-
1106
- if (lowerCaseIncludes(type, ['text', 'proportion', 'counter'])) {
1107
- chartType = 'zb'
1108
- } else if (lowerCaseIncludes(type, ['valueline'])) {
1109
- chartType = 'valueline'
1110
- }
1111
-
1112
- // queryColumns 表格配置为空返回
1113
- if (isGroupTable || type === 'card') {
1114
- if (rowHeaders.length === 0 || indicatorList.length === 0) {
1115
- return
1116
- } else {
1117
- chartType = 'grouptable'
1118
- }
1119
- } else if (layer === '1' && queryColumns.length === 0) {
1120
- return
1121
- // queryColumns 图表配置为空返回
1122
- } else if (layer === '2' && indicatorList.length === 0) {
1123
- return
1124
- } else if (layer === '3' && ((!typeGuidString && source !== 'EDV_DATA_SET') || !formFields.labelField || !formFields.valueField)) {
1125
- return
1126
- } else if (layer === '3' && type === 'ecanDataSelect' && indicatorList.length === 0) {
1127
- return
1128
- }
1129
-
1130
- // 文本维度
1131
- if (dimensionList?.length) {
1132
- layer = '1'
1133
- chartType = 'grouptable'
1134
- }
1135
-
1136
- if (!pageId) {
1137
- const { pathname } = (window as any)?.location
1138
- if (pathname) {
1139
- const list = pathname.split('/')
1140
- if (list?.length) {
1141
- pageId = list[list.length - 1]
1142
- }
1143
- }
1144
- }
1145
-
1146
- let resultParams: any
1147
- if (!lowerCaseIncludes(type, ['scatter', 'valueline']) && Object.keys(formFields)?.length) {
1148
- const cascadeControl = getConditions(controlList).find((v: any) => v.conditionKey === 'parentCode')
1149
- const someParams: any = {}
1150
- if (cascadeControl) {
1151
- const model = getGlobalModel(cascadeControl.id) || {}
1152
- if (model?.itemCodes) {
1153
- someParams.parentItemCodes = model.itemCodes
1154
- } else {
1155
- return
1156
- }
1157
- }
1158
- if (type === 'ecanDataSelect') {
1159
- someParams.indicatorList = indicatorList.filter(v => v.show)
1160
- }
1161
- if (source === 'EDV_DATA_SET') {
1162
- someParams.edvDataSetId = edvDataSetId
1163
- }
1164
- resultParams = {
1165
- url: '/diagram/formData',
1166
- source,
1167
- dataViewId,
1168
- plugin: '4',
1169
- layer,
1170
- chartType: 'normalSelect',
1171
- rangeIndexTypeGuid: typeGuidString,
1172
- type: type === 'ecanDataSelect' ? 'normalSelectData' : 'normalSelect',
1173
- labelField: formFields.labelField,
1174
- valueField: formFields.valueField,
1175
- pageId,
1176
- sqlConditions,
1177
- idxLibMode: 'WITH_DATE_DIM_TABLE',
1178
- keyName: props.keyName,
1179
- ...someParams
1180
- }
1181
- } else {
1182
- let classParams = {}
1183
- if (lowerCaseIncludes(type, ['scatter', 'valueline'])) {
1184
- // 散点图多个维度
1185
- classParams = {
1186
- classifications
1187
- }
1188
- } else {
1189
- classParams = {
1190
- classification
1191
- }
1192
- }
1193
- resultParams = {
1194
- url: '/diagram',
1195
- source,
1196
- dataViewId,
1197
- plugin: isPivotTable ? '5' : plugin,
1198
- layer,
1199
- chartType: isPivotTable ? 'pivot-table' : chartType,
1200
- series,
1201
- indicatorList,
1202
- queryColumns: isGroupTable ? [] : queryColumns,
1203
- pageFlag: true,
1204
- pageId,
1205
- edvDataSetId: edvDataSetId || '',
1206
- sqlConditions: sqlConditions.map(v => {
1207
- const { fieldValue } = v
1208
- const params: any = {}
1209
- if (fieldValue && Array.isArray(fieldValue)) {
1210
- params.fieldValue = JSON.stringify(fieldValue)
1211
- }
1212
- return {
1213
- ...v,
1214
- ...params
1215
- }
1216
- }),
1217
- idxLibMode,
1218
- preview,
1219
- rowHeaders,
1220
- keyName: props.keyName,
1221
- // 透视表指标排序相关入参
1222
- columnData: pivotColumnData,
1223
- columnHeaders: pivotColumnHeader,
1224
- ...classParams,
1225
- }
1226
- }
1227
- return resultParams
1228
- }