uni-collapse-item.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view :class="{ 'uni-collapse-cell--disabled': disabled,'uni-collapse-cell--notdisabled': !disabled, 'uni-collapse-cell--open': isOpen,'uni-collapse-cell--hide':!isOpen }" class="uni-collapse-cell">
  3. <view class="uni-collapse-cell__title">
  4. <image v-if="thumb" :src="thumb" class="uni-collapse-cell__title-img" />
  5. <text class="uni-collapse-cell__title-text">{{ title }}</text>
  6. <!-- #ifdef MP-ALIPAY -->
  7. <view :class="{ 'uni-collapse-cell__title-arrow-active': isOpen, 'uni-collapse-cell--animation': showAnimation === true }" class="uni-collapse-cell__title-arrow">
  8. <!-- <uni-icons color="#fff" size="20" type="arrowdown" /> -->
  9. </view>
  10. <!-- #endif -->
  11. <!-- #ifndef MP-ALIPAY -->
  12. <!-- <uni-icons :class="{ 'uni-collapse-cell__title-arrow-active': isOpen, 'uni-collapse-cell--animation': showAnimation === true }" class="uni-collapse-cell__title-arrow" color="#fff" size="20" type="arrowdown" /> -->
  13. <!-- #endif -->
  14. </view>
  15. <view :class="{'uni-collapse-cell__content--hide':!isOpen}" class="uni-collapse-cell__content">
  16. <view :class="{ 'uni-collapse-cell--animation': showAnimation === true }" class="uni-collapse-cell__wrapper" :style="{'transform':isOpen?'translateY(0)':'translateY(-50%)','-webkit-transform':isOpen?'translateY(0)':'translateY(-50%)'}">
  17. <slot />
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import uniIcons from '../uni-icons/uni-icons.vue'
  24. /**
  25. * CollapseItem 折叠面板子组件
  26. * @description 折叠面板子组件
  27. * @property {String} title 标题文字
  28. * @property {String} thumb 标题左侧缩略图
  29. * @property {Boolean} disabled = [true|false] 是否展开面板
  30. * @property {Boolean} showAnimation = [true|false] 开启动画
  31. */
  32. export default {
  33. name: 'UniCollapseItem',
  34. components: {
  35. uniIcons
  36. },
  37. props: {
  38. title: {
  39. // 列表标题
  40. type: String,
  41. default: ''
  42. },
  43. name: {
  44. // 唯一标识符
  45. type: [Number, String],
  46. default: 0
  47. },
  48. disabled: {
  49. // 是否禁用
  50. type: Boolean,
  51. default: false
  52. },
  53. showAnimation: {
  54. // 是否显示动画
  55. type: Boolean,
  56. default: false
  57. },
  58. open: {
  59. // 是否展开
  60. type: Boolean,
  61. default: true
  62. },
  63. thumb: {
  64. // 缩略图
  65. type: String,
  66. default: ''
  67. }
  68. },
  69. data() {
  70. return {
  71. isOpen: true
  72. }
  73. },
  74. watch: {
  75. open(val) {
  76. this.isOpen = val
  77. }
  78. },
  79. inject: ['collapse'],
  80. created() {
  81. this.isOpen = this.open
  82. this.nameSync = this.name ? this.name : this.collapse.childrens.length
  83. this.collapse.childrens.push(this)
  84. if (String(this.collapse.accordion) === 'true') {
  85. if (this.isOpen) {
  86. let lastEl = this.collapse.childrens[this.collapse.childrens.length - 2]
  87. if (lastEl) {
  88. this.collapse.childrens[this.collapse.childrens.length - 2].isOpen = false
  89. }
  90. }
  91. }
  92. },
  93. methods: {
  94. // onClick() {
  95. // if (this.disabled) {
  96. // return
  97. // }
  98. // if (String(this.collapse.accordion) === 'true') {
  99. // this.collapse.childrens.forEach(vm => {
  100. // if (vm === this) {
  101. // return
  102. // }
  103. // vm.isOpen = false
  104. // })
  105. // }
  106. // this.isOpen = !this.isOpen
  107. // this.collapse.onChange && this.collapse.onChange()
  108. // this.$forceUpdate()
  109. // }
  110. }
  111. }
  112. </script>
  113. <style scoped>
  114. .uni-collapse-cell {
  115. flex-direction: column;
  116. border-color: #FFFFFF;
  117. border-bottom-width: 1px;
  118. border-bottom-style: solid;
  119. }
  120. .uni-collapse-cell--hover {
  121. /* background-color: #e61916; */
  122. }
  123. .uni-collapse-cell--open {
  124. /* background-color: #e61916; */
  125. border-radius: 10px 10px 0 0;
  126. }
  127. .uni-collapse-cell--disabled {
  128. /* background-color: #e61916; */
  129. /* opacity: 0.3;
  130. */
  131. }
  132. .uni-collapse-cell--hide {
  133. height: 48px;
  134. }
  135. .uni-collapse-cell--animation {
  136. /* transition: transform 0.3s ease;
  137. */
  138. transition-property: transform;
  139. transition-duration: 0.3s;
  140. transition-timing-function: ease;
  141. }
  142. .uni-collapse-cell__title {
  143. padding: 12px 12px;
  144. position: relative;
  145. /* #ifndef APP-NVUE */
  146. display: flex;
  147. width: 100%;
  148. box-sizing: border-box;
  149. /* #endif */
  150. height: 48px;
  151. line-height: 24px;
  152. flex-direction: row;
  153. justify-content: space-between;
  154. align-items: center;
  155. background-color: #e61916;
  156. }
  157. .uni-collapse-cell__title:active {
  158. /* background-color: #e61916; */
  159. }
  160. .uni-collapse-cell__title-img {
  161. height: 26px;
  162. width: 26px;
  163. margin-right: 10px;
  164. }
  165. .uni-collapse-cell__title-arrow {
  166. width: 20px;
  167. height: 20px;
  168. transform: rotate(0deg);
  169. margin-left: 10px;
  170. transform-origin: center center;
  171. }
  172. .uni-collapse-cell__title-arrow-active {
  173. transform: rotate(180deg);
  174. }
  175. .uni-collapse-cell__title-text {
  176. flex: 1;
  177. font-size: 16px;
  178. font-weight: bold;
  179. /* #ifndef APP-NVUE */
  180. white-space: nowrap;
  181. color: inherit;
  182. /* #endif */
  183. /* #ifdef APP-NVUE */
  184. lines: 1;
  185. /* #endif */
  186. overflow: hidden;
  187. text-overflow: ellipsis;
  188. }
  189. .uni-collapse-cell__content {
  190. overflow: hidden;
  191. }
  192. .uni-collapse-cell__wrapper {
  193. /* #ifndef APP-NVUE */
  194. display: flex;
  195. /* #endif */
  196. flex-direction: column;
  197. }
  198. .uni-collapse-cell__content--hide {
  199. height: 0px;
  200. line-height: 0px;
  201. }
  202. </style>