@mi-avalon/libs 0.0.7 → 0.0.8

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 (36) hide show
  1. package/package.json +12 -5
  2. package/src/components/ItemsRow/index.scss +0 -18
  3. package/src/components/ItemsRow/index.tsx +0 -85
  4. package/src/components/MBreadcrumb/index.scss +0 -82
  5. package/src/components/MBreadcrumb/index.tsx +0 -93
  6. package/src/components/MDescriptions/index.tsx +0 -131
  7. package/src/components/MForm/MFormItemConst.tsx +0 -206
  8. package/src/components/MForm/index.scss +0 -13
  9. package/src/components/MForm/index.tsx +0 -97
  10. package/src/components/MForm/type.ts +0 -229
  11. package/src/components/MSearch/index.scss +0 -63
  12. package/src/components/MSearch/index.tsx +0 -173
  13. package/src/components/MTable/index.tsx +0 -22
  14. package/src/components/MiModal/index.tsx +0 -106
  15. package/src/components/ThemeContext/CompThemeProvider.tsx +0 -19
  16. package/src/components/ThemeContext/index.ts +0 -20
  17. package/src/components/index.ts +0 -9
  18. package/src/constants/date.ts +0 -11
  19. package/src/constants/index.ts +0 -3
  20. package/src/constants/pageInfo.ts +0 -1
  21. package/src/constants/pattern.ts +0 -53
  22. package/src/hooks/index.ts +0 -7
  23. package/src/hooks/useFuncRequest.ts +0 -100
  24. package/src/hooks/useInterval.ts +0 -50
  25. package/src/hooks/usePagination.ts +0 -184
  26. package/src/hooks/useQuery.ts +0 -6
  27. package/src/hooks/useReactive.ts +0 -26
  28. package/src/hooks/useTimeout.ts +0 -50
  29. package/src/hooks/useVirtualList.ts +0 -209
  30. package/src/index.tsx +0 -4
  31. package/src/utils/calc.ts +0 -92
  32. package/src/utils/index.ts +0 -5
  33. package/src/utils/nextTick.ts +0 -89
  34. package/src/utils/openModal.tsx +0 -137
  35. package/src/utils/util.ts +0 -37
  36. package/src/utils/version.ts +0 -206
