|
|
@ -2,10 +2,8 @@ |
|
|
|
<view class="uni-date"> |
|
|
|
<view class="uni-date-editor" @click="show"> |
|
|
|
<slot> |
|
|
|
<view |
|
|
|
class="uni-date-editor--x" |
|
|
|
:class="{'uni-date-editor--x__disabled': disabled,'uni-date-x--border': border}" |
|
|
|
> |
|
|
|
<view class="uni-date-editor--x" |
|
|
|
:class="{'uni-date-editor--x__disabled': disabled,'uni-date-x--border': border}"> |
|
|
|
<view v-if="!isRange" class="uni-date-x uni-date-single"> |
|
|
|
<uni-icons class="icon-calendar" type="calendar" color="#c0c4cc" size="22"></uni-icons> |
|
|
|
<view class="uni-date__x-input">{{ displayValue || singlePlaceholderText }}</view> |
|
|
@ -13,11 +11,15 @@ |
|
|
|
|
|
|
|
<view v-else class="uni-date-x uni-date-range"> |
|
|
|
<uni-icons class="icon-calendar" type="calendar" color="#c0c4cc" size="22"></uni-icons> |
|
|
|
<view class="uni-date__x-input text-center">{{ displayRangeValue.startDate || startPlaceholderText }}</view> |
|
|
|
<view class="uni-date__x-input text-center"> |
|
|
|
{{ displayRangeValue.startDate || startPlaceholderText }} |
|
|
|
</view> |
|
|
|
|
|
|
|
<view class="range-separator">{{rangeSeparator}}</view> |
|
|
|
|
|
|
|
<view class="uni-date__x-input text-center">{{ displayRangeValue.endDate || endPlaceholderText }}</view> |
|
|
|
<view class="uni-date__x-input text-center"> |
|
|
|
{{ displayRangeValue.endDate || endPlaceholderText }} |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
|
|
|
|
<view v-if="showClearIcon" class="uni-date__icon-clear" @click.stop="clear"> |
|
|
@ -38,16 +40,16 @@ |
|
|
|
:placeholder="selectDateText" /> |
|
|
|
|
|
|
|
<time-picker type="time" v-model="pickerTime" :border="false" :disabled="!inputDate" |
|
|
|
:start="timepickerStartTime" :end="timepickerEndTime" :hideSecond="hideSecond" style="width: 100%;"> |
|
|
|
<input class="uni-date__input text-center" type="text" v-model="pickerTime" :placeholder="selectTimeText" |
|
|
|
:disabled="!inputDate" /> |
|
|
|
:start="timepickerStartTime" :end="timepickerEndTime" :hideSecond="hideSecond" |
|
|
|
style="width: 100%;"> |
|
|
|
<input class="uni-date__input text-center" type="text" v-model="pickerTime" |
|
|
|
:placeholder="selectTimeText" :disabled="!inputDate" /> |
|
|
|
</time-picker> |
|
|
|
</view> |
|
|
|
|
|
|
|
<Calendar ref="pcSingle" :showMonth="false" :start-date="calendarRange.startDate" |
|
|
|
:end-date="calendarRange.endDate" :date="calendarDate" @change="singleChange" |
|
|
|
:default-value="defaultValue" |
|
|
|
style="padding: 0 8px;" /> |
|
|
|
:default-value="defaultValue" style="padding: 0 8px;" /> |
|
|
|
|
|
|
|
<view v-if="hasTime" class="popup-x-footer"> |
|
|
|
<text class="confirm-text" @click="confirmSingleChange">{{okText}}</text> |
|
|
@ -61,8 +63,8 @@ |
|
|
|
<input class="uni-date__input uni-date-range__input" type="text" v-model="tempRange.startDate" |
|
|
|
:placeholder="startDateText" /> |
|
|
|
|
|
|
|
<time-picker type="time" v-model="tempRange.startTime" :start="timepickerStartTime" :border="false" |
|
|
|
:disabled="!tempRange.startDate" :hideSecond="hideSecond"> |
|
|
|
<time-picker type="time" v-model="tempRange.startTime" :start="timepickerStartTime" |
|
|
|
:border="false" :disabled="!tempRange.startDate" :hideSecond="hideSecond"> |
|
|
|
<input class="uni-date__input uni-date-range__input" type="text" |
|
|
|
v-model="tempRange.startTime" :placeholder="startTimeText" |
|
|
|
:disabled="!tempRange.startDate" /> |
|
|
@ -102,8 +104,7 @@ |
|
|
|
|
|
|
|
<Calendar v-if="isPhone" ref="mobile" :clearDate="false" :date="calendarDate" :defTime="mobileCalendarTime" |
|
|
|
:start-date="calendarRange.startDate" :end-date="calendarRange.endDate" :selectableTimes="mobSelectableTime" |
|
|
|
:startPlaceholder="startPlaceholder" :endPlaceholder="endPlaceholder" |
|
|
|
:default-value="defaultValue" |
|
|
|
:startPlaceholder="startPlaceholder" :endPlaceholder="endPlaceholder" :default-value="defaultValue" |
|
|
|
:pleStatus="endMultipleStatus" :showMonth="false" :range="isRange" :hasTime="hasTime" :insert="false" |
|
|
|
:hideSecond="hideSecond" @confirm="mobileChange" @maskClose="close" /> |
|
|
|
</view> |
|
|
@ -133,9 +134,19 @@ |
|
|
|
**/ |
|
|
|
import Calendar from './calendar.vue' |
|
|
|
import TimePicker from './time-picker.vue' |
|
|
|
import { initVueI18n } from '@dcloudio/uni-i18n' |
|
|
|
import { |
|
|
|
initVueI18n |
|
|
|
} from '@dcloudio/uni-i18n' |
|
|
|
import i18nMessages from './i18n/index.js' |
|
|
|
import { getDateTime, getDate, getTime, getDefaultSecond, dateCompare, checkDate, fixIosDateFormat } from './util' |
|
|
|
import { |
|
|
|
getDateTime, |
|
|
|
getDate, |
|
|
|
getTime, |
|
|
|
getDefaultSecond, |
|
|
|
dateCompare, |
|
|
|
checkDate, |
|
|
|
fixIosDateFormat |
|
|
|
} from './util' |
|
|
|
|
|
|
|
export default { |
|
|
|
name: 'UniDatetimePicker', |
|
|
@ -373,7 +384,8 @@ |
|
|
|
return this.i18nT("uni-datetime-picker.clear") |
|
|
|
}, |
|
|
|
showClearIcon() { |
|
|
|
return this.clearIcon && !this.disabled && (this.displayValue || (this.displayRangeValue.startDate && this.displayRangeValue.endDate)) |
|
|
|
return this.clearIcon && !this.disabled && (this.displayValue || (this.displayRangeValue.startDate && this |
|
|
|
.displayRangeValue.endDate)) |
|
|
|
} |
|
|
|
}, |
|
|
|
created() { |
|
|
@ -394,15 +406,15 @@ |
|
|
|
} |
|
|
|
|
|
|
|
if (!Array.isArray(newVal) && !this.isRange) { |
|
|
|
if(newVal){ |
|
|
|
if (newVal) { |
|
|
|
this.displayValue = this.inputDate = this.calendarDate = getDate(newVal) |
|
|
|
if (this.hasTime) { |
|
|
|
this.pickerTime = getTime(newVal, this.hideSecond) |
|
|
|
this.displayValue = `${this.displayValue} ${this.pickerTime}` |
|
|
|
} |
|
|
|
}else if(this.defaultValue){ |
|
|
|
} else if (this.defaultValue) { |
|
|
|
this.inputDate = this.calendarDate = getDate(this.defaultValue) |
|
|
|
if(this.hasTime){ |
|
|
|
if (this.hasTime) { |
|
|
|
this.pickerTime = getTime(this.defaultValue, this.hideSecond) |
|
|
|
} |
|
|
|
} |
|
|
@ -450,11 +462,13 @@ |
|
|
|
right.setDate(this.$refs.right.nowDate.fullDate) |
|
|
|
}, |
|
|
|
platform() { |
|
|
|
if(typeof navigator !== "undefined"){ |
|
|
|
if (typeof navigator !== "undefined") { |
|
|
|
this.isPhone = navigator.userAgent.toLowerCase().indexOf('mobile') !== -1 |
|
|
|
return |
|
|
|
} |
|
|
|
const { windowWidth } = uni.getSystemInfoSync() |
|
|
|
const { |
|
|
|
windowWidth |
|
|
|
} = uni.getSystemInfoSync() |
|
|
|
this.isPhone = windowWidth <= 500 |
|
|
|
this.windowWidth = windowWidth |
|
|
|
}, |
|
|
@ -492,7 +506,9 @@ |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.$refs.right.changeMonth('next') |
|
|
|
this.$refs.right.cale.lastHover = false |
|
|
|
if (this.isPhone) { |
|
|
|
this.$refs.right.cale.lastHover = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -544,7 +560,7 @@ |
|
|
|
this.confirmSingleChange() |
|
|
|
}, |
|
|
|
confirmSingleChange() { |
|
|
|
if(!checkDate(this.inputDate)){ |
|
|
|
if (!checkDate(this.inputDate)) { |
|
|
|
const now = new Date() |
|
|
|
this.calendarDate = this.inputDate = getDate(now) |
|
|
|
this.pickerTime = getTime(now, this.hideSecond) |
|
|
@ -552,13 +568,13 @@ |
|
|
|
|
|
|
|
let startLaterInputDate = false |
|
|
|
let startDate, startTime |
|
|
|
if(this.start) { |
|
|
|
if (this.start) { |
|
|
|
let startString = this.start |
|
|
|
if(typeof this.start === 'number'){ |
|
|
|
if (typeof this.start === 'number') { |
|
|
|
startString = getDateTime(this.start, this.hideSecond) |
|
|
|
} |
|
|
|
[startDate, startTime] = startString.split(' ') |
|
|
|
if(this.start && !dateCompare(startDate, this.inputDate)) { |
|
|
|
if (this.start && !dateCompare(startDate, this.inputDate)) { |
|
|
|
startLaterInputDate = true |
|
|
|
this.inputDate = startDate |
|
|
|
} |
|
|
@ -566,25 +582,25 @@ |
|
|
|
|
|
|
|
let endEarlierInputDate = false |
|
|
|
let endDate, endTime |
|
|
|
if(this.end) { |
|
|
|
if (this.end) { |
|
|
|
let endString = this.end |
|
|
|
if(typeof this.end === 'number'){ |
|
|
|
if (typeof this.end === 'number') { |
|
|
|
endString = getDateTime(this.end, this.hideSecond) |
|
|
|
} |
|
|
|
[endDate, endTime] = endString.split(' ') |
|
|
|
if(this.end && !dateCompare(this.inputDate, endDate)) { |
|
|
|
if (this.end && !dateCompare(this.inputDate, endDate)) { |
|
|
|
endEarlierInputDate = true |
|
|
|
this.inputDate = endDate |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.hasTime) { |
|
|
|
if(startLaterInputDate){ |
|
|
|
if (startLaterInputDate) { |
|
|
|
this.pickerTime = startTime || getDefaultSecond(this.hideSecond) |
|
|
|
} |
|
|
|
if(endEarlierInputDate){ |
|
|
|
if (endEarlierInputDate) { |
|
|
|
this.pickerTime = endTime || getDefaultSecond(this.hideSecond) |
|
|
|
} |
|
|
|
if(!this.pickerTime){ |
|
|
|
if (!this.pickerTime) { |
|
|
|
this.pickerTime = getTime(Date.now(), this.hideSecond) |
|
|
|
} |
|
|
|
this.displayValue = `${this.inputDate} ${this.pickerTime}` |
|
|
@ -624,9 +640,12 @@ |
|
|
|
}, |
|
|
|
mobileChange(e) { |
|
|
|
if (this.isRange) { |
|
|
|
const {before, after} = e.range |
|
|
|
const { |
|
|
|
before, |
|
|
|
after |
|
|
|
} = e.range |
|
|
|
|
|
|
|
if(!before || !after){ |
|
|
|
if (!before || !after) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
@ -661,10 +680,10 @@ |
|
|
|
this.pickerVisible = false |
|
|
|
return |
|
|
|
} |
|
|
|
if(!checkDate(this.tempRange.startDate)){ |
|
|
|
if (!checkDate(this.tempRange.startDate)) { |
|
|
|
this.tempRange.startDate = getDate(Date.now()) |
|
|
|
} |
|
|
|
if(!checkDate(this.tempRange.endDate)){ |
|
|
|
if (!checkDate(this.tempRange.endDate)) { |
|
|
|
this.tempRange.endDate = getDate(Date.now()) |
|
|
|
} |
|
|
|
|
|
|
@ -673,17 +692,17 @@ |
|
|
|
let startDateLaterRangeStartDate = false |
|
|
|
let startDateLaterRangeEndDate = false |
|
|
|
let startDate, startTime |
|
|
|
if(this.start) { |
|
|
|
if (this.start) { |
|
|
|
let startString = this.start |
|
|
|
if(typeof this.start === 'number'){ |
|
|
|
if (typeof this.start === 'number') { |
|
|
|
startString = getDateTime(this.start, this.hideSecond) |
|
|
|
} |
|
|
|
[startDate,startTime] = startString.split(' ') |
|
|
|
if(this.start && !dateCompare(this.start, this.tempRange.startDate)) { |
|
|
|
[startDate, startTime] = startString.split(' ') |
|
|
|
if (this.start && !dateCompare(this.start, this.tempRange.startDate)) { |
|
|
|
startDateLaterRangeStartDate = true |
|
|
|
this.tempRange.startDate = startDate |
|
|
|
} |
|
|
|
if(this.start && !dateCompare(this.start, this.tempRange.endDate)) { |
|
|
|
if (this.start && !dateCompare(this.start, this.tempRange.endDate)) { |
|
|
|
startDateLaterRangeEndDate = true |
|
|
|
this.tempRange.endDate = startDate |
|
|
|
} |
|
|
@ -691,18 +710,18 @@ |
|
|
|
let endDateEarlierRangeStartDate = false |
|
|
|
let endDateEarlierRangeEndDate = false |
|
|
|
let endDate, endTime |
|
|
|
if(this.end) { |
|
|
|
if (this.end) { |
|
|
|
let endString = this.end |
|
|
|
if(typeof this.end === 'number'){ |
|
|
|
if (typeof this.end === 'number') { |
|
|
|
endString = getDateTime(this.end, this.hideSecond) |
|
|
|
} |
|
|
|
[endDate,endTime] = endString.split(' ') |
|
|
|
[endDate, endTime] = endString.split(' ') |
|
|
|
|
|
|
|
if(this.end && !dateCompare(this.tempRange.startDate, this.end)) { |
|
|
|
if (this.end && !dateCompare(this.tempRange.startDate, this.end)) { |
|
|
|
endDateEarlierRangeStartDate = true |
|
|
|
this.tempRange.startDate = endDate |
|
|
|
} |
|
|
|
if(this.end && !dateCompare(this.tempRange.endDate, this.end)) { |
|
|
|
if (this.end && !dateCompare(this.tempRange.endDate, this.end)) { |
|
|
|
endDateEarlierRangeEndDate = true |
|
|
|
this.tempRange.endDate = endDate |
|
|
|
} |
|
|
@ -711,27 +730,27 @@ |
|
|
|
start = this.displayRangeValue.startDate = this.tempRange.startDate |
|
|
|
end = this.displayRangeValue.endDate = this.tempRange.endDate |
|
|
|
} else { |
|
|
|
if(startDateLaterRangeStartDate){ |
|
|
|
if (startDateLaterRangeStartDate) { |
|
|
|
this.tempRange.startTime = startTime || getDefaultSecond(this.hideSecond) |
|
|
|
}else if(endDateEarlierRangeStartDate){ |
|
|
|
} else if (endDateEarlierRangeStartDate) { |
|
|
|
this.tempRange.startTime = endTime || getDefaultSecond(this.hideSecond) |
|
|
|
} |
|
|
|
if(!this.tempRange.startTime){ |
|
|
|
if (!this.tempRange.startTime) { |
|
|
|
this.tempRange.startTime = getTime(Date.now(), this.hideSecond) |
|
|
|
} |
|
|
|
|
|
|
|
if(startDateLaterRangeEndDate){ |
|
|
|
if (startDateLaterRangeEndDate) { |
|
|
|
this.tempRange.endTime = startTime || getDefaultSecond(this.hideSecond) |
|
|
|
}else if(endDateEarlierRangeEndDate){ |
|
|
|
} else if (endDateEarlierRangeEndDate) { |
|
|
|
this.tempRange.endTime = endTime || getDefaultSecond(this.hideSecond) |
|
|
|
} |
|
|
|
if(!this.tempRange.endTime){ |
|
|
|
if (!this.tempRange.endTime) { |
|
|
|
this.tempRange.endTime = getTime(Date.now(), this.hideSecond) |
|
|
|
} |
|
|
|
start = this.displayRangeValue.startDate = `${this.tempRange.startDate} ${this.tempRange.startTime}` |
|
|
|
end = this.displayRangeValue.endDate = `${this.tempRange.endDate} ${this.tempRange.endTime}` |
|
|
|
} |
|
|
|
if(!dateCompare(start,end)){ |
|
|
|
if (!dateCompare(start, end)) { |
|
|
|
[start, end] = [end, start] |
|
|
|
} |
|
|
|
this.displayRangeValue.startDate = start |
|
|
@ -818,6 +837,7 @@ |
|
|
|
width: 100%; |
|
|
|
flex: 1; |
|
|
|
} |
|
|
|
|
|
|
|
.uni-date-x { |
|
|
|
display: flex; |
|
|
|
flex-direction: row; |
|
|
@ -829,10 +849,11 @@ |
|
|
|
font-size: 14px; |
|
|
|
flex: 1; |
|
|
|
|
|
|
|
.icon-calendar{ |
|
|
|
.icon-calendar { |
|
|
|
padding-left: 3px; |
|
|
|
} |
|
|
|
.range-separator{ |
|
|
|
|
|
|
|
.range-separator { |
|
|
|
height: 35px; |
|
|
|
/* #ifndef MP */ |
|
|
|
padding: 0 2px; |
|
|
@ -871,7 +892,7 @@ |
|
|
|
position: relative; |
|
|
|
flex: 1; |
|
|
|
line-height: 35px; |
|
|
|
font-size: 14px; |
|
|
|
font-size: 12px; |
|
|
|
overflow: hidden; |
|
|
|
} |
|
|
|
|
|
|
|