Commit 36628acaab7b1c14ddbc540a89f0b943e92eb595

Authored by 梁灏
1 parent c1abaed9

update TimePicker

update TimePicker
src/components/date-picker/base/time-spinner.vue
... ... @@ -2,21 +2,29 @@
2 2 <div :class="classes">
3 3 <div :class="[prefixCls+ '-wrapper']">
4 4 <ul :class="[prefixCls + '-list']">
5   - <li v-for="item in hoursList"></li>
  5 + <li :class="getCellCls(item)" v-for="item in hoursList" v-show="!item.hide">{{ item.text }}</li>
6 6 </ul>
7 7 </div>
8 8 <div :class="[prefixCls+ '-wrapper']">
9   - <li v-for="item in minutesList"></li>
  9 + <ul :class="[prefixCls + '-list']">
  10 + <li :class="getCellCls(item)" v-for="item in minutesList" v-show="!item.hide">{{ item.text }}</li>
  11 + </ul>
10 12 </div>
11 13 <div :class="[prefixCls+ '-wrapper']" v-show="showSeconds">
12   - <li v-for="item in secondsList"></li>
  14 + <ul :class="[prefixCls + '-list']">
  15 + <li :class="getCellCls(item)" v-for="item in secondsList" v-show="!item.hide">{{ item.text }}</li>
  16 + </ul>
13 17 </div>
14 18 </div>
15 19 </template>
16 20 <script>
  21 + import Options from '../time-mixins';
  22 + import { deepCopy } from '../../../utils/assist';
  23 +
17 24 const prefixCls = 'ivu-time-picker-cells';
18 25  
19 26 export default {
  27 + mixins: [Options],
20 28 props: {
21 29 hours: {
22 30 type: Number,
... ... @@ -50,17 +58,82 @@
50 58 ];
51 59 },
52 60 hoursList () {
53   - return [];
  61 + let hours = [];
  62 + const hour_tmpl = {
  63 + text: '',
  64 + selected: false,
  65 + disabled: false,
  66 + hide: false
  67 + };
  68 +
  69 + for (let i = 0; i < 24; i++) {
  70 + const hour = deepCopy(hour_tmpl);
  71 + hour.text = i;
  72 +
  73 + if (this.disabledHours && this.disabledHours.indexOf(i) > -1) {
  74 + hour.disabled = true;
  75 + if (this.hideDisabledOptions) hour.hide = true;
  76 + }
  77 + hours.push(hour);
  78 + }
  79 +
  80 + return hours;
54 81 },
55 82 minutesList () {
56   - return [];
  83 + let minutes = [];
  84 + const minute_tmpl = {
  85 + text: '',
  86 + selected: false,
  87 + disabled: false,
  88 + hide: false
  89 + };
  90 +
  91 + for (let i = 0; i < 60; i++) {
  92 + const minute = deepCopy(minute_tmpl);
  93 + minute.text = i;
  94 +
  95 + if (this.disabledMinutes && this.disabledMinutes.indexOf(i) > -1) {
  96 + minute.disabled = true;
  97 + if (this.hideDisabledOptions) minute.hide = true;
  98 + }
  99 + minutes.push(minute);
  100 + }
  101 +
  102 + return minutes;
57 103 },
58 104 secondsList () {
59   - return [];
  105 + let seconds = [];
  106 + const second_tmpl = {
  107 + text: '',
  108 + selected: false,
  109 + disabled: false,
  110 + hide: false
  111 + };
  112 +
  113 + for (let i = 0; i < 60; i++) {
  114 + const second = deepCopy(second_tmpl);
  115 + second.text = i;
  116 +
  117 + if (this.disabledSeconds && this.disabledSeconds.indexOf(i) > -1) {
  118 + second.disabled = true;
  119 + if (this.hideDisabledOptions) second.hide = true;
  120 + }
  121 + seconds.push(second);
  122 + }
  123 +
  124 + return seconds;
60 125 }
61 126 },
62 127 methods: {
63   -
  128 + getCellCls (cell) {
  129 + return [
  130 + `${prefixCls}-cell`,
  131 + {
  132 + [`${prefixCls}-cell-selected`]: cell.selected,
  133 + [`${prefixCls}-cell-disabled`]: cell.disabled
  134 + }
  135 + ];
  136 + }
64 137 }
65 138 };
66 139 </script>
67 140 \ No newline at end of file
... ...
src/components/date-picker/panel/time.vue
... ... @@ -7,6 +7,10 @@
7 7 :hours="hours"
8 8 :minutes="minutes"
9 9 :seconds="seconds"
  10 + :disabled-hours="disabledHours"
  11 + :disabled-minutes="disabledMinutes"
  12 + :disabled-seconds="disabledSeconds"
  13 + :hide-disabled-options="hideDisabledOptions"
10 14 @on-change="handleChange"
11 15 @on-pick-click="handlePickClick"></time-spinner>
12 16 </div>
... ...
test/routers/date.vue
... ... @@ -7,7 +7,7 @@
7 7 <date-picker type="daterange" placement="bottom-end" placeholder="选择日期" style="width: 200px"></date-picker>
8 8 </i-col>
9 9 <i-col span="12">
10   - <time-picker placeholder="选择时间" :disabled-hours="[1,2]" style="width: 200px"></time-picker>
  10 + <time-picker placeholder="选择时间" :hide-disabled-options="false" :disabled-hours="[1,2]" style="width: 200px"></time-picker>
11 11 </i-col>
12 12 </row>
13 13 </template>
... ...