Skip to content

Commit 8eef44b

Browse files
author
Uber
committed
1.增加时间
2.一些ui
1 parent 9b4689f commit 8eef44b

File tree

1 file changed

+67
-18
lines changed

1 file changed

+67
-18
lines changed

dist/ch_calendar-card.js

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ChineseCalendarCard extends LitElement {
1010
:host {
1111
--main-bg-color: linear-gradient(to bottom,#03a9f4,#68d0ff);
1212
--main-title-color: white;
13-
--ch-highlight-color: #03a9f4;
13+
--ch-highlight-color: #68d0ff;
1414
--cell-title-color: #515151;
1515
--cell-date-color: #aaa;
1616
}
@@ -47,12 +47,19 @@ class ChineseCalendarCard extends LitElement {
4747
}
4848
.title {
4949
margin-left: 16px;
50-
font-size: 16px;
50+
font-size: 14px;
51+
}
52+
53+
.flex_container_center {
54+
display: flex;
55+
align-items: baseline;
56+
justify-content: center;
5157
}
58+
5259
.date_solar {
5360
font-size: 30px;
5461
text-align: right;
55-
margin-right: 20px;
62+
margin-right: 17px;
5663
padding-top: 20px;
5764
color: var(--main-title-color);
5865
}
@@ -73,12 +80,13 @@ class ChineseCalendarCard extends LitElement {
7380
color: var(--main-title-color);
7481
font-size: 14px;
7582
text-align: center;
76-
padding-top: 35px;
83+
padding-top: 20px;
7784
}
7885
.latest_holiday {
7986
color: var(--main-title-color);
8087
font-size: 18px;
8188
text-align: center;
89+
padding-top: 4px;
8290
}
8391
.latest_days {
8492
color: var(--main-title-color);
@@ -87,17 +95,25 @@ class ChineseCalendarCard extends LitElement {
8795
padding-top: 20px;
8896
padding-bottom: 16px;
8997
}
98+
99+
.latest_days_unit {
100+
101+
color: var(--main-title-color);
102+
font-size: 14px;
103+
margin-left: 2px;
104+
}
105+
90106
.latest_date {
91107
color: var(--main-title-color);
92108
font-size: 14px;
93109
text-align: center;
94-
padding-bottom: 50px;
110+
padding-bottom: 35px;
95111
}
96112
.cell_l {
97113
text-align: left;
98114
}
99115
.cell_name {
100-
font-size: 16px;
116+
font-size: 14px;
101117
color: var(--cell-title-color);
102118
}
103119
.cell_date {
@@ -106,12 +122,12 @@ class ChineseCalendarCard extends LitElement {
106122
}
107123
.cell_day_h {
108124
text-align: right;
109-
font-size: 16px;
125+
font-size: 14px;
110126
color: var(--ch-highlight-color);
111127
}
112128
.cell_day_n {
113129
text-align: right;
114-
font-size: 16px;
130+
font-size: 14px;
115131
color: var(--cell-title-color);
116132
}
117133
.table {
@@ -122,6 +138,8 @@ class ChineseCalendarCard extends LitElement {
122138
}
123139
.container {
124140
background: var(--main-bg-color);
141+
border-top-left-radius: 8px;
142+
border-top-right-radius: 8px;
125143
}
126144
.list_container {
127145
padding-bottom: 20px;
@@ -136,11 +154,12 @@ class ChineseCalendarCard extends LitElement {
136154
<div style="align-items: baseline;">
137155
<div class="title">${this.title}</div>
138156
</div>
139-
140157
<div class="date_solar">
141158
${this.attributes.solar}
142159
</div>
143-
160+
<div class="date_solar">
161+
${this.currentTime}
162+
</div>
144163
<div class="date_week">
145164
<p class="icon_state" style="background: none, url(${this.getStateIcon(this.calendarEntity.state)}) no-repeat; background-size: contain;"></p>
146165
${this.attributes.week}
@@ -155,8 +174,15 @@ class ChineseCalendarCard extends LitElement {
155174
</div>
156175
<div class="latest_title">距离</div>
157176
<div class="latest_holiday">${this.latestReminder.name}</div>
158-
<div class="latest_days">${this.latestReminder.days}</div>
159-
<div class="latest_date">${this.latestReminder.date}</div>
177+
<div class="flex_container_center">
178+
<div class="latest_days">
179+
${this.latestReminder.days}
180+
</div>
181+
<div class="latest_days_unit">
182+
183+
</div>
184+
</div>
185+
<div class="latest_date">${this.dateFormatIfNeed(this.latestReminder.date)}</div>
160186
</div>
161187
<div class=list_container>
162188
${this.reminderList.map((item, index) =>
@@ -172,7 +198,7 @@ class ChineseCalendarCard extends LitElement {
172198
<td class="cell_name">${item.name}</td>
173199
</tr>
174200
<tr>
175-
<td class="cell_date">${item.date}</td>
201+
<td class="cell_date">${this.dateFormatIfNeed(item.date)}</td>
176202
</tr>
177203
</table>
178204
</td>
@@ -231,6 +257,18 @@ class ChineseCalendarCard extends LitElement {
231257

232258
constructor() {
233259
super();
260+
const options = {
261+
hour: 'numeric',
262+
minute: 'numeric',
263+
second: 'numeric',
264+
}
265+
var d = new Date();
266+
this.currentTime = d.toLocaleTimeString();
267+
setInterval(() => {
268+
var d = new Date();
269+
this.currentTime = d.toLocaleTimeString();
270+
this.requestUpdate();
271+
}, 1000);
234272

235273
}
236274

@@ -350,6 +388,17 @@ class ChineseCalendarCard extends LitElement {
350388

351389
}
352390

391+
//transfer yyyyMMdd to yyyy-MM-dd
392+
dateFormatIfNeed(date_str) {
393+
const regex = /^\d{4}(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[01])$/;
394+
395+
if (regex.test(date_str)) {
396+
const formattedDate = date_str.replace(/^(\d{4})(\d{2})(\d{2})$/, '$1-$2-$3');
397+
return formattedDate
398+
}
399+
400+
return date_str
401+
}
353402

354403
getIcon(index) {
355404
return `${
@@ -360,11 +409,11 @@ class ChineseCalendarCard extends LitElement {
360409
}
361410

362411
getStateIcon(state) {
363-
var stateIcons = [{state:'工作日', icon:'working'},{state:'休息日', icon:'dating'},{state:'节假日', icon:'vacation'}];
364-
var iconName = "";
365-
366-
stateIcons.forEach(function(item, index) {
367-
if(item.state == state) {
412+
var stateIcons = [{state:'工作日', icon:'working'},{state:'休息日', icon:'dating'},{state:'节假日', icon:'vacation'}];
413+
var iconName = "";
414+
415+
stateIcons.forEach(function(item, index) {
416+
if(item.state == state) {
368417
iconName = item.icon;
369418
return true;
370419
}

0 commit comments

Comments
 (0)