prod-test-chat-sdk 0.0.1

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.
Files changed (208) hide show
  1. package/.prettierrc.js +24 -0
  2. package/README.md +46 -0
  3. package/config/env.js +104 -0
  4. package/config/getHttpsConfig.js +66 -0
  5. package/config/jest/babelTransform.js +29 -0
  6. package/config/jest/cssTransform.js +14 -0
  7. package/config/jest/fileTransform.js +40 -0
  8. package/config/modules.js +134 -0
  9. package/config/paths.js +77 -0
  10. package/config/webpack/persistentCache/createEnvironmentHash.js +9 -0
  11. package/config/webpack.config.js +785 -0
  12. package/config/webpackDevServer.config.js +127 -0
  13. package/dist/Chat/AgentList/index.d.ts +9 -0
  14. package/dist/Chat/ChatFooter/index.d.ts +17 -0
  15. package/dist/Chat/Conversation/index.d.ts +11 -0
  16. package/dist/Chat/MessageContainer/index.d.ts +19 -0
  17. package/dist/Chat/MobileAgents/index.d.ts +11 -0
  18. package/dist/Chat/components/AgentTip/index.d.ts +8 -0
  19. package/dist/Chat/components/ConversationModal/index.d.ts +10 -0
  20. package/dist/Chat/components/CopilotAvatar/index.d.ts +2 -0
  21. package/dist/Chat/components/Message.d.ts +10 -0
  22. package/dist/Chat/components/RecommendQuestions/index.d.ts +6 -0
  23. package/dist/Chat/components/Text.d.ts +9 -0
  24. package/dist/Chat/constants.d.ts +19 -0
  25. package/dist/Chat/index.d.ts +17 -0
  26. package/dist/Chat/service.d.ts +11 -0
  27. package/dist/Chat/type.d.ts +97 -0
  28. package/dist/Copilot/constants.d.ts +11 -0
  29. package/dist/Copilot/index.d.ts +13 -0
  30. package/dist/ShowCase/index.d.ts +8 -0
  31. package/dist/ShowCase/service.d.ts +2 -0
  32. package/dist/ShowCase/type.d.ts +11 -0
  33. package/dist/common/constants.d.ts +58 -0
  34. package/dist/common/env.d.ts +3 -0
  35. package/dist/common/type.d.ts +247 -0
  36. package/dist/components/ChatItem/ExecuteItem.d.ts +25 -0
  37. package/dist/components/ChatItem/ExpandParseTip.d.ts +20 -0
  38. package/dist/components/ChatItem/FilterItem.d.ts +17 -0
  39. package/dist/components/ChatItem/Loading.d.ts +2 -0
  40. package/dist/components/ChatItem/ParseTip.d.ts +26 -0
  41. package/dist/components/ChatItem/ParseTipUtils.d.ts +10 -0
  42. package/dist/components/ChatItem/SimilarQuestionItem.d.ts +10 -0
  43. package/dist/components/ChatItem/SqlItem.d.ts +17 -0
  44. package/dist/components/ChatItem/SwitchEntity.d.ts +9 -0
  45. package/dist/components/ChatItem/Text.d.ts +6 -0
  46. package/dist/components/ChatItem/Typing.d.ts +2 -0
  47. package/dist/components/ChatItem/index.d.ts +33 -0
  48. package/dist/components/ChatMsg/ApplyAuth/index.d.ts +7 -0
  49. package/dist/components/ChatMsg/Bar/index.d.ts +13 -0
  50. package/dist/components/ChatMsg/DateOptions/index.d.ts +9 -0
  51. package/dist/components/ChatMsg/FilterSection/index.d.ts +8 -0
  52. package/dist/components/ChatMsg/MarkDown/index.d.ts +10 -0
  53. package/dist/components/ChatMsg/Message/index.d.ts +18 -0
  54. package/dist/components/ChatMsg/MetricCard/PeriodCompareItem.d.ts +7 -0
  55. package/dist/components/ChatMsg/MetricCard/index.d.ts +10 -0
  56. package/dist/components/ChatMsg/MetricTrend/MetricInfo.d.ts +8 -0
  57. package/dist/components/ChatMsg/MetricTrend/MetricTrendChart.d.ts +14 -0
  58. package/dist/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.d.ts +12 -0
  59. package/dist/components/ChatMsg/MetricTrend/index.d.ts +16 -0
  60. package/dist/components/ChatMsg/NoPermissionChart/index.d.ts +8 -0
  61. package/dist/components/ChatMsg/Pie/PieChart.d.ts +11 -0
  62. package/dist/components/ChatMsg/Pie/index.d.ts +14 -0
  63. package/dist/components/ChatMsg/Table/index.d.ts +12 -0
  64. package/dist/components/ChatMsg/Text/index.d.ts +9 -0
  65. package/dist/components/ChatMsg/WebPage/index.d.ts +8 -0
  66. package/dist/components/ChatMsg/index.d.ts +15 -0
  67. package/dist/components/DrillDownDimensions/DimensionSection.d.ts +11 -0
  68. package/dist/components/DrillDownDimensions/index.d.ts +13 -0
  69. package/dist/components/IconFont/index.d.ts +3 -0
  70. package/dist/components/MetricOptions/index.d.ts +11 -0
  71. package/dist/components/RecommendOptions/index.d.ts +9 -0
  72. package/dist/components/Tools/FeedbackModal.d.ts +9 -0
  73. package/dist/components/Tools/index.d.ts +12 -0
  74. package/dist/demo/Chat.d.ts +2 -0
  75. package/dist/demo/ChatDemo.d.ts +4 -0
  76. package/dist/demo/CopilotDemo.d.ts +2 -0
  77. package/dist/hooks/index.d.ts +3 -0
  78. package/dist/hooks/useComposing.d.ts +5 -0
  79. package/dist/hooks/useExportByEcharts.d.ts +10 -0
  80. package/dist/hooks/useMethodRegister.d.ts +4 -0
  81. package/dist/index.d.ts +10 -0
  82. package/dist/index.es.js +1 -0
  83. package/dist/service/axiosInstance.d.ts +3 -0
  84. package/dist/service/index.d.ts +25 -0
  85. package/dist/utils/utils.d.ts +45 -0
  86. package/package.json +214 -0
  87. package/public/favicon.ico +0 -0
  88. package/public/index.html +43 -0
  89. package/public/manifest.json +15 -0
  90. package/public/robots.txt +3 -0
  91. package/rollup/rollup.config.mjs +37 -0
  92. package/rollup/rollup.esm.config.mjs +21 -0
  93. package/rollup/rollup.umd.config.mjs +30 -0
  94. package/scripts/build.js +217 -0
  95. package/scripts/start.js +154 -0
  96. package/scripts/test.js +52 -0
  97. package/src/Chat/AgentList/index.tsx +52 -0
  98. package/src/Chat/AgentList/style.module.less +83 -0
  99. package/src/Chat/ChatFooter/index.tsx +423 -0
  100. package/src/Chat/ChatFooter/style.module.less +225 -0
  101. package/src/Chat/Conversation/index.tsx +236 -0
  102. package/src/Chat/Conversation/style.module.less +171 -0
  103. package/src/Chat/MessageContainer/index.tsx +145 -0
  104. package/src/Chat/MessageContainer/style.module.less +53 -0
  105. package/src/Chat/MobileAgents/index.tsx +62 -0
  106. package/src/Chat/MobileAgents/style.module.less +55 -0
  107. package/src/Chat/components/AgentTip/index.tsx +48 -0
  108. package/src/Chat/components/AgentTip/style.module.less +44 -0
  109. package/src/Chat/components/ConversationModal/index.tsx +65 -0
  110. package/src/Chat/components/CopilotAvatar/index.tsx +8 -0
  111. package/src/Chat/components/CopilotAvatar/style.module.less +13 -0
  112. package/src/Chat/components/Message.tsx +38 -0
  113. package/src/Chat/components/RecommendQuestions/index.tsx +64 -0
  114. package/src/Chat/components/RecommendQuestions/style.module.less +36 -0
  115. package/src/Chat/components/Text.tsx +42 -0
  116. package/src/Chat/components/style.module.less +311 -0
  117. package/src/Chat/constants.ts +37 -0
  118. package/src/Chat/index.tsx +526 -0
  119. package/src/Chat/service.ts +49 -0
  120. package/src/Chat/style.module.less +119 -0
  121. package/src/Chat/type.ts +107 -0
  122. package/src/Copilot/constants.ts +11 -0
  123. package/src/Copilot/index.tsx +149 -0
  124. package/src/Copilot/style.module.less +151 -0
  125. package/src/ShowCase/index.tsx +120 -0
  126. package/src/ShowCase/service.ts +12 -0
  127. package/src/ShowCase/style.module.less +46 -0
  128. package/src/ShowCase/type.ts +14 -0
  129. package/src/common/constants.ts +93 -0
  130. package/src/common/env.ts +5 -0
  131. package/src/common/type.ts +270 -0
  132. package/src/components/ChatItem/ExecuteItem.tsx +211 -0
  133. package/src/components/ChatItem/ExpandParseTip.tsx +333 -0
  134. package/src/components/ChatItem/FilterItem.tsx +209 -0
  135. package/src/components/ChatItem/Loading.tsx +14 -0
  136. package/src/components/ChatItem/ParseTip.tsx +322 -0
  137. package/src/components/ChatItem/ParseTipUtils.tsx +205 -0
  138. package/src/components/ChatItem/SimilarQuestionItem.tsx +84 -0
  139. package/src/components/ChatItem/SqlItem.tsx +410 -0
  140. package/src/components/ChatItem/SwitchEntity.tsx +52 -0
  141. package/src/components/ChatItem/Text.tsx +17 -0
  142. package/src/components/ChatItem/Typing.tsx +19 -0
  143. package/src/components/ChatItem/index.tsx +843 -0
  144. package/src/components/ChatItem/style.less +670 -0
  145. package/src/components/ChatMsg/ApplyAuth/index.tsx +30 -0
  146. package/src/components/ChatMsg/ApplyAuth/style.less +13 -0
  147. package/src/components/ChatMsg/Bar/index.tsx +223 -0
  148. package/src/components/ChatMsg/Bar/style.less +60 -0
  149. package/src/components/ChatMsg/DateOptions/index.tsx +46 -0
  150. package/src/components/ChatMsg/DateOptions/style.less +43 -0
  151. package/src/components/ChatMsg/FilterSection/index.tsx +42 -0
  152. package/src/components/ChatMsg/FilterSection/style.less +37 -0
  153. package/src/components/ChatMsg/MarkDown/index.tsx +26 -0
  154. package/src/components/ChatMsg/MarkDown/style.less +9 -0
  155. package/src/components/ChatMsg/Message/index.tsx +105 -0
  156. package/src/components/ChatMsg/Message/style.less +119 -0
  157. package/src/components/ChatMsg/MetricCard/PeriodCompareItem.tsx +29 -0
  158. package/src/components/ChatMsg/MetricCard/index.tsx +80 -0
  159. package/src/components/ChatMsg/MetricCard/style.less +126 -0
  160. package/src/components/ChatMsg/MetricTrend/MetricInfo.tsx +60 -0
  161. package/src/components/ChatMsg/MetricTrend/MetricTrendChart.tsx +235 -0
  162. package/src/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.tsx +162 -0
  163. package/src/components/ChatMsg/MetricTrend/index.tsx +127 -0
  164. package/src/components/ChatMsg/MetricTrend/style.less +195 -0
  165. package/src/components/ChatMsg/NoPermissionChart/index.tsx +28 -0
  166. package/src/components/ChatMsg/NoPermissionChart/style.less +26 -0
  167. package/src/components/ChatMsg/Pie/PieChart.tsx +134 -0
  168. package/src/components/ChatMsg/Pie/index.tsx +88 -0
  169. package/src/components/ChatMsg/Pie/style.less +43 -0
  170. package/src/components/ChatMsg/Table/index.tsx +105 -0
  171. package/src/components/ChatMsg/Table/style.less +131 -0
  172. package/src/components/ChatMsg/Text/index.tsx +70 -0
  173. package/src/components/ChatMsg/Text/style.less +38 -0
  174. package/src/components/ChatMsg/WebPage/index.tsx +125 -0
  175. package/src/components/ChatMsg/index.tsx +428 -0
  176. package/src/components/ChatMsg/style.less +28 -0
  177. package/src/components/DrillDownDimensions/DimensionSection.tsx +99 -0
  178. package/src/components/DrillDownDimensions/index.tsx +76 -0
  179. package/src/components/DrillDownDimensions/style.less +64 -0
  180. package/src/components/IconFont/index.tsx +7 -0
  181. package/src/components/MetricOptions/index.tsx +75 -0
  182. package/src/components/MetricOptions/style.less +69 -0
  183. package/src/components/RecommendOptions/index.tsx +126 -0
  184. package/src/components/RecommendOptions/style.less +24 -0
  185. package/src/components/Tools/FeedbackModal.tsx +55 -0
  186. package/src/components/Tools/index.tsx +126 -0
  187. package/src/components/Tools/style.less +67 -0
  188. package/src/demo/Chat.tsx +73 -0
  189. package/src/demo/ChatDemo.tsx +14 -0
  190. package/src/demo/CopilotDemo.tsx +43 -0
  191. package/src/demo/style.module.less +19 -0
  192. package/src/hooks/index.ts +3 -0
  193. package/src/hooks/useComposing.ts +31 -0
  194. package/src/hooks/useExportByEcharts.ts +41 -0
  195. package/src/hooks/useMethodRegister.ts +25 -0
  196. package/src/index.tsx +44 -0
  197. package/src/service/axiosInstance.ts +58 -0
  198. package/src/service/index.ts +174 -0
  199. package/src/setupProxy.js +18 -0
  200. package/src/setupTests.ts +5 -0
  201. package/src/styles/global.less +52 -0
  202. package/src/styles/index.less +39 -0
  203. package/src/styles/reboot.less +14 -0
  204. package/src/styles/variables.less +80 -0
  205. package/src/typings.d.ts +179 -0
  206. package/src/utils/utils.ts +346 -0
  207. package/tsconfig.build.json +20 -0
  208. package/tsconfig.json +27 -0
