luna-plus 0.0.8 → 0.0.9
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/MessageBox/index.js
CHANGED
|
@@ -1,32 +1,85 @@
|
|
|
1
|
+
import { mount, unmount } from 'svelte';
|
|
2
|
+
import MessageBox from './MessageBox.svelte';
|
|
3
|
+
let containerEl = null;
|
|
4
|
+
let messageBoxInstance = null;
|
|
5
|
+
/** 确保 MessageBox 容器已挂载 */
|
|
6
|
+
const ensureContainer = () => {
|
|
7
|
+
if (typeof window === 'undefined')
|
|
8
|
+
return;
|
|
9
|
+
if (containerEl)
|
|
10
|
+
return;
|
|
11
|
+
containerEl = document.createElement('div');
|
|
12
|
+
containerEl.className = 'lm-messagebox-container';
|
|
13
|
+
document.body.appendChild(containerEl);
|
|
14
|
+
messageBoxInstance = mount(MessageBox, {
|
|
15
|
+
target: containerEl,
|
|
16
|
+
props: {}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
1
19
|
/** 显示消息框 */
|
|
2
20
|
export const showMessageBox = (options) => {
|
|
3
21
|
return new Promise((resolve) => {
|
|
4
|
-
|
|
5
|
-
options.onOk?.();
|
|
6
|
-
resolve(true);
|
|
7
|
-
};
|
|
8
|
-
const onCancel = () => {
|
|
9
|
-
options.onCancel?.();
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
10
23
|
resolve(false);
|
|
11
|
-
|
|
12
|
-
// 实际实现需要挂载组件,这里提供基础结构
|
|
13
|
-
console.log('MessageBox:', options);
|
|
14
|
-
// 模拟异步确认
|
|
15
|
-
if (typeof window !== 'undefined' && window.confirm(options.content)) {
|
|
16
|
-
onOk();
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
onCancel();
|
|
24
|
+
return;
|
|
20
25
|
}
|
|
26
|
+
ensureContainer();
|
|
27
|
+
const wrappedOptions = {
|
|
28
|
+
...options,
|
|
29
|
+
onOk: () => {
|
|
30
|
+
options.onOk?.();
|
|
31
|
+
resolve(true);
|
|
32
|
+
},
|
|
33
|
+
onCancel: () => {
|
|
34
|
+
options.onCancel?.();
|
|
35
|
+
resolve(false);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// 派发自定义事件触发 MessageBox 组件
|
|
39
|
+
const event = new CustomEvent('lumen-messagebox', {
|
|
40
|
+
detail: wrappedOptions
|
|
41
|
+
});
|
|
42
|
+
window.dispatchEvent(event);
|
|
21
43
|
});
|
|
22
44
|
};
|
|
23
45
|
/** 便捷方法 */
|
|
24
46
|
export const messageBox = {
|
|
25
47
|
show: showMessageBox,
|
|
26
|
-
alert: (content, title) => showMessageBox({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
48
|
+
alert: (content, title) => showMessageBox({
|
|
49
|
+
content,
|
|
50
|
+
title,
|
|
51
|
+
type: 'info',
|
|
52
|
+
okText: '确定'
|
|
53
|
+
}),
|
|
54
|
+
confirm: (content, title) => showMessageBox({
|
|
55
|
+
content,
|
|
56
|
+
title,
|
|
57
|
+
type: 'warning',
|
|
58
|
+
okText: '确定',
|
|
59
|
+
cancelText: '取消'
|
|
60
|
+
}),
|
|
61
|
+
success: (content, title) => showMessageBox({
|
|
62
|
+
content,
|
|
63
|
+
title,
|
|
64
|
+
type: 'success',
|
|
65
|
+
okText: '确定'
|
|
66
|
+
}),
|
|
67
|
+
warning: (content, title) => showMessageBox({
|
|
68
|
+
content,
|
|
69
|
+
title,
|
|
70
|
+
type: 'warning',
|
|
71
|
+
okText: '确定'
|
|
72
|
+
}),
|
|
73
|
+
error: (content, title) => showMessageBox({
|
|
74
|
+
content,
|
|
75
|
+
title,
|
|
76
|
+
type: 'error',
|
|
77
|
+
okText: '确定'
|
|
78
|
+
}),
|
|
79
|
+
info: (content, title) => showMessageBox({
|
|
80
|
+
content,
|
|
81
|
+
title,
|
|
82
|
+
type: 'info',
|
|
83
|
+
okText: '确定'
|
|
84
|
+
})
|
|
32
85
|
};
|