wok-ui-ext 0.1.0
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/LICENSE +21 -0
- package/README.en.md +75 -0
- package/README.md +75 -0
- package/dist/alert/index.d.ts +10 -0
- package/dist/alert/index.js +48 -0
- package/dist/alert/style.css +116 -0
- package/dist/avatar/index.d.ts +9 -0
- package/dist/avatar/index.js +30 -0
- package/dist/avatar/style.css +32 -0
- package/dist/badge/index.d.ts +32 -0
- package/dist/badge/index.js +61 -0
- package/dist/badge/style.css +68 -0
- package/dist/breadcrumb/index.d.ts +25 -0
- package/dist/breadcrumb/index.js +47 -0
- package/dist/breadcrumb/style.css +35 -0
- package/dist/button/index.d.ts +34 -0
- package/dist/button/index.js +57 -0
- package/dist/button/style.css +133 -0
- package/dist/card/index.d.ts +25 -0
- package/dist/card/index.js +29 -0
- package/dist/card/style.css +23 -0
- package/dist/collapse/index.d.ts +89 -0
- package/dist/collapse/index.js +213 -0
- package/dist/collapse/style.css +76 -0
- package/dist/context-menu/context-menu.d.ts +113 -0
- package/dist/context-menu/context-menu.js +150 -0
- package/dist/context-menu/index.d.ts +30 -0
- package/dist/context-menu/index.js +42 -0
- package/dist/context-menu/style.css +46 -0
- package/dist/date-picker/calendar-panel.d.ts +44 -0
- package/dist/date-picker/calendar-panel.js +180 -0
- package/dist/date-picker/date-picker.d.ts +29 -0
- package/dist/date-picker/date-picker.js +81 -0
- package/dist/date-picker/date-utils.d.ts +63 -0
- package/dist/date-picker/date-utils.js +130 -0
- package/dist/date-picker/index.d.ts +7 -0
- package/dist/date-picker/index.js +5 -0
- package/dist/date-picker/layer.d.ts +19 -0
- package/dist/date-picker/layer.js +36 -0
- package/dist/date-picker/range-picker.d.ts +30 -0
- package/dist/date-picker/range-picker.js +117 -0
- package/dist/date-picker/style.css +161 -0
- package/dist/description-list/index.d.ts +37 -0
- package/dist/description-list/index.js +145 -0
- package/dist/description-list/style.css +63 -0
- package/dist/divider/index.d.ts +29 -0
- package/dist/divider/index.js +29 -0
- package/dist/divider/style.css +50 -0
- package/dist/drawer/index.d.ts +51 -0
- package/dist/drawer/index.js +183 -0
- package/dist/drawer/style.css +100 -0
- package/dist/dropdown/index.d.ts +38 -0
- package/dist/dropdown/index.js +97 -0
- package/dist/dropdown/style.css +39 -0
- package/dist/empty/index.d.ts +11 -0
- package/dist/empty/index.js +20 -0
- package/dist/empty/style.css +19 -0
- package/dist/floating-layer/index.d.ts +109 -0
- package/dist/floating-layer/index.js +337 -0
- package/dist/floating-layer/style.css +5 -0
- package/dist/form/form-item/index.d.ts +26 -0
- package/dist/form/form-item/index.js +21 -0
- package/dist/form/form-item/style.css +33 -0
- package/dist/form/form-modal/index.d.ts +18 -0
- package/dist/form/form-modal/index.js +38 -0
- package/dist/form/form.d.ts +21 -0
- package/dist/form/form.js +28 -0
- package/dist/form/index.d.ts +4 -0
- package/dist/form/index.js +4 -0
- package/dist/form/select/index.d.ts +48 -0
- package/dist/form/select/index.js +94 -0
- package/dist/form/select/style.css +29 -0
- package/dist/global.css +71 -0
- package/dist/i18n/de-DE.d.ts +2 -0
- package/dist/i18n/de-DE.js +36 -0
- package/dist/i18n/en-US.d.ts +2 -0
- package/dist/i18n/en-US.js +36 -0
- package/dist/i18n/es-ES.d.ts +2 -0
- package/dist/i18n/es-ES.js +36 -0
- package/dist/i18n/fr-FR.d.ts +2 -0
- package/dist/i18n/fr-FR.js +36 -0
- package/dist/i18n/index.d.ts +12 -0
- package/dist/i18n/index.js +39 -0
- package/dist/i18n/ja-JP.d.ts +2 -0
- package/dist/i18n/ja-JP.js +36 -0
- package/dist/i18n/ko-KR.d.ts +2 -0
- package/dist/i18n/ko-KR.js +36 -0
- package/dist/i18n/messages.d.ts +40 -0
- package/dist/i18n/messages.js +1 -0
- package/dist/i18n/wok-ui/de-DE.d.ts +2 -0
- package/dist/i18n/wok-ui/de-DE.js +20 -0
- package/dist/i18n/wok-ui/es-ES.d.ts +2 -0
- package/dist/i18n/wok-ui/es-ES.js +20 -0
- package/dist/i18n/wok-ui/fr-FR.d.ts +2 -0
- package/dist/i18n/wok-ui/fr-FR.js +20 -0
- package/dist/i18n/wok-ui/ja-JP.d.ts +2 -0
- package/dist/i18n/wok-ui/ja-JP.js +20 -0
- package/dist/i18n/wok-ui/ko-KR.d.ts +2 -0
- package/dist/i18n/wok-ui/ko-KR.js +20 -0
- package/dist/i18n/wok-ui/zh-TW.d.ts +2 -0
- package/dist/i18n/wok-ui/zh-TW.js +20 -0
- package/dist/i18n/zh-CN.d.ts +2 -0
- package/dist/i18n/zh-CN.js +36 -0
- package/dist/i18n/zh-TW.d.ts +2 -0
- package/dist/i18n/zh-TW.js +36 -0
- package/dist/icons.d.ts +88 -0
- package/dist/icons.js +176 -0
- package/dist/image/index.d.ts +38 -0
- package/dist/image/index.js +97 -0
- package/dist/image/style.css +72 -0
- package/dist/image-preview/index.d.ts +26 -0
- package/dist/image-preview/index.js +134 -0
- package/dist/image-preview/style.css +96 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +45 -0
- package/dist/list/index.d.ts +32 -0
- package/dist/list/index.js +42 -0
- package/dist/list/list-item.d.ts +27 -0
- package/dist/list/list-item.js +51 -0
- package/dist/list/style.css +20 -0
- package/dist/loading/index.d.ts +10 -0
- package/dist/loading/index.js +46 -0
- package/dist/loading/style.css +48 -0
- package/dist/menu/index.d.ts +38 -0
- package/dist/menu/index.js +62 -0
- package/dist/menu/leaf-item.d.ts +12 -0
- package/dist/menu/leaf-item.js +41 -0
- package/dist/menu/style.css +117 -0
- package/dist/menu/sub-menu.d.ts +21 -0
- package/dist/menu/sub-menu.js +85 -0
- package/dist/menu/types.d.ts +36 -0
- package/dist/menu/types.js +1 -0
- package/dist/menu/utils.d.ts +11 -0
- package/dist/menu/utils.js +24 -0
- package/dist/modal/index.d.ts +23 -0
- package/dist/modal/index.js +79 -0
- package/dist/modal/modal.d.ts +76 -0
- package/dist/modal/modal.js +188 -0
- package/dist/modal/style.css +90 -0
- package/dist/pagination/index.d.ts +31 -0
- package/dist/pagination/index.js +215 -0
- package/dist/pagination/style.css +50 -0
- package/dist/popconfirm/api.d.ts +43 -0
- package/dist/popconfirm/api.js +77 -0
- package/dist/popconfirm/component.d.ts +47 -0
- package/dist/popconfirm/component.js +48 -0
- package/dist/popconfirm/index.d.ts +3 -0
- package/dist/popconfirm/index.js +3 -0
- package/dist/popconfirm/style.css +22 -0
- package/dist/popover/api.d.ts +36 -0
- package/dist/popover/api.js +61 -0
- package/dist/popover/component.d.ts +38 -0
- package/dist/popover/component.js +51 -0
- package/dist/popover/index.d.ts +3 -0
- package/dist/popover/index.js +3 -0
- package/dist/popover/style.css +102 -0
- package/dist/progress/index.d.ts +34 -0
- package/dist/progress/index.js +70 -0
- package/dist/progress/style.css +37 -0
- package/dist/quick-input/index.d.ts +2 -0
- package/dist/quick-input/index.js +2 -0
- package/dist/quick-input/number.d.ts +35 -0
- package/dist/quick-input/number.js +68 -0
- package/dist/quick-input/text.d.ts +20 -0
- package/dist/quick-input/text.js +61 -0
- package/dist/result/index.d.ts +39 -0
- package/dist/result/index.js +71 -0
- package/dist/result/style.css +41 -0
- package/dist/search-box/index.d.ts +26 -0
- package/dist/search-box/index.js +60 -0
- package/dist/search-box/style.css +22 -0
- package/dist/segmented/index.d.ts +42 -0
- package/dist/segmented/index.js +61 -0
- package/dist/segmented/style.css +28 -0
- package/dist/skeleton/index.d.ts +22 -0
- package/dist/skeleton/index.js +68 -0
- package/dist/skeleton/style.css +31 -0
- package/dist/steps/index.d.ts +46 -0
- package/dist/steps/index.js +95 -0
- package/dist/steps/style.css +181 -0
- package/dist/switch/index.d.ts +32 -0
- package/dist/switch/index.js +74 -0
- package/dist/switch/style.css +52 -0
- package/dist/table/body.d.ts +21 -0
- package/dist/table/body.js +35 -0
- package/dist/table/column.d.ts +78 -0
- package/dist/table/column.js +113 -0
- package/dist/table/header.d.ts +13 -0
- package/dist/table/header.js +15 -0
- package/dist/table/index.d.ts +41 -0
- package/dist/table/index.js +84 -0
- package/dist/table/row.d.ts +25 -0
- package/dist/table/row.js +74 -0
- package/dist/table/style.css +98 -0
- package/dist/tabs/index.d.ts +49 -0
- package/dist/tabs/index.js +76 -0
- package/dist/tabs/style.css +41 -0
- package/dist/tag/index.d.ts +53 -0
- package/dist/tag/index.js +100 -0
- package/dist/tag/style.css +134 -0
- package/dist/text/index.d.ts +104 -0
- package/dist/text/index.js +143 -0
- package/dist/text/style.css +113 -0
- package/dist/theme/index.d.ts +14 -0
- package/dist/theme/index.js +94 -0
- package/dist/theme/themes.d.ts +3 -0
- package/dist/theme/themes.js +323 -0
- package/dist/theme/types.d.ts +58 -0
- package/dist/theme/types.js +1 -0
- package/dist/timeline/index.d.ts +28 -0
- package/dist/timeline/index.js +35 -0
- package/dist/timeline/style.css +53 -0
- package/dist/toast/index.d.ts +53 -0
- package/dist/toast/index.js +131 -0
- package/dist/toast/style.css +76 -0
- package/dist/tooltip/api.d.ts +44 -0
- package/dist/tooltip/api.js +103 -0
- package/dist/tooltip/component.d.ts +28 -0
- package/dist/tooltip/component.js +35 -0
- package/dist/tooltip/index.d.ts +3 -0
- package/dist/tooltip/index.js +3 -0
- package/dist/tooltip/style.css +46 -0
- package/dist/tree/dragging-img.d.ts +13 -0
- package/dist/tree/dragging-img.js +23 -0
- package/dist/tree/index.d.ts +180 -0
- package/dist/tree/index.js +385 -0
- package/dist/tree/node-info.d.ts +63 -0
- package/dist/tree/node-info.js +128 -0
- package/dist/tree/node.d.ts +132 -0
- package/dist/tree/node.js +264 -0
- package/dist/tree/style.css +99 -0
- package/dist/upload/index.d.ts +48 -0
- package/dist/upload/index.js +141 -0
- package/dist/upload/style.css +41 -0
- package/package.json +51 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getWokUiExtI18n } from '../i18n';
|
|
2
|
+
import { IconExclamationCircle, IconQuestionCircle } from '../icons';
|
|
3
|
+
import { Modal } from './modal';
|
|
4
|
+
import './style.css';
|
|
5
|
+
export * from './modal';
|
|
6
|
+
/**
|
|
7
|
+
* 显示模态框
|
|
8
|
+
* @param opts 模态框选项
|
|
9
|
+
* @returns 模态框句柄
|
|
10
|
+
*/
|
|
11
|
+
export function showModal(opts) {
|
|
12
|
+
const modal = new Modal(opts);
|
|
13
|
+
modal.mount(document.body);
|
|
14
|
+
return {
|
|
15
|
+
close: () => {
|
|
16
|
+
modal.destroy();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 显示警告模态框
|
|
22
|
+
* @param msg 警告内容
|
|
23
|
+
*/
|
|
24
|
+
export function showAlert(opts) {
|
|
25
|
+
if (typeof opts === 'string') {
|
|
26
|
+
const msg = opts;
|
|
27
|
+
return new Promise(resolve => {
|
|
28
|
+
showAlert({
|
|
29
|
+
msg,
|
|
30
|
+
onConfirm: () => {
|
|
31
|
+
resolve();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const i18n = getWokUiExtI18n();
|
|
37
|
+
const modal = showModal({
|
|
38
|
+
title: i18n.buildMsg('alert-warning'),
|
|
39
|
+
titleIcon: new IconExclamationCircle(),
|
|
40
|
+
closeBtn: false,
|
|
41
|
+
body: opts.msg,
|
|
42
|
+
buttons: {
|
|
43
|
+
confirm: i18n.buildMsg('alert-ok')
|
|
44
|
+
},
|
|
45
|
+
onConfirm: () => {
|
|
46
|
+
modal.close();
|
|
47
|
+
opts.onConfirm?.();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export function showConfirm(opts) {
|
|
52
|
+
if (typeof opts === 'string') {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
showConfirm({
|
|
55
|
+
msg: opts,
|
|
56
|
+
onConfirm: () => resolve(true),
|
|
57
|
+
onCancel: () => resolve(false)
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const i18n = getWokUiExtI18n();
|
|
62
|
+
const modal = showModal({
|
|
63
|
+
title: i18n.buildMsg('modal-confirm'),
|
|
64
|
+
titleIcon: new IconQuestionCircle(),
|
|
65
|
+
closeBtn: false,
|
|
66
|
+
body: opts.msg,
|
|
67
|
+
buttons: {
|
|
68
|
+
confirm: i18n.buildMsg('modal-confirm'),
|
|
69
|
+
cancel: i18n.buildMsg('modal-cancel')
|
|
70
|
+
},
|
|
71
|
+
onConfirm: () => {
|
|
72
|
+
modal.close();
|
|
73
|
+
opts.onConfirm?.();
|
|
74
|
+
},
|
|
75
|
+
onClose: () => {
|
|
76
|
+
opts.onCancel?.();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ConvertibleModule, DivModule, RemoteSvgIcon, SubModulesOpt, SvgIcon } from 'wok-ui';
|
|
2
|
+
import { Button } from '../button';
|
|
3
|
+
/**
|
|
4
|
+
* 模态框选项
|
|
5
|
+
*/
|
|
6
|
+
export interface ModalOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 标题,无标题不出现头部.
|
|
9
|
+
*/
|
|
10
|
+
title?: SubModulesOpt;
|
|
11
|
+
/**
|
|
12
|
+
* 标题图标,无图标不出现图标.
|
|
13
|
+
*/
|
|
14
|
+
titleIcon?: SvgIcon | RemoteSvgIcon;
|
|
15
|
+
/**
|
|
16
|
+
* 是否出现关闭按钮.只在有标题的情况下有效,如果设置为true会在右上角出现关闭图标.默认为 true.
|
|
17
|
+
*/
|
|
18
|
+
closeBtn?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 主体部分.
|
|
21
|
+
*/
|
|
22
|
+
body: SubModulesOpt;
|
|
23
|
+
/**
|
|
24
|
+
* 使用 body 部分替换掉整个内容,且容器不再附加背景、圆角等外观样式,
|
|
25
|
+
* 外观完全由 body 自定义.
|
|
26
|
+
*/
|
|
27
|
+
replaceByBody?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 追加到模态框容器上的自定义 class,可用于覆盖默认样式.
|
|
30
|
+
*/
|
|
31
|
+
className?: string;
|
|
32
|
+
/**
|
|
33
|
+
* 宽度,默认 500px.
|
|
34
|
+
*/
|
|
35
|
+
width?: number;
|
|
36
|
+
/**
|
|
37
|
+
* 关闭回调.
|
|
38
|
+
*/
|
|
39
|
+
onClose?: () => void;
|
|
40
|
+
/**
|
|
41
|
+
* 确认回调,点击确认按钮后触发
|
|
42
|
+
*/
|
|
43
|
+
onConfirm?: () => void;
|
|
44
|
+
/**
|
|
45
|
+
* 自定义脚部,优先级高于按钮.
|
|
46
|
+
*/
|
|
47
|
+
footer?: ConvertibleModule;
|
|
48
|
+
/**
|
|
49
|
+
* 按钮设置,可选,可设置显示按钮或自定义按钮文字,有设置才会显示出来。
|
|
50
|
+
* 当值是 Button[] 类型时,可自定义多个按钮,需要注意按钮是从右往左排列的。
|
|
51
|
+
* 当值是 { confirm?: boolean | string, cancel?: boolean | string } 类型时,
|
|
52
|
+
* 会显示确认按钮和取消按钮,按钮文字可自定义,当值为 true 时,按钮文字为默认值。
|
|
53
|
+
* 确认按钮为主要按钮,取消按钮为次要按钮。
|
|
54
|
+
*/
|
|
55
|
+
buttons?: {
|
|
56
|
+
confirm?: boolean | string;
|
|
57
|
+
cancel?: boolean | string;
|
|
58
|
+
} | Button[];
|
|
59
|
+
/**
|
|
60
|
+
* 模态框完全显示回调,在模态框入场动画完成后触发
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
onShown?: () => void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 弹窗组件
|
|
67
|
+
*/
|
|
68
|
+
export declare class Modal extends DivModule {
|
|
69
|
+
private readonly opts;
|
|
70
|
+
private docChangeListener?;
|
|
71
|
+
private keydownListener?;
|
|
72
|
+
constructor(opts: ModalOptions);
|
|
73
|
+
mount(parentEl: Element): void;
|
|
74
|
+
private destroyed;
|
|
75
|
+
destroy(): void;
|
|
76
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { animate, ANIMATION_PROVISION, Animation, DivModule } from 'wok-ui';
|
|
2
|
+
import { Button } from '../button';
|
|
3
|
+
import { getWokUiExtI18n } from '../i18n';
|
|
4
|
+
import { IconTimes } from '../icons';
|
|
5
|
+
/**
|
|
6
|
+
* 弹窗组件
|
|
7
|
+
*/
|
|
8
|
+
export class Modal extends DivModule {
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
super('wok-ui-ext-modal-overlay');
|
|
11
|
+
this.opts = opts;
|
|
12
|
+
this.destroyed = false;
|
|
13
|
+
const i18n = getWokUiExtI18n();
|
|
14
|
+
document.body.classList.add('modal-open');
|
|
15
|
+
const containerClassNames = ['wok-ui-ext-modal-container', ANIMATION_PROVISION];
|
|
16
|
+
if (opts.replaceByBody) {
|
|
17
|
+
containerClassNames.push('wok-ui-ext-modal-replace-body');
|
|
18
|
+
}
|
|
19
|
+
if (opts.className) {
|
|
20
|
+
containerClassNames.push(opts.className);
|
|
21
|
+
}
|
|
22
|
+
this.addChild({
|
|
23
|
+
classNames: containerClassNames,
|
|
24
|
+
preHandle(el) {
|
|
25
|
+
if (typeof opts.width === 'number' && opts.width > 0) {
|
|
26
|
+
el.style.width = `${opts.width}px`;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
children: add => {
|
|
30
|
+
if (opts.replaceByBody) {
|
|
31
|
+
add(opts.body);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// 头部
|
|
35
|
+
if (opts.title) {
|
|
36
|
+
const title = opts.title;
|
|
37
|
+
add({
|
|
38
|
+
classNames: 'wok-ui-ext-modal-header',
|
|
39
|
+
children: add => {
|
|
40
|
+
// 标题
|
|
41
|
+
add({
|
|
42
|
+
tag: 'h3',
|
|
43
|
+
children: add => {
|
|
44
|
+
if (opts.titleIcon) {
|
|
45
|
+
add(opts.titleIcon, ' ');
|
|
46
|
+
}
|
|
47
|
+
add(title);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
// 关闭按钮
|
|
51
|
+
if (opts.closeBtn !== false) {
|
|
52
|
+
add({
|
|
53
|
+
tag: 'button',
|
|
54
|
+
classNames: 'wok-ui-ext-modal-close',
|
|
55
|
+
attrs: {
|
|
56
|
+
'aria-label': i18n.buildMsg('modal-close')
|
|
57
|
+
},
|
|
58
|
+
children: new IconTimes(),
|
|
59
|
+
onClick: () => {
|
|
60
|
+
this.destroy();
|
|
61
|
+
opts.onClose?.();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// body
|
|
69
|
+
add({
|
|
70
|
+
classNames: 'wok-ui-ext-modal-body',
|
|
71
|
+
children: opts.body
|
|
72
|
+
});
|
|
73
|
+
// footer
|
|
74
|
+
if (opts.footer) {
|
|
75
|
+
add({
|
|
76
|
+
classNames: 'wok-ui-ext-modal-footer',
|
|
77
|
+
children: opts.footer
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!opts.buttons) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const buttons = opts.buttons;
|
|
85
|
+
if ((Array.isArray(buttons) && buttons.length) ||
|
|
86
|
+
(!Array.isArray(buttons) && (buttons.confirm || buttons.cancel))) {
|
|
87
|
+
add({
|
|
88
|
+
classNames: 'wok-ui-ext-modal-footer',
|
|
89
|
+
children: add => {
|
|
90
|
+
if (Array.isArray(buttons)) {
|
|
91
|
+
add(...buttons);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// 确定和取消
|
|
95
|
+
if (buttons.cancel) {
|
|
96
|
+
add(new Button({
|
|
97
|
+
type: 'secondary',
|
|
98
|
+
text: buttons.cancel === true ? i18n.buildMsg('modal-cancel') : buttons.cancel,
|
|
99
|
+
onClick: () => {
|
|
100
|
+
this.destroy();
|
|
101
|
+
opts.onClose?.();
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
if (buttons.confirm) {
|
|
106
|
+
add(new Button({
|
|
107
|
+
type: 'primary',
|
|
108
|
+
text: buttons.confirm === true ? i18n.buildMsg('modal-confirm') : buttons.confirm,
|
|
109
|
+
onClick: () => opts.onConfirm?.()
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
// 监听文档变化,当路由变化时自动关闭
|
|
118
|
+
this.docChangeListener = () => this.destroy();
|
|
119
|
+
window.addEventListener('popstate', this.docChangeListener, { once: true });
|
|
120
|
+
// Esc 键关闭
|
|
121
|
+
this.keydownListener = (e) => {
|
|
122
|
+
if (e.key === 'Escape') {
|
|
123
|
+
const btns = opts.buttons;
|
|
124
|
+
const hasCancelBtn = !Array.isArray(btns) && btns && btns.cancel;
|
|
125
|
+
if (hasCancelBtn) {
|
|
126
|
+
// 有取消按钮 → 触发取消行为(showConfirm 的取消回调)
|
|
127
|
+
opts.onClose?.();
|
|
128
|
+
this.destroy();
|
|
129
|
+
}
|
|
130
|
+
else if (!Array.isArray(btns) && btns && btns.confirm) {
|
|
131
|
+
// 只有确认按钮 → 触发确认行为(showAlert 的确认回调)
|
|
132
|
+
opts.onConfirm?.();
|
|
133
|
+
this.destroy();
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
// 无按钮或自定义按钮数组 → 直接关闭
|
|
137
|
+
this.destroy();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
document.addEventListener('keydown', this.keydownListener);
|
|
142
|
+
}
|
|
143
|
+
mount(parentEl) {
|
|
144
|
+
parentEl.appendChild(this.el);
|
|
145
|
+
const container = this.el.querySelector('.wok-ui-ext-modal-container');
|
|
146
|
+
if (container) {
|
|
147
|
+
animate({
|
|
148
|
+
el: container,
|
|
149
|
+
animation: Animation.SCALE_UP,
|
|
150
|
+
duration: 200
|
|
151
|
+
}).then(() => {
|
|
152
|
+
this.opts.onShown?.();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
destroy() {
|
|
157
|
+
if (this.destroyed)
|
|
158
|
+
return;
|
|
159
|
+
this.destroyed = true;
|
|
160
|
+
const container = this.el.querySelector('.wok-ui-ext-modal-container');
|
|
161
|
+
const doDestroy = () => {
|
|
162
|
+
// 先清理事件监听,再销毁 DOM
|
|
163
|
+
if (this.docChangeListener) {
|
|
164
|
+
document.removeEventListener('popstate', this.docChangeListener);
|
|
165
|
+
}
|
|
166
|
+
if (this.keydownListener) {
|
|
167
|
+
document.removeEventListener('keydown', this.keydownListener);
|
|
168
|
+
}
|
|
169
|
+
if (!document.querySelector('.wok-ui-ext-modal-overlay')) {
|
|
170
|
+
document.body.classList.remove('modal-open');
|
|
171
|
+
}
|
|
172
|
+
super.destroy();
|
|
173
|
+
};
|
|
174
|
+
if (container) {
|
|
175
|
+
animate({
|
|
176
|
+
el: container,
|
|
177
|
+
animation: Animation.SCALE_UP,
|
|
178
|
+
reverse: true,
|
|
179
|
+
duration: 200
|
|
180
|
+
}).then(() => {
|
|
181
|
+
doDestroy();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
doDestroy();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
.wok-ui-ext-modal-overlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
background: rgba(8, 20, 40, 0.6);
|
|
8
|
+
backdrop-filter: blur(5px);
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
z-index: 1000;
|
|
13
|
+
}
|
|
14
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container {
|
|
15
|
+
background: var(--bg-card);
|
|
16
|
+
width: 440px;
|
|
17
|
+
max-width: 90%;
|
|
18
|
+
border-radius: 32px;
|
|
19
|
+
box-shadow: 0 30px 60px rgba(0, 20, 50, 0.5);
|
|
20
|
+
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
max-height: 100%;
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
}
|
|
26
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container.wok-ui-ext-modal-replace-body {
|
|
27
|
+
background: none;
|
|
28
|
+
border: none;
|
|
29
|
+
border-radius: 0;
|
|
30
|
+
box-shadow: none;
|
|
31
|
+
overflow: visible;
|
|
32
|
+
display: block;
|
|
33
|
+
}
|
|
34
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container .wok-ui-ext-modal-header {
|
|
35
|
+
padding: 20px 24px 8px 24px;
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: space-between;
|
|
39
|
+
flex-shrink: 0;
|
|
40
|
+
}
|
|
41
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container .wok-ui-ext-modal-header h3 {
|
|
42
|
+
font-size: 20px;
|
|
43
|
+
font-weight: 600;
|
|
44
|
+
color: var(--text-primary);
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
gap: 8px;
|
|
48
|
+
}
|
|
49
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container .wok-ui-ext-modal-header h3 svg {
|
|
50
|
+
font-size: 20px;
|
|
51
|
+
color: var(--color-primary);
|
|
52
|
+
}
|
|
53
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container .wok-ui-ext-modal-header .wok-ui-ext-modal-close {
|
|
54
|
+
background: transparent;
|
|
55
|
+
border: none;
|
|
56
|
+
font-size: 24px;
|
|
57
|
+
color: var(--text-placeholder);
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
width: 32px;
|
|
60
|
+
height: 32px;
|
|
61
|
+
display: flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
border-radius: var(--radius-full);
|
|
65
|
+
transition: background 0.1s;
|
|
66
|
+
padding: 0;
|
|
67
|
+
}
|
|
68
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container .wok-ui-ext-modal-header .wok-ui-ext-modal-close:hover {
|
|
69
|
+
background: var(--bg-hover);
|
|
70
|
+
color: var(--text-secondary);
|
|
71
|
+
}
|
|
72
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container .wok-ui-ext-modal-body {
|
|
73
|
+
padding: 8px 24px 24px 24px;
|
|
74
|
+
color: var(--text-secondary);
|
|
75
|
+
font-size: 16px;
|
|
76
|
+
line-height: 1.5;
|
|
77
|
+
flex-grow: 1;
|
|
78
|
+
overflow: auto;
|
|
79
|
+
}
|
|
80
|
+
.wok-ui-ext-modal-overlay .wok-ui-ext-modal-container .wok-ui-ext-modal-footer {
|
|
81
|
+
padding: 16px 24px;
|
|
82
|
+
display: flex;
|
|
83
|
+
justify-content: flex-end;
|
|
84
|
+
gap: 12px;
|
|
85
|
+
border-top: 1px solid var(--border-light);
|
|
86
|
+
flex-shrink: 0;
|
|
87
|
+
}
|
|
88
|
+
body.modal-open {
|
|
89
|
+
overflow: hidden;
|
|
90
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FullRenderingModule } from 'wok-ui';
|
|
2
|
+
import './style.less';
|
|
3
|
+
/**
|
|
4
|
+
* 分页组件
|
|
5
|
+
*/
|
|
6
|
+
export declare class Pagination extends FullRenderingModule {
|
|
7
|
+
private opts;
|
|
8
|
+
private pn;
|
|
9
|
+
/**
|
|
10
|
+
* 分页组件
|
|
11
|
+
* @param opts
|
|
12
|
+
* @param opts.total 总条数
|
|
13
|
+
* @param opts.pz 每页条数
|
|
14
|
+
* @param opts.pn 当前页码
|
|
15
|
+
* @param opts.simple 简洁模式,仅显示上下页 + 页码信息(默认 false)
|
|
16
|
+
* @param opts.onChange 分页回调
|
|
17
|
+
*/
|
|
18
|
+
constructor(opts: {
|
|
19
|
+
total: number;
|
|
20
|
+
pz: number;
|
|
21
|
+
pn: number;
|
|
22
|
+
simple?: boolean;
|
|
23
|
+
onChange: (pn: number, pz: number) => void;
|
|
24
|
+
});
|
|
25
|
+
private calcPageNumbers;
|
|
26
|
+
protected buildContent(): void;
|
|
27
|
+
/** 简洁模式:仅上下页 + 页码信息 */
|
|
28
|
+
private buildSimpleContent;
|
|
29
|
+
/** 完整模式:页码按钮 + 省略号 */
|
|
30
|
+
private buildFullContent;
|
|
31
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { FullRenderingModule } from 'wok-ui';
|
|
2
|
+
import './style.css';
|
|
3
|
+
import { getWokUiExtI18n } from '../i18n';
|
|
4
|
+
import { IconChevronLeft, IconChevronRight } from '../icons';
|
|
5
|
+
/**
|
|
6
|
+
* 分页组件
|
|
7
|
+
*/
|
|
8
|
+
export class Pagination extends FullRenderingModule {
|
|
9
|
+
/**
|
|
10
|
+
* 分页组件
|
|
11
|
+
* @param opts
|
|
12
|
+
* @param opts.total 总条数
|
|
13
|
+
* @param opts.pz 每页条数
|
|
14
|
+
* @param opts.pn 当前页码
|
|
15
|
+
* @param opts.simple 简洁模式,仅显示上下页 + 页码信息(默认 false)
|
|
16
|
+
* @param opts.onChange 分页回调
|
|
17
|
+
*/
|
|
18
|
+
constructor(opts) {
|
|
19
|
+
super();
|
|
20
|
+
this.opts = opts;
|
|
21
|
+
this.el.classList.add('wok-ui-ext-pagination');
|
|
22
|
+
this.el.setAttribute('role', 'navigation');
|
|
23
|
+
this.el.setAttribute('aria-label', 'Pagination');
|
|
24
|
+
if (opts.simple) {
|
|
25
|
+
this.el.classList.add('wok-ui-ext-pagination-simple');
|
|
26
|
+
}
|
|
27
|
+
this.pn = opts.pn;
|
|
28
|
+
this.render();
|
|
29
|
+
}
|
|
30
|
+
calcPageNumbers() {
|
|
31
|
+
const { total, pz } = this.opts;
|
|
32
|
+
const pn = this.pn;
|
|
33
|
+
const totalPages = Math.ceil(total / pz);
|
|
34
|
+
const maxPagesToShow = 5;
|
|
35
|
+
const halfMaxPagesToShow = Math.floor(maxPagesToShow / 2);
|
|
36
|
+
const startPage = Math.max(1, pn - halfMaxPagesToShow);
|
|
37
|
+
const endPage = Math.min(totalPages, pn + halfMaxPagesToShow);
|
|
38
|
+
const pageNumbers = [];
|
|
39
|
+
for (let i = startPage; i <= endPage; i++) {
|
|
40
|
+
pageNumbers.push(i);
|
|
41
|
+
}
|
|
42
|
+
if (startPage > 1) {
|
|
43
|
+
pageNumbers.unshift('...');
|
|
44
|
+
pageNumbers.unshift(1);
|
|
45
|
+
}
|
|
46
|
+
if (endPage < totalPages) {
|
|
47
|
+
pageNumbers.push('...');
|
|
48
|
+
pageNumbers.push(totalPages);
|
|
49
|
+
}
|
|
50
|
+
if (pn > 1) {
|
|
51
|
+
pageNumbers.unshift('<');
|
|
52
|
+
}
|
|
53
|
+
if (pn < totalPages) {
|
|
54
|
+
pageNumbers.push('>');
|
|
55
|
+
}
|
|
56
|
+
return pageNumbers;
|
|
57
|
+
}
|
|
58
|
+
buildContent() {
|
|
59
|
+
if (this.opts.simple) {
|
|
60
|
+
this.buildSimpleContent();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.buildFullContent();
|
|
64
|
+
}
|
|
65
|
+
/** 简洁模式:仅上下页 + 页码信息 */
|
|
66
|
+
buildSimpleContent() {
|
|
67
|
+
const i18n = getWokUiExtI18n();
|
|
68
|
+
const { total, pz } = this.opts;
|
|
69
|
+
const totalPages = Math.ceil(total / pz);
|
|
70
|
+
if (totalPages <= 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const isFirst = this.pn <= 1;
|
|
74
|
+
const isLast = this.pn >= totalPages;
|
|
75
|
+
this.addChild({
|
|
76
|
+
tag: 'button',
|
|
77
|
+
classNames: ['wok-ui-ext-page-item', 'prev'],
|
|
78
|
+
attrs: {
|
|
79
|
+
type: 'button',
|
|
80
|
+
'aria-label': i18n.buildMsg('pagination-prev-page'),
|
|
81
|
+
disabled: isFirst ? true : undefined
|
|
82
|
+
},
|
|
83
|
+
children: new IconChevronLeft(),
|
|
84
|
+
preHandle: el => {
|
|
85
|
+
if (isFirst) {
|
|
86
|
+
el.classList.add('disabled');
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
onClick: () => {
|
|
90
|
+
if (this.pn > 1) {
|
|
91
|
+
this.pn--;
|
|
92
|
+
this.render();
|
|
93
|
+
this.opts.onChange(this.pn, this.opts.pz);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
this.addChild({
|
|
98
|
+
classNames: ['wok-ui-ext-page-info'],
|
|
99
|
+
attrs: {
|
|
100
|
+
'aria-current': 'page'
|
|
101
|
+
},
|
|
102
|
+
children: i18n.buildMsg('pagination-simple-format', `${this.pn}`, `${totalPages}`)
|
|
103
|
+
});
|
|
104
|
+
this.addChild({
|
|
105
|
+
tag: 'button',
|
|
106
|
+
classNames: ['wok-ui-ext-page-item', 'next'],
|
|
107
|
+
attrs: {
|
|
108
|
+
type: 'button',
|
|
109
|
+
'aria-label': i18n.buildMsg('pagination-next-page'),
|
|
110
|
+
disabled: isLast ? true : undefined
|
|
111
|
+
},
|
|
112
|
+
children: new IconChevronRight(),
|
|
113
|
+
preHandle: el => {
|
|
114
|
+
if (isLast) {
|
|
115
|
+
el.classList.add('disabled');
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
onClick: () => {
|
|
119
|
+
if (this.pn < totalPages) {
|
|
120
|
+
this.pn++;
|
|
121
|
+
this.render();
|
|
122
|
+
this.opts.onChange(this.pn, this.opts.pz);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** 完整模式:页码按钮 + 省略号 */
|
|
128
|
+
buildFullContent() {
|
|
129
|
+
const i18n = getWokUiExtI18n();
|
|
130
|
+
const { total, pz } = this.opts;
|
|
131
|
+
const totalPages = Math.ceil(total / pz);
|
|
132
|
+
this.addChild({
|
|
133
|
+
classNames: ['wok-ui-ext-page-total'],
|
|
134
|
+
children: i18n.buildMsg('pagination-total', `${total}`)
|
|
135
|
+
});
|
|
136
|
+
if (totalPages <= 1) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const pageNumbers = this.calcPageNumbers();
|
|
140
|
+
for (const page of pageNumbers) {
|
|
141
|
+
const isPrev = page === '<';
|
|
142
|
+
const isNext = page === '>';
|
|
143
|
+
const isEllipsis = page === '...';
|
|
144
|
+
const pageNumber = typeof page === 'number' ? page : undefined;
|
|
145
|
+
const isActive = pageNumber === this.pn;
|
|
146
|
+
let label;
|
|
147
|
+
if (isPrev) {
|
|
148
|
+
label = i18n.buildMsg('pagination-prev-page');
|
|
149
|
+
}
|
|
150
|
+
else if (isNext) {
|
|
151
|
+
label = i18n.buildMsg('pagination-next-page');
|
|
152
|
+
}
|
|
153
|
+
else if (pageNumber !== undefined) {
|
|
154
|
+
label = i18n.buildMsg('pagination-page', `${pageNumber}`);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
label = '';
|
|
158
|
+
}
|
|
159
|
+
this.addChild({
|
|
160
|
+
tag: 'button',
|
|
161
|
+
classNames: ['wok-ui-ext-page-item'],
|
|
162
|
+
attrs: {
|
|
163
|
+
type: 'button',
|
|
164
|
+
'aria-label': label,
|
|
165
|
+
'aria-current': isActive ? 'page' : undefined,
|
|
166
|
+
disabled: isEllipsis ? true : undefined
|
|
167
|
+
},
|
|
168
|
+
children: add => {
|
|
169
|
+
if (isPrev) {
|
|
170
|
+
add(new IconChevronLeft());
|
|
171
|
+
}
|
|
172
|
+
else if (isNext) {
|
|
173
|
+
add(new IconChevronRight());
|
|
174
|
+
}
|
|
175
|
+
else if (pageNumber !== undefined) {
|
|
176
|
+
add(`${pageNumber}`);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
add('...');
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
preHandle: el => {
|
|
183
|
+
if (isActive) {
|
|
184
|
+
el.classList.add('active');
|
|
185
|
+
}
|
|
186
|
+
if (isEllipsis) {
|
|
187
|
+
el.classList.add('disabled');
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
onClick: () => {
|
|
191
|
+
if (isEllipsis) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (isPrev) {
|
|
195
|
+
this.pn = this.pn - 1;
|
|
196
|
+
if (this.pn < 1) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (isNext) {
|
|
201
|
+
this.pn = this.pn + 1;
|
|
202
|
+
if (this.pn > totalPages) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (pageNumber !== undefined) {
|
|
207
|
+
this.pn = pageNumber;
|
|
208
|
+
}
|
|
209
|
+
this.render();
|
|
210
|
+
this.opts.onChange(this.pn, this.opts.pz);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|