fs-dropdown-item.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. }
  56. }
  57. &-text{
  58. margin-right: 10rpx;
  59. }
  60. &-icon{
  61. transition: all .2s;
  62. }
  63. &-content{
  64. position: absolute;
  65. left: 0;
  66. right: 0;
  67. top: 80rpx;
  68. transform: scaleY(0);
  69. transform-origin: left top;
  70. transition: all .1s;
  71. z-index: 100;
  72. background-color: #fff;
  73. opacity: 0;
  74. &.visible{
  75. transform: scaleY(1);
  76. opacity: 1;
  77. }
  78. }
  79. }
  80. </style>