代码优化

This commit is contained in:
kron
2025-06-02 14:42:07 +08:00
parent 43889669d7
commit 1eab5a151e
6 changed files with 118 additions and 119 deletions

View File

@@ -119,10 +119,3 @@ export const readyGameAPI = (battleId) => {
battleId, battleId,
}); });
}; };
export const finishGameAPI = (battleId, arrow) => {
return request("POST", "/user/game/shoot", {
battleId,
arrow,
});
};

View File

@@ -28,5 +28,9 @@ defineProps({
width: 100%; width: 100%;
height: calc(100vh - 96px); height: calc(100vh - 96px);
overflow: auto; overflow: auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
} }
</style> </style>

View File

@@ -46,6 +46,7 @@ onMounted(() => {
if (scores.value.length === total) { if (scores.value.length === total) {
showScore.value = true; showScore.value = true;
} }
// if (step.value === 2 && msg.target.dst / 100 > 5) {
if (step.value === 2 && msg.target.dst > 5) { if (step.value === 2 && msg.target.dst > 5) {
btnDisabled.value = false; btnDisabled.value = false;
} }
@@ -68,7 +69,6 @@ const nextStep = async () => {
if (step.value === 0) { if (step.value === 0) {
step.value = 1; step.value = 1;
} else if (step.value === 1) { } else if (step.value === 1) {
await createPractise(1);
btnDisabled.value = true; btnDisabled.value = true;
step.value = 2; step.value = 2;
} else if (step.value === 2) { } else if (step.value === 2) {
@@ -95,109 +95,116 @@ const onClose = () => {
<template> <template>
<Container :bgType="1" title="新手试炼场"> <Container :bgType="1" title="新手试炼场">
<Guide v-if="step !== 4" :tall="step === 2 || step === 5"> <view class="container">
<text v-if="step === 0"> <Guide v-if="step !== 4" :tall="step === 2 || step === 5">
hi<text :style="{ color: '#fed847' }">{{ user.nickName }}</text> <text v-if="step === 0">
这是新人必刷小任务0基础小白也能快速掌握弓箭技巧和游戏规则哦~ hi<text :style="{ color: '#fed847' }">{{ user.nickName }}</text>
</text> 这是新人必刷小任务0基础小白也能快速掌握弓箭技巧和游戏规则哦~
<text v-if="step === 1" </text>
>这是我们人帅技高的高教练首先请按教练示范尝试自己去做这些动作和手势吧</text <text v-if="step === 1"
> >这是我们人帅技高的高教练首先请按教练示范尝试自己去做这些动作和手势吧</text
<view v-if="step === 2">
<view :style="{ display: 'flex', flexDirection: 'column' }">
<text :style="{ color: '#fed847' }">你知道5米射程有多远吗</text>
<text>
在我们的排位赛中射程小于5米的成绩无效建议平时练习距离至少5米现在来边射箭边调整你的站位点吧
</text>
</view>
</view>
<view v-if="step === 3">
<view :style="{ display: 'flex', flexDirection: 'column' }">
<text :style="{ color: '#fed847' }">一切准备就绪</text>
<text>试着完成一个真正的弓箭手任务吧</text>
</view>
</view>
<view v-if="step === 5">
<view
:style="{ display: 'flex', flexDirection: 'column', marginTop: 20 }"
> >
<text :style="{ color: '#fed847' }">新手试炼场通关啦优秀</text> <view v-if="step === 2">
<text <view :style="{ display: 'flex', flexDirection: 'column' }">
>反曲弓运动基本知识和射灵世界系统规则你已Get是不是挺容易呀</text <text :style="{ color: '#fed847' }">你知道5米射程有多远吗</text>
> <text>
<!-- 这行是占位用的 --> 在我们的排位赛中射程小于5米的成绩无效建议平时练习距离至少5米现在来边射箭边调整你的站位点吧
<text :style="{ opacity: 0 }">新手试炼场通关啦优秀</text> </text>
</view>
</view> </view>
<view v-if="step === 3">
<view :style="{ display: 'flex', flexDirection: 'column' }">
<text :style="{ color: '#fed847' }">一切准备就绪</text>
<text>试着完成一个真正的弓箭手任务吧</text>
</view>
</view>
<view v-if="step === 5">
<view
:style="{ display: 'flex', flexDirection: 'column', marginTop: 20 }"
>
<text :style="{ color: '#fed847' }">新手试炼场通关啦优秀</text>
<text
>反曲弓运动基本知识和射灵世界系统规则你已Get是不是挺容易呀</text
>
<!-- 这行是占位用的 -->
<text :style="{ opacity: 0 }">新手试炼场通关啦优秀</text>
</view>
</view>
</Guide>
<image
src="../static/first-try-tip.png"
class="try-tip"
mode="widthFix"
v-if="step === 0"
/>
<image
src="../static/first-try-tip2.png"
class="try-tip"
mode="widthFix"
v-if="step === 3"
/>
<image
src="../static/first-try-tip3.png"
class="try-tip"
mode="widthFix"
v-if="step === 5"
/>
<view style="height: 570px" v-if="step === 1">
<Swiper
:data="[
'../static/first-try-tip.png',
'../static/first-try-tip.png',
'../static/first-try-tip.png',
]"
/>
</view> </view>
</Guide> <ShootProgress
<image v-if="step === 4"
src="../static/first-try-tip.png" tips="请开始连续射箭"
class="try-tip" :total="100"
mode="widthFix" :start="start"
v-if="step === 0" />
/> <BowTarget
<image :avatar="user.avatarUrl"
src="../static/first-try-tip2.png" :power="power"
class="try-tip" :debug="step === 2"
mode="widthFix" v-if="step === 2 || step === 4"
v-if="step === 3" :tips="
/> step === 2 && scores.length > 0
<image ? `本次射程${scores[scores.length - 1].dst / 100}米,${
src="../static/first-try-tip3.png" scores[scores.length - 1].dst / 100 >= 5 ? '已' : '未'
class="try-tip" }达到距离要求`
mode="widthFix" : ''
v-if="step === 5" "
/> :scores="scores"
<view style="height: 570px" v-if="step === 1"> />
<Swiper <ScorePanel
:data="[ v-if="step === 4"
'../static/first-try-tip.png', :total="total"
'../static/first-try-tip.png', :rowCount="6"
'../static/first-try-tip.png', :scores="scores.map((s) => s.ring)"
]" />
<ScoreResult
:total="total"
:rowCount="6"
:show="showScore"
v-if="step === 4"
:onClose="onClose"
:result="practiseResult"
/> />
</view> </view>
<ShootProgress <view :style="{ marginBottom: '25px' }">
v-if="step === 4" <SButton v-if="step !== 4" :onClick="nextStep" :disabled="btnDisabled">{{
tips="请开始连续射箭" stepButtonTexts[step]
:total="100" }}</SButton>
:start="start" </view>
/>
<BowTarget
:avatar="user.avatarUrl"
:power="power"
:debug="step === 2"
v-if="step === 2 || step === 4"
:tips="
step === 2 && scores.length > 0
? `本次射程${scores[scores.length - 1].dst}米,${
scores[scores.length - 1].dst >= 5 ? '已' : '未'
}达到距离要求`
: ''
"
:scores="scores"
/>
<ScorePanel
v-if="step === 4"
:total="total"
:rowCount="6"
:scores="scores.map((s) => s.ring)"
/>
<ScoreResult
:total="total"
:rowCount="6"
:show="showScore"
v-if="step === 4"
:onClose="onClose"
:result="practiseResult"
/>
<SButton v-if="step !== 4" :onClick="nextStep" :disabled="btnDisabled">{{
stepButtonTexts[step]
}}</SButton>
</Container> </Container>
</template> </template>
<style scoped> <style scoped>
.container {
width: 100%;
}
.try-tip { .try-tip {
width: calc(100% - 20px); width: calc(100% - 20px);
margin: 10px 10px; margin: 10px 10px;

View File

@@ -8,6 +8,7 @@ import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
const store = useStore(); const store = useStore();
const { updateConfig } = store;
// 使用storeToRefs用于UI里显示保持响应性 // 使用storeToRefs用于UI里显示保持响应性
const { user } = storeToRefs(store); const { user } = storeToRefs(store);
@@ -61,28 +62,15 @@ const toMyDevicePage = () => {
} }
}; };
const toAddDevicePage = () => { onMounted(async () => {
if (isLogin()) {
uni.navigateTo({
url: "/pages/add-device",
});
}
};
// 获取全局配置
const getConfig = async () => {
try { try {
const config = await getAppConfig(); const config = await getAppConfig();
console.log("全局配置:", config); console.log("全局配置:", config);
updateConfig(config);
// 这里可以处理配置数据 // 这里可以处理配置数据
} catch (error) { } catch (error) {
console.error("获取配置失败:", error); console.error("获取配置失败:", error);
} }
};
// 页面加载完成后检查本地存储的用户信息并获取配置
onMounted(() => {
getConfig();
}); });
</script> </script>

View File

@@ -59,7 +59,10 @@ const toRankIntroPage = () => {
}" }"
:onClick="toOrderPage" :onClick="toOrderPage"
/> />
<UserItem title="新手试炼场" :onClick="toFristTryPage"> <UserItem
title="新手试炼场"
:onClick="user.trio > 1 ? null : toFristTryPage"
>
<text v-if="user.trio > 1" :style="{ color: '#259249' }">已完成</text> <text v-if="user.trio > 1" :style="{ color: '#259249' }">已完成</text>
<text v-else :style="{ color: '#CC311F' }">未完成</text> <text v-else :style="{ color: '#CC311F' }">未完成</text>
</UserItem> </UserItem>

View File

@@ -14,6 +14,7 @@ export default defineStore("store", {
id: "", id: "",
deviceName: "", deviceName: "",
}, },
config: {},
}), }),
// 计算属性 // 计算属性
@@ -32,6 +33,9 @@ export default defineStore("store", {
this.device.id = deviceId; this.device.id = deviceId;
this.device.deviceName = deviceName; this.device.deviceName = deviceName;
}, },
updateConfig(config) {
this.config = config;
},
}, },
// 开启数据持久化 // 开启数据持久化
@@ -40,7 +44,7 @@ export default defineStore("store", {
strategies: [ strategies: [
{ {
storage: uni.getStorageSync, storage: uni.getStorageSync,
paths: ["user", "device"], // 只持久化用户信息 paths: ["user", "device", "config"], // 只持久化用户信息
}, },
], ],
}, },