import { VantComponent } from '../common/component';
import { isDef } from '../common/utils';
import { pickerProps } from '../picker/shared';
const currentYear = new Date().getFullYear();
function isValidDate(date) {
return isDef(date) && !isNaN(new Date(date).getTime());
}
function range(num, min, max) {
return Math.min(Math.max(num, min), max);
}
function padZero(val) {
return `00${val}`.slice(-2);
}
function times(n, iteratee) {
let index = -1;
const result = Array(n < 0 ? 0 : n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
}
function getTrueValue(formattedValue) {
if (!formattedValue)
return;
while (isNaN(parseInt(formattedValue, 10))) {
formattedValue = formattedValue.slice(1);
}
return parseInt(formattedValue, 10);
}
function getMonthEndDay(year, month) {
return 32 - new Date(year, month - 1, 32).getDate();
}
const defaultFormatter = (_, value) => value;
VantComponent({
classes: ['active-class', 'toolbar-class', 'column-class'],
props: Object.assign({}, pickerProps, { formatter: {
type: Function,
value: defaultFormatter
}, value: null, type: {
type: String,
value: 'datetime'
}, showToolbar: {
type: Boolean,
value: true
}, minDate: {
type: Number,
value: new Date(currentYear - 10, 0, 1).getTime()
}, maxDate: {
type: Number,
value: new Date(currentYear + 10, 11, 31).getTime()
}, minHour: {
type: Number,
value: 0
}, maxHour: {
type: Number,
value: 23
}, minMinute: {
type: Number,
value: 0
}, maxMinute: {
type: Number,
value: 59
} }),
data: {
innerValue: Date.now(),
columns: []
},
watch: {
value: 'updateValue',
type: 'updateValue',
minDate: 'updateValue',
maxDate: 'updateValue',
minHour: 'updateValue',
maxHour: 'updateValue',
minMinute: 'updateValue',
maxMinute: 'updateValue'
},
methods: {
updateValue() {
const { data } = this;
const val = this.correctValue(this.data.value);
const isEqual = val === data.innerValue;
if (!isEqual) {
this.updateColumnValue(val).then(() => {
this.$emit('input', val);
});
}
else {
this.updateColumns();
}
},
getPicker() {
if (this.picker == null) {
this.picker = this.selectComponent('.van-datetime-picker');
const { picker } = this;
const { setColumnValues } = picker;
picker.setColumnValues = (...args) => setColumnValues.apply(picker, [...args, false]);
}
return this.picker;
},
updateColumns() {
const { formatter = defaultFormatter } = this.data;
const results = this.getRanges().map(({ type, range }) => {
const values = times(range[1] - range[0] + 1, index => {
let value = range[0] + index;
value = type === 'year' ? `${value}` : padZero(value);
return formatter(type, value);
});
return { values };
});
return this.set({ columns: results });
},
getRanges() {
const { data } = this;
if (data.type === 'time') {
return [
{
type: 'hour',
range: [data.minHour, data.maxHour]
},
{
type: 'minute',
range: [data.minMinute, data.maxMinute]
}
];
}
const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = this.getBoundary('max', data.innerValue);
const { minYear, minDate, minMonth, minHour, minMinute } = this.getBoundary('min', data.innerValue);
const result = [
{
type: 'year',
range: [minYear, maxYear]
},
{
type: 'month',
range: [minMonth, maxMonth]
},
{
type: 'day',
range: [minDate, maxDate]
},
{
type: 'hour',
range: [minHour, maxHour]
},
{
type: 'minute',
range: [minMinute, maxMinute]
}
];
if (data.type === 'date')
result.splice(3, 2);
if (data.type === 'year-month')
result.splice(2, 3);
return result;
},
correctValue(value) {
const { data } = this;
// validate value
const isDateType = data.type !== 'time';
if (isDateType && !isValidDate(value)) {
value = data.minDate;
}
else if (!isDateType && !value) {
const { minHour } = data;
value = `${padZero(minHour)}:00`;
}
// time type
if (!isDateType) {
let [hour, minute] = value.split(':');
hour = padZero(range(hour, data.minHour, data.maxHour));
minute = padZero(range(minute, data.minMinute, data.maxMinute));
return `${hour}:${minute}`;
}
// date type
value = Math.max(value, data.minDate);
value = Math.min(value, data.maxDate);
return value;
},
getBoundary(type, innerValue) {
const value = new Date(innerValue);
const boundary = new Date(this.data[`${type}Date`]);
const year = boundary.getFullYear();
let month = 1;
let date = 1;
let hour = 0;
let minute = 0;
if (type === 'max') {
month = 12;
date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1);
hour = 23;
minute = 59;
}
if (value.getFullYear() === year) {
month = boundary.getMonth() + 1;
if (value.getMonth() + 1 === month) {
date = boundary.getDate();
if (value.getDate() === date) {
hour = boundary.getHours();
if (value.getHours() === hour) {
minute = boundary.getMinutes();
}
}
}
}
return {
[`${type}Year`]: year,
[`${type}Month`]: month,
[`${type}Date`]: date,
[`${type}Hour`]: hour,
[`${type}Minute`]: minute
};
},
onCancel() {
this.$emit('cancel');
},
onConfirm() {
this.$emit('confirm', this.data.innerValue);
},
onChange() {
const { data } = this;
let value;
const picker = this.getPicker();
if (data.type === 'time') {
const indexes = picker.getIndexes();
value = `${indexes[0] + data.minHour}:${indexes[1] + data.minMinute}`;
}
else {
const values = picker.getValues();
const year = getTrueValue(values[0]);
const month = getTrueValue(values[1]);
const maxDate = getMonthEndDay(year, month);
let date = getTrueValue(values[2])
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源内项目代码都是经过测试运行成功,功能正常的情况下才上传的,请放心下载使用。 2、适用人群:主要针对计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、数学、电子信息等)的同学或企业员工下载使用,具有较高的学习借鉴价值。 3、不仅适合小白学习实战练习,也可作为大作业、课程设计、毕设项目、初期项目立项演示等,欢迎下载,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
驾校科目考试小程序完整源码.zip (406个子文件)
index.js 10KB
index.js 10KB
index.js 7KB
index.js 5KB
index.js 4KB
transition.js 4KB
index.js 3KB
index.js 3KB
index.js 3KB
index.js 3KB
index.js 3KB
index.js 3KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
toast.js 2KB
index.js 2KB
dialog.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 1KB
component.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
behavior.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
safe-area.js 1KB
index.js 1KB
index.js 1KB
app.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 999B
index.js 925B
index.js 907B
index.js 903B
index.js 890B
touch.js 889B
index.js 877B
index.js 838B
index.js 824B
notify.js 770B
index.js 738B
index.js 726B
basic.js 676B
index.js 676B
open-type.js 674B
utils.js 619B
index.js 599B
props.js 597B
index.js 554B
index.js 548B
index.js 542B
index.js 486B
util.js 472B
index.js 470B
button.js 442B
shared.js 388B
index.js 382B
index.js 375B
header.js 366B
link.js 364B
index.js 336B
index.js 334B
logs.js 261B
index.js 239B
index.js 194B
index.js 146B
index.js 140B
color.js 123B
weapp.js 0B
index.js 0B
app.json 1KB
project.config.json 964B
package-lock.json 362B
package.json 248B
index.json 207B
sitemap.json 191B
index.json 186B
index.json 158B
index.json 133B
index.json 123B
index.json 123B
index.json 121B
index.json 121B
index.json 121B
index.json 117B
共 406 条
- 1
- 2
- 3
- 4
- 5
资源评论
龙年行大运
- 粉丝: 1006
- 资源: 3852
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- java将grib2数据转为json格式
- ffmpeg安装软件.rar
- Go语言练习资源 - go-main
- 第十五届蓝桥杯省一代码
- 海信智能电视刷机数据 LED42K330X3D(0000) 生产用软件数据 务必确认机编一致 强制刷机 整机USB升级程序
- shujudaochuceshi
- learn-ruby.zip
- test111111111111111111
- 海信智能电视刷机数据 LED42K326X3D(0011) 生产用软件数据 务必确认机编一致 强制刷机 整机USB升级程序
- 这里有一份针对美国数学建模竞赛(MCM)的案例分析,涵盖了问题描述、建模过程、求解方法、结果分析以及总结反思
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功