Commit d70cad45ec14fc75f456926f3f3f622f8c06e518

Authored by 梁灏
1 parent 603e437b

update TimePicker

update TimePicker
src/components/date-picker/base/time-spinner.vue
... ... @@ -19,7 +19,7 @@
19 19 </template>
20 20 <script>
21 21 import Options from '../time-mixins';
22   - import { deepCopy, scrollTop } from '../../../utils/assist';
  22 + import { deepCopy, scrollTop, firstUpperCase } from '../../../utils/assist';
23 23  
24 24 const prefixCls = 'ivu-time-picker-cells';
25 25  
... ... @@ -70,7 +70,7 @@
70 70 const hour = deepCopy(hour_tmpl);
71 71 hour.text = i;
72 72  
73   - if (this.disabledHours && this.disabledHours.indexOf(i) > -1) {
  73 + if (this.disabledHours.length && this.disabledHours.indexOf(i) > -1) {
74 74 hour.disabled = true;
75 75 if (this.hideDisabledOptions) hour.hide = true;
76 76 }
... ... @@ -93,7 +93,7 @@
93 93 const minute = deepCopy(minute_tmpl);
94 94 minute.text = i;
95 95  
96   - if (this.disabledMinutes && this.disabledMinutes.indexOf(i) > -1) {
  96 + if (this.disabledMinutes.length && this.disabledMinutes.indexOf(i) > -1) {
97 97 minute.disabled = true;
98 98 if (this.hideDisabledOptions) minute.hide = true;
99 99 }
... ... @@ -116,7 +116,7 @@
116 116 const second = deepCopy(second_tmpl);
117 117 second.text = i;
118 118  
119   - if (this.disabledSeconds && this.disabledSeconds.indexOf(i) > -1) {
  119 + if (this.disabledSeconds.length && this.disabledSeconds.indexOf(i) > -1) {
120 120 second.disabled = true;
121 121 if (this.hideDisabledOptions) second.hide = true;
122 122 }
... ... @@ -156,7 +156,17 @@
156 156 this.$emit('on-change', data);
157 157  
158 158 const from = this.$els[type].scrollTop;
159   - const to = 24 * cell.text;
  159 +
  160 + let index = cell.text;
  161 + const Type = firstUpperCase(type);
  162 + const disabled = this[`disabled${Type}`];
  163 + if (disabled.length && this.hideDisabledOptions) {
  164 + let _count = 0;
  165 + disabled.forEach(item => item <= index ? _count++ : '');
  166 + index -= _count;
  167 + }
  168 +
  169 + const to = 24 * index;
160 170 scrollTop(this.$els[type], from, to, 500);
161 171 }
162 172 }
... ...
src/utils/assist.js
... ... @@ -81,6 +81,7 @@ export function getStyle (element, styleName) {
81 81 function firstUpperCase(str) {
82 82 return str.toString()[0].toUpperCase() + str.toString().slice(1);
83 83 }
  84 +export {firstUpperCase};
84 85  
85 86 // Warn
86 87 export function warnProp(component, prop, correctType, wrongType) {
... ...
test/routers/date.vue
... ... @@ -16,8 +16,8 @@
16 16 :value="value"
17 17 placeholder="选择时间"
18 18 format="HH:mm:ss"
19   - :hide-disabled-options="true"
20   - :disabled-hours="[1,2]"
  19 + :hide-disabled-options="false"
  20 + :disabled-hours="[1,2,5,10,11]"
21 21 style="width: 168px"></time-picker>
22 22 </i-col>
23 23 </row>
... ...