Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
1bdecf9c
Commit
1bdecf9c
authored
Jan 03, 2017
by
qingwei.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DatePicker: fix change event no trigger when setting the initial value, fixed #2167
parent
4da8b2a2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
41 deletions
+45
-41
packages/date-picker/src/picker.vue
packages/date-picker/src/picker.vue
+32
-38
packages/date-picker/src/picker/time-picker.js
packages/date-picker/src/picker/time-picker.js
+6
-0
packages/date-picker/src/picker/time-select.js
packages/date-picker/src/picker/time-select.js
+1
-1
packages/date-picker/src/util/index.js
packages/date-picker/src/util/index.js
+6
-2
No files found.
packages/date-picker/src/picker.vue
View file @
1bdecf9c
...
...
@@ -10,8 +10,8 @@
@
focus=
"handleFocus"
@
blur=
"handleBlur"
@
keydown.native=
"handleKeydown"
:value=
"
visual
Value"
@
change.native=
"
visual
Value = $event.target.value"
:value=
"
display
Value"
@
change.native=
"
display
Value = $event.target.value"
ref=
"reference"
>
<i
slot=
"icon"
class=
"el-input__icon"
...
...
@@ -27,7 +27,7 @@
<
script
>
import
Vue
from
'
vue
'
;
import
Clickoutside
from
'
element-ui/src/utils/clickoutside
'
;
import
{
formatDate
,
parseDate
,
getWeekNumber
,
equalDate
}
from
'
./util
'
;
import
{
formatDate
,
parseDate
,
getWeekNumber
,
equalDate
,
isDate
}
from
'
./util
'
;
import
Popper
from
'
element-ui/src/utils/vue-popper
'
;
import
Emitter
from
'
element-ui/src/mixins/emitter
'
;
import
ElInput
from
'
element-ui/packages/input
'
;
...
...
@@ -213,7 +213,7 @@ export default {
return
{
pickerVisible
:
false
,
showClose
:
false
,
internal
Value
:
''
current
Value
:
''
};
},
...
...
@@ -222,16 +222,22 @@ export default {
if
(
this
.
readonly
||
this
.
disabled
)
return
;
val
?
this
.
showPicker
()
:
this
.
hidePicker
();
},
internalValue
(
val
)
{
if
(
!
val
&&
this
.
picker
&&
typeof
this
.
picker
.
handleClear
===
'
function
'
)
{
currentValue
(
val
)
{
if
(
val
)
return
;
if
(
this
.
picker
&&
typeof
this
.
picker
.
handleClear
===
'
function
'
)
{
this
.
picker
.
handleClear
();
}
else
{
this
.
$emit
(
'
input
'
);
}
},
value
:
{
immediate
:
true
,
handler
(
val
)
{
this
.
internalValue
=
val
;
this
.
currentValue
=
isDate
(
val
)
?
new
Date
(
val
)
:
val
;
}
},
displayValue
(
val
)
{
this
.
$emit
(
'
change
'
,
val
);
}
},
...
...
@@ -246,7 +252,7 @@ export default {
},
valueIsEmpty
()
{
const
val
=
this
.
internal
Value
;
const
val
=
this
.
current
Value
;
if
(
Array
.
isArray
(
val
))
{
for
(
let
i
=
0
,
len
=
val
.
length
;
i
<
len
;
i
++
)
{
if
(
val
[
i
])
{
...
...
@@ -284,9 +290,9 @@ export default {
return
HAVE_TRIGGER_TYPES
.
indexOf
(
this
.
type
)
!==
-
1
;
},
visual
Value
:
{
display
Value
:
{
get
()
{
const
value
=
this
.
internal
Value
;
const
value
=
this
.
current
Value
;
if
(
!
value
)
return
;
const
formatter
=
(
TYPE_VALUE_RESOLVER_MAP
[
this
.
type
]
||
...
...
@@ -318,9 +324,6 @@ export default {
},
created
()
{
this
.
cachePicker
=
{};
this
.
cacheChange
=
{};
// vue-popper
this
.
options
=
{
boundariesPadding
:
0
,
...
...
@@ -340,26 +343,25 @@ export default {
handleClickIcon
()
{
if
(
this
.
readonly
||
this
.
disabled
)
return
;
if
(
this
.
showClose
)
{
this
.
internalValue
=
''
;
this
.
currentValue
=
''
;
this
.
showClose
=
false
;
}
else
{
this
.
pickerVisible
=
!
this
.
pickerVisible
;
}
},
dateIsUpdated
(
date
,
cache
)
{
let
updated
=
true
;
if
(
Array
.
isArray
(
date
))
{
if
(
equalDate
(
cache
.
cacheDateMin
,
date
[
0
])
&&
equalDate
(
cache
.
cacheDateMax
,
date
[
1
]))
updated
=
false
;
cache
.
cacheDateMin
=
new
Date
(
date
[
0
]);
cache
.
cacheDateMax
=
new
Date
(
date
[
1
]);
dateChanged
(
dateA
,
dateB
)
{
if
(
Array
.
isArray
(
dateA
))
{
let
len
=
dateA
.
length
;
if
(
!
dateB
)
return
true
;
while
(
len
--
)
{
if
(
!
equalDate
(
dateA
[
len
],
dateB
[
len
]))
return
true
;
}
}
else
{
if
(
equalDate
(
cache
.
cacheDate
,
date
))
updated
=
false
;
cache
.
cacheDate
=
new
Date
(
date
);
if
(
!
equalDate
(
dateA
,
dateB
))
return
true
;
}
return
updated
;
return
false
;
},
handleClose
()
{
...
...
@@ -400,7 +402,7 @@ export default {
showPicker
()
{
if
(
this
.
$isServer
)
return
;
if
(
!
this
.
picker
)
{
this
.
panel
.
defaultValue
=
this
.
internal
Value
;
this
.
panel
.
defaultValue
=
this
.
current
Value
;
this
.
picker
=
new
Vue
(
this
.
panel
).
$mount
(
document
.
createElement
(
'
div
'
));
this
.
picker
.
popperClass
=
this
.
popperClass
;
this
.
popperElm
=
this
.
picker
.
$el
;
...
...
@@ -423,12 +425,6 @@ export default {
this
.
picker
.
selectableRange
=
ranges
.
map
(
range
=>
parser
(
range
,
format
));
}
if
(
this
.
type
===
'
time-select
'
&&
options
)
{
this
.
$watch
(
'
pickerOptions.minTime
'
,
val
=>
{
this
.
picker
.
minTime
=
val
;
});
}
for
(
const
option
in
options
)
{
if
(
options
.
hasOwnProperty
(
option
)
&&
// 忽略 time-picker 的该配置项
...
...
@@ -446,9 +442,7 @@ export default {
this
.
picker
.
$on
(
'
dodestroy
'
,
this
.
doDestroy
);
this
.
picker
.
$on
(
'
pick
'
,
(
date
,
visible
=
false
)
=>
{
if
(
this
.
dateIsUpdated
(
date
,
this
.
cachePicker
))
this
.
$emit
(
'
input
'
,
date
);
this
.
$nextTick
(()
=>
this
.
dateIsUpdated
(
date
,
this
.
cacheChange
)
&&
this
.
$emit
(
'
change
'
,
this
.
visualValue
));
if
(
this
.
dateChanged
(
date
,
this
.
value
))
this
.
$emit
(
'
input
'
,
date
);
this
.
pickerVisible
=
this
.
picker
.
visible
=
visible
;
this
.
picker
.
resetView
&&
this
.
picker
.
resetView
();
});
...
...
@@ -463,10 +457,10 @@ export default {
this
.
updatePopper
();
if
(
this
.
internal
Value
instanceof
Date
)
{
this
.
picker
.
date
=
new
Date
(
this
.
internal
Value
.
getTime
());
if
(
this
.
current
Value
instanceof
Date
)
{
this
.
picker
.
date
=
new
Date
(
this
.
current
Value
.
getTime
());
}
else
{
this
.
picker
.
value
=
this
.
internal
Value
;
this
.
picker
.
value
=
this
.
current
Value
;
}
this
.
picker
.
resetView
&&
this
.
picker
.
resetView
();
...
...
packages/date-picker/src/picker/time-picker.js
View file @
1bdecf9c
...
...
@@ -11,6 +11,12 @@ export default {
isRange
:
Boolean
},
data
()
{
return
{
type
:
''
};
},
created
()
{
this
.
type
=
this
.
isRange
?
'
timerange
'
:
'
time
'
;
this
.
panel
=
this
.
isRange
?
TimeRangePanel
:
TimePanel
;
...
...
packages/date-picker/src/picker/time-select.js
View file @
1bdecf9c
...
...
@@ -6,7 +6,7 @@ export default {
name
:
'
ElTimeSelect
'
,
created
()
{
beforeCreate
()
{
this
.
type
=
'
time-select
'
;
this
.
panel
=
Panel
;
}
...
...
packages/date-picker/src/util/index.js
View file @
1bdecf9c
...
...
@@ -13,9 +13,13 @@ export const equalDate = function(dateA, dateB) {
};
export
const
toDate
=
function
(
date
)
{
return
isDate
(
date
)
?
date
:
null
;
};
export
const
isDate
=
function
(
date
)
{
date
=
new
Date
(
date
);
if
(
isNaN
(
date
.
getTime
()))
return
null
;
return
dat
e
;
if
(
isNaN
(
date
.
getTime
()))
return
false
;
return
tru
e
;
};
export
const
formatDate
=
function
(
date
,
format
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment