后台教程

This commit is contained in:
2025-03-05 14:31:22 +08:00
parent d2d4c2974e
commit 24880e62ad
9 changed files with 48 additions and 19 deletions

View File

@@ -6,8 +6,8 @@
</n-button>
<n-button
v-for="item in menu"
:type="$route.name === item.name ? 'primary' : 'default'"
@click="$router.push({ name: item.name })"
:type="$route.name === item.route.name ? 'primary' : 'default'"
@click="$router.push(item.route)"
>
{{ item.label }}
</n-button>
@@ -18,9 +18,14 @@
</n-flex>
</template>
<script lang="ts" setup>
import { step } from "../store/tutorial"
const menu = [
{ label: "教程", name: "tutorial" },
{ label: "用户", name: "user-manage" },
{
label: "教程",
route: { name: "tutorial", params: { display: step.value } },
},
{ label: "用户", route: { name: "user-manage" } },
]
</script>
<style scoped>

View File

@@ -6,7 +6,11 @@
v-for="item in list"
:key="item.display"
@click="show(item.display)"
style="cursor: pointer"
class="card"
:header-style="{
backgroundColor:
item.display === tutorial.display ? 'rgba(24, 160, 80, 0.1)' : '',
}"
:embedded="!item.is_public"
>
<template #header>
@@ -72,11 +76,14 @@
<script lang="ts" setup>
import { marked } from "marked"
import { computed, onMounted, reactive, ref, watch } from "vue"
import { useRoute, useRouter } from "vue-router"
import { Icon } from "@iconify/vue"
import { Tutorial } from "../api"
import type { TutorialSlim } from "../utils/type"
import { useDialog, useMessage } from "naive-ui"
const route = useRoute()
const router = useRouter()
const message = useMessage()
const confirm = useDialog()
@@ -90,14 +97,11 @@ const tutorial = reactive({
})
const canSubmit = computed(
() =>
tutorial.display && tutorial.title && tutorial.content,
() => tutorial.display && tutorial.title && tutorial.content,
)
async function getContent() {
const res = await Tutorial.list()
list.value = res.list
const data = tutorial.content || res.first?.content
content.value = await marked.parse(data ?? "", { async: true })
list.value = await Tutorial.list()
show(Number(route.params.display))
}
function createNew() {
@@ -137,6 +141,7 @@ async function remove(display: number) {
}
async function show(display: number) {
router.push({ name: "tutorial", params: { display } })
const item = await Tutorial.get(display)
tutorial.display = item.display
tutorial.title = item.title
@@ -173,6 +178,10 @@ onMounted(getContent)
padding-top: 10px;
}
.card {
cursor: pointer;
}
.editor {
height: calc(100vh - 200px);
}