diff --git a/src/js/datepicker/index.js b/src/js/datepicker/index.js
index 01ee533..4ba4d45 100644
--- a/src/js/datepicker/index.js
+++ b/src/js/datepicker/index.js
@@ -6,8 +6,7 @@
*/
'use strict'
-import tpl from './main.htm'
-import './style.css'
+import './style.scss'
/**************** 公共函数 *****************/
//计算日历数组
@@ -124,7 +123,75 @@ Anot.ui.datepicker = '1.0.0'
export default Anot.component('datepicker', {
render: function() {
- return tpl
+ return `
`
},
construct: function(props, state) {
if (!props.hasOwnProperty('key')) {
@@ -238,6 +305,9 @@ export default Anot.component('datepicker', {
props: {
showTime: false, //对话框上显示时间
radius: 3,
+ height: null,
+ width: null,
+ size: 'mini', //默认规格,mini, medium, large
format: '', // 日期显示格式
onCreated: Anot.PropsTypes.isFunction(),
onDatePicked: Anot.PropsTypes.isFunction()
@@ -276,7 +346,7 @@ export default Anot.component('datepicker', {
// 重置日历表格
resetCalendarTable: function() {
let { max, min, calendar: { year, month }, last } = this
-
+ this.calendar.day = 0
this.calendar.list.clear()
this.calendar.list.pushArray(
getCalendarTable({ max, min, year, month }, last)
@@ -297,6 +367,12 @@ export default Anot.component('datepicker', {
onFocus: function() {
this.showCalendar = !0
},
+ back2today: function() {
+ let today = new Date()
+ this.calendar.year = today.getFullYear()
+ this.calendar.month = today.getMonth() + 1
+ this.resetCalendarTable()
+ },
// 切换上/下 年/月
turn: function(isYear, step) {
let { calendar: { year, month }, max, min } = this
@@ -333,6 +409,11 @@ export default Anot.component('datepicker', {
updateTime: function() {
let { year, month, day, hour, minute, second } = this.calendar
+ // day 小于1, 说明切换年/月之后, 没有选择具体日期
+ if (day < 1) {
+ return
+ }
+
this.last = { year, month, day }
if (!this.props.showTime) {
@@ -358,8 +439,11 @@ export default Anot.component('datepicker', {
onConfirm: function() {
this.updateTime()
this.close()
- if (typeof this.props.onDatePicked === 'function') {
- this.props.onDatePicked(this.value, this.last.pick)
+ if (
+ this.calendar.day > 0 &&
+ typeof this.props.onDatePicked === 'function'
+ ) {
+ this.props.onDatePicked(this.props.key, this.value, this.last.pick)
}
}
}
diff --git a/src/js/datepicker/main.htm b/src/js/datepicker/main.htm
deleted file mode 100644
index 5f9a2bf..0000000
--- a/src/js/datepicker/main.htm
+++ /dev/null
@@ -1,62 +0,0 @@
-
\ No newline at end of file
diff --git a/src/js/datepicker/style.scss b/src/js/datepicker/style.scss
index ce38870..0323f48 100644
--- a/src/js/datepicker/style.scss
+++ b/src/js/datepicker/style.scss
@@ -8,6 +8,10 @@
@import 'var.scss';
.do-datepicker { position:relative;width:100%; height:100%;color:nth($cgr, 1);font-size:14px;
+ &.mini {width:155px;height:30px;line-height:30px;}
+ &.medium {width:175px;height:35px;line-height:35px;}
+ &.large {width:195px;height:40px;line-height:40px;}
+
a { text-decoration:none;color:nth($cgr, 1);
&:hover {color:nth($cgr, 2);}
@@ -21,7 +25,7 @@
&:focus { border-color:nth($ct, 1); }
&[disabled] {background:#f7f8fb;cursor:not-allowed;}
}
- .icon {position:absolute;right:10px;top:4px;font-size:25px;color:nth($cp, 3);
+ .icon {position:absolute;right:0;top:0;width:35px;text-align:center;font-size:25px;color:nth($cp, 3);
&::after {content:"\e650"}
}
}