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.
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 +210 -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 +208 -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 +120 -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 +103 -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,103 @@
1
+ import { formatByDataFormatType, formatByThousandSeperator } from '../../../utils/utils';
2
+ import { Table as AntTable } from 'antd';
3
+ import { MsgDataType } from '../../../common/type';
4
+ import { CLS_PREFIX } from '../../../common/constants';
5
+ import ApplyAuth from '../ApplyAuth';
6
+ import { SizeType } from 'antd/es/config-provider/SizeContext';
7
+ import moment from 'moment';
8
+
9
+ type Props = {
10
+ data: MsgDataType;
11
+ size?: SizeType;
12
+ question?: string;
13
+ loading?: boolean;
14
+ onApplyAuth?: (model: string) => void;
15
+ };
16
+
17
+ const Table: React.FC<Props> = ({ data, size, loading, question, onApplyAuth }) => {
18
+ const { entityInfo, queryColumns, queryResults } = data;
19
+
20
+ const prefixCls = `${CLS_PREFIX}-table`;
21
+ const tableColumns: any[] = queryColumns.map(
22
+ ({ name, bizName, showType, dataFormatType, dataFormat, authorized }) => {
23
+ return {
24
+ dataIndex: bizName,
25
+ key: bizName,
26
+ title: name || bizName,
27
+ sorter:
28
+ showType === 'NUMBER'
29
+ ? (a, b) => {
30
+ return a[bizName] - b[bizName];
31
+ }
32
+ : undefined,
33
+ render: (value: string | number) => {
34
+ if (!authorized) {
35
+ return (
36
+ <ApplyAuth model={entityInfo?.dataSetInfo.name || ''} onApplyAuth={onApplyAuth} />
37
+ );
38
+ }
39
+ if (dataFormatType === 'percent') {
40
+ return (
41
+ <div className={`${prefixCls}-formatted-value`}>
42
+ {`${
43
+ value
44
+ ? formatByDataFormatType(value, dataFormatType, dataFormat)
45
+ : '0%'
46
+ }`}
47
+ </div>
48
+ );
49
+ }
50
+ if (showType === 'NUMBER') {
51
+ return (
52
+ <div className={`${prefixCls}-formatted-value`}>
53
+ {/* {getFormattedValue(value as number)} */}
54
+ {formatByThousandSeperator(value)}
55
+ </div>
56
+ );
57
+ }
58
+ if (bizName.includes('photo')) {
59
+ return (
60
+ <div className={`${prefixCls}-photo`}>
61
+ <img width={40} height={40} src={value as string} alt="" />
62
+ </div>
63
+ );
64
+ }
65
+ return value;
66
+ },
67
+ };
68
+ }
69
+ );
70
+
71
+ const getRowClassName = (_: any, index: number) => {
72
+ return index % 2 !== 0 ? `${prefixCls}-even-row` : '';
73
+ };
74
+
75
+ const dateColumn = queryColumns.find(column => column.type === 'DATE' || column.showType === 'DATE');
76
+ const dataSource = dateColumn
77
+ ? queryResults.sort((a, b) => moment(a[dateColumn.bizName]).diff(moment(b[dateColumn.bizName])))
78
+ : queryResults;
79
+
80
+ return (
81
+ <div className={prefixCls}>
82
+ {question && (
83
+ <div className={`${prefixCls}-top-bar`}>
84
+ <div className={`${prefixCls}-indicator-name`}>{question}</div>
85
+ </div>
86
+ )}
87
+
88
+ <AntTable
89
+ pagination={
90
+ queryResults.length <= 10 ? false : { defaultPageSize: 10, position: ['bottomCenter'] }
91
+ }
92
+ columns={tableColumns}
93
+ dataSource={dataSource}
94
+ style={{ width: '100%', overflowX: 'auto', overflowY: 'hidden' }}
95
+ rowClassName={getRowClassName}
96
+ size={size}
97
+ loading={loading}
98
+ />
99
+ </div>
100
+ );
101
+ };
102
+
103
+ export default Table;
@@ -0,0 +1,131 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @table-prefix-cls: ~'@{supersonic-chat-prefix}-table';
4
+
5
+ .@{table-prefix-cls} {
6
+ margin-top: 6px;
7
+
8
+ &-photo {
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ }
13
+
14
+ &-filter-section-wrapper {
15
+ display: flex;
16
+ align-items: center;
17
+ color: var(--text-color-third);
18
+ margin-bottom: 12px;
19
+ }
20
+
21
+ &-filter-section {
22
+ display: flex;
23
+ align-items: center;
24
+ font-size: 13px;
25
+ column-gap: 12px;
26
+ color: var(--text-color-third);
27
+ }
28
+
29
+ &-top-bar {
30
+ display: flex;
31
+ align-items: baseline;
32
+ flex-wrap: wrap;
33
+ column-gap: 8px;
34
+ row-gap: 12px;
35
+ font-style: italic;
36
+ margin-bottom: 15px;
37
+ }
38
+ &-indicator-name {
39
+ font-size: 14px;
40
+ color: var(--text-color);
41
+ font-weight: 500;
42
+ margin-top: 2px;
43
+ }
44
+
45
+ &-filter-item {
46
+ display: flex;
47
+ align-items: center;
48
+ }
49
+
50
+ &-filter-item-label {
51
+ color: var(--text-color-third);
52
+ }
53
+
54
+ &-filter-item-value {
55
+ color: var(--text-color);
56
+ font-weight: 500;
57
+ }
58
+
59
+ &-drill-down-dimensions {
60
+ margin-top: 12px;
61
+ }
62
+
63
+ table {
64
+ width: 100%;
65
+ }
66
+
67
+ &-even-row {
68
+ background-color: #fbfbfb;
69
+ }
70
+
71
+ .ant-table-container table > thead > tr:first-child th:first-child {
72
+ border-top-left-radius: 12px !important;
73
+ border-bottom-left-radius: 12px !important;
74
+ }
75
+
76
+ .ant-table-container table > thead > tr:first-child th:last-child {
77
+ border-top-right-radius: 12px !important;
78
+ border-bottom-right-radius: 12px !important;
79
+ }
80
+
81
+ .ant-table-tbody > tr.ant-table-row:hover > td {
82
+ background-color: #fafafa !important;
83
+ }
84
+
85
+ .ant-table-cell { // 更新修改,解决表格内容太长导致显示的问题
86
+ white-space: nowrap;
87
+ overflow: hidden;
88
+ text-overflow: ellipsis;
89
+ max-width: 250px;
90
+ text-align: center !important;
91
+ }
92
+
93
+ .ant-table-thead {
94
+ .ant-table-cell {
95
+ padding-top: 10px;
96
+ padding-bottom: 10px;
97
+ color: #666;
98
+ font-size: 13px;
99
+ background: #f0f2f5;
100
+
101
+ &::before {
102
+ display: none;
103
+ }
104
+ }
105
+ }
106
+
107
+ .@{table-prefix-cls}-formatted-value {
108
+ font-weight: 500;
109
+ }
110
+
111
+ .ant-table-thead .ant-table-cell {
112
+ padding-top: 8.5px;
113
+ padding-bottom: 8.5px;
114
+ color: #737b7b;
115
+ font-weight: 500;
116
+ font-size: 14px;
117
+ background-color: #edf2f2;
118
+ }
119
+
120
+ .ant-table-tbody {
121
+ .ant-table-cell {
122
+ padding: 12px 2px;
123
+ color: var(--text-color);
124
+ font-size: 14px;
125
+ }
126
+ }
127
+
128
+ .ant-table-pagination.ant-pagination {
129
+ margin-bottom: 0;
130
+ }
131
+ }
@@ -0,0 +1,70 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { UpOutlined, DownOutlined } from '@ant-design/icons';
3
+ import { CLS_PREFIX } from '../../../common/constants';
4
+ import { ColumnType } from '../../../common/type';
5
+
6
+ type Props = {
7
+ columns: ColumnType[];
8
+ referenceColumn?: ColumnType;
9
+ dataSource: any[];
10
+ };
11
+
12
+ const Text: React.FC<Props> = ({ columns, referenceColumn, dataSource }) => {
13
+ const [text, setText] = useState<string>();
14
+ const [referenceExpanded, setRederenceExpanded] = useState(false);
15
+ const [referenceData, setReferenceData] = useState<any[]>([]);
16
+
17
+ const prefixCls = `${CLS_PREFIX}-text`;
18
+
19
+ const initData = () => {
20
+ let textValue = dataSource[0][columns[0].bizName];
21
+ setText(textValue === undefined ? '暂无数据' : textValue);
22
+ if (referenceColumn) {
23
+ const referenceDataValue = dataSource[0][referenceColumn.bizName];
24
+ setReferenceData(referenceDataValue || []);
25
+ }
26
+ };
27
+
28
+ useEffect(() => {
29
+ initData();
30
+ }, []);
31
+
32
+ const onToggleMore = () => {
33
+ setRederenceExpanded(!referenceExpanded);
34
+ };
35
+
36
+ return (
37
+ <div
38
+ style={{
39
+ lineHeight: '24px',
40
+ width: 'fit-content',
41
+ maxWidth: '100%',
42
+ overflowX: 'hidden',
43
+ }}
44
+ >
45
+ {text}
46
+ {referenceData.length > 0 && (
47
+ <span className={`${prefixCls}-check-more`} onClick={onToggleMore}>
48
+ {referenceExpanded ? '收起' : '查看'}更多
49
+ {referenceExpanded ? (
50
+ <UpOutlined className={`${prefixCls}-arrow-icon`} />
51
+ ) : (
52
+ <DownOutlined className={`${prefixCls}-arrow-icon`} />
53
+ )}
54
+ </span>
55
+ )}
56
+ {referenceData.length > 0 && referenceExpanded && (
57
+ <div className={`${prefixCls}-reference-data`}>
58
+ {referenceData.map(item => (
59
+ <div className={`${prefixCls}-reference-item`} key={item.doc_title}>
60
+ <div className={`${prefixCls}-reference-item-title`}>{item.doc_title}</div>
61
+ <div className={`${prefixCls}-reference-item-value`}>{item.doc_chunk}</div>
62
+ </div>
63
+ ))}
64
+ </div>
65
+ )}
66
+ </div>
67
+ );
68
+ };
69
+
70
+ export default Text;
@@ -0,0 +1,38 @@
1
+ @import '../../../styles/index.less';
2
+
3
+ @text-prefix-cls: ~'@{supersonic-chat-prefix}-text';
4
+
5
+ .@{text-prefix-cls} {
6
+ &-check-more {
7
+ margin-left: 12px;
8
+ font-size: 13px;
9
+ color: var(--chat-blue);
10
+ cursor: pointer;
11
+ }
12
+
13
+ &-arrow-icon {
14
+ margin-left: 2px;
15
+ font-size: 12px;
16
+ }
17
+
18
+ &-reference-data {
19
+ display: flex;
20
+ flex-direction: column;
21
+ row-gap: 10px;
22
+ margin-top: 10px;
23
+ }
24
+
25
+ &-reference-item {
26
+ font-size: 13px;
27
+ }
28
+
29
+ &-reference-item-title {
30
+ color: var(--text-color);
31
+ font-weight: 500;
32
+ }
33
+
34
+ &-reference-item-value {
35
+ color: var(--text-color-secondary);
36
+ margin-top: 4px;
37
+ }
38
+ }
@@ -0,0 +1,125 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { MsgDataType } from '../../../common/type';
3
+ import { getToken, isMobile, isProd } from '../../../utils/utils';
4
+ import { webPageHost } from '../../../common/env';
5
+
6
+ type Props = {
7
+ id: string | number;
8
+ data: MsgDataType;
9
+ };
10
+
11
+ const DEFAULT_HEIGHT = 800;
12
+
13
+ const WebPage: React.FC<Props> = ({ id, data }) => {
14
+ const [pluginUrl, setPluginUrl] = useState('');
15
+ const [height, setHeight] = useState(DEFAULT_HEIGHT);
16
+
17
+ const {
18
+ name,
19
+ webPage: { url, params },
20
+ } = data.response || {};
21
+
22
+ const handleMessage = useCallback((event: MessageEvent) => {
23
+ const messageData = event.data;
24
+ const { type, payload } = messageData;
25
+ if (type === 'changeMiniProgramContainerSize') {
26
+ const { msgId, height } = payload;
27
+ if (`${msgId}` === `${id}`) {
28
+ setHeight(height);
29
+ }
30
+ return;
31
+ }
32
+ if (messageData === 'storyResize') {
33
+ const ifr: any = document.getElementById(`reportIframe_${id}`);
34
+ const iDoc = ifr.contentDocument || ifr.document || ifr.contentWindow;
35
+ setTimeout(() => {
36
+ setHeight(isProd() ? calcPageHeight(iDoc) : DEFAULT_HEIGHT);
37
+ }, 200);
38
+ return;
39
+ }
40
+ }, []);
41
+
42
+ useEffect(() => {
43
+ window.addEventListener('message', handleMessage);
44
+ return () => {
45
+ window.removeEventListener('message', handleMessage);
46
+ };
47
+ }, [handleMessage]);
48
+
49
+ function calcPageHeight(doc: any) {
50
+ const titleAreaEl = doc.getElementById('titleArea');
51
+ const titleAreaHeight = Math.max(
52
+ titleAreaEl?.clientHeight || 0,
53
+ titleAreaEl?.scrollHeight || 0
54
+ );
55
+ const dashboardGridEl = doc.getElementsByClassName('dashboardGrid')?.[0];
56
+ const dashboardGridHeight = Math.max(
57
+ dashboardGridEl?.clientHeight || 0,
58
+ dashboardGridEl?.scrollHeight || 0
59
+ );
60
+ return Math.max(titleAreaHeight + dashboardGridHeight + 10, DEFAULT_HEIGHT);
61
+ }
62
+
63
+ const initData = () => {
64
+ const heightValue =
65
+ params?.find((option: any) => option.paramType === 'FORWARD' && option.key === 'height')
66
+ ?.value || DEFAULT_HEIGHT;
67
+ setHeight(heightValue);
68
+ let urlValue = url;
69
+ const valueParams = (params || [])
70
+ .filter((option: any) => option.paramType !== 'FORWARD')
71
+ .reduce((result: any, item: any) => {
72
+ result[item.key] = item.value;
73
+ return result;
74
+ }, {});
75
+ if (urlValue.includes('?type=dashboard') || urlValue.includes('?type=widget')) {
76
+ const filterData = encodeURIComponent(
77
+ JSON.stringify(
78
+ urlValue.includes('dashboard')
79
+ ? {
80
+ global: valueParams,
81
+ }
82
+ : {
83
+ local: valueParams,
84
+ }
85
+ )
86
+ );
87
+ urlValue = urlValue.replace(
88
+ '?',
89
+ `?token=${getToken()}&miniProgram=true&reportName=${name}&filterData=${filterData}&`
90
+ );
91
+ urlValue = `${webPageHost}${urlValue}`;
92
+ } else {
93
+ const params = Object.keys(valueParams || {}).map(key => `${key}=${valueParams[key]}`);
94
+ if (params.length > 0) {
95
+ if (url.includes('?')) {
96
+ urlValue = urlValue.replace('?', `?${params.join('&')}&`);
97
+ } else {
98
+ urlValue = `${urlValue}?${params.join('&')}`;
99
+ }
100
+ }
101
+ }
102
+ setPluginUrl(urlValue);
103
+ };
104
+
105
+ useEffect(() => {
106
+ initData();
107
+ }, []);
108
+
109
+ return (
110
+ <iframe
111
+ id={`reportIframe_${id}`}
112
+ name={`reportIframe_${id}`}
113
+ src={pluginUrl}
114
+ style={{
115
+ width: isMobile ? 'calc(100vw - 20px)' : 'calc(100vw - 410px)',
116
+ height,
117
+ border: 'none',
118
+ }}
119
+ title="reportIframe"
120
+ allowFullScreen
121
+ />
122
+ );
123
+ };
124
+
125
+ export default WebPage;