当前位置:网站首页>APICloud AVM wraps date and time selection components
APICloud AVM wraps date and time selection components
2022-08-08 16:35:00 【InfoQ】

datePicker
<template>
<picker class="picker" id={pickerId} mode="multiSelector" range-key="name" value={dateMltiSelectorValue} onchange={this.dateMultiSelectorChange} oncolumnchange={this.dateMultiSelectorColumnChange}>
<text class="picker-label">{dateDesc}</text>
</picker>
</template>
<script>
export default {
name: 'datePicker',
props:{
label:String,
pickerId:String
},
installed(){
this.getYears();
this.initDateData();
},
data() {
return{
year:[],
month:[1,2,3,4,5,6,7,8,9,10,11,12],
day:[],
yearNow:new Date().getFullYear(),
dateMltiSelectorValue:[0,0,0],
selectYear:new Date().getFullYear(),
selectMoth:1,
selectDay:1,
dateList:[],
dateDesc:''
}
},
methods: {
getYears(){
this.data.year=[];//When a page is used multiple times must be cleared first 否则会出现各种问题
for(i=0;i<100;i++){
this.data.year.push(this.yearNow-i);
}
},
initDateData(){
//Get the number of days in the current month based on the current year and month
this.data.day=[];
var days = new Date(new Date().getFullYear(), new Date().getMonth()+1, 0).getDate();
console.log(days);
for(i=1;i<=days;i++){
this.data.day.push(i);
}
this.data.dateMltiSelectorValue=[0,new Date().getMonth(),new Date().getDate()-1];
this.data.dateList = [this.data.year,this.data.month,this.data.day];
var picker = document.getElementById(this.props.pickerId);
picker.setData({
data: this.data.dateList
});
},
//根据年月获取天数
setDays(){
this.data.day=[];
var days = new Date(this.data.selectYear, this.data.selectMoth, 0).getDate();
for(i=1;i<=days;i++){
this.data.day.push(i);
}
this.data.dateList = [this.data.year,this.data.month,this.data.day];
var picker = document.getElementById(this.props.pickerId);
picker.setData({
data: this.data.dateList
});
},
dateMultiSelectorChange(e){
this.data.dateMltiSelectorValue=[e.detail.value[0],e.detail.value[1],e.detail.value[2]];
var year = this.data.year[e.detail.value[0]];
// var month = this.data.selectMoth>9?this.data.selectMoth:'0'+this.data.selectMoth;
var month = this.data.month[e.detail.value[1]]>9?this.data.month[e.detail.value[1]]:'0'+this.data.month[e.detail.value[1]];
var day = this.data.day[e.detail.value[2]]>9?this.data.day[e.detail.value[2]]:'0'+this.data.day[e.detail.value[2]];
this.data.dateDesc = year+'-'+month+'-'+day;
this.fire('setDate', this.data.dateDesc);
},
dateMultiSelectorColumnChange(e){
var column = e.detail.column;
if (column == this.data.dateList.length-1) {
return;
}
if(column==0){
this.data.selectYear = this.data.year[e.detail.value];
this.data.dateMltiSelectorValue[0]=e.detail.value;
this.setDays();
}
else if(column==1){
this.data.selectMoth = this.data.month[e.detail.value];
this.data.dateMltiSelectorValue[1]=e.detail.value;
this.setDays();
}
}
}
}
</script>
<style>
.picker {
background-color: #ffffff;
}
.picker-label{
font-size: 18px;
}
</style>
timePicker
<template>
<picker class="picker" id={pickerId} mode="multiSelector" range-key="name" value={timeMltiSelectorValue} onchange={this.timeMultiSelectorChange}>
<text class="picker-label">{timeDesc}</text>
</picker>
</template>
<script>
export default {
name: 'timePicker',
props:{
label:String,
pickerId:String
},
installed(){
this.setHours();
this.setMinutes();
this.initDateData();
},
data() {
return{
hour:[],
minute:[],
second:[],
timeList:[],
timeMltiSelectorValue:[0,0,0],
timeDesc:''
}
},
methods: {
setHours(){
for (let index = 0; index < 24; index++) {
this.data.hour.push(index>9?index:'0'+index);
}
},
setMinutes(){
for (let index = 0; index < 60; index++) {
this.data.minute.push(index>9?index:'0'+index);
this.data.second.push(index>9?index:'0'+index);
}
},
initDateData(){
//Initialize to set the current time
this.data.timeMltiSelectorValue=[new Date().getHours(),new Date().getMinutes(),new Date().getSeconds()];
this.data.timeList=[this.data.hour,this.data.minute,this.data.second];
var picker = document.getElementById(this.props.pickerId);
picker.setData({
data: this.data.timeList
});
},
timeMultiSelectorChange(e){
this.data.timeMltiSelectorValue=[e.detail.value[0],e.detail.value[1],e.detail.value[2]];
var hour = this.data.hour[e.detail.value[0]];
var minute = this.data.minute[e.detail.value[1]];
var second = this.data.second[e.detail.value[2]];
this.data.timeDesc = hour+':'+minute+':'+second;
this.fire('setDate', this.data.timeDesc);
},
}
}
</script>
<style>
.picker {
background-color: #ffffff;
}
.picker-label{
font-size: 18px;
}
</style>
组件使用
<template>
<scroll-view class="page">
<safe-area></safe-area>
<view class="item">
<text class="item-label">Agenda theme</text>
<input class="item-input" placeholder="输入Agenda theme" v-model="title"/>
</view>
<view class="item">
<text class="item-label">Brief schedule</text>
<textarea class="item-area" placeholder="Enter a brief description of the agenda" v-model="content"/>
</view>
<view class="item">
<text class="item-label">日期</text>
<datePicker onsetDate="setDate" label="" pickerId="datePicker"></datePicker>
</view>
<view class="item">
<text class="item-label">时间</text>
<timePicker onsetDate="setTime" label="" pickerId="timePicker"></timePicker>
</view>
<view class="item">
<text class="item-label">人员</text>
<input class="item-input" placeholder="请选择人员" v-model="title"/>
</view>
<view class="bt-box">
<button class="bt" onclick={this.btnAction}>保存</button>
</view>
</scroll-view>
</template>
<script>
import '../../components/datePicker.stml'
import '../../components/timePicker.stml'
export default {
name: 'adddaily',
apiready(){
},
data() {
return{
date:'',
time:'',
title:'',
content:'',
users:''
}
},
methods: {
setDate(e){
this.data.date = e.detail;
},
setTime(e){
this.data.time = e.detail;
}
}
}
</script>
<style>
.page {
height: 100%;
background-color: #ffffff;
}
.item{
margin: 10px;
border-bottom: 1px solid #ccc;
}
.item-label{
font-size: 13px;
color: #666666;
}
.item-input{
width: auto;
border: 0;
}
.item-area{
border: 0;
height: 50px;
width: auto;
}
.bt-box{
margin: 10px;
}
.bt{
color: #ffffff;
font-size: 18px;
background-color: #035dff;
border-radius: 10px;
}
</style>
效果图


