win-chart 1.0.1 → 1.0.3

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 (185) hide show
  1. package/build/js/index.js +1 -0
  2. package/package.json +5 -2
  3. package/.eslintrc.json +0 -3
  4. package/.prettierrc.json +0 -5
  5. package/localhost-key.pem +0 -28
  6. package/localhost.pem +0 -25
  7. package/rsbuild.config.ts +0 -48
  8. package/src/api/README.md +0 -15
  9. package/src/api/index.js +0 -5
  10. package/src/api/layout/index.js +0 -32
  11. package/src/api/request.ts +0 -87
  12. package/src/api/url-map/index.js +0 -10
  13. package/src/api/user/index.js +0 -12
  14. package/src/components/FilterContext.tsx +0 -6
  15. package/src/components/GlobalStyle.tsx +0 -25
  16. package/src/components/HalfScreenBrowser.tsx +0 -95
  17. package/src/components/ImgBox.tsx +0 -19
  18. package/src/components/JumpBtn.tsx +0 -38
  19. package/src/components/MCardWrapper.tsx +0 -33
  20. package/src/components/NoContent/index.tsx +0 -85
  21. package/src/components/ResponsiveReactGridLayout.tsx +0 -218
  22. package/src/components/SliderDecoration.tsx +0 -27
  23. package/src/components/VisionUserConfigContext.ts +0 -6
  24. package/src/components/WinMenu/README.md +0 -11
  25. package/src/components/WinMenu/WinHeader.tsx +0 -5
  26. package/src/components/WinMenu/components/ExtraBox.tsx +0 -61
  27. package/src/components/WinMenu/components/FullMenuBox.tsx +0 -80
  28. package/src/components/WinMenu/components/FullMenuContainer.tsx +0 -50
  29. package/src/components/WinMenu/components/FullMenuItem.tsx +0 -128
  30. package/src/components/WinMenu/components/LangSwitch.tsx +0 -84
  31. package/src/components/WinMenu/components/LogoBox.tsx +0 -29
  32. package/src/components/WinMenu/components/PinDialog.tsx +0 -72
  33. package/src/components/WinMenu/components/PinnedMenuBox.tsx +0 -183
  34. package/src/components/WinMenu/components/UserBox.tsx +0 -83
  35. package/src/components/WinMenu/hooks/useUserInfo.ts +0 -21
  36. package/src/components/WinMenu/hooks/useUserMenu.ts +0 -35
  37. package/src/components/WinMenu/index.tsx +0 -100
  38. package/src/components/WinMenu/services/WinService.ts +0 -79
  39. package/src/components/WinMenu/services/request.ts +0 -53
  40. package/src/components/WinMenu/utils/const.ts +0 -80
  41. package/src/components/WinMenu/utils/enum.ts +0 -19
  42. package/src/components/WinMenu/utils/interface.ts +0 -61
  43. package/src/components/WinMenu/utils/map.ts +0 -39
  44. package/src/components/WinMenu/utils/tool.ts +0 -142
  45. package/src/components/WinMenu/utils/type.ts +0 -1
  46. package/src/components/hover-view.tsx +0 -48
  47. package/src/components/icon.tsx +0 -44
  48. package/src/components/indicator-remark.tsx +0 -25
  49. package/src/components/none-content.tsx +0 -93
  50. package/src/components/panel-tab.tsx +0 -150
  51. package/src/components/panel-title-tab.tsx +0 -60
  52. package/src/components/win-card/components/ChartContent.tsx +0 -47
  53. package/src/components/win-card/components/Indicator.tsx +0 -42
  54. package/src/components/win-card/components/IndicatorArea.tsx +0 -63
  55. package/src/components/win-card/components/IndicatorInfo.tsx +0 -78
  56. package/src/components/win-card/components/MatterContent.tsx +0 -121
  57. package/src/components/win-card/components/MatterList.tsx +0 -141
  58. package/src/components/win-card/components/NoticeContent.tsx +0 -73
  59. package/src/components/win-card/components/NoticeList.tsx +0 -68
  60. package/src/components/win-card/components/SelectDecoration.tsx +0 -34
  61. package/src/components/win-card/components/WinRankContent.tsx +0 -102
  62. package/src/components/win-card/index.tsx +0 -298
  63. package/src/components/win-card/utils/interface.ts +0 -12
  64. package/src/components/win-card/utils/tool.ts +0 -11
  65. package/src/components/win-card-mobile/components/ChartContent.tsx +0 -47
  66. package/src/components/win-card-mobile/components/DualLineBar.tsx +0 -61
  67. package/src/components/win-card-mobile/components/Indicator.tsx +0 -42
  68. package/src/components/win-card-mobile/components/IndicatorArea.tsx +0 -65
  69. package/src/components/win-card-mobile/components/IndicatorInfo.tsx +0 -83
  70. package/src/components/win-card-mobile/components/SelectDecoration.tsx +0 -28
  71. package/src/components/win-card-mobile/index.tsx +0 -235
  72. package/src/components/win-card-mobile/utils/interface.ts +0 -12
  73. package/src/components/win-card-mobile/utils/tool.ts +0 -9
  74. package/src/components/win-chart/components/chart-wrapper.tsx +0 -5
  75. package/src/components/win-chart/index.tsx +0 -59
  76. package/src/components/win-chart/theme/win-dark.json +0 -372
  77. package/src/components/win-chart/theme/win-light.json +0 -372
  78. package/src/components/win-chart/utils/const.ts +0 -37
  79. package/src/components/win-chart/utils/getAreaSpec.ts +0 -150
  80. package/src/components/win-chart/utils/getBarSpec.ts +0 -60
  81. package/src/components/win-chart/utils/getChartOptions.ts +0 -59
  82. package/src/components/win-chart/utils/getColumnSpec.ts +0 -112
  83. package/src/components/win-chart/utils/getDualSpec.ts +0 -79
  84. package/src/components/win-chart/utils/getFunnelSpec.ts +0 -70
  85. package/src/components/win-chart/utils/getLineSpec.ts +0 -53
  86. package/src/components/win-chart/utils/getPieSpec.ts +0 -124
  87. package/src/components/win-chart/utils/getRadarSpec.ts +0 -87
  88. package/src/components/win-chart/utils/tool.ts +0 -163
  89. package/src/components/win-chart/utils/type.ts +0 -96
  90. package/src/components/win-icon/index.tsx +0 -97
  91. package/src/components/win-v/components/EmptyBox.tsx +0 -9
  92. package/src/components/win-v/components/VDialog.tsx +0 -173
  93. package/src/components/win-v/components/VDialogBtn.tsx +0 -119
  94. package/src/components/win-v/components/VDialogMsg.tsx +0 -325
  95. package/src/components/win-v/components/VInput.tsx +0 -15
  96. package/src/components/win-v/components/VRemindMsgList.tsx +0 -303
  97. package/src/components/win-v/components/VRobot.tsx +0 -97
  98. package/src/components/win-v/hooks/useVDialogCore.ts +0 -102
  99. package/src/components/win-v/hooks/useVDialogOperate.ts +0 -132
  100. package/src/components/win-v/hooks/useVDialogState.ts +0 -52
  101. package/src/components/win-v/hooks/useVRemindMsgShow.ts +0 -15
  102. package/src/components/win-v/index.tsx +0 -205
  103. package/src/components/win-wrappers/card-wrapper.tsx +0 -103
  104. package/src/components/win-wrappers/dot-wrapper.tsx +0 -18
  105. package/src/components/win-wrappers/iframe-wrapper.tsx +0 -7
  106. package/src/components/win-wrappers/request-wrapper.tsx +0 -190
  107. package/src/global.d.ts +0 -53
  108. package/src/hooks/useCardOptionList.ts +0 -23
  109. package/src/hooks/useCostFiltersDicList.ts +0 -22
  110. package/src/hooks/useFbiUrl.ts +0 -22
  111. package/src/hooks/useHalfScreenState.ts +0 -50
  112. package/src/hooks/useHasIntersected.ts +0 -36
  113. package/src/hooks/useIndicatorCardInfo.ts +0 -26
  114. package/src/hooks/useIndicatorCardQueryList.ts +0 -22
  115. package/src/hooks/useIndicatorClassifyList.ts +0 -25
  116. package/src/hooks/useIndicatorDetailsDateList.ts +0 -22
  117. package/src/hooks/useIndicatorDetailsInfo.ts +0 -49
  118. package/src/hooks/useIndicatorDetailsTrend.ts +0 -25
  119. package/src/hooks/useIndicatorDicList.ts +0 -22
  120. package/src/hooks/useIndicatorLabelList.ts +0 -20
  121. package/src/hooks/useIndicatorList.ts +0 -24
  122. package/src/hooks/useIndicatorRangeList.ts +0 -20
  123. package/src/hooks/useIndicatorTypeList.ts +0 -20
  124. package/src/hooks/useIndicatorUnitList.ts +0 -21
  125. package/src/hooks/useListenQuery.ts +0 -29
  126. package/src/hooks/useMobile.ts +0 -58
  127. package/src/hooks/useNotice.ts +0 -42
  128. package/src/hooks/useOrgLevelList.ts +0 -23
  129. package/src/hooks/usePageSelection.ts +0 -121
  130. package/src/hooks/usePageState.ts +0 -22
  131. package/src/hooks/usePendingList.ts +0 -27
  132. package/src/hooks/usePortalPageInfo.ts +0 -43
  133. package/src/hooks/useRefreshByLocationChange.ts +0 -16
  134. package/src/hooks/useReportIndicatorList.ts +0 -21
  135. package/src/hooks/useReportInfo.ts +0 -45
  136. package/src/hooks/useReportPersonList.ts +0 -21
  137. package/src/hooks/useScriptLoader.ts +0 -22
  138. package/src/hooks/useUnreadMsgList.ts +0 -26
  139. package/src/hooks/useUserAvatar.ts +0 -23
  140. package/src/hooks/useVReportInfo.ts +0 -50
  141. package/src/hooks/useVisionUserConfig.ts +0 -25
  142. package/src/hooks/useWorkbenchOptions.ts +0 -63
  143. package/src/index.tsx +0 -20
  144. package/src/services/CardService.ts +0 -91
  145. package/src/services/CommonService.ts +0 -23
  146. package/src/services/CostService.ts +0 -56
  147. package/src/services/DialogService.ts +0 -74
  148. package/src/services/IndicatorService.ts +0 -406
  149. package/src/services/PageService.ts +0 -204
  150. package/src/services/ReportService.ts +0 -335
  151. package/src/services/WorkbenchService.ts +0 -411
  152. package/src/styles/README.md +0 -12
  153. package/src/styles/index.scss +0 -9
  154. package/src/styles/mixins/index.scss +0 -25
  155. package/src/styles/next-cover.scss +0 -4
  156. package/src/styles/normalize.scss +0 -27
  157. package/src/styles/utilities/index.scss +0 -5
  158. package/src/styles/vars/index.scss +0 -17
  159. package/src/types/enum-workbench.ts +0 -29
  160. package/src/types/enum.ts +0 -156
  161. package/src/types/index.ts +0 -19
  162. package/src/types/indicator.ts +0 -299
  163. package/src/types/interface.ts +0 -303
  164. package/src/types/portal.ts +0 -211
  165. package/src/types/report.ts +0 -28
  166. package/src/types/type.ts +0 -11
  167. package/src/types/user.ts +0 -28
  168. package/src/utils/README.md +0 -4
  169. package/src/utils/arms.ts +0 -59
  170. package/src/utils/arr.ts +0 -123
  171. package/src/utils/const-workbench.ts +0 -9
  172. package/src/utils/const.ts +0 -18
  173. package/src/utils/index.ts +0 -18
  174. package/src/utils/init.ts +0 -5
  175. package/src/utils/map-workbench.ts +0 -66
  176. package/src/utils/map.ts +0 -377
  177. package/src/utils/number.ts +0 -101
  178. package/src/utils/page.ts +0 -81
  179. package/src/utils/str.ts +0 -26
  180. package/src/utils/tools.ts +0 -44
  181. package/src/utils/tree.ts +0 -145
  182. package/src/utils/url.ts +0 -40
  183. package/src/utils/util.ts +0 -99
  184. package/src/utils/workbench.ts +0 -25
  185. package/tsconfig.json +0 -33
