File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6565 this .isOpen = val
6666 }
6767 },
68+ inject: [' collapse' ],
6869 created () {
69- let parent = this .$parent || this .$root
70- let name = parent .$options .name
7170 this .isOpen = this .open
72-
73- while (parent && name !== ' uni-collapse' ) {
74- parent = parent .$parent
75- if (parent) {
76- name = parent .$options .name
71+ this .nameSync = this .name ? this .name : this .collapse .childrens .length
72+ this .collapse .childrens .push (this )
73+ if (String (this .collapse .accordion ) === ' true' ) {
74+ if (this .isOpen ) {
75+ let lastEl = this .collapse .childrens [this .collapse .childrens .length - 2 ]
76+ if (lastEl) {
77+ this .collapse .childrens [this .collapse .childrens .length - 2 ].isOpen = false
78+ }
7779 }
7880 }
79- this .parent = parent
8081 },
8182 // #ifdef H5
8283 mounted () {
9899 if (this .disabled ) {
99100 return
100101 }
101- let accordion = this .parent .accordion ? this .parent .accordion : false
102- if (accordion === true || accordion === ' true' ) {
103- this .$parent .$children .forEach (vm => {
102+ if (String (this .collapse .accordion ) === ' true' ) {
103+ this .collapse .childrens .forEach (vm => {
104104 if (vm === this ) {
105105 return
106106 }
107107 vm .isOpen = false
108108 })
109109 }
110110 this .isOpen = ! this .isOpen
111- this .parent .onChange && this .parent .onChange (this )
111+ this .collapse .onChange && this .collapse .onChange ()
112112 }
113113 }
114114 }
Original file line number Diff line number Diff line change 1515 data () {
1616 return {}
1717 },
18- mounted () {
19- let children = this .$children
20- let childrens = []
21- this .getChildren (children, childrens)
22- this .childrens = childrens
23- childrens .forEach ((vm , index ) => {
24- vm .nameSync = vm .name ? vm .name : index
25- if (this .accordion === true || this .accordion === ' true' ) {
26- childrens .forEach ((v , i ) => {
27- if (index >= i) {
28- return
29- }
30- if (v .isOpen ) {
31- vm .isOpen = false
32- }
33- })
34- }
35- })
18+ provide () {
19+ return {
20+ collapse: this
21+ }
22+ },
23+ created () {
24+ this .childrens = []
3625 },
3726 methods: {
38- onChange (e ) {
27+ onChange () {
3928 let activeItem = []
4029 this .childrens .forEach ((vm , index ) => {
4130 if (vm .isOpen ) {
4231 activeItem .push (vm .nameSync )
4332 }
4433 })
4534 this .$emit (' change' , activeItem)
46- },
47- getChildren (arr , childrens ) {
48- for (let i = 0 , length = arr .length ; i < length; i++ ) {
49- let name = arr[i].$options .name
50- if (name !== ' uni-collapse-item' ) {
51- arr[i].$children && this .getChildren (arr[i].$children , childrens)
52- } else {
53- childrens .push (arr[i])
54- }
55- }
5635 }
5736 }
5837 }
Original file line number Diff line number Diff line change 624624 "navigationBarTitleText" : " Card 卡片"
625625 }
626626 },
627- // #ifdef H5 || APP-PLUS
627+ // #ifdef H5 || APP-PLUS || MP-WEIXIN
628628 {
629629 "path" : " collapse/collapse" ,
630630 "style" : {
Original file line number Diff line number Diff line change 2525 name: ' Card 卡片' ,
2626 url: ' card'
2727 },
28- // #ifdef H5 || APP-PLUS
28+ // #ifdef H5 || APP-PLUS || MP-WEIXIN
2929 {
3030 name: ' Collapse 折叠面板' ,
3131 url: ' collapse'
You can’t perform that action at this time.
0 commit comments