update:代码备份
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
<script setup>
|
||||
import { computed, nextTick, ref } from "vue";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import TargetPicker from "@/components/TargetPicker.vue";
|
||||
import TrainingDifficultyBadge from "@/components/training/TrainingDifficultyBadge.vue";
|
||||
import TrainingDifficultyPreviewCard from "@/components/training/TrainingDifficultyPreviewCard.vue";
|
||||
import TrainingDifficultyStartButton from "@/components/training/TrainingDifficultyStartButton.vue";
|
||||
import TrainingDifficultyBadge from "./components/TrainingDifficultyBadge.vue";
|
||||
import TrainingDifficultyPreviewCard from "./components/TrainingDifficultyPreviewCard.vue";
|
||||
import TrainingDifficultyStartButton from "./components/TrainingDifficultyStartButton.vue";
|
||||
import { getTrainingDifficultyListAPI } from "@/apis";
|
||||
|
||||
// 难度页接口数据源:
|
||||
// 1. 接口:GET /training/difficulty/list?type=base/endurance/precision/rhythm
|
||||
// 2. 当前进度:接口 user_levels / list.completed,路由参数可覆盖选中难度
|
||||
const trainingDifficultyStorageKey = "training-selection";
|
||||
const trainingDifficultyRefreshEvent = "training-difficulty-refresh";
|
||||
const defaultTrainingType = "precision";
|
||||
const defaultUnlockedDifficultyId = "lv1";
|
||||
const trainingTypeMetaMap = {
|
||||
@@ -234,6 +235,8 @@ const selectedDifficultyId = ref(defaultUnlockedDifficultyId);
|
||||
const showTargetPicker = ref(false);
|
||||
const nodesScrollTop = ref(0);
|
||||
const nodesScrollWithAnimation = ref(false);
|
||||
const routeOptions = ref({});
|
||||
const needRefreshProgress = ref(false);
|
||||
|
||||
const difficultyProgressMap = computed(() => {
|
||||
return pageConfig.value?.progressMap || {};
|
||||
@@ -525,11 +528,14 @@ const applyPageState = (options = {}, config) => {
|
||||
});
|
||||
};
|
||||
|
||||
const initPageState = async (options = {}) => {
|
||||
const initPageState = async (options = {}, refreshOptions = {}) => {
|
||||
const { keepCurrent = false } = refreshOptions;
|
||||
const trainingType = resolveTrainingType(options.mode);
|
||||
const fallbackConfig = createEmptyModeConfig(trainingType);
|
||||
|
||||
pageConfig.value = fallbackConfig;
|
||||
if (!keepCurrent) {
|
||||
pageConfig.value = fallbackConfig;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await getTrainingDifficultyListAPI(trainingType);
|
||||
@@ -539,7 +545,9 @@ const initPageState = async (options = {}) => {
|
||||
);
|
||||
} catch (error) {
|
||||
console.log("training difficulty load failed", error);
|
||||
applyPageState(options, fallbackConfig);
|
||||
if (!keepCurrent) {
|
||||
applyPageState(options, fallbackConfig);
|
||||
}
|
||||
uni.showToast({
|
||||
title: "训练难度加载失败",
|
||||
icon: "none",
|
||||
@@ -625,9 +633,30 @@ const handleTargetConfirm = (target) => {
|
||||
});
|
||||
};
|
||||
|
||||
const markProgressRefresh = () => {
|
||||
needRefreshProgress.value = true;
|
||||
};
|
||||
|
||||
onLoad((options = {}) => {
|
||||
routeOptions.value = { ...options };
|
||||
uni.$on(trainingDifficultyRefreshEvent, markProgressRefresh);
|
||||
initPageState(options);
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
if (!needRefreshProgress.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
needRefreshProgress.value = false;
|
||||
initPageState(routeOptions.value, {
|
||||
keepCurrent: true,
|
||||
});
|
||||
});
|
||||
|
||||
onUnload(() => {
|
||||
uni.$off(trainingDifficultyRefreshEvent, markProgressRefresh);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user