@@ -1,83 +0,0 @@
1
- import { IStyleProps } from '@/types';
2
- import { ReactNode } from 'react';
3
- import { css, styled } from 'styled-components';
4
- import { UnitWrapper } from 'src/components/win-wrappers/card-wrapper';
5
- import { useHalfScreenDispatch } from '@/hooks/useHalfScreenState';
6
-
7
- interface IProps extends IStyleProps {
8
- label: string;
9
- value: ReactNode;
10
- unit: string;
11
- extraLabel?: string;
12
- extraValue?: ReactNode;
13
- extraValueColor?: string;
14
- jumpUrl?: string;
15
- }
16
-
17
- export const IndicatorInfo = ({
18
- label,
19
- value,
20
- unit,
21
- extraLabel,
22
- extraValue,
23
- extraValueColor,
24
- jumpUrl,
25
- ...args
26
- }: Partial<IProps>) => {
27
- const halfScreenDispatch = useHalfScreenDispatch();
28
-
29
- return (
30
- <div {...args}>
31
- <LabelWrapper>
32
- <div
33
- data-value
34
- onClick={() => {
35
- halfScreenDispatch.setState({
36
- show: true,
37
- src: jumpUrl,
38
- title: '指标详情',
39
- });
40
- }}
41
- style={{
42
- ...(!!jumpUrl && {
43
- cursor: 'pointer',
44
- }),
45
- }}
46
- >
47
- {value}
48
- </div>
49
- {!!unit && <UnitWrapper>({unit})</UnitWrapper>}
50
- </LabelWrapper>
51
- </div>
52
- );
53
- };
54
-
55
- const LabelWrapper = styled.div<{ unit?: string }>`
56
- line-height: 1;
57
- margin-bottom: 0.08rem;
58
-
59
- [data-label] {
60
- width: 106px;
61
- font-size: 0.32rem;
62
- font-weight: 600;
63
- margin-bottom: 0.08rem;
64
- display: flex;
65
-
66
- ${(props) =>
67
- !!props.unit &&
68
- css`
69
- &::after {
70
- content: '(${props.unit})';
71
- display: inline-block;
72
- color: #6d7a90;
73
- }
74
- `}
75
- }
76
-
77
- [data-value] {
78
- font-size: 0.56rem;
79
- font-weight: 700;
80
- color: #000;
81
- margin-bottom: 0.08rem;
82
- }
83
- `;
@@ -1,28 +0,0 @@
1
- import { IListItem } from '@/types';
2
- import { CnSelect } from '@cainiaofe/cn-ui-m';
3
- import { css, styled } from 'styled-components';
4
-
5
- export const IndicatorSelectDecoration = styled(CnSelect).attrs({
6
- size: 'small',
7
- showSearch: true,
8
- style: {
9
- width: '2rem',
10
- },
11
- })<{ dataSource?: IListItem[]; $right?: boolean }>`
12
- .cn-ui-m-selectdrawer-content {
13
- padding-left: 0;
14
- cursor: pointer;
15
-
16
- div {
17
- white-space: nowrap;
18
- overflow: hidden;
19
- text-overflow: ellipsis;
20
- }
21
- }
22
-
23
- ${(props) =>
24
- props.$right &&
25
- css`
26
- transform: translateY(-0.08rem);
27
- `}
28
- `;
@@ -1,235 +0,0 @@
1
- import { IndicatorService } from 'src/services/IndicatorService';
2
- import { IIndicatorCardConfig } from '@/types';
3
- import { IndicatorArea } from './components/IndicatorArea';
4
- import { RequestWrapper } from '../win-wrappers/request-wrapper';
5
- import {
6
- CardTitleWrapperMobile,
7
- CardWrapperMobile,
8
- } from '../win-wrappers/card-wrapper';
9
- import { WinCardChartType } from 'src/types/enum';
10
- import { INDICATOR_CONFIG_BASE_URL } from '../../utils/const';
11
- import { Indicator } from './components/Indicator';
12
- import { CnBox } from '@cainiaofe/cn-ui';
13
- import { IndicatorSelectDecoration } from './components/SelectDecoration';
14
- import { getListLabel, unitList } from 'src/utils';
15
- import { useContext, useEffect, useRef, useState } from 'react';
16
- import { HoverView } from '../hover-view';
17
- import { useCardOptionList } from 'src/hooks/useCardOptionList';
18
- import { VisionUserConfigContext } from '../VisionUserConfigContext';
19
- import { ChartContent } from './components/ChartContent';
20
- import { WinChartType } from 'src/components/win-chart';
21
- import { useInViewport } from 'ahooks';
22
-
23
- interface IProps {
24
- id: number;
25
- config?: IIndicatorCardConfig;
26
- }
27
-
28
- export const WidCardMobile = ({ id, config }: IProps) => {
29
- if (config) {
30
- return <ShowCard configData={config} />;
31
- }
32
-
33
- return (
34
- <RequestWrapper
35
- requestData={{ url: `${INDICATOR_CONFIG_BASE_URL}?id=${id}` }}
36
- service={IndicatorService.getConfigInfo}
37
- style={{
38
- width: '100%',
39
- height: '100%',
40
- }}
41
- >
42
- {(configData) => {
43
- return <ShowCard configData={configData} />;
44
- }}
45
- </RequestWrapper>
46
- );
47
- };
48
-
49
- const ShowCard = ({ configData }: { configData: IIndicatorCardConfig }) => {
50
- const ref = useRef<HTMLDivElement>(null);
51
- const [inViewport] = useInViewport(ref);
52
- const [shouldInit, setShouldInit] = useState(false);
53
- const orgLevelList = useCardOptionList(
54
- shouldInit && configData.commonConfig.orgLevel ? configData.id : undefined,
55
- );
56
- const [curOrgLevelValue, setCurOrgLevelValue] = useState<string>();
57
- const isSingleIndicator = configData.chartType === WinCardChartType.INDICATOR;
58
- const hasOrgLevel = !!configData.commonConfig.orgLevel;
59
- const isCommonTitle = ![WinCardChartType.CUSTOM_CARD].includes(
60
- configData.chartType,
61
- );
62
- const visionUserConfig = useContext(VisionUserConfigContext);
63
- const hasInitOrgLevelRef = useRef(false);
64
-
65
- useEffect(() => {
66
- if (inViewport) {
67
- setShouldInit(true);
68
- }
69
- }, [inViewport]);
70
-
71
- useEffect(() => {
72
- if (orgLevelList.length !== 0 && visionUserConfig) {
73
- const configOrgLevelVal =
74
- visionUserConfig[configData.commonConfig.orgLevel];
75
- const valueInList = orgLevelList
76
- .map((item) => item.value)
77
- .includes(configOrgLevelVal);
78
-
79
- if (!hasInitOrgLevelRef.current) {
80
- // 第一次赋值
81
- setCurOrgLevelValue(
82
- valueInList ? configOrgLevelVal : orgLevelList[0].value,
83
- );
84
- hasInitOrgLevelRef.current = true;
85
- } else {
86
- // 用户配置切换赋值
87
- if (valueInList) {
88
- setCurOrgLevelValue(configOrgLevelVal);
89
- }
90
- }
91
- }
92
- }, [configData.commonConfig.orgLevel, orgLevelList, visionUserConfig]);
93
-
94
- // 单位
95
- const unit = getListLabel(unitList, configData.indicatorConfig[0]?.unit);
96
-
97
- return (
98
- <CardWrapperMobile ref={ref}>
99
- <CnBox direction="row" justify="space-between">
100
- {isCommonTitle ? (
101
- <CardTitleWrapperMobile
102
- data-card-id={configData.id}
103
- style={{
104
- maxWidth: isSingleIndicator || !hasOrgLevel ? '80%' : '45%',
105
- position: 'relative',
106
- ...([
107
- WinCardChartType.INDICATOR,
108
- WinCardChartType.INDICATOR_AREA,
109
- ].includes(configData.chartType) && {
110
- fontSize: '0.24rem',
111
- fontWeight: 500,
112
- }),
113
- }}
114
- >
115
- <HoverView content={configData.name} />
116
- </CardTitleWrapperMobile>
117
- ) : (
118
- <div />
119
- )}
120
- <CnBox spacing={16} direction="row" align="center">
121
- {hasOrgLevel && !isSingleIndicator && (
122
- <IndicatorSelectDecoration
123
- $right
124
- value={curOrgLevelValue}
125
- dataSource={orgLevelList}
126
- onChange={setCurOrgLevelValue}
127
- />
128
- )}
129
- </CnBox>
130
- </CnBox>
131
- {getShowContent({
132
- configData,
133
- hasOrgLevel,
134
- orgLevelVal: curOrgLevelValue,
135
- unit,
136
- })}
137
- {isSingleIndicator && (
138
- <div style={{ height: 32 }}>
139
- {hasOrgLevel && (
140
- <IndicatorSelectDecoration
141
- value={curOrgLevelValue}
142
- dataSource={orgLevelList}
143
- onChange={setCurOrgLevelValue}
144
- />
145
- )}
146
- </div>
147
- )}
148
- </CardWrapperMobile>
149
- );
150
- };
151
-
152
- const getShowContent = ({
153
- configData,
154
- hasOrgLevel,
155
- orgLevelVal,
156
- unit,
157
- }: {
158
- configData: IIndicatorCardConfig;
159
- orgLevelVal?: string;
160
- unit?: string;
161
- hasOrgLevel: boolean;
162
- }) => {
163
- const data = {
164
- configData,
165
- orgLevelVal,
166
- unit,
167
- };
168
-
169
- if (hasOrgLevel && !orgLevelVal) {
170
- return null;
171
- }
172
-
173
- switch (configData.chartType) {
174
- case WinCardChartType.INDICATOR:
175
- return <Indicator {...data} />;
176
-
177
- case WinCardChartType.INDICATOR_AREA:
178
- return <IndicatorArea {...data} />;
179
-
180
- case WinCardChartType.DUAL_LINE_BAR_CHART:
181
- return (
182
- <ChartContent winChartType={WinChartType.DUAL_LINE_BAR} {...data} />
183
- );
184
-
185
- case WinCardChartType.AREA_CHART:
186
- return <ChartContent winChartType={WinChartType.AREA} {...data} />;
187
-
188
- case WinCardChartType.LINE_CHART:
189
- return <ChartContent winChartType={WinChartType.LINE} {...data} />;
190
-
191
- case WinCardChartType.COLUMN_CHART:
192
- return <ChartContent winChartType={WinChartType.COLUMN} {...data} />;
193
-
194
- case WinCardChartType.STACK_COLUMN_CHART:
195
- return (
196
- <ChartContent winChartType={WinChartType.STACK_COLUMN} {...data} />
197
- );
198
-
199
- case WinCardChartType.FUNNEL_CHART:
200
- return <ChartContent winChartType={WinChartType.FUNNEL} {...data} />;
201
-
202
- case WinCardChartType.BAR_CHART:
203
- return <ChartContent winChartType={WinChartType.BAR} {...data} />;
204
-
205
- case WinCardChartType.PIE_CHART:
206
- return <ChartContent winChartType={WinChartType.PIE} {...data} />;
207
-
208
- case WinCardChartType.PIE_CHART_RESERVE:
209
- return (
210
- <ChartContent
211
- reserveValueWithLabelType
212
- winChartType={WinChartType.PIE}
213
- {...data}
214
- />
215
- );
216
-
217
- case WinCardChartType.RADAR_CHART:
218
- return <ChartContent winChartType={WinChartType.RADAR} {...data} />;
219
-
220
- case WinCardChartType.RADAR_CHART_RESERVE:
221
- return (
222
- <ChartContent
223
- reserveValueWithLabelType
224
- winChartType={WinChartType.RADAR}
225
- {...data}
226
- />
227
- );
228
-
229
- case WinCardChartType.CYCLE_CHART:
230
- return <ChartContent winChartType={WinChartType.CYCLE} {...data} />;
231
-
232
- default:
233
- return undefined;
234
- }
235
- };
@@ -1,12 +0,0 @@
1
- import { IIndicatorCardConfig } from '@/types';
2
- import { CSSProperties } from 'react';
3
-
4
- export interface IContentProps {
5
- configData: IIndicatorCardConfig;
6
- theme?: string;
7
- orgLevelVal?: string;
8
- unit?: string;
9
- extraCondition?: {
10
- [p: string]: string;
11
- };
12
- }
@@ -1,9 +0,0 @@
1
- export const getExtraLabel = (subTitle?: number) => {
2
- switch (subTitle) {
3
- case 1:
4
- return '目标';
5
-
6
- default:
7
- return undefined;
8
- }
9
- };
@@ -1,5 +0,0 @@
1
- import { styled } from 'styled-components';
2
-
3
- export const ChartWrapper = styled.div`
4
- height: 100%;
5
- `;
@@ -1,59 +0,0 @@
1
- import { ChartWrapper } from './components/chart-wrapper';
2
- import { IWinChartProps } from './utils/type';
3
- import { useRef, useEffect, useState } from 'react';
4
- import { getEChartOptions } from './utils/getChartOptions';
5
- import * as echarts from 'echarts';
6
- import { commonOpt } from './utils/const';
7
- import { debounce } from './utils/tool';
8
- import light from './theme/win-light.json';
9
- import dark from './theme/win-dark.json';
10
- import deepMerge from 'deepmerge';
11
-
12
- export * from './utils/const';
13
- export * from './utils/type';
14
-
15
- echarts.registerTheme('light', deepMerge(light, commonOpt));
16
- echarts.registerTheme('dark', deepMerge(dark, commonOpt));
17
-
18
- export const WinChart = ({
19
- className,
20
- style,
21
- extraOption,
22
- theme = 'light',
23
- ...args
24
- }: IWinChartProps) => {
25
- const boxRef = useRef<HTMLDivElement>(null);
26
- const [eChart, setEChart] = useState<echarts.ECharts>();
27
- const argsStr = JSON.stringify(args);
28
- const extraOptionStr = JSON.stringify(extraOption ?? {});
29
-
30
- // 生成实例
31
- useEffect(() => {
32
- const eChart = echarts.init(boxRef.current, theme);
33
- setEChart(eChart);
34
-
35
- // 监听窗口变化
36
- const resize = debounce(eChart.resize, 500);
37
- globalThis.addEventListener('resize', () => {
38
- resize();
39
- });
40
- }, [theme]);
41
-
42
- // 设置配置
43
- useEffect(() => {
44
- if (eChart) {
45
- eChart.setOption(
46
- deepMerge(
47
- getEChartOptions(JSON.parse(argsStr)),
48
- JSON.parse(extraOptionStr),
49
- ),
50
- );
51
-
52
- setTimeout(() => {
53
- eChart.resize();
54
- }, 500);
55
- }
56
- }, [argsStr, eChart, extraOptionStr]);
57
-
58
- return <ChartWrapper ref={boxRef} className={className} style={style} />;
59
- };