From 4d52c2ae82837e348a449cbd7519c9635ca8e4ef Mon Sep 17 00:00:00 2001 From: Cxx0822 <1556464090@qq.com> Date: Thu, 23 Oct 2025 19:55:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E8=8D=89=E7=A8=BF?= =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/blog.ts | 15 ++------------- src/store/blog.ts | 11 +++++------ src/types/blog.ts | 2 ++ src/utils/element/elRules.ts | 6 +++--- src/views/blog/article.vue | 6 ++++++ src/views/blog/detail[id].vue | 9 +++++++-- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/apis/blog.ts b/src/apis/blog.ts index 46d40de..ad39101 100644 --- a/src/apis/blog.ts +++ b/src/apis/blog.ts @@ -1,26 +1,15 @@ import { cloudService } from './index' -import { IBlog, IBlogCategory, IBlogComment, IBlogStats, IBlogVisit, INewBlog, IQueryBlog } from '@/types/blog' +import { IBlog, IBlogCategory, IBlogComment, IBlogStats, IBlogVisit, INewBlog } from '@/types/blog' -import qs from 'qs' import { IPageRecord } from '@/types' export const queryBlogApi = (currentPage: number, pageSize: number): Promise> => cloudService({ - url: '/blog-api/blog/page', + url: '/blog-api/blog/all/page', method: 'get', params: { currentPage, pageSize } }) -export const queryBlogByConditionApi = (query: IQueryBlog): Promise => - cloudService({ - url: '/blog-api/blog/condition', - method: 'get', - params: query, - paramsSerializer: (params) => { - return qs.stringify(params, { arrayFormat: 'indices' }) - } - }) - export const queryBlogByIdApi = (id: number): Promise => cloudService({ url: `/blog-api/blog/${id}/content`, diff --git a/src/store/blog.ts b/src/store/blog.ts index c725a6d..4cac976 100644 --- a/src/store/blog.ts +++ b/src/store/blog.ts @@ -5,7 +5,7 @@ import { } from '@/types/blog' import { addBlogApi, addBlogCommentApi, deleteBlogApi, - queryBlogApi, queryBlogByConditionApi, queryBlogByIdApi, + queryBlogApi, queryBlogByIdApi, queryBlogCategoryApi, queryBlogCommentApi, queryBlogStatsApi, queryLatestBlogApi, updateBlogApi } from '@/apis/blog.ts' import { IHandleApi } from 'vue3-common/types' @@ -51,7 +51,8 @@ export const useBlogStore = defineStore('blog', { topValue: 1, isGreat: false, category: '', - content: '' + content: '', + isApproved: 0 } as INewBlog, blogCategoryList: [] as IBlogCategory[], blogStats: {} as IBlogStats, @@ -74,9 +75,6 @@ export const useBlogStore = defineStore('blog', { this.blogList = result.records this.pageInfo.totalSize = result.total }, - async queryBlogByCondition(query: IQueryBlog) { - this.blogList = await queryBlogByConditionApi(query) - }, async queryBlogById(id: number) { this.currentBlog = await queryBlogByIdApi(id) await this.queryBlogComment(this.currentBlogId) @@ -133,7 +131,8 @@ export const useBlogStore = defineStore('blog', { content: '', isGreat: false, title: '', - topValue: 0 + topValue: 0, + isApproved: 0 } }, getEmptyBlogComment(): IBlogComment { diff --git a/src/types/blog.ts b/src/types/blog.ts index 3f500ca..56784d4 100644 --- a/src/types/blog.ts +++ b/src/types/blog.ts @@ -10,6 +10,7 @@ export interface IBlog { wordCount: number; readDuration: number; visitCount: number; + isApproved: number; createTime: string; updateTime: string; } @@ -21,6 +22,7 @@ export interface INewBlog { isGreat: boolean; category: string; content: string; + isApproved: number; } export interface IQueryBlog { diff --git a/src/utils/element/elRules.ts b/src/utils/element/elRules.ts index 6fb6db7..448c729 100644 --- a/src/utils/element/elRules.ts +++ b/src/utils/element/elRules.ts @@ -9,12 +9,12 @@ export const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ export const blogRules = { title: [ - { required: true, message: '请输入博客标题', trigger: 'change' } + { required: true, message: '请输入博客标题', trigger: 'blur' } ], category: [ - { required: true, message: '请输入或选择博客分类', trigger: 'change' }, + // { required: true, message: '请输入或选择博客分类', trigger: 'change' }, // { pattern: new RegExp(chinesePattern), message: '请输入中英文或数字' }, - { min: 1, max: 10, message: '请输入10字以内的类别', trigger: 'blur' }] + { required: true, min: 1, max: 10, message: '请输入10字以内的类别', trigger: 'blur' }] } export const loginRules = { diff --git a/src/views/blog/article.vue b/src/views/blog/article.vue index d04e064..56d215c 100644 --- a/src/views/blog/article.vue +++ b/src/views/blog/article.vue @@ -28,6 +28,12 @@ + + + @@ -63,6 +66,7 @@ const focusCategoryEvent = async () => { } onMounted(async () => { + console.log('cxx') formRef.value?.clearValidate() const blogId = route.params.id as number @@ -91,9 +95,10 @@ const validateBlog = (): boolean => { /** * 提交表单事件 */ -const submitFormEvent = () => { +const submitFormEvent = (isApprove: number) => { // 表单校验 formRef.value?.validate().then(async () => { + blogStore.newBlog.isApproved = isApprove if (validateBlog()) { await blogStore.handleBlogApi() await router.push('/blog')