easy-component-ui 0.0.1 → 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,90 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
import setStyle from '../utils/setStyle.js';
|
|
4
|
+
|
|
5
|
+
export default class Base extends HTMLElement {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
this.isProduction = false;
|
|
10
|
+
this.isProduction = true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 设置属性值,并切换className
|
|
15
|
+
* @param {string} attr 属性名
|
|
16
|
+
* @param {boolean} flag 属性值
|
|
17
|
+
* @param {string} className class名
|
|
18
|
+
*/
|
|
19
|
+
toggleAttribute(attr, flag, className) {
|
|
20
|
+
if (flag) {
|
|
21
|
+
this.setAttribute(attr, flag);
|
|
22
|
+
|
|
23
|
+
if (className) this.dom.classList.add(className);
|
|
24
|
+
} else {
|
|
25
|
+
|
|
26
|
+
if (this.hasAttribute(attr)) this.removeAttribute(attr);
|
|
27
|
+
if (className) this.dom.classList.remove(className);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 设置属性值
|
|
33
|
+
* @param {string} attr 属性名
|
|
34
|
+
* @param {boolean} flag 属性值
|
|
35
|
+
*/
|
|
36
|
+
toggleAttr(attr, flag) {
|
|
37
|
+
if (flag) {
|
|
38
|
+
this.setAttribute(attr, flag);
|
|
39
|
+
} else {
|
|
40
|
+
this.removeAttribute(attr);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 获取属性值,并转换为布尔值
|
|
46
|
+
* @param {string} attrName 属性名
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
getAttrBoolean(attrName) {
|
|
50
|
+
const attr = this.getAttribute(attrName);
|
|
51
|
+
return attr === 'true' || attr === '';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 获取属性值,并转换为数字
|
|
56
|
+
* @param {string} attrName 属性名
|
|
57
|
+
* @returns {number}
|
|
58
|
+
*/
|
|
59
|
+
getAttrNumber(attrName) {
|
|
60
|
+
const attr = this.getAttribute(attrName);
|
|
61
|
+
|
|
62
|
+
return attr ? Number(attr) : 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 样式构建
|
|
66
|
+
build(shadowRoot, stylesheet) {
|
|
67
|
+
if (this.isProduction) {
|
|
68
|
+
const styleNode = document.createElement('style');
|
|
69
|
+
styleNode.innerHTML = stylesheet;
|
|
70
|
+
this.shadowRoot.appendChild(styleNode);
|
|
71
|
+
} else {
|
|
72
|
+
if (this.nodeName.toLowerCase() == 'ea-skeleton-item' && !this.isProduction) setStyle(shadowRoot, new URL("ea-skeleton" + '/index.css', import.meta.url).href);
|
|
73
|
+
else if (this.nodeName.toLowerCase() == 'ea-carousel-item' && !this.isProduction) setStyle(shadowRoot, new URL("ea-carousel" + '/index.css', import.meta.url).href);
|
|
74
|
+
else if (this.nodeName.toLowerCase() == 'ea-timeline-item' && !this.isProduction) setStyle(shadowRoot, new URL("ea-timeline" + '/index.css', import.meta.url).href);
|
|
75
|
+
else if (this.nodeName.toLowerCase() == 'ea-collapse-item' && !this.isProduction) setStyle(shadowRoot, new URL("ea-collapse" + '/index.css', import.meta.url).href);
|
|
76
|
+
else setStyle(shadowRoot, new URL(this.nodeName.toLowerCase() + '/index.css', import.meta.url).href);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param {string} url 链接
|
|
83
|
+
*/
|
|
84
|
+
setIconFile(url) {
|
|
85
|
+
const link = document.createElement('link');
|
|
86
|
+
link.rel = 'stylesheet';
|
|
87
|
+
link.href = url;
|
|
88
|
+
this.shadowRoot.appendChild(link);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
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
|
+
.ea-alert_wrap {
|
|
8
|
+
position: relative;
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
border-radius: 4px;
|
|
12
|
+
padding: 8px 16px;
|
|
13
|
+
margin: 20px 0 0;
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
width: 100%;
|
|
17
|
+
opacity: 1;
|
|
18
|
+
transition: opacity 0.2s;
|
|
19
|
+
}
|
|
20
|
+
.ea-alert_wrap .ea-alert_content {
|
|
21
|
+
width: 100%;
|
|
22
|
+
display: flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: space-between;
|
|
25
|
+
}
|
|
26
|
+
.ea-alert_wrap .ea-alert_content .ea-alert_title {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
}
|
|
30
|
+
.ea-alert_wrap .ea-alert_content .ea-alert_title i {
|
|
31
|
+
margin-right: 0.5rem;
|
|
32
|
+
}
|
|
33
|
+
.ea-alert_wrap .ea-alert_content .ea-alert_close-icon {
|
|
34
|
+
color: #c0c4cc;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
}
|
|
37
|
+
.ea-alert_wrap .ea-alert_content.ea-alert--center .ea-alert_title,
|
|
38
|
+
.ea-alert_wrap .ea-alert_content.ea-alert--center .ea-alert_close-icon {
|
|
39
|
+
margin-left: auto;
|
|
40
|
+
}
|
|
41
|
+
.ea-alert_wrap .ea-alert_description {
|
|
42
|
+
width: 100%;
|
|
43
|
+
margin: 5px 0 0;
|
|
44
|
+
font-size: 12px;
|
|
45
|
+
}
|
|
46
|
+
.ea-alert_wrap.ea-alert--success {
|
|
47
|
+
background-color: #f0f9eb;
|
|
48
|
+
color: #67c23a;
|
|
49
|
+
}
|
|
50
|
+
.ea-alert_wrap.ea-alert--success.ea-alert--dark {
|
|
51
|
+
color: #fff;
|
|
52
|
+
background-color: #67c23a;
|
|
53
|
+
}
|
|
54
|
+
.ea-alert_wrap.ea-alert--success.ea-alert--dark .ea-alert_close-icon {
|
|
55
|
+
color: #fff;
|
|
56
|
+
}
|
|
57
|
+
.ea-alert_wrap.ea-alert--info {
|
|
58
|
+
background-color: #f4f4f5;
|
|
59
|
+
color: #909399;
|
|
60
|
+
}
|
|
61
|
+
.ea-alert_wrap.ea-alert--info.ea-alert--dark {
|
|
62
|
+
color: #fff;
|
|
63
|
+
background-color: #909399;
|
|
64
|
+
}
|
|
65
|
+
.ea-alert_wrap.ea-alert--info.ea-alert--dark .ea-alert_close-icon {
|
|
66
|
+
color: #fff;
|
|
67
|
+
}
|
|
68
|
+
.ea-alert_wrap.ea-alert--warning {
|
|
69
|
+
background-color: #fdf6ec;
|
|
70
|
+
color: #e6a23c;
|
|
71
|
+
}
|
|
72
|
+
.ea-alert_wrap.ea-alert--warning.ea-alert--dark {
|
|
73
|
+
color: #fff;
|
|
74
|
+
background-color: #e6a23c;
|
|
75
|
+
}
|
|
76
|
+
.ea-alert_wrap.ea-alert--warning.ea-alert--dark .ea-alert_close-icon {
|
|
77
|
+
color: #fff;
|
|
78
|
+
}
|
|
79
|
+
.ea-alert_wrap.ea-alert--error {
|
|
80
|
+
background-color: #fef0f0;
|
|
81
|
+
color: #f56c6c;
|
|
82
|
+
}
|
|
83
|
+
.ea-alert_wrap.ea-alert--error.ea-alert--dark {
|
|
84
|
+
color: #fff;
|
|
85
|
+
background-color: #f56c6c;
|
|
86
|
+
}
|
|
87
|
+
.ea-alert_wrap.ea-alert--error.ea-alert--dark .ea-alert_close-icon {
|
|
88
|
+
color: #fff;
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
export class EaAlert extends Base {
|
|
93
|
+
#wrap;
|
|
94
|
+
|
|
95
|
+
#alertContent;
|
|
96
|
+
#alertTitle;
|
|
97
|
+
|
|
98
|
+
constructor() {
|
|
99
|
+
super();
|
|
100
|
+
|
|
101
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
102
|
+
const wrap = document.createElement('div');
|
|
103
|
+
wrap.className = 'ea-alert_wrap';
|
|
104
|
+
|
|
105
|
+
const alertTitle = createElement('span', 'ea-alert_title');
|
|
106
|
+
const alertContent = createElement('div', 'ea-alert_content', alertTitle);
|
|
107
|
+
wrap.appendChild(alertContent);
|
|
108
|
+
|
|
109
|
+
this.#wrap = wrap;
|
|
110
|
+
this.#alertContent = alertContent;
|
|
111
|
+
this.#alertTitle = alertTitle;
|
|
112
|
+
|
|
113
|
+
this.setIconFile(new URL('../ea-icon/index.css', import.meta.url).href);
|
|
114
|
+
|
|
115
|
+
this.build(shadowRoot, stylesheet);
|
|
116
|
+
this.shadowRoot.appendChild(wrap);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ------- type 获取提示类型 -------
|
|
120
|
+
// #region
|
|
121
|
+
get type() {
|
|
122
|
+
return this.getAttribute('type') || "info";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
set type(value) {
|
|
126
|
+
this.setAttribute('type', value);
|
|
127
|
+
|
|
128
|
+
this.#wrap.classList.add(`ea-alert--${value}`);
|
|
129
|
+
}
|
|
130
|
+
// #endregion
|
|
131
|
+
// ------- end -------
|
|
132
|
+
|
|
133
|
+
// ------- title 获取提示标题 -------
|
|
134
|
+
// #region
|
|
135
|
+
get title() {
|
|
136
|
+
return this.getAttribute('title') || "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
set title(value) {
|
|
140
|
+
this.setAttribute('title', value);
|
|
141
|
+
|
|
142
|
+
this.#alertTitle.innerText = value;
|
|
143
|
+
}
|
|
144
|
+
// #endregion
|
|
145
|
+
// ------- end -------
|
|
146
|
+
|
|
147
|
+
// ------- closable 是否可关闭 -------
|
|
148
|
+
// #region
|
|
149
|
+
get closable() {
|
|
150
|
+
const flag = this.getAttribute('closable');
|
|
151
|
+
|
|
152
|
+
if (flag === null || flag === "true" || flag === "") return true;
|
|
153
|
+
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
set closable(value) {
|
|
158
|
+
this.setAttribute('closable', value);
|
|
159
|
+
}
|
|
160
|
+
// #endregion
|
|
161
|
+
// ------- end -------
|
|
162
|
+
|
|
163
|
+
// ------- close-text 关闭按钮文字 -------
|
|
164
|
+
// #region
|
|
165
|
+
get closeText() {
|
|
166
|
+
return this.getAttribute('close-text') || "";
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
set closeText(value) {
|
|
170
|
+
this.setAttribute('close-text', value);
|
|
171
|
+
}
|
|
172
|
+
// #endregion
|
|
173
|
+
// ------- end -------
|
|
174
|
+
|
|
175
|
+
// ------- effect 亮色与暗色主题 -------
|
|
176
|
+
// #region
|
|
177
|
+
get effect() {
|
|
178
|
+
return this.getAttribute('effect') || "light";
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
set effect(value) {
|
|
182
|
+
this.setAttribute('effect', value);
|
|
183
|
+
|
|
184
|
+
if (value === "dark") {
|
|
185
|
+
this.#wrap.classList.add('ea-alert--dark');
|
|
186
|
+
} else {
|
|
187
|
+
this.#wrap.classList.remove('ea-alert--dark');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// #endregion
|
|
191
|
+
// ------- end -------
|
|
192
|
+
|
|
193
|
+
// ------- show-icon 是否显示图标 -------
|
|
194
|
+
// #region
|
|
195
|
+
get showIcon() {
|
|
196
|
+
return this.getAttrBoolean('show-icon') || false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
set showIcon(value) {
|
|
200
|
+
this.setAttribute('show-icon', value);
|
|
201
|
+
}
|
|
202
|
+
// #endregion
|
|
203
|
+
// ------- end -------
|
|
204
|
+
|
|
205
|
+
// ------- center 是否居中 -------
|
|
206
|
+
// #region
|
|
207
|
+
get center() {
|
|
208
|
+
return this.getAttrBoolean('center') || false;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
set center(value) {
|
|
212
|
+
this.setAttribute('center', value);
|
|
213
|
+
|
|
214
|
+
this.#alertContent.classList.toggle('ea-alert--center', value);
|
|
215
|
+
}
|
|
216
|
+
// #endregion
|
|
217
|
+
// ------- end -------
|
|
218
|
+
|
|
219
|
+
// ------- description 提示描述 -------
|
|
220
|
+
// #region
|
|
221
|
+
get description() {
|
|
222
|
+
return this.getAttribute('description') || "";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
set description(value) {
|
|
226
|
+
this.setAttribute('description', value);
|
|
227
|
+
}
|
|
228
|
+
// #endregion
|
|
229
|
+
// ------- end -------
|
|
230
|
+
|
|
231
|
+
initClosableElement(closable, closeText) {
|
|
232
|
+
const that = this;
|
|
233
|
+
|
|
234
|
+
const closeIcon = createElement('i', 'ea-alert_close-icon');
|
|
235
|
+
closable === true && closeText === "" ? closeIcon.classList.add('icon-cancel') : closeIcon.innerText = closeText;
|
|
236
|
+
this.#alertContent.appendChild(closeIcon);
|
|
237
|
+
|
|
238
|
+
closeIcon.addEventListener('click', function () {
|
|
239
|
+
that.#wrap.style.opacity = 0;
|
|
240
|
+
|
|
241
|
+
that.dispatchEvent(new CustomEvent('close', { detail: { target: that } }));
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
this.#wrap.addEventListener('transitionend', function () {
|
|
245
|
+
that.remove();
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
initShowIconElement(type) {
|
|
250
|
+
const iconClass = {
|
|
251
|
+
success: 'ok-circled',
|
|
252
|
+
info: 'info',
|
|
253
|
+
warning: 'attention-alt',
|
|
254
|
+
error: 'cancel-circled'
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const icon = createElement('i', `icon-${iconClass[type]}`);
|
|
258
|
+
icon.classList.add(`ea-alert--${type}`);
|
|
259
|
+
this.#alertTitle.insertBefore(icon, this.#alertTitle.firstChild);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
initDescriptionElement(description) {
|
|
263
|
+
const descriptionElement = createElement('p', 'ea-alert_description');
|
|
264
|
+
this.#wrap.style.flexDirection = 'column';
|
|
265
|
+
|
|
266
|
+
descriptionElement.innerText = description;
|
|
267
|
+
this.#wrap.appendChild(descriptionElement);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
init() {
|
|
271
|
+
|
|
272
|
+
this.type = this.type;
|
|
273
|
+
|
|
274
|
+
this.title = this.title;
|
|
275
|
+
|
|
276
|
+
this.closable = this.closable;
|
|
277
|
+
|
|
278
|
+
this.closeText = this.closeText;
|
|
279
|
+
|
|
280
|
+
this.effect = this.effect;
|
|
281
|
+
|
|
282
|
+
this.center = this.center;
|
|
283
|
+
|
|
284
|
+
if (this.closable) this.initClosableElement(this.closable, this.closeText);
|
|
285
|
+
|
|
286
|
+
if (this.showIcon) this.initShowIconElement(this.type);
|
|
287
|
+
|
|
288
|
+
if (this.description) this.initDescriptionElement(this.description);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
connectedCallback() {
|
|
292
|
+
this.init();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (!customElements.get('ea-alert')) {
|
|
297
|
+
customElements.define('ea-alert', EaAlert);
|
|
298
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from '../Base.js';
|
|
3
|
+
|
|
4
|
+
const stylesheet = `
|
|
5
|
+
.ea-avatar_wrap .ea-avatar {
|
|
6
|
+
position: relative;
|
|
7
|
+
display: inline-block;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
color: #ffffff;
|
|
10
|
+
}
|
|
11
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar-fill--fill img {
|
|
12
|
+
object-fit: fill;
|
|
13
|
+
}
|
|
14
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar-fill--contain img {
|
|
15
|
+
object-fit: contain;
|
|
16
|
+
}
|
|
17
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar-fill--cover img {
|
|
18
|
+
object-fit: cover;
|
|
19
|
+
}
|
|
20
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar-fill--none img {
|
|
21
|
+
object-fit: none;
|
|
22
|
+
}
|
|
23
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar-fill--scale-down img {
|
|
24
|
+
object-fit: scale-down;
|
|
25
|
+
}
|
|
26
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar--normal {
|
|
27
|
+
width: 50px;
|
|
28
|
+
height: 50px;
|
|
29
|
+
line-height: 50px;
|
|
30
|
+
}
|
|
31
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar--large {
|
|
32
|
+
width: 40px;
|
|
33
|
+
height: 40px;
|
|
34
|
+
line-height: 40px;
|
|
35
|
+
}
|
|
36
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar--medium {
|
|
37
|
+
width: 36px;
|
|
38
|
+
height: 36px;
|
|
39
|
+
line-height: 36px;
|
|
40
|
+
}
|
|
41
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar--small {
|
|
42
|
+
width: 28px;
|
|
43
|
+
height: 28px;
|
|
44
|
+
line-height: 28px;
|
|
45
|
+
}
|
|
46
|
+
.ea-avatar_wrap .ea-avatar .ea-avatar--text {
|
|
47
|
+
position: absolute;
|
|
48
|
+
top: 50%;
|
|
49
|
+
left: 50%;
|
|
50
|
+
transform: translate(-50%, -50%);
|
|
51
|
+
}
|
|
52
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar--circle {
|
|
53
|
+
border-radius: 50%;
|
|
54
|
+
}
|
|
55
|
+
.ea-avatar_wrap .ea-avatar.ea-avatar--square {
|
|
56
|
+
border-radius: 5px;
|
|
57
|
+
}
|
|
58
|
+
.ea-avatar_wrap .ea-avatar .ea-avatar--img {
|
|
59
|
+
width: 100%;
|
|
60
|
+
height: 100%;
|
|
61
|
+
object-fit: cover;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const defaultAvatar = `
|
|
66
|
+
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
|
67
|
+
<defs>
|
|
68
|
+
<clipPath id="a">
|
|
69
|
+
<path d="M0 40h90v45H0z" />
|
|
70
|
+
</clipPath>
|
|
71
|
+
</defs>
|
|
72
|
+
<path fill="#c0c4cc" d="M0 0h100v100H0z" />
|
|
73
|
+
<circle cx="50" cy="35" r="20" fill="#fff" />
|
|
74
|
+
<circle cx="50" cy="97" r="40" fill="#fff" clip-path="url(#a)" />
|
|
75
|
+
</svg>
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
const errorAvatar = `
|
|
79
|
+
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
|
80
|
+
<path fill="#c0c4cc" d="M0 0h100v100H0z" />
|
|
81
|
+
<path fill="#fff" d="M15 20h70v60H15z" />
|
|
82
|
+
<circle r="8" cx="32" cy="35" fill="#c0c4cc" />
|
|
83
|
+
<path d="M60 42.5L39 75h42z" fill="#c0c4cc" />
|
|
84
|
+
<path d="M35 52.5L20 75h-4 32z" fill="#c0c4cc" />
|
|
85
|
+
</svg>
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
const iconAvatar = (icon) => {
|
|
89
|
+
return `
|
|
90
|
+
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
|
91
|
+
<path fill="#c0c4cc" d="M0 0h100v100H0z" />
|
|
92
|
+
</svg>
|
|
93
|
+
<i class="fa ea-avatar--text ${icon}"></i>
|
|
94
|
+
`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const textAvatar = (text) => {
|
|
98
|
+
return `
|
|
99
|
+
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
|
100
|
+
<path fill="#c0c4cc" d="M0 0h100v100H0z" />
|
|
101
|
+
</svg>
|
|
102
|
+
<span class="ea-avatar--text">${text}</span>
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export class EaAvatar extends Base {
|
|
107
|
+
#wrap;
|
|
108
|
+
|
|
109
|
+
#textSlot;
|
|
110
|
+
|
|
111
|
+
#avatar;
|
|
112
|
+
#img;
|
|
113
|
+
|
|
114
|
+
constructor() {
|
|
115
|
+
super();
|
|
116
|
+
|
|
117
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
118
|
+
const wrap = document.createElement('div');
|
|
119
|
+
wrap.className = 'ea-avatar_wrap';
|
|
120
|
+
|
|
121
|
+
const avatar = document.createElement('span');
|
|
122
|
+
avatar.className = 'ea-avatar';
|
|
123
|
+
avatar.innerHTML = defaultAvatar;
|
|
124
|
+
wrap.appendChild(avatar);
|
|
125
|
+
|
|
126
|
+
const slot = document.createElement('slot');
|
|
127
|
+
avatar.appendChild(slot);
|
|
128
|
+
|
|
129
|
+
const img = document.createElement('img');
|
|
130
|
+
avatar.appendChild(img);
|
|
131
|
+
|
|
132
|
+
this.#wrap = wrap;
|
|
133
|
+
this.#textSlot = slot;
|
|
134
|
+
this.#avatar = avatar;
|
|
135
|
+
this.#img = img;
|
|
136
|
+
|
|
137
|
+
const link = document.createElement('link');
|
|
138
|
+
link.rel = 'stylesheet';
|
|
139
|
+
link.href = new URL('../ea-icon/index.css', import.meta.url).href;
|
|
140
|
+
shadowRoot.appendChild(link);
|
|
141
|
+
|
|
142
|
+
this.build(shadowRoot, stylesheet);
|
|
143
|
+
this.shadowRoot.appendChild(wrap);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ------- size 图片大小 -------
|
|
147
|
+
// #region
|
|
148
|
+
get size() {
|
|
149
|
+
const sizeNumber = this.getAttrNumber('size');
|
|
150
|
+
const sizeString = this.getAttribute('size');
|
|
151
|
+
|
|
152
|
+
if (sizeNumber === 0 || !sizeNumber) {
|
|
153
|
+
return ['large', 'medium', 'small'].includes(sizeString) ? sizeString : 'normal';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return this.getAttrNumber('size');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
set size(value) {
|
|
160
|
+
this.setAttribute('size', value);
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
if (typeof value === "number") {
|
|
164
|
+
this.#avatar.style.width = `${value}px`;
|
|
165
|
+
this.#avatar.style.height = `${value}px`;
|
|
166
|
+
this.#avatar.style.lineHeight = `${value}px`;
|
|
167
|
+
} else if (typeof value === "string") {
|
|
168
|
+
this.#avatar.classList.add(`ea-avatar--${value}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// #endregion
|
|
172
|
+
// ------- end -------
|
|
173
|
+
|
|
174
|
+
// ------- shape 图片形状 -------
|
|
175
|
+
// #region
|
|
176
|
+
get shape() {
|
|
177
|
+
const shape = this.getAttribute('shape');
|
|
178
|
+
|
|
179
|
+
return ['circle', 'square'].includes(shape) ? shape : 'circle';
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
set shape(value) {
|
|
183
|
+
this.setAttribute('shape', value);
|
|
184
|
+
this.#avatar.classList.add(`ea-avatar--${this.shape}`);
|
|
185
|
+
}
|
|
186
|
+
// #endregion
|
|
187
|
+
// ------- end -------
|
|
188
|
+
|
|
189
|
+
// ------- src 图片链接 -------
|
|
190
|
+
// #region
|
|
191
|
+
get src() {
|
|
192
|
+
return this.getAttribute('src');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
set src(value) {
|
|
196
|
+
if (!value) return;
|
|
197
|
+
|
|
198
|
+
const image = new Image();
|
|
199
|
+
image.src = value;
|
|
200
|
+
|
|
201
|
+
image.onload = () => {
|
|
202
|
+
this.setAttribute('src', value);
|
|
203
|
+
this.#avatar.innerHTML = `<img class="ea-avatar--img" src="${value}" alt="头像">`;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
image.onerror = (e) => {
|
|
207
|
+
this.setAttribute('src', value);
|
|
208
|
+
this.#avatar.innerHTML = errorAvatar;
|
|
209
|
+
|
|
210
|
+
this.dispatchEvent(new CustomEvent('error', {
|
|
211
|
+
detail: {
|
|
212
|
+
error: e,
|
|
213
|
+
},
|
|
214
|
+
}));
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
// #endregion
|
|
218
|
+
// ------- end -------
|
|
219
|
+
|
|
220
|
+
// ------- icon 图标 -------
|
|
221
|
+
// #region
|
|
222
|
+
get icon() {
|
|
223
|
+
return this.getAttribute('icon');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
set icon(value) {
|
|
227
|
+
this.setAttribute('icon', value);
|
|
228
|
+
|
|
229
|
+
this.#avatar.innerHTML = iconAvatar(value);
|
|
230
|
+
}
|
|
231
|
+
// #endregion
|
|
232
|
+
// ------- end -------
|
|
233
|
+
|
|
234
|
+
// ------- fit 图片容器适应 -------
|
|
235
|
+
// #region
|
|
236
|
+
get fit() {
|
|
237
|
+
return this.getAttribute('fit') || 'cover';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
set fit(value) {
|
|
241
|
+
this.setAttribute('fit', value);
|
|
242
|
+
|
|
243
|
+
this.#avatar.classList.add(`ea-avatar-fill--${value}`);
|
|
244
|
+
}
|
|
245
|
+
// #endregion
|
|
246
|
+
// ------- end -------
|
|
247
|
+
|
|
248
|
+
init() {
|
|
249
|
+
const that = this;
|
|
250
|
+
|
|
251
|
+
this.size = this.size;
|
|
252
|
+
|
|
253
|
+
this.shape = this.shape;
|
|
254
|
+
|
|
255
|
+
this.src = this.src;
|
|
256
|
+
|
|
257
|
+
if (this.src) {
|
|
258
|
+
this.fit = this.fit;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!this.src && this.icon) {
|
|
262
|
+
this.icon = this.icon;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (this.innerHTML !== "" && !this.icon && !this.src) {
|
|
266
|
+
this.#avatar.innerHTML = textAvatar(this.innerHTML);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
connectedCallback() {
|
|
271
|
+
this.init();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (!customElements.get('ea-avatar')) {
|
|
276
|
+
customElements.define('ea-avatar', EaAvatar);
|
|
277
|
+
}
|