@creekjs/web-components 1.0.5 → 1.0.6

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 (164) hide show
  1. package/.turbo/turbo-father$colon$build.log +35 -19
  2. package/README.md +97 -18
  3. package/dist/creek-config-provider/CreekConfigContext.d.ts +4 -0
  4. package/dist/creek-config-provider/CreekConfigContext.d.ts.map +1 -1
  5. package/dist/creek-config-provider/CreekConfigContext.js.map +2 -2
  6. package/dist/creek-config-provider/CreekI18nProvider.d.ts +22 -0
  7. package/dist/creek-config-provider/CreekI18nProvider.d.ts.map +1 -0
  8. package/dist/creek-config-provider/CreekI18nProvider.js +92 -0
  9. package/dist/creek-config-provider/CreekI18nProvider.js.map +7 -0
  10. package/dist/creek-config-provider/index.d.ts +5 -3
  11. package/dist/creek-config-provider/index.d.ts.map +1 -1
  12. package/dist/creek-config-provider/index.js +47 -4
  13. package/dist/creek-config-provider/index.js.map +3 -3
  14. package/dist/creek-hooks/useApp/index.d.ts +3 -3
  15. package/dist/creek-keep-alive/index.d.ts +24 -1
  16. package/dist/creek-keep-alive/index.d.ts.map +1 -1
  17. package/dist/creek-keep-alive/index.js +141 -4
  18. package/dist/creek-keep-alive/index.js.map +2 -2
  19. package/dist/creek-layout/ActionRender/FullScreen.d.ts.map +1 -1
  20. package/dist/creek-layout/ActionRender/FullScreen.js +3 -1
  21. package/dist/creek-layout/ActionRender/FullScreen.js.map +2 -2
  22. package/dist/creek-layout/ActionRender/LayoutSettings.d.ts +5 -0
  23. package/dist/creek-layout/ActionRender/LayoutSettings.d.ts.map +1 -0
  24. package/dist/creek-layout/ActionRender/LayoutSettings.js +73 -0
  25. package/dist/creek-layout/ActionRender/LayoutSettings.js.map +7 -0
  26. package/dist/creek-layout/ActionRender/UserInfo.js.map +2 -2
  27. package/dist/creek-layout/ActionRender/index.d.ts +1 -0
  28. package/dist/creek-layout/ActionRender/index.d.ts.map +1 -1
  29. package/dist/creek-layout/ActionRender/index.js +3 -0
  30. package/dist/creek-layout/ActionRender/index.js.map +2 -2
  31. package/dist/creek-layout/index.d.ts +5 -5
  32. package/dist/creek-layout/index.d.ts.map +1 -1
  33. package/dist/creek-layout/index.js +79 -16
  34. package/dist/creek-layout/index.js.map +3 -3
  35. package/dist/creek-layout/useLayoutSettingsStore.d.ts +20 -0
  36. package/dist/creek-layout/useLayoutSettingsStore.d.ts.map +1 -0
  37. package/dist/creek-layout/useLayoutSettingsStore.js +45 -0
  38. package/dist/creek-layout/useLayoutSettingsStore.js.map +7 -0
  39. package/dist/creek-locale-button/index.d.ts +1 -0
  40. package/dist/creek-locale-button/index.d.ts.map +1 -0
  41. package/dist/creek-locale-button/index.js +66 -0
  42. package/dist/creek-locale-button/index.js.map +7 -0
  43. package/dist/creek-page-container/index.d.ts +4 -0
  44. package/dist/creek-page-container/index.d.ts.map +1 -0
  45. package/dist/creek-page-container/index.js +68 -0
  46. package/dist/creek-page-container/index.js.map +7 -0
  47. package/dist/creek-style/index.d.ts +1 -0
  48. package/dist/creek-style/index.d.ts.map +1 -0
  49. package/dist/creek-style/index.js +24 -0
  50. package/dist/creek-style/index.js.map +7 -0
  51. package/dist/creek-style/scrollbar.d.ts +2 -0
  52. package/dist/creek-style/scrollbar.d.ts.map +1 -0
  53. package/dist/creek-style/scrollbar.js +55 -0
  54. package/dist/creek-style/scrollbar.js.map +7 -0
  55. package/dist/creek-table/SearchTable.d.ts +9 -0
  56. package/dist/creek-table/SearchTable.d.ts.map +1 -1
  57. package/dist/creek-table/SearchTable.js +109 -72
  58. package/dist/creek-table/SearchTable.js.map +3 -3
  59. package/dist/creek-table/components/DensityIcon.d.ts +9 -0
  60. package/dist/creek-table/components/DensityIcon.d.ts.map +1 -0
  61. package/dist/creek-table/components/DensityIcon.js +77 -0
  62. package/dist/creek-table/components/DensityIcon.js.map +7 -0
  63. package/dist/creek-table/components/EllipsisTooltip.d.ts +9 -0
  64. package/dist/creek-table/components/EllipsisTooltip.d.ts.map +1 -0
  65. package/dist/creek-table/components/EllipsisTooltip.js +122 -0
  66. package/dist/creek-table/components/EllipsisTooltip.js.map +7 -0
  67. package/dist/creek-table/components/index.d.ts +2 -0
  68. package/dist/creek-table/components/index.d.ts.map +1 -0
  69. package/dist/creek-table/components/index.js +26 -0
  70. package/dist/creek-table/components/index.js.map +7 -0
  71. package/dist/creek-table/hooks/index.d.ts +5 -0
  72. package/dist/creek-table/hooks/index.d.ts.map +1 -1
  73. package/dist/creek-table/hooks/index.js +10 -0
  74. package/dist/creek-table/hooks/index.js.map +2 -2
  75. package/dist/creek-table/hooks/useAutoWidthColumns.d.ts +1 -1
  76. package/dist/creek-table/hooks/useAutoWidthColumns.d.ts.map +1 -1
  77. package/dist/creek-table/hooks/useAutoWidthColumns.js +76 -17
  78. package/dist/creek-table/hooks/useAutoWidthColumns.js.map +2 -2
  79. package/dist/creek-table/hooks/useEllipsisColumns.d.ts +8 -0
  80. package/dist/creek-table/hooks/useEllipsisColumns.d.ts.map +1 -0
  81. package/dist/creek-table/hooks/useEllipsisColumns.js +58 -0
  82. package/dist/creek-table/hooks/useEllipsisColumns.js.map +7 -0
  83. package/dist/creek-table/hooks/useIndexColumn.d.ts +2 -0
  84. package/dist/creek-table/hooks/useIndexColumn.d.ts.map +1 -0
  85. package/dist/creek-table/hooks/useIndexColumn.js +52 -0
  86. package/dist/creek-table/hooks/useIndexColumn.js.map +7 -0
  87. package/dist/creek-table/hooks/useResizableColumns.d.ts +20 -0
  88. package/dist/creek-table/hooks/useResizableColumns.d.ts.map +1 -0
  89. package/dist/creek-table/hooks/useResizableColumns.js +279 -0
  90. package/dist/creek-table/hooks/useResizableColumns.js.map +7 -0
  91. package/dist/creek-table/hooks/useStatusColumns.d.ts +2 -0
  92. package/dist/creek-table/hooks/useStatusColumns.d.ts.map +1 -0
  93. package/dist/creek-table/hooks/useStatusColumns.js +215 -0
  94. package/dist/creek-table/hooks/useStatusColumns.js.map +7 -0
  95. package/dist/creek-table/hooks/useTableOptions.d.ts +15 -0
  96. package/dist/creek-table/hooks/useTableOptions.d.ts.map +1 -0
  97. package/dist/creek-table/hooks/useTableOptions.js +78 -0
  98. package/dist/creek-table/hooks/useTableOptions.js.map +7 -0
  99. package/dist/creek-table/hooks/useTableScrollHeight.d.ts +6 -1
  100. package/dist/creek-table/hooks/useTableScrollHeight.d.ts.map +1 -1
  101. package/dist/creek-table/hooks/useTableScrollHeight.js +44 -5
  102. package/dist/creek-table/hooks/useTableScrollHeight.js.map +2 -2
  103. package/dist/creek-table/type.d.ts +4 -6
  104. package/dist/creek-table/type.d.ts.map +1 -1
  105. package/dist/creek-table/type.js.map +1 -1
  106. package/dist/index.d.ts +4 -0
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +8 -0
  109. package/dist/index.js.map +2 -2
  110. package/dist/locales/en-US.d.ts +25 -0
  111. package/dist/locales/en-US.d.ts.map +1 -0
  112. package/dist/locales/en-US.js +49 -0
  113. package/dist/locales/en-US.js.map +7 -0
  114. package/dist/locales/zh-CN.d.ts +25 -0
  115. package/dist/locales/zh-CN.d.ts.map +1 -0
  116. package/dist/locales/zh-CN.js +49 -0
  117. package/dist/locales/zh-CN.js.map +7 -0
  118. package/dist/utils/i18n.d.ts +2 -0
  119. package/dist/utils/i18n.d.ts.map +1 -0
  120. package/dist/utils/i18n.js +34 -0
  121. package/dist/utils/i18n.js.map +7 -0
  122. package/i18n.config.ts +27 -0
  123. package/package.json +17 -3
  124. package/src/creek-config-provider/CreekConfigContext.tsx +5 -1
  125. package/src/creek-config-provider/CreekI18nProvider.tsx +87 -0
  126. package/src/creek-config-provider/index.tsx +53 -4
  127. package/src/creek-keep-alive/index.tsx +225 -6
  128. package/src/creek-layout/ActionRender/FullScreen.tsx +10 -6
  129. package/src/creek-layout/ActionRender/LayoutSettings.tsx +67 -0
  130. package/src/creek-layout/ActionRender/UserInfo.tsx +1 -1
  131. package/src/creek-layout/ActionRender/index.tsx +1 -0
  132. package/src/creek-layout/index.tsx +89 -22
  133. package/src/creek-layout/useLayoutSettingsStore.ts +25 -0
  134. package/src/creek-locale-button/index.tsx +42 -0
  135. package/src/creek-page-container/index.tsx +32 -0
  136. package/src/creek-style/index.ts +1 -0
  137. package/src/creek-style/scrollbar.ts +29 -0
  138. package/src/creek-table/SearchTable.tsx +125 -72
  139. package/src/creek-table/components/DensityIcon.tsx +63 -0
  140. package/src/creek-table/components/EllipsisTooltip.tsx +116 -0
  141. package/src/creek-table/components/index.tsx +3 -0
  142. package/src/creek-table/hooks/index.ts +5 -1
  143. package/src/creek-table/hooks/useAutoWidthColumns.tsx +93 -19
  144. package/src/creek-table/hooks/useEllipsisColumns.tsx +47 -0
  145. package/src/creek-table/hooks/useIndexColumn.tsx +27 -0
  146. package/src/creek-table/hooks/useResizableColumns.tsx +323 -0
  147. package/src/creek-table/hooks/useStatusColumns.tsx +252 -0
  148. package/src/creek-table/hooks/useTableOptions.tsx +81 -0
  149. package/src/creek-table/hooks/useTableScrollHeight.tsx +61 -6
  150. package/src/creek-table/type.ts +5 -7
  151. package/src/index.tsx +4 -0
  152. package/src/locales/en-US.ts +24 -0
  153. package/src/locales/zh-CN.ts +24 -0
  154. package/src/utils/i18n.ts +4 -0
  155. package/dist/creek-table/TableOptionRender.d.ts +0 -9
  156. package/dist/creek-table/TableOptionRender.d.ts.map +0 -1
  157. package/dist/creek-table/TableOptionRender.js +0 -74
  158. package/dist/creek-table/TableOptionRender.js.map +0 -7
  159. package/dist/creek-table/toolBarRender.d.ts +0 -5
  160. package/dist/creek-table/toolBarRender.d.ts.map +0 -1
  161. package/dist/creek-table/toolBarRender.js +0 -58
  162. package/dist/creek-table/toolBarRender.js.map +0 -7
  163. package/src/creek-table/TableOptionRender.tsx +0 -57
  164. package/src/creek-table/toolBarRender.tsx +0 -28
