@ecan-bi/tools 1.0.7 → 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/dist/index.es.js +1740 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +6 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +26 -5
- package/types/hooks/useTransformChartDataByAttrKey.d.ts +25 -0
- package/types/hooks/useTransformChartDataByAttrValue.d.ts +23 -0
- package/types/hooks/useValueFormatter.d.ts +2 -0
- package/types/hooks/useVariablesInText.d.ts +12 -0
- package/types/index.d.ts +53 -0
- package/types/indicator.d.ts +4 -0
- package/types/utils/constant.d.ts +1 -0
- package/types/utils/runCode.d.ts +4 -0
- package/types/utils/transformProps.d.ts +21 -0
- package/types/utils/util.d.ts +31 -0
- package/.babelrc +0 -8
- package/index.js +0 -35
- package/src/hooks/useTransformChartDataByAttrKey.ts +0 -77
- package/src/hooks/useTransformChartDataByAttrValue.ts +0 -61
- package/src/hooks/useValueFormatter.js +0 -28
- package/src/hooks/useVariablesInText.ts +0 -44
- package/src/indicator.ts +0 -1228
- package/src/utils/constant.ts +0 -1
- package/src/utils/runCode.ts +0 -26
- package/src/utils/transformProps.ts +0 -901
- package/src/utils/util.ts +0 -192
package/src/utils/util.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import useVariablesInText from '../hooks/useVariablesInText'
|
|
2
|
-
import { unref } from 'vue'
|
|
3
|
-
/**
|
|
4
|
-
* 字符串1 中是否包含 字符串2 (会全部转成小写)
|
|
5
|
-
* @param v1 字符串1
|
|
6
|
-
* @param v2 字符串2
|
|
7
|
-
* @constructor
|
|
8
|
-
*/
|
|
9
|
-
export const lowerCaseIncludes = (v1:any, v2:any): boolean => {
|
|
10
|
-
if (typeof v1 === 'string' && typeof v2 === 'string') {
|
|
11
|
-
return v1.toLocaleLowerCase().includes(v2.toLocaleLowerCase())
|
|
12
|
-
} else if (typeof v1 === 'string' && Array.isArray(v2)) {
|
|
13
|
-
const len = v2.length
|
|
14
|
-
for (let i = 0; i < len; i++) {
|
|
15
|
-
const s = v2[i]
|
|
16
|
-
if (typeof s === 'string' && v1.toLocaleLowerCase().includes(s.toLocaleLowerCase())) {
|
|
17
|
-
return true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return false
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 判断 key 是否在对象上
|
|
26
|
-
* @param v
|
|
27
|
-
* @param k
|
|
28
|
-
*/
|
|
29
|
-
export const hasOwn = (v: object, k: string | symbol): k is keyof typeof v => Object.prototype.hasOwnProperty.call(v, k)
|
|
30
|
-
|
|
31
|
-
export const getConditions = (conditions) => {
|
|
32
|
-
const result: any = []
|
|
33
|
-
for (const item of conditions) {
|
|
34
|
-
if (item.conditions) {
|
|
35
|
-
result.push(...getConditions(item.conditions))
|
|
36
|
-
} else if (item?.dataType === 'component') {
|
|
37
|
-
result.push(item)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return result
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function getFormatStep (format: string) {
|
|
44
|
-
const value = format.split('-')
|
|
45
|
-
let formatStep = ''
|
|
46
|
-
if (value?.length) {
|
|
47
|
-
switch (value[value.length - 1]) {
|
|
48
|
-
case 'YYYY':
|
|
49
|
-
formatStep = 'year'
|
|
50
|
-
break
|
|
51
|
-
case 'MM':
|
|
52
|
-
formatStep = 'month'
|
|
53
|
-
break
|
|
54
|
-
case 'DD':
|
|
55
|
-
formatStep = 'day'
|
|
56
|
-
break
|
|
57
|
-
default:
|
|
58
|
-
break
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return formatStep
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const handleFormatter = (formatter: string) => {
|
|
65
|
-
return formatter.replace(/\\n/g, '\n')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 图表的图例格式化
|
|
70
|
-
* @param format 表达式
|
|
71
|
-
* @param textData 传入参数
|
|
72
|
-
* @returns 显示的图例文本
|
|
73
|
-
*/
|
|
74
|
-
export const getLegendFormat = (format: string = '', textData: any) => {
|
|
75
|
-
const variables = format.match(/\{(.+?)\}/g)
|
|
76
|
-
// 换行符个数
|
|
77
|
-
const lineBreakCount = format.split('\n')?.length - 1
|
|
78
|
-
let lineBreakStr = ''
|
|
79
|
-
if (lineBreakCount) {
|
|
80
|
-
for (let i = 0; i < lineBreakCount; i++) {
|
|
81
|
-
lineBreakStr += '\n'
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
let text = format
|
|
85
|
-
if (variables?.length) {
|
|
86
|
-
for (const item of variables) {
|
|
87
|
-
const str = useVariablesInText(
|
|
88
|
-
item,
|
|
89
|
-
{
|
|
90
|
-
textData
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
useNewline: false,
|
|
94
|
-
useSpace: false
|
|
95
|
-
}
|
|
96
|
-
)
|
|
97
|
-
if (str) {
|
|
98
|
-
text = text.replace(item, str)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return `${lineBreakStr}{text|${text}}`
|
|
102
|
-
} else {
|
|
103
|
-
return format
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// 千分位转换
|
|
108
|
-
export function formatQfw (str: string) {
|
|
109
|
-
let result = ''
|
|
110
|
-
let str1 = ''
|
|
111
|
-
let str2 = ''
|
|
112
|
-
let value = ''
|
|
113
|
-
if (str.indexOf('.') > -1) {
|
|
114
|
-
str1 = str.split('.')[0] // 千分位处理部分
|
|
115
|
-
str2 = str.split('.')[1] // 小数值
|
|
116
|
-
} else {
|
|
117
|
-
str1 = str
|
|
118
|
-
}
|
|
119
|
-
let index = 0
|
|
120
|
-
let len = 0
|
|
121
|
-
len = str1.length - 1
|
|
122
|
-
while (len >= 0) {
|
|
123
|
-
index % 3 === 0 && index !== 0
|
|
124
|
-
? str1[len] === '-'
|
|
125
|
-
? (result += str1[len])
|
|
126
|
-
: (result += ',' + str1[len])
|
|
127
|
-
: (result += str1[len])
|
|
128
|
-
len--
|
|
129
|
-
index++
|
|
130
|
-
}
|
|
131
|
-
result = result
|
|
132
|
-
.split('')
|
|
133
|
-
.reverse()
|
|
134
|
-
.join('')
|
|
135
|
-
if (str.indexOf('.') > -1) {
|
|
136
|
-
value = result + '.' + str2
|
|
137
|
-
} else {
|
|
138
|
-
value = result
|
|
139
|
-
}
|
|
140
|
-
return value
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 根据指标获取其他参数-用于条件查询
|
|
144
|
-
export async function getIndicatorParams ({ graphicConfig, request, INDICATOR_URL = '', PAGE_ID, dataSourceId }) {
|
|
145
|
-
try {
|
|
146
|
-
const { leftAxisList = [], rightAxisList = [], queryColumnList = [], indicators = [] } = unref(graphicConfig)
|
|
147
|
-
const otherList = [...leftAxisList, ...rightAxisList, ...queryColumnList, ...indicators]
|
|
148
|
-
const idMap: any = {}
|
|
149
|
-
for (const item of otherList) {
|
|
150
|
-
const { indexCode = '', parentId = '' } = item
|
|
151
|
-
if (parentId && !hasOwn(item, 'calcType') && !idMap[parentId]) {
|
|
152
|
-
idMap[parentId] = indexCode
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (Object.keys(idMap)?.length) {
|
|
156
|
-
const promiseList: any = []
|
|
157
|
-
for (const id in idMap) {
|
|
158
|
-
promiseList.push(
|
|
159
|
-
new Promise((resolve, reject) => {
|
|
160
|
-
request
|
|
161
|
-
.post(
|
|
162
|
-
`${INDICATOR_URL}/diagram/hrpIndexWithComplex`,
|
|
163
|
-
{
|
|
164
|
-
pageId: PAGE_ID,
|
|
165
|
-
indexGuid: id,
|
|
166
|
-
indexCode: idMap[id],
|
|
167
|
-
dataSourceId
|
|
168
|
-
}
|
|
169
|
-
)
|
|
170
|
-
.then((res: any) => {
|
|
171
|
-
const { success, data = [] } = res.data
|
|
172
|
-
if (success && data?.dataViewColumns?.length) {
|
|
173
|
-
resolve(data.dataViewColumns)
|
|
174
|
-
} else {
|
|
175
|
-
reject(data)
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
.catch((e) => {
|
|
179
|
-
reject(e)
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
)
|
|
183
|
-
}
|
|
184
|
-
const res = await Promise.all(promiseList)
|
|
185
|
-
const resultList = res.reduce((a: any, b: any) =>
|
|
186
|
-
a.filter((c: any) => b.find((v: any) => v.typeGuid === c.typeGuid))
|
|
187
|
-
)
|
|
188
|
-
return resultList.filter((v: any) => v.typeGuid)
|
|
189
|
-
}
|
|
190
|
-
} catch (err) { }
|
|
191
|
-
return ([])
|
|
192
|
-
}
|