feat: floating-bubble

This commit is contained in:
Burt 2024-01-21 04:22:45 +08:00
parent 06390f014b
commit 36bd9fe1de

View File

@ -0,0 +1,82 @@
<template>
<view>
<movable-area class="movable-area">
<movable-view
:style="`--size:${ballSize}px`"
class="movable-view"
direction="all"
:x="x"
:y="y"
@change="onChange"
@touchend.prevent="onTouchEnd"
>
<view class="w-full h-full rounded-full bg-green-400"></view>
</movable-view>
</movable-area>
<view>页面其他元素</view>
<view>可以正常触发点击事件吗答案是可以的</view>
<button @click="onClick">按钮</button>
<view>{{ x }}</view>
<view>{{ y }}</view>
<view @click="onSet">点击设置</view>
</view>
</template>
<script lang="ts" setup name="FloatingBubble">
const { windowHeight, windowWidth } = uni.getSystemInfoSync()
console.log(uni.getSystemInfoSync())
const ballSize = 60
const x = ref(windowWidth - ballSize) //
const y = ref(windowHeight - ballSize - 20) // 20px
const middleX = (windowWidth - ballSize) / 2
const onChange: UniHelper.MovableViewOnChange = (e) => {
// console.log(e.detail)
const { x: _x, y: _y } = e.detail
x.value = _x
y.value = _y
}
// TODO:
const onTouchEnd = (e) => {
console.log(e)
console.log('onTouchEnd')
// TODOonSetonSet
nextTick(() => {
console.log(x.value, middleX)
if (x.value < middleX) {
x.value = 0
} else {
x.value = windowWidth - ballSize
}
})
}
const onClick = () => {
uni.showToast({
title: 'yes',
icon: 'none',
})
}
const onSet = () => {
x.value = 100
y.value = 100
}
</script>
<style lang="scss">
.movable-area {
position: absolute;
top: 0;
left: 0;
z-index: 100;
width: 100%;
height: 100%;
pointer-events: none; // area便
.movable-view {
width: var(--size);
height: var(--size);
pointer-events: auto; //
}
}
</style>