tui-collapse.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="tui-collapse" :style="{backgroundColor:bgColor}">
  3. <view class="tui-collapse-head" :style="{backgroundColor:hdBgColor}" @tap.stop="handleClick">
  4. <view class="tui-header" :class="{'tui-opacity':disabled}">
  5. <slot name="title"></slot>
  6. <view class="open" v-if="!isOpen">
  7. 展开
  8. </view>
  9. <view class="open" v-else>
  10. 收起
  11. </view>
  12. <view class="tui-collapse-icon tui-icon-arrow" :class="{'tui-icon-active':isOpen}" :style="{color:arrowColor}" v-if="arrow"></view>
  13. </view>
  14. </view>
  15. <view class="tui-collapse-body_box" :style="{backgroundColor:bdBgColor,height:isOpen?height:'0rpx'}">
  16. <view class="tui-collapse-body" :class="{'tui-collapse-transform':height=='auto','tui-collapse-body_show':isOpen && height=='auto'}">
  17. <slot name="content"></slot>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. name: "tuiCollapse",
  25. emits: ['click'],
  26. props: {
  27. //collapse背景颜色
  28. bgColor: {
  29. type: String,
  30. default: 'transparent'
  31. },
  32. //collapse-head 背景颜色
  33. hdBgColor: {
  34. type: String,
  35. default: '#fff'
  36. },
  37. //collapse-body 背景颜色
  38. bdBgColor: {
  39. type: String,
  40. default: 'transparent'
  41. },
  42. //collapse-body实际高度 open时使用
  43. height: {
  44. type: String,
  45. default: 'auto'
  46. },
  47. //索引
  48. index: {
  49. type: Number,
  50. default: 0
  51. },
  52. //当前索引,index==current时展开
  53. current: {
  54. type: Number,
  55. default: -1
  56. },
  57. // 是否禁用
  58. disabled: {
  59. type: [Boolean, String],
  60. default: false
  61. },
  62. //是否带箭头
  63. arrow: {
  64. type: [Boolean, String],
  65. default: true
  66. },
  67. //箭头颜色
  68. arrowColor: {
  69. type: String,
  70. default: "#666666"
  71. }
  72. },
  73. watch: {
  74. current() {
  75. this.updateCurrentChange()
  76. }
  77. },
  78. created() {
  79. this.updateCurrentChange()
  80. },
  81. data() {
  82. return {
  83. isOpen: false
  84. };
  85. },
  86. methods: {
  87. updateCurrentChange() {
  88. this.isOpen = this.index == this.current
  89. },
  90. handleClick() {
  91. if (this.disabled) return;
  92. this.$emit("click", {
  93. index: Number(this.index)
  94. })
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. @font-face {
  101. font-family: 'tuiCollapse';
  102. src: url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAQ4AA0AAAAABlgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAAEHAAAABoAAAAciRx3B0dERUYAAAP8AAAAHgAAAB4AKQAKT1MvMgAAAaAAAABCAAAAVjxuR/JjbWFwAAAB9AAAAD4AAAFCAA/pq2dhc3AAAAP0AAAACAAAAAj//wADZ2x5ZgAAAkAAAABEAAAARCs1U/toZWFkAAABMAAAADAAAAA2FpaT+mhoZWEAAAFgAAAAHQAAACQHngOFaG10eAAAAeQAAAAPAAAAEAwAAEBsb2NhAAACNAAAAAoAAAAKACIAAG1heHAAAAGAAAAAHwAAACABDwAdbmFtZQAAAoQAAAFJAAACiCnmEVVwb3N0AAAD0AAAACMAAAA1DunpUnjaY2BkYGAAYja/oO54fpuvDNwsDCBwc4/6fzjtwNDNfICpBMjlYGACiQIAGVAKZnjaY2BkYGBu+N/AEMPCAALMBxgYGVABCwBVNgMsAAAAeNpjYGRgYGBhEGQA0QwMTEDMBYQMDP/BfAYACnYBLQB42mNgZGFgnMDAysDA1Ml0hoGBoR9CM75mMGLkAIoysDIzYAUBaa4pDA7PGJ4xMDf8b2CIYW5gaAAKM4LkANq9C9sAAHjaY2GAABYIdgAAAMAATQB42mNgYGBmgGAZBkYGELAB8hjBfBYGBSDNAoRA/jOG//8hpBQzVCUDIxsDjMnAyAQkmBhQASPDsAcAMCAGoQAAAAAAAAAAAAAAIgAAAAEAQACLA8ACdAAQAAAlASYiBhQXARYyNwE2NCYiBwIA/oYNIBkMAZcNIA0BlwwZIA3uAXoMGSAN/mkMDAGXDSAZDAB42n2QPU4DMRCFn/MHJBJCIKhdUQDa/JQpEyn0CKWjSDbekGjXXnmdSDkBLRUHoOUYHIAbINFyCl6WSZMia+3o85uZ57EBnOMbCv/fJe6EFY7xKFzBETLhKvUX4Rr5XbiOFj6FG9R/hJu4VQPhFi7UGx1U7YS7m9JtywpnGAhXcIon4Sr1lXCN/CpcxxU+hBvUv4SbGONXuIVrZakM4WEwQWCcQWOKDeMCMRwskjIG1qE59GYSzExPN3oRO5s4GyjvV2KXAx5oOeeAKe09t2a+Sif+YMuB1JhuHgVLtimNLiJ0KBtfLJzV3ahzsP2e7ba02L9rgTXH7FENbNT8Pdsz0khsDK+QkjXyMrekElOPaGus8btnKdbzXgiJTrzL9IjHmjR1OvduaeLA4ufyjBx9tLmSPfeoHD5jWQh5v91OxCCKXYY/k9hxGQAAAHjaY2BigAAuMMnIgA5YwKJMjExciUVF+eW6KfnleQAZ0wQyAAAAAAH//wACAAEAAAAMAAAAFgAAAAIAAQADAAMAAQAEAAAAAgAAAAB42mNgYGBkAIKrS9Q5QPTNPer/YTQAQ+0HIAAA) format('woff');
  103. font-weight: normal;
  104. font-style: normal;
  105. }
  106. .tui-collapse-icon {
  107. font-family: "tuiCollapse" !important;
  108. font-style: normal;
  109. -webkit-font-smoothing: antialiased;
  110. -moz-osx-font-smoothing: grayscale;
  111. }
  112. .tui-icon-arrow:before {
  113. content: "\e600";
  114. }
  115. .open {
  116. position: absolute;
  117. top: 22rpx;
  118. right: 50rpx;
  119. font-size: 20rpx;
  120. font-weight: 400;
  121. color: #666666;
  122. margin-right: 10rpx;
  123. }
  124. .tui-icon-arrow {
  125. font-size: 16rpx;
  126. transform: rotate(0);
  127. transform-origin: center center;
  128. transition: all 0.3s;
  129. position: absolute;
  130. top: 50%;
  131. margin-top: -8px;
  132. right: 30rpx;
  133. }
  134. .tui-arrow-padding {
  135. padding-right: 62rpx;
  136. box-sizing: border-box;
  137. }
  138. .tui-icon-active {
  139. transform: rotate(180deg);
  140. transform-origin: center center;
  141. }
  142. .tui-header {
  143. position: relative;
  144. z-index: 2;
  145. }
  146. .tui-collapse-body_box{
  147. transition: all 0.25s;
  148. overflow: hidden;
  149. }
  150. .tui-collapse-body {
  151. transition: all 0.25s;
  152. overflow: hidden;
  153. position: relative;
  154. z-index: 1;
  155. }
  156. .tui-collapse-transform {
  157. opacity: 0;
  158. visibility: hidden;
  159. -webkit-transform: translateY(-40%);
  160. transform: translateY(-40%);
  161. }
  162. .tui-collapse-body_show {
  163. opacity: 1;
  164. visibility: visible;
  165. -webkit-transform: translateY(0);
  166. transform: translateY(0);
  167. }
  168. .tui-opacity {
  169. opacity: 0.6;
  170. }
  171. </style>