floating-activity.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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="img" 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. img: {
  24. type: String,
  25. default: "",
  26. },
  27. // 是否显示
  28. visible: {
  29. type: Boolean,
  30. default: true,
  31. },
  32. // 初始位置
  33. initialPosition: {
  34. type: Object,
  35. default: () => ({
  36. left: "auto",
  37. right: 0,
  38. bottom: "30%",
  39. }),
  40. },
  41. // 按钮大小
  42. size: {
  43. type: [Number, String],
  44. default: 200,
  45. },
  46. // 背景颜色
  47. bgColor: {
  48. type: String,
  49. default: "#007AFF",
  50. },
  51. // 图标
  52. icon: {
  53. type: String,
  54. default: "",
  55. },
  56. // 文本
  57. text: {
  58. type: String,
  59. default: "按钮",
  60. },
  61. },
  62. methods: {
  63. // 处理点击事件
  64. handleClick() {
  65. this.$emit("click");
  66. },
  67. // 处理位置变更事件
  68. onPositionChange(position) {
  69. this.$emit("position-change", position);
  70. },
  71. },
  72. };
  73. </script>
  74. <style lang="scss" scoped>
  75. .floating-btn {
  76. width: 100%;
  77. height: 100%;
  78. display: flex;
  79. align-items: center;
  80. justify-content: center;
  81. .icon {
  82. width: 100%;
  83. height: 100%;
  84. }
  85. text {
  86. color: #ffffff;
  87. font-size: 28rpx;
  88. text-align: center;
  89. font-weight: 500;
  90. }
  91. }
  92. </style>