手册版本 V3.0
组件名称
graceDateTime : /graceUI/组件目录/graceDateTime
功能介绍
graceDateTime 组件以 picker-view 形式来实现日期时间的选择工作,具备以下特色 :
1. 展示、关闭变量封装在组件内,不需要开发者实现,调用更方便;
2. 自动识别对应年份对应月份应有的天数(如 : 自动计算某年2月份应用的天数);
组件属性
| 属性名称 | 类型 | 默认值 | 作用 |
| background | String | rgba(0, 0, 0, 0.5) | 遮罩层背景颜色 |
| cancelText | String | 取消 | 取消按钮文本 |
| cancelTColor | String | #888888 | 取消按钮文颜色 |
| confirmText | String | 确定 | 确认按钮文本 |
| confirmColor | String | #3688FF | 确认按钮文本颜色 |
| value | String | '' | 默认时间值,格式 xxxx-xx-xx HH:ii:ss,默认当前时间 |
| isTime | Boolean
| true | 是否展示时间没有 |
| isSecond | Boolean | true | 是否展示秒选择器 |
| startYear | Number | 1980 | 起始年份 |
| endYear | Number | 2050 | 结束年份 |
| units | Array | Array('年','月','日','时','分','秒') | 日期时间单位信息 |
| height | String | 300rpx | 组件高度 |
| paddingBottom | String | 0rpx | 底部内间距,当您的页面有其他底部元素时请使用此属性避开 |
会触发的事件
01 change
客户滑动组件切换时间信息时触发,可用于监测选择变化;
02 confirm
客户点击确认按钮后触发,可以记录最终选择的时间;
返回值说明:
change和confirm事件均会携带日期时间信息,格式 : [年,月,日,时,分,秒].
利用这个返回数值您可以灵活的组合出各种您需要的时间格式;
修改默认值
01 使用 value 属性;
02 使用组件的 setValue 函数可以动态改变组件的默认值;
组件插槽
请将选择结果展示在组件插槽内( 插槽内您可以灵活地进行样式及内容的布置 );
演示代码
UNI 普通版本
NVUE 版本
微信小程序独立版本
<template>
<gracePage headerBG="#FFFFFF" :customHeader="false">
<view slot="gBody" class="grace-body">
<view class="grace-title grace-margin-top">默认属性</view>
<view class="grace-margin-top">
<graceDateTime @confirm="confirm1" :value="demo1Val" @change="chang1">
<text class="demo grace-border-radius">{{demo1Val}}<text class="grace-icons icon-date icon-left-margin"></text></text>
</graceDateTime>
</view>
<view class="grace-title grace-margin-top">只有日期</view>
<view class="grace-margin-top">
<graceDateTime @confirm="confirm2" :value="demo2Val" :isTime="false">
<text class="demo grace-border-radius">{{demo2Val}}<text class="grace-icons icon-date icon-left-margin"></text></text>
</graceDateTime>
</view>
<view class="grace-title grace-margin-top">默认设置</view>
<view class="grace-margin-top">
<graceDateTime @confirm="confirm3" :value="demo3Val">
<text class="demo grace-border-radius">{{demo3Val}}<text class="grace-icons icon-date icon-left-margin"></text></text>
</graceDateTime>
</view>
<view class="grace-title grace-margin-top">延迟设置</view>
<view class="grace-margin-top">
<graceDateTime @confirm="confirm4" :value="demo4Val" ref="graceDateTime4">
<text class="demo grace-border-radius">{{demo4Val}}<text class="grace-icons icon-date icon-left-margin"></text></text>
</graceDateTime>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceDateTime from "../../graceUI/components/graceDateTime.vue";
export default {
data() {
return {
demo1Val:"请选择具体时间",
demo2Val:"请选择具体日期",
demo3Val:"2020-02-18 18:18:18",
demo4Val:"请选择具体时间"
};
},
onLoad:function(){
// 模拟 api 请求
setTimeout(()=>{
this.demo4Val = "2018-08-18 18:18:18";
// 调用组件到 setVal 函数来设置组件到默认时间
this.$refs.graceDateTime4.setValue('2018-08-18 18:18:18');
},2000);
},
methods:{
chang1:function (e) {
console.log(e);
},
confirm1:function (res) {
this.demo1Val = res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5];
},
confirm2:function (res) {
this.demo2Val = res[0]+'-'+res[1]+'-'+res[2];
},
confirm3:function (res) {
this.demo3Val = res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5];
},
confirm4:function (res) {
this.demo4Val = res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5];
}
},
components:{gracePage, graceDateTime}
}
</script>
<style>
.demo{display:block; width:388rpx; line-height:66rpx; background-color:#3688FF; color:#FFFFFF; font-size:28rpx; text-align:center;}
</style>
<template>
<gracePage headerBG="#FFFFFF" :customHeader="false">
<view slot="gBody" class="grace-body">
<text class="grace-title grace-margin-top">默认属性</text>
<view class="grace-margin-top">
<graceDateTime @confirm="confirm1" :value="demo1Val" @change="change1">
<text class="demo grace-border-radius grace-icons">{{demo1Val}} </text>
</graceDateTime>
</view>
<text class="grace-title grace-margin-top">只有日期</text>
<view class="grace-margin-top">
<graceDateTime @confirm="confirm2" :value="demo2Val" :isTime="false">
<text class="demo grace-border-radius grace-icons">{{demo2Val}} </text>
</graceDateTime>
</view>
<text class="grace-title grace-margin-top">默认设置</text>
<view class="grace-margin-top">
<graceDateTime @confirm="confirm3" :value="demo3Val">
<text class="demo grace-border-radius grace-icons">{{demo3Val}} </text>
</graceDateTime>
</view>
<text class="grace-title grace-margin-top">延迟设置</text>
<view class="grace-margin-top">
<graceDateTime @confirm="confirm4" :value="demo4Val" ref="graceDateTime4">
<text class="demo grace-border-radius grace-icons">{{demo4Val}} </text>
</graceDateTime>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceDateTime from "../../graceUI/weexComponents/graceDateTime.nvue";
export default {
data() {
return {
demo1Val:"请选择具体时间",
demo2Val:"请选择具体日期",
demo3Val:"2020-02-18 18:18:18",
demo4Val:"请选择具体时间"
};
},
onLoad:function(){
// 模拟 api 请求
setTimeout(()=>{
this.demo4Val = "2018-08-18 18:18:18";
// 调用组件到 setVal 函数来设置组件到默认时间
this.$refs.graceDateTime4.setValue('2018-08-18 18:18:18');
},2000);
},
methods:{
change1:function (e) {
console.log(e);
},
confirm1:function (res) {
this.demo1Val = res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5];
},
confirm2:function (res) {
this.demo2Val = res[0]+'-'+res[1]+'-'+res[2];
},
confirm3:function (res) {
this.demo3Val = res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5];
},
confirm4:function (res) {
this.demo4Val = res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5];
}
},
components:{gracePage, graceDateTime}
}
</script>
<style>
.demo{line-height:66rpx; background-color:#3688FF; width:388rpx; color:#FFFFFF; font-size:28rpx; text-align:center;}
</style>
.wxml
<gracePage customHeader="{{false}}">
<view slot="gBody" class="grace-body">
<view class="grace-title grace-margin-top">默认属性</view>
<view class="grace-margin-top">
<graceDateTime bind:confirm="confirm1" value="{{demo1Val}}" bind:change="chang1">
<text class="demo grace-border-radius">{{demo1Val}}<text class="grace-icons icon-date icon-left-margin"></text></text>
</graceDateTime>
</view>
<view class="grace-title grace-margin-top">只有日期</view>
<view class="grace-margin-top">
<graceDateTime bind:confirm="confirm2" value="{{demo2Val}}" isTime="{{false}}">
<text class="demo grace-border-radius">{{demo2Val}}<text class="grace-icons icon-date icon-left-margin"></text></text>
</graceDateTime>
</view>
<view class="grace-title grace-margin-top">默认设置</view>
<view class="grace-margin-top">
<graceDateTime bind:confirm="confirm3" value="{{demo3Val}}">
<text class="demo grace-border-radius">{{demo3Val}}<text class="grace-icons icon-date icon-left-margin"></text></text>
</graceDateTime>
</view>
<view class="grace-title grace-margin-top">延迟设置</view>
<view class="grace-margin-top">
<graceDateTime bind:confirm="confirm4" value="{{demo4Val}}" id="graceDateTime4">
<text class="demo grace-border-radius">{{demo4Val}}<text class="grace-icons icon-date icon-left-margin"></text></text>
</graceDateTime>
</view>
</view>
</gracePage>.js
Page({
data: {
demo1Val:"请选择具体时间",
demo2Val:"请选择具体日期",
demo3Val:"2020-02-18 18:18:18",
demo4Val:"请选择具体时间"
},
onReady:function(){
// 模拟 api 请求
setTimeout(()=>{
this.setData({demo4Val : "2018-08-18 18:18:18"});
// 调用组件到 setVal 函数来设置组件到默认时间
this.selectComponent("#graceDateTime4").setValue('2018-08-18 18:18:18');
},2000);
},
chang1:function (e) {
console.log(e.detail);
},
confirm1:function (res) {
res = res.detail;
this.setData({demo1Val : res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5]});
},
confirm2:function (res) {
res = res.detail;
this.setData({demo2Val : res[0]+'-'+res[1]+'-'+res[2]});
},
confirm3:function (res) {
res = res.detail;
this.setData({demo3Val : res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5]});
},
confirm4:function (res) {
res = res.detail;
this.setData({demo4Val : res[0]+'-'+res[1]+'-'+res[2]+' '+res[3]+':'+res[4]+':'+res[5]});
}
});.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"graceDateTime": "../../graceUI/components/graceDateTime"
}
}.wxss
.demo{display:block; width:388rpx; line-height:66rpx; background-color:#3688FF; color:#FFFFFF; font-size:28rpx; text-align:center;}