Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<view class="uni-countdown">
<text v-if="showDay" :style="[timeStyle]" class="uni-countdown__number">{{ d }}</text>
<text v-if="showDay" :style="[splitorStyle]" class="uni-countdown__splitor">{{dayText}}</text>
<text :style="[timeStyle]" class="uni-countdown__number">{{ h }}</text>
<text :style="[splitorStyle]" class="uni-countdown__splitor">{{ showColon ? ':' : hourText }}</text>
<text :style="[timeStyle]" class="uni-countdown__number">{{ i }}</text>
<text :style="[splitorStyle]" class="uni-countdown__splitor">{{ showColon ? ':' : minuteText }}</text>
<text :style="[timeStyle]" class="uni-countdown__number">{{ s }}</text>
<text v-if="!showColon" :style="[splitorStyle]" class="uni-countdown__splitor">{{secondText}}</text>
<text v-if="mergeShowTime.hour" :style="[timeStyle]" class="uni-countdown__number">{{ h }}</text>
<text v-if="mergeShowTime.hour" :style="[splitorStyle]" class="uni-countdown__splitor">{{ showColon ? ':' : hourText }}</text>
<text v-if="mergeShowTime.minute" :style="[timeStyle]" class="uni-countdown__number">{{ i }}</text>
<text v-if="mergeShowTime.minute" :style="[splitorStyle]" class="uni-countdown__splitor">{{ showColon ? ':' : minuteText }}</text>
<text v-if="mergeShowTime.second" :style="[timeStyle]" class="uni-countdown__number">{{ s }}</text>
<text v-if="!showColon&&mergeShowTime.second" :style="[splitorStyle]" class="uni-countdown__splitor">{{secondText}}</text>
</view>
</template>
<script>
Expand Down Expand Up @@ -43,6 +43,12 @@
type: Boolean,
default: true
},
showTime:{
type: Object,
default () {
return {}
}
},
showColon: {
type: Boolean,
default: true
Expand All @@ -58,10 +64,10 @@
color: {
type: String,
default: '#333'
},
fontSize: {
type: Number,
default: 14
},
fontSize: {
type: Number,
default: 14
},
splitorColor: {
type: String,
Expand Down Expand Up @@ -101,6 +107,14 @@
}
},
computed: {
mergeShowTime() {
return {
hour: true,
minute: true,
second: true,
...this.showTime
}
},
dayText() {
return t("uni-countdown.day")
},
Expand All @@ -116,23 +130,23 @@
timeStyle() {
const {
color,
backgroundColor,
backgroundColor,
fontSize
} = this
return {
color,
backgroundColor,
fontSize: `${fontSize}px`,
width: `${fontSize * 22 / 14}px`, // 按字体大小为 14px 时的比例缩放
lineHeight: `${fontSize * 20 / 14}px`,
borderRadius: `${fontSize * 3 / 14}px`,
backgroundColor,
fontSize: `${fontSize}px`,
width: `${fontSize * 22 / 14}px`, // 按字体大小为 14px 时的比例缩放
lineHeight: `${fontSize * 20 / 14}px`,
borderRadius: `${fontSize * 3 / 14}px`,
}
},
splitorStyle() {
const { splitorColor, fontSize, backgroundColor } = this
return {
color: splitorColor,
fontSize: `${fontSize * 12 / 14}px`,
splitorStyle() {
const { splitorColor, fontSize, backgroundColor } = this
return {
color: splitorColor,
fontSize: `${fontSize * 12 / 14}px`,
margin: backgroundColor ? `${fontSize * 4 / 14}px` : ''
}
}
Expand All @@ -141,10 +155,10 @@
day(val) {
this.changeFlag()
},
hour(val) {
hour(val) {
this.changeFlag()
},
minute(val) {
minute(val) {
this.changeFlag()
},
second(val) {
Expand Down Expand Up @@ -214,15 +228,15 @@
this.d = day
this.h = hour
this.i = minute
this.s = second
this.s = second
},
startData() {
this.seconds = this.toSeconds(this.timestamp, this.day, this.hour, this.minute, this.second)
if (this.seconds <= 0) {
this.seconds = this.toSeconds(0, 0, 0, 0, 0)
if (this.seconds <= 0) {
this.seconds = this.toSeconds(0, 0, 0, 0, 0)
this.countDown()
return
}
}
clearInterval(this.timer)
this.countDown()
this.timer = setInterval(() => {
Expand All @@ -233,11 +247,11 @@
}
this.countDown()
}, 1000)
},
update(){
this.startData();
},
changeFlag() {
update(){
this.startData();
},
changeFlag() {
if (!this.syncFlag) {
this.seconds = this.toSeconds(this.timestamp, this.day, this.hour, this.minute, this.second)
this.startData();
Expand All @@ -248,24 +262,24 @@
}
</script>
<style lang="scss" scoped>
$font-size: 14px;
$font-size: 14px;

.uni-countdown {
.uni-countdown {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
align-items: center;

&__splitor {
margin: 0 2px;
font-size: $font-size;
color: #333;
font-size: $font-size;
color: #333;
}

&__number {
&__number {
border-radius: 3px;
text-align: center;
font-size: $font-size;
font-size: $font-size;
}
}
</style>
</style>