feat: 继续完成...
This commit is contained in:
1 parent
31e253eaef
commit
d7f1bf7d49
8 files changed
+270
-122
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512"><path d="M384 224v184a40 40 0 0 1-40 40H104a40 40 0 0 1-40-40V168a40 40 0 0 1 40-40h167.48" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></path><path d="M459.94 53.25a16.06 16.06 0 0 0-23.22-.56L424.35 65a8 8 0 0 0 0 11.31l11.34 11.32a8 8 0 0 0 11.34 0l12.06-12c6.1-6.09 6.67-16.01.85-22.38z" fill="currentColor"></path><path d="M399.34 90L218.82 270.2a9 9 0 0 0-2.31 3.93L208.16 299a3.91 3.91 0 0 0 4.86 4.86l24.85-8.35a9 9 0 0 0 3.93-2.31L422 112.66a9 9 0 0 0 0-12.66l-9.95-10a9 9 0 0 0-12.71 0z" fill="currentColor"></path></svg>
|
||||||
|
</template>
|
||||||
@@ -1,20 +1,29 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="post-editor">
|
<div class="post-editor">
|
||||||
editor以后再写
|
<!-- editor以后再写 -->
|
||||||
<el-input v-model:model-value="id" placeholder="id" />
|
<el-row :gutter="10">
|
||||||
<el-input v-model:model-value="title" placeholder="title" />
|
<el-col :span="8">
|
||||||
<el-input v-model:model-value="summary" placeholder="summary" />
|
<el-input v-model:model-value="title" placeholder="title">
|
||||||
<el-input-tag v-model:model-value="tags" placeholder="tags" />
|
<template #prepend>标题</template>
|
||||||
<el-input type="textarea" v-model:model-value="content" placeholder="content" autosize />
|
</el-input>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="16">
|
||||||
|
<el-input-tag v-model:model-value="tags" placeholder="添加标签" />
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<el-row>
|
||||||
|
<el-col>
|
||||||
|
<el-input v-model:model-value="summary" placeholder="summary" >
|
||||||
|
<template #prepend>摘要</template>
|
||||||
|
</el-input>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<el-input type="textarea" v-model:model-value="content" placeholder="content" :autosize="{ minRows: 15 }" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import useMiaoFetch from '~/hooks/useMiaoFetch';
|
|
||||||
|
|
||||||
// const { post: { updatePost } } = useMiaoFetch()
|
|
||||||
|
|
||||||
const id = defineModel<number>('id')
|
|
||||||
const title = defineModel<string>('title')
|
const title = defineModel<string>('title')
|
||||||
const summary = defineModel<string>('summary')
|
const summary = defineModel<string>('summary')
|
||||||
const tags = defineModel<string[]>('tags')
|
const tags = defineModel<string[]>('tags')
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
|
<!-- 若route.params.id为new则为新建而非修改 -->
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="post-editor-wrapper">
|
||||||
edit: id-{{ route.params.id }}
|
<editor v-model:title="title" v-model:summary="summary" v-model:tags="tags" v-model:content="content" />
|
||||||
<editor v-model:id="id" v-model:title="title" v-model:summary="summary" v-model:tags="tags"
|
<el-row>
|
||||||
v-model:content="content"></editor>
|
<el-col :span="24">
|
||||||
<el-button @click = handleUpdate>
|
<div class="flex-end">
|
||||||
upload
|
<el-text v-if="message" :type="message.type">{{ message.message }}</el-text>
|
||||||
</el-button>
|
<el-button @click="handleSubmit" style="margin-left: 10px;">
|
||||||
|
upload
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -20,42 +26,114 @@ type resType = {
|
|||||||
} & postItem
|
} & postItem
|
||||||
|
|
||||||
|
|
||||||
const { post: { getPost, updatePost } } = useFetch()
|
const { post: { getPost, updatePost, uploadPost } } = useFetch()
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const id = ref<number>(-1)
|
const id = ref<number>(-1)
|
||||||
const title = ref<string>('title')
|
const title = ref<string>('')
|
||||||
const summary = ref<string>('summary')
|
const summary = ref<string>('')
|
||||||
const tags = ref<string[]>([])
|
const tags = ref<string[]>([])
|
||||||
const content = ref<string>('content')
|
const content = ref<string>('')
|
||||||
|
|
||||||
const handleUpdate = () => {
|
const message = ref<{ type: "" | "success" | "warning" | "info" | "primary" | "danger", message: string }>()
|
||||||
updatePost({
|
|
||||||
id: id.value,
|
const handleSubmit = () => {
|
||||||
title: title.value,
|
if (id.value === -1) {
|
||||||
summary: summary.value,
|
handleUpload()
|
||||||
tags: tags.value,
|
} else {
|
||||||
url: '',
|
handleUpdate()
|
||||||
content: content.value,
|
}
|
||||||
type: 'markdown',
|
|
||||||
date: Date.now()
|
|
||||||
})
|
|
||||||
const store = useDefaultStore()
|
|
||||||
store.deleteCache('posts')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
const handleUpload = async () => {
|
||||||
|
try {
|
||||||
|
const response = await uploadPost({
|
||||||
|
title: title.value,
|
||||||
|
summary: summary.value,
|
||||||
|
tags: tags.value,
|
||||||
|
url: '',
|
||||||
|
content: content.value,
|
||||||
|
type: 'markdown',
|
||||||
|
date: Date.now()
|
||||||
|
})
|
||||||
|
if (response.code !== 200) {
|
||||||
|
throw ('response')
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
id.value = response.id
|
||||||
|
console.log(id.value)
|
||||||
|
message.value = {
|
||||||
|
type: 'success',
|
||||||
|
message: '上传成功'
|
||||||
|
}
|
||||||
|
const store = useDefaultStore()
|
||||||
|
store.deleteCache('posts')
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
message.value = {
|
||||||
|
type: 'danger',
|
||||||
|
message: '上传出错'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
id.value = parseInt(route.params.id as string)
|
const handleUpdate = async () => {
|
||||||
const res = await getPost(id.value) as any as resType
|
try {
|
||||||
console.log(res)
|
const response = await updatePost({
|
||||||
id.value = res.id
|
id: id.value,
|
||||||
title.value = res.title
|
title: title.value,
|
||||||
summary.value = res.summary
|
summary: summary.value,
|
||||||
tags.value = []
|
tags: tags.value,
|
||||||
content.value = res.data
|
url: '',
|
||||||
|
content: content.value,
|
||||||
|
type: 'markdown',
|
||||||
|
date: Date.now()
|
||||||
|
})
|
||||||
|
if (response.code !== 200) {
|
||||||
|
throw ('response')
|
||||||
|
}
|
||||||
|
message.value = {
|
||||||
|
type: 'success',
|
||||||
|
message: '上传成功'
|
||||||
|
}
|
||||||
|
const store = useDefaultStore()
|
||||||
|
store.deleteCache('posts')
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
message.value = {
|
||||||
|
type: 'danger',
|
||||||
|
message: '上传出错'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
console.log('route', route.params.id, route.params.id === 'new')
|
||||||
|
if (route.params.id !== 'new') {
|
||||||
|
id.value = parseInt(route.params.id as string)
|
||||||
|
const res = await getPost(id.value) as any as resType
|
||||||
|
console.log(res)
|
||||||
|
id.value = res.id
|
||||||
|
title.value = res.title
|
||||||
|
summary.value = res.summary
|
||||||
|
tags.value = []
|
||||||
|
content.value = res.data
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped>
|
||||||
|
.post-editor-wrapper {
|
||||||
|
/* box-sizing: border-box; */
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flex-end {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
+122
-75
@@ -4,55 +4,68 @@
|
|||||||
文章列表
|
文章列表
|
||||||
</div>
|
</div>
|
||||||
<div class="post-index-list">
|
<div class="post-index-list">
|
||||||
<div class="post-index-list-item">
|
<el-card class="post-index-list-create" @click="handleNewPost">
|
||||||
上传文章
|
<create class="post-index-list-create-icon"></create>
|
||||||
</div>
|
<div class="post-index-list-create-text">新建文章</div>
|
||||||
<div v-for="post in postList" :key="post.id" class="post-item post-index-list-item">
|
</el-card>
|
||||||
<div class="post-item-header">
|
<el-card class="post-index-list-card" v-for="post in postList" :key="post.id">
|
||||||
<div class="post-item-header-title">
|
<template #header>
|
||||||
{{ post.title }}
|
<div class="post-index-list-card-header">
|
||||||
|
<el-text line-clamp="2">{{ post.title }}</el-text>
|
||||||
|
<el-button @click="handleClickEditBtn(post.id)">
|
||||||
|
编辑
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="post-item-header-date">
|
</template>
|
||||||
{{ formatDate(post.date, 'yy-MM-dd HH:mm:ss') }}
|
<div class="post-index-list-card-content">
|
||||||
</div> -->
|
<div class="post-index-list-card-content-summary">
|
||||||
</div>
|
<el-text line-clamp="2">
|
||||||
<div class="post-item-content">
|
{{ post.summary }}
|
||||||
<span>
|
</el-text>
|
||||||
{{ post.summary }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="post-item-footer">
|
|
||||||
<div class="post-item-footer-info">
|
|
||||||
<div class="post-item-footer-info-date">
|
|
||||||
{{ formatDate(post.date, 'yy-MM-dd HH:mm:ss') }}
|
|
||||||
</div>
|
|
||||||
<div class="post-item-footer-info-tags">
|
|
||||||
<span v-for="tag in post.tags" :key="tag">{{ tag }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<el-button class="post-item-footer-btn" @click="handleClickEditBtn(post.id)">
|
<el-text line-clamp="1">
|
||||||
编辑
|
<el-tag size="small" class="post-index-list-card-content-tag" v-for="tag in post.tags"
|
||||||
</el-button>
|
:key="tag" style="user-select: none;">
|
||||||
|
{{ tag }}
|
||||||
|
</el-tag>
|
||||||
|
</el-text>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<template #footer>
|
||||||
|
<div class="post-index-list-card-footer">
|
||||||
|
{{ formatDate(post.date, 'yyyy-MM-dd HH:mm:ss') }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-card>
|
||||||
|
|
||||||
|
<el-card v-if="isLoading" v-for="_ in 6">
|
||||||
|
<el-skeleton :rows="5" />
|
||||||
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { postItem } from '~/types/post';
|
import type { postItem } from '~/types/post';
|
||||||
|
import create from '~/components/icons/create.vue';
|
||||||
import getPostList from '~/utils/getPost';
|
import getPostList from '~/utils/getPost';
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
const isLoading = ref(true);
|
||||||
|
|
||||||
const postList = ref<postItem[]>([]);
|
const postList = ref<postItem[]>([]);
|
||||||
|
|
||||||
const handleClickEditBtn = (id: number) => {
|
const handleClickEditBtn = (id: number) => {
|
||||||
router.push(`/user/main/post/edit-${id}`)
|
router.push(`/user/main/post/edit-${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleNewPost = () => {
|
||||||
|
router.push('/user/main/post/edit-new')
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
postList.value = await getPostList();
|
postList.value = await getPostList();
|
||||||
|
isLoading.value = false;
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -85,65 +98,99 @@ onMounted(async () => {
|
|||||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
|
|
||||||
&-item {
|
&-create {
|
||||||
// height: 100px;
|
display: flex;
|
||||||
border-radius: 5px;
|
flex-direction: column;
|
||||||
border: 1px solid #ccc;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&-text {
|
||||||
|
letter-spacing: 2px;
|
||||||
|
transform: translateX(-2px);
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-item {
|
&-card {
|
||||||
box-sizing: border-box;
|
|
||||||
overflow: hidden;
|
|
||||||
padding-bottom: 5px;
|
|
||||||
|
|
||||||
// padding: 10px;
|
|
||||||
&-header {
|
&-header {
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-between;
|
|
||||||
|
|
||||||
&-title {
|
|
||||||
width: 100%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
text-align: center;
|
|
||||||
letter-spacing: 4px;
|
|
||||||
text-decoration: none;
|
|
||||||
font-size: large;
|
|
||||||
background-color: #15aa87;
|
|
||||||
color: #fff;
|
|
||||||
padding: 3px 0 5px;
|
|
||||||
// font-family: PT Serif, Serif;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&-content {
|
|
||||||
max-height: 45px;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
text-indent: 2em;
|
|
||||||
color: #363636;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-footer {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-top: 5px;
|
}
|
||||||
|
|
||||||
&-info {
|
&-content {
|
||||||
padding: 0 5px;
|
&-tags {
|
||||||
|
display: flex;
|
||||||
&>div {
|
height: 25px;
|
||||||
font-size: 10px;
|
max-width: calc(100% - 0px);
|
||||||
}
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-btn {
|
&-tag:not(:first-child) {
|
||||||
height: 25px;
|
margin: 0 5px;
|
||||||
margin-right: 10px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-footer {
|
||||||
|
font-size: smaller;
|
||||||
|
color: #686868;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .post-item {
|
||||||
|
// box-sizing: border-box;
|
||||||
|
// overflow: hidden;
|
||||||
|
// padding-bottom: 5px;
|
||||||
|
|
||||||
|
// // padding: 10px;
|
||||||
|
// &-header {
|
||||||
|
// display: flex;
|
||||||
|
// flex-direction: column;
|
||||||
|
// justify-content: space-between;
|
||||||
|
|
||||||
|
// &-title {
|
||||||
|
// width: 100%;
|
||||||
|
// box-sizing: border-box;
|
||||||
|
// text-align: center;
|
||||||
|
// letter-spacing: 4px;
|
||||||
|
// text-decoration: none;
|
||||||
|
// font-size: large;
|
||||||
|
// background-color: #15aa87;
|
||||||
|
// color: #fff;
|
||||||
|
// padding: 3px 0 5px;
|
||||||
|
// // font-family: PT Serif, Serif;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// &-content {
|
||||||
|
// max-height: 45px;
|
||||||
|
// overflow: hidden;
|
||||||
|
// text-overflow: ellipsis;
|
||||||
|
// text-indent: 2em;
|
||||||
|
// color: #363636;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// &-footer {
|
||||||
|
// display: flex;
|
||||||
|
// justify-content: space-between;
|
||||||
|
// align-items: center;
|
||||||
|
// margin-top: 5px;
|
||||||
|
|
||||||
|
// &-info {
|
||||||
|
// padding: 0 5px;
|
||||||
|
|
||||||
|
// &>div {
|
||||||
|
// font-size: 10px;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// &-btn {
|
||||||
|
// height: 25px;
|
||||||
|
// margin-right: 10px;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -30,6 +30,6 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
data: posts
|
data: posts.reverse()
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -42,6 +42,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
const tags = tagsArray.slice(0, 15).concat(new Array(15 - tagsArray.length).fill(null));
|
const tags = tagsArray.slice(0, 15).concat(new Array(15 - tagsArray.length).fill(null));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let id = -1
|
||||||
db.transaction(() => {
|
db.transaction(() => {
|
||||||
// 插入tags表
|
// 插入tags表
|
||||||
const tagResult = insertTagsStmt.run(...tags);
|
const tagResult = insertTagsStmt.run(...tags);
|
||||||
@@ -51,13 +52,16 @@ export default defineEventHandler(async (event) => {
|
|||||||
const postResult = insertPostStmt.run(title, summary, type, url, date, tagId);
|
const postResult = insertPostStmt.run(title, summary, type, url, date, tagId);
|
||||||
const postId = postResult.lastInsertRowid;
|
const postId = postResult.lastInsertRowid;
|
||||||
|
|
||||||
|
id = postId as number;
|
||||||
|
|
||||||
// 插入postContent表
|
// 插入postContent表
|
||||||
insertContentStmt.run(postId, content);
|
insertContentStmt.run(postId, content);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
msg: '插入成功'
|
msg: '插入成功',
|
||||||
|
id
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('插入数据时出错:', error);
|
console.error('插入数据时出错:', error);
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.miao-button {
|
||||||
|
|
||||||
|
}
|
||||||
+5
-1
@@ -8,8 +8,12 @@
|
|||||||
"server/**/*",
|
"server/**/*",
|
||||||
"style/**/*",
|
"style/**/*",
|
||||||
"utils/**/*",
|
"utils/**/*",
|
||||||
".nuxt/*.d.ts",
|
|
||||||
"types/**/*",
|
"types/**/*",
|
||||||
"plugins/**/*",
|
"plugins/**/*",
|
||||||
|
".nuxt/imports.d.ts",
|
||||||
|
".nuxt/nuxt.d.ts",
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
".nuxt/components.d.ts",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user