This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

优化:attr设置值为的Date对象时的存储;优化构造VM时对Date对象的处理;更新datepicker组件,使用最新的host-push接口

old
宇天 2018-05-30 17:20:21 +08:00
parent c2e52e0535
commit 346e18fe5f
6 changed files with 81 additions and 50 deletions

View File

@ -1749,7 +1749,7 @@ const _Anot = (function() {
simple.forEach(function(name) { simple.forEach(function(name) {
var oldVal = old && old[name] var oldVal = old && old[name]
var val = ($vmodel[name] = state[name]) var val = ($vmodel[name] = state[name])
if (val && typeof val === 'object') { if (val && typeof val === 'object' && !Date.isDate(val)) {
val.$up = $vmodel val.$up = $vmodel
val.$pathname = name val.$pathname = name
} }
@ -4017,7 +4017,12 @@ const _Anot = (function() {
if (typeof obj === 'object' && obj !== null) { if (typeof obj === 'object' && obj !== null) {
if (!Anot.isPlainObject(obj)) { if (!Anot.isPlainObject(obj)) {
obj = obj.$model if (Date.isDate(obj)) {
obj = {}
obj[this.param] = val.toUTCString()
} else {
obj = obj.$model
}
} }
} else { } else {
if (!this.param) { if (!this.param) {
@ -4085,7 +4090,9 @@ const _Anot = (function() {
elem[k] = obj[i] elem[k] = obj[i]
} else { } else {
if (typeof obj[i] === 'object') { if (typeof obj[i] === 'object') {
obj[i] = JSON.stringify(obj[i]) obj[i] = Date.isDate(obj[i])
? obj[i].toUTCString()
: JSON.stringify(obj[i])
} else if (typeof obj[i] === 'function') { } else if (typeof obj[i] === 'function') {
k = ronattr + camelize(k.slice(1)) k = ronattr + camelize(k.slice(1))
elem[k] = obj[i].bind(vm) elem[k] = obj[i].bind(vm)

View File

@ -1764,7 +1764,7 @@
simple.forEach(function(name) { simple.forEach(function(name) {
var oldVal = old && old[name] var oldVal = old && old[name]
var val = ($vmodel[name] = state[name]) var val = ($vmodel[name] = state[name])
if (val && typeof val === 'object') { if (val && typeof val === 'object' && !Date.isDate(val)) {
val.$up = $vmodel val.$up = $vmodel
val.$pathname = name val.$pathname = name
} }
@ -4032,7 +4032,12 @@
if (typeof obj === 'object' && obj !== null) { if (typeof obj === 'object' && obj !== null) {
if (!Anot.isPlainObject(obj)) { if (!Anot.isPlainObject(obj)) {
obj = obj.$model if (Date.isDate(obj)) {
obj = {}
obj[this.param] = val.toUTCString()
} else {
obj = obj.$model
}
} }
} else { } else {
if (!this.param) { if (!this.param) {
@ -4100,7 +4105,9 @@
elem[k] = obj[i] elem[k] = obj[i]
} else { } else {
if (typeof obj[i] === 'object') { if (typeof obj[i] === 'object') {
obj[i] = JSON.stringify(obj[i]) obj[i] = Date.isDate(obj[i])
? obj[i].toUTCString()
: JSON.stringify(obj[i])
} else if (typeof obj[i] === 'function') { } else if (typeof obj[i] === 'function') {
k = ronattr + camelize(k.slice(1)) k = ronattr + camelize(k.slice(1))
elem[k] = obj[i].bind(vm) elem[k] = obj[i].bind(vm)

View File

@ -1749,7 +1749,7 @@ const _Anot = (function() {
simple.forEach(function(name) { simple.forEach(function(name) {
var oldVal = old && old[name] var oldVal = old && old[name]
var val = ($vmodel[name] = state[name]) var val = ($vmodel[name] = state[name])
if (val && typeof val === 'object') { if (val && typeof val === 'object' && !Date.isDate(val)) {
val.$up = $vmodel val.$up = $vmodel
val.$pathname = name val.$pathname = name
} }
@ -4017,7 +4017,12 @@ const _Anot = (function() {
if (typeof obj === 'object' && obj !== null) { if (typeof obj === 'object' && obj !== null) {
if (!Anot.isPlainObject(obj)) { if (!Anot.isPlainObject(obj)) {
obj = obj.$model if (Date.isDate(obj)) {
obj = {}
obj[this.param] = val.toUTCString()
} else {
obj = obj.$model
}
} }
} else { } else {
if (!this.param) { if (!this.param) {
@ -4085,7 +4090,9 @@ const _Anot = (function() {
elem[k] = obj[i] elem[k] = obj[i]
} else { } else {
if (typeof obj[i] === 'object') { if (typeof obj[i] === 'object') {
obj[i] = JSON.stringify(obj[i]) obj[i] = Date.isDate(obj[i])
? obj[i].toUTCString()
: JSON.stringify(obj[i])
} else if (typeof obj[i] === 'function') { } else if (typeof obj[i] === 'function') {
k = ronattr + camelize(k.slice(1)) k = ronattr + camelize(k.slice(1))
elem[k] = obj[i].bind(vm) elem[k] = obj[i].bind(vm)

View File

@ -1764,7 +1764,7 @@
simple.forEach(function(name) { simple.forEach(function(name) {
var oldVal = old && old[name] var oldVal = old && old[name]
var val = ($vmodel[name] = state[name]) var val = ($vmodel[name] = state[name])
if (val && typeof val === 'object') { if (val && typeof val === 'object' && !Date.isDate(val)) {
val.$up = $vmodel val.$up = $vmodel
val.$pathname = name val.$pathname = name
} }
@ -4032,7 +4032,12 @@
if (typeof obj === 'object' && obj !== null) { if (typeof obj === 'object' && obj !== null) {
if (!Anot.isPlainObject(obj)) { if (!Anot.isPlainObject(obj)) {
obj = obj.$model if (Date.isDate(obj)) {
obj = {}
obj[this.param] = val.toUTCString()
} else {
obj = obj.$model
}
} }
} else { } else {
if (!this.param) { if (!this.param) {
@ -4100,7 +4105,9 @@
elem[k] = obj[i] elem[k] = obj[i]
} else { } else {
if (typeof obj[i] === 'object') { if (typeof obj[i] === 'object') {
obj[i] = JSON.stringify(obj[i]) obj[i] = Date.isDate(obj[i])
? obj[i].toUTCString()
: JSON.stringify(obj[i])
} else if (typeof obj[i] === 'function') { } else if (typeof obj[i] === 'function') {
k = ronattr + camelize(k.slice(1)) k = ronattr + camelize(k.slice(1))
elem[k] = obj[i].bind(vm) elem[k] = obj[i].bind(vm)

View File

@ -139,7 +139,7 @@ export default Anot.component('datepicker', {
:css="{'border-radius': props.radius}" :css="{'border-radius': props.radius}"
:attr-placeholder="props.placeholder || '请选择日期'" :attr-placeholder="props.placeholder || '请选择日期'"
:attr-disabled="disabled"> :attr-disabled="disabled">
<i class="do-ui-font icon"></i> <i class="do-icon-calendar icon"></i>
</label> </label>
<dl <dl
@ -147,11 +147,12 @@ export default Anot.component('datepicker', {
:if="showCalendar"> :if="showCalendar">
<dt class="contrl"> <dt class="contrl">
<a href="javascript:;" class="do-ui-font" :click="turn(1, -1)"></a> <a class="do-icon-dbl-left" :click="turn(1, -1)"></a>
<a href="javascript:;" class="do-ui-font prev-month" :click="turn(0, -1)"></a> <a class="do-icon-left prev-month" :click="turn(0, -1)"></a>
<a href="javascript:;" class="do-ui-font next-month" :click="turn(0, 1)"></a> <a class="do-icon-right next-month" :click="turn(0, 1)"></a>
<a href="javascript:;" class="do-ui-font next-year" :click="turn(1, 1)"></a> <a class="do-icon-dbl-right next-year" :click="turn(1, 1)"></a>
<span title="双击回到今天" <span
title="双击回到今天"
:dblclick="back2today" :dblclick="back2today"
:text="calendar.year + '-' + numberFormat(calendar.month)"></span> :text="calendar.year + '-' + numberFormat(calendar.month)"></span>
</dt> </dt>
@ -186,25 +187,21 @@ export default Anot.component('datepicker', {
<a href="javascript:;" class="now" :click="now">现在</a> <a href="javascript:;" class="now" :click="now">现在</a>
</dd> </dd>
<dt class="confirm"> <dt class="confirm">
<a href="javascript:;" :click="close" class="cancel">取消</a> <a :click="close" class="cancel">取消</a>
<a href="javascript:;" :click="onConfirm" class="ok">确定</a> <a :click="onConfirm" class="ok">确定</a>
</dt> </dt>
<dd class="tips" :if="tips" :text="tips"></dd> <dd class="tips" :if="tips" :text="tips"></dd>
</dl> </dl>
</div>` </div>`
}, },
construct: function(props, state) { construct: function(props, state) {
if (!props.hasOwnProperty('key')) {
return Anot.error('日历组件必须设置key属性')
}
// 日期格式化, 不显示时间时, 默认会调用过滤器的格式'Y-m-d H:i:s' // 日期格式化, 不显示时间时, 默认会调用过滤器的格式'Y-m-d H:i:s'
if (!props.showTime && !props.format) { if (!props.showTime && !props.format) {
props.format = 'Y-m-d' props.format = 'Y-m-d'
} }
//获取初始值 //获取初始值
let defVal = props.value let defVal = props.hostPush || null
if (!defVal) { if (!defVal) {
if (props.minDate) { if (props.minDate) {
defVal = props.minDate defVal = props.minDate
@ -213,9 +210,10 @@ export default Anot.component('datepicker', {
} }
} }
// 修正默认值, 如果不是Date对象, 则转为Date对象 // 修正默认值, 如果不是Date对象, 则转为Date对象
if (defVal && !Date.isDate(defVal)) { if (defVal) {
defVal += ' GMT+8000' if (!Date.isDate(defVal)) {
defVal = new Date(defVal) defVal = new Date(defVal)
}
} else { } else {
defVal = new Date() defVal = new Date()
} }
@ -245,7 +243,8 @@ export default Anot.component('datepicker', {
state.max.month = props.maxDate.getMonth() + 1 state.max.month = props.maxDate.getMonth() + 1
state.max.day = props.maxDate.getDate() state.max.day = props.maxDate.getDate()
} }
if (props.value) {
if (props.hostPush) {
state.last = { state.last = {
year: defVal.getFullYear(), year: defVal.getFullYear(),
month: defVal.getMonth() + 1, month: defVal.getMonth() + 1,
@ -268,17 +267,17 @@ export default Anot.component('datepicker', {
//移除部分属性 //移除部分属性
delete props.minDate delete props.minDate
delete props.maxDate delete props.maxDate
delete props.value delete props.hostPush
delete props.disabled delete props.disabled
}, },
componentWillMount: function() { componentWillMount: function() {
this.resetCalendarTable() this.resetCalendarTable()
this.$push(this.value)
}, },
componentDidMount: function() { componentDidMount: function() {
if (typeof this.props.created === 'function') { if (typeof this.props.created === 'function') {
this.props.created(this) this.props.created(this)
} }
document.addEventListener('click', () => { document.addEventListener('click', () => {
this.close() this.close()
}) })
@ -345,7 +344,12 @@ export default Anot.component('datepicker', {
methods: { methods: {
// 重置日历表格 // 重置日历表格
resetCalendarTable: function() { resetCalendarTable: function() {
let { max, min, calendar: { year, month }, last } = this let {
max,
min,
calendar: { year, month },
last
} = this
this.calendar.day = 0 this.calendar.day = 0
this.calendar.list.clear() this.calendar.list.clear()
this.calendar.list.pushArray( this.calendar.list.pushArray(
@ -375,7 +379,11 @@ export default Anot.component('datepicker', {
}, },
// 切换上/下 年/月 // 切换上/下 年/月
turn: function(isYear, step) { turn: function(isYear, step) {
let { calendar: { year, month }, max, min } = this let {
calendar: { year, month },
max,
min
} = this
if (isYear === 1) { if (isYear === 1) {
year += step year += step
@ -439,11 +447,13 @@ export default Anot.component('datepicker', {
onConfirm: function() { onConfirm: function() {
this.updateTime() this.updateTime()
this.close() this.close()
this.$push(this.value)
if ( if (
this.calendar.day > 0 && this.calendar.day > 0 &&
typeof this.props.onDatePicked === 'function' typeof this.props.onDatePicked === 'function'
) { ) {
this.props.onDatePicked(this.props.key, this.value, this.last.pick) // 返回一个格式化后的值和一个Date对象
this.props.onDatePicked(this.value, this.last.pick)
} }
} }
} }

View File

@ -5,7 +5,8 @@
* @date 2016-02-14 14:00:06 * @date 2016-02-14 14:00:06
* *
*/ */
@import 'var.scss'; @import "var.scss";
.do-datepicker { position:relative;width:100%; height:100%;color:nth($cgr, 1);font-size:14px; .do-datepicker { position:relative;width:100%; height:100%;color:nth($cgr, 1);font-size:14px;
&.mini {width:155px;height:30px;line-height:30px;} &.mini {width:155px;height:30px;line-height:30px;}
@ -26,7 +27,6 @@
&[disabled] {background:#f7f8fb;cursor:not-allowed;} &[disabled] {background:#f7f8fb;cursor:not-allowed;}
} }
.icon {position:absolute;right:0;top:0;width:35px;text-align:center;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"}
} }
} }
.calendar-box { position:absolute; left:0; top:100%; z-index:65534; width:267px; height:auto; min-height:60px;padding:10px;line-height:35px; border:1px solid #ddd; background:#fff; font-size:14px; color:nth($cgr, 1); text-align:center; box-shadow:0 1px 5px rgba(0, 0, 0, 0.1); .calendar-box { position:absolute; left:0; top:100%; z-index:65534; width:267px; height:auto; min-height:60px;padding:10px;line-height:35px; border:1px solid #ddd; background:#fff; font-size:14px; color:nth($cgr, 1); text-align:center; box-shadow:0 1px 5px rgba(0, 0, 0, 0.1);
@ -35,24 +35,17 @@
dt.contrl {position:relative; width:100%; height:35px; margin:5px 0 0;border-radius:3px;color:#fff; dt.contrl {position:relative; width:100%; height:35px; margin:5px 0 0;border-radius:3px;color:#fff;
a { position:absolute; left:0; top:0; width:35px; height:35px;color:#fff; a { position:absolute; left:0; top:0; width:35px; height:35px;color:#fff;cursor:pointer;
&::before {position:absolute;left:0;top:0;z-index:-1;display:block;width:35px;height:35px;border-radius:50%;background:nth($ct, 3); content:"";opacity:0;transform: scale(0);} &::after {position:absolute;left:0;top:0;z-index:-1;display:block;width:35px;height:35px;border-radius:50%;background:nth($ct, 3); content:"";opacity:0;transform: scale(0);}
&:active {font-weight:bold; &:active {font-weight:bold;
&::before {animation:ripple .3s cubic-bezier(0.23, 1, 0.32, 1);} &::after {animation:ripple .3s cubic-bezier(0.23, 1, 0.32, 1);}
} }
&::after {content:"\e692";}
&.prev-month {left:35px; &.prev-month {left:35px;}
&::after {content:"\e67c"} &.next-month {left:auto; right:35px;}
} &.next-year {left:auto; right:0;}
&.next-month {left:auto; right:35px;
&::after {content:"\e66e"}
}
&.next-year {left:auto; right:0;
&::after {content:"\e694"}
}
} }
} }
@ -92,7 +85,7 @@
dt.confirm { position:relative; width:100%; height:41px; padding:10px 0 0;line-height:30px; border-top:1px solid #eee; text-align:right; dt.confirm { position:relative; width:100%; height:41px; padding:10px 0 0;line-height:30px; border-top:1px solid #eee; text-align:right;
.ok,.cancel {display:inline-block;width:60px; height:30px;margin:0 0 0 10px;border-radius:3px;text-align:center;} .ok,.cancel {display:inline-block;width:60px; height:30px;margin:0 0 0 10px;border-radius:3px;text-align:center;cursor:pointer;}
.ok { background:nth($ct, 1); color:#fff; .ok { background:nth($ct, 1); color:#fff;
&:hover { background:nth($ct, 2); } &:hover { background:nth($ct, 2); }