Skip to content

Commit af3ef42

Browse files
committed
feat(QDate): enhance model management when model is invalid
1 parent 63362db commit af3ef42

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

ui/dev/src/pages/form/date-part2-multiple-range.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export default {
4949
],
5050
dayRange: { from: '2020/07/08', to: '2020/07/17' },
5151
daysRange: [
52+
{ from: '2020/08/12', to: '2020/08/16' },
5253
'2020/08/02',
5354
'2020/08/10',
54-
{ from: '2020/08/12', to: '2020/08/16' },
5555
{ from: '2020/08/27', to: '2020/09/15' }
5656
// '2021/09/11',
5757
]

ui/src/components/date/QDate.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ export default Vue.extend({
130130
return this.normalizedModel
131131
.filter(date => typeof date === 'string')
132132
.map(date => this.__decodeString(date, this.computedMask, this.computedLocale))
133+
.filter(date => date.dateHash !== null)
133134
},
134135

135136
rangeModel () {
136137
const fn = date => this.__decodeString(date, this.computedMask, this.computedLocale)
137138
return this.normalizedModel
138139
.filter(date => Object(date) === date && date.from !== void 0 && date.to !== void 0)
139-
.map(date => ({ from: fn(date.from), to: fn(date.to) }))
140+
.map(range => ({ from: fn(range.from), to: fn(range.to) }))
141+
.filter(range => range.from.dateHash !== null && range.to.dateHash !== null)
140142
},
141143

142144
getNativeDateFn () {
@@ -172,8 +174,7 @@ export default Vue.extend({
172174
model.day + lineStr + '?'
173175
}
174176

175-
if (this.normalizedModel.length === 0 || this.daysInModel === 0) {
176-
// TODO: || this.daysModel[0].dateHash === null
177+
if (this.daysInModel === 0) {
177178
return lineStr
178179
}
179180

@@ -202,8 +203,7 @@ export default Vue.extend({
202203
return this.subtitle
203204
}
204205

205-
if (this.daysInModel === 0 || this.daysInModel === 0) {
206-
// TODO: || this.daysModel[0].year === null
206+
if (this.daysInModel === 0) {
207207
return lineStr
208208
}
209209

@@ -704,29 +704,36 @@ export default Vue.extend({
704704
},
705705

706706
__decodeString (date, mask, locale) {
707-
const decoded = __splitDate(
707+
return __splitDate(
708708
date,
709709
this.calendar === 'persian' ? 'YYYY/MM/DD' : mask || this.mask,
710710
locale || this.__getComputedLocale(),
711-
this.calendar
711+
this.calendar,
712+
{
713+
hour: 0,
714+
minute: 0,
715+
second: 0,
716+
millisecond: 0
717+
}
712718
)
713-
714-
decoded.hour = decoded.hour || 0
715-
decoded.minute = decoded.minute || 0
716-
decoded.second = decoded.second || 0
717-
decoded.millisecond = decoded.millisecond || 0
718-
719-
return decoded
720719
},
721720

722721
__getViewModel (value) {
723722
const model = Array.isArray(value) === true
724723
? value
725724
: (value ? [ value ] : [])
726725

727-
return model.length === 0
726+
if (model.length === 0) {
727+
return this.__getDefaultViewModel()
728+
}
729+
730+
const decoded = this.__decodeString(
731+
model[0].from !== void 0 ? model[0].from : model[0]
732+
)
733+
734+
return decoded.dateHash === null
728735
? this.__getDefaultViewModel()
729-
: this.__decodeString(model[0].from !== void 0 ? model[0].from : model[0])
736+
: decoded
730737
},
731738

732739
__getDefaultViewModel () {

ui/src/utils/date.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export function extractDate (str, mask, dateLocale) {
172172
}
173173

174174
export function __splitDate (str, mask, dateLocale, calendar, defaultModel) {
175-
const date = Object.assign({
175+
const date = {
176176
year: null,
177177
month: null,
178178
day: null,
@@ -183,7 +183,9 @@ export function __splitDate (str, mask, dateLocale, calendar, defaultModel) {
183183
timezoneOffset: null,
184184
dateHash: null,
185185
timeHash: null
186-
}, defaultModel)
186+
}
187+
188+
defaultModel !== void 0 && Object.assign(date, defaultModel)
187189

188190
if (
189191
str === void 0 ||

0 commit comments

Comments
 (0)