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,409 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from '../Base.js';
|
|
3
|
+
import { createElement, createSlotElement } from '../../utils/createElement.js';
|
|
4
|
+
|
|
5
|
+
import "../ea-button-group/index.js";
|
|
6
|
+
import "../ea-button/index.js";
|
|
7
|
+
import "../ea-descriptions/index.js";
|
|
8
|
+
import "../ea-descriptions-item/index.js";
|
|
9
|
+
|
|
10
|
+
const stylesheet = `
|
|
11
|
+
.ea-calendar_wrap {
|
|
12
|
+
padding: 12px 20px 35px;
|
|
13
|
+
}
|
|
14
|
+
.ea-calendar_wrap .ea-calendar-header_wrap {
|
|
15
|
+
border-bottom: 1px solid #ebeef5;
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: space-between;
|
|
19
|
+
padding-bottom: 0.5rem;
|
|
20
|
+
}
|
|
21
|
+
.ea-calendar_wrap .ea-calendar-header_wrap .ea-calendar-header_changer .ea-calendar-header_sg-changer {
|
|
22
|
+
border: 1px solid #ebeef5;
|
|
23
|
+
border-left: 0px none transparent;
|
|
24
|
+
}
|
|
25
|
+
.ea-calendar_wrap .ea-calendar-header_wrap .ea-calendar-header_changer .ea-calendar-header_sg-changer:first-child {
|
|
26
|
+
border-left: 1px solid #ebeef5;
|
|
27
|
+
}
|
|
28
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table {
|
|
29
|
+
width: 100%;
|
|
30
|
+
table-layout: fixed;
|
|
31
|
+
border-collapse: collapse;
|
|
32
|
+
}
|
|
33
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table th {
|
|
34
|
+
font-weight: 400;
|
|
35
|
+
color: #606266;
|
|
36
|
+
padding: 12px 0;
|
|
37
|
+
}
|
|
38
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table td {
|
|
39
|
+
border-right: 1px solid #ebeef5;
|
|
40
|
+
border-bottom: 1px solid #ebeef5;
|
|
41
|
+
}
|
|
42
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table td.is-selected {
|
|
43
|
+
color: #1989fa;
|
|
44
|
+
background-color: #f2f8fe;
|
|
45
|
+
}
|
|
46
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table td.is-today {
|
|
47
|
+
color: #1989fa;
|
|
48
|
+
}
|
|
49
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table td.is-disabled {
|
|
50
|
+
pointer-events: none;
|
|
51
|
+
color: #c0c4cc;
|
|
52
|
+
}
|
|
53
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table td span {
|
|
54
|
+
display: block;
|
|
55
|
+
box-sizing: border-box;
|
|
56
|
+
height: 85px;
|
|
57
|
+
padding: 8px;
|
|
58
|
+
}
|
|
59
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table td span .calendar-description {
|
|
60
|
+
margin-top: auto;
|
|
61
|
+
}
|
|
62
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table tr:first-child td {
|
|
63
|
+
border-top: 1px solid #ebeef5;
|
|
64
|
+
}
|
|
65
|
+
.ea-calendar_wrap .ea-calendar_calendar-wrap .ea-calendar_table tr td:first-child {
|
|
66
|
+
border-left: 1px solid #ebeef5;
|
|
67
|
+
border-top: 1px solid #ebeef5;
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 创建一个具有特定文本和类名的元素。
|
|
73
|
+
*
|
|
74
|
+
* 此函数专为创建具有特定样式和文本的按钮元素而设计,用于日历头部的改变功能。
|
|
75
|
+
* 它通过传入的文本和类名参数,生成一个具有相应属性的元素,并返回该元素。
|
|
76
|
+
*
|
|
77
|
+
* @param {string} text - 按钮元素的显示文本。
|
|
78
|
+
* @param {string} className - 按钮元素的类名,用于应用特定的样式。
|
|
79
|
+
* @returns {HTMLElement} - 返回创建的具有指定文本和类名的按钮元素。
|
|
80
|
+
*/
|
|
81
|
+
const createChangerElement = (text, className) => {
|
|
82
|
+
// 创建一个具有特定类名的元素,类名包括一个基础类和一个由传入的className参数动态组成的类。
|
|
83
|
+
const el = createElement('ea-button', `ea-calendar-header_sg-changer ea-calendar-header_changer-${className}`);
|
|
84
|
+
// 设置元素的内部文本为传入的text参数。
|
|
85
|
+
el.innerText = text;
|
|
86
|
+
// 设置元素的尺寸为小号。
|
|
87
|
+
el.size = "small";
|
|
88
|
+
|
|
89
|
+
// 返回创建的元素。
|
|
90
|
+
return el;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 创建一个包含一周七天的表头thead元素。
|
|
95
|
+
*
|
|
96
|
+
* 该函数通过动态创建元素的方式,构建一个包含一周七天名称的表头。使用map函数遍历一周的天数,
|
|
97
|
+
* 为每一天创建一个th元素,并设置其innerText为对应的天数名称。然后将这些th元素添加到一个tr元素中,
|
|
98
|
+
* 最后将tr元素添加到thead中,完成一周七天表头的创建。
|
|
99
|
+
*
|
|
100
|
+
* @returns {HTMLElement} 返回创建好的thead元素。
|
|
101
|
+
*/
|
|
102
|
+
const createThead = (weekArr = ["一", "二", "三", "四", "五", "六", "日"]) => {
|
|
103
|
+
// 创建tr元素
|
|
104
|
+
const tr = createElement('tr');
|
|
105
|
+
|
|
106
|
+
// 使用map函数遍历一周的天数,为每一天创建一个th元素
|
|
107
|
+
const ths = weekArr.map(item => {
|
|
108
|
+
// 创建th元素
|
|
109
|
+
const th = createElement('th');
|
|
110
|
+
// 设置th元素的文本内容为当前遍历的天数名称
|
|
111
|
+
th.innerText = item;
|
|
112
|
+
|
|
113
|
+
return th;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// 将所有th元素添加到tr元素中
|
|
117
|
+
tr.append(...ths);
|
|
118
|
+
|
|
119
|
+
// 返回创建好的thead元素
|
|
120
|
+
return tr;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export class EaCalendar extends Base {
|
|
124
|
+
#wrap;
|
|
125
|
+
|
|
126
|
+
#headerDateContent;
|
|
127
|
+
#headerChangerWrap;
|
|
128
|
+
|
|
129
|
+
#lastMonthBtn;
|
|
130
|
+
#todayBtn;
|
|
131
|
+
#nextMonthBtn;
|
|
132
|
+
|
|
133
|
+
#tableHead;
|
|
134
|
+
#tableContent;
|
|
135
|
+
constructor() {
|
|
136
|
+
super();
|
|
137
|
+
|
|
138
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
139
|
+
|
|
140
|
+
const headerDateContent = createElement('span', 'ea-calendar-header_content');
|
|
141
|
+
|
|
142
|
+
const headerChanger_lastMonth = createChangerElement("上个月", "lastMonth");
|
|
143
|
+
const headerChanger_today = createChangerElement("今天", "today");
|
|
144
|
+
const headerChanger_nextMonth = createChangerElement("下个月", "nextMonth");
|
|
145
|
+
const headerChangerWrap = createElement('ea-button-group', 'ea-calendar-header_changer', [headerChanger_lastMonth, headerChanger_today, headerChanger_nextMonth]);
|
|
146
|
+
|
|
147
|
+
const calendarThead = createElement('thead', 'ea-calendar_table-head');
|
|
148
|
+
const calendarTbody = createElement('tbody', 'ea-calendar_table-body');
|
|
149
|
+
const calendarTable = createElement('table', 'ea-calendar_table', [calendarThead, calendarTbody]);
|
|
150
|
+
const calendarWrap = createElement('div', 'ea-calendar_calendar-wrap', [calendarTable]);
|
|
151
|
+
|
|
152
|
+
const headerWrap = createElement('div', 'ea-calendar-header_wrap', [headerDateContent, headerChangerWrap]);
|
|
153
|
+
|
|
154
|
+
const wrap = createElement('div', 'ea-calendar_wrap', [headerWrap, calendarWrap]);
|
|
155
|
+
|
|
156
|
+
this.#wrap = wrap;
|
|
157
|
+
|
|
158
|
+
this.#headerDateContent = headerDateContent;
|
|
159
|
+
|
|
160
|
+
this.#headerChangerWrap = headerChangerWrap;
|
|
161
|
+
this.#lastMonthBtn = headerChanger_lastMonth;
|
|
162
|
+
this.#todayBtn = headerChanger_today;
|
|
163
|
+
this.#nextMonthBtn = headerChanger_nextMonth;
|
|
164
|
+
|
|
165
|
+
this.#tableHead = calendarThead;
|
|
166
|
+
this.#tableContent = calendarTbody;
|
|
167
|
+
|
|
168
|
+
this.build(shadowRoot, stylesheet);
|
|
169
|
+
this.shadowRoot.appendChild(wrap);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
getToday() {
|
|
173
|
+
const myDate = new Date();
|
|
174
|
+
|
|
175
|
+
return `${myDate.getFullYear()}-${myDate.getMonth() + 1}`
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
getUserToday(date) {
|
|
179
|
+
const myDate = new Date(date);
|
|
180
|
+
|
|
181
|
+
return `${myDate.getFullYear()}-${myDate.getMonth() + 1}`
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
// ------- week-start 用户传入的每周起始日 -------
|
|
186
|
+
// #region
|
|
187
|
+
get weekStart() {
|
|
188
|
+
return this.getAttribute('week-start') || "一";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
set weekStart(weekStart) {
|
|
192
|
+
this.setAttribute('week-start', weekStart);
|
|
193
|
+
|
|
194
|
+
this.#tableHead.innerHTML = createThead(this.#getUserWeekStart(this.week, weekStart)).innerHTML;
|
|
195
|
+
}
|
|
196
|
+
// #endregion
|
|
197
|
+
// ------- end -------
|
|
198
|
+
|
|
199
|
+
// ------- date 用户传入日期 -------
|
|
200
|
+
// #region
|
|
201
|
+
get date() {
|
|
202
|
+
const myDate = new Date();
|
|
203
|
+
|
|
204
|
+
return this.getAttribute('date') || this.getToday();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
set date(date) {
|
|
208
|
+
this.setAttribute('date', date);
|
|
209
|
+
|
|
210
|
+
this.#headerDateContent.innerHTML = date = isNaN(new Date(date)) ? this.getToday() : this.getUserToday(date);
|
|
211
|
+
|
|
212
|
+
this.#handleDateChange(this.#tableContent, date, this.weekStart);
|
|
213
|
+
}
|
|
214
|
+
// #endregion
|
|
215
|
+
// ------- end -------
|
|
216
|
+
|
|
217
|
+
get week() {
|
|
218
|
+
return ["日", "一", "二", "三", "四", "五", "六"];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
*
|
|
223
|
+
* @param {Array} weekArr
|
|
224
|
+
* @param {string} start
|
|
225
|
+
* @returns
|
|
226
|
+
*/
|
|
227
|
+
#getUserWeekStart(weekArr, start) {
|
|
228
|
+
if (!weekArr.includes(start)) return weekArr;
|
|
229
|
+
|
|
230
|
+
const index = weekArr.findIndex((item, index) => {
|
|
231
|
+
if (item === start) return index;
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
if (index === 0 || index === -1) return weekArr;
|
|
235
|
+
|
|
236
|
+
return weekArr.slice(index).concat(weekArr.slice(0, index));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 处理日历项的选择事件。
|
|
241
|
+
* 当日历项被点击时,此函数被调用。它的目的是切换所点击项的选中状态,并取消其他项的选中状态。
|
|
242
|
+
* @param {HTMLElement} node - 日历项元素节点。这个节点代表日历中的一个日期单元格。
|
|
243
|
+
*/
|
|
244
|
+
#handleCalendarItemSelect(node) {
|
|
245
|
+
// 为日历项添加点击事件监听器
|
|
246
|
+
node.addEventListener('click', (e) => {
|
|
247
|
+
// 遍历日历表中的所有单元格,并移除它们的 'is-selected' 类,以取消选中状态
|
|
248
|
+
this.#tableContent.querySelectorAll('td').forEach(el => {
|
|
249
|
+
el.classList.remove('is-selected');
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// 如果当前点击的节点已经选中,则取消选中状态,否则选中当前节点
|
|
253
|
+
if (node.classList.contains('is-selected')) {
|
|
254
|
+
node.classList.remove('is-selected');
|
|
255
|
+
} else {
|
|
256
|
+
node.classList.add('is-selected');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const myDate = new Date(this.date);
|
|
260
|
+
this.dispatchEvent(new CustomEvent('select', {
|
|
261
|
+
detail: {
|
|
262
|
+
year: myDate.getFullYear(),
|
|
263
|
+
month: myDate.getMonth() + 1,
|
|
264
|
+
date: Number(node.innerText),
|
|
265
|
+
day: this.week[Number(node.innerText) % 7],
|
|
266
|
+
}
|
|
267
|
+
}));
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
#handleMonthChange(flag) {
|
|
272
|
+
const date = new Date(this.date);
|
|
273
|
+
date.setMonth(date.getMonth() + (flag === "next" ? 1 : -1));
|
|
274
|
+
|
|
275
|
+
this.date = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 根据给定的日期更新页面上的日历视图。
|
|
280
|
+
* @param {HTMLElement} content - 用于展示日历的HTML元素。
|
|
281
|
+
* @param {string|number|Date} date - 需要展示的月份的日期对象。
|
|
282
|
+
*/
|
|
283
|
+
#handleDateChange(content, date, weekStart = "一") {
|
|
284
|
+
date = isNaN(new Date(date)) ? new Date() : new Date(date);
|
|
285
|
+
|
|
286
|
+
// 清空内容区域,为展示新月份做准备
|
|
287
|
+
content.innerHTML = "";
|
|
288
|
+
|
|
289
|
+
// 创建当前月份的日期对象
|
|
290
|
+
const userDate = new Date(date);
|
|
291
|
+
// 获取月份,月份从0开始,因此需要加1
|
|
292
|
+
const month = userDate.getMonth() + 1;
|
|
293
|
+
|
|
294
|
+
// 初始化当前日期为月份的第一天
|
|
295
|
+
const currentDate = new Date(date);
|
|
296
|
+
currentDate.setDate(1);
|
|
297
|
+
|
|
298
|
+
// 计算上个月的最后一天
|
|
299
|
+
const lastDate = new Date(date);
|
|
300
|
+
lastDate.setMonth(month);
|
|
301
|
+
lastDate.setDate(0);
|
|
302
|
+
|
|
303
|
+
// 计算下个月的第一天
|
|
304
|
+
const nextDate = new Date(date);
|
|
305
|
+
nextDate.setMonth(month);
|
|
306
|
+
nextDate.setDate(1);
|
|
307
|
+
|
|
308
|
+
// 定义星期的中文简写数组
|
|
309
|
+
const weekArr = this.#getUserWeekStart(this.week, weekStart);
|
|
310
|
+
|
|
311
|
+
// 构建日历的行,每行7天
|
|
312
|
+
for (let i = 0; i < 6; i++) {
|
|
313
|
+
const tr = createElement('tr');
|
|
314
|
+
|
|
315
|
+
// 构建每一天的单元格
|
|
316
|
+
for (let j = 0; j < 7; j++) {
|
|
317
|
+
const { length } = tr.children;
|
|
318
|
+
const td = createElement('td');
|
|
319
|
+
const span = createElement('span');
|
|
320
|
+
|
|
321
|
+
// 获取当前日期是星期几
|
|
322
|
+
const day = currentDate.getDay();
|
|
323
|
+
const myDate = new Date();
|
|
324
|
+
|
|
325
|
+
// 判断当前单元格应展示哪一天的日期
|
|
326
|
+
if (weekArr[length] === this.week[day] && month === currentDate.getMonth() + 1) {
|
|
327
|
+
// 如果是当前月的日期,则展示当前月的日期
|
|
328
|
+
span.innerText = currentDate.getDate();
|
|
329
|
+
currentDate.setDate(currentDate.getDate() + 1);
|
|
330
|
+
this.#handleCalendarItemSelect(td);
|
|
331
|
+
} else if (month == currentDate.getMonth()) {
|
|
332
|
+
// 如果是下个月的日期,则展示下个月的日期
|
|
333
|
+
span.innerText = currentDate.getDate();
|
|
334
|
+
currentDate.setDate(currentDate.getDate() + 1);
|
|
335
|
+
td.classList.add("is-disabled");
|
|
336
|
+
} else {
|
|
337
|
+
// 如果是上个月的日期,则展示上个月的日期
|
|
338
|
+
const lastMonthDateStep = j - day + 2;
|
|
339
|
+
const step = weekArr.findIndex((item, index) => {
|
|
340
|
+
if (item === "一") return index;
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
lastDate.setMonth(month - 1);
|
|
344
|
+
lastDate.setDate(lastMonthDateStep > 0 ? (day + length) - step : lastMonthDateStep);
|
|
345
|
+
span.innerText = lastDate.getDate();
|
|
346
|
+
td.classList.add("is-disabled");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const userToday = new Date(this.date);
|
|
350
|
+
if (currentDate.getFullYear() === myDate.getFullYear() && currentDate.getMonth() === myDate.getMonth() && currentDate.getDate() === myDate.getDate() + 1) {
|
|
351
|
+
td.classList.add("is-today");
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (currentDate.getFullYear() === userDate.getFullYear() && currentDate.getMonth() === userDate.getMonth() && currentDate.getDate() === userDate.getDate() + 1) {
|
|
355
|
+
td.classList.add("is-selected");
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
// 将日期单元格添加到行中
|
|
360
|
+
td.appendChild(span);
|
|
361
|
+
tr.appendChild(td);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// 将行添加到日历表格中
|
|
365
|
+
content.appendChild(tr);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* 初始化日期选择器的按钮事件监听器。
|
|
371
|
+
* 此方法为上个月、今天和下个月按钮添加点击事件监听器,以实现日期的选择和切换。
|
|
372
|
+
*
|
|
373
|
+
* @private
|
|
374
|
+
*/
|
|
375
|
+
#initDateChangersEvent() {
|
|
376
|
+
// 为上个月按钮添加点击事件监听器,点击时调用#handleMonthChange方法,参数为"last"表示切换到上个月
|
|
377
|
+
this.#lastMonthBtn.addEventListener('click', () => {
|
|
378
|
+
this.#handleMonthChange("last");
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// 为今天按钮添加点击事件监听器,点击时设置日期为当前日期
|
|
382
|
+
this.#todayBtn.addEventListener('click', () => {
|
|
383
|
+
this.date = `${new Date().getFullYear()}-${new Date().getMonth() + 1}-${new Date().getDate()}`;
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
// 为下个月按钮添加点击事件监听器,点击时调用#handleMonthChange方法,参数为"next"表示切换到下个月
|
|
387
|
+
this.#nextMonthBtn.addEventListener('click', () => {
|
|
388
|
+
this.#handleMonthChange("next");
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
init() {
|
|
393
|
+
const that = this;
|
|
394
|
+
|
|
395
|
+
this.weekStart = this.weekStart;
|
|
396
|
+
|
|
397
|
+
this.date = this.date;
|
|
398
|
+
|
|
399
|
+
this.#initDateChangersEvent();
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
connectedCallback() {
|
|
403
|
+
this.init();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (!customElements.get('ea-calendar')) {
|
|
408
|
+
customElements.define('ea-calendar', EaCalendar);
|
|
409
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Base from '../Base.js';
|
|
3
|
+
import { createElement, createSlotElement } from '../../utils/createElement.js';
|
|
4
|
+
|
|
5
|
+
const stylesheet = `
|
|
6
|
+
.ea-card_wrap {
|
|
7
|
+
border-radius: 4px;
|
|
8
|
+
border: 1px solid #ebeef5;
|
|
9
|
+
background-color: #fff;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
color: #303133;
|
|
12
|
+
transition: box-shadow 0.3s;
|
|
13
|
+
}
|
|
14
|
+
.ea-card_wrap.is-always-shadow, .ea-card_wrap.is-hover-shadow:hover {
|
|
15
|
+
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
16
|
+
}
|
|
17
|
+
.ea-card_wrap.is-never-shadow {
|
|
18
|
+
box-shadow: none;
|
|
19
|
+
}
|
|
20
|
+
.ea-card_wrap .ea-card_content {
|
|
21
|
+
padding: 20px;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
class EaCard extends Base {
|
|
26
|
+
#wrap;
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
|
|
31
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
32
|
+
const wrap = document.createElement('div');
|
|
33
|
+
wrap.className = 'ea-card_wrap';
|
|
34
|
+
|
|
35
|
+
const headerSlot = createSlotElement('header');
|
|
36
|
+
const header = createElement('div', 'ea-card_header', [headerSlot]);
|
|
37
|
+
wrap.appendChild(header);
|
|
38
|
+
|
|
39
|
+
const contentSlot = document.createElement('slot');
|
|
40
|
+
const content = createElement('div', 'ea-card_content', [contentSlot]);
|
|
41
|
+
wrap.appendChild(content);
|
|
42
|
+
|
|
43
|
+
this.#wrap = wrap;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
this.build(shadowRoot, stylesheet);
|
|
47
|
+
this.shadowRoot.appendChild(wrap);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ------- shadow 阴影属性 -------
|
|
51
|
+
// #region
|
|
52
|
+
get shadow() {
|
|
53
|
+
return this.getAttribute('shadow') || "always";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
set shadow(val) {
|
|
57
|
+
this.setAttribute('shadow', val);
|
|
58
|
+
|
|
59
|
+
this.#wrap.classList.add(`is-${val}-shadow`);
|
|
60
|
+
}
|
|
61
|
+
// #endregion
|
|
62
|
+
// ------- end -------
|
|
63
|
+
|
|
64
|
+
init() {
|
|
65
|
+
const that = this;
|
|
66
|
+
|
|
67
|
+
this.shadow = this.shadow;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
connectedCallback() {
|
|
71
|
+
this.init();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!customElements.get('ea-card')) {
|
|
76
|
+
customElements.define('ea-card', EaCard);
|
|
77
|
+
}
|