Files
shoot-miniprograms/src/pages/first-try.vue

285 lines
8.7 KiB
Vue
Raw Normal View History

2025-05-01 16:36:24 +08:00
<script setup>
2025-08-25 13:47:32 +08:00
import { ref, onMounted, onBeforeUnmount } from "vue";
2025-05-01 22:58:02 +08:00
import Guide from "@/components/Guide.vue";
2025-05-10 16:57:36 +08:00
import SButton from "@/components/SButton.vue";
import Swiper from "@/components/Swiper.vue";
import BowTarget from "@/components/BowTarget.vue";
import ShootProgress from "@/components/ShootProgress.vue";
import ScoreResult from "@/components/ScoreResult.vue";
import ScorePanel from "@/components/ScorePanel.vue";
2025-05-23 21:20:38 +08:00
import Container from "@/components/Container.vue";
2025-06-17 16:58:24 +08:00
import Avatar from "@/components/Avatar.vue";
import BowPower from "@/components/BowPower.vue";
2025-07-05 14:52:41 +08:00
import TestDistance from "@/components/TestDistance.vue";
2025-07-12 16:01:49 +08:00
import BubbleTip from "@/components/BubbleTip.vue";
2025-11-13 11:58:16 +08:00
import audioManager from "@/audioManager";
2026-01-08 10:30:41 +08:00
import { createPractiseAPI, getPractiseAPI } from "@/apis";
import { sharePractiseData } from "@/canvas";
import { wxShare, debounce } from "@/util";
2025-05-30 13:58:43 +08:00
import { MESSAGETYPES } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const scores = ref([]);
2025-05-10 16:57:36 +08:00
const step = ref(0);
2025-05-30 13:58:43 +08:00
const total = 12;
2025-05-10 16:57:36 +08:00
const stepButtonTexts = [
"开始",
"进入下一个任务",
"进入下一个任务",
"我准备好了,开始",
"",
"退出新手试炼",
];
2025-06-16 11:26:57 +08:00
const title = ref("新手试炼场");
2025-05-31 14:57:25 +08:00
const start = ref(false);
const practiseResult = ref({});
2025-07-12 16:01:49 +08:00
const btnDisabled = ref(false);
2025-06-25 18:41:30 +08:00
const practiseId = ref("");
2025-07-12 16:01:49 +08:00
const showGuide = ref(false);
const guideImages = [
2025-08-04 18:36:44 +08:00
"https://static.shelingxingqiu.com/attachment/2025-07-09/db77x68bs7z5elwvw7.png",
"https://static.shelingxingqiu.com/attachment/2025-07-09/db77x68qmi7grgreen.png",
"https://static.shelingxingqiu.com/attachment/2025-07-09/db77x68hgrw1ip4wae.png",
"https://static.shelingxingqiu.com/attachment/2025-07-09/db77x684x8zmfrmbla.png",
"https://static.shelingxingqiu.com/attachment/2025-07-09/db77x67sding7fodnk.png",
"https://static.shelingxingqiu.com/attachment/2025-07-09/db77x68mpug7cac4yt.png",
"https://static.shelingxingqiu.com/attachment/2025-07-09/db77x68my783mlmgxv.png",
"https://static.shelingxingqiu.com/attachment/2025-07-09/db77x68p48ylzirtb0.png",
2025-07-12 16:01:49 +08:00
];
const onSwiperIndexChange = (index) => {
if (index + 1 === guideImages.length) {
showGuide.value = true;
}
};
2025-05-30 13:58:43 +08:00
2025-05-31 18:39:41 +08:00
const createPractise = async (arrows) => {
2025-11-17 14:15:06 +08:00
const result = await createPractiseAPI(arrows, 1);
2025-06-25 18:41:30 +08:00
if (result) practiseId.value = result.id;
2025-05-31 18:39:41 +08:00
};
2026-01-08 10:30:41 +08:00
const onOver = async () => {
start.value = false;
practiseResult.value = await getPractiseAPI(practiseId.value);
};
2025-06-19 21:03:33 +08:00
async function onReceiveMessage(messages = []) {
2025-06-05 21:32:15 +08:00
messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
2025-10-29 17:26:27 +08:00
if (step.value === 2 && msg.target.dst / 100 >= 5) {
btnDisabled.value = false;
showGuide.value = true;
2026-01-08 10:30:41 +08:00
} else if (scores.value.length < total) {
scores.value.push(msg.target);
2025-10-29 17:26:27 +08:00
}
2026-01-08 10:30:41 +08:00
if (scores.value.length === total) {
setTimeout(onOver, 1500);
2025-06-25 18:41:30 +08:00
}
2025-06-05 21:32:15 +08:00
}
2025-05-30 13:58:43 +08:00
});
2025-06-05 21:32:15 +08:00
}
2025-11-11 10:13:14 +08:00
const onClickShare = debounce(async () => {
2026-01-08 10:30:41 +08:00
await sharePractiseData("shareCanvas", 1, user.value, practiseResult.value);
2025-11-11 10:13:14 +08:00
await wxShare("shareCanvas");
});
2025-06-05 21:32:15 +08:00
onMounted(() => {
2025-07-13 11:21:19 +08:00
uni.setKeepScreenOn({
keepScreenOn: true,
});
2025-06-05 21:32:15 +08:00
uni.$on("socket-inbox", onReceiveMessage);
2025-11-11 10:13:14 +08:00
uni.$on("share-image", onClickShare);
2025-05-31 18:39:41 +08:00
});
2025-05-30 13:58:43 +08:00
2025-08-25 13:47:32 +08:00
onBeforeUnmount(() => {
2025-07-13 11:21:19 +08:00
uni.setKeepScreenOn({
keepScreenOn: false,
});
2025-06-05 21:32:15 +08:00
uni.$off("socket-inbox", onReceiveMessage);
2025-11-11 10:13:14 +08:00
uni.$off("share-image", onClickShare);
2025-11-13 11:58:16 +08:00
audioManager.stopAll();
2025-05-30 13:58:43 +08:00
});
2025-05-31 18:39:41 +08:00
const nextStep = async () => {
2025-05-10 16:57:36 +08:00
if (step.value === 0) {
step.value = 1;
2025-07-11 00:47:34 +08:00
title.value = "-凹造型";
2025-05-10 16:57:36 +08:00
} else if (step.value === 1) {
2025-07-12 16:01:49 +08:00
showGuide.value = false;
btnDisabled.value = true;
2025-05-10 16:57:36 +08:00
step.value = 2;
2025-07-11 00:47:34 +08:00
title.value = "-感知距离";
2025-05-10 16:57:36 +08:00
} else if (step.value === 2) {
2025-07-12 16:01:49 +08:00
showGuide.value = false;
2025-05-10 16:57:36 +08:00
step.value = 3;
2025-07-11 00:47:34 +08:00
title.value = "-小试牛刀";
2025-05-10 16:57:36 +08:00
} else if (step.value === 3) {
2025-07-11 00:47:34 +08:00
title.value = "小试牛刀";
2025-05-31 18:39:41 +08:00
await createPractise(total);
2025-06-25 00:09:53 +08:00
scores.value = [];
2025-05-10 16:57:36 +08:00
step.value = 4;
2025-06-25 00:09:53 +08:00
start.value = true;
2025-07-14 16:37:56 +08:00
setTimeout(() => {
uni.$emit("play-sound", "请开始射击");
}, 300);
2025-05-10 16:57:36 +08:00
} else if (step.value === 5) {
uni.navigateBack({
delta: 1,
});
}
};
2025-05-30 13:58:43 +08:00
2025-05-10 16:57:36 +08:00
const onClose = () => {
2025-11-17 17:14:51 +08:00
const validArrows = (practiseResult.value.arrows || []).filter(
(a) => a.x !== -30 && a.y !== -30
);
if (validArrows.length === total) {
2025-07-05 13:12:58 +08:00
setTimeout(() => {
practiseResult.value = {};
2025-07-15 14:02:09 +08:00
showGuide.value = false;
2025-07-05 13:12:58 +08:00
step.value = 5;
}, 500);
} else {
2025-06-25 18:41:30 +08:00
practiseResult.value = {};
2025-07-05 13:12:58 +08:00
start.value = false;
scores.value = [];
step.value = 3;
}
2025-05-10 16:57:36 +08:00
};
2025-05-01 16:36:24 +08:00
</script>
<template>
2026-01-12 10:09:36 +08:00
<Container :bgType="1" :title="title" :showBottom="step !== 4">
2025-06-02 14:42:07 +08:00
<view class="container">
2025-06-16 11:26:57 +08:00
<Guide
v-if="step !== 4"
2025-06-24 13:18:03 +08:00
:type="
step === 2
? 2
2025-06-25 00:09:53 +08:00
: step === 5 || (step === 0 && user.nickName.length > 6)
2025-06-24 13:18:03 +08:00
? 1
: 0
2025-06-16 11:26:57 +08:00
"
>
2025-11-11 16:31:47 +08:00
<text
v-if="step === 0"
:style="{
fontSize: '28rpx',
marginTop: user.nickName.length > 6 ? '-10rpx' : '0',
}"
>
2025-06-02 14:42:07 +08:00
hi<text :style="{ color: '#fed847' }">{{ user.nickName }}</text>
这是新人必刷小任务0基础小白也能快速掌握弓箭技巧和游戏规则哦~
</text>
2025-11-06 09:38:19 +08:00
<text v-if="step === 1" :style="{ fontSize: '28rpx' }"
2025-06-02 14:42:07 +08:00
>这是我们人帅技高的高教练首先请按教练示范尝试自己去做这些动作和手势吧</text
>
2025-11-06 09:38:19 +08:00
<view
class="guide-tips"
:style="{ marginTop: '8rpx' }"
v-if="step === 2"
>
<text>你知道5米射程有多远吗</text>
<text>
在我们的排位赛中射程小于5米的成绩无效建议平时练习距离至少5米现在来边射箭边调整你的站位点吧
</text>
2025-05-15 12:43:40 +08:00
</view>
2025-11-06 09:38:19 +08:00
<view class="guide-tips" v-if="step === 3">
<text>一切准备就绪</text>
<text :style="{ fontSize: '28rpx' }"
>试着完成一个真正的弓箭手任务吧</text
>
2025-05-15 12:43:40 +08:00
</view>
2025-11-06 09:38:19 +08:00
<view class="guide-tips" v-if="step === 5">
<text>新手试炼场通关啦优秀</text>
<text :style="{ fontSize: '28rpx' }"
>反曲弓运动基本知识和射灵世界系统规则你已Get是不是挺容易呀</text
2025-05-15 12:43:40 +08:00
>
</view>
2025-06-02 14:42:07 +08:00
</Guide>
<image
2025-08-04 18:36:44 +08:00
src="https://static.shelingxingqiu.com/attachment/2025-07-01/db0ehhek5yutxsetyi.png"
2025-06-02 14:42:07 +08:00
class="try-tip"
mode="widthFix"
v-if="step === 0"
/>
<image
2025-11-17 15:49:53 +08:00
src="https://static.shelingxingqiu.com/attachment/2025-11-17/deas80ef1sf9td0leq.png"
2025-06-02 14:42:07 +08:00
class="try-tip"
mode="widthFix"
v-if="step === 3"
/>
<image
2025-08-04 18:36:44 +08:00
src="https://static.shelingxingqiu.com/attachment/2025-07-01/db0ehpz9lav58g5drl.png"
2025-06-02 14:42:07 +08:00
class="try-tip"
mode="widthFix"
v-if="step === 5"
/>
<view style="height: 570px" v-if="step === 1">
2025-07-12 16:01:49 +08:00
<Swiper :onChange="onSwiperIndexChange" :data="guideImages" />
2025-05-10 16:57:36 +08:00
</view>
2025-07-16 17:55:11 +08:00
<ShootProgress v-if="step === 4" tips="请开始连续射箭" :start="start" />
2025-07-05 14:52:41 +08:00
<TestDistance v-if="step === 2" :guide="false" />
2025-06-28 12:03:33 +08:00
<view
2025-07-11 00:47:34 +08:00
class="user-row"
2025-07-05 14:52:41 +08:00
v-if="step === 4"
2025-06-28 12:03:33 +08:00
:style="{ marginBottom: step === 2 ? '40px' : '0' }"
>
2025-07-05 14:52:41 +08:00
<Avatar :src="user.avatar" :size="35" />
2025-10-29 17:26:27 +08:00
<BowPower />
2025-06-17 16:58:24 +08:00
</view>
2025-06-02 14:42:07 +08:00
<BowTarget
2025-07-05 14:52:41 +08:00
v-if="step === 4"
2025-06-17 16:58:24 +08:00
:currentRound="step === 4 ? scores.length : 0"
:totalRound="step === 4 ? total : 0"
2025-06-02 14:42:07 +08:00
:scores="scores"
/>
<ScorePanel
v-if="step === 4"
:total="total"
:rowCount="6"
:scores="scores.map((s) => s.ring)"
2025-05-10 16:57:36 +08:00
/>
2025-06-02 14:42:07 +08:00
<ScoreResult
2025-06-25 18:41:30 +08:00
v-if="practiseResult.arrows"
2025-06-02 14:42:07 +08:00
:rowCount="6"
2025-07-05 13:12:58 +08:00
:total="total"
2025-06-02 14:42:07 +08:00
:onClose="onClose"
:result="practiseResult"
2025-06-29 12:17:24 +08:00
:tipSrc="`../static/${
2025-11-17 17:14:51 +08:00
practiseResult.arrows.filter(
(arrow) => arrow.x !== -30 && arrow.y !== -30
).length < total
? 'un'
: ''
2025-06-29 12:17:24 +08:00
}finish-tip.png`"
2025-06-02 14:42:07 +08:00
/>
2026-01-08 10:30:41 +08:00
<canvas class="share-canvas" id="shareCanvas" type="2d"></canvas>
2025-06-02 14:42:07 +08:00
</view>
2026-01-09 18:12:27 +08:00
<template #bottom>
2026-01-12 10:09:36 +08:00
<SButton :onClick="nextStep" :disabled="btnDisabled">
2025-07-13 11:38:54 +08:00
<BubbleTip v-if="showGuide" :type="step === 1 ? 'long' : 'short'">
2025-07-12 16:01:49 +08:00
<text :style="{ transform: 'translateY(-18rpx)' }">{{
step === 1 ? "学会了,我摆得比教练还帅" : "我找到合适的点位了"
}}</text>
</BubbleTip>
{{ stepButtonTexts[step] }}
</SButton>
2026-01-09 18:12:27 +08:00
</template>
2025-05-23 21:20:38 +08:00
</Container>
2025-05-01 16:36:24 +08:00
</template>
<style scoped>
2025-06-02 14:42:07 +08:00
.container {
width: 100%;
}
2025-05-01 22:58:02 +08:00
.try-tip {
width: calc(100% - 20px);
2025-07-10 15:34:00 +08:00
margin: 0 10px;
2025-05-01 16:36:24 +08:00
}
</style>