fix
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
import { defineStore } from "pinia"
|
||||
import { LANGUAGE, Problem } from "utils/types"
|
||||
import type { LANGUAGE, Problem } from "utils/types"
|
||||
|
||||
/**
|
||||
* 题目状态管理 Store
|
||||
* 管理当前题目的信息
|
||||
*/
|
||||
export const useProblemStore = defineStore("problem", () => {
|
||||
// ==================== 状态 ====================
|
||||
const problem = ref<Problem | null>(null)
|
||||
const route = useRoute()
|
||||
|
||||
// 本次会话内累计的失败次数(与服务端 my_failed_count 叠加)
|
||||
const localFailCount = ref(0)
|
||||
const failCount = ref(0)
|
||||
|
||||
// ==================== 计算属性 ====================
|
||||
const languages = computed<LANGUAGE[]>(() => {
|
||||
if (route.name === "problem" && problem.value?.allow_flowchart) {
|
||||
return ["Flowchart", ...problem.value?.languages]
|
||||
@@ -21,27 +14,21 @@ export const useProblemStore = defineStore("problem", () => {
|
||||
return problem.value?.languages ?? []
|
||||
})
|
||||
|
||||
const totalFailCount = computed(
|
||||
() => (problem.value?.my_failed_count ?? 0) + localFailCount.value,
|
||||
)
|
||||
|
||||
function incrementFailCount() {
|
||||
localFailCount.value++
|
||||
failCount.value++
|
||||
}
|
||||
|
||||
// 切题时重置
|
||||
watch(
|
||||
() => problem.value?.id,
|
||||
() => {
|
||||
localFailCount.value = 0
|
||||
failCount.value = 0
|
||||
},
|
||||
)
|
||||
|
||||
return {
|
||||
problem,
|
||||
localFailCount,
|
||||
failCount,
|
||||
languages,
|
||||
totalFailCount,
|
||||
incrementFailCount,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user