index.vue 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 :size="size" :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. size: String,
  29. name: null,
  30. title: null,
  31. value: null,
  32. icon: String,
  33. label: String,
  34. disabled: Boolean,
  35. clickable: Boolean,
  36. border: {
  37. type: Boolean,
  38. value: true,
  39. },
  40. isLink: {
  41. type: Boolean,
  42. value: true,
  43. },
  44. },
  45. data: {
  46. expanded: false,
  47. },
  48. mounted() {
  49. this.updateExpanded();
  50. this.mounted = true;
  51. },
  52. methods: {
  53. updateExpanded() {
  54. if (!this.parent) {
  55. return;
  56. }
  57. const { value, accordion } = this.parent.data;
  58. const { children = [] } = this.parent;
  59. const { name } = this.data;
  60. const index = children.indexOf(this);
  61. const currentName = name == null ? index : name;
  62. const expanded = accordion
  63. ? value === currentName
  64. : (value || []).some((name) => name === currentName);
  65. if (expanded !== this.data.expanded) {
  66. setContentAnimate(this, expanded, this.mounted);
  67. }
  68. this.setData({ index, expanded });
  69. },
  70. onClick() {
  71. if (this.data.disabled) {
  72. return;
  73. }
  74. const { name, expanded } = this.data;
  75. const index = this.parent.children.indexOf(this);
  76. const currentName = name == null ? index : name;
  77. this.parent.switch(currentName, !expanded);
  78. },
  79. },
  80. });
  81. export default global['__wxComponents']['vant/collapse-item/index']
  82. </script>
  83. <style platform="mp-weixin">
  84. @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)}
  85. </style>