Commit eb7f31db00f8aad1a17692d251f11172c2c2c9cd
1 parent
ac2f8493
Switch add loading prop
Showing
3 changed files
with
65 additions
and
9 deletions
Show diff stats
examples/routers/switch.vue
1 | 1 | <template> |
2 | 2 | <div> |
3 | - <i-switch v-model="m1" true-value="yes" false-value="no"> | |
3 | + <i-switch v-model="m1" :loading="loading"> | |
4 | 4 | <span slot="open">开</span> |
5 | 5 | <span slot="close">关</span> |
6 | 6 | </i-switch> |
7 | 7 | {{ m1 }} |
8 | - <div @click="m1 = 'no'">toggle</div> | |
8 | + <div @click="m1 = !m1">toggle</div> | |
9 | + <div @click="loading = !loading">loading</div> | |
9 | 10 | <br><br> |
10 | - <i-switch size="large"></i-switch> | |
11 | + <i-switch size="large" loading></i-switch> | |
11 | 12 | <i-switch></i-switch> |
12 | - <i-switch size="small"></i-switch> | |
13 | + <i-switch size="small" v-model="m1" :loading="loading"></i-switch> | |
13 | 14 | <br><br> |
14 | 15 | <i-switch> |
15 | 16 | <span slot="open">开</span> |
... | ... | @@ -24,7 +25,7 @@ |
24 | 25 | <span slot="open">开启</span> |
25 | 26 | <span slot="close">关闭</span> |
26 | 27 | </i-switch> |
27 | - <i-switch size="large"> | |
28 | + <i-switch size="large" v-model="m1" :loading="loading"> | |
28 | 29 | <span slot="open">ON</span> |
29 | 30 | <span slot="close">OFF</span> |
30 | 31 | </i-switch> |
... | ... | @@ -37,8 +38,9 @@ |
37 | 38 | export default { |
38 | 39 | data () { |
39 | 40 | return { |
40 | - m1: 'yes', | |
41 | - disabled: true | |
41 | + m1: true, | |
42 | + disabled: true, | |
43 | + loading: false | |
42 | 44 | } |
43 | 45 | }, |
44 | 46 | methods: { | ... | ... |
src/components/switch/switch.vue
... | ... | @@ -45,6 +45,10 @@ |
45 | 45 | }, |
46 | 46 | name: { |
47 | 47 | type: String |
48 | + }, | |
49 | + loading: { | |
50 | + type: Boolean, | |
51 | + default: false | |
48 | 52 | } |
49 | 53 | }, |
50 | 54 | data () { |
... | ... | @@ -59,7 +63,8 @@ |
59 | 63 | { |
60 | 64 | [`${prefixCls}-checked`]: this.currentValue === this.trueValue, |
61 | 65 | [`${prefixCls}-disabled`]: this.disabled, |
62 | - [`${prefixCls}-${this.size}`]: !!this.size | |
66 | + [`${prefixCls}-${this.size}`]: !!this.size, | |
67 | + [`${prefixCls}-loading`]: this.loading, | |
63 | 68 | } |
64 | 69 | ]; |
65 | 70 | }, |
... | ... | @@ -70,7 +75,7 @@ |
70 | 75 | methods: { |
71 | 76 | toggle (event) { |
72 | 77 | event.preventDefault(); |
73 | - if (this.disabled) { | |
78 | + if (this.disabled || this.loading) { | |
74 | 79 | return false; |
75 | 80 | } |
76 | 81 | ... | ... |
src/styles/components/switch.less
... | ... | @@ -14,6 +14,10 @@ |
14 | 14 | user-select: none; |
15 | 15 | transition: all @transition-time @ease-in-out; |
16 | 16 | |
17 | + &-loading{ | |
18 | + opacity: .4; | |
19 | + } | |
20 | + | |
17 | 21 | &-inner { |
18 | 22 | color: #fff; |
19 | 23 | font-size: @font-size-small; |
... | ... | @@ -44,6 +48,26 @@ |
44 | 48 | width: 26px; |
45 | 49 | } |
46 | 50 | |
51 | + &:before{ | |
52 | + content: ''; | |
53 | + display: none; | |
54 | + width: 14px; | |
55 | + height: 14px; | |
56 | + border-radius: 50%; | |
57 | + background-color: transparent; | |
58 | + position: absolute; | |
59 | + left: 3px; | |
60 | + top: 3px; | |
61 | + z-index: 1; | |
62 | + border: 1px solid @primary-color; | |
63 | + border-color: transparent transparent transparent @primary-color; | |
64 | + animation: switch-loading 1s linear; | |
65 | + animation-iteration-count: infinite; | |
66 | + } | |
67 | + &-loading:before{ | |
68 | + display: block; | |
69 | + } | |
70 | + | |
47 | 71 | &:focus { |
48 | 72 | box-shadow: 0 0 0 2px fade(@primary-color, 20%); |
49 | 73 | outline: 0; |
... | ... | @@ -64,11 +88,20 @@ |
64 | 88 | &:active:after { |
65 | 89 | width: 14px; |
66 | 90 | } |
91 | + &:before{ | |
92 | + width: 10px; | |
93 | + height: 10px; | |
94 | + left: 2px; | |
95 | + top: 2px; | |
96 | + } | |
67 | 97 | } |
68 | 98 | |
69 | 99 | &-small&-checked:after { |
70 | 100 | left: 13px; |
71 | 101 | } |
102 | + &-small&-checked:before { | |
103 | + left: 14px; | |
104 | + } | |
72 | 105 | |
73 | 106 | &-small:active&-checked:after { |
74 | 107 | left: 11px; |
... | ... | @@ -88,6 +121,9 @@ |
88 | 121 | &-large&-checked:after { |
89 | 122 | left: 35px; |
90 | 123 | } |
124 | + &-large&-checked:before { | |
125 | + left: 37px; | |
126 | + } | |
91 | 127 | |
92 | 128 | &-large:active&-checked:after { |
93 | 129 | left: 23px; |
... | ... | @@ -104,6 +140,9 @@ |
104 | 140 | &:after { |
105 | 141 | left: 23px; |
106 | 142 | } |
143 | + &:before{ | |
144 | + left: 25px; | |
145 | + } | |
107 | 146 | |
108 | 147 | &:active:after { |
109 | 148 | left: 15px; |
... | ... | @@ -124,4 +163,14 @@ |
124 | 163 | color: #ccc; |
125 | 164 | } |
126 | 165 | } |
166 | + | |
127 | 167 | } |
168 | + | |
169 | +@keyframes switch-loading { | |
170 | + 0% { | |
171 | + transform: rotate(0); | |
172 | + } | |
173 | + 100% { | |
174 | + transform: rotate(360deg); | |
175 | + } | |
176 | +} | |
128 | 177 | \ No newline at end of file | ... | ... |