Merge pull request #69 in YR/star-web-components from feature-component-modify to master

* commit '32f64207344ef4d153dfbaf3536ad33cd9597f7a':
  修改完善代码
  modify
  修改代码
  修改代码
  修改代码
  TASK:#112052-实现电池组件自适应
  修改代码
This commit is contained in:
汪昌棋 2022-10-10 15:16:23 +08:00
commit a94c33c204
9 changed files with 248 additions and 553 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,64 +1,67 @@
import {css, CSSResult} from 'lit'
export const sharedStyles: CSSResult = css`
.holder {
position: relative;
width: var(--battery-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%;
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;
}
.power {
position: absolute;
left: 0%;
right: 36.01%;
top: 0%;
bottom: 0%;
background: linear-gradient(152.36deg, #6be4d0 8.74%, #10a775 82.29%);
border-radius: 20px 0px 0px 20px;
display: flex;
box-shadow: 0px 0.92vw 2.3vw rgba(0, 0, 0, 0.08);
border-radius: 4.6vw;
justify-content: space-between;
align-items: center;
overflow: hidden;
}
.power {
position: absolute;
left: 0%;
right: var(--power-right);
top: 0%;
bottom: 0%;
background: linear-gradient(152.36deg, #6be4d0 8.74%, #10a775 82.29%);
border-radius: 4.6vw 0px 0px 4.6vw;
display: flex;
}
.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;
font-style: normal;
left: var(--percent-left);
font-weight: 400;
font-size: 26px;
line-height: 26px;
font-size: 5.98vw;
line-height: 5.98vw;
color: #ebc883;
bottom: 35%;
padding-block-start: 4.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 +71,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;
@ -77,24 +80,24 @@ export const sharedStyles: CSSResult = css`
@keyframes flying {
0% {
left: 0%;
transform: translateY(0px);
top: 90%;
transform: translateX(0vw);
}
25% {
transform: translateY(25px);
transform: translateX(5.75vw);
}
50% {
transform: translateY(75px);
transform: translateX(17.25vw);
}
75% {
transform: translateY(-25px);
transform: translateX(-5.75vw);
}
88% {
transform: translateY(-38px);
transform: translateX(-8.74vw);
}
100% {
left: 90%;
transform: translateY(-50px);
top: 0%;
transform: translateX(-11.5vw);
}
}
@ -103,335 +106,48 @@ export const sharedStyles: CSSResult = css`
animation-delay: 0s;
}
.bubbles:nth-child(2) {
width: 18px;
height: 18px;
top: 10%;
width: 4.14vw;
height: 4.14vw;
left: 10%;
animation-duration: 8s;
animation-delay: 1s;
}
.bubbles:nth-child(3) {
top: 20%;
left: 20%;
animation-duration: 5s;
animation-delay: 2s;
}
.bubbles:nth-child(4) {
width: 10px;
height: 10px;
width: 2.3vw;
height: 2.3vw;
animation-duration: 6s;
animation-delay: 0s;
}
.bubbles:nth-child(5) {
top: 40%;
left: 40%;
animation-duration: 7s;
animation-delay: 2s;
}
.bubbles:nth-child(6) {
top: 80%;
width: 18px;
height: 18px;
left: 80%;
width: 4.14vw;
height: 4.14vw;
animation-duration: 6s;
animation-delay: 1s;
}
.bubbles:nth-child(7) {
top: 40%;
left: 40%;
animation-duration: 9s;
animation-delay: 2s;
}
.bubbles:nth-child(8) {
bottom: 90%;
width: 10px;
height: 10px;
right: 90%;
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 +157,104 @@ 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%;
padding-right: var(--vertical-right);
padding-block-end: var(--vertical-end);
}
:host([vertical]) .lightning {
transform: rotate(90deg);
}
/*mini*/
:host([mini]) .container {
width: 113px;
height: 40px;
border-radius: 12px;
.bubbles_vertical {
position: absolute;
background: linear-gradient(
180deg,
rgba(255, 255, 255, 0.5) 0%,
rgba(255, 255, 255, 0) 100%
);
width: 5.52vw;
height: 5.52vw;
border-radius: 50%;
opacity: 0.5;
animation: flying-vertical 10s ease-in infinite;
}
: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;
@keyframes flying-vertical {
0% {
left: 0%;
transform: translateY(0vw);
}
25% {
transform: translateY(5.75vw);
}
50% {
transform: translateY(17.25vw);
}
75% {
transform: translateY(-5.75vw);
}
88% {
transform: translateY(-8.74vw);
}
100% {
left: 90%;
transform: translateY(-11.5vw);
}
}
/*small*/
:host([small]) .container {
width: 226px;
height: 80px;
border-radius: 15px;
.bubbles_vertical:nth-child(1) {
animation-duration: 8s;
animation-delay: 0s;
}
:host([small]) .power {
border-radius: 15px 0px 0px 15px;
.bubbles_vertical:nth-child(2) {
width: 4.14vw;
height: 4.14vw;
top: 10%;
animation-duration: 8s;
animation-delay: 1s;
}
:host([small]) .number {
font-size: 25px;
left: 17px;
.bubbles_vertical:nth-child(3) {
top: 20%;
animation-duration: 5s;
animation-delay: 2s;
}
:host([small]) .percent {
left: 48px;
font-size: 13px;
line-height: 13px;
.bubbles_vertical:nth-child(4) {
width: 2.3vw;
height: 2.3vw;
animation-duration: 6s;
animation-delay: 0s;
}
:host([small]) .lightning {
right: 18.63px;
width: 16.87px;
height: 18.63px;
.bubbles_vertical:nth-child(5) {
top: 40%;
animation-duration: 7s;
animation-delay: 2s;
}
:host([small]) .bubbles {
width: 12px;
height: 12px;
.bubbles_vertical:nth-child(6) {
top: 80%;
width: 4.14vw;
height: 4.14vw;
animation-duration: 6s;
animation-delay: 1s;
}
/*medium*/
:host([medium]) .container {
width: 339px;
height: 120px;
border-radius: 15px;
.bubbles_vertical:nth-child(7) {
top: 40%;
animation-duration: 9s;
animation-delay: 2s;
}
: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;
.bubbles_vertical:nth-child(8) {
bottom: 90%;
width: 2.3vw;
height: 2.3vw;
animation-duration: 9s;
animation-delay: 0s;
}
`

