update TimePicker

update TimePicker
This commit is contained in:
梁灏 2016-12-27 15:50:07 +08:00
parent 603e437bc2
commit d70cad45ec
3 changed files with 18 additions and 7 deletions

View file

@ -19,7 +19,7 @@
</template> </template>
<script> <script>
import Options from '../time-mixins'; import Options from '../time-mixins';
import { deepCopy, scrollTop } from '../../../utils/assist'; import { deepCopy, scrollTop, firstUpperCase } from '../../../utils/assist';
const prefixCls = 'ivu-time-picker-cells'; const prefixCls = 'ivu-time-picker-cells';
@ -70,7 +70,7 @@
const hour = deepCopy(hour_tmpl); const hour = deepCopy(hour_tmpl);
hour.text = i; hour.text = i;
if (this.disabledHours && this.disabledHours.indexOf(i) > -1) { if (this.disabledHours.length && this.disabledHours.indexOf(i) > -1) {
hour.disabled = true; hour.disabled = true;
if (this.hideDisabledOptions) hour.hide = true; if (this.hideDisabledOptions) hour.hide = true;
} }
@ -93,7 +93,7 @@
const minute = deepCopy(minute_tmpl); const minute = deepCopy(minute_tmpl);
minute.text = i; minute.text = i;
if (this.disabledMinutes && this.disabledMinutes.indexOf(i) > -1) { if (this.disabledMinutes.length && this.disabledMinutes.indexOf(i) > -1) {
minute.disabled = true; minute.disabled = true;
if (this.hideDisabledOptions) minute.hide = true; if (this.hideDisabledOptions) minute.hide = true;
} }
@ -116,7 +116,7 @@
const second = deepCopy(second_tmpl); const second = deepCopy(second_tmpl);
second.text = i; second.text = i;
if (this.disabledSeconds && this.disabledSeconds.indexOf(i) > -1) { if (this.disabledSeconds.length && this.disabledSeconds.indexOf(i) > -1) {
second.disabled = true; second.disabled = true;
if (this.hideDisabledOptions) second.hide = true; if (this.hideDisabledOptions) second.hide = true;
} }
@ -156,7 +156,17 @@
this.$emit('on-change', data); this.$emit('on-change', data);
const from = this.$els[type].scrollTop; const from = this.$els[type].scrollTop;
const to = 24 * cell.text;
let index = cell.text;
const Type = firstUpperCase(type);
const disabled = this[`disabled${Type}`];
if (disabled.length && this.hideDisabledOptions) {
let _count = 0;
disabled.forEach(item => item <= index ? _count++ : '');
index -= _count;
}
const to = 24 * index;
scrollTop(this.$els[type], from, to, 500); scrollTop(this.$els[type], from, to, 500);
} }
} }

View file

@ -81,6 +81,7 @@ export function getStyle (element, styleName) {
function firstUpperCase(str) { function firstUpperCase(str) {
return str.toString()[0].toUpperCase() + str.toString().slice(1); return str.toString()[0].toUpperCase() + str.toString().slice(1);
} }
export {firstUpperCase};
// Warn // Warn
export function warnProp(component, prop, correctType, wrongType) { export function warnProp(component, prop, correctType, wrongType) {

View file

@ -16,8 +16,8 @@
:value="value" :value="value"
placeholder="选择时间" placeholder="选择时间"
format="HH:mm:ss" format="HH:mm:ss"
:hide-disabled-options="true" :hide-disabled-options="false"
:disabled-hours="[1,2]" :disabled-hours="[1,2,5,10,11]"
style="width: 168px"></time-picker> style="width: 168px"></time-picker>
</i-col> </i-col>
</row> </row>