fs-fab.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="fs-fab">
  3. <view class="fs-fab-btn" :style="{right, bottom}">
  4. <view class="fs-fab-option" :class="{'fs-fab-scale': visible}">
  5. <fs-avatar
  6. class="fs-fab-option-gutter"
  7. v-for="(item,index) in options"
  8. :key="index"
  9. :size="size"
  10. :bgColor="item.bgColor"
  11. :bgColorType="item.bgColorType"
  12. @click="handleOption(item)">
  13. {{item.name}}
  14. </fs-avatar>
  15. <slot name="option"></slot>
  16. </view>
  17. <fs-avatar :size="size" @click="handleToggle">
  18. <fs-icon type="icon-plus2" :size="iconSize" class="fs-fab-plus" :class="{'fs-fab-visible':visible}"></fs-icon>
  19. </fs-avatar>
  20. </view>
  21. <fs-mask v-model="visible"></fs-mask>
  22. </view>
  23. </template>
  24. <script setup>
  25. import { ref } from 'vue'
  26. const props = defineProps({
  27. right: {
  28. type: String,
  29. default: '40rpx'
  30. },
  31. bottom: {
  32. type: String,
  33. default: '40rpx'
  34. },
  35. options: {
  36. type: Array,
  37. default: () => []
  38. },
  39. size: {
  40. type: String,
  41. default: '120rpx'
  42. },
  43. iconSize: {
  44. type: String,
  45. default: '50rpx'
  46. }
  47. })
  48. const emits = defineEmits(['clickOption'])
  49. const visible = ref(false)
  50. const handleToggle = () => {
  51. visible.value = !visible.value
  52. }
  53. const handleOption = item => {
  54. close()
  55. emits('clickOption',item)
  56. }
  57. const close = () => {
  58. visible.value = false
  59. }
  60. defineExpose({
  61. close
  62. })
  63. </script>
  64. <style lang="scss" scoped>
  65. .fs-fab{
  66. &-btn{
  67. position: fixed;
  68. margin-bottom: var(--window-bottom);
  69. z-index: 1000;
  70. }
  71. &-plus{
  72. transition: all .2s;
  73. }
  74. &-visible{
  75. transform: rotate(315deg);
  76. }
  77. &-option{
  78. display: flex;
  79. flex-direction: column;
  80. margin-bottom: 30rpx;
  81. transition: all .2s;
  82. transform: translateY(-50%);
  83. opacity: 0;
  84. z-index: -1;
  85. &-gutter{
  86. margin-top: 20rpx;
  87. }
  88. }
  89. &-scale{
  90. transform: translateY(0);
  91. opacity: 1;
  92. z-index: 1000;
  93. }
  94. }
  95. </style>