Files
shoot-miniprograms/src/components/Container.vue

172 lines
4.1 KiB
Vue
Raw Normal View History

2025-05-23 21:20:38 +08:00
<script setup>
2025-08-25 13:47:32 +08:00
import { ref, onMounted, onBeforeUnmount } from "vue";
import { onShow } from "@dcloudio/uni-app";
2025-05-23 21:20:38 +08:00
import AppBackground from "@/components/AppBackground.vue";
import Header from "@/components/Header.vue";
2025-07-02 17:21:44 +08:00
import ScreenHint from "@/components/ScreenHint.vue";
2025-07-13 14:57:16 +08:00
import BackToGame from "@/components/BackToGame.vue";
2025-07-03 21:12:59 +08:00
import { getCurrentGameAPI } from "@/apis";
import { debounce } from "@/util";
2025-08-07 10:48:05 +08:00
const props = defineProps({
2025-05-23 21:20:38 +08:00
title: {
type: String,
default: "",
},
bgType: {
2025-05-27 12:38:39 +08:00
type: Number,
2025-05-23 21:20:38 +08:00
default: 0,
},
2025-06-17 16:42:53 +08:00
onBack: {
type: Function,
default: null,
},
2025-06-18 12:32:08 +08:00
overflow: {
type: String,
default: "auto",
},
2025-07-02 17:21:44 +08:00
isHome: {
type: Boolean,
default: false,
},
2025-07-13 14:57:16 +08:00
showBackToGame: {
type: Boolean,
default: false,
2025-07-13 14:57:16 +08:00
},
2025-07-29 10:46:37 +08:00
bgColor: {
type: String,
default: "#050b19",
},
whiteBackArrow: {
type: Boolean,
default: true,
},
2025-05-23 21:20:38 +08:00
});
2025-07-02 17:21:44 +08:00
const showHint = ref(false);
2025-07-03 21:12:59 +08:00
const hintType = ref(0);
2025-08-07 10:48:05 +08:00
const capsuleHeight = ref(0);
2025-07-03 21:12:59 +08:00
const showGlobalHint = (type) => {
hintType.value = type;
2025-07-02 17:21:44 +08:00
showHint.value = true;
};
2025-07-14 13:39:10 +08:00
const hideGlobalHint = () => {
showHint.value = false;
};
onMounted(() => {
2025-08-07 10:48:05 +08:00
const menuBtnInfo = uni.getMenuButtonBoundingClientRect();
capsuleHeight.value = menuBtnInfo.top - 9;
});
2025-08-25 13:47:32 +08:00
onBeforeUnmount(() => {
2025-07-25 09:59:54 +08:00
// const pages = getCurrentPages();
// const currentPage = pages[pages.length - 1];
// uni.setStorageSync("last-route", currentPage.route);
});
onShow(() => {
uni.$showHint = showGlobalHint;
2025-07-14 13:39:10 +08:00
uni.$hideHint = hideGlobalHint;
showHint.value = false;
});
const backToGame = debounce(async () => {
2025-07-03 21:12:59 +08:00
const result = await getCurrentGameAPI();
});
2025-07-11 00:47:34 +08:00
const goBack = () => {
uni.navigateBack();
};
2025-05-23 21:20:38 +08:00
</script>
<template>
2025-08-07 10:48:05 +08:00
<view :style="{ paddingTop: capsuleHeight + 'px' }">
2025-07-29 10:46:37 +08:00
<AppBackground :type="bgType" :bgColor="bgColor" />
<Header
v-if="!isHome"
:title="title"
:onBack="onBack"
:whiteBackArrow="whiteBackArrow"
/>
2025-07-13 14:57:16 +08:00
<BackToGame v-if="showBackToGame" />
2025-06-15 22:01:06 +08:00
<view
class="content"
2025-07-03 21:12:59 +08:00
:style="{
2025-08-07 10:48:05 +08:00
height: `calc(100vh - ${capsuleHeight + (isHome ? 0 : 50)}px)`,
2025-07-03 21:12:59 +08:00
overflow,
}"
2025-06-15 22:01:06 +08:00
>
2025-05-23 21:20:38 +08:00
<slot></slot>
</view>
2025-07-03 21:12:59 +08:00
<ScreenHint :show="showHint">
2025-07-11 00:47:34 +08:00
<view v-if="hintType === 1" class="tip-content">
2025-07-24 11:54:38 +08:00
<text>完成进行中的对局才能开启新的</text>
<text>您有正在进行中的对局是否进入?</text>
2025-07-03 21:12:59 +08:00
<view>
<button hover-class="none" @click="() => (showHint = false)">
不进入
</button>
2025-07-21 16:15:14 +08:00
<button hover-class="none" @click="backToGame">进入</button>
2025-07-03 21:12:59 +08:00
</view>
</view>
2025-07-11 00:47:34 +08:00
<view v-if="hintType === 2" class="tip-content">
<text>离开比赛可能会导致比赛失败</text>
<text>确认离开吗</text>
<view>
2025-07-21 16:15:14 +08:00
<button hover-class="none" @click="goBack">离开比赛</button>
2025-07-11 00:47:34 +08:00
<button hover-class="none" @click="() => (showHint = false)">
继续比赛
</button>
</view>
</view>
2025-07-11 01:00:54 +08:00
<view v-if="hintType === 3" class="tip-content">
<text>今天不玩了吗</text>
<view>
<button hover-class="none" @click="() => (showHint = false)">
取消
</button>
2025-07-21 16:15:14 +08:00
<button hover-class="none" @click="goBack">确认</button>
2025-07-11 01:00:54 +08:00
</view>
</view>
2025-07-02 17:21:44 +08:00
</ScreenHint>
2025-05-23 21:20:38 +08:00
</view>
</template>
<style scoped>
.content {
2025-06-06 00:34:54 +08:00
width: 100vw;
2025-07-02 17:21:44 +08:00
height: 100vh;
2025-06-06 00:34:54 +08:00
overflow-x: hidden;
2025-06-02 14:42:07 +08:00
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
2025-06-21 12:59:59 +08:00
overflow-x: hidden;
2025-05-23 21:20:38 +08:00
}
2025-07-11 00:47:34 +08:00
.tip-content {
2025-07-03 21:12:59 +08:00
flex-direction: column;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
width: 100%;
font-size: 14px;
}
2025-07-11 00:47:34 +08:00
.tip-content > text {
text-align: center;
}
.tip-content > view {
2025-07-03 21:12:59 +08:00
display: flex;
align-items: center;
justify-content: space-around;
margin-top: 50rpx;
width: 100%;
}
2025-07-11 00:47:34 +08:00
.tip-content > view > button {
2025-07-03 21:12:59 +08:00
padding: 12px;
border-radius: 20px;
background-color: #fff6;
color: #fff;
width: 45%;
font-size: 16px;
}
2025-07-21 16:15:14 +08:00
.tip-content > view > button:last-child {
2025-07-03 21:12:59 +08:00
background-color: #fed847;
color: #000;
}
2025-05-23 21:20:38 +08:00
</style>