update DatePicker
update DatePicker
This commit is contained in:
parent
f92ef70f46
commit
7c5ccdab4d
3 changed files with 73 additions and 27 deletions
|
@ -73,8 +73,11 @@
|
|||
});
|
||||
}
|
||||
},
|
||||
cells (cells) {
|
||||
this.readCells = cells;
|
||||
cells: {
|
||||
handler (cells) {
|
||||
this.readCells = cells;
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
|
|
@ -248,21 +248,47 @@
|
|||
const value = event.target.value;
|
||||
|
||||
let correctValue = '';
|
||||
const format = this.format || DEFAULT_FORMATS[this.type];
|
||||
const parsedDate = parseDate(value, format);
|
||||
let correctDate = '';
|
||||
const type = this.type;
|
||||
const format = this.format || DEFAULT_FORMATS[type];
|
||||
|
||||
if (parsedDate instanceof Date) {
|
||||
const options = this.options;
|
||||
if (options.disabledDate && typeof options.disabledDate === 'function' && options.disabledDate(new Date(parsedDate))) {
|
||||
correctValue = oldValue;
|
||||
if (type === 'daterange' || type === 'timerange' || type === 'datetimerange') {
|
||||
const parser = (
|
||||
TYPE_VALUE_RESOLVER_MAP[type] ||
|
||||
TYPE_VALUE_RESOLVER_MAP['default']
|
||||
).parser;
|
||||
|
||||
const formatter = (
|
||||
TYPE_VALUE_RESOLVER_MAP[type] ||
|
||||
TYPE_VALUE_RESOLVER_MAP['default']
|
||||
).formatter;
|
||||
|
||||
const parsedValue = parser(value, format);
|
||||
|
||||
if (parsedValue) {
|
||||
// todo 判断disabledDate
|
||||
correctValue = formatter(parsedValue, format);
|
||||
} else {
|
||||
correctValue = formatDate(parsedDate, format);
|
||||
correctValue = oldValue;
|
||||
}
|
||||
} else {
|
||||
correctValue = oldValue;
|
||||
}
|
||||
|
||||
const correctDate = parseDate(correctValue, format);
|
||||
correctDate = parsedValue;
|
||||
} else {
|
||||
const parsedDate = parseDate(value, format);
|
||||
|
||||
if (parsedDate instanceof Date) {
|
||||
const options = this.options;
|
||||
if (options.disabledDate && typeof options.disabledDate === 'function' && options.disabledDate(new Date(parsedDate))) {
|
||||
correctValue = oldValue;
|
||||
} else {
|
||||
correctValue = formatDate(parsedDate, format);
|
||||
}
|
||||
} else {
|
||||
correctValue = oldValue;
|
||||
}
|
||||
|
||||
correctDate = parseDate(correctValue, format);
|
||||
}
|
||||
|
||||
this.visualValue = correctValue;
|
||||
event.target.value = correctValue;
|
||||
|
|
|
@ -17,10 +17,12 @@
|
|||
<i-col span="8">
|
||||
<date-picker
|
||||
type="daterange"
|
||||
style="width:200px"
|
||||
style="width:300px"
|
||||
placeholder="请选择日期"
|
||||
:value.sync="value2"
|
||||
align="right"
|
||||
:editable="true"
|
||||
:format="format"
|
||||
:options="options2"></date-picker>
|
||||
</i-col>
|
||||
</row>
|
||||
|
@ -34,37 +36,52 @@
|
|||
value: '2016-12-25',
|
||||
value2: ['2016-12-17', '2017-01-05'],
|
||||
options2: {
|
||||
// disabledDate(time) {
|
||||
//// console.log(time)
|
||||
//// return time.getFullYear() < 2016;
|
||||
//// return time.getTime() < Date.now() - 8.64e7;
|
||||
//// return time && time.valueOf() < Date.now();
|
||||
// if (time.getDate() === 22 || time.getDate() === 23) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// },
|
||||
shortcuts: [
|
||||
{
|
||||
text: '今天',
|
||||
text: '最近一周',
|
||||
value () {
|
||||
// return new Date();
|
||||
return '1/2/19'
|
||||
const end = new Date();
|
||||
const start = new Date();
|
||||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
|
||||
return [start, end];
|
||||
},
|
||||
onClick (picker) {
|
||||
console.log('点击了今天');
|
||||
console.log('点击了最近一周');
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '昨天',
|
||||
text: '最近一个月',
|
||||
value () {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() - 3600 * 1000 * 24);
|
||||
return date;
|
||||
const end = new Date();
|
||||
const start = new Date();
|
||||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
|
||||
return [start, end];
|
||||
},
|
||||
onClick () {
|
||||
console.log('点击了昨天');
|
||||
console.log('点击了最近一个月');
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '最近三个月',
|
||||
value () {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
|
||||
return date;
|
||||
const end = new Date();
|
||||
const start = new Date();
|
||||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
|
||||
return [start, end];
|
||||
},
|
||||
onClick () {
|
||||
console.log('点击了一周前');
|
||||
console.log('点击了最近三个月');
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Reference in a new issue