fs-dropdown-item.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. display: flex;
  43. justify-content: center;
  44. align-items: center;
  45. background-color: #fff;
  46. z-index: 100;
  47. padding: 0 20rpx;
  48. &-title{
  49. display: flex;
  50. align-items: center;
  51. .visible{
  52. transform: rotate(180deg);
  53. }
  54. }
  55. &-text{
  56. margin-right: 10rpx;
  57. }
  58. &-icon{
  59. transition: all .2s;
  60. }
  61. &-content{
  62. position: absolute;
  63. left: 0;
  64. right: 0;
  65. top: 80rpx;
  66. transform: scaleY(0);
  67. transform-origin: left top;
  68. transition: all .1s;
  69. z-index: 100;
  70. background-color: #fff;
  71. opacity: 0;
  72. &.visible{
  73. transform: scaleY(1);
  74. opacity: 1;
  75. }
  76. }
  77. }
  78. </style>