@ecan-bi/tools 1.0.19 → 1.0.21
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/.babelrc +6 -0
- package/lib/index.es.js +1 -0
- package/package.json +15 -27
- package/rollup.config.js +30 -0
- package/src/hooks/useTransformChartDataByAttrKey.ts +77 -0
- package/src/hooks/useTransformChartDataByAttrValue.ts +61 -0
- package/src/hooks/useValueFormatter.ts +27 -0
- package/src/hooks/useVariablesInText.ts +44 -0
- package/src/index.ts +22 -0
- package/src/indicator.ts +1215 -0
- package/src/utils/constant.ts +1 -0
- package/src/utils/runCode.ts +26 -0
- package/src/utils/transformProps.ts +901 -0
- package/src/utils/util.ts +195 -0
- package/tsconfig.json +38 -0
- package/dist/index.es.js +0 -1740
- package/dist/index.es.js.map +0 -1
- package/dist/index.umd.js +0 -6
- package/dist/index.umd.js.map +0 -1
package/src/indicator.ts
ADDED
|
@@ -0,0 +1,1215 @@
|
|
|
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
|
+
const isPivotTable = lowerCaseIncludes(type, 'pivottable')
|
|
702
|
+
|
|
703
|
+
let {
|
|
704
|
+
source,
|
|
705
|
+
dataViewId,
|
|
706
|
+
plugin = '1', // 插件类型
|
|
707
|
+
layer, // 后台图表类型,值分0,1
|
|
708
|
+
chartType, // 前端图表类型
|
|
709
|
+
classificationList = [],
|
|
710
|
+
rowHeaderList = [],
|
|
711
|
+
dimensionList = [], // 文本组件的维度列表
|
|
712
|
+
seriesList = [],
|
|
713
|
+
leftAxisList = [],
|
|
714
|
+
rightAxisList = [],
|
|
715
|
+
queryColumnList = [],
|
|
716
|
+
indicators = [],
|
|
717
|
+
controlList = [],
|
|
718
|
+
formFields = {},
|
|
719
|
+
variableList = [],
|
|
720
|
+
variableConditions = [],
|
|
721
|
+
// dataSourceId, // 所属数据源ID
|
|
722
|
+
idxLibMode, // 指标库模式, source= INDICATOR_LIB时候必填, NORMAL_YEAR_TABLE = 普通年表, WITH_DATE_DIM_TABLE = 带有时间维度表
|
|
723
|
+
preview = false, // 预览开关
|
|
724
|
+
edvDataSetId // 数据集id
|
|
725
|
+
} = graphicConfig || {}
|
|
726
|
+
|
|
727
|
+
let sqlConditions: any = []
|
|
728
|
+
if (graphicConfig?.pageMode === 'design') {
|
|
729
|
+
// relativeList 在设计模式下,由于联动无法直接获取,已经处理好数据直接获取
|
|
730
|
+
sqlConditions = (graphicConfig.sqlConditions ?? []).map((v: any) => {
|
|
731
|
+
const gParams: any = {}
|
|
732
|
+
if (!hasOwn(v, 'globalCondition') && !v.join) {
|
|
733
|
+
gParams.globalCondition = true
|
|
734
|
+
}
|
|
735
|
+
if (!v.join) {
|
|
736
|
+
const ruleVaule = v.rule || 'EQUAL'
|
|
737
|
+
gParams.rule = ruleVaule === 'NONE' ? 'EQUAL' : ruleVaule
|
|
738
|
+
}
|
|
739
|
+
return {
|
|
740
|
+
...v,
|
|
741
|
+
...gParams
|
|
742
|
+
}
|
|
743
|
+
})
|
|
744
|
+
if (variableConditions?.length) {
|
|
745
|
+
sqlConditions = sqlConditions.concat(variableConditions)
|
|
746
|
+
}
|
|
747
|
+
} else {
|
|
748
|
+
sqlConditions = handleSqlConditions(graphicConfig)
|
|
749
|
+
if (variableList?.length) {
|
|
750
|
+
sqlConditions = sqlConditions.concat(handleVariableList(variableList))
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (sqlConditions?.length) {
|
|
755
|
+
const globalList = sqlConditions.filter((v: any) => v.globalCondition)
|
|
756
|
+
const notGlobalList = sqlConditions.filter((v: any) => !v.globalCondition)
|
|
757
|
+
if (globalList?.length > 1) {
|
|
758
|
+
sqlConditions = [
|
|
759
|
+
{
|
|
760
|
+
join: '&&',
|
|
761
|
+
conditions: globalList
|
|
762
|
+
},
|
|
763
|
+
...notGlobalList
|
|
764
|
+
]
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// 把sqlConditions转成接口要求的数据格式
|
|
769
|
+
if (sqlConditions?.length) {
|
|
770
|
+
sqlConditions = handleConditions(sqlConditions, '1')
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// 图类型,1=表 2=图
|
|
774
|
+
if (layer == null) {
|
|
775
|
+
if (lowerCaseIncludes(type, ['table', 'card']) || (lowerCaseIncludes(type, ['list', 'circulate']) && classificationList?.length > 1)) {
|
|
776
|
+
layer = '1'
|
|
777
|
+
} else if (lowerCaseIncludes(type, ['select', 'checkbox', 'radio'])) {
|
|
778
|
+
layer = '3'
|
|
779
|
+
} else {
|
|
780
|
+
layer = '2'
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
let classification
|
|
785
|
+
const classifications: any = []
|
|
786
|
+
let typeGuidString = ''
|
|
787
|
+
if (
|
|
788
|
+
Array.isArray(classificationList) &&
|
|
789
|
+
classificationList.length > 0 &&
|
|
790
|
+
(!['ecanList', 'ecanCirculate'].includes(type) || classificationList?.length === 1)
|
|
791
|
+
) {
|
|
792
|
+
const len = classificationList.length
|
|
793
|
+
for (let i = 0; i < len; i++) {
|
|
794
|
+
const item = classificationList[i] || {}
|
|
795
|
+
const {
|
|
796
|
+
label = '',
|
|
797
|
+
name = '',
|
|
798
|
+
show = false,
|
|
799
|
+
sort,
|
|
800
|
+
customGroup,
|
|
801
|
+
conditions,
|
|
802
|
+
dateFormat,
|
|
803
|
+
typeGuid = '',
|
|
804
|
+
truncations = []
|
|
805
|
+
} = item
|
|
806
|
+
// 如果是 show 直接提取 classification,停止遍历
|
|
807
|
+
if (show || len === 1) {
|
|
808
|
+
typeGuidString = typeGuid
|
|
809
|
+
classification = {
|
|
810
|
+
label: label.trim(),
|
|
811
|
+
columnName: name,
|
|
812
|
+
show,
|
|
813
|
+
sort: getCpntSortData(item) || handleSort(sort) || sort,
|
|
814
|
+
customGroup,
|
|
815
|
+
conditions: handleConditions(conditions),
|
|
816
|
+
typeGuid
|
|
817
|
+
}
|
|
818
|
+
if (dateFormat) {
|
|
819
|
+
classification.dateFormat = dateFormat
|
|
820
|
+
}
|
|
821
|
+
if (name === 'the_date' && !classification.dateFormat) {
|
|
822
|
+
classification.dateFormat = 'YYYY-MM'
|
|
823
|
+
}
|
|
824
|
+
// truncation
|
|
825
|
+
const truncation: any = {}
|
|
826
|
+
if (Array.isArray(truncations) && truncations.length > 0) {
|
|
827
|
+
const len = truncations.length
|
|
828
|
+
for (let i = 0; i < len; i++) {
|
|
829
|
+
const item = truncations[i] || {}
|
|
830
|
+
const { rule = '', num = 0, name = '' } = item
|
|
831
|
+
if (rule && num) {
|
|
832
|
+
truncation.num = num
|
|
833
|
+
truncation.rule = rule
|
|
834
|
+
if (name) {
|
|
835
|
+
truncation.otherGroupName = name
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (Object.keys(truncation)?.length) {
|
|
841
|
+
classification.truncation = truncation
|
|
842
|
+
}
|
|
843
|
+
if (lowerCaseIncludes(type, ['scatter', 'valueline'])) {
|
|
844
|
+
classifications.push(classification)
|
|
845
|
+
} else {
|
|
846
|
+
break
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
// seriesList (取第一项) => series
|
|
852
|
+
let series
|
|
853
|
+
if (Array.isArray(seriesList) && seriesList.length > 0) {
|
|
854
|
+
const len = seriesList.length
|
|
855
|
+
for (let i = 0; i < len; i++) {
|
|
856
|
+
const item = seriesList[i] || {}
|
|
857
|
+
const { label = '', name = '', show = false, sort, customGroup, conditions, typeGuid } = item
|
|
858
|
+
// 如果是 show 直接提取 seriesList,停止遍历
|
|
859
|
+
if (show || len === 1) {
|
|
860
|
+
series = {
|
|
861
|
+
label: label.trim(),
|
|
862
|
+
columnName: name,
|
|
863
|
+
show,
|
|
864
|
+
sort: handleSort(sort),
|
|
865
|
+
customGroup,
|
|
866
|
+
conditions: handleConditions(conditions),
|
|
867
|
+
typeGuid
|
|
868
|
+
}
|
|
869
|
+
break
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// leftAxisList + rightAxisList + indicators => indicatorList
|
|
875
|
+
const indicatorList: any = []
|
|
876
|
+
leftAxisList?.forEach((leftAxis: { [key:string]: any }) => {
|
|
877
|
+
leftAxis.location = 'LEFT'
|
|
878
|
+
indicatorList.push(handleIndicator(leftAxis, classification))
|
|
879
|
+
})
|
|
880
|
+
rightAxisList?.forEach((rightAxis: { [key:string]: any }) => {
|
|
881
|
+
rightAxis.location = 'RIGHT'
|
|
882
|
+
indicatorList.push(handleIndicator(rightAxis, classification))
|
|
883
|
+
})
|
|
884
|
+
|
|
885
|
+
let indicatorsData = indicators
|
|
886
|
+
if (otherParams?.pivotTableCal?.indicators?.length) {
|
|
887
|
+
// 透视表全设计模式,替换设计态拖拽的指标
|
|
888
|
+
indicatorsData = otherParams.pivotTableCal.indicators
|
|
889
|
+
}
|
|
890
|
+
indicatorsData?.forEach((indicator: { [key:string]: any }) => {
|
|
891
|
+
indicator.location = 'LEFT'
|
|
892
|
+
indicatorList.push(handleIndicator(indicator, classification))
|
|
893
|
+
})
|
|
894
|
+
|
|
895
|
+
// queryColumnList => queryColumns
|
|
896
|
+
const queryColumns: any = []
|
|
897
|
+
if (['ecanList', 'ecanCirculate'].includes(type) && classificationList?.length > 1) {
|
|
898
|
+
queryColumnList = classificationList
|
|
899
|
+
}
|
|
900
|
+
if (otherParams?.pivotTableCal?.dimensions?.length) {
|
|
901
|
+
// 透视表全设计模式,替换设计态拖拽的维度
|
|
902
|
+
queryColumnList = otherParams.pivotTableCal.dimensions
|
|
903
|
+
}
|
|
904
|
+
queryColumnList?.forEach((queryColumn: { [key:string]: any }) => {
|
|
905
|
+
const { label, name, location, show, indexCode, sort, typeGuid, indexCodeNum, dateFormat, conditions } = queryColumn
|
|
906
|
+
let customSort = handleSort(sort)
|
|
907
|
+
if (otherParams.sort) {
|
|
908
|
+
// 表格的表头排序
|
|
909
|
+
const { field, order } = otherParams.sort
|
|
910
|
+
let indicator = indicatorList.find(v => v.label === field)
|
|
911
|
+
if (!indicator && label === field) {
|
|
912
|
+
indicator = queryColumn
|
|
913
|
+
}
|
|
914
|
+
if (indicator) {
|
|
915
|
+
customSort = {
|
|
916
|
+
columnName: indicator.columnName,
|
|
917
|
+
label: otherParams.sort.field,
|
|
918
|
+
order: order.toUpperCase(),
|
|
919
|
+
type: 'NORMAL'
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
const itemObj: any = {
|
|
924
|
+
label,
|
|
925
|
+
columnName: name,
|
|
926
|
+
location,
|
|
927
|
+
show,
|
|
928
|
+
sort: customSort,
|
|
929
|
+
calcType: 'COLUMN',
|
|
930
|
+
hrpIndexCode: indexCode,
|
|
931
|
+
hrpIndexCodeNum: indexCodeNum,
|
|
932
|
+
conditions: handleConditions(conditions),
|
|
933
|
+
typeGuid
|
|
934
|
+
}
|
|
935
|
+
if (dateFormat) {
|
|
936
|
+
itemObj.dateFormat = dateFormat
|
|
937
|
+
}
|
|
938
|
+
if (name === 'the_date' && !itemObj.dateFormat) {
|
|
939
|
+
itemObj.dateFormat = 'YYYY-MM'
|
|
940
|
+
}
|
|
941
|
+
queryColumns.push(itemObj)
|
|
942
|
+
})
|
|
943
|
+
|
|
944
|
+
// 行表头
|
|
945
|
+
let rowHeaders: any = []
|
|
946
|
+
let resultRowHeaderList: any = []
|
|
947
|
+
if (Array.isArray(rowHeaderList) && rowHeaderList.length > 0) {
|
|
948
|
+
resultRowHeaderList = rowHeaderList
|
|
949
|
+
} else if (Array.isArray(dimensionList) && dimensionList.length > 0) {
|
|
950
|
+
resultRowHeaderList = dimensionList
|
|
951
|
+
}
|
|
952
|
+
if (resultRowHeaderList?.length) {
|
|
953
|
+
const len = resultRowHeaderList.length
|
|
954
|
+
for (let i = 0; i < len; i++) {
|
|
955
|
+
const item = resultRowHeaderList[i] || {}
|
|
956
|
+
const { label = '', name = '', show = false, sort, customGroup, conditions, truncations, typeGuid = '', dateFormat } = item
|
|
957
|
+
let customSort = handleSort(sort)
|
|
958
|
+
if (otherParams.sort) {
|
|
959
|
+
// 表格的表头排序
|
|
960
|
+
const { field, order } = otherParams.sort
|
|
961
|
+
let indicator = indicatorList.find(v => v.label === field)
|
|
962
|
+
if (!indicator && item.label === field) {
|
|
963
|
+
indicator = item
|
|
964
|
+
}
|
|
965
|
+
if (indicator) {
|
|
966
|
+
customSort = {
|
|
967
|
+
columnName: indicator.columnName,
|
|
968
|
+
label: otherParams.sort.field,
|
|
969
|
+
order: order.toUpperCase(),
|
|
970
|
+
type: 'NORMAL'
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
const itemObj: any = {
|
|
975
|
+
label: label.trim(),
|
|
976
|
+
columnName: name,
|
|
977
|
+
show,
|
|
978
|
+
sort: customSort,
|
|
979
|
+
customGroup,
|
|
980
|
+
conditions: handleConditions(conditions),
|
|
981
|
+
typeGuid
|
|
982
|
+
}
|
|
983
|
+
if (dateFormat) {
|
|
984
|
+
itemObj.dateFormat = dateFormat
|
|
985
|
+
}
|
|
986
|
+
if (name === 'the_date' && !itemObj.dateFormat) {
|
|
987
|
+
itemObj.dateFormat = 'YYYY-MM'
|
|
988
|
+
}
|
|
989
|
+
// truncation
|
|
990
|
+
const truncation: any = {}
|
|
991
|
+
if (Array.isArray(truncations) && truncations.length > 0) {
|
|
992
|
+
const len = truncations.length
|
|
993
|
+
for (let i = 0; i < len; i++) {
|
|
994
|
+
const item = truncations[i] || {}
|
|
995
|
+
const { rule = '', num = 0, name = '' } = item
|
|
996
|
+
if (rule && num) {
|
|
997
|
+
truncation.num = num
|
|
998
|
+
truncation.rule = rule
|
|
999
|
+
if (name) {
|
|
1000
|
+
truncation.otherGroupName = name
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
if (Object.keys(truncation)?.length) {
|
|
1006
|
+
itemObj.truncation = truncation
|
|
1007
|
+
}
|
|
1008
|
+
rowHeaders.push(itemObj)
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// 透视表指标排序要用到的
|
|
1013
|
+
let pivotColumnHeader: any = []
|
|
1014
|
+
let pivotColumnData: any
|
|
1015
|
+
// 透视表
|
|
1016
|
+
if (otherParams?.pivotTableCal) {
|
|
1017
|
+
let resultList: any = []
|
|
1018
|
+
const {
|
|
1019
|
+
calc = [],
|
|
1020
|
+
filter = [],
|
|
1021
|
+
truncations = [],
|
|
1022
|
+
sorts = [],
|
|
1023
|
+
aggregateMethod = [],
|
|
1024
|
+
rowDimensionKeys = [],
|
|
1025
|
+
colDimensionKeys = []
|
|
1026
|
+
} = otherParams.pivotTableCal
|
|
1027
|
+
// 计算
|
|
1028
|
+
indicatorList.push(...calc)
|
|
1029
|
+
// 筛选
|
|
1030
|
+
if (filter?.length) {
|
|
1031
|
+
for (const fl of filter) {
|
|
1032
|
+
const { type, ...flParams } = fl
|
|
1033
|
+
if (type === 'indicators') {
|
|
1034
|
+
// 指标筛选
|
|
1035
|
+
resultList = indicatorList
|
|
1036
|
+
} else if (type === 'dimension') {
|
|
1037
|
+
// 维度筛选
|
|
1038
|
+
resultList = queryColumns
|
|
1039
|
+
}
|
|
1040
|
+
const target = resultList.find((v: any) => v.columnName === fl.fieldName)
|
|
1041
|
+
if (target) {
|
|
1042
|
+
if (!target.conditions) {
|
|
1043
|
+
target.conditions = []
|
|
1044
|
+
}
|
|
1045
|
+
target.conditions.push(flParams)
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
// 取top
|
|
1050
|
+
if (truncations?.length) {
|
|
1051
|
+
for (const item of truncations) {
|
|
1052
|
+
const target = queryColumns.find(v => v.columnName === item.key)
|
|
1053
|
+
if (target) {
|
|
1054
|
+
target.truncation = {
|
|
1055
|
+
num: item.num,
|
|
1056
|
+
rule: item.rule
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// 维度/指标排序
|
|
1063
|
+
if (sorts?.length) {
|
|
1064
|
+
for (const item of sorts) {
|
|
1065
|
+
const { fieldType, columnData, ...sortParams } = item
|
|
1066
|
+
if (fieldType === 'indicators') {
|
|
1067
|
+
// 指标排序
|
|
1068
|
+
resultList = indicatorList
|
|
1069
|
+
pivotColumnData = columnData
|
|
1070
|
+
} else if (fieldType === 'dimension') {
|
|
1071
|
+
// 维度排序
|
|
1072
|
+
resultList = queryColumns
|
|
1073
|
+
}
|
|
1074
|
+
const target = resultList.find(v => v.label === sortParams.label)
|
|
1075
|
+
if (target) {
|
|
1076
|
+
target.sort = {
|
|
1077
|
+
...sortParams,
|
|
1078
|
+
columnName: target.columnName
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// 聚合
|
|
1085
|
+
if (Object.keys(aggregateMethod)?.length) {
|
|
1086
|
+
for (const key in aggregateMethod) {
|
|
1087
|
+
const target = queryColumns.find(v => v.label === key)
|
|
1088
|
+
if (target && aggregateMethod[key]?.length) {
|
|
1089
|
+
target.aggregateMethod = aggregateMethod[key]
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
rowHeaders = []
|
|
1095
|
+
pivotColumnHeader = []
|
|
1096
|
+
for (const q of queryColumns) {
|
|
1097
|
+
if (rowDimensionKeys.includes(q.columnName)) {
|
|
1098
|
+
rowHeaders.push(q)
|
|
1099
|
+
} else if (colDimensionKeys.includes(q.columnName)) {
|
|
1100
|
+
pivotColumnHeader.push(q)
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
if (lowerCaseIncludes(type, ['text', 'proportion', 'counter'])) {
|
|
1106
|
+
chartType = 'zb'
|
|
1107
|
+
} else if (lowerCaseIncludes(type, ['valueline'])) {
|
|
1108
|
+
chartType = 'valueline'
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// queryColumns 表格配置为空返回
|
|
1112
|
+
if (isGroupTable || type === 'card') {
|
|
1113
|
+
if (rowHeaders.length === 0 || indicatorList.length === 0) {
|
|
1114
|
+
return
|
|
1115
|
+
} else {
|
|
1116
|
+
chartType = 'grouptable'
|
|
1117
|
+
}
|
|
1118
|
+
} else if (layer === '1' && queryColumns.length === 0) {
|
|
1119
|
+
return
|
|
1120
|
+
// queryColumns 图表配置为空返回
|
|
1121
|
+
} else if (layer === '2' && indicatorList.length === 0) {
|
|
1122
|
+
return
|
|
1123
|
+
} else if (layer === '3' && ((!typeGuidString && source !== 'EDV_DATA_SET') || !formFields.labelField || !formFields.valueField)) {
|
|
1124
|
+
return
|
|
1125
|
+
} else if (layer === '3' && type === 'ecanDataSelect' && indicatorList.length === 0) {
|
|
1126
|
+
return
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// 文本维度
|
|
1130
|
+
if (dimensionList?.length) {
|
|
1131
|
+
layer = '1'
|
|
1132
|
+
chartType = 'grouptable'
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
let resultParams: any
|
|
1136
|
+
if (!lowerCaseIncludes(type, ['scatter', 'valueline']) && Object.keys(formFields)?.length) {
|
|
1137
|
+
const cascadeControl = getConditions(controlList).find((v: any) => v.conditionKey === 'parentCode')
|
|
1138
|
+
const someParams: any = {}
|
|
1139
|
+
if (cascadeControl) {
|
|
1140
|
+
const model = getGlobalModel(cascadeControl.id) || {}
|
|
1141
|
+
if (model?.itemCodes) {
|
|
1142
|
+
someParams.parentItemCodes = model.itemCodes
|
|
1143
|
+
} else {
|
|
1144
|
+
return
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
if (type === 'ecanDataSelect') {
|
|
1148
|
+
someParams.indicatorList = indicatorList.filter(v => v.show)
|
|
1149
|
+
}
|
|
1150
|
+
if (source === 'EDV_DATA_SET') {
|
|
1151
|
+
someParams.edvDataSetId = edvDataSetId
|
|
1152
|
+
}
|
|
1153
|
+
resultParams = {
|
|
1154
|
+
url: '/diagram/formData',
|
|
1155
|
+
source,
|
|
1156
|
+
dataViewId,
|
|
1157
|
+
plugin: '4',
|
|
1158
|
+
layer,
|
|
1159
|
+
chartType: 'normalSelect',
|
|
1160
|
+
rangeIndexTypeGuid: typeGuidString,
|
|
1161
|
+
type: type === 'ecanDataSelect' ? 'normalSelectData' : 'normalSelect',
|
|
1162
|
+
labelField: formFields.labelField,
|
|
1163
|
+
valueField: formFields.valueField,
|
|
1164
|
+
sqlConditions,
|
|
1165
|
+
idxLibMode: 'WITH_DATE_DIM_TABLE',
|
|
1166
|
+
keyName: props.keyName,
|
|
1167
|
+
...someParams
|
|
1168
|
+
}
|
|
1169
|
+
} else {
|
|
1170
|
+
let classParams = {}
|
|
1171
|
+
if (lowerCaseIncludes(type, ['scatter', 'valueline'])) {
|
|
1172
|
+
// 散点图多个维度
|
|
1173
|
+
classParams = {
|
|
1174
|
+
classifications
|
|
1175
|
+
}
|
|
1176
|
+
} else {
|
|
1177
|
+
classParams = {
|
|
1178
|
+
classification
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
resultParams = {
|
|
1182
|
+
url: '/diagram',
|
|
1183
|
+
source,
|
|
1184
|
+
dataViewId,
|
|
1185
|
+
plugin: isPivotTable ? '5' : plugin,
|
|
1186
|
+
layer,
|
|
1187
|
+
chartType: isPivotTable ? 'pivot-table' : chartType,
|
|
1188
|
+
series,
|
|
1189
|
+
indicatorList,
|
|
1190
|
+
queryColumns: isGroupTable ? [] : queryColumns,
|
|
1191
|
+
pageFlag: true,
|
|
1192
|
+
edvDataSetId: edvDataSetId || '',
|
|
1193
|
+
sqlConditions: sqlConditions.map(v => {
|
|
1194
|
+
const { fieldValue } = v
|
|
1195
|
+
const params: any = {}
|
|
1196
|
+
if (fieldValue && Array.isArray(fieldValue)) {
|
|
1197
|
+
params.fieldValue = JSON.stringify(fieldValue)
|
|
1198
|
+
}
|
|
1199
|
+
return {
|
|
1200
|
+
...v,
|
|
1201
|
+
...params
|
|
1202
|
+
}
|
|
1203
|
+
}),
|
|
1204
|
+
idxLibMode,
|
|
1205
|
+
preview,
|
|
1206
|
+
rowHeaders,
|
|
1207
|
+
keyName: props.keyName,
|
|
1208
|
+
// 透视表指标排序相关入参
|
|
1209
|
+
columnData: pivotColumnData,
|
|
1210
|
+
columnHeaders: pivotColumnHeader,
|
|
1211
|
+
...classParams,
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
return resultParams
|
|
1215
|
+
}
|