@@ -0,0 +1,162 @@
1
+ import { CHART_SECONDARY_COLOR, CLS_PREFIX, THEME_COLOR_LIST } from '../../../common/constants';
2
+ import { getFormattedValue } from '../../../utils/utils';
3
+ import type { ECharts } from 'echarts';
4
+ import * as echarts from 'echarts';
5
+ import React, { useContext, useEffect, useRef, useState } from 'react';
6
+ import moment from 'moment';
7
+ import { ColumnType } from '../../../common/type';
8
+ import { isArray } from 'lodash';
9
+ import { ChartItemContext } from '../../ChatItem';
10
+ import { useExportByEcharts } from '../../../hooks';
11
+
12
+ type Props = {
13
+ dateColumnName: string;
14
+ metricFields: ColumnType[];
15
+ resultList: any[];
16
+ triggerResize?: boolean;
17
+ chartType?: string;
18
+ question: string;
19
+ };
20
+
21
+ const MultiMetricsTrendChart: React.FC<Props> = ({
22
+ dateColumnName,
23
+ metricFields,
24
+ resultList,
25
+ triggerResize,
26
+ chartType,
27
+ question,
28
+ }) => {
29
+ const chartRef = useRef<any>();
30
+ const instanceRef = useRef<ECharts>();
31
+ const renderChart = () => {
32
+ let instanceObj: any;
33
+ if (!instanceRef.current) {
34
+ instanceObj = echarts.init(chartRef.current);
35
+ instanceRef.current = instanceObj;
36
+ } else {
37
+ instanceObj = instanceRef.current;
38
+ instanceObj.clear();
39
+ }
40
+
41
+ const xData = resultList?.map((item: any) => {
42
+ const date = isArray(item[dateColumnName])
43
+ ? item[dateColumnName].join('-')
44
+ : `${item[dateColumnName]}`;
45
+ return date.length === 10 ? moment(date).format('MM-DD') : date;
46
+ });
47
+
48
+ instanceObj.setOption({
49
+ legend: {
50
+ left: 0,
51
+ top: 0,
52
+ icon: 'rect',
53
+ itemWidth: 15,
54
+ itemHeight: 5,
55
+ type: 'scroll',
56
+ },
57
+ xAxis: {
58
+ type: 'category',
59
+ axisTick: {
60
+ alignWithLabel: true,
61
+ lineStyle: {
62
+ color: CHART_SECONDARY_COLOR,
63
+ },
64
+ },
65
+ axisLine: {
66
+ lineStyle: {
67
+ color: CHART_SECONDARY_COLOR,
68
+ },
69
+ },
70
+ axisLabel: {
71
+ showMaxLabel: true,
72
+ color: '#999',
73
+ },
74
+ data: xData,
75
+ },
76
+ yAxis: {
77
+ type: 'value',
78
+ splitLine: {
79
+ lineStyle: {
80
+ opacity: 0.3,
81
+ },
82
+ },
83
+ axisLabel: {
84
+ formatter: function (value: any) {
85
+ return value === 0 ? 0 : getFormattedValue(value);
86
+ },
87
+ },
88
+ },
89
+ tooltip: {
90
+ trigger: 'axis',
91
+ formatter: function (params: any[]) {
92
+ const param = params[0];
93
+ const valueLabels = params
94
+ .sort((a, b) => b.value - a.value)
95
+ .map(
96
+ (item: any) =>
97
+ `<div style="margin-top: 3px;">${
98
+ item.marker
99
+ } <span style="display: inline-block; width: 70px; margin-right: 12px;">${
100
+ item.seriesName
101
+ }</span><span style="display: inline-block; width: 90px; text-align: right; font-weight: 500;">${
102
+ item.value === '' ? '-' : getFormattedValue(item.value)
103
+ }</span></div>`
104
+ )
105
+ .join('');
106
+ return `${param.name}<br />${valueLabels}`;
107
+ },
108
+ },
109
+ grid: {
110
+ left: '1%',
111
+ right: '4%',
112
+ bottom: '3%',
113
+ top: 45,
114
+ containLabel: true,
115
+ },
116
+ series: metricFields.map((metricField, index) => {
117
+ return {
118
+ type: chartType,
119
+ name: metricField.name,
120
+ symbol: 'circle',
121
+ showSymbol: resultList.length === 1,
122
+ smooth: true,
123
+ data: resultList.map((item: any) => {
124
+ const value = item[metricField.bizName];
125
+ return (metricField.dataFormatType === 'percent' ||
126
+ metricField.dataFormatType === 'decimal') &&
127
+ metricField.dataFormat?.needMultiply100
128
+ ? value * 100
129
+ : value;
130
+ }),
131
+ color: THEME_COLOR_LIST[index],
132
+ };
133
+ }),
134
+ });
135
+ instanceObj.resize();
136
+ };
137
+
138
+ const { downloadChartAsImage } = useExportByEcharts({
139
+ instanceRef,
140
+ question,
141
+ });
142
+
143
+ const { register } = useContext(ChartItemContext);
144
+
145
+ register('downloadChartAsImage', downloadChartAsImage);
146
+
147
+ useEffect(() => {
148
+ renderChart();
149
+ }, [resultList, chartType]);
150
+
151
+ useEffect(() => {
152
+ if (triggerResize && instanceRef.current) {
153
+ instanceRef.current.resize();
154
+ }
155
+ }, [triggerResize]);
156
+
157
+ const prefixCls = `${CLS_PREFIX}-metric-trend`;
158
+
159
+ return <div className={`${prefixCls}-flow-trend-chart`} ref={chartRef} />;
160
+ };
161
+
162
+ export default MultiMetricsTrendChart;
@@ -0,0 +1,127 @@
1
+ import { CLS_PREFIX } from '../../../common/constants';
2
+ import { DrillDownDimensionType, FieldType, MsgDataType } from '../../../common/type';
3
+ import { isMobile } from '../../../utils/utils';
4
+ import MetricTrendChart from './MetricTrendChart';
5
+ import { Spin, Select } from 'antd';
6
+ import Table from '../Table';
7
+ import MetricInfo from './MetricInfo';
8
+ import DateOptions from '../DateOptions';
9
+ import MultiMetricsTrendChart from './MultiMetricsTrendChart';
10
+ import { useState } from 'react';
11
+
12
+ const metricChartSelectOptions = [
13
+ {
14
+ value: 'line',
15
+ label: '折线图',
16
+ },
17
+ {
18
+ value: 'bar',
19
+ label: '柱状图',
20
+ },
21
+ ];
22
+
23
+ type Props = {
24
+ data: MsgDataType;
25
+ question: string;
26
+ chartIndex: number;
27
+ triggerResize?: boolean;
28
+ loading: boolean;
29
+ activeMetricField?: FieldType;
30
+ drillDownDimension?: DrillDownDimensionType;
31
+ currentDateOption?: number;
32
+ onApplyAuth?: (model: string) => void;
33
+ onSelectDateOption: (value: number) => void;
34
+ };
35
+
36
+ const MetricTrend: React.FC<Props> = ({
37
+ data,
38
+ question,
39
+ chartIndex,
40
+ triggerResize,
41
+ loading,
42
+ activeMetricField,
43
+ drillDownDimension,
44
+ currentDateOption,
45
+ onApplyAuth,
46
+ onSelectDateOption,
47
+ }) => {
48
+ const { queryColumns, queryResults, aggregateInfo, entityInfo, chatContext } = data;
49
+ const [chartType, setChartType] = useState('line');
50
+
51
+ const dateField: any = queryColumns?.find(
52
+ (column: any) => column.showType === 'DATE' || column.type === 'DATE'
53
+ );
54
+ const dateColumnName = dateField?.bizName || '';
55
+ const categoryColumnName =
56
+ queryColumns?.find((column: any) => column.showType === 'CATEGORY')?.bizName || '';
57
+ const metricFields = queryColumns?.filter((column: any) => column.showType === 'NUMBER');
58
+
59
+ const currentMetricField = queryColumns?.find((column: any) => column.showType === 'NUMBER');
60
+
61
+ if (!currentMetricField) {
62
+ return null;
63
+ }
64
+
65
+ const prefixCls = `${CLS_PREFIX}-metric-trend`;
66
+
67
+ return (
68
+ <div className={prefixCls}>
69
+ <div className={`${prefixCls}-charts`}>
70
+ <div className={`${prefixCls}-top-bar`}>
71
+ <div className={`${prefixCls}-metric-fields ${prefixCls}-metric-field-single`}>
72
+ {question}
73
+ </div>
74
+ </div>
75
+ <Spin spinning={loading}>
76
+ <div className={`${prefixCls}-content`}>
77
+ {!isMobile &&
78
+ aggregateInfo?.metricInfos?.length > 0 &&
79
+ drillDownDimension === undefined && (
80
+ <MetricInfo aggregateInfo={aggregateInfo} currentMetricField={currentMetricField} />
81
+ )}
82
+ <div className={`${prefixCls}-select-options`}>
83
+ <DateOptions
84
+ chatContext={chatContext}
85
+ currentDateOption={currentDateOption}
86
+ onSelectDateOption={onSelectDateOption}
87
+ />
88
+ <div>
89
+ <Select
90
+ defaultValue="line"
91
+ bordered={false}
92
+ options={metricChartSelectOptions}
93
+ onChange={(value: string) => setChartType(value)}
94
+ />
95
+ </div>
96
+ </div>
97
+ {queryResults?.length === 1 || chartIndex % 2 === 1 ? (
98
+ <Table data={{ ...data, queryResults }} onApplyAuth={onApplyAuth} />
99
+ ) : metricFields.length > 1 ? (
100
+ <MultiMetricsTrendChart
101
+ dateColumnName={dateColumnName}
102
+ metricFields={metricFields}
103
+ question={question}
104
+ resultList={queryResults}
105
+ triggerResize={triggerResize}
106
+ chartType={chartType}
107
+ />
108
+ ) : (
109
+ <MetricTrendChart
110
+ model={entityInfo?.dataSetInfo.name}
111
+ dateColumnName={dateColumnName}
112
+ categoryColumnName={categoryColumnName}
113
+ metricField={currentMetricField}
114
+ resultList={queryResults}
115
+ triggerResize={triggerResize}
116
+ onApplyAuth={onApplyAuth}
117
+ chartType={chartType}
118
+ />
119
+ )}
120
+ </div>
121
+ </Spin>
122
+ </div>
123
+ </div>
124
+ );
125
+ };
126
+
127
+ export default MetricTrend;
@@ -0,0 +1,195 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @metric-trend-prefix-cls: ~'@{supersonic-chat-prefix}-metric-trend';
4
+
5
+ @metric-info-prefix-cls: ~'@{supersonic-chat-prefix}-metric-info';
6
+
7
+ .@{metric-trend-prefix-cls} {
8
+ display: flex;
9
+ flex-direction: column;
10
+ align-items: center;
11
+ justify-content: center;
12
+ margin-top: 4px;
13
+ width: 100%;
14
+ row-gap: 4px;
15
+
16
+ &-top-bar {
17
+ display: flex;
18
+ align-items: baseline;
19
+ flex-wrap: wrap;
20
+ row-gap: 12px;
21
+ }
22
+
23
+ &-filter-section-wrapper {
24
+ display: flex;
25
+ align-items: center;
26
+ color: var(--text-color-third);
27
+ margin-left: 4px;
28
+ }
29
+
30
+ &-filter-section {
31
+ display: flex;
32
+ align-items: center;
33
+ font-size: 13px;
34
+ column-gap: 12px;
35
+ color: var(--text-color-third);
36
+ }
37
+
38
+ &-filter-item {
39
+ display: flex;
40
+ align-items: center;
41
+ }
42
+
43
+ &-filter-item-label {
44
+ color: var(--text-color-third);
45
+ }
46
+
47
+ &-filter-item-value {
48
+ color: var(--text-color);
49
+ font-weight: 500;
50
+ }
51
+
52
+ &-content {
53
+ display: flex;
54
+ flex-direction: column;
55
+ width: 100%;
56
+ row-gap: 12px;
57
+ }
58
+
59
+ &-select-options {
60
+ display: flex;
61
+ justify-content: space-between;
62
+ }
63
+
64
+ &-indicator {
65
+ display: flex;
66
+ flex-direction: column;
67
+ align-items: baseline;
68
+ justify-content: center;
69
+ }
70
+
71
+ &-date-range {
72
+ color: var(--text-color-fourth);
73
+ font-size: 14px;
74
+ }
75
+
76
+ &-indicator-value {
77
+ color: var(--text-color);
78
+ font-weight: 600;
79
+ font-size: 30px;
80
+ }
81
+
82
+ &-indicator-name {
83
+ color: var(--text-color-fourth);
84
+ font-size: 14px;
85
+ }
86
+
87
+ &-flow-trend-chart {
88
+ margin-top: 4px;
89
+ height: 230px;
90
+ }
91
+
92
+ &-flow-trend-chart-single {
93
+ height: 180px;
94
+ }
95
+
96
+ &-charts {
97
+ display: flex;
98
+ flex-direction: column;
99
+ width: 100%;
100
+ row-gap: 8px;
101
+ }
102
+
103
+ &-metric-fields {
104
+ display: flex;
105
+ flex-wrap: wrap;
106
+ align-items: center;
107
+ row-gap: 12px;
108
+ color: var(--text-color);
109
+ font-size: 15px;
110
+ }
111
+
112
+ &-metric-field {
113
+ display: inline-block;
114
+ box-sizing: border-box;
115
+ height: auto;
116
+ margin: 0;
117
+ margin-right: 8px;
118
+ padding: 1px 8px;
119
+ color: var(--text-color-third);
120
+ font-variant: tabular-nums;
121
+ line-height: 20px;
122
+ white-space: nowrap;
123
+ list-style: none;
124
+ border-color: transparent;
125
+ border-radius: 2px;
126
+ cursor: pointer;
127
+ opacity: 1;
128
+ transition: all 0.3s;
129
+ font-feature-settings: 'tnum', 'tnum';
130
+
131
+ &:hover {
132
+ color: var(--chat-blue);
133
+ }
134
+ }
135
+
136
+ &-metric-field-single {
137
+ padding-left: 0;
138
+ font-weight: 500;
139
+ cursor: default;
140
+ font-size: 15px;
141
+ color: var(--text-color);
142
+
143
+ &:hover {
144
+ color: var(--text-color);
145
+ }
146
+ }
147
+ }
148
+
149
+ .@{metric-info-prefix-cls} {
150
+ &-indicator {
151
+ display: flex;
152
+ align-items: baseline;
153
+ column-gap: 12px;
154
+ }
155
+
156
+ &-indicator-value {
157
+ color: var(--text-color);
158
+ font-weight: 500;
159
+ font-size: 28px;
160
+ line-height: 40px;
161
+ margin-top: 2px;
162
+ color: var(--text-color-secondary);
163
+ }
164
+
165
+ &-bottom-section {
166
+ display: flex;
167
+ align-items: center;
168
+ column-gap: 20px;
169
+ margin-top: 4px;
170
+ }
171
+
172
+ &-date {
173
+ color: var(--text-color-fourth);
174
+ font-size: 13px;
175
+ }
176
+
177
+ &-date-value {
178
+ color: var(--chat-blue);
179
+ }
180
+
181
+ &-indicator-switch {
182
+ color: var(--text-color-fourth);
183
+ font-size: 18px;
184
+ margin-left: 6px;
185
+ margin-bottom: 3px;
186
+ }
187
+
188
+ &-period-compare {
189
+ display: flex;
190
+ align-items: center;
191
+ column-gap: 20px;
192
+ font-size: 13px;
193
+ overflow-x: auto;
194
+ }
195
+ }
@@ -0,0 +1,28 @@
1
+ import classNames from 'classnames';
2
+ import { CLS_PREFIX } from '../../../common/constants';
3
+ import ApplyAuth from '../ApplyAuth';
4
+
5
+ type Props = {
6
+ model: string;
7
+ chartType?: string;
8
+ onApplyAuth?: (model: string) => void;
9
+ };
10
+
11
+ const NoPermissionChart: React.FC<Props> = ({ model, chartType, onApplyAuth }) => {
12
+ const prefixCls = `${CLS_PREFIX}-no-permission-chart`;
13
+
14
+ const chartHolderClass = classNames(`${prefixCls}-holder`, {
15
+ [`${prefixCls}-bar-chart-holder`]: chartType === 'barChart',
16
+ });
17
+
18
+ return (
19
+ <div className={prefixCls}>
20
+ <div className={chartHolderClass} />
21
+ <div className={`${prefixCls}-no-permission`}>
22
+ <ApplyAuth model={model} onApplyAuth={onApplyAuth} />
23
+ </div>
24
+ </div>
25
+ );
26
+ };
27
+
28
+ export default NoPermissionChart;
@@ -0,0 +1,26 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @no-permission-chart-prefix-cls: ~'@{supersonic-chat-prefix}-no-permission-chart';
4
+
5
+ .@{no-permission-chart-prefix-cls} {
6
+ position: relative;
7
+ width: 100%;
8
+ height: 300px;
9
+
10
+ &-holder {
11
+ width: 100%;
12
+ height: 280px;
13
+ }
14
+
15
+ &-bar-chart-holder {
16
+ margin-top: 20px;
17
+ }
18
+
19
+ &-no-permission {
20
+ position: absolute;
21
+ top: 50%;
22
+ left: 50%;
23
+ padding: 4px 12px;
24
+ transform: translate(-50%, -50%);
25
+ }
26
+ }
@@ -0,0 +1,134 @@
1
+ import { PREFIX_CLS, THEME_COLOR_LIST } from '../../../common/constants';
2
+ import { MsgDataType } from '../../../common/type';
3
+ import { formatByDataFormatType, getFormattedValue } from '../../../utils/utils';
4
+ import type { ECharts } from 'echarts';
5
+ import * as echarts from 'echarts';
6
+ import { useEffect, useRef } from 'react';
7
+ import { ColumnType } from '../../../common/type';
8
+ import moment from 'moment';
9
+
10
+ type Props = {
11
+ data: MsgDataType;
12
+ metricField: ColumnType;
13
+ categoryField: ColumnType;
14
+ triggerResize?: boolean;
15
+ };
16
+
17
+ const PieChart: React.FC<Props> = ({
18
+ data,
19
+ metricField,
20
+ categoryField,
21
+ triggerResize,
22
+ }) => {
23
+ const chartRef = useRef<any>();
24
+ const instanceRef = useRef<ECharts>();
25
+
26
+ const { queryResults } = data;
27
+ const categoryColumnName = categoryField?.bizName || '';
28
+ const metricColumnName = metricField?.bizName || '';
29
+
30
+ const renderChart = () => {
31
+ let instanceObj: any;
32
+ if (!instanceRef.current) {
33
+ instanceObj = echarts.init(chartRef.current);
34
+ instanceRef.current = instanceObj;
35
+ } else {
36
+ instanceObj = instanceRef.current;
37
+ }
38
+
39
+ const data = queryResults || [];
40
+
41
+ // 检查是否有日期字段,如果有则按时间排序
42
+ const dateColumn = queryResults[0] ? Object.keys(queryResults[0]).find(key =>
43
+ key.toLowerCase().includes('date') || key.toLowerCase().includes('time')
44
+ ) : null;
45
+
46
+ let sortedData = data;
47
+ if (dateColumn) {
48
+ sortedData = [...data].sort((a, b) => {
49
+ return moment(a[dateColumn]).diff(moment(b[dateColumn]));
50
+ });
51
+ }
52
+
53
+ const seriesData = sortedData.map((item, index) => {
54
+ const value = item[metricColumnName];
55
+ const name = item[categoryColumnName] !== undefined ? item[categoryColumnName] : '未知';
56
+ return {
57
+ name,
58
+ value,
59
+ itemStyle: {
60
+ color: THEME_COLOR_LIST[index % THEME_COLOR_LIST.length],
61
+ },
62
+ };
63
+ });
64
+
65
+ instanceObj.setOption({
66
+ tooltip: {
67
+ trigger: 'item',
68
+ formatter: function (params: any) {
69
+ const value = params.value;
70
+ return `${params.name}: ${
71
+ metricField.dataFormatType === 'percent'
72
+ ? formatByDataFormatType(value, metricField.dataFormatType, metricField.dataFormat)
73
+ : getFormattedValue(value)
74
+ }`;
75
+ },
76
+ },
77
+ legend: {
78
+ orient: 'vertical',
79
+ left: 'left',
80
+ type: 'scroll',
81
+ data: seriesData.map(item => item.name),
82
+ selectedMode: true,
83
+ textStyle: {
84
+ color: '#666',
85
+ },
86
+ },
87
+ series: [
88
+ {
89
+ name: '占比',
90
+ type: 'pie',
91
+ radius: ['40%', '70%'],
92
+ avoidLabelOverlap: false,
93
+ itemStyle: {
94
+ borderRadius: 10,
95
+ borderColor: '#fff',
96
+ borderWidth: 2,
97
+ },
98
+ label: {
99
+ show: false,
100
+ position: 'center',
101
+ },
102
+ emphasis: {
103
+ label: {
104
+ show: true,
105
+ fontSize: '14',
106
+ fontWeight: 'bold',
107
+ },
108
+ },
109
+ labelLine: {
110
+ show: false,
111
+ },
112
+ data: seriesData,
113
+ },
114
+ ],
115
+ });
116
+ instanceObj.resize();
117
+ };
118
+
119
+ useEffect(() => {
120
+ if (queryResults && queryResults.length > 0) {
121
+ renderChart();
122
+ }
123
+ }, [queryResults, metricField, categoryField]);
124
+
125
+ useEffect(() => {
126
+ if (triggerResize && instanceRef.current) {
127
+ instanceRef.current.resize();
128
+ }
129
+ }, [triggerResize]);
130
+
131
+ return <div className={`${PREFIX_CLS}-pie-chart`} ref={chartRef} />;
132
+ };
133
+
134
+ export default PieChart;