test-chat-sdk 0.0.0
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/.prettierrc.js +24 -0
- package/README.md +46 -0
- package/config/env.js +104 -0
- package/config/getHttpsConfig.js +66 -0
- package/config/jest/babelTransform.js +29 -0
- package/config/jest/cssTransform.js +14 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/modules.js +134 -0
- package/config/paths.js +77 -0
- package/config/webpack/persistentCache/createEnvironmentHash.js +9 -0
- package/config/webpack.config.js +785 -0
- package/config/webpackDevServer.config.js +127 -0
- package/dist/Chat/AgentList/index.d.ts +9 -0
- package/dist/Chat/ChatFooter/index.d.ts +17 -0
- package/dist/Chat/Conversation/index.d.ts +11 -0
- package/dist/Chat/MessageContainer/index.d.ts +19 -0
- package/dist/Chat/MobileAgents/index.d.ts +11 -0
- package/dist/Chat/components/AgentTip/index.d.ts +8 -0
- package/dist/Chat/components/ConversationModal/index.d.ts +10 -0
- package/dist/Chat/components/CopilotAvatar/index.d.ts +2 -0
- package/dist/Chat/components/Message.d.ts +10 -0
- package/dist/Chat/components/RecommendQuestions/index.d.ts +6 -0
- package/dist/Chat/components/Text.d.ts +9 -0
- package/dist/Chat/constants.d.ts +19 -0
- package/dist/Chat/index.d.ts +17 -0
- package/dist/Chat/service.d.ts +11 -0
- package/dist/Chat/type.d.ts +97 -0
- package/dist/Copilot/constants.d.ts +11 -0
- package/dist/Copilot/index.d.ts +13 -0
- package/dist/ShowCase/index.d.ts +8 -0
- package/dist/ShowCase/service.d.ts +2 -0
- package/dist/ShowCase/type.d.ts +11 -0
- package/dist/common/constants.d.ts +58 -0
- package/dist/common/env.d.ts +3 -0
- package/dist/common/type.d.ts +247 -0
- package/dist/components/ChatItem/ExecuteItem.d.ts +25 -0
- package/dist/components/ChatItem/ExpandParseTip.d.ts +20 -0
- package/dist/components/ChatItem/FilterItem.d.ts +17 -0
- package/dist/components/ChatItem/Loading.d.ts +2 -0
- package/dist/components/ChatItem/ParseTip.d.ts +26 -0
- package/dist/components/ChatItem/ParseTipUtils.d.ts +10 -0
- package/dist/components/ChatItem/SimilarQuestionItem.d.ts +10 -0
- package/dist/components/ChatItem/SqlItem.d.ts +17 -0
- package/dist/components/ChatItem/SwitchEntity.d.ts +9 -0
- package/dist/components/ChatItem/Text.d.ts +6 -0
- package/dist/components/ChatItem/Typing.d.ts +2 -0
- package/dist/components/ChatItem/index.d.ts +33 -0
- package/dist/components/ChatMsg/ApplyAuth/index.d.ts +7 -0
- package/dist/components/ChatMsg/Bar/index.d.ts +13 -0
- package/dist/components/ChatMsg/DateOptions/index.d.ts +9 -0
- package/dist/components/ChatMsg/FilterSection/index.d.ts +8 -0
- package/dist/components/ChatMsg/MarkDown/index.d.ts +10 -0
- package/dist/components/ChatMsg/Message/index.d.ts +18 -0
- package/dist/components/ChatMsg/MetricCard/PeriodCompareItem.d.ts +7 -0
- package/dist/components/ChatMsg/MetricCard/index.d.ts +10 -0
- package/dist/components/ChatMsg/MetricTrend/MetricInfo.d.ts +8 -0
- package/dist/components/ChatMsg/MetricTrend/MetricTrendChart.d.ts +14 -0
- package/dist/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.d.ts +12 -0
- package/dist/components/ChatMsg/MetricTrend/index.d.ts +16 -0
- package/dist/components/ChatMsg/NoPermissionChart/index.d.ts +8 -0
- package/dist/components/ChatMsg/Pie/PieChart.d.ts +11 -0
- package/dist/components/ChatMsg/Pie/index.d.ts +14 -0
- package/dist/components/ChatMsg/Table/index.d.ts +12 -0
- package/dist/components/ChatMsg/Text/index.d.ts +9 -0
- package/dist/components/ChatMsg/WebPage/index.d.ts +8 -0
- package/dist/components/ChatMsg/index.d.ts +15 -0
- package/dist/components/DrillDownDimensions/DimensionSection.d.ts +11 -0
- package/dist/components/DrillDownDimensions/index.d.ts +13 -0
- package/dist/components/IconFont/index.d.ts +3 -0
- package/dist/components/MetricOptions/index.d.ts +11 -0
- package/dist/components/RecommendOptions/index.d.ts +9 -0
- package/dist/components/Tools/FeedbackModal.d.ts +9 -0
- package/dist/components/Tools/index.d.ts +12 -0
- package/dist/demo/Chat.d.ts +2 -0
- package/dist/demo/ChatDemo.d.ts +4 -0
- package/dist/demo/CopilotDemo.d.ts +2 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useComposing.d.ts +5 -0
- package/dist/hooks/useExportByEcharts.d.ts +10 -0
- package/dist/hooks/useMethodRegister.d.ts +4 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.es.js +1 -0
- package/dist/service/axiosInstance.d.ts +3 -0
- package/dist/service/index.d.ts +25 -0
- package/dist/utils/utils.d.ts +45 -0
- package/package.json +214 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +43 -0
- package/public/manifest.json +15 -0
- package/public/robots.txt +3 -0
- package/rollup/rollup.config.mjs +37 -0
- package/rollup/rollup.esm.config.mjs +21 -0
- package/rollup/rollup.umd.config.mjs +30 -0
- package/scripts/build.js +217 -0
- package/scripts/start.js +154 -0
- package/scripts/test.js +52 -0
- package/src/Chat/AgentList/index.tsx +52 -0
- package/src/Chat/AgentList/style.module.less +83 -0
- package/src/Chat/ChatFooter/index.tsx +423 -0
- package/src/Chat/ChatFooter/style.module.less +225 -0
- package/src/Chat/Conversation/index.tsx +236 -0
- package/src/Chat/Conversation/style.module.less +171 -0
- package/src/Chat/MessageContainer/index.tsx +145 -0
- package/src/Chat/MessageContainer/style.module.less +53 -0
- package/src/Chat/MobileAgents/index.tsx +62 -0
- package/src/Chat/MobileAgents/style.module.less +55 -0
- package/src/Chat/components/AgentTip/index.tsx +48 -0
- package/src/Chat/components/AgentTip/style.module.less +44 -0
- package/src/Chat/components/ConversationModal/index.tsx +65 -0
- package/src/Chat/components/CopilotAvatar/index.tsx +8 -0
- package/src/Chat/components/CopilotAvatar/style.module.less +13 -0
- package/src/Chat/components/Message.tsx +38 -0
- package/src/Chat/components/RecommendQuestions/index.tsx +64 -0
- package/src/Chat/components/RecommendQuestions/style.module.less +36 -0
- package/src/Chat/components/Text.tsx +42 -0
- package/src/Chat/components/style.module.less +311 -0
- package/src/Chat/constants.ts +37 -0
- package/src/Chat/index.tsx +526 -0
- package/src/Chat/service.ts +49 -0
- package/src/Chat/style.module.less +119 -0
- package/src/Chat/type.ts +107 -0
- package/src/Copilot/constants.ts +11 -0
- package/src/Copilot/index.tsx +149 -0
- package/src/Copilot/style.module.less +151 -0
- package/src/ShowCase/index.tsx +120 -0
- package/src/ShowCase/service.ts +12 -0
- package/src/ShowCase/style.module.less +46 -0
- package/src/ShowCase/type.ts +14 -0
- package/src/common/constants.ts +93 -0
- package/src/common/env.ts +5 -0
- package/src/common/type.ts +270 -0
- package/src/components/ChatItem/ExecuteItem.tsx +210 -0
- package/src/components/ChatItem/ExpandParseTip.tsx +333 -0
- package/src/components/ChatItem/FilterItem.tsx +209 -0
- package/src/components/ChatItem/Loading.tsx +14 -0
- package/src/components/ChatItem/ParseTip.tsx +322 -0
- package/src/components/ChatItem/ParseTipUtils.tsx +205 -0
- package/src/components/ChatItem/SimilarQuestionItem.tsx +84 -0
- package/src/components/ChatItem/SqlItem.tsx +410 -0
- package/src/components/ChatItem/SwitchEntity.tsx +52 -0
- package/src/components/ChatItem/Text.tsx +17 -0
- package/src/components/ChatItem/Typing.tsx +19 -0
- package/src/components/ChatItem/index.tsx +843 -0
- package/src/components/ChatItem/style.less +670 -0
- package/src/components/ChatMsg/ApplyAuth/index.tsx +30 -0
- package/src/components/ChatMsg/ApplyAuth/style.less +13 -0
- package/src/components/ChatMsg/Bar/index.tsx +208 -0
- package/src/components/ChatMsg/Bar/style.less +60 -0
- package/src/components/ChatMsg/DateOptions/index.tsx +46 -0
- package/src/components/ChatMsg/DateOptions/style.less +43 -0
- package/src/components/ChatMsg/FilterSection/index.tsx +42 -0
- package/src/components/ChatMsg/FilterSection/style.less +37 -0
- package/src/components/ChatMsg/MarkDown/index.tsx +26 -0
- package/src/components/ChatMsg/MarkDown/style.less +9 -0
- package/src/components/ChatMsg/Message/index.tsx +105 -0
- package/src/components/ChatMsg/Message/style.less +119 -0
- package/src/components/ChatMsg/MetricCard/PeriodCompareItem.tsx +29 -0
- package/src/components/ChatMsg/MetricCard/index.tsx +80 -0
- package/src/components/ChatMsg/MetricCard/style.less +126 -0
- package/src/components/ChatMsg/MetricTrend/MetricInfo.tsx +60 -0
- package/src/components/ChatMsg/MetricTrend/MetricTrendChart.tsx +235 -0
- package/src/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.tsx +162 -0
- package/src/components/ChatMsg/MetricTrend/index.tsx +127 -0
- package/src/components/ChatMsg/MetricTrend/style.less +195 -0
- package/src/components/ChatMsg/NoPermissionChart/index.tsx +28 -0
- package/src/components/ChatMsg/NoPermissionChart/style.less +26 -0
- package/src/components/ChatMsg/Pie/PieChart.tsx +120 -0
- package/src/components/ChatMsg/Pie/index.tsx +88 -0
- package/src/components/ChatMsg/Pie/style.less +43 -0
- package/src/components/ChatMsg/Table/index.tsx +103 -0
- package/src/components/ChatMsg/Table/style.less +131 -0
- package/src/components/ChatMsg/Text/index.tsx +70 -0
- package/src/components/ChatMsg/Text/style.less +38 -0
- package/src/components/ChatMsg/WebPage/index.tsx +125 -0
- package/src/components/ChatMsg/index.tsx +428 -0
- package/src/components/ChatMsg/style.less +28 -0
- package/src/components/DrillDownDimensions/DimensionSection.tsx +99 -0
- package/src/components/DrillDownDimensions/index.tsx +76 -0
- package/src/components/DrillDownDimensions/style.less +64 -0
- package/src/components/IconFont/index.tsx +7 -0
- package/src/components/MetricOptions/index.tsx +75 -0
- package/src/components/MetricOptions/style.less +69 -0
- package/src/components/RecommendOptions/index.tsx +126 -0
- package/src/components/RecommendOptions/style.less +24 -0
- package/src/components/Tools/FeedbackModal.tsx +55 -0
- package/src/components/Tools/index.tsx +126 -0
- package/src/components/Tools/style.less +67 -0
- package/src/demo/Chat.tsx +73 -0
- package/src/demo/ChatDemo.tsx +14 -0
- package/src/demo/CopilotDemo.tsx +43 -0
- package/src/demo/style.module.less +19 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useComposing.ts +31 -0
- package/src/hooks/useExportByEcharts.ts +41 -0
- package/src/hooks/useMethodRegister.ts +25 -0
- package/src/index.tsx +44 -0
- package/src/service/axiosInstance.ts +58 -0
- package/src/service/index.ts +174 -0
- package/src/setupProxy.js +18 -0
- package/src/setupTests.ts +5 -0
- package/src/styles/global.less +52 -0
- package/src/styles/index.less +39 -0
- package/src/styles/reboot.less +14 -0
- package/src/styles/variables.less +80 -0
- package/src/typings.d.ts +179 -0
- package/src/utils/utils.ts +346 -0
- package/tsconfig.build.json +20 -0
- package/tsconfig.json +27 -0
package/src/typings.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
declare module 'slash2';
|
|
2
|
+
declare module '*.css';
|
|
3
|
+
declare module '*.less';
|
|
4
|
+
declare module '*.module.less';
|
|
5
|
+
declare module '*.scss';
|
|
6
|
+
declare module '*.sass';
|
|
7
|
+
declare module '*.svg';
|
|
8
|
+
declare module '*.png';
|
|
9
|
+
declare module '*.jpg';
|
|
10
|
+
declare module '*.jpeg';
|
|
11
|
+
declare module '*.gif';
|
|
12
|
+
declare module '*.bmp';
|
|
13
|
+
declare module '*.tiff';
|
|
14
|
+
declare module 'omit.js';
|
|
15
|
+
declare module 'numeral';
|
|
16
|
+
declare module '@antv/data-set';
|
|
17
|
+
declare module 'mockjs';
|
|
18
|
+
declare module 'react-fittext';
|
|
19
|
+
declare module 'bizcharts-plugin-slider';
|
|
20
|
+
declare module 'react-split-pane/lib/Pane';
|
|
21
|
+
|
|
22
|
+
declare const REACT_APP_ENV: 'test' | 'dev' | 'pre' | false;
|
|
23
|
+
|
|
24
|
+
declare module '*.module.less' {
|
|
25
|
+
const classes: {
|
|
26
|
+
readonly [key: string]: string
|
|
27
|
+
}
|
|
28
|
+
export default classes
|
|
29
|
+
declare module '*.less'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface AxiosResponse<T = any> extends Promise<T> {
|
|
33
|
+
code: number;
|
|
34
|
+
data: T;
|
|
35
|
+
msg: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type Result<T> = {
|
|
39
|
+
code: number;
|
|
40
|
+
data: T;
|
|
41
|
+
msg: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type DavinciResponseHeader = {
|
|
45
|
+
code: number;
|
|
46
|
+
msg: string;
|
|
47
|
+
token: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type DavinciResponse<T> = {
|
|
51
|
+
header: DavinciResponseHeader;
|
|
52
|
+
payload: T;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// 达芬奇接口返回的参数格式
|
|
56
|
+
type DavinciResult<T> = {
|
|
57
|
+
payload: T;
|
|
58
|
+
header: {
|
|
59
|
+
msg: string;
|
|
60
|
+
code: number;
|
|
61
|
+
token: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// 新请求器下的超音数分页接口声明泛型
|
|
66
|
+
type TPaginationResponse<T> = {
|
|
67
|
+
content: T[];
|
|
68
|
+
current: number;
|
|
69
|
+
pageSize: number;
|
|
70
|
+
total: number;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type DavinciPaginationResponse<T> = DavinciResult<{
|
|
74
|
+
resultList: T[];
|
|
75
|
+
pageNo: number;
|
|
76
|
+
pageSize: number;
|
|
77
|
+
totalCount: number;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
}>;
|
|
80
|
+
|
|
81
|
+
type BDResponse<T> = {
|
|
82
|
+
code: string;
|
|
83
|
+
data: T;
|
|
84
|
+
msg: string;
|
|
85
|
+
traceId: string;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
type TopNConfig = {
|
|
89
|
+
computeType: 'field' | 'dimension';
|
|
90
|
+
column: string;
|
|
91
|
+
direction: 'asc' | 'desc';
|
|
92
|
+
limit: number;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
type ColumnType = {
|
|
96
|
+
name: string;
|
|
97
|
+
nameEn: string;
|
|
98
|
+
type: string;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
type DataType = {
|
|
102
|
+
columns: ColumnType[];
|
|
103
|
+
pageNo: number;
|
|
104
|
+
pageSize: number;
|
|
105
|
+
totalCount: number;
|
|
106
|
+
resultList: any[];
|
|
107
|
+
sqlToExec: string;
|
|
108
|
+
timeUsed: number;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
type QueryVariable = { name: string; value: string | number }[];
|
|
112
|
+
|
|
113
|
+
type GetDataParams = {
|
|
114
|
+
groups: string[];
|
|
115
|
+
aggregators: { column: string; func: string }[];
|
|
116
|
+
filters: any[];
|
|
117
|
+
params?: QueryVariable;
|
|
118
|
+
orders?: { column: string; direction?: string; sortList?: string[] }[];
|
|
119
|
+
limit: number;
|
|
120
|
+
cache: boolean;
|
|
121
|
+
expired: number;
|
|
122
|
+
flush: boolean;
|
|
123
|
+
pageNo?: number;
|
|
124
|
+
pageSize?: number;
|
|
125
|
+
nativeQuery: boolean;
|
|
126
|
+
topN?: TopNConfig;
|
|
127
|
+
classId?: number;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
type ReportEventParams = {
|
|
131
|
+
event: string;
|
|
132
|
+
dt_pgid?: string;
|
|
133
|
+
page_title: string;
|
|
134
|
+
page_path?: string;
|
|
135
|
+
entity_id?: string | number;
|
|
136
|
+
singer_id?: number;
|
|
137
|
+
producer?: string;
|
|
138
|
+
ip?: string;
|
|
139
|
+
song_id?: number;
|
|
140
|
+
album_id?: number;
|
|
141
|
+
brand_id?: number;
|
|
142
|
+
company_id?: number;
|
|
143
|
+
song_ids?: string;
|
|
144
|
+
compare_Ids?: string;
|
|
145
|
+
element_name?: string;
|
|
146
|
+
entrance_name?: string;
|
|
147
|
+
category_id?: string;
|
|
148
|
+
category_type?: string;
|
|
149
|
+
conversation_name?: string;
|
|
150
|
+
msg?: string;
|
|
151
|
+
msg_type?: string;
|
|
152
|
+
search_value?: string;
|
|
153
|
+
[key: string]: string | number;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
type RowSpanMapIndexItem = number[];
|
|
157
|
+
type RowSpanMap = Record<string, RowSpanMapIndexItem>;
|
|
158
|
+
|
|
159
|
+
type Pagination = {
|
|
160
|
+
current?: number;
|
|
161
|
+
pageSize?: number;
|
|
162
|
+
sort?: string;
|
|
163
|
+
orderCondition?: string;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
type PromiseSettledItem = {
|
|
167
|
+
status: string;
|
|
168
|
+
value?: any;
|
|
169
|
+
reason?: any;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
type PromiseSettledList = PromiseSettledItem[];
|
|
173
|
+
|
|
174
|
+
type PaginationResponse<T> = Result<{
|
|
175
|
+
content: T[];
|
|
176
|
+
current: number;
|
|
177
|
+
pageSize: number;
|
|
178
|
+
total: number;
|
|
179
|
+
}>;
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import moment, { Moment } from 'moment';
|
|
2
|
+
import { NumericUnit } from '../common/constants';
|
|
3
|
+
import { isString } from 'lodash';
|
|
4
|
+
import { ColumnType } from '../common/type';
|
|
5
|
+
|
|
6
|
+
export function formatByDataFormatType(value: number | string, type: ColumnType['dataFormatType'], dataFormat: Partial<ColumnType['dataFormat']> = {}) {
|
|
7
|
+
return `${formatByDecimalPlaces(dataFormat?.needMultiply100 ? +value * 100 : value, dataFormat?.decimalPlaces || 2)}${type === 'percent' ? '%' : ''}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function formatByDecimalPlaces(value: number | string, decimalPlaces: number) {
|
|
11
|
+
if (value === null || value === undefined || value === '') {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
if (isNaN(+value) || decimalPlaces < 0 || decimalPlaces > 100) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
let strValue = (+value).toFixed(decimalPlaces);
|
|
18
|
+
if (!/^-?[0-9.]+$/g.test(strValue)) {
|
|
19
|
+
return '0';
|
|
20
|
+
}
|
|
21
|
+
while (strValue.includes('.') && (strValue.endsWith('.') || strValue.endsWith('0'))) {
|
|
22
|
+
strValue = strValue.slice(0, -1);
|
|
23
|
+
}
|
|
24
|
+
return strValue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function formatByThousandSeperator(value: number | string) {
|
|
28
|
+
if (value === null || value === undefined || value === '') {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
if (isNaN(+value)) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
const partValues = value.toString().split('.');
|
|
35
|
+
partValues[0] = partValues[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
36
|
+
return partValues.join('.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function formatMetric(value: number | string) {
|
|
40
|
+
return formatByThousandSeperator(formatByDecimalPlaces(value, 4));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function formatByUnit(value: number | string, unit: NumericUnit) {
|
|
44
|
+
const numericValue = +value;
|
|
45
|
+
if (isNaN(numericValue) || unit === NumericUnit.None) {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
let exponentValue = 0;
|
|
49
|
+
switch (unit) {
|
|
50
|
+
case NumericUnit.TenThousand:
|
|
51
|
+
case NumericUnit.EnTenThousand:
|
|
52
|
+
exponentValue = 4;
|
|
53
|
+
break;
|
|
54
|
+
case NumericUnit.OneHundredMillion:
|
|
55
|
+
exponentValue = 8;
|
|
56
|
+
break;
|
|
57
|
+
case NumericUnit.Thousand:
|
|
58
|
+
exponentValue = 3;
|
|
59
|
+
break;
|
|
60
|
+
case NumericUnit.Million:
|
|
61
|
+
exponentValue = 6;
|
|
62
|
+
break;
|
|
63
|
+
case NumericUnit.Giga:
|
|
64
|
+
exponentValue = 9;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return numericValue / Math.pow(10, exponentValue);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const getFormattedValue = (value: number | string, remainZero?: boolean) => {
|
|
71
|
+
if (remainZero && (value === undefined || +value === 0)) {
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
if (value === undefined) {
|
|
75
|
+
return '-';
|
|
76
|
+
}
|
|
77
|
+
if (!isFinite(+value)) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const absNumericValue = Math.abs(+value);
|
|
82
|
+
|
|
83
|
+
const unit =
|
|
84
|
+
absNumericValue >= 100000000
|
|
85
|
+
? NumericUnit.OneHundredMillion
|
|
86
|
+
: absNumericValue >= 10000
|
|
87
|
+
? NumericUnit.TenThousand
|
|
88
|
+
: NumericUnit.None;
|
|
89
|
+
|
|
90
|
+
let formattedValue = formatByUnit(value, unit);
|
|
91
|
+
formattedValue = formatByDecimalPlaces(
|
|
92
|
+
formattedValue,
|
|
93
|
+
unit === NumericUnit.OneHundredMillion ? 2 : absNumericValue < 1 ? 3 : 1
|
|
94
|
+
);
|
|
95
|
+
formattedValue = formatByThousandSeperator(formattedValue);
|
|
96
|
+
if ((typeof formattedValue === 'number' && isNaN(formattedValue)) || +formattedValue === 0) {
|
|
97
|
+
return '-';
|
|
98
|
+
}
|
|
99
|
+
return `${formattedValue}${unit === NumericUnit.None ? '' : unit}`;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const formatNumberWithCN = (num: number) => {
|
|
103
|
+
if (isNaN(num)) return '-';
|
|
104
|
+
if (Math.abs(+num) >= 10000) {
|
|
105
|
+
return (num / 10000).toFixed(1) + '万';
|
|
106
|
+
} else {
|
|
107
|
+
return formatByDecimalPlaces(num, 2);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const groupByColumn = (data: any[], column: string) => {
|
|
112
|
+
return data.reduce((result, item) => {
|
|
113
|
+
const resultData = { ...result };
|
|
114
|
+
const key = item[column];
|
|
115
|
+
if (!resultData[key]) {
|
|
116
|
+
resultData[key] = [];
|
|
117
|
+
}
|
|
118
|
+
resultData[key].push(item);
|
|
119
|
+
return resultData;
|
|
120
|
+
}, {});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// 获取任意两个日期中的所有日期
|
|
124
|
+
export function enumerateDaysBetweenDates(startDate: Moment, endDate: Moment, dateType?: any) {
|
|
125
|
+
let daysList: any[] = [];
|
|
126
|
+
const day = endDate.diff(startDate, dateType || 'days');
|
|
127
|
+
const format = dateType === 'months' ? 'YYYY-MM' : 'YYYY-MM-DD';
|
|
128
|
+
daysList.push(startDate.format(format));
|
|
129
|
+
for (let i = 1; i <= day; i++) {
|
|
130
|
+
daysList.push(startDate.add(1, dateType || 'days').format(format));
|
|
131
|
+
}
|
|
132
|
+
return daysList;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const normalizeTrendData = (
|
|
136
|
+
resultList: any[],
|
|
137
|
+
dateColumnName: string,
|
|
138
|
+
valueColumnName: string,
|
|
139
|
+
startDate: string,
|
|
140
|
+
endDate: string,
|
|
141
|
+
dateType?: string
|
|
142
|
+
) => {
|
|
143
|
+
const dateList = enumerateDaysBetweenDates(moment(startDate), moment(endDate), dateType);
|
|
144
|
+
const result = dateList.map(date => {
|
|
145
|
+
const item = resultList.find(
|
|
146
|
+
result =>
|
|
147
|
+
moment(result[dateColumnName]).format(dateType === 'months' ? 'YYYY-MM' : 'YYYY-MM-DD') ===
|
|
148
|
+
date
|
|
149
|
+
);
|
|
150
|
+
return {
|
|
151
|
+
...(item || {}),
|
|
152
|
+
[dateColumnName]: date,
|
|
153
|
+
[valueColumnName]: item ? item[valueColumnName] : 0,
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
return result;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const getMinMaxDate = (resultList: any[], dateColumnName: string) => {
|
|
160
|
+
const dateList = resultList.map(item => moment(item[dateColumnName]));
|
|
161
|
+
return [moment.min(dateList).format('YYYY-MM-DD'), moment.max(dateList).format('YYYY-MM-DD')];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export function hexToRgbObj(hex) {
|
|
165
|
+
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
166
|
+
return result
|
|
167
|
+
? {
|
|
168
|
+
r: parseInt(result[1], 16),
|
|
169
|
+
g: parseInt(result[2], 16),
|
|
170
|
+
b: parseInt(result[3], 16),
|
|
171
|
+
}
|
|
172
|
+
: null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function getLightenDarkenColor(col, amt) {
|
|
176
|
+
let result;
|
|
177
|
+
if (col?.includes('rgb')) {
|
|
178
|
+
const [r, g, b, a] = col.match(/\d+/g).map(Number);
|
|
179
|
+
result = { r, g, b, a };
|
|
180
|
+
} else {
|
|
181
|
+
result = hexToRgbObj(col) || {};
|
|
182
|
+
}
|
|
183
|
+
return `rgba(${result.r + amt},${result.g + amt},${result.b + amt}${
|
|
184
|
+
result.a ? `,${result.a}` : ''
|
|
185
|
+
})`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function getChartLightenColor(col) {
|
|
189
|
+
return getLightenDarkenColor(col, 80);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const isMobile = window.navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i);
|
|
193
|
+
|
|
194
|
+
export const isIOS = window.navigator.userAgent.match(/(iPhone|iPod|ios)/i);
|
|
195
|
+
|
|
196
|
+
export const isAndroid = window.navigator.userAgent.match(/(Android)/i);
|
|
197
|
+
|
|
198
|
+
export function isProd() {
|
|
199
|
+
return process.env.NODE_ENV === 'production';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function setToken(token: string) {
|
|
203
|
+
localStorage.setItem('SUPERSONIC_TOKEN', token);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function getToken() {
|
|
207
|
+
return localStorage.getItem('SUPERSONIC_TOKEN');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export const updateMessageContainerScroll = (nodeId?: string) => {
|
|
211
|
+
setTimeout(() => {
|
|
212
|
+
const ele: any = document.getElementById('messageContainer');
|
|
213
|
+
if (ele && ele.scrollHeight > ele.clientHeight) {
|
|
214
|
+
if (nodeId) {
|
|
215
|
+
const node = document.getElementById(nodeId);
|
|
216
|
+
if (node) {
|
|
217
|
+
ele.scrollTop = ele.scrollHeight - node.clientHeight - 130;
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
ele.scrollTop = ele.scrollHeight;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}, 100);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* UUID生成器
|
|
228
|
+
* @param len 长度 number
|
|
229
|
+
* @param radix 随机数基数 number
|
|
230
|
+
* @returns {string}
|
|
231
|
+
*/
|
|
232
|
+
export const uuid = (len: number = 8, radix: number = 62) => {
|
|
233
|
+
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
|
234
|
+
const uuid: string[] = [];
|
|
235
|
+
let i;
|
|
236
|
+
|
|
237
|
+
if (len) {
|
|
238
|
+
// Compact form
|
|
239
|
+
for (i = 0; i < len; i++) {
|
|
240
|
+
uuid[i] = chars[Math.floor(Math.random() * radix)];
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
// rfc4122, version 4 form
|
|
244
|
+
let r;
|
|
245
|
+
|
|
246
|
+
// rfc4122 requires these characters
|
|
247
|
+
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
|
248
|
+
uuid[14] = '4';
|
|
249
|
+
|
|
250
|
+
// Fill in random data. At i==19 set the high bits of clock sequence as
|
|
251
|
+
// per rfc4122, sec. 4.1.5
|
|
252
|
+
for (i = 0; i < 36; i++) {
|
|
253
|
+
if (!uuid[i]) {
|
|
254
|
+
r = Math.floor(Math.random() * 16);
|
|
255
|
+
uuid[i] = chars[i === 19 ? ((r % 4) % 8) + 8 : r];
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return uuid.join('');
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
let utilCanvas: any = null;
|
|
263
|
+
|
|
264
|
+
export const getTextWidth = (
|
|
265
|
+
text: string,
|
|
266
|
+
fontSize: string = '16px',
|
|
267
|
+
fontWeight: string = 'normal',
|
|
268
|
+
fontFamily: string = 'DINPro Medium'
|
|
269
|
+
): number => {
|
|
270
|
+
const canvas = utilCanvas || (utilCanvas = document.createElement('canvas'));
|
|
271
|
+
const context = canvas.getContext('2d');
|
|
272
|
+
context.font = `${fontWeight} ${fontSize} ${fontFamily}`;
|
|
273
|
+
const metrics = context.measureText(text);
|
|
274
|
+
return Math.ceil(metrics.width);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export function jsonParse(config: any, defaultReturn?: any) {
|
|
278
|
+
if (!isString(config)) {
|
|
279
|
+
return config;
|
|
280
|
+
}
|
|
281
|
+
if (!config) {
|
|
282
|
+
return defaultReturn;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
return JSON.parse(config);
|
|
286
|
+
} catch (error) {
|
|
287
|
+
console.log(error);
|
|
288
|
+
return defaultReturn;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* 导出文本文件的函数
|
|
294
|
+
* @param content - 要导出的文本内容
|
|
295
|
+
* @param fileName - 导出的文件名
|
|
296
|
+
* @param mimeType - 文件的 MIME 类型,默认为 'text/plain'
|
|
297
|
+
*/
|
|
298
|
+
export function exportTextFile(content: string, fileName: string, mimeType: string = 'text/plain') {
|
|
299
|
+
// 创建一个 Blob 对象
|
|
300
|
+
const blob = new Blob([content], { type: mimeType });
|
|
301
|
+
|
|
302
|
+
// 创建一个 URL 对象
|
|
303
|
+
const url = URL.createObjectURL(blob);
|
|
304
|
+
|
|
305
|
+
// 创建一个 <a> 元素
|
|
306
|
+
const a = document.createElement('a');
|
|
307
|
+
a.href = url;
|
|
308
|
+
a.download = fileName;
|
|
309
|
+
|
|
310
|
+
// 触发下载
|
|
311
|
+
document.body.appendChild(a);
|
|
312
|
+
a.click();
|
|
313
|
+
|
|
314
|
+
// 移除 <a> 元素
|
|
315
|
+
document.body.removeChild(a);
|
|
316
|
+
|
|
317
|
+
// 释放 URL 对象
|
|
318
|
+
URL.revokeObjectURL(url);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function replacer(key: string, value: any) {
|
|
322
|
+
return value === null ? '' : value; // 将null值转换为空字符串
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function exportCsvFile(data: any[]) {
|
|
326
|
+
// 生成CSV内容
|
|
327
|
+
const csvRows: any[] = [];
|
|
328
|
+
const headers = Object.keys(data[0]);
|
|
329
|
+
csvRows.push(headers.join(',')); // 添加表头
|
|
330
|
+
|
|
331
|
+
for (const row of data) {
|
|
332
|
+
csvRows.push(headers.map(header => JSON.stringify(row[header], replacer)).join(','));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 创建Blob并下载文件
|
|
336
|
+
const csvString = '\ufeff' + csvRows.join('\n');
|
|
337
|
+
const blob = new Blob([csvString], { type: 'text/csv;charset=utf-8;' });
|
|
338
|
+
const url = window.URL.createObjectURL(blob);
|
|
339
|
+
const a = document.createElement('a');
|
|
340
|
+
a.href = url;
|
|
341
|
+
a.download = 'data.csv'; // 指定下载文件名
|
|
342
|
+
document.body.appendChild(a);
|
|
343
|
+
a.click();
|
|
344
|
+
a.remove();
|
|
345
|
+
window.URL.revokeObjectURL(url); // 释放Blob URL
|
|
346
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"target": "es5",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"moduleResolution":"Node",
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
10
|
+
"importHelpers": true,
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"exclude": [
|
|
16
|
+
"src/**/*.test.tsx",
|
|
17
|
+
"src/**/*.stories.tsx",
|
|
18
|
+
"src/setupTests.ts",
|
|
19
|
+
]
|
|
20
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
"jsx": "react-jsx",
|
|
22
|
+
"noImplicitAny": false,
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"src"
|
|
26
|
+
]
|
|
27
|
+
}
|