@@ -1,36 +1,68 @@
1
1
  import { ProLayout, ProLayoutProps } from '@ant-design/pro-components';
2
2
  import { useMemoizedFn } from 'ahooks';
3
3
  import { theme } from 'antd';
4
+ import _ from 'lodash';
5
+
4
6
  import classnames from 'classnames';
5
7
 
6
- import { FullScreen, UserInfo } from './ActionRender';
8
+ import { useT } from '@creekjs/i18n/react';
9
+
10
+ import { CreekKeepAlive, CreekKeepAliveProps } from '../creek-keep-alive';
11
+ import { CreekLocaleButton } from '../creek-locale-button';
12
+ import { GlobalScrollbarStyle } from '../creek-style/scrollbar';
13
+ import { FullScreen, LayoutSettings } from './ActionRender';
7
14
  import { CollapsedButton, useCollapsedStore } from './CollapseButton';
8
15
  import { Exception } from './Exception';
16
+ import { useLayoutSettingsStore } from './useLayoutSettingsStore';
9
17
 
10
18
  export type LayoutProps = ProLayoutProps & {
11
19
  runtimeConfig: ProLayoutProps;
12
20
  userConfig?: ProLayoutProps;
13
21
  navigate?: (path?: string | number) => void;
14
22
  showFullScreen?: boolean;
15
- userInfo?: {
16
- name?: React.ReactNode;
17
- avatar?: string;
18
- menu?: any;
19
- };
23
+ showLocaleButton?: boolean;
24
+ showSettingsButton?: boolean;
20
25
  initialInfo?: {
21
26
  initialState: any;
22
27
  loading: boolean;
23
28
  setInitialState: () => void;
24
29
  };
30
+ keepAlive?: boolean | CreekKeepAliveProps;
31
+ extraActions?: React.ReactNode[];
32
+ };
33
+
34
+ const MenuName = ({ name, path }: { name: string; path?: string }) => {
35
+ const t = useT();
36
+ const key = !path || path === '/' ? 'menu.home' : `menu${path.replace(/\//g, '.')}`;
37
+ return <>{t(key, name)}</>;
25
38
  };
