fs-dropdown-item.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="fs-dropdown-item">
  3. <view class="fs-dropdown-item-title" @click="handleToggle">
  4. <view class="fs-dropdown-item-text">{{title}}</view>
  5. <fs-icon class="fs-dropdown-item-icon" type="icon-sort-down" size="26rpx" :class="{visible}"></fs-icon>
  6. </view>
  7. <view class="fs-dropdown-item-content" :class="{visible}">
  8. <slot></slot>
  9. </view>
  10. </view>
  11. <fs-mask v-model="visible" :z-index="99"></fs-mask>
  12. </template>
  13. <script setup>
  14. import { ref, inject } from 'vue'
  15. const props = defineProps({
  16. title: String,
  17. })
  18. const visible = ref(false)
  19. let flag = false
  20. const updateState = () => {
  21. if (flag) {
  22. flag = false
  23. visible.value = !visible.value
  24. } else{
  25. visible.value = false
  26. }
  27. }
  28. const dropdownGroup = inject('dropdownGroup')
  29. dropdownGroup.updateChildren({
  30. updateState
  31. })
  32. const handleToggle = () => {
  33. flag = true
  34. dropdownGroup.toggle()
  35. }
  36. </script>
  37. <style lang="scss" scoped>
  38. .fs-dropdown-item{
  39. flex: 1;
  40. width: 100%;
  41. height: 80rpx;
  42. background-color: #fff;
  43. &-title{
  44. display: flex;
  45. justify-content: center;
  46. align-items: center;
  47. position: relative;
  48. z-index: 100;
  49. padding: 0 20rpx;
  50. width: 100%;
  51. height: 100%;
  52. background-color: #fff;
  53. .visible{
  54. transform: rotate(180deg);
  55. transform-origin: center center;
  56. }
  57. }
  58. &-text{
  59. margin-right: 10rpx;
  60. }
  61. &-icon{
  62. transition: all .2s;
  63. }
  64. &-content{
  65. position: absolute;
  66. left: 0;
  67. right: 0;
  68. top: 80rpx;
  69. transform: scaleY(0);
  70. transform-origin: left top;
  71. transition: all .1s;
  72. z-index: 100;
  73. background-color: #fff;
  74. opacity: 0;
  75. &.visible{
  76. transform: scaleY(1);
  77. opacity: 1;
  78. }
  79. }
  80. }
  81. </style>