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 === undefined) {
formattedValue = '1';
}
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 = (type, value) => value;
VantComponent({
classes: ['active-class', 'toolbar-class', 'column-class'],
props: Object.assign(Object.assign({}, pickerProps), {
value: {
type: null,
observer: 'updateValue',
},
filter: null,
type: {
type: String,
value: 'datetime',
observer: 'updateValue',
},
showToolbar: {
type: Boolean,
value: true,
},
formatter: {
type: null,
value: defaultFormatter,
},
minDate: {
type: Number,
value: new Date(currentYear - 10, 0, 1).getTime(),
observer: 'updateValue',
},
maxDate: {
type: Number,
value: new Date(currentYear + 10, 11, 31).getTime(),
observer: 'updateValue',
},
minHour: {
type: Number,
value: 0,
observer: 'updateValue',
},
maxHour: {
type: Number,
value: 23,
observer: 'updateValue',
},
minMinute: {
type: Number,
value: 0,
observer: 'updateValue',
},
maxMinute: {
type: Number,
value: 59,
observer: 'updateValue',
},
}),
data: {
innerValue: Date.now(),
columns: [],
},
methods: {
updateValue() {
const { data } = this;
const val = this.correctValue(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.getOriginColumns().map((column) => ({
values: column.values.map((value) => formatter(column.type, value)),
}));
return this.set({ columns: results });
},
getOriginColumns() {
const { filter } = this.data;
const results = this.getRanges().map(({ type, range }) => {
let values = times(range[1] - range[0] + 1, (index) => {
let value = range[0] + index;
value = type === 'year' ? `${value}` : padZero(value);
return value;
});
if (filter) {
values = filter(type, values);
}
return { type, values };
});
return 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();
const originColumns = this.getOriginColumns();
if (data.type === 'time') {
const indexes = picker.getIndexes();
value = `${+originColumns[0].values[indexes[0]]}:${+originColumns[1]
.values[indexes[1]]}`;
} else {
const indexes = picker.getIndexes();
const values = indexes.map(
(value, index) => originColumns[index].values[value]
);
const year = getTrueValue(values[0]);
const month = getTrueValue(values[1]);
const maxDate = getMonthEndDay(year, month);
let date = getTrueValue(values[2]);
if (data.type === 'year-month') {
date = 1;
}
date = date > maxDate ? maxDate : date;
let hour = 0;
let minute = 0;
if (data.type === 'datetime') {
hour = getTrueValue(values[3]);
minute = getTrueValue(values[4]);
}
value = new Date(year, month - 1, date, hour, minute);
}
value = this.correctValue(value);
this.updateColumnValue(value).then(() => {
this.$emit('input', value);
this.$emit('change', picker);
});
},
updateColumnValue(value) {
let values = [];
const { type } = this.data
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
会议室预订预约小程序,前后台源码 (1185个子文件)
0013057ff84345b6fdc433dea81c6280efd699 153B
0041f001616e80f2a800bf94b6c24bdba815b4 341B
006c692fda9d261cc1d40a02576ac03a50d3cc 162B
0089cd5dc6395ff8355fa52550af2427c8dbe7 105B
00aeb25b0ef0afed327f6231218dc738762d9b 134B
00cc0a7751570159a79f24325ac8d40beaa89a 678B
0122b3fa6b73ddedcc432ec0f2e847b74a7ac1 136B
01d2abc5019420a4902067a82cac0527fb0cd5 337B
025b306fbd9a1fc8121c3fee674542a281ec0c 188B
02add20b581be471b8d17f887b8e8337070546 194B
030ec7f8b16e5db24bb17cee6b67558de921a0 119B
0313fbcc704a275dbc0b33e3efb3ea351172d2 37B
03cd78ab6c1d887d5db1585a71f3ce45319eac 421B
03ebfaa06b9f42f16a5f003b2f8bfa1dde52c3 549B
04be10f07bb4614ede2e80d3935191635d3831 345B
04dd412ac38058a99cf37ea76830e5f0f27b24 52B
05106e07984cde1d25a33a548370531370503a 57B
0543016487ae7ca94bca1aa81d1a3b88813c67 218B
0558aa397f74f9c14a634db77299110bb81c81 408B
06096d7782f947759d00efbd9f5a66227cbe14 134B
06c5048acd40f797098314747f67ef4e5107db 97B
06e1677070434f2bd7d07cffb36e1365d5e476 116B
0737b11de84351b30da4c6c1b59c6594e8985f 813B
077f5dafe4ea3780999933518963b8b6551d8d 85B
0807034582a676cb312b776e7e7f816d37ca8f 142B
085e2f3ad20076acc6e64a906ebefa8a15fda3 979B
0943198aa1463e365e9c7927d2b31399f9ddb9 232B
09aa60e0f4a23d833c329e8614d4fc6edc4c48 643B
0a588702da8887bbe5f8261aea5764251d14ff 100B
0ad0c13afaf5a16b7743d004a9c7f993c0dbcb 141B
0b471df92a41a2110e7481263f539a5d69430d 148B
0b4af1f92c8bfbe5b972bf24f2cc262151a81f 133B
0bc133461bf8aaef8dd8e2a7bbe6a656969626 211B
0bd9e19caa2a617e0f05d9495905f586a983c9 86B
0c6c3234617aefeb99ca3cf32b9dabaeacd361 208B
0ce30d21372b73059528875bbf3cfa8b9e6c79 338B
0d1ba85dc2e3798930412b8a9e6ee9f27dfedb 311B
0e021f6c341f35af67fe1cabc0e0350f0287b2 78B
0e6f1f1177a9a39a324ae314b7c75de5118065 688B
0e73620093aaaaeaf103de7d8b4e187325f406 786B
0eb238c129ecf59f5b3ccf7deb3a87d4b604c8 2KB
0ebe009c3904229ff4005710f4136b55cf57aa 81B
0f0dba8c5d8a041e56f4666f13593935bdda33 137B
0f4627bc8bfeea6e2bb41ee5a4be7b15b7f9be 134B
0ff5c3b541f646105198ee23ac0fc3d805023e 27B
1100c3fc9abf9f52ae952a4cd20dc224a7dad5 48B
11335e326bb7bc2eba64792da749c3308ef20e 350B
12348b0896c2cc5f208082d04eddd2066793c1 169B
123524f492969f82f270988cc5c0ddbb165990 956B
123d1da2c7548c01a195557ab3e1824fa10498 350B
12b1b408fed1cad28459b80d928b6feb32acf3 400B
12cedb0c53977f8dacdb834b20ab66b7e406f1 469B
12dfc9d0c753a416e9ee91d613c9903006b838 171B
1339f75c5d357175e3f25ebd094896d2f6311f 581B
135d23daa06e22df8ccbac0786044efd2fe0ea 245B
136a2bd41ae3b24030db554df1d8a922cceb5c 579B
13bc9ad225701a813eb8ad97f4c15d67465a6a 965B
1429139c20facaad8dc9acbf31606297326cfc 369B
142fc6382ffd173e1711e73760700eddde96b4 199B
152709db7ca52744270fff39cfdf819af51847 183B
152a8250d37907d52016b2866dd110678de196 189B
15742e44f85a5b60a1645eabb7fb5ea45ed9b8 195B
1703f0530a799e0b5f28a6868e4d698b7d15da 108B
173e4a0de699496f5a9745bfdd8161d0a5f02e 619B
17407692d20b91dbe066e7e198db5e93ae474a 82B
18bf283aaa89a61c58147ef831b816b09520f1 185B
18deb85c2603893653d0256ae87e494fc9e8d1 468B
18fc4428e2e355e5d6aec4ad6157a24908ab8a 186B
191635a842ac3246314f0f76380f2f449a75d7 939B
195697d69acc624250793feb0e0d101cae7b72 216B
19d7cb71ae126cf3b5ba060af26a0d01042058 132B
1a35c9b3f1ff4d8ba4986eb80df53f9e67993b 750B
1a5995810a30a1ba04a92fcd830d1b79b32ee6 813B
1a5ee5738e5ed97a8415d0b689aa48284a2a7e 2KB
1a68d63179f3d740e6bf241455709ea98f2a34 316B
1a73012e400ba496c609e58be7617492c09458 260B
1aab7b912bc49453413e93ccd496f33630b8ae 766B
1ad9fc4bf877baa657d47567da5e28a6dd8792 163B
1ae67df983342491c9b90ef477cbdae45a5533 461B
1b78c4aa37d522149a65979bb4f4786ecbf2ed 126B
1c081b901561df6e1c206bd4f6a32a1be380da 2KB
1dae7a0f881d0978daae945a78e1968846191c 163B
1db875930c7926639ca56610fbeb66ce84e639 53B
1df16401470a5c9d3bf7b31be8efdad14e8102 85B
1df200c30b82d9767132e6b42a7a84d196305c 412B
1e3ef20449bb3264689c183b1804092debf968 310B
1e64c5e2e4f5fb42b3b31c9f7588902d3c47ed 892B
1eeaba66449e2369e87aec87762fcf76acc9bc 375B
1fa7c94469321fecf80bfaf1029e3dbdf46d37 167B
204b69df0f29095c81235820e69b18c2519686 143B
20acd1da0071f10e4f4511914afea919f1929e 434B
2172e568c0e3d42abef62b20a67583d8156d7b 163B
219d9cb26661b5a07aa2d58fdcdcaa7c4c0ae3 248B
21e6d9266d3e3036d17f28ce6490d2049ff4fb 449B
2289bfac362de3db991c6929d26b28be05f0f1 931B
230f83b03e65845674a44f7bb21f667453aca0 108B
2379c4f3fd8796794dc668b807687c9716c1a0 219B
2406232edf646c2f46b4270ce8bd72926fe807 160B
242b82f5863d01b4887fa8a8ab29ec7686575b 811B
247d5d81acaf35e41a90a4c959f6e48738de1f 700B
共 1185 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
qq_38289553
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- mongodb数据库基本操作.pdf
- C#,布尔可满足性问题(Boolean Satisfiability Problem)算法与源代码
- C#,回文分割问题(Palindrome Partitioning Problem)算法与源代码
- C#,煎饼排序问题(Pancake Sorting Problem)算法与源代码
- C#,排列组合的堆生成法(Heap’s Algorithm for generating permutations)算法与源代码
- C#,老鼠迷宫问题的回溯法求解(Rat in a Maze)算法与源代码
- 6693eeb8d683458a07938615fba9e68f.apk
- C#,数值计算,解微分方程的龙格-库塔二阶方法与源代码
- C#,数值计算,用割线法(Secant Method)求方程根的算法与源代码
- C#,子集和问题(Subset Sum Problem)的算法与源代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论3