index.vue 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <uni-shadow-root class="vant-collapse-item-index"><view :class="'van-collapse-item custom-class '+(index !== 0 ? 'van-hairline--top' : '')">
  3. <van-cell :title="title" title-class="title-class" :icon="icon" :value="value" :label="label" :is-link="isLink" :clickable="clickable" :border="border && expanded" :class="utils.bem('collapse-item__title', { disabled, expanded })" right-icon-class="van-cell__right-icon" custom-class="van-cell" hover-class="van-cell--hover" @click="onClick">
  4. <slot name="title" slot="title"></slot>
  5. <slot name="icon" slot="icon"></slot>
  6. <slot name="value"></slot>
  7. <slot name="right-icon" slot="right-icon"></slot>
  8. </van-cell>
  9. <view :class="utils.bem('collapse-item__wrapper')" style="height: 0;" :animation="animation">
  10. <view class="van-collapse-item__content content-class">
  11. <slot></slot>
  12. </view>
  13. </view>
  14. </view></uni-shadow-root>
  15. </template>
  16. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  17. <script>
  18. import VanCell from '../cell/index.vue'
  19. global['__wxVueOptions'] = {components:{'van-cell': VanCell}}
  20. global['__wxRoute'] = 'vant/collapse-item/index'
  21. import { VantComponent } from '../common/component';
  22. import { useParent } from '../common/relation';
  23. import { setContentAnimate } from './animate';
  24. VantComponent({
  25. classes: ['title-class', 'content-class'],
  26. relation: useParent('collapse'),
  27. props: {
  28. name: null,
  29. title: null,
  30. value: null,
  31. icon: String,
  32. label: String,
  33. disabled: Boolean,
  34. clickable: Boolean,
  35. border: {
  36. type: Boolean,
  37. value: true,
  38. },
  39. isLink: {
  40. type: Boolean,
  41. value: true,
  42. },
  43. },
  44. data: {
  45. expanded: false,
  46. },
  47. mounted() {
  48. this.updateExpanded();
  49. this.mounted = true;
  50. },
  51. methods: {
  52. updateExpanded() {
  53. if (!this.parent) {
  54. return;
  55. }
  56. const { value, accordion } = this.parent.data;
  57. const { children = [] } = this.parent;
  58. const { name } = this.data;
  59. const index = children.indexOf(this);
  60. const currentName = name == null ? index : name;
  61. const expanded = accordion
  62. ? value === currentName
  63. : (value || []).some((name) => name === currentName);
  64. if (expanded !== this.data.expanded) {
  65. setContentAnimate(this, expanded, this.mounted);
  66. }
  67. this.setData({ index, expanded });
  68. },
  69. onClick() {
  70. if (this.data.disabled) {
  71. return;
  72. }
  73. const { name, expanded } = this.data;
  74. const index = this.parent.children.indexOf(this);
  75. const currentName = name == null ? index : name;
  76. this.parent.switch(currentName, !expanded);
  77. },
  78. },
  79. });
  80. export default global['__wxComponents']['vant/collapse-item/index']
  81. </script>
  82. <style platform="mp-weixin">
  83. @import '../common/index.css';.van-collapse-item__title .van-cell__right-icon{transform:rotate(90deg);transition:transform var(--collapse-item-transition-duration,.3s)}.van-collapse-item__title--expanded .van-cell__right-icon{transform:rotate(-90deg)}.van-collapse-item__title--disabled .van-cell,.van-collapse-item__title--disabled .van-cell__right-icon{color:var(--collapse-item-title-disabled-color,#c8c9cc)!important}.van-collapse-item__title--disabled .van-cell--hover{background-color:#fff!important}.van-collapse-item__wrapper{overflow:hidden}.van-collapse-item__content{background-color:var(--collapse-item-content-background-color,#fff);color:var(--collapse-item-content-text-color,#969799);font-size:var(--collapse-item-content-font-size,13px);line-height:var(--collapse-item-content-line-height,1.5);padding:var(--collapse-item-content-padding,15px)}
  84. </style>