easy-component-ui 0.0.2 → 1.0.3
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/components/Base.js +90 -0
- package/components/ea-alert/index.js +298 -0
- package/components/ea-avatar/index.js +277 -0
- package/components/ea-backtop/index.js +232 -0
- package/components/ea-badge/index.js +160 -0
- package/components/ea-button/index.js +584 -0
- package/components/ea-button-group/index.js +459 -0
- package/components/ea-calendar/index.js +409 -0
- package/components/ea-card/index.js +77 -0
- package/components/ea-carousel/index.js +434 -0
- package/components/ea-checkbox/index.js +314 -0
- package/components/ea-checkbox-group/index.js +107 -0
- package/components/ea-collapse/index.js +293 -0
- package/components/ea-descriptions/index.js +240 -0
- package/components/ea-descriptions-item/index.js +110 -0
- package/components/ea-empty/index.js +141 -0
- package/{icon → components/ea-icon}/config.json +1017 -1017
- package/{icon → components/ea-icon}/css/animation.css +85 -85
- package/{icon → components/ea-icon}/css/fontello.css +224 -224
- package/components/ea-icon/font/fontello.svg +683 -0
- package/components/ea-icon/index.css +2 -0
- package/components/ea-icon/index.js +47 -0
- package/components/ea-image/index.js +412 -0
- package/components/ea-infinite-scroll/index.js +170 -0
- package/components/ea-input/index.js +765 -0
- package/components/ea-input-number/index.js +458 -0
- package/components/ea-link/index.js +200 -0
- package/components/ea-loading/index.js +218 -0
- package/components/ea-message/MessageClass.js +71 -0
- package/components/ea-message/index.js +233 -0
- package/components/ea-message-box/EaMessageBoxClass.js +48 -0
- package/components/ea-message-box/index.js +202 -0
- package/components/ea-pagination/index.js +444 -0
- package/components/ea-progress/index.js +333 -0
- package/components/ea-radio/index.js +287 -0
- package/components/ea-radio-group/index.js +59 -0
- package/components/ea-rate/index.js +326 -0
- package/components/ea-result/index.js +167 -0
- package/components/ea-select/index.js +34 -0
- package/components/ea-skeleton/index.js +341 -0
- package/components/ea-switch/index.js +301 -0
- package/components/ea-tag/index.js +212 -0
- package/components/ea-textarea/index.js +333 -0
- package/components/ea-timeline/index.js +334 -0
- package/components/ea-ui-base-style.css +0 -0
- package/package.json +1 -1
- package/utils/createElement.js +30 -0
- package/utils/handleTemplate.js +19 -0
- package/utils/setStyle.js +8 -0
- package/icon/font/fontello.svg +0 -346
- package/icon/index.css +0 -2
- package/index.js +0 -1693
- /package/{icon → components/ea-icon}/css/fontello-codes.css +0 -0
- /package/{icon → components/ea-icon}/css/fontello-embedded.css +0 -0
- /package/{icon → components/ea-icon}/css/fontello-ie7-codes.css +0 -0
- /package/{icon → components/ea-icon}/css/fontello-ie7.css +0 -0
- /package/{icon → components/ea-icon}/font/fontello.eot +0 -0
- /package/{icon → components/ea-icon}/font/fontello.ttf +0 -0
- /package/{icon → components/ea-icon}/font/fontello.woff +0 -0
- /package/{icon → components/ea-icon}/font/fontello.woff2 +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { createElement, createSlotElement } from '../../utils/createElement.js';
|
|
3
|
+
import Base from '../Base.js';
|
|
4
|
+
import "../ea-icon/index.js"
|
|
5
|
+
|
|
6
|
+
const stylesheet = `
|
|
7
|
+
.ea-loading_wrap {
|
|
8
|
+
position: relative;
|
|
9
|
+
}
|
|
10
|
+
.ea-loading_wrap i {
|
|
11
|
+
opacity: 0;
|
|
12
|
+
transition: opacity 0.2s;
|
|
13
|
+
color: #409eff;
|
|
14
|
+
}
|
|
15
|
+
.ea-loading_wrap .ea-loading_text {
|
|
16
|
+
color: #409eff;
|
|
17
|
+
margin-left: 0.5rem;
|
|
18
|
+
}
|
|
19
|
+
.ea-loading_wrap.ea-loading_wrap--fullscreen {
|
|
20
|
+
position: fixed;
|
|
21
|
+
left: 0;
|
|
22
|
+
top: 0;
|
|
23
|
+
z-index: 999;
|
|
24
|
+
width: 100%;
|
|
25
|
+
height: 100%;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
}
|
|
28
|
+
.ea-loading_wrap.ea-loading_wrap--loading .ea-loading_mask {
|
|
29
|
+
position: absolute;
|
|
30
|
+
top: 0;
|
|
31
|
+
left: 0;
|
|
32
|
+
display: flex;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
align-items: center;
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
background-color: hsla(0, 0%, 100%, 0.9);
|
|
38
|
+
z-index: 1;
|
|
39
|
+
transition: background-color 0.2s;
|
|
40
|
+
}
|
|
41
|
+
.ea-loading_wrap.ea-loading_wrap--loading .ea-loading_mask i {
|
|
42
|
+
opacity: 1;
|
|
43
|
+
font-size: 2rem;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
export class EaLoading extends Base {
|
|
48
|
+
#wrap;
|
|
49
|
+
|
|
50
|
+
#loadingWrap;
|
|
51
|
+
|
|
52
|
+
#spinner;
|
|
53
|
+
constructor() {
|
|
54
|
+
super();
|
|
55
|
+
|
|
56
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
57
|
+
const wrap = document.createElement('div');
|
|
58
|
+
wrap.className = 'ea-loading_wrap';
|
|
59
|
+
|
|
60
|
+
const spinner = createElement('i', 'ea-loading_spinner animate-spin');
|
|
61
|
+
const loading = createElement('div', 'ea-loading', spinner);
|
|
62
|
+
const loadingWrap = createElement('div', 'ea-loading_mask', loading);
|
|
63
|
+
wrap.appendChild(loadingWrap);
|
|
64
|
+
|
|
65
|
+
const slot = createSlotElement('')
|
|
66
|
+
wrap.appendChild(slot);
|
|
67
|
+
|
|
68
|
+
this.#wrap = wrap;
|
|
69
|
+
this.#loadingWrap = loadingWrap;
|
|
70
|
+
this.#spinner = spinner;
|
|
71
|
+
|
|
72
|
+
this.build(shadowRoot, stylesheet);
|
|
73
|
+
this.setIconFile(new URL('../ea-icon/index.css', import.meta.url).href);
|
|
74
|
+
|
|
75
|
+
this.shadowRoot.appendChild(wrap);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ------- loading 加载状态 -------
|
|
79
|
+
// #region
|
|
80
|
+
get loading() {
|
|
81
|
+
return this.getAttrBoolean('loading') || false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
set loading(flag) {
|
|
85
|
+
this.toggleAttr('loading', flag);
|
|
86
|
+
|
|
87
|
+
if (flag) {
|
|
88
|
+
this.#wrap.classList.add('ea-loading_wrap--loading');
|
|
89
|
+
this.#loadingWrap.style.display = "flex";
|
|
90
|
+
} else {
|
|
91
|
+
this.#wrap.classList.remove('ea-loading_wrap--loading');
|
|
92
|
+
this.#loadingWrap.style.display = "none";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.handleFullscreen(this.fullscreen, flag, this.lock);
|
|
96
|
+
}
|
|
97
|
+
// #endregion
|
|
98
|
+
// ------- end -------
|
|
99
|
+
|
|
100
|
+
// ------- spinner 加载图标 -------
|
|
101
|
+
// #region
|
|
102
|
+
get spinner() {
|
|
103
|
+
return this.getAttribute('spinner') || "icon-spin6";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
set spinner(val) {
|
|
107
|
+
this.setAttribute('spinner', val);
|
|
108
|
+
|
|
109
|
+
this.#spinner.className = `ea-loading_spinner animate-spin ${val}`;
|
|
110
|
+
}
|
|
111
|
+
// #endregion
|
|
112
|
+
// ------- end -------
|
|
113
|
+
|
|
114
|
+
// ------- spinner-size 加载图标大小 -------
|
|
115
|
+
// #region
|
|
116
|
+
get spinnerSize() {
|
|
117
|
+
return this.getAttrNumber('spinner-size') || 16;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
set spinnerSize(val) {
|
|
121
|
+
this.setAttribute('spinner-size', val);
|
|
122
|
+
|
|
123
|
+
this.#spinner.style.fontSize = `${val}px`;
|
|
124
|
+
}
|
|
125
|
+
// #endregion
|
|
126
|
+
// ------- end -------
|
|
127
|
+
|
|
128
|
+
// ------- background 背景颜色 -------
|
|
129
|
+
// #region
|
|
130
|
+
get background() {
|
|
131
|
+
return this.getAttribute('background') || "hsla(0, 0%, 100%, 0.9)";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
set background(val) {
|
|
135
|
+
this.setAttribute('background', val);
|
|
136
|
+
|
|
137
|
+
this.#loadingWrap.style.backgroundColor = val;
|
|
138
|
+
}
|
|
139
|
+
// #endregion
|
|
140
|
+
// ------- end -------
|
|
141
|
+
|
|
142
|
+
// ------- text 文本 -------
|
|
143
|
+
// #region
|
|
144
|
+
get text() {
|
|
145
|
+
return this.getAttribute('text') || "";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
set text(val) {
|
|
149
|
+
this.setAttribute('text', val);
|
|
150
|
+
}
|
|
151
|
+
// #endregion
|
|
152
|
+
// ------- end -------
|
|
153
|
+
|
|
154
|
+
// ------- fullscreen 全屏 -------
|
|
155
|
+
// #region
|
|
156
|
+
get fullscreen() {
|
|
157
|
+
return this.getAttrBoolean('fullscreen') || false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
set fullscreen(val) {
|
|
161
|
+
this.setAttribute('fullscreen', val);
|
|
162
|
+
}
|
|
163
|
+
// #endregion
|
|
164
|
+
// ------- end -------
|
|
165
|
+
|
|
166
|
+
// ------- lock 全屏是否锁定 -------
|
|
167
|
+
// #region
|
|
168
|
+
get lock() {
|
|
169
|
+
return this.getAttrBoolean('lock') || false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
set lock(val) {
|
|
173
|
+
this.setAttribute('lock', val);
|
|
174
|
+
}
|
|
175
|
+
// #endregion
|
|
176
|
+
// ------- end -------
|
|
177
|
+
|
|
178
|
+
initTextElement(text) {
|
|
179
|
+
const el = createElement('div', 'ea-loading_text');
|
|
180
|
+
el.innerHTML = text;
|
|
181
|
+
this.#loadingWrap.appendChild(el);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
handleFullscreen(isFullscreen, isLoading, isLock) {
|
|
185
|
+
if (isFullscreen) {
|
|
186
|
+
this.#wrap.classList.toggle('ea-loading_wrap--fullscreen', isLoading);
|
|
187
|
+
this.#wrap.style.display = isLoading ? 'block' : 'none';
|
|
188
|
+
|
|
189
|
+
if (isLock) document.body.style.overflow = isLoading ? 'hidden' : 'auto';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
init() {
|
|
194
|
+
const that = this;
|
|
195
|
+
|
|
196
|
+
this.fullscreen = this.fullscreen;
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
this.loading = this.loading;
|
|
201
|
+
|
|
202
|
+
this.spinnerSize = this.spinnerSize;
|
|
203
|
+
|
|
204
|
+
this.spinner = this.spinner;
|
|
205
|
+
|
|
206
|
+
this.background = this.background;
|
|
207
|
+
|
|
208
|
+
if (this.text) this.initTextElement(this.text);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
connectedCallback() {
|
|
212
|
+
this.init();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!customElements.get('ea-loading')) {
|
|
217
|
+
customElements.define('ea-loading', EaLoading);
|
|
218
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
export class EaMessage {
|
|
3
|
+
constructor() {
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 处理字符串型消息
|
|
8
|
+
* @param {Element} el EaMessage元素
|
|
9
|
+
* @param {String} tip 文本
|
|
10
|
+
*/
|
|
11
|
+
handleStringMsg(el, tip) {
|
|
12
|
+
el.text = tip;
|
|
13
|
+
el.type = "info";
|
|
14
|
+
el.hasClose = false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 处理对象型消息
|
|
19
|
+
* @param {Element} el EaMessage元素
|
|
20
|
+
* @param {String} tips 文本
|
|
21
|
+
* @param {*} attrs 属性列表
|
|
22
|
+
*/
|
|
23
|
+
handleObjectMsg(el, tips, attrs) {
|
|
24
|
+
for (const k in tips) {
|
|
25
|
+
if (attrs.includes(k)) el[k] = tips[k];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!Object.keys(tips).includes("type")) el.type = "info";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 处理消失的时长
|
|
33
|
+
* @param {*} el EaMessage元素
|
|
34
|
+
* @param {*} duration 时间间隔
|
|
35
|
+
*/
|
|
36
|
+
handleDuration(el, duration = 3) {
|
|
37
|
+
if (duration === 0) return;
|
|
38
|
+
|
|
39
|
+
let timer = setTimeout(() => {
|
|
40
|
+
el.show = false;
|
|
41
|
+
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
timer = null;
|
|
44
|
+
}, duration * 1000 + 40);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
open(tip) {
|
|
48
|
+
const eaMessage = document.createElement('ea-message');
|
|
49
|
+
document.body.appendChild(eaMessage);
|
|
50
|
+
|
|
51
|
+
if (typeof tip === 'string') {
|
|
52
|
+
this.handleStringMsg(eaMessage, tip);
|
|
53
|
+
this.handleDuration(eaMessage);
|
|
54
|
+
} else if (typeof tip === 'object') {
|
|
55
|
+
this.handleObjectMsg(eaMessage, tip, eaMessage.attrs);
|
|
56
|
+
this.handleDuration(eaMessage, tip.duration);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
eaMessage.show = true;
|
|
61
|
+
}, 20);
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
onClose(fn) {
|
|
65
|
+
if (typeof fn === 'function') eaMessage.addEventListener('click', function () {
|
|
66
|
+
fn();
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from '../Base.js';
|
|
3
|
+
import { createElement } from '../../utils/createElement.js';
|
|
4
|
+
import "../ea-icon/index.js"
|
|
5
|
+
|
|
6
|
+
const stylesheet = `
|
|
7
|
+
|
|
8
|
+
.ea-message_wrap {
|
|
9
|
+
position: fixed;
|
|
10
|
+
left: 50%;
|
|
11
|
+
z-index: 999;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
padding: 15px 15px 15px 20px;
|
|
15
|
+
border: 1px solid #ebeef5;
|
|
16
|
+
border-radius: 4px;
|
|
17
|
+
top: -100%;
|
|
18
|
+
transform-origin: center;
|
|
19
|
+
opacity: 0;
|
|
20
|
+
transform: translate(-50%, 0);
|
|
21
|
+
min-width: 380px;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
background-color: black;
|
|
24
|
+
transition: opacity 0.3s, top 0.3s;
|
|
25
|
+
}
|
|
26
|
+
.ea-message_wrap .ea-icon-wrap {
|
|
27
|
+
margin-right: 0.5rem;
|
|
28
|
+
line-height: 1;
|
|
29
|
+
}
|
|
30
|
+
.ea-message_wrap .ea-text-content {
|
|
31
|
+
line-height: 1;
|
|
32
|
+
vertical-align: middle;
|
|
33
|
+
}
|
|
34
|
+
.ea-message_wrap .ea-close-icon {
|
|
35
|
+
margin-left: auto;
|
|
36
|
+
}
|
|
37
|
+
.ea-message_wrap.ea-message--success {
|
|
38
|
+
background-color: #f0f9eb;
|
|
39
|
+
color: #67c23a;
|
|
40
|
+
}
|
|
41
|
+
.ea-message_wrap.ea-message--info {
|
|
42
|
+
background-color: #f4f4f5;
|
|
43
|
+
color: #909399;
|
|
44
|
+
}
|
|
45
|
+
.ea-message_wrap.ea-message--warning {
|
|
46
|
+
background-color: #fdf6ec;
|
|
47
|
+
color: #e6a23c;
|
|
48
|
+
}
|
|
49
|
+
.ea-message_wrap.ea-message--error {
|
|
50
|
+
background-color: #fef0f0;
|
|
51
|
+
color: #f56c6c;
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
export class EaMessageElement extends Base {
|
|
56
|
+
#wrap;
|
|
57
|
+
|
|
58
|
+
#icon;
|
|
59
|
+
|
|
60
|
+
#textContent;
|
|
61
|
+
|
|
62
|
+
#closeWrap;
|
|
63
|
+
|
|
64
|
+
constructor() {
|
|
65
|
+
super();
|
|
66
|
+
|
|
67
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
68
|
+
const wrap = document.createElement('div');
|
|
69
|
+
wrap.className = 'ea-message_wrap';
|
|
70
|
+
|
|
71
|
+
const icon = createElement('i', 'ea-icon-wrap');
|
|
72
|
+
wrap.appendChild(icon);
|
|
73
|
+
|
|
74
|
+
const textContent = createElement('div', 'ea-text-content');
|
|
75
|
+
wrap.appendChild(textContent);
|
|
76
|
+
|
|
77
|
+
const closeIcon = createElement('i', 'ea-close-icon icon-cancel');
|
|
78
|
+
wrap.appendChild(closeIcon);
|
|
79
|
+
closeIcon.style.display = 'none';
|
|
80
|
+
|
|
81
|
+
this.#wrap = wrap;
|
|
82
|
+
this.wrap = wrap;
|
|
83
|
+
this.#icon = icon;
|
|
84
|
+
this.#textContent = textContent;
|
|
85
|
+
this.#closeWrap = closeIcon;
|
|
86
|
+
this.closeWrap = closeIcon;
|
|
87
|
+
|
|
88
|
+
this.build(shadowRoot, stylesheet);
|
|
89
|
+
this.setIconFile(new URL('../ea-icon/index.css', import.meta.url).href);
|
|
90
|
+
|
|
91
|
+
this.shadowRoot.appendChild(wrap);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get attrs() {
|
|
95
|
+
return ["show", "text", "icon", "type", "showClose", "center"];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get iconList() {
|
|
99
|
+
return {
|
|
100
|
+
"success": "icon-ok-circled",
|
|
101
|
+
"error": "icon-cancel-circled",
|
|
102
|
+
"warning": "icon-attention-alt",
|
|
103
|
+
"info": "icon-info"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ------- show 提示框的显示状态 -------
|
|
108
|
+
// #region
|
|
109
|
+
get show() {
|
|
110
|
+
return this.getAttrBoolean('show');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
set show(value) {
|
|
114
|
+
this.setAttribute('show', value);
|
|
115
|
+
|
|
116
|
+
const eaMessageList = document.querySelectorAll('ea-message');
|
|
117
|
+
|
|
118
|
+
if (value) {
|
|
119
|
+
const length = eaMessageList.length - 1;
|
|
120
|
+
const elementHeight = this.#wrap.getBoundingClientRect().height;
|
|
121
|
+
let gap = length <= 0 ? 10 : (length + 1) * 10;
|
|
122
|
+
|
|
123
|
+
this.#wrap.style.top = `${length * elementHeight + gap}px`;
|
|
124
|
+
this.#wrap.style.opacity = 1;
|
|
125
|
+
} else {
|
|
126
|
+
const that = this;
|
|
127
|
+
|
|
128
|
+
this.#wrap.style.top = `-100%`;
|
|
129
|
+
this.#wrap.style.opacity = 0;
|
|
130
|
+
|
|
131
|
+
let event = this.#wrap.addEventListener('transitionend', function () {
|
|
132
|
+
this.removeEventListener('transitionend', event);
|
|
133
|
+
that.remove();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
// #endregion
|
|
139
|
+
// ------- end -------
|
|
140
|
+
|
|
141
|
+
// ------- text 提示框的文字 -------
|
|
142
|
+
// #region
|
|
143
|
+
get text() {
|
|
144
|
+
return this.getAttribute('text');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
set text(value) {
|
|
148
|
+
this.setAttribute('text', value);
|
|
149
|
+
|
|
150
|
+
this.#textContent.innerText = value;
|
|
151
|
+
}
|
|
152
|
+
// #endregion
|
|
153
|
+
// ------- end -------
|
|
154
|
+
|
|
155
|
+
// ------- type 提示框的类型 -------
|
|
156
|
+
// #region
|
|
157
|
+
get type() {
|
|
158
|
+
return this.getAttribute('type') || "info";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
set type(value) {
|
|
162
|
+
this.setAttribute('type', value);
|
|
163
|
+
|
|
164
|
+
this.#wrap.classList.add(`ea-message--${value}`);
|
|
165
|
+
this.#icon.classList.add(`${this.iconList[value]}`);
|
|
166
|
+
}
|
|
167
|
+
// #endregion
|
|
168
|
+
// ------- end -------
|
|
169
|
+
|
|
170
|
+
// ------- showClose 提示框的关闭按钮 -------
|
|
171
|
+
// #region
|
|
172
|
+
get showClose() {
|
|
173
|
+
return this.getAttrBoolean('showClose') || false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
set showClose(value) {
|
|
177
|
+
this.setAttribute('showClose', value);
|
|
178
|
+
|
|
179
|
+
if (value) {
|
|
180
|
+
this.#closeWrap.style.display = "block";
|
|
181
|
+
} else {
|
|
182
|
+
this.#closeWrap.style.display = "none";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// #endregion
|
|
186
|
+
// ------- end -------
|
|
187
|
+
|
|
188
|
+
// ------- center 提示框是否居中 -------
|
|
189
|
+
// #region
|
|
190
|
+
get center() {
|
|
191
|
+
return this.getAttrBoolean('center') || false;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
set center(value) {
|
|
195
|
+
this.setAttribute('center', value);
|
|
196
|
+
|
|
197
|
+
if (value) {
|
|
198
|
+
this.#icon.style.marginLeft = `auto`;
|
|
199
|
+
} else {
|
|
200
|
+
this.#icon.style.marginLeft = `0`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// #endregion
|
|
204
|
+
// ------- end -------
|
|
205
|
+
|
|
206
|
+
init() {
|
|
207
|
+
const that = this;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
connectedCallback() {
|
|
211
|
+
this.init();
|
|
212
|
+
|
|
213
|
+
this.#closeWrap.addEventListener('click', () => {
|
|
214
|
+
this.show = false;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
disconnectedCallback() {
|
|
219
|
+
const eaMessageList = document.querySelectorAll('ea-message');
|
|
220
|
+
const length = eaMessageList.length;
|
|
221
|
+
|
|
222
|
+
if (length > 0) {
|
|
223
|
+
Array.from(eaMessageList).forEach((el, index) => {
|
|
224
|
+
const elementHeight = el.wrap.getBoundingClientRect().height;
|
|
225
|
+
el.wrap.style.top = `${index * elementHeight + (index * 10)}px`;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (!customElements.get('ea-message')) {
|
|
232
|
+
customElements.define('ea-message', EaMessageElement);
|
|
233
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createElement } from "../../utils/createElement.js"
|
|
2
|
+
|
|
3
|
+
export class EaMessageBox {
|
|
4
|
+
constructor() {
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get attrs() {
|
|
9
|
+
return ["cancelButtonText", "confirmButtonText"];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
#handleElementAttrs(el, options, attrs) {
|
|
13
|
+
attrs.forEach(attr => {
|
|
14
|
+
if (options[attr]) el[attr] = options[attr];
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#close(el) {
|
|
19
|
+
el.remove();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
open(content, title, options) {
|
|
23
|
+
const that = this;
|
|
24
|
+
|
|
25
|
+
const EaMessageBox = createElement('ea-message-box', '');
|
|
26
|
+
document.body.appendChild(EaMessageBox);
|
|
27
|
+
|
|
28
|
+
EaMessageBox.open = true;
|
|
29
|
+
|
|
30
|
+
EaMessageBox.content = content;
|
|
31
|
+
EaMessageBox.title = title;
|
|
32
|
+
|
|
33
|
+
this.#handleElementAttrs(EaMessageBox, options, this.attrs);
|
|
34
|
+
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
EaMessageBox.addEventListener('cancel', () => {
|
|
37
|
+
that.#close(EaMessageBox);
|
|
38
|
+
reject();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
EaMessageBox.addEventListener('confirm', () => {
|
|
42
|
+
that.#close(EaMessageBox);
|
|
43
|
+
resolve(true);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|