完成新的个人练习流程调试
This commit is contained in:
19
src/apis.js
19
src/apis.js
@@ -196,18 +196,23 @@ export const getMyDevicesAPI = () => {
|
||||
return request("GET", "/user/device/getBindings");
|
||||
};
|
||||
|
||||
export const createPractiseAPI = (arrows, mode) => {
|
||||
export const createPractiseAPI = (arrows, time) => {
|
||||
return request("POST", "/user/practice/create", {
|
||||
arrows,
|
||||
mode,
|
||||
shootNumber: arrows,
|
||||
shootTime: time,
|
||||
});
|
||||
};
|
||||
|
||||
export const startPractiseAPI = () => {
|
||||
return request("POST", "/user/practice/begin");
|
||||
};
|
||||
|
||||
export const endPractiseAPI = () => {
|
||||
return request("POST", "/user/practice/stop");
|
||||
};
|
||||
|
||||
export const getPractiseAPI = async (id) => {
|
||||
const result = await request("GET", `/user/practice/get?id=${id}`);
|
||||
const data = { ...(result.UserPracticeRound || {}) };
|
||||
if (data.arrows) data.arrows = JSON.parse(data.arrows);
|
||||
return data;
|
||||
return request("GET", `/user/practice/get?id=${id}`);
|
||||
};
|
||||
|
||||
export const createRoomAPI = (gameType, teamSize) => {
|
||||
|
||||
@@ -50,14 +50,14 @@ onMounted(() => {
|
||||
if (props.result.lvl > user.value.lvl) {
|
||||
showUpgrade.value = true;
|
||||
}
|
||||
totalRing.value = (props.result.arrows || []).reduce(
|
||||
totalRing.value = (props.result.details || []).reduce(
|
||||
(last, next) => last + next.ring,
|
||||
0
|
||||
);
|
||||
});
|
||||
|
||||
const validArrows = computed(() => {
|
||||
return (props.result.arrows || []).filter(
|
||||
return (props.result.details || []).filter(
|
||||
(arrow) => arrow.x !== -30 && arrow.y !== -30
|
||||
).length;
|
||||
});
|
||||
@@ -96,8 +96,8 @@ const getRing = (arrow) => {
|
||||
</view>
|
||||
<view :style="{ gridTemplateColumns: `repeat(${rowCount}, 1fr)` }">
|
||||
<view v-for="(_, index) in new Array(total).fill(0)" :key="index">
|
||||
{{ getRing(result.arrows[index])
|
||||
}}<text v-if="getRing(result.arrows[index]) !== '-'">环</text>
|
||||
{{ getRing(result.details[index])
|
||||
}}<text v-if="getRing(result.details[index]) !== '-'">环</text>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
@@ -133,7 +133,7 @@ const getRing = (arrow) => {
|
||||
}}</text
|
||||
>环的成绩,所有箭支上靶后的平均点间距为<text
|
||||
:style="{ color: '#fed847' }"
|
||||
>{{ Number(result.average_distance.toFixed(2)) }}</text
|
||||
>{{ Number((result.average_distance || 0).toFixed(2)) }}</text
|
||||
>,{{
|
||||
result.spreadEvaluation === "Dispersed"
|
||||
? "还需要持续改进哦~"
|
||||
@@ -161,7 +161,7 @@ const getRing = (arrow) => {
|
||||
</ScreenHint>
|
||||
<BowData
|
||||
:total="result.completed_arrows"
|
||||
:arrows="result.arrows"
|
||||
:arrows="result.details"
|
||||
:show="showBowData"
|
||||
:onClose="() => (showBowData = false)"
|
||||
/>
|
||||
|
||||
@@ -128,14 +128,17 @@ async function onReceiveMessage(msg) {
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
audioManager.play("比赛结束");
|
||||
} else if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
let arrow = {};
|
||||
if (msg.details && Array.isArray(msg.details)) {
|
||||
arrow = msg.details[msg.details.length - 1];
|
||||
} else {
|
||||
if (msg.shootData.playerId !== user.value.id) return;
|
||||
if (msg.shootData) {
|
||||
let key = [];
|
||||
key.push(msg.shootData.ring ? `${msg.shootData.ring}环` : "未上靶");
|
||||
if (!msg.shootData.ring)
|
||||
key.push(`向${getDirectionText(msg.shootData.angle)}调整`);
|
||||
audioManager.play(key, false);
|
||||
if (msg.shootData) arrow = msg.shootData;
|
||||
}
|
||||
let key = [];
|
||||
key.push(arrow.ring ? `${arrow.ring}环` : "未上靶");
|
||||
if (!arrow.ring) key.push(`向${getDirectionText(arrow.angle)}调整`);
|
||||
audioManager.play(key, false);
|
||||
} else if (msg.type === MESSAGETYPESV2.HalfRest) {
|
||||
halfTime.value = true;
|
||||
audioManager.play("中场休息");
|
||||
|
||||
@@ -13,10 +13,15 @@ import BowPower from "@/components/BowPower.vue";
|
||||
import TestDistance from "@/components/TestDistance.vue";
|
||||
import BubbleTip from "@/components/BubbleTip.vue";
|
||||
import audioManager from "@/audioManager";
|
||||
import { createPractiseAPI, getPractiseAPI } from "@/apis";
|
||||
import {
|
||||
createPractiseAPI,
|
||||
startPractiseAPI,
|
||||
endPractiseAPI,
|
||||
getPractiseAPI,
|
||||
} from "@/apis";
|
||||
import { sharePractiseData } from "@/canvas";
|
||||
import { wxShare, debounce } from "@/util";
|
||||
import { MESSAGETYPES } from "@/constants";
|
||||
import { MESSAGETYPESV2 } from "@/constants";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
@@ -62,24 +67,35 @@ const createPractise = async (arrows) => {
|
||||
};
|
||||
|
||||
const onOver = async () => {
|
||||
start.value = false;
|
||||
practiseResult.value = await getPractiseAPI(practiseId.value);
|
||||
start.value = false;
|
||||
};
|
||||
|
||||
async function onReceiveMessage(messages = []) {
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
if (step.value === 2 && msg.target.dst / 100 >= 5) {
|
||||
async function onReceiveMessage(msg) {
|
||||
if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
scores.value = msg.details;
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
setTimeout(onOver, 1500);
|
||||
} else if (msg.type === MESSAGETYPESV2.TestDistance) {
|
||||
if (msg.shootData.distance / 100 >= 5) {
|
||||
audioManager.play("距离合格");
|
||||
btnDisabled.value = false;
|
||||
showGuide.value = true;
|
||||
} else if (scores.value.length < total) {
|
||||
scores.value.push(msg.target);
|
||||
} else audioManager.play("距离不足");
|
||||
}
|
||||
if (scores.value.length === total) {
|
||||
setTimeout(onOver, 1500);
|
||||
}
|
||||
}
|
||||
});
|
||||
// messages.forEach((msg) => {
|
||||
// if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
// if (step.value === 2 && msg.target.dst / 100 >= 5) {
|
||||
// btnDisabled.value = false;
|
||||
// showGuide.value = true;
|
||||
// } else if (scores.value.length < total) {
|
||||
// scores.value.push(msg.target);
|
||||
// }
|
||||
// if (scores.value.length === total) {
|
||||
// setTimeout(onOver, 1500);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
const onClickShare = debounce(async () => {
|
||||
@@ -102,6 +118,7 @@ onBeforeUnmount(() => {
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
uni.$off("share-image", onClickShare);
|
||||
audioManager.stopAll();
|
||||
endPractiseAPI();
|
||||
});
|
||||
|
||||
const nextStep = async () => {
|
||||
@@ -113,13 +130,15 @@ const nextStep = async () => {
|
||||
btnDisabled.value = true;
|
||||
step.value = 2;
|
||||
title.value = "-感知距离";
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
} else if (step.value === 2) {
|
||||
showGuide.value = false;
|
||||
step.value = 3;
|
||||
title.value = "-小试牛刀";
|
||||
} else if (step.value === 3) {
|
||||
title.value = "小试牛刀";
|
||||
await createPractise(total);
|
||||
await startPractiseAPI();
|
||||
scores.value = [];
|
||||
step.value = 4;
|
||||
start.value = true;
|
||||
@@ -133,8 +152,8 @@ const nextStep = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
const validArrows = (practiseResult.value.arrows || []).filter(
|
||||
const onClose = async () => {
|
||||
const validArrows = (practiseResult.value.details || []).filter(
|
||||
(a) => a.x !== -30 && a.y !== -30
|
||||
);
|
||||
if (validArrows.length === total) {
|
||||
@@ -148,6 +167,8 @@ const onClose = () => {
|
||||
start.value = false;
|
||||
scores.value = [];
|
||||
step.value = 3;
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -245,13 +266,13 @@ const onClose = () => {
|
||||
:scores="scores.map((s) => s.ring)"
|
||||
/>
|
||||
<ScoreResult
|
||||
v-if="practiseResult.arrows"
|
||||
v-if="practiseResult.details"
|
||||
:rowCount="6"
|
||||
:total="total"
|
||||
:onClose="onClose"
|
||||
:result="practiseResult"
|
||||
:tipSrc="`../static/${
|
||||
practiseResult.arrows.filter(
|
||||
practiseResult.details.filter(
|
||||
(arrow) => arrow.x !== -30 && arrow.y !== -30
|
||||
).length < total
|
||||
? 'un'
|
||||
|
||||
@@ -40,11 +40,9 @@ const toPage = async (path) => {
|
||||
return;
|
||||
}
|
||||
if (path === "/pages/first-try") {
|
||||
if (canEenter(user.value, device.value, online.value, path)) {
|
||||
await uni.$checkAudio();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// if (canEenter(user.value, device.value, online.value, path)) {
|
||||
// await uni.$checkAudio();
|
||||
// }
|
||||
}
|
||||
uni.navigateTo({ url: path });
|
||||
};
|
||||
|
||||
@@ -13,10 +13,15 @@ import TestDistance from "@/components/TestDistance.vue";
|
||||
import BubbleTip from "@/components/BubbleTip.vue";
|
||||
import audioManager from "@/audioManager";
|
||||
|
||||
import { createPractiseAPI, getPractiseAPI } from "@/apis";
|
||||
import {
|
||||
createPractiseAPI,
|
||||
startPractiseAPI,
|
||||
endPractiseAPI,
|
||||
getPractiseAPI,
|
||||
} from "@/apis";
|
||||
import { sharePractiseData } from "@/canvas";
|
||||
import { wxShare, debounce } from "@/util";
|
||||
import { MESSAGETYPES, roundsName } from "@/constants";
|
||||
import { MESSAGETYPESV2, MESSAGETYPES, roundsName } from "@/constants";
|
||||
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -33,8 +38,7 @@ const showGuide = ref(false);
|
||||
const tips = ref("");
|
||||
|
||||
const onReady = async () => {
|
||||
const result = await createPractiseAPI(total, 2);
|
||||
if (result) practiseId.value = result.id;
|
||||
await startPractiseAPI();
|
||||
currentRound.value = 0;
|
||||
scores.value = [];
|
||||
start.value = true;
|
||||
@@ -42,35 +46,40 @@ const onReady = async () => {
|
||||
};
|
||||
|
||||
const onOver = async () => {
|
||||
start.value = false;
|
||||
practiseResult.value = await getPractiseAPI(practiseId.value);
|
||||
start.value = false;
|
||||
};
|
||||
|
||||
async function onReceiveMessage(messages = []) {
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
if (scores.value.length < total) {
|
||||
scores.value.push(msg.target);
|
||||
currentRound.value += 1;
|
||||
if (currentRound.value === 4) {
|
||||
currentRound.value = 1;
|
||||
}
|
||||
if (practiseId && scores.value.length === total / 2) {
|
||||
showGuide.value = true;
|
||||
setTimeout(() => {
|
||||
showGuide.value = false;
|
||||
}, 3000);
|
||||
}
|
||||
if (scores.value.length === total) {
|
||||
async function onReceiveMessage(msg) {
|
||||
if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
scores.value = msg.details;
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
setTimeout(onOver, 1500);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// messages.forEach((msg) => {
|
||||
// if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
// if (scores.value.length < total) {
|
||||
// scores.value.push(msg.target);
|
||||
// currentRound.value += 1;
|
||||
// if (currentRound.value === 4) {
|
||||
// currentRound.value = 1;
|
||||
// }
|
||||
// if (practiseId && scores.value.length === total / 2) {
|
||||
// showGuide.value = true;
|
||||
// setTimeout(() => {
|
||||
// showGuide.value = false;
|
||||
// }, 3000);
|
||||
// }
|
||||
// if (scores.value.length === total) {
|
||||
// setTimeout(onOver, 1500);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
async function onComplete() {
|
||||
const validArrows = (practiseResult.value.arrows || []).filter(
|
||||
const validArrows = (practiseResult.value.details || []).filter(
|
||||
(a) => a.x !== -30 && a.y !== -30
|
||||
);
|
||||
if (validArrows.length === total) {
|
||||
@@ -81,6 +90,8 @@ async function onComplete() {
|
||||
start.value = false;
|
||||
scores.value = [];
|
||||
currentRound.value = 0;
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,13 +100,15 @@ const onClickShare = debounce(async () => {
|
||||
await wxShare("shareCanvas");
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
audioManager.play("第一轮");
|
||||
onMounted(async () => {
|
||||
// audioManager.play("第一轮");
|
||||
uni.setKeepScreenOn({
|
||||
keepScreenOn: true,
|
||||
});
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
uni.$on("share-image", onClickShare);
|
||||
const result = await createPractiseAPI(total, 120);
|
||||
if (result) practiseId.value = result.id;
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
@@ -105,6 +118,7 @@ onBeforeUnmount(() => {
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
uni.$off("share-image", onClickShare);
|
||||
audioManager.stopAll();
|
||||
endPractiseAPI();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -115,8 +129,8 @@ onBeforeUnmount(() => {
|
||||
:showBottom="!start && !scores.length"
|
||||
>
|
||||
<view>
|
||||
<TestDistance v-if="!practiseId" />
|
||||
<block v-if="practiseId">
|
||||
<TestDistance v-if="!start && !practiseResult.id" />
|
||||
<block v-else>
|
||||
<ShootProgress
|
||||
:tips="`${
|
||||
!start || scores.length === 12
|
||||
@@ -143,13 +157,13 @@ onBeforeUnmount(() => {
|
||||
/>
|
||||
<ScorePanel2 :scores="scores.map((s) => s.ring)" />
|
||||
<ScoreResult
|
||||
v-if="practiseResult.arrows"
|
||||
v-if="practiseResult.details"
|
||||
:rowCount="6"
|
||||
:total="total"
|
||||
:onClose="onComplete"
|
||||
:result="practiseResult"
|
||||
:tipSrc="`../static/${
|
||||
practiseResult.arrows.filter(
|
||||
practiseResult.details.filter(
|
||||
(arrow) => arrow.x !== -30 && arrow.y !== -30
|
||||
).length < total
|
||||
? 'un'
|
||||
|
||||
@@ -12,10 +12,15 @@ import TestDistance from "@/components/TestDistance.vue";
|
||||
import BubbleTip from "@/components/BubbleTip.vue";
|
||||
import audioManager from "@/audioManager";
|
||||
|
||||
import { createPractiseAPI, getPractiseAPI } from "@/apis";
|
||||
import {
|
||||
createPractiseAPI,
|
||||
startPractiseAPI,
|
||||
endPractiseAPI,
|
||||
getPractiseAPI,
|
||||
} from "@/apis";
|
||||
import { sharePractiseData } from "@/canvas";
|
||||
import { wxShare, debounce } from "@/util";
|
||||
import { MESSAGETYPES } from "@/constants";
|
||||
import { MESSAGETYPESV2 } from "@/constants";
|
||||
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -30,41 +35,43 @@ const practiseId = ref("");
|
||||
const showGuide = ref(false);
|
||||
|
||||
const onReady = async () => {
|
||||
const result = await createPractiseAPI(total, 3);
|
||||
if (result) practiseId.value = result.id;
|
||||
await startPractiseAPI();
|
||||
scores.value = [];
|
||||
start.value = true;
|
||||
setTimeout(() => {
|
||||
audioManager.play("练习开始");
|
||||
}, 300);
|
||||
};
|
||||
|
||||
const onOver = async () => {
|
||||
start.value = false;
|
||||
practiseResult.value = await getPractiseAPI(practiseId.value);
|
||||
start.value = false;
|
||||
};
|
||||
|
||||
async function onReceiveMessage(messages = []) {
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
if (scores.value.length < total) {
|
||||
scores.value.push(msg.target);
|
||||
if (practiseId && scores.value.length === total / 2) {
|
||||
showGuide.value = true;
|
||||
setTimeout(() => {
|
||||
showGuide.value = false;
|
||||
}, 3000);
|
||||
}
|
||||
if (scores.value.length === total) {
|
||||
async function onReceiveMessage(msg) {
|
||||
if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
scores.value = msg.details;
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
setTimeout(onOver, 1500);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// messages.forEach((msg) => {
|
||||
// if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
// if (scores.value.length < total) {
|
||||
// scores.value.push(msg.target);
|
||||
// if (practiseId && scores.value.length === total / 2) {
|
||||
// showGuide.value = true;
|
||||
// setTimeout(() => {
|
||||
// showGuide.value = false;
|
||||
// }, 3000);
|
||||
// }
|
||||
// if (scores.value.length === total) {
|
||||
// setTimeout(onOver, 1500);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
async function onComplete() {
|
||||
const validArrows = (practiseResult.value.arrows || []).filter(
|
||||
const validArrows = (practiseResult.value.details || []).filter(
|
||||
(a) => a.x !== -30 && a.y !== -30
|
||||
);
|
||||
if (validArrows.length === total) {
|
||||
@@ -74,7 +81,8 @@ async function onComplete() {
|
||||
practiseResult.value = {};
|
||||
start.value = false;
|
||||
scores.value = [];
|
||||
currentRound.value = 0;
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +91,14 @@ const onClickShare = debounce(async () => {
|
||||
await wxShare("shareCanvas");
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
uni.setKeepScreenOn({
|
||||
keepScreenOn: true,
|
||||
});
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
uni.$on("share-image", onClickShare);
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
@@ -98,14 +108,19 @@ onBeforeUnmount(() => {
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
uni.$off("share-image", onClickShare);
|
||||
audioManager.stopAll();
|
||||
endPractiseAPI();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Container :bgType="1" title="日常耐力挑战" :showBottom="!start && !scores.length">
|
||||
<Container
|
||||
:bgType="1"
|
||||
title="日常耐力挑战"
|
||||
:showBottom="!start && !scores.length"
|
||||
>
|
||||
<view>
|
||||
<TestDistance v-if="!practiseId" />
|
||||
<block v-if="practiseId">
|
||||
<TestDistance v-if="!start && !practiseResult.id" />
|
||||
<block v-else>
|
||||
<ShootProgress
|
||||
:tips="`请连续射${total}支箭`"
|
||||
:start="start"
|
||||
@@ -134,13 +149,13 @@ onBeforeUnmount(() => {
|
||||
:font-size="20"
|
||||
/>
|
||||
<ScoreResult
|
||||
v-if="practiseResult.arrows"
|
||||
v-if="practiseResult.details"
|
||||
:total="total"
|
||||
:rowCount="9"
|
||||
:onClose="onComplete"
|
||||
:result="practiseResult"
|
||||
:tipSrc="`../static/${
|
||||
practiseResult.arrows.filter(
|
||||
practiseResult.details.filter(
|
||||
(arrow) => arrow.x !== -30 && arrow.y !== -30
|
||||
).length < total
|
||||
? '2un'
|
||||
|
||||
@@ -15,7 +15,7 @@ const data = ref({});
|
||||
|
||||
const goPractise = async (type) => {
|
||||
if (!canEenter(user.value, device.value, online.value)) return;
|
||||
await uni.$checkAudio();
|
||||
// await uni.$checkAudio();
|
||||
uni.navigateTo({
|
||||
url: `/pages/practise-${type}`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user