fix
This commit is contained in:
@@ -7,7 +7,7 @@ import { marked } from "marked"
|
|||||||
import copyFn from "copy-text-to-clipboard"
|
import copyFn from "copy-text-to-clipboard"
|
||||||
import { css, html, js, tab } from "../../store/editors"
|
import { css, html, js, tab } from "../../store/editors"
|
||||||
import { Tutorial } from "../../api"
|
import { Tutorial } from "../../api"
|
||||||
import { step, tutorialIds } from "../../store/tutorial"
|
import { step, tutorialIds, loadTutorials } from "../../store/tutorial"
|
||||||
import { taskId } from "../../store/task"
|
import { taskId } from "../../store/task"
|
||||||
import { useRouter } from "vue-router"
|
import { useRouter } from "vue-router"
|
||||||
|
|
||||||
@@ -36,17 +36,6 @@ const router = useRouter()
|
|||||||
const content = ref("")
|
const content = ref("")
|
||||||
const $content = useTemplateRef<any>("$content")
|
const $content = useTemplateRef<any>("$content")
|
||||||
|
|
||||||
async function prepare() {
|
|
||||||
tutorialIds.value = await Tutorial.listDisplay()
|
|
||||||
if (!tutorialIds.value.length) {
|
|
||||||
content.value = "暂无教程"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!tutorialIds.value.includes(step.value)) {
|
|
||||||
step.value = tutorialIds.value[0] as number
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function render() {
|
async function render() {
|
||||||
const data = await Tutorial.get(step.value)
|
const data = await Tutorial.get(step.value)
|
||||||
taskId.value = data.task_ptr
|
taskId.value = data.task_ptr
|
||||||
@@ -85,7 +74,11 @@ function setupCodeActions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
await prepare()
|
await loadTutorials()
|
||||||
|
if (!tutorialIds.value.length) {
|
||||||
|
content.value = "暂无教程"
|
||||||
|
return
|
||||||
|
}
|
||||||
render()
|
render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
import { useStorage } from "@vueuse/core"
|
import { useStorage } from "@vueuse/core"
|
||||||
import { ref } from "vue"
|
import { ref } from "vue"
|
||||||
|
import { Tutorial } from "../api"
|
||||||
|
|
||||||
export const step = useStorage("tutorial-step", 1)
|
export const step = useStorage("tutorial-step", 1)
|
||||||
export const tutorialIds = ref<number[]>([])
|
export const tutorialIds = ref<number[]>([])
|
||||||
|
|
||||||
|
export async function loadTutorials(): Promise<void> {
|
||||||
|
tutorialIds.value = await Tutorial.listDisplay()
|
||||||
|
if (tutorialIds.value.length && !tutorialIds.value.includes(step.value)) {
|
||||||
|
step.value = tutorialIds.value[0] as number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function prevDisabled(): boolean {
|
export function prevDisabled(): boolean {
|
||||||
const i = tutorialIds.value.indexOf(step.value)
|
const i = tutorialIds.value.indexOf(step.value)
|
||||||
return i <= 0
|
return i <= 0
|
||||||
|
|||||||
Reference in New Issue
Block a user