@@ -1,97 +0,0 @@
1
- /**
2
- * 表单组件
3
- */
4
- import { Col, Form, FormInstance, Row } from 'antd';
5
- import { Rule } from 'antd/es/form';
6
- import React from 'react';
7
- import { getClassName } from '../../utils';
8
- import CompThemeProvider from '../ThemeContext/CompThemeProvider';
9
- import './index.scss';
10
- import { MFormItemConst } from './MFormItemConst';
11
- import { IMFormItem, IMFormProps } from './type';
12
-
13
- const classname = (n: string = '') => {
14
- const cn = 'm-form';
15
- return getClassName(cn, n);
16
- };
17
-
18
- function MForm(props: IMFormProps) {
19
- const {
20
- formProps,
21
- formItems = [],
22
- column = 1,
23
- form,
24
- itemLayout,
25
- formRowProps,
26
- } = props;
27
-
28
- const renderItem = (item: IMFormItem, form?: FormInstance) => {
29
- if (item.render) {
30
- return item.render(form);
31
- }
32
- const func = MFormItemConst[item.type];
33
- if (item && item.type && func) {
34
- const renderFunc = func as (item: IMFormItem) => React.ReactNode;
35
- return renderFunc(item);
36
- }
37
-
38
- return <div className="error-message">Invalid form item configuration</div>;
39
- };
40
-
41
- const renderFormItem = (item: IMFormItem) => {
42
- const { show = true } = item;
43
- if (!show) return null;
44
- const rules: Rule[] = [...(item.rules || [])];
45
- if (item.required) {
46
- rules.push({ required: true, message: item.required });
47
- }
48
-
49
- const formItemLayout = {
50
- labelCol: MFormItemConst.labelCol,
51
- wrapperCol: MFormItemConst.wrapperCol,
52
- ...itemLayout,
53
- ...item.itemLayout,
54
- };
55
- return (
56
- <Col key={`col-${item.id}`} span={item.span || 24 / column}>
57
- <div className={classname('item-wrapper')}>
58
- <Form.Item
59
- label={item.label}
60
- name={item.id}
61
- rules={rules}
62
- initialValue={item.initialValue}
63
- {...formItemLayout}
64
- {...item.formItemProps}
65
- >
66
- {renderItem(item, form)}
67
- </Form.Item>
68
- </div>
69
- </Col>
70
- );
71
- };
72
-
73
- return (
74
- <CompThemeProvider>
75
- <Form
76
- form={form}
77
- {...formProps}
78
- className={`${classname()} ${formProps?.className}`}
79
- >
80
- <Row
81
- gutter={MFormItemConst.defaultRowGutter}
82
- {...formRowProps}
83
- className={`${classname('grid')} ${formRowProps?.className}`}
84
- >
85
- {formItems.map(e => renderFormItem(e))}
86
- </Row>
87
- </Form>
88
- </CompThemeProvider>
89
- );
90
- }
91
-
92
- MForm.displayName = 'MForm';
93
-
94
- export default MForm;
95
-
96
- export * from './MFormItemConst';
97
- export * from './type';
@@ -1,229 +0,0 @@
1
- import {
2
- CascaderAutoProps,
3
- FormInstance,
4
- FormItemProps,
5
- FormProps,
6
- InputNumberProps,
7
- InputProps,
8
- MentionsProps,
9
- RadioGroupProps,
10
- RowProps,
11
- SelectProps,
12
- SliderSingleProps,
13
- TreeSelectProps,
14
- UploadProps,
15
- } from 'antd';
16
- import { CheckboxGroupProps } from 'antd/es/checkbox';
17
- import { RangePickerProps } from 'antd/es/date-picker';
18
- import { Rule } from 'antd/es/form';
19
- import { TextAreaProps } from 'antd/es/input';
20
- import { SliderRangeProps } from 'antd/es/slider';
21
- import { DatePickerProps } from 'antd/lib';
22
- import { ReactElement } from 'react';
23
-
24
- export enum MFormItemTypeEnum {
25
- Input = 'input',
26
- InputNumber = 'inputNumber',
27
- Text = 'text',
28
- Password = 'password',
29
- Radio = 'radio',
30
- Select = 'select',
31
- Checkbox = 'checkbox',
32
- DatePicker = 'datePicker',
33
- RangePicker = 'rangePicker',
34
- Upload = 'upload',
35
- Mentions = 'mentions',
36
- Cascader = 'cascader',
37
- TreeSelect = 'treeSelect',
38
- Slider = 'slider',
39
- }
40
-
41
- export declare type MFormItemLayout = { span?: number; offset?: number };
42
-
43
- export interface IMFormProps {
44
- /**
45
- * 一行显示几个label 默认1个, 其他:2, 3, 4
46
- */
47
- column?: 1 | 2 | 3 | 4;
48
- /**
49
- * 需要的数据: [ { label: ...,id: ..., required: ..., type: ..., ... }, ... ]
50
- */
51
- formItems: IMFormItem[];
52
- /**
53
- * Antd const [form] = useForm()
54
- */
55
- form?: FormInstance;
56
- /**
57
- * 表单其他属性
58
- */
59
- formProps?: FormProps;
60
- /**
61
- * 全局 MFormItem layout, 默认为 {labelCol:{span: 7}, wrapperCol: {span: 7}}
62
- * @type {{labelCol: MFormItemLayout, wrapperCol: MFormItemLayout}}
63
- * @memberof MFormItem
64
- */
65
- itemLayout?: { labelCol?: MFormItemLayout; wrapperCol?: MFormItemLayout };
66
- /**
67
- * Antd Row 的其他属性
68
- */
69
- formRowProps?: RowProps;
70
- }
71
-
72
- export interface IMFormBaseItem {
73
- /**
74
- * 属性名
75
- */
76
- id: string;
77
- /**
78
- * label名称
79
- */
80
- label: string;
81
- /**
82
- * 组件是否禁用
83
- */
84
- disabled?: boolean;
85
- /**
86
- * form类型 FORM_TYPE
87
- */
88
- type?: MFormItemTypeEnum;
89
- /**
90
- * 初始值
91
- */
92
- initialValue?: any;
93
- /**
94
- * rules required的验证消息, 不填写则不验证
95
- */
96
- required?: string;
97
- /**
98
- * rule-max, 正则,验证消息
99
- */
100
- rules?: Rule[];
101
- /**
102
- * 自定义form
103
- */
104
- render?: (form?: FormInstance) => ReactElement;
105
- /**
106
- * Antd MForm.Item 的其他属性
107
- */
108
- formItemProps?: FormItemProps;
109
- /**
110
- * MFormItem layout, 默认为 {labelCol:{span: 7}, wrapperCol: {span: 7}}
111
- * @type {{labelCol: MFormItemLayout, wrapperCol: MFormItemLayout}}
112
- * @memberof MFormItem
113
- */
114
- itemLayout?: { labelCol?: MFormItemLayout; wrapperCol?: MFormItemLayout };
115
- /**
116
- * 当前表单占据行的宽度 1-24 默认 24 / column
117
- */
118
- span?: number;
119
- /**
120
- * 是否显示当前组件 默认显示
121
- */
122
- show?: boolean;
123
- /**
124
- * item组件的其他属性
125
- */
126
- props?: any;
127
- }
128
-
129
- export interface IMFormInputItem extends IMFormBaseItem {
130
- type: MFormItemTypeEnum.Input | MFormItemTypeEnum.Password;
131
- props?: InputProps;
132
- placeholder?: string;
133
- maxLength?: number;
134
- }
135
- export interface IMFormInputNumItem extends IMFormBaseItem {
136
- type: MFormItemTypeEnum.InputNumber;
137
- props?: InputNumberProps;
138
- placeholder?: string;
139
- maxLength?: number;
140
- }
141
-
142
- export interface IMFormTextItem extends IMFormBaseItem {
143
- type: MFormItemTypeEnum.Text;
144
- props?: TextAreaProps;
145
- placeholder?: string;
146
- maxLength?: number;
147
- }
148
-
149
- // 单选
150
- export interface IMFormRadioGroupItem extends IMFormBaseItem {
151
- type: MFormItemTypeEnum.Radio;
152
- props?: RadioGroupProps;
153
- }
154
-
155
- // 多选
156
- export interface IMFormChkBoxGroupItem extends IMFormBaseItem {
157
- type: MFormItemTypeEnum.Checkbox;
158
- props?: CheckboxGroupProps;
159
- }
160
-
161
- // 下拉选择
162
- export interface IMFormSelectItem<T = any> extends IMFormBaseItem {
163
- type: MFormItemTypeEnum.Select;
164
- placeholder?: string;
165
- props?: SelectProps<T>;
166
- }
167
-
168
- // 日期选择
169
- export interface IMFormDatePickerItem extends IMFormBaseItem {
170
- type: MFormItemTypeEnum.DatePicker;
171
- placeholder?: string;
172
- props?: DatePickerProps;
173
- }
174
-
175
- // 日期范围选择
176
- export interface IMFormRangePickerItem extends IMFormBaseItem {
177
- type: MFormItemTypeEnum.RangePicker;
178
- placeholder?: [string, string];
179
- props?: RangePickerProps;
180
- }
181
-
182
- // 文件上传
183
- export interface IMFormUploadItem extends IMFormBaseItem {
184
- type: MFormItemTypeEnum.Upload;
185
- children?: ReactElement;
186
- props?: UploadProps;
187
- }
188
-
189
- // 提及
190
- export interface IMFormMentionsItem extends IMFormBaseItem {
191
- type: MFormItemTypeEnum.Mentions;
192
- placeholder?: string;
193
- props?: MentionsProps;
194
- }
195
-
196
- // 联级选择
197
- export interface IMFormCascaderItem extends IMFormBaseItem {
198
- type: MFormItemTypeEnum.Cascader;
199
- placeholder?: string;
200
- props?: CascaderAutoProps;
201
- }
202
-
203
- // 树选择
204
- export interface IMFormTreeSelectItem extends IMFormBaseItem {
205
- type: MFormItemTypeEnum.TreeSelect;
206
- placeholder?: string;
207
- props?: TreeSelectProps;
208
- }
209
-
210
- // 滑块
211
- export interface IMFormSliderItem extends IMFormBaseItem {
212
- type: MFormItemTypeEnum.Slider;
213
- props?: SliderSingleProps | SliderRangeProps;
214
- }
215
-
216
- export type IMFormItem =
217
- | IMFormInputItem
218
- | IMFormInputNumItem
219
- | IMFormSelectItem
220
- | IMFormChkBoxGroupItem
221
- | IMFormRadioGroupItem
222
- | IMFormTextItem
223
- | IMFormDatePickerItem
224
- | IMFormRangePickerItem
225
- | IMFormUploadItem
226
- | IMFormMentionsItem
227
- | IMFormCascaderItem
228
- | IMFormTreeSelectItem
229
- | IMFormSliderItem;
@@ -1,63 +0,0 @@
1
- $comp-name: 'm-search';
2
-
3
- .#{$comp-name} {
4
- position: relative;
5
- border-radius: 8px;
6
-
7
- .ant-card {
8
- margin: 0;
9
- padding: 16px 0;
10
-
11
- .ant-card-body {
12
- padding: 0;
13
- border-radius: 0;
14
- }
15
- }
16
-
17
- &-form {
18
- position: relative;
19
- margin-right: 20px;
20
- }
21
-
22
- &-btn-wrapper {
23
- display: inline-block;
24
- }
25
-
26
- &-collapsed {
27
- }
28
-
29
- &-collapsed &-btn-wrapper {
30
- position: absolute;
31
- right: 0px;
32
- top: 0;
33
- display: flex;
34
- height: 100%;
35
- align-items: center;
36
- }
37
-
38
- & .ant-form-item {
39
- margin-bottom: 10px;
40
- }
41
-
42
- &-collapsed .ant-form-item {
43
- margin-bottom: 0;
44
- }
45
-
46
- &-footer {
47
- text-align: right;
48
- padding: 10px 20px;
49
- }
50
-
51
- &-btn {
52
- margin-left: 10px;
53
- }
54
-
55
- &-btn-collapse {
56
- display: inline-block;
57
- cursor: pointer;
58
- }
59
-
60
- & .ant-calendar-picker {
61
- width: auto !important;
62
- }
63
- }
@@ -1,173 +0,0 @@
1
- import { CaretDownOutlined, CaretUpOutlined } from '@ant-design/icons';
2
- import { Button, ButtonProps, Card, Form } from 'antd';
3
- import { FormInstance } from 'antd/lib';
4
- import React, { useEffect, useRef, useState } from 'react';
5
- import { getClassName, removeNull } from '../../utils';
6
- import MForm, { IMFormItem } from '../MForm';
7
- import CompThemeProvider from '../ThemeContext/CompThemeProvider';
8
- import './index.scss';
9
-
10
- const ENTER_KEY_CODE = 13; // 回车键的值为13
11
-
12
- const classname = (n: string = '') => {
13
- const cn = 'm-search';
14
- return getClassName(cn, n);
15
- };
16
-
17
- export interface IMSearchProps {
18
- form?: FormInstance;
19
- /**
20
- * 需要的数据: [ { lable: ...,id: ..., required: ..., type: ..., }, ... ]
21
- */
22
- searchItems: IMFormItem[];
23
- className?: string;
24
- /**
25
- * 搜索按钮 params返回form表单的数据
26
- */
27
- onSearch?: (params: any, isReset: boolean) => any;
28
- /**
29
- * 搜索项默认展开,不填写默认false
30
- */
31
- defaultShowAll?: boolean;
32
- /**
33
- * 自定义按钮
34
- */
35
- customButtons?: ButtonProps[];
36
- }
37
-
38
- interface IKeyObj {
39
- keyCode: number;
40
- }
41
-
42
- const MSearch: React.FC<IMSearchProps> = props => {
43
- const {
44
- className,
45
- searchItems = [],
46
- onSearch,
47
- defaultShowAll = false,
48
- customButtons = [],
49
- form: propsForm,
50
- } = props;
51
- const [showAll, setShowAll] = useState(defaultShowAll);
52
- const [curForm] = Form.useForm();
53
- const searchWrap = useRef<HTMLDivElement>(null);
54
-
55
- const form = propsForm ?? curForm;
56
-
57
- // 键盘按下事件处理
58
- const onEnterKeySearch = (keyObj: IKeyObj) => {
59
- const { keyCode } = keyObj;
60
- if (keyCode === ENTER_KEY_CODE) {
61
- search();
62
- }
63
- };
64
-
65
- // 添加和移除事件监听
66
- useEffect(() => {
67
- const currentWrap = searchWrap.current;
68
- currentWrap?.addEventListener('keydown', onEnterKeySearch);
69
-
70
- return () => {
71
- currentWrap?.removeEventListener('keydown', onEnterKeySearch);
72
- };
73
- }, []);
74
-
75
- // 重置表单
76
- const reset = () => {
77
- form?.resetFields();
78
- search(true);
79
- };
80
-
81
- // 搜索函数
82
- const search = (isReset = false) => {
83
- form?.validateFields().then(values => {
84
- removeNull(values);
85
- onSearch?.(values, isReset);
86
- });
87
- };
88
-
89
- // 渲染搜索按钮
90
- const renderSearchButtons = () => {
91
- const hasMore = searchItems.length > 2;
92
-
93
- return (
94
- <div className={classname('btn-wrapper')}>
95
- {customButtons?.length > 0 ? (
96
- <>
97
- {customButtons.map((buttonProps, index) => (
98
- <Button
99
- key={`custom-btn-${index}`}
100
- className={classname('btn')}
101
- {...buttonProps}
102
- >
103
- {buttonProps.children}
104
- </Button>
105
- ))}
106
- </>
107
- ) : (
108
- <>
109
- <Button className={classname('btn btn-reset')} onClick={reset}>
110
- 重置
111
- </Button>
112
- <Button
113
- className={classname('btn btn-search')}
114
- onClick={() => search()}
115
- type="primary"
116
- >
117
- 搜索
118
- </Button>
119
- </>
120
- )}
121
- {hasMore && (
122
- <div
123
- className={classname('btn btn-collapse')}
124
- onClick={() => setShowAll(!showAll)}
125
- >
126
- <span>{showAll ? '收起' : '展开'}</span>
127
- {showAll ? <CaretUpOutlined /> : <CaretDownOutlined />}
128
- </div>
129
- )}
130
- </div>
131
- );
132
- };
133
-
134
- // 处理搜索项显示/隐藏
135
- const processedSearchItems = searchItems.map((item, idx) => {
136
- const newItem = { ...item };
137
- if (searchItems.length > 2 && idx >= 2 && !showAll) {
138
- newItem.formItemProps = {
139
- ...item.formItemProps,
140
- style: {
141
- ...item.formItemProps?.style,
142
- display: 'none',
143
- },
144
- };
145
- }
146
- return newItem;
147
- });
148
-
149
- const hasMore = searchItems.length > 2;
150
-
151
- return (
152
- <CompThemeProvider>
153
- <div
154
- className={`${classname('')} ${
155
- showAll ? '' : classname('collapsed')
156
- } ${className || ''}`}
157
- ref={searchWrap}
158
- >
159
- <Card>
160
- <div className={classname('form')}>
161
- <MForm form={form} formItems={processedSearchItems} column={3} />
162
- {(!hasMore || (hasMore && !showAll)) && renderSearchButtons()}
163
- </div>
164
- {hasMore && showAll && (
165
- <div className={classname('footer')}>{renderSearchButtons()}</div>
166
- )}
167
- </Card>
168
- </div>
169
- </CompThemeProvider>
170
- );
171
- };
172
-
173
- export default MSearch;
@@ -1,22 +0,0 @@
1
- /**
2
- * 表格
3
- */
4
- import { Table, TableProps } from 'antd';
5
- import { ColumnsType } from 'antd/es/table';
6
- import React from 'react';
7
- import CompThemeProvider from '../ThemeContext/CompThemeProvider';
8
-
9
- export interface IMTableProps extends TableProps {}
10
-
11
- function MTable(props: IMTableProps) {
12
- const columns: ColumnsType<any> = props.columns?.map(e => ({ ...e, dataIndex: e.key })) ?? [];
13
- return (
14
- <CompThemeProvider>
15
- <Table rowKey={e => e.id} {...props} columns={columns} />;
16
- </CompThemeProvider>
17
- );
18
- }
19
-
20
- MTable.displayName = 'MTable';
21
-
22
- export default MTable;
@@ -1,106 +0,0 @@
1
- import { Modal as AntModal, ConfigProvider, theme, ThemeConfig } from 'antd';
2
- import React, { Component } from 'react';
3
- import { IModalBaseProps, openModal } from '../../utils';
4
-
5
- export type IMiModalProps = IModalBaseProps & {
6
- mode?: string;
7
- };
8
-
9
- // 全局状态管理
10
- let globalMode: string = 'default';
11
- const modalInstances: Array<{
12
- update: (config: Partial<IMiModalProps>) => void;
13
- }> = [];
14
- let getThemeConfig = (mode: string): ThemeConfig => {
15
- switch (mode) {
16
- case 'light':
17
- return {
18
- algorithm: [theme.defaultAlgorithm],
19
- };
20
- case 'dark':
21
- return {
22
- algorithm: [theme.darkAlgorithm],
23
- };
24
- default:
25
- return {
26
- algorithm: [theme.defaultAlgorithm],
27
- };
28
- }
29
- };
30
-
31
- class MiModal extends Component<IMiModalProps> {
32
- // 静态方法设置全局模式并更新所有弹窗
33
- static setMode = (mode: string) => {
34
- globalMode = mode;
35
- // 更新所有已打开的弹窗
36
- modalInstances.forEach(instance => {
37
- instance.update({ mode });
38
- });
39
- };
40
-
41
- // 静态方法设置全局ThemeConfig
42
- static setThemeConfig = (fn: (m: string) => ThemeConfig) => {
43
- getThemeConfig = fn;
44
- };
45
-
46
- static open = (props: IMiModalProps) => {
47
- const instance = openModal(MiModal, {
48
- mode: globalMode, // 默认使用全局主题
49
- ...props,
50
- });
51
-
52
- // 注册实例以便全局更新
53
- modalInstances.push(instance);
54
-
55
- // 添加销毁时的清理逻辑
56
- const originalDestroy = instance.destroy;
57
- instance.destroy = (...args) => {
58
- const index = modalInstances.indexOf(instance);
59
- if (index !== -1) {
60
- modalInstances.splice(index, 1);
61
- }
62
- return originalDestroy(...args);
63
- };
64
-
65
- return instance;
66
- };
67
-
68
- getTheme() {
69
- const mode = this.props.mode || globalMode;
70
- return getThemeConfig(mode);
71
- }
72
-
73
- handleCancel = (e: React.MouseEvent<HTMLButtonElement>) => {
74
- this.props.onCancel?.(e);
75
- this.props.onClosed?.({ cancel: true });
76
- };
77
-
78
- handleOk = (e: React.MouseEvent<HTMLButtonElement>) => {
79
- this.props.onOk?.(e);
80
- this.props.onClosed?.({ ok: true });
81
- };
82
-
83
- render() {
84
- return (
85
- <ConfigProvider
86
- theme={this.getTheme()} // 确保内部组件能正确继承主题
87
- componentSize="middle"
88
- componentDisabled={false}
89
- >
90
- <AntModal
91
- maskClosable={false}
92
- open={this.props.open}
93
- onCancel={this.handleCancel}
94
- onOk={this.handleOk}
95
- okText="确定"
96
- cancelText="取消"
97
- {...this.props}
98
- >
99
- {this.props.children}
100
- </AntModal>
101
- </ConfigProvider>
102
- );
103
- }
104
- }
105
-
106
- export default MiModal;
@@ -1,19 +0,0 @@
1
- /**
2
- * CompThemeProvider
3
- */
4
- import { ConfigProvider } from 'antd';
5
- import React from 'react';
6
- import { useMiThemeConfig } from '.';
7
-
8
- interface IProps {
9
- children: React.ReactNode;
10
- }
11
-
12
- function CompThemeProvider(props: IProps) {
13
- const { theme } = useMiThemeConfig();
14
- return <ConfigProvider theme={theme}>{props.children}</ConfigProvider>;
15
- }
16
-
17
- CompThemeProvider.displayName = 'CompThemeProvider';
18
-
19
- export default CompThemeProvider;