fix:房间号更新改为pinia
This commit is contained in:
@@ -6,7 +6,7 @@ import Avatar from "@/components/Avatar.vue";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { user } = storeToRefs(store);
|
||||
const { user, game } = storeToRefs(store);
|
||||
|
||||
const currentPage = computed(() => {
|
||||
const pages = getCurrentPages();
|
||||
@@ -59,8 +59,6 @@ const loading = ref(false);
|
||||
const pointBook = ref(null);
|
||||
const showProgress = ref(false);
|
||||
const heat = ref(0);
|
||||
/** 当前对战房间的房号,由 battle-room 页面通过 uni.$emit 传入 */
|
||||
const battleRoomNumber = ref("");
|
||||
|
||||
const updateLoading = (value) => {
|
||||
loading.value = value;
|
||||
@@ -70,14 +68,6 @@ const updateHot = (value) => {
|
||||
heat.value = value;
|
||||
};
|
||||
|
||||
/**
|
||||
* 接收 battle-room 页面发出的房间信息,更新房号展示
|
||||
* @param {{ roomNumber: string }} info
|
||||
*/
|
||||
const updateBattleRoomInfo = (info) => {
|
||||
battleRoomNumber.value = info.roomNumber || "";
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
@@ -94,11 +84,9 @@ onMounted(() => {
|
||||
showProgress.value = true;
|
||||
}
|
||||
uni.$on("update-hot", updateHot);
|
||||
uni.$on("battle-room-info", updateBattleRoomInfo);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
uni.$off("update-hot", updateHot);
|
||||
uni.$off("battle-room-info", updateBattleRoomInfo);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -185,14 +173,14 @@ onBeforeUnmount(() => {
|
||||
<view v-if="showProgress" class="battle-progress">
|
||||
<HeaderProgress />
|
||||
</view>
|
||||
<!-- 对战房间:整个胶囊为分享按钮,点击任意区域均可触发分享 -->
|
||||
<!-- 对战房间:整个胶囊为分享按钮,房号从 Store 读取 -->
|
||||
<button
|
||||
v-if="currentPage === 'pages/battle-room' && battleRoomNumber"
|
||||
v-if="currentPage === 'pages/battle-room' && game.roomNumber"
|
||||
open-type="share"
|
||||
hover-class="none"
|
||||
class="battle-room-number"
|
||||
>
|
||||
<text class="battle-room-number__text">房号: {{ battleRoomNumber }}</text>
|
||||
<text class="battle-room-number__text">房号: {{ game.roomNumber }}</text>
|
||||
<image src="../static/share2.png" mode="widthFix" class="battle-room-number__icon" />
|
||||
</button>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user