26
39
 
27
40
  export const CreekLayout = (props: LayoutProps) => {
28
- const { route, userConfig, runtimeConfig, children, location, navigate, showFullScreen, userInfo, ...more } = props;
41
+ const { route, userConfig, runtimeConfig, children, location, navigate, showFullScreen, showLocaleButton = true, showSettingsButton = true, keepAlive = true, extraActions = [], ...more } = props;
29
42
 
30
43
  const { useToken } = theme;
31
44
  const { token } = useToken();
32
45
 
33
46
  const { collapsed } = useCollapsedStore();
47
+ const settingsStore = useLayoutSettingsStore();
48
+
49
+ const actualShowFullScreen = settingsStore.showFullScreen ?? showFullScreen ?? false;
50
+ const actualShowLocaleButton = settingsStore.showLocaleButton ?? showLocaleButton ?? true;
51
+ const colorPrimary = settingsStore.colorPrimary || token.colorPrimary;
52
+ const actualKeepAlive = settingsStore.keepAlive ?? keepAlive ?? true;
53
+
54
+ const menuDataRender = useMemoizedFn((menuData: any[]) => {
55
+ const mapMenu = (items: any[]): any[] => {
56
+ return items.map((item) => {
57
+ return {
58
+ ...item,
59
+ name: <MenuName name={item.name} path={item.path} />,
60
+ children: item.children ? mapMenu(item.children) : undefined,
61
+ };
62
+ });
63
+ };
64
+ return mapMenu(menuData);
65
+ });
34
66
 
35
67
  const menuItemRender: ProLayoutProps['menuItemRender'] = useMemoizedFn((itemProps, defaultDom) => {
36
68
  return (
@@ -46,41 +78,73 @@ export const CreekLayout = (props: LayoutProps) => {
46
78
  );
47
79
  });
48
80
 
49
- const actions: React.ReactNode[] = [];
50
- if (showFullScreen) {
81
+ const getTabTitle = useMemoizedFn((pathname: string) => {
82
+ const findTitle = (routes: any[]): string | React.ReactNode | undefined => {
83
+ for (const r of routes) {
84
+ if (r.path === pathname) return r.name || r.title;
85
+ if (r.children) {
86
+ const found = findTitle(r.children);
87
+ if (found) return found;
88
+ }
89
+ }
90
+ return undefined;
91
+ };
92
+ return findTitle(route?.routes || []) || pathname;
93
+ });
94
+
95
+ const actions: React.ReactNode[] = [...extraActions];
96
+
97
+ if (actualShowFullScreen) {
51
98
  actions.push(<FullScreen key="full-screen" />);
52
99
  }
53
- if (userInfo) {
54
- actions.push(<UserInfo key="user-info" {...userInfo} />);
100
+
101
+ if (actualShowLocaleButton) {
102
+ actions.push(<CreekLocaleButton key="locale-button" />);
55
103
  }
56
104
 
57
- return (
105
+ if (showSettingsButton) {
106
+ actions.push(
107
+ <LayoutSettings
108
+ key="settings"
109
+ defaultShowFullScreen={showFullScreen}
110
+ defaultShowLocaleButton={showLocaleButton}
111
+ defaultKeepAlive={_.isBoolean(keepAlive) ? keepAlive : true}
112
+ />
113
+ );
114
+ }
115
+
116
+ const keepAliveProps = _.isBoolean(keepAlive) ? {} : keepAlive;
117
+
118
+ const _userConfig = { ...userConfig, ...runtimeConfig };
119
+
120
+ const layoutContent = (
58
121
  <ProLayout
59
- className={classnames('creek-layout-container', userConfig?.className)}
122
+ className={classnames('creek-layout-container', _userConfig?.className)}
60
123
  route={route}
61
- title={userConfig?.title}
62
- siderWidth={212}
124
+ title={_userConfig?.title}
125
+ siderWidth={200}
63
126
  location={location}
127
+ menuDataRender={menuDataRender}
64
128
  menuItemRender={menuItemRender}
65
129
  actionsRender={() => actions}
66
130
  token={{
67
131
  header: {
68
132
  colorBgHeader: '#fff',
69
133
  colorHeaderTitle: 'rgba(0, 0, 0, 0.80);',
70
- colorTextMenuSelected: token.colorPrimary,
134
+ colorTextMenuSelected: colorPrimary,
71
135
  heightLayoutHeader: 48,
72
136
  },
73
137
  sider: {
74
138
  colorMenuBackground: '#f7f8fa',
75
139
  colorBgMenuItemSelected: 'transparent',
76
- colorTextMenuActive: token.colorPrimary,
77
- colorTextMenuSelected: token.colorPrimary,
78
- colorTextMenuItemHover: token.colorPrimary,
140
+ colorTextMenuActive: colorPrimary,
141
+ colorTextMenuSelected: colorPrimary,
142
+ colorTextMenuItemHover: colorPrimary,
79
143
  colorTextMenu: '#333',
80
144
  },
81
145
  pageContainer: {
82
- paddingBlockPageContainerContent: token.padding,
83
- paddingInlinePageContainerContent: token.padding,
146
+ paddingBlockPageContainerContent: 0,
147
+ paddingInlinePageContainerContent: 0,
84
148
  colorBgPageContainer: 'linear-gradient(180deg, #F7F9FF 0%, #FFF 45.59%);',
85
149
  },
86
150
  }}
@@ -92,9 +156,12 @@ export const CreekLayout = (props: LayoutProps) => {
92
156
  }}
93
157
  {...more}
94
158
  >
95
- <Exception>{children}</Exception>
159
+ <GlobalScrollbarStyle />
160
+ <Exception>{actualKeepAlive ? <CreekKeepAlive getTabTitle={getTabTitle} {...keepAliveProps} /> : children}</Exception>
96
161
  </ProLayout>
97
162
  );
163
+
164
+ return layoutContent;
98
165
  };
99
166
 
100
167
  export * from './Exception';
@@ -0,0 +1,25 @@
1
+ import { create } from 'zustand';
2
+ import { persist } from 'zustand/middleware';
3
+
4
+ export type LayoutSettingsStore = {
5
+ colorPrimary?: string;
6
+ showFullScreen?: boolean;
7
+ showLocaleButton?: boolean;
8
+ keepAlive?: boolean;
9
+ setSettings: (settings: Partial<LayoutSettingsStore>) => void;
10
+ };
11
+
12
+ export const useLayoutSettingsStore = create<LayoutSettingsStore>()(
13
+ persist(
14
+ (set) => ({
15
+ colorPrimary: undefined,
16
+ showFullScreen: true,
17
+ showLocaleButton: true,
18
+ keepAlive: true,
19
+ setSettings: (settings) => set((state) => ({ ...state, ...settings })),
20
+ }),
21
+ {
22
+ name: 'creek-layout-settings',
23
+ }
24
+ )
25
+ );
@@ -0,0 +1,42 @@
1
+ import { GlobalOutlined } from '@ant-design/icons';
2
+ import { Dropdown, Space, Typography } from 'antd';
3
+
4
+ import { useT } from '@creekjs/i18n/react';
5
+
6
+ import { useAppLocale } from '../creek-config-provider';
7
+
8
+ export const CreekLocaleButton = () => {
9
+ const t = useT();
10
+
11
+ const { locale, changeLocale } = useAppLocale();
12
+
13
+ const items = [
14
+ {
15
+ key: 'zh-CN',
16
+ label: t('creek-locale-button.index.jianTiZhongWen', '简体中文'),
17
+ disabled: locale === 'zh-CN',
18
+ },
19
+ {
20
+ key: 'en-US',
21
+ label: 'English',
22
+ disabled: locale === 'en-US',
23
+ },
24
+ ];
25
+
26
+ const currentLabel = items.find((item) => item.key === locale)?.label || 'Language';
27
+
28
+ return (
29
+ <Dropdown
30
+ menu={{
31
+ items,
32
+ onClick: (e) => changeLocale(e.key),
33
+ }}
34
+ placement="bottomRight"
35
+ >
36
+ <Space size="small" align="center">
37
+ <GlobalOutlined />
38
+ <Typography.Text>{currentLabel}</Typography.Text>
39
+ </Space>
40
+ </Dropdown>
41
+ );
42
+ };
@@ -0,0 +1,32 @@
1
+ import { PageContainer, PageContainerProps } from '@ant-design/pro-components';
2
+ import { createStyles } from 'antd-style';
3
+ import React from 'react';
4
+
5
+ import classnames from 'classnames';
6
+
7
+ const useStyles = createStyles(({ token }) => ({
8
+ container: {
9
+ padding: token.padding,
10
+ },
11
+ }));
12
+
13
+ export type CreekPageContainerProps = PageContainerProps;
14
+
15
+ export const CreekPageContainer: React.FC<CreekPageContainerProps> = (props) => {
16
+ const { header, className, children, ...rest } = props;
17
+ const { styles } = useStyles();
18
+
19
+ return (
20
+ <PageContainer
21
+ header={{
22
+ title: null, // 默认没有标题
23
+ breadcrumb: {}, // 保留面包屑配置能力
24
+ ...header, // 允许外部覆盖
25
+ }}
26
+ className={classnames(styles.container, className)}
27
+ {...rest}
28
+ >
29
+ {children}
30
+ </PageContainer>
31
+ );
32
+ };
@@ -0,0 +1 @@
1
+ export * from './scrollbar';
@@ -0,0 +1,29 @@
1
+ import { createGlobalStyle } from 'antd-style';
2
+
3
+ export const GlobalScrollbarStyle = createGlobalStyle(({ theme: token }) => {
4
+ return {
5
+ '*': {
6
+ scrollbarWidth: 'auto',
7
+ scrollbarColor: `${token.colorFillSecondary} transparent !important`,
8
+ },
9
+ /* Webkit (Chrome, Safari, Edge) 滚动条样式 */
10
+ '& *::-webkit-scrollbar': {
11
+ width: '6px !important',
12
+ height: '6px !important',
13
+ backgroundColor: 'transparent !important',
14
+ },
15
+
16
+ '& *::-webkit-scrollbar-thumb': {
17
+ backgroundColor: `${token.colorFillSecondary} !important`,
18
+ borderRadius: '3px !important',
19
+ transition: 'all 0.3s',
20
+ '&:hover': {
21
+ backgroundColor: `${token.colorFill} !important`,
22
+ },
23
+ },
24
+
25
+ '& *::-webkit-scrollbar-track': {
26
+ backgroundColor: 'transparent !important',
27
+ },
28
+ };
29
+ });
@@ -1,106 +1,159 @@
1
1
  import { ParamsType, ProTable } from '@ant-design/pro-components';
2
- import { theme } from 'antd';
2
+ import { useSafeState } from 'ahooks';
3
3
  import { createStyles } from 'antd-style';
4
4
  import classnames from 'classnames';
5
- import _ from 'lodash';
6
5
  import { useRef } from 'react';
7
6
 
8
- import { useAutoWidthColumns, useTableScrollHeight } from './hooks';
9
- import { TableOptionRender } from './TableOptionRender';
10
- import { toolBarRender } from './toolBarRender';
7
+ import { GlobalScrollbarStyle } from '../creek-style';
8
+ import { useAutoWidthColumns, useEllipsisColumns, useIndexColumn, useResizableColumns, useTableOptions, useTableScrollHeight } from './hooks';
9
+
11
10
  import { CreekTableProps } from './type';
12
11
 
13
- const useStyles = createStyles(({ css, token }, { scrollY, prefixCls }: { scrollY?: number | string; prefixCls: string }) => {
12
+ export type SearchTableStyleOptions = {
13
+ prefixCls?: string;
14
+ scrollY?: number;
15
+ tableContainerHeight?: number;
16
+ tableHeight?: number;
17
+ bordered?: boolean;
18
+ hasHeaderTitle?: boolean;
19
+ hasScroll?: boolean;
20
+ };
21
+
22
+ const useStyles = createStyles(({ token }, options: SearchTableStyleOptions) => {
23
+ const { prefixCls = 'ant', scrollY, tableHeight, bordered, hasHeaderTitle, tableContainerHeight, hasScroll } = options;
14
24
  return {
15
- 'creek-table-container': css`
16
- .${prefixCls}-table-body {
17
- overflow-y: auto !important;
18
- min-height: ${typeof scrollY === 'number' ? `${scrollY}px` : (scrollY ?? 'auto')};
19
-
20
- /* Firefox 滚动条样式 */
21
- scrollbar-width: thin;
22
- scrollbar-color: ${token.colorFillSecondary} transparent;
23
- }
24
-
25
- /* Webkit (Chrome, Safari, Edge) 滚动条样式 */
26
- & *::-webkit-scrollbar {
27
- width: 6px !important;
28
- height: 6px !important;
29
- background-color: transparent !important;
30
- }
31
-
32
- & *::-webkit-scrollbar-thumb {
33
- background-color: ${token.colorFillSecondary} !important;
34
- border-radius: 3px !important;
35
- transition: all 0.3s;
36
- }
37
-
38
- & *::-webkit-scrollbar-thumb:hover {
39
- background-color: ${token.colorFill} !important;
40
- }
41
-
42
- & *::-webkit-scrollbar-track {
43
- background-color: transparent !important;
44
- }
45
-
46
- .${prefixCls}-pagination {
47
- .${prefixCls}-pagination-total-text {
48
- flex: 1;
49
- }
50
- }
51
- `,
25
+ 'creek-table-container': {
26
+ overflow: 'hidden',
27
+ position: 'relative',
28
+ height: tableHeight ? `${tableHeight}px` : 'auto',
29
+ backgroundColor: token.colorBgContainer,
30
+ [`.${prefixCls}-table`]: {
31
+ minHeight: `${tableContainerHeight}px`,
32
+ },
33
+ [`.${prefixCls}-table-container`]: {
34
+ borderBottom: 'none',
35
+ overflow: 'hidden'
36
+ },
37
+
38
+ [`.${prefixCls}-table-header`]: {
39
+ borderRight: (bordered && hasScroll) ? `1px solid ${token.colorBorderSecondary}` : 'none',
40
+ },
41
+ [`.${prefixCls}-table-body`]: {
42
+ overflowY: 'auto',
43
+ maxHeight: `${scrollY}px`,
44
+ borderRight: (bordered && hasScroll) ? `1px solid ${token.colorBorderSecondary}` : 'none',
45
+ },
46
+ // 兼容非 scroll.y 模式下的 table 容器
47
+ [`.${prefixCls}-table-content`]: {
48
+ overflowY: 'hidden',
49
+ maxHeight: scrollY ? `${scrollY}px` : undefined,
50
+ },
51
+
52
+ [`.${prefixCls}-table-cell-scrollbar`]: {
53
+ boxShadow: bordered ? 'none!important' : 'inherit',
54
+ borderInlineEnd: bordered ? `none!important` : 'none',
55
+ display: hasScroll ? 'table-cell' : 'none',
56
+ width: hasScroll ? 'initial' : '0px!important',
57
+ minWidth: hasScroll ? 'initial' : '0px!important',
58
+ maxWidth: hasScroll ? 'initial' : '0px!important',
59
+ padding: hasScroll ? 'initial' : '0px!important',
60
+ margin: hasScroll ? 'initial' : '0px!important',
61
+ },
62
+
63
+ [`.${prefixCls}-pagination`]: {
64
+ [`.${prefixCls}-pagination-total-text`]: {
65
+ flex: 1,
66
+ },
67
+ },
68
+ [`.${prefixCls}-pro-table-search`]: {
69
+ marginBlockEnd: 0,
70
+ borderBottom: `1px solid ${token.colorBorderSecondary}`,
71
+ },
72
+
73
+ [`.${prefixCls}-pro-query-filter-container`]: {
74
+ [`.${prefixCls}-pro-query-filter`]: {
75
+ padding: token.paddingXS,
76
+ },
77
+ },
78
+
79
+ // 如果没有 headerTitle,toolbar 展示在 headerTitle 的区域
80
+ [`.${prefixCls}-pro-table-list-toolbar-right`]: !hasHeaderTitle
81
+ ? {
82
+ flex: 1,
83
+ }
84
+ : {},
85
+ [`.${prefixCls}-pro-table-list-toolbar-setting-items`]: !hasHeaderTitle
86
+ ? {
87
+ marginLeft: 'auto',
88
+ }
89
+ : {},
90
+ },
52
91
  };
53
92
  });
54
93
 
55
94
  // 独立的 ProTable 组件
56
95
  export const SearchProTable = <T extends ParamsType, U extends ParamsType, ValueType = 'text'>(props: CreekTableProps<T, U, ValueType>) => {
57
- const { columns, prefixCls = 'ant', autoAddFilterForColumn = true, className, optionsRender, tableViewRender, pagination, pageFixedBottom = true, pageFixedBottomConfig, ...restProps } = props;
96
+ const {
97
+ columns,
98
+ prefixCls = 'ant',
99
+ className,
100
+ optionsRender,
101
+ tableViewRender,
102
+ pagination,
103
+ pageFixedBottom = true,
104
+ pageFixedBottomConfig,
105
+ resizable = true,
106
+ bordered = true,
107
+ options,
108
+ size,
109
+ headerTitle,
110
+ showIndex = true,
111
+ ...restProps
112
+ } = props;
58
113
 
59
114
  const proTableRef = useRef<HTMLDivElement>(null);
60
115
 
61
- const { token } = theme.useToken();
116
+ // 状态提升:管理列宽调整状态,以便 useAutoWidthColumns 能感知到
117
+ const [resizedWidths, setResizedWidths] = useSafeState<Record<string, number>>({});
118
+
119
+ // 使用自定义 Hook 管理 options 和 size
120
+ const { finalOptions, tableSize, finalOptionsRender } = useTableOptions<T, U, ValueType>(options, size, optionsRender);
121
+
122
+ const columnsWithIndex = useIndexColumn<T, ValueType>(columns, showIndex);
62
123
 
63
- // // 使用自定义 hook 处理工具栏的自适应功能
64
- // const { shouldCollapse } = useAdaptiveToolBar({
65
- // containerRef: proTableRef,
66
- // prefixCls,
67
- // });ƒ
124
+ // 处理 columns,默认开启 ellipsis
125
+ const processedColumns = useEllipsisColumns(columnsWithIndex);
68
126
 
69
- const { columns: adaptiveColumns, totalWidth } = useAutoWidthColumns(columns, proTableRef);
127
+ const { columns: adaptiveColumns, totalWidth } = useAutoWidthColumns<T, ValueType>(processedColumns, proTableRef, resizedWidths, bordered, tableSize);
70
128
 
71
- const scrollY = useTableScrollHeight(prefixCls, proTableRef, pageFixedBottom, token.paddingContentVerticalLG, pageFixedBottomConfig?.bottomFix || token.padding);
129
+ const { columns: resizableColumns, components } = useResizableColumns<T, ValueType>(adaptiveColumns, resizable, resizedWidths, setResizedWidths, proTableRef);
72
130
 
73
- const { styles } = useStyles({ scrollY, prefixCls });
131
+ const { scrollY, tableHeight, tableContainerHeight, hasScroll } = useTableScrollHeight(prefixCls, proTableRef, pageFixedBottom, pageFixedBottomConfig?.bottomFix);
132
+
133
+ const { styles } = useStyles({ scrollY, tableHeight, prefixCls, bordered, hasHeaderTitle: !!headerTitle, tableContainerHeight, hasScroll });
74
134
 
75
- console.log('scrollY', scrollY);
76
135
 
77
136
  return (
78
137
  <div ref={proTableRef}>
138
+ <GlobalScrollbarStyle />
139
+ {/* 自定义滚动条 */}
79
140
  <ProTable<T, U, ValueType>
80
- {...props}
141
+ components={components}
142
+ headerTitle={headerTitle}
143
+ options={finalOptions}
144
+ optionsRender={finalOptionsRender}
145
+ size={tableSize}
146
+ {...restProps}
81
147
  className={classnames(styles['creek-table-container'], className)}
82
- columns={adaptiveColumns}
148
+ columns={resizableColumns}
149
+ bordered={bordered}
83
150
  scroll={{
84
- x: totalWidth,
85
- y: scrollY ?? restProps.scroll?.y,
151
+ y: hasScroll ? scrollY || restProps.scroll?.y : undefined,
152
+ x: totalWidth ?? restProps.scroll?.x,
86
153
  }}
87
154
  toolbar={{
88
155
  ...restProps.toolbar,
89
156
  }}
90
- optionsRender={(defaultProps, dom) => {
91
- return _.isFunction(optionsRender)
92
- ? optionsRender(defaultProps, dom)
93
- : restProps?.options
94
- ? [<TableOptionRender key="option" defaultDom={dom} importConfig={restProps?.options?.importConfig} exportConfig={restProps?.options?.exportConfig} />]
95
- : [];
96
- }}
97
- toolBarRender={(...args) => {
98
- return toolBarRender({ shouldCollapse: false, restProps, args });
99
- }}
100
- // 在表格内容区上方显示筛选条件
101
- tableViewRender={(defaultProps, defaultDom) => {
102
- return _.isFunction(tableViewRender) ? <>{tableViewRender(defaultProps, defaultDom)}</> : defaultDom;
103
- }}
104
157
  />
105
158
  </div>
106
159
  );
@@ -0,0 +1,63 @@
1
+ import { ColumnHeightOutlined } from '@ant-design/icons';
2
+ import { ProTableProps } from '@ant-design/pro-components';
3
+ import { Dropdown, MenuProps, Tooltip } from 'antd';
4
+ import React from 'react';
5
+
6
+ import { useT } from '@/utils/i18n';
7
+
8
+ export type SizeType = ProTableProps<any, any>['size'];
9
+
10
+ interface DensityIconProps {
11
+ tableSize: SizeType;
12
+ setTableSize: (size: SizeType) => void;
13
+ }
14
+
15
+ export const DensityIcon: React.FC<DensityIconProps> = ({ tableSize, setTableSize }) => {
16
+ const t = useT();
17
+
18
+ const items: MenuProps['items'] = [
19
+ {
20
+ key: 'large',
21
+ label: t('creek-table.components.DensityIcon.kuanSong', '宽松'),
22
+ onClick: () => setTableSize('large'),
23
+ },
24
+ {
25
+ key: 'middle',
26
+ label: t('creek-table.components.DensityIcon.zhongDeng', '中等'),
27
+ onClick: () => setTableSize('middle'),
28
+ },
29
+ {
30
+ key: 'small',
31
+ label: t('creek-table.components.DensityIcon.jinCou', '紧凑'),
32
+ onClick: () => setTableSize('small'),
33
+ },
34
+ ];
35
+
36
+ const getTitle = () => {
37
+ switch (tableSize) {
38
+ case 'large':
39
+ return t('creek-table.components.DensityIcon.biaoGeMiDu(KuanSong)', '表格密度 (宽松)');
40
+ case 'middle':
41
+ return t('creek-table.components.DensityIcon.biaoGeMiDu(ZhongDeng)', '表格密度 (中等)');
42
+ case 'small':
43
+ return t('creek-table.components.DensityIcon.biaoGeMiDu(JinCou)', '表格密度 (紧凑)');
44
+ default:
45
+ return t('creek-table.components.DensityIcon.biaoGeMiDu', '表格密度');
46
+ }
47
+ };
48
+
49
+ return (
50
+ <Dropdown
51
+ menu={{
52
+ items,
53
+ selectedKeys: [tableSize || 'large'],
54
+ selectable: true,
55
+ }}
56
+ trigger={['click']}
57
+ >
58
+ <Tooltip title={getTitle()}>
59
+ <ColumnHeightOutlined style={{ fontSize: 16, cursor: 'pointer' }} />
60
+ </Tooltip>
61
+ </Dropdown>
62
+ );
63
+ };