Skip to content

Commit

Permalink
article edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
redXpanda authored and bbbbbbbbbbbbba committed Mar 23, 2024
1 parent 105c0c2 commit 09d064f
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/internal/controllers/api/article_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (c *ArticleController) GetEditBy(articleId int64) *web.JsonResult {
}

return web.NewEmptyRspBuilder().
Put("id", article.Id).
Put("articleId", article.Id).
Put("title", article.Title).
Put("content", article.Content).
Expand Down
132 changes: 132 additions & 0 deletions site/src/pages/article/edit/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<template>
<section class="main">
<div class="container" v-if="postForm">
<div class="article-create-form">
<h1 class="title">修改文章</h1>

<div class="field">
<div class="control">
<div
v-for="node in nodes"
:key="node.id"
class="article-tag"
:class="{ selected: postForm.nodeId === node.id }"
@click="postForm.nodeId = node.id"
>
<span>{{ node.name }}</span>
</div>
</div>
</div>

<div class="field">
<div class="control">
<input
v-model="postForm.title"
class="input article-title"
type="text"
placeholder="请输入文章标题"
/>
</div>
</div>

<div class="field">
<div class="control">
<markdown-editor
v-model="postForm.content"
placeholder="可空,将图片复制或拖入编辑器可上传"
/>
</div>
</div>

<div v-if="isEnableHideContent || postForm.hideContent" class="field">
<div class="control">
<markdown-editor
ref="mdEditor"
v-model="postForm.hideContent"
height="200px"
placeholder="隐藏内容,评论后可见"
/>
</div>
</div>

<div class="field">
<div class="control">
<tag-input v-model="postForm.tags" />
</div>
</div>

<div class="field is-grouped">
<div class="control">
<a
v-if="publishing"
:class="{ 'is-loading': publishing }"
disabled
class="button is-success"
>提交更改</a
>
<a
v-else
:class="{ 'is-loading': publishing }"
class="button is-success"
@click="submitCreate"
>提交更改</a
>
</div>
</div>
</div>
</div>
</section>
</template>

<script setup>
definePageMeta({
middleware: "auth",
});
useHead({
title: useSiteTitle("修改文章"),
});
const route = useRoute();
const configStore = useConfigStore();
const isEnableHideContent = computed(() => {
return configStore.config.enableHideContent;
});
const { data: nodes } = useAsyncData("nodes", () =>
useMyFetch("/api/article/nodes")
);
const { data: postForm } = useAsyncData(() =>
useMyFetch(`/api/article/edit/${route.params.id}`)
);
const publishing = ref(false);
async function submitCreate() {
if (publishing.value) {
return;
}
publishing.value = true;
try {
useHttpPostForm(`/api/article/edit/${postForm.value.id}`, {
body: {
title: postForm.value.title,
content: postForm.value.content,
cover: postForm.value.cover,
tags: postForm.value.tags ? postForm.value.tags.join(",") : "",
},
});
useMsg({
message: "修改成功",
onClose() {
useLinkTo(`/article/${postForm.value.id}`);
},
});
} catch (e) {
publishing.value = false;
useMsgError("提交失败:" + (e.message || e));
}
}
</script>

<style lang="scss" scoped></style>

0 comments on commit 09d064f

Please sign in to comment.