View File

@ -1,4 +1,4 @@
import {html, LitElement, CSSResultArray, nothing} from 'lit'
import {html, LitElement, CSSResultArray} from 'lit'
import {customElement, property, query} from 'lit/decorators.js'
import {sharedStyles} from './battery-styles'
@ -10,103 +10,71 @@ export class StarBattery extends LitElement {
@property({type: Boolean}) deep = false
@property({type: Boolean}) charge = false
@property({type: Boolean}) mini = false
@property({type: Boolean}) small = false
@property({type: Boolean}) medium = false
@property({type: Boolean, reflect: true}) charge = false
@query('.power') _power: any
@query('.percent') _percent: any
@property({type: Boolean}) vertical = false
@property({type: Boolean}) vertical = true
@property({type: Number}) percent = 22
@property({type: Number, reflect: true}) percent = 0
static get observedAttributes() {
return ['charge', 'percent']
}
attributeChangedCallback(name: string, oldValue: any, newValue: any) {
//console.log(name, oldValue, newValue)
switch (name) {
case 'charge':
if (newValue !== null) {
for (var i = 0; i < 20; i++) {
const bubbles = document.createElement('span')
if (this.vertical == true) {
bubbles.className = 'bubbles_vertical'
this._power.append(bubbles)
} else {
bubbles.className = 'bubbles'
this._power.append(bubbles)
}
}
} else {
this._power.innerHTML = ''
}
break
case 'percent':
if (newValue !== null) {
this.style.setProperty('--power-right', 100 - this.percent + '%')
if (this.percent == 0) {
this.style.setProperty('--percent-left', '19.5%')
this.style.setProperty('--vertical-right', '13%')
this.style.setProperty('--vertical-end', '38.5%')
} else if (this.percent == 100) {
this.style.setProperty('--percent-left', '31.5%')
this.style.setProperty('--vertical-right', '25%')
this.style.setProperty('--vertical-end', '61.5%')
} else {
this.style.setProperty('--percent-left', '25.5%')
this.style.setProperty('--vertical-right', '20%')
this.style.setProperty('--vertical-end', '50%')
}
}
break
}
}
protected firstUpdated(): void {
if (this.charge == true) {
var power = this._power
power.style.right = this.percent + '%'
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'
}
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'
}
} 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'
}
} 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'
}
}
} else {
nothing
}
this.charge = true
}
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>
`}
<div class="holder">
<div class="container">
<div class="power"></div>
<span class="number">${Math.round(this.percent)}</span>
<span class="percent">%</span>
</div>
<div>
<img src="src/assets/lightning.svg" class="lightning" />
</div>
</div>

View File

@ -23,7 +23,8 @@ import './components/prompt/prompt'
import './components/digicipher/digicipher'
import './components/pattern-view/pattern-view'
import './components/overlay/active-overlay'
import './components/battery/battery'
import './components/battery-square/battery-square'
@customElement('settings-app')
export class SettingsApp extends LitElement {
@query('star-animate-section#root') private rootSection!: StarAnimateSection

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

@ -1,35 +1,34 @@
import {html, LitElement, CSSResultArray} from 'lit'
import {customElement} from 'lit/decorators.js'
import {html, LitElement, CSSResultArray, css} from 'lit'
import {customElement, query} from 'lit/decorators.js'
import {sharedStyles} from '../../../components/battery/battery-styles'
@customElement('panel-battery')
export class PanelBattery extends LitElement {
@query('#container') container!: HTMLElement
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>
<div id="container">
<star-battery vertical></star-battery>
</div>
<!-- <star-battery deep></star-battery> -->
<!-- <star-battery charge></star-battery> -->
`
}
public static override get styles(): CSSResultArray {
return [sharedStyles]
return [
sharedStyles,
css`
:host {
height: 100vh;
width: 100vw;
}
#container {
height: 100vh;
width: 100vw;
}
`,
]
}
}

View File

@ -35,7 +35,8 @@ import './notification/notification'
import './switch/switch'
import './activeoverlay/activeoverlay'
import './battery/battery'
import './battery-square/battery-square'
type SEID = string
@customElement('panel-root')

View File

@ -1,8 +1,12 @@
import {css, CSSResult} from 'lit'
export const sharedStyles: CSSResult = css`
.location {
margin-left: 40px;
hr {
margin: 0;
padding: 0;
border-width: 0 0 1px 0;
border-style: solid;
border-color: #ccc;
}
hr {
margin: 0;