fs-dropdown-item.vue 1.7 KB

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