边栏推荐
猜你喜欢
【uniapp小程序】视图容器cover-view
用于视觉语言导航的自监督三维语义表示学习
IDEA2020安装教程
Grid 布局介绍
redis介绍&命令&性能相关&缓存穿透
国内部分手机游戏开始显示用户IP属地
它们不一样!透析【观察者模式】和【发布订阅模式】
Patience sorting - specializing in quickly solving the longest increasing subarray
ImportError: numpy.core.multiarray failed to import [cv2, matplotlib, PyTorch, pyinstaller ]
jupyter notebook hide & show all output
随机推荐
Go 语言 Strconv 库常用方法
找工作的我看了国聘app
R语言(数值、列表、矩阵)上应用函数(sqrt、round、mean、log)、将矩阵所有数据求对数、就矩阵整体的均值、使用apply函数计算矩阵matrix的行均值、列均值、trim设置返回结果精度
synchronized加载static关键字前和普通方法前的区别?
最高法院关于婚姻案件诉讼程序的一些解答
李沐:机器学习者进阶学习建议
mysql 索引和 pgsql 索引 命名区别
iNFTnews | Metaverse brings new ideas for enterprise development
iNFTnews | 元宇宙为企业发展带来新思路
ESP8266-Arduino编程实例-ADS1015(ADC)驱动
laravel - query builder 2
ctfshow七夕杯复现
正则什么的,你让我写,我会难受,你让我用,真香!
egg(二十):fs读取本地的txt文件
Digital image processing (6) -- image compression
二、pytest+selenium+allure实现web ui自动化
MySQL数据库的简介及select语句的执行流程
基于FTP协议的Excel文件上传与下载
10分钟快速入门RDS【华为云至简致远】
mmdetection最新版食用教程(一):安装并运行demo及开始训练coco