From f3b263b6d15b6af85801b435bb106d0c695d5cef Mon Sep 17 00:00:00 2001 From: barney <15270405776@163.com> Date: Tue, 4 Oct 2022 15:47:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=96=87=E7=AB=A0=E5=8F=AF?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=86=E7=B1=BB=EF=BC=8C=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E5=89=8D=E7=AB=AF=E8=BF=9B=E8=A1=8C=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db.sqlite3 | Bin 221184 -> 221184 bytes drf_vue_blog/settings.py | 2 +- frontend/src/views/ArticleCreate.vue | 79 +++++++++++++++++++++++++-- frontend/src/views/ArticleEdit.vue | 18 ++++++ media/avatar/20221004/apple_00.png | Bin 0 -> 1006 bytes media/avatar/20221004/apple_08.png | Bin 0 -> 1420 bytes media/avatar/20221004/apple_20.png | Bin 0 -> 1241 bytes 7 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 media/avatar/20221004/apple_00.png create mode 100644 media/avatar/20221004/apple_08.png create mode 100644 media/avatar/20221004/apple_20.png diff --git a/db.sqlite3 b/db.sqlite3 index c37e410a285718a29af1d56dd702db05165ab7d3..c3211ca148e5e59d391d021fc852d220e879b72d 100644 GIT binary patch delta 1432 zcmZ`(ZERCj7{2G+u3JBDUuxUInD*Z5APlv)_oLrLv3_7g3{jha#jl%Y85^c;MulyE zHfIz;6CD$8V)&uN48z2+Rd#hmHx)_zjA9~c2wDwui)2c&n7Ln`duB{avZi_Z-t)fi zb8esWyr+Mf>!0RcZbkaZyJJUkXQAVPdt*f{B5&7SFTpEv|XjOSVStESKlJ<@Blr)@;n+gAJG|8E-s-i{4$LgK3JV(`1{O(=W`9 z9x?P?*x#qr{*`4_6fGLpVzrrwoYEpvQc+^j2zH7YfzWNNqH7V9s!wh2vOro~k>k?;RO`Zo9wPd*9F%E@mk)M z<3*OaTi>Ub^scZalp@QKuwE>Z+eek9V!oXhRxFU03;2}_5*CBm^dg?~Rr}v^f2GR( zlmGkQTg*U%J#1qv>l*{3#QFA+^~C#(@loo0vVsq5aP>3sBStV0W5~3IY%Chogb?H}&wFHMG4Y+`ch9@` z+}}O-+}{~2R}Yq}UklK_;k(*t-JWntm}KxFd;wSBeYgz2!6cO7BD{wq8Zz4iy(!4vrXBDrv9dd? z21&pGAHZLPcOY2Il{#bw@6s7oe>MJdFibGhb1)3`cTBih42u;(`#Zt{1F=|}6qhmX zq$ky#JtT{=+#-oBq8ySHRf?*j6px|fePG$KcNI;Fa&SG33wT1&_lyo zM630k8(E0iTVyjmQ5)LCn(T0i*s0&WR-4(x8k|7AoEwu}LA^|`;7m=>VX0;CjN=xB z9j^-w!Vzb>>U!0ymRe`pnHG)|Q#Cg@y*9&+*%^IFJGG1T3|uW8Unot?k7jCk(il#q zC{O0ky>e~(jdmALTrQlTM8eO!jF@bZlOa)5qoNuUBa$S_V(kA{7!wYWv(4+26wi}| zsi~{y2N$M~&cAtdp)hK2;-@`#Hw&*;#E=wIWl4=DBGIHAk0^AvoB9$L}WGYHyvj>Wgab>j584RQI`8t4mRX>Fc>;n&rg=yO0BNyiBM2$zs@ z5lP43EW8Wf;5)v9+AbT0q|d_^V@LHm13mYc{(2Le3=~2zM{I8M9Pb8mzS%&|YasK$ zAEe5BS}W5Q2UvhxHq)$ diff --git a/drf_vue_blog/settings.py b/drf_vue_blog/settings.py index 3a30b39..2e1c978 100644 --- a/drf_vue_blog/settings.py +++ b/drf_vue_blog/settings.py @@ -121,7 +121,7 @@ STATIC_URL = '/static/' # 使用django_rest_framework中的分页功能 REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', - # 每页5条记录 + # 每页3条记录 'PAGE_SIZE': 3, # 使用django-filter后端过滤引擎 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'], diff --git a/frontend/src/views/ArticleCreate.vue b/frontend/src/views/ArticleCreate.vue index 3665074..c20640f 100644 --- a/frontend/src/views/ArticleCreate.vue +++ b/frontend/src/views/ArticleCreate.vue @@ -31,6 +31,23 @@ {{ category.title }} + +
+ 注: 不选分类时可创建新分类! +
+ +
+
创建新分类: 
+
+ +
@@ -85,6 +102,10 @@ export default { // 标题图 id let avatarID = ref(null); + // 新分类 + + let newCategory = ref(""); + const router = useRouter(); onMounted(() => { @@ -160,11 +181,6 @@ export default { body: body.value, }; - // 添加分类 - if (selectedCategory.value) { - data.category_id = selectedCategory.value.id; - } - // 标签预处理 data.tags = tags.value // 用逗号分隔标签 @@ -176,6 +192,49 @@ export default { data.avatar_id = avatarID.value; + if (newCategory.value.length >= 6) { + window.alert("分类名建议不超过6个字符"); + newCategory.value = ""; + return; + } + + for (let item of categories.value) { + if (newCategory.value === item.title){ + window.alert("分类名已存在!"); + newCategory.value = ""; + return; + } + } + + // 创建新的分类 + if ( + selectedCategory.value === null && + newCategory.value !== null + ) { + $.ajax({ + url: "http://127.0.0.1:6789/api/category/", + type: "post", + async: false, + data: { + title: newCategory.value, + }, + headers: { + Authorization: + "Bearer " + + localStorage.getItem("access_blog"), + }, + success(resp) { + selectedCategory.value = resp; + }, + }); + } + + // 添加分类 + if (selectedCategory.value) { + data.category_id = selectedCategory.value.id; + } + + // 将发表文章请求发送至接口 // 成功后前往详情页面 const token = localStorage.getItem("access_blog"); @@ -212,6 +271,7 @@ export default { chooseCategory, onFileChange, submit, + newCategory, }; }, }; @@ -219,7 +279,10 @@ export default { diff --git a/frontend/src/views/ArticleEdit.vue b/frontend/src/views/ArticleEdit.vue index 890da13..2a9f53c 100644 --- a/frontend/src/views/ArticleEdit.vue +++ b/frontend/src/views/ArticleEdit.vue @@ -177,6 +177,21 @@ export default { // 剔除长度为零的无效标签 .filter((x) => x.charAt(0) !== ""); + + if (newCategory.value.length > 6) { + window.alert("分类名建议不超过6个字符"); + newCategory.value = ""; + return; + } + + for (let item of categories.value) { + if (newCategory.value === item.title){ + window.alert("分类名已存在!"); + newCategory.value = ""; + return; + } + } + // 创建新的分类 if ( selectedCategory.value === null && @@ -280,7 +295,10 @@ export default {