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,4 +17,6 @@ class 改为了 className | ||
17 | ### Progress (名称有警告) | 17 | ### Progress (名称有警告) |
18 | 新增 on-status-change 事件 | 18 | 新增 on-status-change 事件 |
19 | ### Upload | 19 | ### Upload |
20 | -父级不能 computed Upload 的 fileList 了 | ||
21 | \ No newline at end of file | 20 | \ No newline at end of file |
21 | +父级不能 computed Upload 的 fileList 了 | ||
22 | +### Collapse | ||
23 | +废弃 activeKey,使用 v-model,key 是保留的,更名为 name | ||
22 | \ No newline at end of file | 24 | \ No newline at end of file |
src/components/collapse/collapse.vue
@@ -12,16 +12,21 @@ | @@ -12,16 +12,21 @@ | ||
12 | type: Boolean, | 12 | type: Boolean, |
13 | default: false | 13 | default: false |
14 | }, | 14 | }, |
15 | - activeKey: { | 15 | + value: { |
16 | type: [Array, String] | 16 | type: [Array, String] |
17 | } | 17 | } |
18 | }, | 18 | }, |
19 | + data () { | ||
20 | + return { | ||
21 | + currentValue: this.value | ||
22 | + }; | ||
23 | + }, | ||
19 | computed: { | 24 | computed: { |
20 | classes () { | 25 | classes () { |
21 | return `${prefixCls}`; | 26 | return `${prefixCls}`; |
22 | } | 27 | } |
23 | }, | 28 | }, |
24 | - compiled () { | 29 | + mounted () { |
25 | this.setActive(); | 30 | this.setActive(); |
26 | }, | 31 | }, |
27 | methods: { | 32 | methods: { |
@@ -29,13 +34,13 @@ | @@ -29,13 +34,13 @@ | ||
29 | const activeKey = this.getActiveKey(); | 34 | const activeKey = this.getActiveKey(); |
30 | 35 | ||
31 | this.$children.forEach((child, index) => { | 36 | this.$children.forEach((child, index) => { |
32 | - const key = child.key || index.toString(); | 37 | + const name = child.name || index.toString(); |
33 | let isActive = false; | 38 | let isActive = false; |
34 | 39 | ||
35 | if (self.accordion) { | 40 | if (self.accordion) { |
36 | - isActive = activeKey === key; | 41 | + isActive = activeKey === name; |
37 | } else { | 42 | } else { |
38 | - isActive = activeKey.indexOf(key) > -1; | 43 | + isActive = activeKey.indexOf(name) > -1; |
39 | } | 44 | } |
40 | 45 | ||
41 | child.isActive = isActive; | 46 | child.isActive = isActive; |
@@ -43,7 +48,7 @@ | @@ -43,7 +48,7 @@ | ||
43 | }); | 48 | }); |
44 | }, | 49 | }, |
45 | getActiveKey () { | 50 | getActiveKey () { |
46 | - let activeKey = this.activeKey || []; | 51 | + let activeKey = this.currentValue || []; |
47 | const accordion = this.accordion; | 52 | const accordion = this.accordion; |
48 | 53 | ||
49 | if (!Array.isArray(activeKey)) { | 54 | if (!Array.isArray(activeKey)) { |
@@ -61,36 +66,40 @@ | @@ -61,36 +66,40 @@ | ||
61 | return activeKey; | 66 | return activeKey; |
62 | }, | 67 | }, |
63 | toggle (data) { | 68 | toggle (data) { |
64 | - const key = data.key.toString(); | 69 | + const name = data.name.toString(); |
65 | let newActiveKey = []; | 70 | let newActiveKey = []; |
66 | 71 | ||
67 | if (this.accordion) { | 72 | if (this.accordion) { |
68 | if (!data.isActive) { | 73 | if (!data.isActive) { |
69 | - newActiveKey.push(key); | 74 | + newActiveKey.push(name); |
70 | } | 75 | } |
71 | } else { | 76 | } else { |
72 | let activeKey = this.getActiveKey(); | 77 | let activeKey = this.getActiveKey(); |
73 | - const keyIndex = activeKey.indexOf(key); | 78 | + const nameIndex = activeKey.indexOf(name); |
74 | 79 | ||
75 | if (data.isActive) { | 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 | } else { | 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 | newActiveKey = activeKey; | 90 | newActiveKey = activeKey; |
86 | } | 91 | } |
87 | 92 | ||
88 | - this.activeKey = newActiveKey; | 93 | + this.currentValue = newActiveKey; |
94 | + this.$emit('input', newActiveKey); | ||
89 | this.$emit('on-change', newActiveKey); | 95 | this.$emit('on-change', newActiveKey); |
90 | } | 96 | } |
91 | }, | 97 | }, |
92 | watch: { | 98 | watch: { |
93 | - activeKey () { | 99 | + value (val) { |
100 | + this.currentValue = val; | ||
101 | + }, | ||
102 | + currentValue () { | ||
94 | this.setActive(); | 103 | this.setActive(); |
95 | } | 104 | } |
96 | } | 105 | } |
src/components/collapse/panel.vue
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | <Icon type="arrow-right-b"></Icon> | 4 | <Icon type="arrow-right-b"></Icon> |
5 | <slot></slot> | 5 | <slot></slot> |
6 | </div> | 6 | </div> |
7 | - <div :class="concentClasses" v-show="isActive"> | 7 | + <div :class="contentClasses" v-show="isActive"> |
8 | <div :class="boxClasses"><slot name="content"></slot></div> | 8 | <div :class="boxClasses"><slot name="content"></slot></div> |
9 | </div> | 9 | </div> |
10 | </div> | 10 | </div> |
@@ -16,13 +16,13 @@ | @@ -16,13 +16,13 @@ | ||
16 | export default { | 16 | export default { |
17 | components: { Icon }, | 17 | components: { Icon }, |
18 | props: { | 18 | props: { |
19 | - key: { | 19 | + name: { |
20 | type: String | 20 | type: String |
21 | } | 21 | } |
22 | }, | 22 | }, |
23 | data () { | 23 | data () { |
24 | return { | 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 | isActive: false | 26 | isActive: false |
27 | }; | 27 | }; |
28 | }, | 28 | }, |
@@ -38,7 +38,7 @@ | @@ -38,7 +38,7 @@ | ||
38 | headerClasses () { | 38 | headerClasses () { |
39 | return `${prefixCls}-header`; | 39 | return `${prefixCls}-header`; |
40 | }, | 40 | }, |
41 | - concentClasses () { | 41 | + contentClasses () { |
42 | return `${prefixCls}-content`; | 42 | return `${prefixCls}-content`; |
43 | }, | 43 | }, |
44 | boxClasses () { | 44 | boxClasses () { |
@@ -47,8 +47,9 @@ | @@ -47,8 +47,9 @@ | ||
47 | }, | 47 | }, |
48 | methods: { | 48 | methods: { |
49 | toggle () { | 49 | toggle () { |
50 | + // todo while向上查找 | ||
50 | this.$parent.toggle({ | 51 | this.$parent.toggle({ |
51 | - key: this.key || this.index, | 52 | + name: this.name || this.index, |
52 | isActive: this.isActive | 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,7 +12,7 @@ import Button from './components/button'; | ||
12 | // import Cascader from './components/cascader'; | 12 | // import Cascader from './components/cascader'; |
13 | import Checkbox from './components/checkbox'; | 13 | import Checkbox from './components/checkbox'; |
14 | // import Circle from './components/circle'; | 14 | // import Circle from './components/circle'; |
15 | -// import Collapse from './components/collapse'; | 15 | +import Collapse from './components/collapse'; |
16 | // import DatePicker from './components/date-picker'; | 16 | // import DatePicker from './components/date-picker'; |
17 | // import Dropdown from './components/dropdown'; | 17 | // import Dropdown from './components/dropdown'; |
18 | // import Form from './components/form'; | 18 | // import Form from './components/form'; |
@@ -70,7 +70,7 @@ const iview = { | @@ -70,7 +70,7 @@ const iview = { | ||
70 | // iForm: Form, | 70 | // iForm: Form, |
71 | // FormItem: Form.Item, | 71 | // FormItem: Form.Item, |
72 | iCol: Col, | 72 | iCol: Col, |
73 | - // Collapse, | 73 | + Collapse, |
74 | Icon, | 74 | Icon, |
75 | // iInput: Input, | 75 | // iInput: Input, |
76 | Input, | 76 | Input, |
@@ -86,7 +86,7 @@ const iview = { | @@ -86,7 +86,7 @@ const iview = { | ||
86 | // iOption: Option, | 86 | // iOption: Option, |
87 | // OptionGroup, | 87 | // OptionGroup, |
88 | // Page, | 88 | // Page, |
89 | - // Panel: Collapse.Panel, | 89 | + Panel: Collapse.Panel, |
90 | // Poptip, | 90 | // Poptip, |
91 | Progress, | 91 | Progress, |
92 | Radio, | 92 | Radio, |
test/app.vue
@@ -28,6 +28,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; } | @@ -28,6 +28,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; } | ||
28 | <li><router-link to="/input-number">InputNumber</router-link></li> | 28 | <li><router-link to="/input-number">InputNumber</router-link></li> |
29 | <li><router-link to="/progress">Progress</router-link></li> | 29 | <li><router-link to="/progress">Progress</router-link></li> |
30 | <li><router-link to="/upload">Upload</router-link></li> | 30 | <li><router-link to="/upload">Upload</router-link></li> |
31 | + <li><router-link to="/collapse">Collapse</router-link></li> | ||
31 | </ul> | 32 | </ul> |
32 | </nav> | 33 | </nav> |
33 | <router-view></router-view> | 34 | <router-view></router-view> |
test/main.js
@@ -76,6 +76,10 @@ const router = new VueRouter({ | @@ -76,6 +76,10 @@ const router = new VueRouter({ | ||
76 | { | 76 | { |
77 | path: '/progress', | 77 | path: '/progress', |
78 | component: require('./routers/progress.vue') | 78 | component: require('./routers/progress.vue') |
79 | + }, | ||
80 | + { | ||
81 | + path: '/collapse', | ||
82 | + component: require('./routers/collapse.vue') | ||
79 | } | 83 | } |
80 | ] | 84 | ] |
81 | }); | 85 | }); |
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 | \ No newline at end of file | 31 | \ No newline at end of file |