TASK:#112052-实现电池组件自适应

This commit is contained in:
wangguoqing 2022-10-08 16:49:36 +08:00
parent e7eb241deb
commit d8f219e13d
6 changed files with 117 additions and 515 deletions

View File

@ -1,11 +1,22 @@
import {css, CSSResult} from 'lit'
export const sharedStyles: CSSResult = css`
.power {
position: relative;
width: 100%;
height: 0;
padding: 0;
padding-bottom: 100%;
}
.container {
position: absolute;
display: flex;
width: 160px;
height: 160px;
inset: 5%;
width: 100%;
height: 100%;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: radial-gradient(
60.05% 60.05% at 12.24% 12.74%,
#f7f9ff 0%,
@ -16,38 +27,36 @@ export const sharedStyles: CSSResult = css`
align-items: center;
}
.canvas {
width: 100%;
height: 100%;
}
.percent {
position: absolute;
font-style: normal;
font-weight: 400;
font-size: 16px;
line-height: 16px;
font-size: 9vw;
color: #717171;
padding-inline-start: 40px;
padding-inline-start: 25%;
padding-top: 2.5%;
}
.lightning {
position: absolute;
padding-block-end: 65px;
width: 20px;
height: 25px;
}
/*进度条为蓝色*/
:host([blue]) .container {
top: 250px;
padding-block-end: 40%;
width: 12.5%;
height: 15%;
}
/*深色模式*/
:host([deep]) .container {
left: 300px;
background: linear-gradient(
131.48deg,
rgba(71, 71, 71, 0.8) 7.8%,
rgba(20, 20, 20, 0.8) 87.95%
);
}
:host([deep]) .percent {
color: #f4f4f4;
}

View File

