Commit a190ce84be94895d54a54dadaddb0f80e7042b55
1 parent
5d08ddf2
support Collapse
support Collapse
Showing
8 changed files
with
72 additions
and
25 deletions
Show diff stats
CHANGE.md
... | ... | @@ -17,4 +17,6 @@ class 改为了 className |
17 | 17 | ### Progress (名称有警告) |
18 | 18 | 新增 on-status-change 事件 |
19 | 19 | ### Upload |
20 | -父级不能 computed Upload 的 fileList 了 | |
21 | 20 | \ No newline at end of file |
21 | +父级不能 computed Upload 的 fileList 了 | |
22 | +### Collapse | |
23 | +废弃 activeKey,使用 v-model,key 是保留的,更名为 name | |
22 | 24 | \ No newline at end of file | ... | ... |
src/components/collapse/collapse.vue
... | ... | @@ -12,16 +12,21 @@ |
12 | 12 | type: Boolean, |
13 | 13 | default: false |
14 | 14 | }, |
15 | - activeKey: { | |
15 | + value: { | |
16 | 16 | type: [Array, String] |
17 | 17 | } |
18 | 18 | }, |
19 | + data () { | |
20 | + return { | |
21 | + currentValue: this.value | |
22 | + }; | |
23 | + }, | |
19 | 24 | computed: { |
20 | 25 | classes () { |
21 | 26 | return `${prefixCls}`; |
22 | 27 | } |
23 | 28 | }, |
24 | - compiled () { | |
29 | + mounted () { | |
25 | 30 | this.setActive(); |
26 | 31 | }, |
27 | 32 | methods: { |
... | ... | @@ -29,13 +34,13 @@ |
29 | 34 | const activeKey = this.getActiveKey(); |
30 | 35 | |
31 | 36 | this.$children.forEach((child, index) => { |
32 | - const key = child.key || index.toString(); | |
37 | + const name = child.name || index.toString(); | |
33 | 38 | let isActive = false; |
34 | 39 | |
35 | 40 | if (self.accordion) { |
36 | - isActive = activeKey === key; | |
41 | + isActive = activeKey === name; | |
37 | 42 | } else { |
38 | - isActive = activeKey.indexOf(key) > -1; | |
43 | + isActive = activeKey.indexOf(name) > -1; | |
39 | 44 | } |
40 | 45 | |
41 | 46 | child.isActive = isActive; |
... | ... | @@ -43,7 +48,7 @@ |
43 | 48 | }); |
44 | 49 | }, |
45 | 50 | getActiveKey () { |
46 | - let activeKey = this.activeKey || []; | |
51 | + let activeKey = this.currentValue || []; | |
47 | 52 | const accordion = this.accordion; |
48 | 53 | |
49 | 54 | if (!Array.isArray(activeKey)) { |
... | ... | @@ -61,36 +66,40 @@ |
61 | 66 | return activeKey; |
62 | 67 | }, |
63 | 68 | toggle (data) { |
64 | - const key = data.key.toString(); | |
69 | + const name = data.name.toString(); | |
65 | 70 | let newActiveKey = []; |
66 | 71 | |
67 | 72 | if (this.accordion) { |
68 | 73 | if (!data.isActive) { |
69 | - newActiveKey.push(key); | |
74 | + newActiveKey.push(name); | |
70 | 75 | } |
71 | 76 | } else { |
72 | 77 | let activeKey = this.getActiveKey(); |
73 | - const keyIndex = activeKey.indexOf(key); | |
78 | + const nameIndex = activeKey.indexOf(name); | |
74 | 79 | |
75 | 80 | if (data.isActive) { |
76 | - if (keyIndex > -1) { | |
77 | - activeKey.splice(keyIndex, 1); | |
81 | + if (nameIndex > -1) { | |
82 | + activeKey.splice(nameIndex, 1); | |
78 | 83 | } |
79 | 84 | } else { |
80 | - if (keyIndex < 0) { | |
81 | - activeKey.push(key); | |
85 | + if (nameIndex < 0) { | |
86 | + activeKey.push(name); | |
82 | 87 | } |
83 | 88 | } |
84 | 89 | |
85 | 90 | newActiveKey = activeKey; |
86 | 91 | } |
87 | 92 | |
88 | - this.activeKey = newActiveKey; | |
93 | + this.currentValue = newActiveKey; | |
94 | + this.$emit('input', newActiveKey); | |
89 | 95 | this.$emit('on-change', newActiveKey); |
90 | 96 | } |
91 | 97 | }, |
92 | 98 | watch: { |
93 | - activeKey () { | |
99 | + value (val) { | |
100 | + this.currentValue = val; | |
101 | + }, | |
102 | + currentValue () { | |
94 | 103 | this.setActive(); |
95 | 104 | } |
96 | 105 | } | ... | ... |
src/components/collapse/panel.vue
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | <Icon type="arrow-right-b"></Icon> |
5 | 5 | <slot></slot> |
6 | 6 | </div> |
7 | - <div :class="concentClasses" v-show="isActive"> | |
7 | + <div :class="contentClasses" v-show="isActive"> | |
8 | 8 | <div :class="boxClasses"><slot name="content"></slot></div> |
9 | 9 | </div> |
10 | 10 | </div> |
... | ... | @@ -16,13 +16,13 @@ |
16 | 16 | export default { |
17 | 17 | components: { Icon }, |
18 | 18 | props: { |
19 | - key: { | |
19 | + name: { | |
20 | 20 | type: String |
21 | 21 | } |
22 | 22 | }, |
23 | 23 | data () { |
24 | 24 | return { |
25 | - index: 0, // use index for default when key is null | |
25 | + index: 0, // use index for default when name is null | |
26 | 26 | isActive: false |
27 | 27 | }; |
28 | 28 | }, |
... | ... | @@ -38,7 +38,7 @@ |
38 | 38 | headerClasses () { |
39 | 39 | return `${prefixCls}-header`; |
40 | 40 | }, |
41 | - concentClasses () { | |
41 | + contentClasses () { | |
42 | 42 | return `${prefixCls}-content`; |
43 | 43 | }, |
44 | 44 | boxClasses () { |
... | ... | @@ -47,8 +47,9 @@ |
47 | 47 | }, |
48 | 48 | methods: { |
49 | 49 | toggle () { |
50 | + // todo while向上查找 | |
50 | 51 | this.$parent.toggle({ |
51 | - key: this.key || this.index, | |
52 | + name: this.name || this.index, | |
52 | 53 | isActive: this.isActive |
53 | 54 | }); |
54 | 55 | } | ... | ... |
src/components/progress/progress.vue
src/index.js
... | ... | @@ -12,7 +12,7 @@ import Button from './components/button'; |
12 | 12 | // import Cascader from './components/cascader'; |
13 | 13 | import Checkbox from './components/checkbox'; |
14 | 14 | // import Circle from './components/circle'; |
15 | -// import Collapse from './components/collapse'; | |
15 | +import Collapse from './components/collapse'; | |
16 | 16 | // import DatePicker from './components/date-picker'; |
17 | 17 | // import Dropdown from './components/dropdown'; |
18 | 18 | // import Form from './components/form'; |
... | ... | @@ -70,7 +70,7 @@ const iview = { |
70 | 70 | // iForm: Form, |
71 | 71 | // FormItem: Form.Item, |
72 | 72 | iCol: Col, |
73 | - // Collapse, | |
73 | + Collapse, | |
74 | 74 | Icon, |
75 | 75 | // iInput: Input, |
76 | 76 | Input, |
... | ... | @@ -86,7 +86,7 @@ const iview = { |
86 | 86 | // iOption: Option, |
87 | 87 | // OptionGroup, |
88 | 88 | // Page, |
89 | - // Panel: Collapse.Panel, | |
89 | + Panel: Collapse.Panel, | |
90 | 90 | // Poptip, |
91 | 91 | Progress, |
92 | 92 | Radio, | ... | ... |
test/app.vue
... | ... | @@ -28,6 +28,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; } |
28 | 28 | <li><router-link to="/input-number">InputNumber</router-link></li> |
29 | 29 | <li><router-link to="/progress">Progress</router-link></li> |
30 | 30 | <li><router-link to="/upload">Upload</router-link></li> |
31 | + <li><router-link to="/collapse">Collapse</router-link></li> | |
31 | 32 | </ul> |
32 | 33 | </nav> |
33 | 34 | <router-view></router-view> | ... | ... |
test/main.js
1 | +<template> | |
2 | + <div> | |
3 | + <Collapse v-model="v1" accordion> | |
4 | + <Panel name="1"> | |
5 | + 史蒂夫·乔布斯 | |
6 | + <p slot="content">史蒂夫·乔布斯(Steve Jobs),1955年2月24日生于美国加利福尼亚州旧金山,美国发明家、企业家、美国苹果公司联合创办人。</p> | |
7 | + </Panel> | |
8 | + <Panel name="2"> | |
9 | + 斯蒂夫·盖瑞·沃兹尼亚克 | |
10 | + <p slot="content">斯蒂夫·盖瑞·沃兹尼亚克(Stephen Gary Wozniak),美国电脑工程师,曾与史蒂夫·乔布斯合伙创立苹果电脑(今之苹果公司)。斯蒂夫·盖瑞·沃兹尼亚克曾就读于美国科罗拉多大学,后转学入美国著名高等学府加州大学伯克利分校(UC Berkeley)并获得电机工程及计算机(EECS)本科学位(1987年)。</p> | |
11 | + </Panel> | |
12 | + <Panel name="3"> | |
13 | + 乔纳森·伊夫 | |
14 | + <p slot="content">乔纳森·伊夫是一位工业设计师,现任Apple公司设计师兼资深副总裁,英国爵士。他曾参与设计了iPod,iMac,iPhone,iPad等众多苹果产品。除了乔布斯,他是对苹果那些著名的产品最有影响力的人。</p> | |
15 | + </Panel> | |
16 | + </Collapse> | |
17 | + </div> | |
18 | +</template> | |
19 | +<script> | |
20 | + export default { | |
21 | + props: {}, | |
22 | + data () { | |
23 | + return { | |
24 | + v1: '2' | |
25 | + }; | |
26 | + }, | |
27 | + computed: {}, | |
28 | + methods: {} | |
29 | + }; | |
30 | +</script> | |
0 | 31 | \ No newline at end of file | ... | ... |