Commit 165bb7c9ed134eaebe5cdfce6ff5634c49635942
1 parent
bd4e3b9b
update Cascader
update Cascader
Showing
7 changed files
with
54 additions
and
31 deletions
Show diff stats
src/components/cascader/cascader.vue
... | ... | @@ -92,7 +92,8 @@ |
92 | 92 | return [ |
93 | 93 | `${prefixCls}`, |
94 | 94 | { |
95 | - [`${prefixCls}-show-clear`]: this.showCloseIcon | |
95 | + [`${prefixCls}-show-clear`]: this.showCloseIcon, | |
96 | + [`${prefixCls}-visible`]: this.visible | |
96 | 97 | } |
97 | 98 | ] |
98 | 99 | }, |
... | ... | @@ -105,28 +106,42 @@ |
105 | 106 | label.push(this.selected[i].label); |
106 | 107 | } |
107 | 108 | |
108 | - return this.renderFormat(label); | |
109 | + return this.renderFormat(label, this.selected); | |
109 | 110 | } |
110 | 111 | }, |
111 | 112 | methods: { |
112 | 113 | clearSelect () { |
113 | - | |
114 | + const oldVal = JSON.stringify(this.value); | |
115 | + this.value = this.selected = this.tmpSelected = []; | |
116 | + this.handleClose(); | |
117 | + this.emitValue(this.value, oldVal); | |
118 | + this.$broadcast('on-clear'); | |
114 | 119 | }, |
115 | 120 | handleClose () { |
116 | 121 | this.visible = false; |
117 | 122 | }, |
118 | 123 | onFocus () { |
119 | 124 | this.visible = true; |
125 | + if (!this.value.length) { | |
126 | + this.$broadcast('on-clear'); | |
127 | + } | |
120 | 128 | }, |
121 | 129 | updateResult (result) { |
122 | 130 | this.tmpSelected = result; |
123 | 131 | }, |
124 | - updateSelected () { | |
125 | - this.$broadcast('on-find-selected', this.value); | |
132 | + updateSelected (init = false) { | |
133 | + if (!this.changeOnSelect || init) { | |
134 | + this.$broadcast('on-find-selected', this.value); | |
135 | + } | |
136 | + }, | |
137 | + emitValue (val, oldVal) { | |
138 | + if (JSON.stringify(val) !== oldVal) { | |
139 | + this.$emit('on-change', this.value, JSON.parse(JSON.stringify(this.selected))); | |
140 | + } | |
126 | 141 | } |
127 | 142 | }, |
128 | 143 | ready () { |
129 | - this.updateSelected(); | |
144 | + this.updateSelected(true); | |
130 | 145 | }, |
131 | 146 | events: { |
132 | 147 | // lastValue: is click the final val |
... | ... | @@ -140,10 +155,10 @@ |
140 | 155 | this.selected.forEach((item) => { |
141 | 156 | newVal.push(item.value); |
142 | 157 | }); |
143 | - this.value = newVal; | |
144 | 158 | |
145 | - if (JSON.stringify(this.value) !== oldVal) { | |
146 | - this.$emit('on-change', this.value); | |
159 | + if (!fromInit) { | |
160 | + this.value = newVal; | |
161 | + this.emitValue(this.value, oldVal); | |
147 | 162 | } |
148 | 163 | } |
149 | 164 | if (lastValue && !fromInit) { | ... | ... |
src/components/cascader/casitem.vue
src/components/cascader/caspanel.vue
src/styles/components/cascader.less
... | ... | @@ -24,14 +24,10 @@ |
24 | 24 | } |
25 | 25 | |
26 | 26 | &-arrow { |
27 | - position: absolute; | |
28 | - top: 50%; | |
29 | - right: 8px; | |
30 | - line-height: 1; | |
31 | - margin-top: -6px; | |
32 | - font-size: @font-size-base; | |
33 | - color: @subsidiary-color; | |
34 | - .transition(all @transition-time @ease-in-out); | |
27 | + .inner-arrow(); | |
28 | + } | |
29 | + &-visible &-arrow:nth-of-type(2){ | |
30 | + .transform(rotate(180deg)); | |
35 | 31 | } |
36 | 32 | |
37 | 33 | .@{select-dropdown-prefix-cls} { |
... | ... | @@ -78,7 +74,7 @@ |
78 | 74 | |
79 | 75 | &-active{ |
80 | 76 | background-color: @background-color-select-hover; |
81 | - font-weight: bold; | |
77 | + color: @primary-color; | |
82 | 78 | } |
83 | 79 | } |
84 | 80 | } | ... | ... |
src/styles/components/select.less
... | ... | @@ -41,13 +41,7 @@ |
41 | 41 | } |
42 | 42 | |
43 | 43 | &-arrow { |
44 | - position: absolute; | |
45 | - top: 50%; | |
46 | - right: 8px; | |
47 | - line-height: 1; | |
48 | - margin-top: -6px; | |
49 | - color: @subsidiary-color; | |
50 | - .transition(all @transition-time @ease-in-out); | |
44 | + .inner-arrow(); | |
51 | 45 | } |
52 | 46 | |
53 | 47 | &-visible{ | ... | ... |
src/styles/mixins/common.less
... | ... | @@ -18,4 +18,16 @@ |
18 | 18 | -webkit-user-select: @type; |
19 | 19 | -moz-user-select: @type; |
20 | 20 | user-select: @type; |
21 | +} | |
22 | + | |
23 | +// for select and input like component's arrow | |
24 | +.inner-arrow() { | |
25 | + position: absolute; | |
26 | + top: 50%; | |
27 | + right: 8px; | |
28 | + line-height: 1; | |
29 | + margin-top: -7px; | |
30 | + font-size: @font-size-base; | |
31 | + color: @subsidiary-color; | |
32 | + .transition(all @transition-time @ease-in-out); | |
21 | 33 | } |
22 | 34 | \ No newline at end of file | ... | ... |
test/routers/cascader.vue
1 | 1 | <template> |
2 | 2 | <div style="margin: 50px;width:300px"> |
3 | - <Cascader :data="data" :value.sync="value" @on-change="change" trigger="click"></Cascader> | |
3 | + {{ value | json }} | |
4 | + <Cascader size="large" :data="data" :value.sync="value" @on-change="change" trigger="hover" :render-format="format"></Cascader> | |
4 | 5 | </div> |
5 | 6 | </template> |
6 | 7 | <script> |
... | ... | @@ -50,8 +51,12 @@ |
50 | 51 | |
51 | 52 | }, |
52 | 53 | methods: { |
53 | - change (data) { | |
54 | - console.log(data) | |
54 | + change (data, opts) { | |
55 | + console.log(data); | |
56 | + console.log(opts) | |
57 | + }, | |
58 | + format (label, data) { | |
59 | + return label[label.length - 1]; | |
55 | 60 | } |
56 | 61 | } |
57 | 62 | } | ... | ... |