floating-activity.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <floating-drag
  3. :visible="visible"
  4. :initialPosition="initialPosition"
  5. :width="size"
  6. :height="size"
  7. @click="handleClick"
  8. @position-change="onPositionChange"
  9. >
  10. <view class="floating-btn">
  11. <image src="/static/img/activity.png" class="icon"></image>
  12. </view>
  13. </floating-drag>
  14. </template>
  15. <script>
  16. import FloatingDrag from "./floating-drag.vue";
  17. export default {
  18. name: "FloatingButton",
  19. components: {
  20. FloatingDrag,
  21. },
  22. props: {
  23. // 是否显示
  24. visible: {
  25. type: Boolean,
  26. default: true,
  27. },
  28. // 初始位置
  29. initialPosition: {
  30. type: Object,
  31. default: () => ({
  32. left: "auto",
  33. right: 0,
  34. bottom: "30%",
  35. }),
  36. },
  37. // 按钮大小
  38. size: {
  39. type: [Number, String],
  40. default: 200,
  41. },
  42. // 背景颜色
  43. bgColor: {
  44. type: String,
  45. default: "#007AFF",
  46. },
  47. // 图标
  48. icon: {
  49. type: String,
  50. default: "",
  51. },
  52. // 文本
  53. text: {
  54. type: String,
  55. default: "按钮",
  56. },
  57. },
  58. methods: {
  59. // 处理点击事件
  60. handleClick() {
  61. this.$emit("click");
  62. },
  63. // 处理位置变更事件
  64. onPositionChange(position) {
  65. this.$emit("position-change", position);
  66. },
  67. },
  68. };
  69. </script>
  70. <style lang="scss" scoped>
  71. .floating-btn {
  72. width: 100%;
  73. height: 100%;
  74. display: flex;
  75. align-items: center;
  76. justify-content: center;
  77. .icon {
  78. width: 100%;
  79. height: 100%;
  80. }
  81. text {
  82. color: #ffffff;
  83. font-size: 28rpx;
  84. text-align: center;
  85. font-weight: 500;
  86. }
  87. }
  88. </style>