fix:房间号模块跟胶囊margin距离根据机型动态写入
This commit is contained in:
@@ -59,6 +59,8 @@ const loading = ref(false);
|
|||||||
const pointBook = ref(null);
|
const pointBook = ref(null);
|
||||||
const showProgress = ref(false);
|
const showProgress = ref(false);
|
||||||
const heat = ref(0);
|
const heat = ref(0);
|
||||||
|
/** 房间号按钮动态定位样式(position: fixed,根据胶囊真实位置计算,脱离 flex 流避免挤压标题) */
|
||||||
|
const battleRoomBtnStyle = ref({});
|
||||||
|
|
||||||
const updateLoading = (value) => {
|
const updateLoading = (value) => {
|
||||||
loading.value = value;
|
loading.value = value;
|
||||||
@@ -83,6 +85,23 @@ onMounted(() => {
|
|||||||
if (currentPage.route === "pages/team-battle") {
|
if (currentPage.route === "pages/team-battle") {
|
||||||
showProgress.value = true;
|
showProgress.value = true;
|
||||||
}
|
}
|
||||||
|
// 仅在对战房间页获取胶囊位置,按钮用 fixed 定位精确贴靠胶囊左侧(脱离 flex 流,不挤压标题)
|
||||||
|
if (currentPage.route === "pages/battle-room") {
|
||||||
|
try {
|
||||||
|
const menuButtonRect = uni.getMenuButtonBoundingClientRect();
|
||||||
|
const { windowWidth } = uni.getSystemInfoSync();
|
||||||
|
battleRoomBtnStyle.value = {
|
||||||
|
// 按钮右边缘距视口右侧 = 屏幕宽 - 胶囊左边缘 + 4px 安全间隙
|
||||||
|
right: (windowWidth - menuButtonRect.left + 4) + "px",
|
||||||
|
// 垂直位置与胶囊顶部对齐
|
||||||
|
top: menuButtonRect.top + "px",
|
||||||
|
// 高度与胶囊一致,视觉融合
|
||||||
|
height: menuButtonRect.height + "px",
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
// 获取失败时使用 CSS 兜底定位(28vw + 4px 作为 right,8px 作为 top)
|
||||||
|
}
|
||||||
|
}
|
||||||
uni.$on("update-hot", updateHot);
|
uni.$on("update-hot", updateHot);
|
||||||
});
|
});
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
@@ -173,12 +192,13 @@ onBeforeUnmount(() => {
|
|||||||
<view v-if="showProgress" class="battle-progress">
|
<view v-if="showProgress" class="battle-progress">
|
||||||
<HeaderProgress />
|
<HeaderProgress />
|
||||||
</view>
|
</view>
|
||||||
<!-- 对战房间:整个胶囊为分享按钮,房号从 Store 读取 -->
|
<!-- 对战房间:整个胶囊为分享按钮,房号从 Store 读取;fixed 定位紧靠系统胶囊左侧 -->
|
||||||
<button
|
<button
|
||||||
v-if="currentPage === 'pages/battle-room' && game.roomNumber"
|
v-if="currentPage === 'pages/battle-room' && game.roomNumber"
|
||||||
open-type="share"
|
open-type="share"
|
||||||
hover-class="none"
|
hover-class="none"
|
||||||
class="battle-room-number"
|
class="battle-room-number"
|
||||||
|
:style="battleRoomBtnStyle"
|
||||||
>
|
>
|
||||||
<text class="battle-room-number__text">房号: {{ game.roomNumber }}</text>
|
<text class="battle-room-number__text">房号: {{ game.roomNumber }}</text>
|
||||||
<image src="../static/share2.png" mode="widthFix" class="battle-room-number__icon" />
|
<image src="../static/share2.png" mode="widthFix" class="battle-room-number__icon" />
|
||||||
@@ -270,10 +290,12 @@ onBeforeUnmount(() => {
|
|||||||
margin: 0 20rpx;
|
margin: 0 20rpx;
|
||||||
max-width: 300rpx;
|
max-width: 300rpx;
|
||||||
}
|
}
|
||||||
/* 对战房间:整个胶囊作为分享按钮,靠右对齐 */
|
/* 对战房间:整个胶囊作为分享按钮,fixed 定位脱离 flex 流,紧贴系统胶囊左侧 */
|
||||||
.battle-room-number {
|
.battle-room-number {
|
||||||
margin-left: auto;
|
position: fixed;
|
||||||
margin-right: 20rpx;
|
/* 兜底定位(JS 获取胶囊位置失败时生效):约 28vw 对应胶囊区域左边缘 */
|
||||||
|
right: calc(28vw + 4px);
|
||||||
|
top: 8px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -282,9 +304,7 @@ onBeforeUnmount(() => {
|
|||||||
background: rgba(0, 0, 0, 0.15);
|
background: rgba(0, 0, 0, 0.15);
|
||||||
border-radius: 96rpx;
|
border-radius: 96rpx;
|
||||||
border: 1rpx solid #5b5758;
|
border: 1rpx solid #5b5758;
|
||||||
flex-shrink: 0;
|
|
||||||
padding: 0;
|
padding: 0;
|
||||||
line-height: normal;
|
|
||||||
}
|
}
|
||||||
/* 重置 button 默认边框 */
|
/* 重置 button 默认边框 */
|
||||||
.battle-room-number::after {
|
.battle-room-number::after {
|
||||||
|
|||||||
Reference in New Issue
Block a user