@ -64,10 +64,12 @@ export class StarBatterysquare extends LitElement {
render() {
return html`
<div class="container">
<canvas class="canvas" width="160" height="160"></canvas>
<img src="src/assets/lightning.svg" class="lightning" />
<span class="percent">%</span>
<div class="power">
<div class="container">
<canvas class="canvas" width="160px" height="160px"></canvas>
<img src="src/assets/lightning.svg" class="lightning" />
<span class="percent">%</span>
</div>
</div>
`
}

View File

@ -1,21 +1,29 @@
import {css, CSSResult} from 'lit'
export const sharedStyles: CSSResult = css`
.holder {
position: absolute;
width: 100%;
height: 0;
padding: 0;
padding-bottom: 35.4%;
}
.container {
display: flex;
position: absolute;
width: 452px;
height: 160px;
left: 150px;
top: 136px;
width: 100%;
height: 100%;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: linear-gradient(
137.64deg,
#f5f0f5 0%,
#fafafa 20.46%,
#d5daf2 90.45%
);
border: 1px dashed rgba(116, 116, 116, 0.12);
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.08);
border-radius: 20px;
box-shadow: 0px 0.92vw 2.3vw rgba(0, 0, 0, 0.08);
border-radius: 4.6vw;
}
.power {
@ -25,7 +33,7 @@ export const sharedStyles: CSSResult = css`
top: 0%;
bottom: 0%;
background: linear-gradient(152.36deg, #6be4d0 8.74%, #10a775 82.29%);
border-radius: 20px 0px 0px 20px;
border-radius: 4.6vw 0px 0px 4.6vw;
display: flex;
justify-content: space-between;
align-items: center;
@ -34,31 +42,31 @@ export const sharedStyles: CSSResult = css`
.number {
position: absolute;
left: 34px;
left: 12%;
font-style: normal;
font-weight: 400;
font-size: 50px;
line-height: 66px;
font-size: 11.5vw;
line-height: 15.18vw;
color: #ebc883;
}
.percent {
position: absolute;
left: 95px;
left: 33%;
font-style: normal;
font-weight: 400;
font-size: 26px;
line-height: 26px;
font-size: 5.98vw;
line-height: 5.98vw;
color: #ebc883;
bottom: 35%;
padding-block-start: 6.5%;
}
.lightning {
position: absolute;
right: 37.26px;
right: 9%;
top: 40%;
width: 33.74px;
height: 37.26px;
width: 7.46%;
height: 23.28%;
}
.bubbles {
@ -68,8 +76,8 @@ export const sharedStyles: CSSResult = css`
rgba(255, 255, 255, 0.5) 0%,
rgba(255, 255, 255, 0) 100%
);
width: 24px;
height: 24px;
width: 5.52vw;
height: 5.52vw;
border-radius: 50%;
opacity: 0.5;
animation: flying 10s ease-in infinite;
@ -78,23 +86,23 @@ export const sharedStyles: CSSResult = css`
@keyframes flying {
0% {
left: 0%;
transform: translateY(0px);
transform: translateY(0vw);
}
25% {
transform: translateY(25px);
transform: translateY(5.75vw);
}
50% {
transform: translateY(75px);
transform: translateY(17.25vw);
}
75% {
transform: translateY(-25px);
transform: translateY(-5.75vw);
}
88% {
transform: translateY(-38px);
transform: translateY(-8.74vw);
}
100% {
left: 90%;
transform: translateY(-50px);
transform: translateY(-11.5vw);
}
}
@ -103,8 +111,8 @@ export const sharedStyles: CSSResult = css`
animation-delay: 0s;
}
.bubbles:nth-child(2) {
width: 18px;
height: 18px;
width: 4.14vw;
height: 4.14vw;
top: 10%;
animation-duration: 8s;
animation-delay: 1s;
@ -115,8 +123,8 @@ export const sharedStyles: CSSResult = css`
animation-delay: 2s;
}
.bubbles:nth-child(4) {
width: 10px;
height: 10px;
width: 2.3vw;
height: 2.3vw;
animation-duration: 6s;
animation-delay: 0s;
}
@ -127,8 +135,8 @@ export const sharedStyles: CSSResult = css`
}
.bubbles:nth-child(6) {
top: 80%;
width: 18px;
height: 18px;
width: 4.14vw;
height: 4.14vw;
animation-duration: 6s;
animation-delay: 1s;
}
@ -139,299 +147,12 @@ export const sharedStyles: CSSResult = css`
}
.bubbles:nth-child(8) {
bottom: 90%;
width: 10px;
height: 10px;
width: 2.3vw;
height: 2.3vw;
animation-duration: 9s;
animation-delay: 0s;
}
/*mini*/
.bubbles_mini {
position: absolute;
background: linear-gradient(
180deg,
rgba(255, 255, 255, 0.5) 0%,
rgba(255, 255, 255, 0) 100%
);
width: 6px;
height: 6px;
border-radius: 50%;
opacity: 0.5;
animation: flymini 10s ease-in infinite;
}
@keyframes flymini {
0% {
left: 0%;
transform: translateY(0px);
}
25% {
transform: translateY(6px);
}
50% {
transform: translateY(19px);
}
75% {
transform: translateY(-6px);
}
88% {
transform: translateY(-10px);
}
100% {
left: 90%;
transform: translateY(-12px);
}
}
.bubbles_mini:nth-child(1) {
animation-duration: 8s;
animation-delay: 0s;
}
.bubbles_mini:nth-child(2) {
width: 4px;
height: 4px;
top: 10%;
animation-duration: 8s;
animation-delay: 1s;
}
.bubbles_mini:nth-child(3) {
top: 20%;
animation-duration: 5s;
animation-delay: 2s;
}
.bubbles_mini:nth-child(4) {
width: 2.5px;
height: 2.5px;
animation-duration: 6s;
animation-delay: 0s;
}
.bubbles_mini:nth-child(5) {
top: 40%;
animation-duration: 7s;
animation-delay: 2s;
}
.bubbles_mini:nth-child(6) {
top: 80%;
width: 5px;
height: 5px;
animation-duration: 6s;
animation-delay: 1s;
}
.bubbles_mini:nth-child(7) {
top: 40%;
animation-duration: 9s;
animation-delay: 2s;
}
.bubbles_mini:nth-child(8) {
bottom: 90%;
width: 2.5px;
height: 2.5px;
animation-duration: 9s;
animation-delay: 0s;
}
/*small*/
.bubbles_small {
position: absolute;
background: linear-gradient(
180deg,
rgba(255, 255, 255, 0.5) 0%,
rgba(255, 255, 255, 0) 100%
);
width: 12px;
height: 12px;
border-radius: 50%;
opacity: 0.5;
animation: flysmall 10s ease-in infinite;
}
@keyframes flysmall {
0% {
left: 0%;
transform: translateY(0px);
}
25% {
transform: translateY(12px);
}
50% {
transform: translateY(38px);
}
75% {
transform: translateY(-12px);
}
88% {
transform: translateY(-20px);
}
100% {
left: 90%;
transform: translateY(-24px);
}
}
.bubbles_small:nth-child(1) {
animation-duration: 8s;
animation-delay: 0s;
}
.bubbles_small:nth-child(2) {
width: 8px;
height: 8px;
top: 10%;
animation-duration: 8s;
animation-delay: 1s;
}
.bubbles_small:nth-child(3) {
top: 20%;
animation-duration: 5s;
animation-delay: 2s;
}
.bubbles_small:nth-child(4) {
width: 5px;
height: 5px;
animation-duration: 6s;
animation-delay: 0s;
}
.bubbles_small:nth-child(5) {
top: 40%;
animation-duration: 7s;
animation-delay: 2s;
}
.bubbles_small:nth-child(6) {
top: 80%;
width: 10px;
height: 10px;
animation-duration: 6s;
animation-delay: 1s;
}
.bubbles_small:nth-child(7) {
top: 40%;
animation-duration: 9s;
animation-delay: 2s;
}
.bubbles_small:nth-child(8) {
bottom: 90%;
width: 5px;
height: 5px;
animation-duration: 9s;
animation-delay: 0s;
}
/*medium*/
.bubbles_medium {
position: absolute;
background: linear-gradient(
180deg,
rgba(255, 255, 255, 0.5) 0%,
rgba(255, 255, 255, 0) 100%
);
width: 18px;
height: 18px;
border-radius: 50%;
opacity: 0.5;
animation: flymini 10s ease-in infinite;
}
@keyframes flymini {
0% {
left: 0%;
transform: translateY(0px);
}
25% {
transform: translateY(18px);
}
50% {
transform: translateY(57px);
}
75% {
transform: translateY(-18px);
}
88% {
transform: translateY(-30px);
}
100% {
left: 90%;
transform: translateY(-36px);
}
}
.bubbles_medium:nth-child(1) {
animation-duration: 8s;
animation-delay: 0s;
}
.bubbles_medium:nth-child(2) {
width: 12px;
height: 12px;
top: 10%;
animation-duration: 8s;
animation-delay: 1s;
}
.bubbles_medium:nth-child(3) {
top: 20%;
animation-duration: 5s;
animation-delay: 2s;
}
.bubbles_medium:nth-child(4) {
width: 7.5px;
height: 7.5px;
animation-duration: 6s;
animation-delay: 0s;
}
.bubbles_medium:nth-child(5) {
top: 40%;
animation-duration: 7s;
animation-delay: 2s;
}
.bubbles_medium:nth-child(6) {
top: 80%;
width: 15px;
height: 15px;
animation-duration: 6s;
animation-delay: 1s;
}
.bubbles_medium:nth-child(7) {
top: 40%;
animation-duration: 9s;
animation-delay: 2s;
}
.bubbles_medium:nth-child(8) {
bottom: 90%;
width: 7.5px;
height: 7.5px;
animation-duration: 9s;
animation-delay: 0s;
}
.location {
position: absolute;
margin-left: 200px;
top: -215px;
}
.location_charge {
position: absolute;
margin-left: 400px;
}
.location_charge_deep {
position: absolute;
margin-left: 600px;
top: -215px;
}
.mini {
position: absolute;
top: 430px;
}
.small {
position: absolute;
top: 530px;
}
.medium {
position: absolute;
top: 670px;
}
/*深色模式*/
:host([deep]) .container {
box-sizing: border-box;
@ -441,109 +162,23 @@ export const sharedStyles: CSSResult = css`
#302f33 100%
);
border: none;
top: 350px;
}
/*充电模式*/
:host([charge]) .container {
left: 700px;
}
/*旋转组件*/
:host([vertical]) .container {
left: 1150px;
transform: rotate(270deg);
margin-top: 70px;
margin-top: 50%;
}
:host([vertical]) .number {
transform: rotate(90deg);
}
:host([vertical]) .percent {
transform: rotate(270deg);
left: 35px;
bottom: 15%;
left: 9%;
padding-right: 31%;
padding-block-end: 30%;
}
:host([vertical]) .lightning {
transform: rotate(90deg);
}
/*mini*/
:host([mini]) .container {
width: 113px;
height: 40px;
border-radius: 12px;
}
:host([mini]) .power {
border-radius: 12px 0px 0px 12px;
}
:host([mini]) .number {
font-size: 12.5px;
left: 13.5px;
}
:host([mini]) .percent {
left: 24px;
font-size: 6.5px;
line-height: 6.5px;
}
:host([mini]) .lightning {
right: 9.315px;
width: 8.435px;
height: 9.315px;
}
:host([mini]) .bubbles {
width: 6px;
height: 6px;
}
/*small*/
:host([small]) .container {
width: 226px;
height: 80px;
border-radius: 15px;
}
:host([small]) .power {
border-radius: 15px 0px 0px 15px;
}
:host([small]) .number {
font-size: 25px;
left: 17px;
}
:host([small]) .percent {
left: 48px;
font-size: 13px;
line-height: 13px;
}
:host([small]) .lightning {
right: 18.63px;
width: 16.87px;
height: 18.63px;
}
:host([small]) .bubbles {
width: 12px;
height: 12px;
}
/*medium*/
:host([medium]) .container {
width: 339px;
height: 120px;
border-radius: 15px;
}
:host([medium]) .power {
border-radius: 15px 0px 0px 15px;
}
:host([medium]) .number {
font-size: 38px;
left: 26px;
}
:host([medium]) .percent {
left: 72px;
font-size: 20px;
line-height: 20px;
}
:host([medium]) .lightning {
right: 28px;
width: 25.3px;
height: 28px;
}
`

View File

@ -12,12 +12,6 @@ export class StarBattery extends LitElement {
@property({type: Boolean}) charge = false
@property({type: Boolean}) mini = false
@property({type: Boolean}) small = false
@property({type: Boolean}) medium = false
@query('.power') _power: any
@query('.percent') _percent: any
@ -30,54 +24,21 @@ export class StarBattery extends LitElement {
if (this.charge == true) {
var power = this._power
power.style.right = this.percent + '%'
this._percent.style.left = '29%'
for (var i = 0; i < 20; i++) {
const bubbles = document.createElement('span')
if (this.mini == true) {
bubbles.className = 'bubbles_mini'
} else if (this.small == true) {
bubbles.className = 'bubbles_small'
} else if (this.medium == true) {
bubbles.className = 'bubbles_medium'
} else {
bubbles.className = 'bubbles'
}
bubbles.className = 'bubbles'
power.append(bubbles)
}
if (this.percent == 0) {
if (this.mini == true) {
this._percent.style.left = '35px'
this._power.style.borderRadius = '12px'
} else if (this.small == true) {
this._percent.style.left = '60px'
this._power.style.borderRadius = '15px'
} else if (this.medium == true) {
this._percent.style.left = '90px'
this._power.style.borderRadius = '15px'
} else {
this._percent.style.left = '120px'
this._power.style.borderRadius = '20px'
}
this._percent.style.left = '32%'
this._percent.style.paddingBlockStart = '5.5%'
this._power.style.borderRadius = '20px'
} else if (this.percent <= 2 && this.percent > 1) {
if (this.mini == true) {
this._power.style.borderRadius = '12px'
} else if (this.small == true) {
this._power.style.borderRadius = '15px'
} else if (this.medium == true) {
this._power.style.borderRadius = '15px'
} else {
this._power.style.borderRadius = '20px 9px 9.5px 20px'
}
this._power.style.borderRadius = '20px 9px 9.5px 20px'
} else if (this.percent <= 1 && this.percent > 0) {
if (this.mini == true) {
this._power.style.borderRadius = '12px'
} else if (this.small == true) {
this._power.style.borderRadius = '15px'
} else if (this.medium == true) {
this._power.style.borderRadius = '15px'
} else {
this._power.style.borderRadius = '20px 11.5px 12px 20px'
}
this._power.style.borderRadius = '20px 11.5px 12px 20px'
}
} else {
nothing
@ -86,28 +47,29 @@ export class StarBattery extends LitElement {
render() {
return html`
<div class="container">
<div class="power">
${this.charge == true
? html`
<span class="number">
<!-- ${(100 - this.percent).toLocaleString()} -->
${this.percent == 0
? html`
100
`
: html`
${(100 - this.percent).toPrecision(2)}
`}
</span>
`
: html`
<span class="number">78</span>
`}
<span class="percent">%</span>
</div>
<div>
<img src="src/assets/lightning.svg" class="lightning" />
<div class="holder">
<div class="container">
<div class="power">
${this.charge == true
? html`
<span class="number">
${this.percent == 0
? html`
100
`
: html`
${(100 - this.percent).toPrecision(2)}
`}
</span>
`
: html`
<span class="number">78</span>
`}
<span class="percent">%</span>
</div>
<div>
<img src="src/assets/lightning.svg" class="lightning" />
</div>
</div>
</div>
`

View File

@ -7,9 +7,9 @@ export class PanelBatterysquare extends LitElement {
render() {
return html`
<star-batterysquare></star-batterysquare>
<star-batterysquare blue></star-batterysquare>
<star-batterysquare deep></star-batterysquare>
<star-batterysquare deep blue></star-batterysquare>
<!-- <star-batterysquare blue></star-batterysquare> -->
<!-- <star-batterysquare deep></star-batterysquare> -->
<!-- <star-batterysquare deep blue></star-batterysquare> -->
`
}

View File

@ -7,19 +7,13 @@ export class PanelBattery extends LitElement {
render() {
return html`
<star-battery></star-battery>
<star-battery deep></star-battery>
<star-battery charge></star-battery>
<star-battery charge deep></star-battery>
<star-battery vertical></star-battery>
<star-battery vertical deep class="location"></star-battery>
<star-battery vertical charge class="location_charge"></star-battery>
<star-battery vertical charge deep class="location_charge_deep"></star-battery>
<star-battery class="mini" mini></star-battery>
<star-battery class="mini" mini charge></star-battery>
<star-battery class="small" small></star-battery>
<star-battery class="small" small charge></star-battery>
<star-battery class="medium" medium></star-battery>
<star-battery class="medium" medium charge></star-battery>
<!-- <star-battery deep></star-battery> -->
<!-- <star-battery charge></star-battery> -->
<!-- <star-battery charge deep></star-battery> -->
<!-- <star-battery vertical></star-battery> -->
<!-- <star-battery vertical deep></star-battery> -->
<!-- <star-battery vertical charge></star-battery> -->
<!-- <star-battery vertical charge deep></star-battery> -->
`
}