@mi-avalon/libs 0.0.24 → 0.0.25
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.
- package/dist/components/MiModal/index.d.ts +15 -0
- package/dist/components/MiModal/index.js +70 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -1
- package/dist/index.es.js +1071 -893
- package/dist/index.umd.js +16 -16
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -1
- package/dist/utils/openModal.d.ts +15 -0
- package/dist/utils/openModal.js +98 -0
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ThemeConfig } from 'antd';
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import { IModalBaseProps } from '../../utils';
|
|
4
|
+
export type IMiModalProps = IModalBaseProps & {
|
|
5
|
+
mode?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class MiModal extends Component<IMiModalProps> {
|
|
8
|
+
static setMode: (mode: string) => void;
|
|
9
|
+
static setThemeConfig: (fn: (m: string) => ThemeConfig) => void;
|
|
10
|
+
static open: (props: IMiModalProps) => import("../../utils").IModalControls<IMiModalProps>;
|
|
11
|
+
getTheme(): ThemeConfig;
|
|
12
|
+
handleCancel: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
13
|
+
handleOk: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
14
|
+
render(): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Modal as AntModal, ConfigProvider, theme } from 'antd';
|
|
3
|
+
import { Component } from 'react';
|
|
4
|
+
import { openModal } from '../../utils';
|
|
5
|
+
// 全局状态管理
|
|
6
|
+
let globalMode = 'default';
|
|
7
|
+
const modalInstances = [];
|
|
8
|
+
let getThemeConfig = (mode) => {
|
|
9
|
+
switch (mode) {
|
|
10
|
+
case 'light':
|
|
11
|
+
return {
|
|
12
|
+
algorithm: [theme.defaultAlgorithm],
|
|
13
|
+
};
|
|
14
|
+
case 'dark':
|
|
15
|
+
return {
|
|
16
|
+
algorithm: [theme.darkAlgorithm],
|
|
17
|
+
};
|
|
18
|
+
default:
|
|
19
|
+
return {
|
|
20
|
+
algorithm: [theme.defaultAlgorithm],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export class MiModal extends Component {
|
|
25
|
+
// 静态方法设置全局模式并更新所有弹窗
|
|
26
|
+
static setMode = (mode) => {
|
|
27
|
+
globalMode = mode;
|
|
28
|
+
// 更新所有已打开的弹窗
|
|
29
|
+
modalInstances.forEach(instance => {
|
|
30
|
+
instance.update({ mode });
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
// 静态方法设置全局ThemeConfig
|
|
34
|
+
static setThemeConfig = (fn) => {
|
|
35
|
+
getThemeConfig = fn;
|
|
36
|
+
};
|
|
37
|
+
static open = (props) => {
|
|
38
|
+
const instance = openModal(MiModal, {
|
|
39
|
+
mode: globalMode, // 默认使用全局主题
|
|
40
|
+
...props,
|
|
41
|
+
});
|
|
42
|
+
// 注册实例以便全局更新
|
|
43
|
+
modalInstances.push(instance);
|
|
44
|
+
// 添加销毁时的清理逻辑
|
|
45
|
+
const originalDestroy = instance.destroy;
|
|
46
|
+
instance.destroy = (...args) => {
|
|
47
|
+
const index = modalInstances.indexOf(instance);
|
|
48
|
+
if (index !== -1) {
|
|
49
|
+
modalInstances.splice(index, 1);
|
|
50
|
+
}
|
|
51
|
+
return originalDestroy(...args);
|
|
52
|
+
};
|
|
53
|
+
return instance;
|
|
54
|
+
};
|
|
55
|
+
getTheme() {
|
|
56
|
+
const mode = this.props.mode || globalMode;
|
|
57
|
+
return getThemeConfig(mode);
|
|
58
|
+
}
|
|
59
|
+
handleCancel = (e) => {
|
|
60
|
+
this.props.onCancel?.(e);
|
|
61
|
+
this.props.onClosed?.({ cancel: true });
|
|
62
|
+
};
|
|
63
|
+
handleOk = (e) => {
|
|
64
|
+
this.props.onOk?.(e);
|
|
65
|
+
this.props.onClosed?.({ ok: true });
|
|
66
|
+
};
|
|
67
|
+
render() {
|
|
68
|
+
return (_jsx(ConfigProvider, { theme: this.getTheme(), componentSize: 'middle', componentDisabled: false, children: _jsx(AntModal, { maskClosable: false, open: this.props.open, onCancel: this.handleCancel, onOk: this.handleOk, okText: '\u786E\u5B9A', cancelText: '\u53D6\u6D88', ...this.props, children: this.props.children }) }));
|
|
69
|
+
}
|
|
70
|
+
}
|
package/dist/components/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export * from './MBreadcrumb';
|
|
|
3
3
|
export * from './MDescriptions';
|
|
4
4
|
export * from './MForm';
|
|
5
5
|
export { default as MForm } from './MForm';
|
|
6
|
-
|
|
6
|
+
export * from './MiModal';
|
|
7
7
|
export * from './MSearch';
|
|
8
8
|
export * from './MTable';
|
|
9
9
|
export * from './ThemeContext';
|