Commit d70cad45ec14fc75f456926f3f3f622f8c06e518

Authored by 梁灏
1 parent 603e437b

update TimePicker

update TimePicker
src/components/date-picker/base/time-spinner.vue
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 </template> 19 </template>
20 <script> 20 <script>
21 import Options from '../time-mixins'; 21 import Options from '../time-mixins';
22 - import { deepCopy, scrollTop } from '../../../utils/assist'; 22 + import { deepCopy, scrollTop, firstUpperCase } from '../../../utils/assist';
23 23
24 const prefixCls = 'ivu-time-picker-cells'; 24 const prefixCls = 'ivu-time-picker-cells';
25 25
@@ -70,7 +70,7 @@ @@ -70,7 +70,7 @@
70 const hour = deepCopy(hour_tmpl); 70 const hour = deepCopy(hour_tmpl);
71 hour.text = i; 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 hour.disabled = true; 74 hour.disabled = true;
75 if (this.hideDisabledOptions) hour.hide = true; 75 if (this.hideDisabledOptions) hour.hide = true;
76 } 76 }
@@ -93,7 +93,7 @@ @@ -93,7 +93,7 @@
93 const minute = deepCopy(minute_tmpl); 93 const minute = deepCopy(minute_tmpl);
94 minute.text = i; 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 minute.disabled = true; 97 minute.disabled = true;
98 if (this.hideDisabledOptions) minute.hide = true; 98 if (this.hideDisabledOptions) minute.hide = true;
99 } 99 }
@@ -116,7 +116,7 @@ @@ -116,7 +116,7 @@
116 const second = deepCopy(second_tmpl); 116 const second = deepCopy(second_tmpl);
117 second.text = i; 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 second.disabled = true; 120 second.disabled = true;
121 if (this.hideDisabledOptions) second.hide = true; 121 if (this.hideDisabledOptions) second.hide = true;
122 } 122 }
@@ -156,7 +156,17 @@ @@ -156,7 +156,17 @@
156 this.$emit('on-change', data); 156 this.$emit('on-change', data);
157 157
158 const from = this.$els[type].scrollTop; 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 scrollTop(this.$els[type], from, to, 500); 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,6 +81,7 @@ export function getStyle (element, styleName) {
81 function firstUpperCase(str) { 81 function firstUpperCase(str) {
82 return str.toString()[0].toUpperCase() + str.toString().slice(1); 82 return str.toString()[0].toUpperCase() + str.toString().slice(1);
83 } 83 }
  84 +export {firstUpperCase};
84 85
85 // Warn 86 // Warn
86 export function warnProp(component, prop, correctType, wrongType) { 87 export function warnProp(component, prop, correctType, wrongType) {
test/routers/date.vue
@@ -16,8 +16,8 @@ @@ -16,8 +16,8 @@
16 :value="value" 16 :value="value"
17 placeholder="选择时间" 17 placeholder="选择时间"
18 format="HH:mm:ss" 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 style="width: 168px"></time-picker> 21 style="width: 168px"></time-picker>
22 </i-col> 22 </i-col>
23 </row> 23 </row>