mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-24 05:00:37 +03:00
feat: add panel-change update:showTimePanel
This commit is contained in:
@@ -16,7 +16,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
'import/extensions': ['.js', '.jsx', '.vue'],
|
'import/extensions': ['.js', '.jsx', '.vue'],
|
||||||
},
|
},
|
||||||
extends: ['airbnb-base', 'plugin:vue/recommended', 'prettier', 'prettier/vue'],
|
extends: ['airbnb-base', 'prettier', 'prettier/vue'],
|
||||||
|
|
||||||
plugins: ['vue'],
|
plugins: ['vue'],
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ export default {
|
|||||||
default: () => () => {},
|
default: () => () => {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: ['select', 'update:calendar'],
|
|
||||||
props: {
|
props: {
|
||||||
value: {},
|
value: {},
|
||||||
defaultValue: {
|
defaultValue: {
|
||||||
@@ -50,6 +49,9 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
|
getYearPanel: {
|
||||||
|
type: Function,
|
||||||
|
},
|
||||||
titleFormat: {
|
titleFormat: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'YYYY-MM-DD',
|
default: 'YYYY-MM-DD',
|
||||||
@@ -61,6 +63,7 @@ export default {
|
|||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: ['select', 'update:calendar'],
|
||||||
data() {
|
data() {
|
||||||
const panels = ['date', 'month', 'year'];
|
const panels = ['date', 'month', 'year'];
|
||||||
const index = Math.max(panels.indexOf(this.type), panels.indexOf(this.defaultPanel));
|
const index = Math.max(panels.indexOf(this.type), panels.indexOf(this.defaultPanel));
|
||||||
@@ -79,7 +82,7 @@ export default {
|
|||||||
date: startOfDay,
|
date: startOfDay,
|
||||||
};
|
};
|
||||||
const start = map[this.type] || map.date;
|
const start = map[this.type] || map.date;
|
||||||
return value.filter(isValidDate).map(v => start(v));
|
return value.filter(isValidDate).map((v) => start(v));
|
||||||
},
|
},
|
||||||
calendarYear() {
|
calendarYear() {
|
||||||
return this.innerCalendar.getFullYear();
|
return this.innerCalendar.getFullYear();
|
||||||
@@ -126,7 +129,9 @@ export default {
|
|||||||
this.dispatchDatePicker('calendar-change', calendar, oldCalendar, type);
|
this.dispatchDatePicker('calendar-change', calendar, oldCalendar, type);
|
||||||
},
|
},
|
||||||
handelPanelChange(panel) {
|
handelPanelChange(panel) {
|
||||||
|
const oldPanel = this.panel;
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
|
this.dispatchDatePicker('panel-change', panel, oldPanel);
|
||||||
},
|
},
|
||||||
handleSelectYear(year) {
|
handleSelectYear(year) {
|
||||||
if (this.type === 'year') {
|
if (this.type === 'year') {
|
||||||
@@ -202,7 +207,7 @@ export default {
|
|||||||
if (this.isDisabled(cellDate)) {
|
if (this.isDisabled(cellDate)) {
|
||||||
return 'disabled';
|
return 'disabled';
|
||||||
}
|
}
|
||||||
if (this.innerValue.some(v => v.getTime() === cellDate.getTime())) {
|
if (this.innerValue.some((v) => v.getTime() === cellDate.getTime())) {
|
||||||
return 'active';
|
return 'active';
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
@@ -211,7 +216,7 @@ export default {
|
|||||||
if (this.type !== 'week') return '';
|
if (this.type !== 'week') return '';
|
||||||
const start = row[0].getTime();
|
const start = row[0].getTime();
|
||||||
const end = row[6].getTime();
|
const end = row[6].getTime();
|
||||||
const active = this.innerValue.some(v => {
|
const active = this.innerValue.some((v) => {
|
||||||
const time = v.getTime();
|
const time = v.getTime();
|
||||||
return time >= start && time <= end;
|
return time >= start && time <= end;
|
||||||
});
|
});
|
||||||
@@ -225,6 +230,7 @@ export default {
|
|||||||
<TableYear
|
<TableYear
|
||||||
calendar={innerCalendar}
|
calendar={innerCalendar}
|
||||||
getCellClasses={this.getYearClasses}
|
getCellClasses={this.getYearClasses}
|
||||||
|
getYearPanel={this.getYearPanel}
|
||||||
onSelect={this.handleSelectYear}
|
onSelect={this.handleSelectYear}
|
||||||
onChangecalendar={this.handleCalendarChange}
|
onChangecalendar={this.handleCalendarChange}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ export default {
|
|||||||
default: 'mx',
|
default: 'mx',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: ['select'],
|
|
||||||
props: {
|
props: {
|
||||||
...CalendarPanel.props,
|
...CalendarPanel.props,
|
||||||
},
|
},
|
||||||
|
emits: ['select'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
innerValue: [],
|
innerValue: [],
|
||||||
|
|||||||
+20
-10
@@ -49,26 +49,36 @@ export default {
|
|||||||
type: Function,
|
type: Function,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
|
getYearPanel: {
|
||||||
|
type: Function,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emits: ['select', 'changecalendar'],
|
emits: ['select', 'changecalendar'],
|
||||||
computed: {
|
computed: {
|
||||||
years() {
|
years() {
|
||||||
const firstYear = Math.floor(this.calendar.getFullYear() / 10) * 10;
|
const calendar = new Date(this.calendar);
|
||||||
|
if (typeof this.getYearPanel === 'function') {
|
||||||
|
return this.getYearPanel(calendar);
|
||||||
|
}
|
||||||
|
return this.getYears(calendar);
|
||||||
|
},
|
||||||
|
firstYear() {
|
||||||
|
return this.years[0][0];
|
||||||
|
},
|
||||||
|
lastYear() {
|
||||||
|
const last = (arr) => arr[arr.length - 1];
|
||||||
|
return last(last(this.years));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getYears(calendar) {
|
||||||
|
const firstYear = Math.floor(calendar.getFullYear() / 10) * 10;
|
||||||
const years = [];
|
const years = [];
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
years.push(firstYear + i);
|
years.push(firstYear + i);
|
||||||
}
|
}
|
||||||
return chunk(years, 2);
|
return chunk(years, 2);
|
||||||
},
|
},
|
||||||
firstYear() {
|
|
||||||
return this.years[0][0];
|
|
||||||
},
|
|
||||||
lastYear() {
|
|
||||||
const last = arr => arr[arr.length - 1];
|
|
||||||
return last(last(this.years));
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
getNextCalendar(diffYear) {
|
getNextCalendar(diffYear) {
|
||||||
const year = this.calendar.getFullYear();
|
const year = this.calendar.getFullYear();
|
||||||
const month = this.calendar.getMonth();
|
const month = this.calendar.getMonth();
|
||||||
|
|||||||
+26
-2
@@ -1,6 +1,6 @@
|
|||||||
import { parse, format, getWeek } from 'date-format-parse';
|
import { parse, format, getWeek } from 'date-format-parse';
|
||||||
import { isValidDate, isValidRangeDate, isValidDates } from './util/date';
|
import { isValidDate, isValidRangeDate, isValidDates } from './util/date';
|
||||||
import { pick, isObject, mergeDeep } from './util/base';
|
import { pick, isObject, mergeDeep, capitalize } from './util/base';
|
||||||
import { getLocale } from './locale';
|
import { getLocale } from './locale';
|
||||||
import Popup from './popup';
|
import Popup from './popup';
|
||||||
import IconCalendar from './icon/icon-calendar';
|
import IconCalendar from './icon/icon-calendar';
|
||||||
@@ -133,6 +133,25 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: [
|
||||||
|
'update:modelValue',
|
||||||
|
'input',
|
||||||
|
'change',
|
||||||
|
'clear',
|
||||||
|
'confirm',
|
||||||
|
'open',
|
||||||
|
'close',
|
||||||
|
'update:open',
|
||||||
|
'blur',
|
||||||
|
'focus',
|
||||||
|
'pick',
|
||||||
|
'input-error',
|
||||||
|
'calendar-change',
|
||||||
|
'panel-change',
|
||||||
|
'inputError',
|
||||||
|
'calendarChange',
|
||||||
|
'panelChange',
|
||||||
|
],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// cache the innervalue, wait to confirm
|
// cache the innervalue, wait to confirm
|
||||||
@@ -468,9 +487,14 @@ export default {
|
|||||||
const Component = map[this.type] || map.default;
|
const Component = map[this.type] || map.default;
|
||||||
const props = {
|
const props = {
|
||||||
...pick(this.$props, Object.keys(Component.props)),
|
...pick(this.$props, Object.keys(Component.props)),
|
||||||
|
...pick(
|
||||||
|
this.$attrs,
|
||||||
|
(Component.emits || []).map((v) => `on${capitalize(v)}`)
|
||||||
|
),
|
||||||
value: this.currentValue,
|
value: this.currentValue,
|
||||||
|
onSelect: this.handleSelectDate,
|
||||||
};
|
};
|
||||||
const content = <Component {...props} onSelect={this.handleSelectDate} ref="picker" />;
|
const content = <Component {...props} ref="picker" />;
|
||||||
return (
|
return (
|
||||||
<div class={`${this.prefixClass}-datepicker-body`}>
|
<div class={`${this.prefixClass}-datepicker-body`}>
|
||||||
{this.renderSlot('content', content, {
|
{this.renderSlot('content', content, {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export default {
|
|||||||
default: 'mx',
|
default: 'mx',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: ['select'],
|
|
||||||
props: {
|
props: {
|
||||||
...CalendarPanel.props,
|
...CalendarPanel.props,
|
||||||
...TimePanel.props,
|
...TimePanel.props,
|
||||||
@@ -19,6 +18,8 @@ export default {
|
|||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: ['select', 'update:showTimePanel'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
defaultTimeVisible: false,
|
defaultTimeVisible: false,
|
||||||
@@ -34,6 +35,9 @@ export default {
|
|||||||
value(val) {
|
value(val) {
|
||||||
this.currentValue = val;
|
this.currentValue = val;
|
||||||
},
|
},
|
||||||
|
defaultTimeVisible(val) {
|
||||||
|
this.$emit('update:showTimePanel', val);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
closeTimePanel() {
|
closeTimePanel() {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export default {
|
|||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: ['select', 'update:showTimePanel'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
defaultTimeVisible: false,
|
defaultTimeVisible: false,
|
||||||
@@ -33,6 +34,9 @@ export default {
|
|||||||
value(val) {
|
value(val) {
|
||||||
this.currentValue = val;
|
this.currentValue = val;
|
||||||
},
|
},
|
||||||
|
defaultTimeVisible(val) {
|
||||||
|
this.$emit('update:showTimePanel', val);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
closeTimePanel() {
|
closeTimePanel() {
|
||||||
|
|||||||
@@ -24,14 +24,14 @@
|
|||||||
import ScrollbarVertical from '../scrollbar/scrollbar-vertical';
|
import ScrollbarVertical from '../scrollbar/scrollbar-vertical';
|
||||||
import { getScrollParent } from '../util/dom';
|
import { getScrollParent } from '../util/dom';
|
||||||
|
|
||||||
const padNumber = value => {
|
const padNumber = (value) => {
|
||||||
value = parseInt(value, 10);
|
value = parseInt(value, 10);
|
||||||
return value < 10 ? `0${value}` : `${value}`;
|
return value < 10 ? `0${value}` : `${value}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateOptions = (length, step, options) => {
|
const generateOptions = (length, step, options) => {
|
||||||
if (Array.isArray(options)) {
|
if (Array.isArray(options)) {
|
||||||
return options.filter(v => v >= 0 && v < length);
|
return options.filter((v) => v >= 0 && v < length);
|
||||||
}
|
}
|
||||||
if (step <= 0) {
|
if (step <= 0) {
|
||||||
step = 1;
|
step = 1;
|
||||||
@@ -123,7 +123,7 @@ export default {
|
|||||||
if (this.showSecond) cols.push({ type: 'second', list: this.getSecondsList() });
|
if (this.showSecond) cols.push({ type: 'second', list: this.getSecondsList() });
|
||||||
if (this.use12h) cols.push({ type: 'ampm', list: this.getAMPMList() });
|
if (this.use12h) cols.push({ type: 'ampm', list: this.getAMPMList() });
|
||||||
|
|
||||||
return cols.filter(v => v.list.length > 0);
|
return cols.filter((v) => v.list.length > 0);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@@ -140,7 +140,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getHoursList() {
|
getHoursList() {
|
||||||
return generateOptions(this.use12h ? 12 : 24, this.hourStep, this.hourOptions).map(num => {
|
return generateOptions(this.use12h ? 12 : 24, this.hourStep, this.hourOptions).map((num) => {
|
||||||
const date = new Date(this.date);
|
const date = new Date(this.date);
|
||||||
let text = padNumber(num);
|
let text = padNumber(num);
|
||||||
if (this.use12h) {
|
if (this.use12h) {
|
||||||
@@ -156,13 +156,13 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
getMinutesList() {
|
getMinutesList() {
|
||||||
return generateOptions(60, this.minuteStep, this.minuteOptions).map(num => {
|
return generateOptions(60, this.minuteStep, this.minuteOptions).map((num) => {
|
||||||
const value = new Date(this.date).setMinutes(num);
|
const value = new Date(this.date).setMinutes(num);
|
||||||
return { value, text: padNumber(num) };
|
return { value, text: padNumber(num) };
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getSecondsList() {
|
getSecondsList() {
|
||||||
return generateOptions(60, this.secondStep, this.secondOptions).map(num => {
|
return generateOptions(60, this.secondStep, this.secondOptions).map((num) => {
|
||||||
const value = new Date(this.date).setSeconds(num);
|
const value = new Date(this.date).setSeconds(num);
|
||||||
return { value, text: padNumber(num) };
|
return { value, text: padNumber(num) };
|
||||||
});
|
});
|
||||||
|
|||||||
+6
-2
@@ -37,7 +37,7 @@ export function pick(obj, props) {
|
|||||||
props = [props];
|
props = [props];
|
||||||
}
|
}
|
||||||
const res = {};
|
const res = {};
|
||||||
props.forEach(prop => {
|
props.forEach((prop) => {
|
||||||
if (prop in obj) {
|
if (prop in obj) {
|
||||||
res[prop] = obj[prop];
|
res[prop] = obj[prop];
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ export function mergeDeep(target, source) {
|
|||||||
}
|
}
|
||||||
let result = target;
|
let result = target;
|
||||||
if (isObject(source)) {
|
if (isObject(source)) {
|
||||||
Object.keys(source).forEach(key => {
|
Object.keys(source).forEach((key) => {
|
||||||
let value = source[key];
|
let value = source[key];
|
||||||
if (isObject(value) && isObject(target[key])) {
|
if (isObject(value) && isObject(target[key])) {
|
||||||
value = mergeDeep(target[key], value);
|
value = mergeDeep(target[key], value);
|
||||||
@@ -66,3 +66,7 @@ export function mergeDeep(target, source) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function capitalize(str) {
|
||||||
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user