修复滑动时候的渲染问题

This commit is contained in:
kron
2025-08-06 17:34:38 +08:00
parent 79feb32766
commit 66dea2b199
3 changed files with 84 additions and 85 deletions

View File

@@ -33,17 +33,12 @@ const onClick = async (e) => {
x: e.detail.x - (rect.value.width * 0.1) / 2, x: e.detail.x - (rect.value.width * 0.1) / 2,
y: e.detail.y - rect.value.top - 10, y: e.detail.y - rect.value.top - 10,
}; };
newArrow.ring = calcRing( const side = rect.value.width * 0.9;
props.id, newArrow.ring = calcRing(props.id, newArrow.x, newArrow.y, side, side);
newArrow.x,
newArrow.y,
rect.value.width * 0.9,
rect.value.height - rect.value.top
);
arrow.value = { arrow.value = {
...newArrow, ...newArrow,
x: newArrow.x / (rect.value.width * 0.9), x: newArrow.x / side,
y: newArrow.y / (rect.value.width * 0.9), y: newArrow.y / side,
}; };
}; };
@@ -80,27 +75,20 @@ const onDrag = async (e) => {
const deltaX = clientX - dragStartPos.value.x; const deltaX = clientX - dragStartPos.value.x;
const deltaY = clientY - dragStartPos.value.y; const deltaY = clientY - dragStartPos.value.y;
const width = rect.value.width * 0.9; const side = rect.value.width * 0.9;
const height = rect.value.height - rect.value.top;
// 更新坐标 // 更新坐标
arrow.value.x = Math.max( arrow.value.x = Math.max(0, Math.min(side, arrow.value.x * side + deltaX));
0, arrow.value.y = Math.max(0, Math.min(side, arrow.value.y * side + deltaY));
Math.min(width, arrow.value.x * (rect.value.width * 0.9) + deltaX)
);
arrow.value.y = Math.max(
0,
Math.min(height, arrow.value.y * (rect.value.width * 0.9) + deltaY)
);
arrow.value.ring = calcRing( arrow.value.ring = calcRing(
props.id, props.id,
arrow.value.x, arrow.value.x,
arrow.value.y, arrow.value.y,
width, side,
height side
); );
arrow.value.x = arrow.value.x / (rect.value.width * 0.9); arrow.value.x = arrow.value.x / side;
arrow.value.y = arrow.value.y / (rect.value.width * 0.9); arrow.value.y = arrow.value.y / side;
// 更新拖拽起始位置 // 更新拖拽起始位置
dragStartPos.value = { x: clientX, y: clientY }; dragStartPos.value = { x: clientX, y: clientY };
@@ -118,6 +106,7 @@ onMounted(async () => {
</script> </script>
<template> <template>
<movable-area class="move-container">
<view <view
class="container" class="container"
@click="onClick" @click="onClick"
@@ -134,30 +123,34 @@ onMounted(async () => {
top: (arrow.y !== undefined ? arrow.y : 0) * 100 + '%', top: (arrow.y !== undefined ? arrow.y : 0) * 100 + '%',
}" }"
> >
<view v-if="arrow.x !== undefined && arrow.y !== undefined" class="point" <view
v-if="arrow.x !== undefined && arrow.y !== undefined"
class="point"
><text>{{ index + 1 }}</text></view ><text>{{ index + 1 }}</text></view
> >
</view> </view>
<!-- 渲染所有箭矢点 --> <movable-view
<view
v-if="arrow" v-if="arrow"
class="arrow-point" class="arrow-point"
:style="{ direction="all"
left: arrow.x * 100 + '%', :animation="false"
top: arrow.y * 100 + '%', :x="rect.width * 0.9 * arrow.x"
}" :y="rect.width * 0.9 * arrow.y"
> >
<!-- 箭矢点 --> <!-- 箭矢点 -->
<view class="point"> </view> <view class="point"> </view>
<!-- 编辑按钮组只在编辑状态下显示 --> <!-- 编辑按钮组只在编辑状态下显示 -->
<view class="edit-buttons" @click.stop> <view class="edit-buttons" @click.stop>
<view class="edit-btn-text"> <view class="edit-btn-text">
<text>{{ arrow.ring === 0 ? "未上靶" : arrow.ring }}</text> <text v-if="arrow.ring === 0" :style="{ width: '100%' }"
>未上靶</text
>
<text v-if="arrow.ring !== 0">{{ arrow.ring }}</text>
<text <text
v-if="arrow.ring > 0" v-if="arrow.ring > 0"
:style="{ :style="{
fontSize: '20px', fontSize: '16px',
marginLeft: '5px', marginLeft: '2px',
}" }"
></text ></text
> >
@@ -175,14 +168,19 @@ onMounted(async () => {
<image src="../static/arrow-edit-move.png" mode="widthFix" /> <image src="../static/arrow-edit-move.png" mode="widthFix" />
</view> </view>
</view> </view>
</movable-view>
</view> </view>
</view> </movable-area>
</template> </template>
<style scoped> <style scoped>
.container { .move-container {
width: 90%; width: 90vw;
height: 90vw;
margin: 10px auto; margin: 10px auto;
}
.container {
width: 100%;
position: relative; position: relative;
user-select: none; user-select: none;
} }
@@ -194,11 +192,10 @@ onMounted(async () => {
.arrow-point { .arrow-point {
position: absolute; position: absolute;
transform: translate(-50%, -50%);
z-index: 10;
} }
.point { .point {
transform: translate(-50%, -50%);
width: 12px; width: 12px;
height: 12px; height: 12px;
border-radius: 50%; border-radius: 50%;

View File

@@ -87,6 +87,7 @@ onShow(async () => {
}); });
onMounted(async () => { onMounted(async () => {
uni.removeStorageSync("point-book-config");
const deviceInfo = uni.getDeviceInfo(); const deviceInfo = uni.getDeviceInfo();
isIos.value = deviceInfo.osName === "ios"; isIos.value = deviceInfo.osName === "ios";
const config = await getAppConfig(); const config = await getAppConfig();

View File

@@ -406,15 +406,16 @@ export const calcPinBowTarget = (
if ( if (
x / targetWidth >= 0.26 && x / targetWidth >= 0.26 &&
x / targetWidth <= 0.74 && x / targetWidth <= 0.74 &&
y / targetHeight <= 0.48 y / targetWidth >= 0.032 &&
y / targetHeight <= 0.51
) { ) {
return calcHalfBowTarget(x - targetWidth * 0.26, y, side, noX); return calcHalfBowTarget(x - targetWidth * 0.26, y - targetHeight * 0.032, side, noX);
} else if (x / targetHeight <= 0.48 && y / targetHeight >= 0.456) { } else if (x / targetHeight <= 0.48 && y / targetHeight >= 0.482) {
return calcHalfBowTarget(x, y - targetHeight * 0.456, side, noX); return calcHalfBowTarget(x, y - targetHeight * 0.482, side, noX);
} else if (x / targetHeight >= 0.52 && y / targetHeight >= 0.456) { } else if (x / targetHeight >= 0.52 && y / targetHeight >= 0.482) {
return calcHalfBowTarget( return calcHalfBowTarget(
x - targetWidth * 0.52, x - targetWidth * 0.52,
y - targetHeight * 0.456, y - targetHeight * 0.482,
side, side,
noX noX
); );