fs-fab.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. <slot name="option">
  6. <fs-avatar
  7. class="fs-fab-option-gutter"
  8. v-for="(item, index) in options"
  9. :key="index"
  10. :size="size"
  11. :bgColor="item.bgColor"
  12. :bgColorType="item.bgColorType"
  13. @click="handleOption(item)"
  14. >
  15. {{ item.name }}
  16. </fs-avatar>
  17. </slot>
  18. </view>
  19. <fs-avatar :size="size" bgColorType="danger" @click="handleToggle" v-if="visible">
  20. <fs-icon type="icon-close" :size="iconSize"></fs-icon>
  21. </fs-avatar>
  22. <fs-avatar :size="size" :bgColor="bgColor" @click="handleToggle" v-else>
  23. <slot name="icon">
  24. <fs-icon
  25. type="icon-plus"
  26. :size="iconSize"
  27. class="fs-fab-plus"
  28. :class="{ 'fs-fab-visible': visible }"
  29. ></fs-icon>
  30. </slot>
  31. </fs-avatar>
  32. </view>
  33. <fs-mask v-if="showMask" v-model="visible"></fs-mask>
  34. </view>
  35. </template>
  36. <script>
  37. /**
  38. * 悬浮按钮组件
  39. * @description 悬浮按钮组件
  40. * @property {String} right 按钮右边距
  41. * @property {String} bottom 按钮下边距
  42. * @property {Array} options 选项
  43. * @property {String} size 按钮大小
  44. * @property {String} iconSize 图标大小
  45. * @property {String} bgColor 背景色
  46. * @property {Boolean} showMask 是否显示遮罩
  47. */
  48. export default {
  49. name: 'fs-fab'
  50. }
  51. </script>
  52. <script setup>
  53. import { ref } from 'vue'
  54. const props = defineProps({
  55. right: {
  56. type: String,
  57. default: '40rpx'
  58. },
  59. bottom: {
  60. type: String,
  61. default: '40rpx'
  62. },
  63. options: {
  64. type: Array,
  65. default: () => []
  66. },
  67. size: {
  68. type: String,
  69. default: '120rpx'
  70. },
  71. iconSize: {
  72. type: String,
  73. default: '50rpx'
  74. },
  75. bgColor: String,
  76. showMask: Boolean
  77. })
  78. const emits = defineEmits(['clickOption'])
  79. const visible = ref(false)
  80. const handleToggle = () => {
  81. visible.value = !visible.value
  82. }
  83. const handleOption = item => {
  84. close()
  85. emits('clickOption', item)
  86. }
  87. const close = () => {
  88. visible.value = false
  89. }
  90. defineExpose({
  91. close
  92. })
  93. </script>
  94. <style lang="scss" scoped>
  95. .fs-fab {
  96. &-btn {
  97. position: fixed;
  98. margin-bottom: var(--window-bottom);
  99. z-index: 900;
  100. }
  101. &-plus {
  102. transition: all 0.2s;
  103. }
  104. &-visible {
  105. transform: rotate(315deg);
  106. }
  107. &-option {
  108. display: flex;
  109. flex-direction: column;
  110. margin-bottom: 30rpx;
  111. transition: all 0.2s;
  112. transform: translateY(-50%);
  113. opacity: 0;
  114. z-index: -1;
  115. &-gutter {
  116. margin-top: 20rpx;
  117. }
  118. }
  119. &-scale {
  120. transform: translateY(0);
  121. opacity: 1;
  122. z-index: 900;
  123. }
  124. }
  125. </style>