<template>
<gracePage headerBG="#FFFFFF" :customHeader="false">
<view slot="gBody" class="grace-body">
<view class="grace-margin-top">
<text class="grace-title">示例1</text>
</view>
<view class="grace-flex-center">
<graceCountDown :timer="timer1" width="38rpx" v-on:endDo="endDo(1)" ref="graceCountDown1"></graceCountDown>
</view>
<view class="grace-margin-top">
<text class="grace-title">示例2</text>
</view>
<view class="grace-flex-center" style="background:#3688FF; padding:30rpx 0;">
<graceCountDown
:timer="timer2" borderColor="#FFFFFF" splitorColor="#FFFFFF" fontColor="#FFFFFF" bgrColor="none"
:splitorText="['天', '时', '分', '秒']" v-on:endDo="endDo(2)"></graceCountDown>
</view>
<view class="grace-margin-top">
<text class="grace-title">示例3</text>
</view>
<view class="grace-flex-center" @tap="getTimeRemaining">
<!-- 使用 v-if 等时间数据加载后再创建组件 -->
<graceCountDown :splitorText="['天','时','分','秒']" width="60rpx" v-if="timer3 != ''" ref="graceCountDown3"
fontColor="#FFFFFF" borderColor="#FF0036" bgrColor="#FF0036" splitorColor="#FF0036" :timer="timer3" v-on:endDo="endDo(3)"></graceCountDown>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceCountDown from "../../graceUI/components/graceCountDown.vue";
var graceDate = require("../../graceUI/jsTools/date.js");
// date.js 更新于 2019-12-19 11:05 请保证此js版本更新 (:
export default {
data() {
return {
// 模拟当前时间 + 15秒
timer1 : graceDate.currentTime('str', 1000 * 15),
// 模拟 当前时间 + 15 天
timer2 : graceDate.currentTime('str', 1000 * 3600 * 24 * 15),
// 通过 api 请求获取
timer3 : ''
}
},
onLoad:function () {
// 模拟 api 请求
setTimeout(() => { this.timer3 = graceDate.currentTime('str', 1000 * 10);}, 1000);
// 演示重置倒计时时间 : 第一个倒计时时间重置
setTimeout(()=>{
this.$refs.graceCountDown1.reSetTimer(graceDate.currentTime('str', 1000 * 30));
}, 3000);
},
methods:{
endDo : function (index) {
uni.showToast({
title:"第 " + index + ' 个倒计时执行完毕 '
});
},
getTimeRemaining : function () {
var lefeTime = this.$refs.graceCountDown3.getTimeRemaining();
console.log('倒计时剩余时间 : ' + lefeTime);
}
},
components:{gracePage, graceCountDown}
}
</script>
<style>
</style>
<template>
<gracePage :customHeader="false">
<view slot="gBody" class="grace-body">
<view class="grace-margin-top">
<text class="grace-title">示例1</text>
</view>
<view class="grace-flex-center">
<graceCountDown :timer="timer1" width="38rpx" v-on:endDo="endDo(1)" ref="graceCountDown1"></graceCountDown>
</view>
<view class="grace-margin-top">
<text class="grace-title">示例2</text>
</view>
<view class="grace-flex-center" style="background-color:#3688FF; padding:30rpx;">
<graceCountDown
:timer="timer2" borderColor="#FFFFFF" splitorColor="#FFFFFF" fontColor="#FFFFFF" bgrColor="#3688FF"
:splitorText="['天', '时', '分', '秒']" v-on:endDo="endDo(2)"></graceCountDown>
</view>
<view class="grace-margin-top">
<text class="grace-title">示例3</text>
</view>
<view class="grace-flex-center" @tap="getTimeRemaining">
<graceCountDown :splitorText="['天','时','分','秒']" width="60rpx" v-if="timer3 != ''" ref="graceCountDown3"
fontColor="#FFFFFF" borderColor="#FF0036" bgrColor="#FF0036" splitorColor="#FF0036" :timer="timer3" v-on:endDo="endDo(3)"></graceCountDown>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceCountDown from "../../graceUI/weexComponents/graceCountDown.nvue";
var graceDate = require("../../graceUI/jsTools/date.js");
export default {
data() {
return {
// 模拟当前时间 + 15秒
timer1 : graceDate.currentTime('str', 1000 * 15),
// 模拟 当前时间 + 15 天
timer2 : graceDate.currentTime('str', 1000 * 3600 * 24 * 15),
// 通过 api 请求获取
timer3 : ''
}
},
onLoad:function () {
// 模拟 api 请求
setTimeout(() => { this.timer3 = graceDate.currentTime('str', 1000 * 10);}, 1000);
// 演示重置倒计时时间 : 第一个倒计时时间重置
setTimeout(()=>{
this.$refs.graceCountDown1.reSetTimer(graceDate.currentTime('str', 1000 * 30));
}, 3000);
},
methods:{
endDo : function (index) {
uni.showToast({
title:"第 " + index + ' 个倒计时执行完毕 '
})
},
getTimeRemaining : function () {
var lefeTime = this.$refs.graceCountDown3.getTimeRemaining();
console.log('倒计时剩余时间 : ' + lefeTime);
}
},
components:{gracePage, graceCountDown}
}
</script>
<style>
</style>
.wxml
<gracePage customHeader="{{false}}">
<view class="grace-body" slot="gBody">
<view class="grace-title grace-margin-top">示例1</view>
<view class="grace-flex-center">
<graceCountDown timer="{{timer1}}" width="38rpx" bind:endDo="endDo" data-index="1" id="graceCountDown1"></graceCountDown>
</view>
<view class="grace-title grace-margin-top">示例2</view>
<view class="grace-flex-center" style="background:#3688FF; padding:30rpx 0; border-radius:10rpx;">
<graceCountDown splitorText="{{['天','时','分','秒']}}" timer="{{timer2}}" borderColor="#FFFFFF"
splitorColor="#FFF" fontColor="#FFFFFF" bgrColor="none" bind:endDo="endDo" data-index="2"></graceCountDown>
</view>
<view class="grace-title grace-margin-top">示例3</view>
<view class="grace-flex-center" bindtap="getTimeRemaining">
<graceCountDown splitorText="{{['天','时','分','秒']}}" fontSize="30rpx" width="80rpx" fontColor="#FFFFFF" wx:if="{{timer3 != ''}}" id="graceCountDown3"
borderColor="#3688FF" bgrColor="#3688FF" splitorColor="#3688FF" timer="{{timer3}}" data-index="3" bind:endDo="endDo"></graceCountDown>
</view>
</view>
</gracePage>.js
var graceDate = require("../../graceUI/jsTools/date.js");
Page({
data: {
// 模拟当前时间 + 15秒
timer1: graceDate.currentTime('str', 1000 * 15),
// 模拟 当前时间 + 15 天
timer2: graceDate.currentTime('str', 1000 * 3600 * 24 * 15),
// 通过 api 请求获取
timer3: ''
},
onLoad: function () {
// 模拟 api 请求
setTimeout(() => { this.setData({ timer3: graceDate.currentTime('str', 1000 * 10) }); }, 1000);
// 演示重置倒计时时间 : 第一个倒计时时间重置
setTimeout(() => {
this.selectComponent("#graceCountDown1").reSetTimer(graceDate.currentTime('str', 1000 * 30));
}, 3000);
},
endDo: function (e) {
var index = e.currentTarget.dataset.index;
wx.showToast({
title: "第 " + index + ' 个倒计时执行完毕 '
})
},
getTimeRemaining : function(){
var lefeTime = this.selectComponent("#graceCountDown3").getTimeRemaining();
console.log('倒计时剩余时间 : ' + lefeTime);
}
});.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"graceCountDown": "../../graceUI/components/graceCountDown"
}
}