update:代码备份
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
import { computed, nextTick, ref } from "vue";
|
||||
import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import TargetPicker from "@/components/TargetPicker.vue";
|
||||
import TrainingDifficultyBadge from "./components/TrainingDifficultyBadge.vue";
|
||||
import TrainingDifficultyPreviewCard from "./components/TrainingDifficultyPreviewCard.vue";
|
||||
import TrainingDifficultyStartButton from "./components/TrainingDifficultyStartButton.vue";
|
||||
@@ -40,6 +39,7 @@ const routeModeTypeMap = {
|
||||
precision: "precision",
|
||||
rhythm: "rhythm",
|
||||
};
|
||||
const defaultTargetType = 1;
|
||||
|
||||
const resolveTrainingType = (mode) => {
|
||||
const normalizedMode = String(mode || "").toLowerCase();
|
||||
@@ -232,7 +232,6 @@ const emptyDifficulty = {
|
||||
const pageConfig = ref(createEmptyModeConfig(defaultTrainingType));
|
||||
const unlockedDifficultyId = ref(defaultUnlockedDifficultyId);
|
||||
const selectedDifficultyId = ref(defaultUnlockedDifficultyId);
|
||||
const showTargetPicker = ref(false);
|
||||
const nodesScrollTop = ref(0);
|
||||
const nodesScrollWithAnimation = ref(false);
|
||||
const routeOptions = ref({});
|
||||
@@ -555,11 +554,63 @@ const initPageState = async (options = {}, refreshOptions = {}) => {
|
||||
}
|
||||
};
|
||||
|
||||
const resolveTargetPaperType = (target) => {
|
||||
return Number(target) === 1 ? "20厘米全环靶" : "40厘米全环靶";
|
||||
const cleanQueryValue = (value) => {
|
||||
if (value === undefined || value === null || value === "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (typeof value === "number" && !Number.isFinite(value)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
const saveTrainingContext = (target) => {
|
||||
const createPracticeQuery = (difficulty) => {
|
||||
const trainingType = pageConfig.value.key || defaultTrainingType;
|
||||
const commonQuery = {
|
||||
type: trainingType,
|
||||
difficultyId: difficulty.id,
|
||||
difficulty: difficulty.level,
|
||||
recordId: difficulty.recordId,
|
||||
arrows: toNumber(difficulty.arrows, 12),
|
||||
time: toNumber(difficulty.time_limit, 120) || 120,
|
||||
target: defaultTargetType,
|
||||
};
|
||||
const typedQueryMap = {
|
||||
base: {
|
||||
hitReq: toNumber(difficulty.hit_req),
|
||||
},
|
||||
endurance: {
|
||||
totalReq: toNumber(difficulty.total_req),
|
||||
},
|
||||
precision: {
|
||||
blocks: toNumber(difficulty.blocks),
|
||||
mode: toNumber(difficulty.mode),
|
||||
},
|
||||
rhythm: {
|
||||
hitReq: toNumber(difficulty.hit_req),
|
||||
mode: toNumber(difficulty.mode),
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
...commonQuery,
|
||||
...(typedQueryMap[trainingType] || {}),
|
||||
};
|
||||
};
|
||||
|
||||
const createPracticeUrl = (difficulty) => {
|
||||
const query = Object.entries(createPracticeQuery(difficulty))
|
||||
.map(([key, value]) => [key, cleanQueryValue(value)])
|
||||
.filter(([, value]) => value !== "")
|
||||
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
||||
.join("&");
|
||||
|
||||
return `/pages/training/practise-one${query ? `?${query}` : ""}`;
|
||||
};
|
||||
|
||||
const saveTrainingContext = () => {
|
||||
const difficulty = selectedDifficulty.value;
|
||||
|
||||
if (!difficulty.id) {
|
||||
@@ -571,9 +622,8 @@ const saveTrainingContext = (target) => {
|
||||
trainingTitle: pageConfig.value.title,
|
||||
difficultyId: difficulty.id,
|
||||
difficultyLabel: difficulty.label,
|
||||
targetPaperType: target
|
||||
? resolveTargetPaperType(target)
|
||||
: difficulty.targetPaperType,
|
||||
targetType: defaultTargetType,
|
||||
targetPaperType: difficulty.targetPaperType,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -606,30 +656,8 @@ const handleStart = () => {
|
||||
}
|
||||
|
||||
saveTrainingContext();
|
||||
uni.showToast({
|
||||
title: `${selectedDifficulty.value.title} 即将开始`,
|
||||
icon: "none",
|
||||
});
|
||||
};
|
||||
|
||||
const openTargetPicker = () => {
|
||||
if (!selectedDifficulty.value.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
showTargetPicker.value = true;
|
||||
};
|
||||
|
||||
const handleTargetConfirm = (target) => {
|
||||
showTargetPicker.value = false;
|
||||
saveTrainingContext(target);
|
||||
// uni.showToast({
|
||||
// title: `${selectedDifficulty.value.title} 即将开始`,
|
||||
// icon: "none",
|
||||
// });
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages/training/practise-one?target=${target}`,
|
||||
url: createPracticeUrl(selectedDifficulty.value),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -708,15 +736,10 @@ onUnload(() => {
|
||||
<view class="difficulty-page__start">
|
||||
<TrainingDifficultyStartButton
|
||||
:text="selectedDifficulty.startText"
|
||||
@click="openTargetPicker"
|
||||
@click="handleStart"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<TargetPicker
|
||||
:show="showTargetPicker"
|
||||
:onClose="() => (showTargetPicker = false)"
|
||||
:onConfirm="handleTargetConfirm"
|
||||
/>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user