This commit is contained in:
2025-03-03 23:33:55 +08:00
parent e04605c03e
commit 9ed8dda14c
4 changed files with 45 additions and 16 deletions

4
components.d.ts vendored
View File

@@ -25,10 +25,14 @@ declare module 'vue' {
NGrid: typeof import('naive-ui')['NGrid'] NGrid: typeof import('naive-ui')['NGrid']
NIcon: typeof import('naive-ui')['NIcon'] NIcon: typeof import('naive-ui')['NIcon']
NInput: typeof import('naive-ui')['NInput'] NInput: typeof import('naive-ui')['NInput']
NInputNu: typeof import('naive-ui')['NInputNu']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NMessageProvider: typeof import('naive-ui')['NMessageProvider'] NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NModal: typeof import('naive-ui')['NModal'] NModal: typeof import('naive-ui')['NModal']
NModalProvider: typeof import('naive-ui')['NModalProvider'] NModalProvider: typeof import('naive-ui')['NModalProvider']
NS: typeof import('naive-ui')['NS']
NSplit: typeof import('naive-ui')['NSplit'] NSplit: typeof import('naive-ui')['NSplit']
NSwitch: typeof import('naive-ui')['NSwitch']
NTabPane: typeof import('naive-ui')['NTabPane'] NTabPane: typeof import('naive-ui')['NTabPane']
NTabs: typeof import('naive-ui')['NTabs'] NTabs: typeof import('naive-ui')['NTabs']
NTag: typeof import('naive-ui')['NTag'] NTag: typeof import('naive-ui')['NTag']

View File

@@ -60,16 +60,16 @@ export class Tutorial {
return res.data return res.data
} }
static async create(payload: TutorialIn) { static async createOrUpdate(payload: TutorialIn) {
const res = await http.post("/tutorial/", payload) const res = await http.post("/tutorial/", payload)
return res.data return res.data
} }
static async remove(display: string) { static async remove(display: number) {
await http.delete(`/tutorial/${display}`) await http.delete(`/tutorial/${display}`)
} }
static async get(display: string) { static async get(display: number) {
const res = await http.get(`/tutorial/${display}`) const res = await http.get(`/tutorial/${display}`)
return res.data return res.data
} }

View File

@@ -3,12 +3,23 @@
<n-gi :span="2" class="col"> <n-gi :span="2" class="col">
<n-flex vertical class="list"> <n-flex vertical class="list">
<n-card <n-card
style="cursor: pointer"
v-for="item in list" v-for="item in list"
:key="item.display" :key="item.display"
@click="show(item.display)" @click="show(item.display)"
style="cursor: pointer"
> >
<template #header>({{ item.display }}) {{ item.title }}</template> <template #header>
<n-flex align="center">
<Icon
:icon="
item.is_public
? 'twemoji:check-mark-button'
: 'twemoji:locked'
"
></Icon>
<span>{{ item.display }}{{ item.title }}</span>
</n-flex>
</template>
<template #header-extra> <template #header-extra>
<n-button text type="default" @click="remove(item.display)"> <n-button text type="default" @click="remove(item.display)">
<Icon width="20" icon="material-symbols:close-rounded"></Icon> <Icon width="20" icon="material-symbols:close-rounded"></Icon>
@@ -21,10 +32,10 @@
<n-gi :span="3" class="col"> <n-gi :span="3" class="col">
<n-form> <n-form>
<n-grid x-gap="10" :cols="3"> <n-grid x-gap="10" :cols="4">
<n-gi :span="1"> <n-gi :span="1">
<n-form-item label="序号"> <n-form-item label="序号">
<n-input v-model:value="tutorial.display" /> <n-input-number v-model:value="tutorial.display" />
</n-form-item> </n-form-item>
</n-gi> </n-gi>
<n-gi :span="2"> <n-gi :span="2">
@@ -32,9 +43,18 @@
<n-input v-model:value="tutorial.title" /> <n-input v-model:value="tutorial.title" />
</n-form-item> </n-form-item>
</n-gi> </n-gi>
<n-gi :span="1">
<n-form-item label="公开">
<n-switch v-model:value="tutorial.is_public" />
</n-form-item>
</n-gi>
</n-grid> </n-grid>
<n-form-item label="内容"> <n-form-item label="内容">
<n-input v-model:value="tutorial.content" type="textarea" class="editor" /> <n-input
v-model:value="tutorial.content"
type="textarea"
class="editor"
/>
</n-form-item> </n-form-item>
<n-button block type="primary" @click="submit" :disabled="!canSubmit"> <n-button block type="primary" @click="submit" :disabled="!canSubmit">
提交 提交
@@ -60,9 +80,10 @@ const confirm = useDialog()
const list = ref<TutorialSlim[]>([]) const list = ref<TutorialSlim[]>([])
const content = ref("") const content = ref("")
const tutorial = useStorage("web-tutorial", { const tutorial = useStorage("web-tutorial", {
display: "", display: 0,
title: "", title: "",
content: "", content: "",
is_public: false,
}) })
const canSubmit = computed( const canSubmit = computed(
@@ -77,18 +98,20 @@ async function getContent() {
} }
function createNew() { function createNew() {
tutorial.value.display = "" tutorial.value.display = list.value[list.value.length - 1].display + 1
tutorial.value.title = "" tutorial.value.title = ""
tutorial.value.content = "" tutorial.value.content = ""
tutorial.value.is_public = false
content.value = "" content.value = ""
} }
async function submit() { async function submit() {
try { try {
await Tutorial.create(tutorial.value) await Tutorial.createOrUpdate(tutorial.value)
tutorial.value.display = "" tutorial.value.display = 0
tutorial.value.title = "" tutorial.value.title = ""
tutorial.value.content = "" tutorial.value.content = ""
tutorial.value.is_public = false
await getContent() await getContent()
content.value = "" content.value = ""
} catch (error: any) { } catch (error: any) {
@@ -96,7 +119,7 @@ async function submit() {
} }
} }
async function remove(display: string) { async function remove(display: number) {
confirm.warning({ confirm.warning({
title: "警告", title: "警告",
content: "你确定要删除吗?", content: "你确定要删除吗?",
@@ -110,13 +133,15 @@ async function remove(display: string) {
}) })
} }
async function show(display: string) { async function show(display: number) {
const item = await Tutorial.get(display) const item = await Tutorial.get(display)
tutorial.value.display = item.display tutorial.value.display = item.display
tutorial.value.title = item.title tutorial.value.title = item.title
tutorial.value.content = item.content tutorial.value.content = item.content
tutorial.value.is_public = item.is_public
content.value = await marked.parse(item.content, { async: true }) content.value = await marked.parse(item.content, { async: true })
} }
watch( watch(
() => tutorial.value.content, () => tutorial.value.content,
async (v: string) => { async (v: string) => {

View File

@@ -5,13 +5,13 @@ export enum Role {
} }
export interface TutorialSlim { export interface TutorialSlim {
display: string display: number
title: string title: string
is_public: boolean is_public: boolean
} }
export interface TutorialIn { export interface TutorialIn {
display: string display: number
title: string title: string
content: string content: string
} }