From ea0942acaaf0b8ae9a943a9bed1427cf79865141 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B0=B4=E5=86=B0=E6=B7=BC?= <546483720@qq.com>
Date: Sun, 26 Sep 2021 02:08:51 +0800
Subject: [PATCH 01/34] :pencil: (doc)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
1.1开始开发,文档编写完成
---
readme.md | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/readme.md b/readme.md
index 69a7bc6..8e9f9e8 100644
--- a/readme.md
+++ b/readme.md
@@ -1,7 +1,7 @@
@@ -71,7 +71,6 @@
// import { mapMutations } from 'vuex'
// import { login } from '@/api/index'
// import * as login from '@/api/login'
-import store from '@/store/index'
export default {
name: 'login',
// 数据绑定
@@ -150,8 +149,6 @@ export default {
console.log('开始存储信息')
console.log(res.data['userInfo'])
this.$store.commit('login', res.data['userInfo'])
- console.log('store已储存' + store.state.userinfo)
- store.state.pageControl.UIloadDone = true
} else {
alert('获取用户信息失败')
}
diff --git a/packages/blog-view/src/pages/PersonInfo.vue b/packages/blog-view/src/pages/PersonInfo.vue
index d4e5a3f..16dde44b 100644
--- a/packages/blog-view/src/pages/PersonInfo.vue
+++ b/packages/blog-view/src/pages/PersonInfo.vue
@@ -12,18 +12,28 @@
-
-
+
+
- 保密
- 男
- 女
+ 保密
+ 男
+ 女
-
+
-
-
@@ -51,7 +59,7 @@ export default {
birth: new Date(),
minDate: new Date(1900, 1, 1),
maxDate: new Date(),
- statement: this.$store.state.userinfo.statement,
+ desc: this.$store.state.userinfo.desc,
sex: this.$store.state.userinfo.sex
}
},
@@ -75,27 +83,41 @@ export default {
},
// 头部右侧图标点击动作
onClickRight () {
- this.commen.changeUserinfo(
- {
- statement: this.statement,
- birth: {
- year: this.birth.getFullYear(),
- month: this.birth.getMonth() + 1,
- day: this.birth.getDate()
- },
- sex: this.sex
- },
- res => {
- if (res.data.status === 200) {
- this.$dialog({ message: res.data.msg })
- this.userinfo.birth = this.birthday
- this.userinfo.statement = this.statement
- this.userinfo.sex = this.sex
+ // 更新服务器信息
+ this.$service.user.changeInfo({
+ desc: this.desc,
+ birth: this.birth,
+ sex: this.sex
+ })
+
+ // 更新本地信息
+ console.log('开始更新用户信息')
+ this.$service.user
+ .getInfo()
+ .then(res => {
+ console.log(res)
+ if (res.code === 200) {
+ // 将用户信息保存至store中
+ console.log('开始存储信息')
+ console.log(res.data['userInfo'])
+ this.$store.commit('login', res.data['userInfo'])
} else {
- this.$dialog({ message: res.data.msg })
+ alert('获取用户信息失败')
}
- }
- )
+ })
+ .catch(err => {
+ console.log(err)
+ })
+ console.log('store已储存' + this.$store.state.userinfo)
+
+ // 更新本页信息
+ // this.birth = this.$store.state.userinfo.birth
+ // this.desc = this.$store.state.userinfo.desc
+ // this.sex = this.$store.state.userinfo.sex
+
+ this.birth = new Date()
+ this.desc = '测试'
+ this.sex = 'male'
},
onSubmit () {},
onConfirm (time) {
diff --git a/packages/blog-view/src/router/index.js b/packages/blog-view/src/router/index.js
index 7ecd0cd..8397597 100644
--- a/packages/blog-view/src/router/index.js
+++ b/packages/blog-view/src/router/index.js
@@ -1,7 +1,8 @@
import Vue from 'vue'
import Router from 'vue-router'
// eslint-disable-next-line camelcase
-import Index_Main from '@/Index_Main'
+// s这里要记得注释回来!!!!
+// import Index_Main from '@/Index_Main'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Account from '@/pages/Account'
@@ -23,7 +24,9 @@ const router = new Router({
{
path: '/',
name: 'Index_Main',
- component: Index_Main,
+ // component: Index_Main,
+ // 调试用。记得注释,改回原来的主页路由
+ component: PersonInfo,
redirect: { name: 'home' },
children: [
{
diff --git a/packages/blog-view/src/store/index.js b/packages/blog-view/src/store/index.js
index 517d6d8..3af618f 100644
--- a/packages/blog-view/src/store/index.js
+++ b/packages/blog-view/src/store/index.js
@@ -7,21 +7,9 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
- userinfo: {
- username: 'aaaa',
- desc: '个人简介',
- nickname: String,
- email: '234335435',
- birth: String,
- phone: '12324353',
- image: String,
- sex: String,
- statement: String,
- point: Number,
- level: String
- },
+ userinfo: sessionStorage.getItem('userinfo'),
pageControl: {
- UIloadDone: false,
+ UIloadDone: sessionStorage.getItem('status'),
sectionLoadDone: true,
leftPopupShow: false,
topPopupShow_search: false,
@@ -137,16 +125,20 @@ export default new Vuex.Store({
return r ? r[1] : undefined
},
login (state, userinfo) {
- state.userinfo.username = userinfo.username
- state.userinfo.nickname = userinfo.nickname
- state.userinfo.email = userinfo.email
- state.userinfo.birth = userinfo.birth
- state.userinfo.image = userinfo.image
- state.userinfo.sex = userinfo.sex
- state.userinfo.statement = userinfo.statement
- state.userinfo.point = userinfo.point
- state.userinfo.level = userinfo.level
- state.userinfo.phone = userinfo.phonenum
+ // state.userinfo.username = userinfo.username
+ // state.userinfo.nickname = userinfo.nickname
+ // state.userinfo.email = userinfo.email
+ // state.userinfo.birth = userinfo.birth
+ // state.userinfo.image = userinfo.image
+ // state.userinfo.sex = userinfo.sex
+ // state.userinfo.statement = userinfo.statement
+ // state.userinfo.point = userinfo.point
+ // state.userinfo.level = userinfo.level
+ // state.userinfo.phone = userinfo.phonenum
+ // state.pageControl.UIloadDone = true
+ sessionStorage.setItem('userinfo', userinfo)
+ sessionStorage.setItem('status', true)
+ state.userinfo = userinfo
state.pageControl.UIloadDone = true
},
UILoad (state) {
--
Gitee
From 46c4e8f7dda1a00347b39b85c8fd203af86caf54 Mon Sep 17 00:00:00 2001
From: csh1314
Date: Sun, 26 Sep 2021 09:13:05 +0800
Subject: [PATCH 03/34] =?UTF-8?q?:sparkles:=20(server)=20=E5=AE=8C?=
=?UTF-8?q?=E5=96=84=E8=8D=89=E7=A8=BF=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?api?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../blog-server/src/controllers/article.controller.js | 9 +++++----
packages/blog-server/src/services/articleService.js | 6 ++----
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/packages/blog-server/src/controllers/article.controller.js b/packages/blog-server/src/controllers/article.controller.js
index 93dd629..efea7c9 100644
--- a/packages/blog-server/src/controllers/article.controller.js
+++ b/packages/blog-server/src/controllers/article.controller.js
@@ -190,12 +190,13 @@ class ArticleController {
const { _id } = ctx.userInfo
const article = ctx.request.body
article.uid = _id
- // 未缓存过 => create
- if(!article.id){
- await articleService.createCache(article)
- }else{
+ const result = await articleService.getCache(_id)
+ if(result){
// 已有缓存 => update
await articleService.updateCache(article)
+ }else{
+ // 未缓存过 => create
+ await articleService.createCache(article)
}
ctx.body = {
code: 200,
diff --git a/packages/blog-server/src/services/articleService.js b/packages/blog-server/src/services/articleService.js
index 8355ced..6dbc40f 100644
--- a/packages/blog-server/src/services/articleService.js
+++ b/packages/blog-server/src/services/articleService.js
@@ -93,10 +93,8 @@ class ArticleService {
* @param {Object} article
*/
async updateCache(article){
- const { id } = article
- let before = await cacheArticleTable.where({_id: ObjectId(id)}).findOne()
- delete article.id
- console.log(before, article)
+ const { uid } = article
+ let before = await cacheArticleTable.where({uid}).findOne()
const res = await cacheArticleTable.save(Object.assign(before, article))
return res
}
--
Gitee
From 438aaf38ef33e44ffab211fff7fe1e2e12881097 Mon Sep 17 00:00:00 2001
From: csh1314
Date: Sun, 26 Sep 2021 09:40:20 +0800
Subject: [PATCH 04/34] =?UTF-8?q?:sparkles:=20(server)=20=E5=AE=8C?=
=?UTF-8?q?=E6=88=90=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9?=
=?UTF-8?q?api?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../blog-server/src/controllers/auth.controller.js | 10 ++++++++++
packages/blog-server/src/routers/auth.js | 6 ++++++
packages/blog-server/src/services/userService.js | 13 +++++++++++++
3 files changed, 29 insertions(+)
diff --git a/packages/blog-server/src/controllers/auth.controller.js b/packages/blog-server/src/controllers/auth.controller.js
index 780c556..f2ceecd 100644
--- a/packages/blog-server/src/controllers/auth.controller.js
+++ b/packages/blog-server/src/controllers/auth.controller.js
@@ -91,6 +91,16 @@ class AuthController {
msg:"修改密码成功"
}
}
+
+ async put(ctx) {
+ const { username } = ctx.userInfo
+ const { sex, desc, birth } = ctx.request.body
+ const ret = await userService.put({username, sex, desc, birth})
+ ctx.body = {
+ code: 200,
+ msg: "修改个人信息成功"
+ }
+ }
}
module.exports = new AuthController()
\ No newline at end of file
diff --git a/packages/blog-server/src/routers/auth.js b/packages/blog-server/src/routers/auth.js
index a652cc0..60c3fc8 100644
--- a/packages/blog-server/src/routers/auth.js
+++ b/packages/blog-server/src/routers/auth.js
@@ -9,9 +9,15 @@ const authController = require('../controllers/auth.controller');
// 组装路由
+// 注册
router.post('/user', authController.create)
+// 登录
router.post('/login', authController.login);
+// 得到用户信息
router.get('/account', authMiddleware.verifyAuth, authController.account)
+// 修改密码
router.patch('/account', authMiddleware.verifyAuth, authController.patch)
+// 修改用户信息
+router.put('/account', authMiddleware.verifyAuth, authController.put)
// Koa 的路由需要调用 routes 函数获取实际用于 use 的函数
module.exports = router;
diff --git a/packages/blog-server/src/services/userService.js b/packages/blog-server/src/services/userService.js
index 4bdb648..72db520 100644
--- a/packages/blog-server/src/services/userService.js
+++ b/packages/blog-server/src/services/userService.js
@@ -49,6 +49,19 @@ class UserService {
result: user
}
}
+ /**
+ * 修改用户信息
+ * @param {*} userInfo
+ */
+ async put(userInfo) {
+ const { username } = userInfo
+ let user = await userTable.where({username}).findOne()
+ user = Object.assign(user, userInfo)
+ await userTable.save(user)
+ return {
+ result: user
+ }
+ }
}
module.exports = new UserService()
\ No newline at end of file
--
Gitee
From ed96fd06eede140f18406ef7bdf086a6a862cb64 Mon Sep 17 00:00:00 2001
From: CreatingLiu <773673499@qq.com>
Date: Sun, 26 Sep 2021 10:26:48 +0800
Subject: [PATCH 05/34] =?UTF-8?q?:bug:=20(server)=20=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E6=96=87=E7=AB=A0=E8=AF=A6=E6=83=85API=E8=BF=94=E5=9B=9E?=
=?UTF-8?q?=E7=9A=84=E6=AD=A3=E6=96=87=E5=92=8C=E5=88=86=E7=B1=BB=E4=BF=A1?=
=?UTF-8?q?=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/controllers/article.controller.js | 21 +++++++++++++++++--
.../src/services/sectionService.js | 18 ++++++++++++++++
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/packages/blog-server/src/controllers/article.controller.js b/packages/blog-server/src/controllers/article.controller.js
index 93dd629..1ed5d30 100644
--- a/packages/blog-server/src/controllers/article.controller.js
+++ b/packages/blog-server/src/controllers/article.controller.js
@@ -1,6 +1,7 @@
const articleService = require('../services/articleService')
const userService = require('../services/userService')
const commentService = require('../services/commentService')
+const sectionService = require('../services/sectionService')
const commonResponse = {
code: 200,
@@ -84,6 +85,22 @@ class ArticleController {
commentsResult.push(await formatComments(comments[i]));
}
+ let section = await sectionService.getSectionTreeById(article.section.toString());
+
+ const formatSection = section => {
+ let child = undefined;
+ if(section.child !== undefined) {
+ child = formatSection(section.child);
+ }
+
+ return {
+ id: section._id,
+ name: section.name,
+ description: section.description,
+ child: child
+ }
+ }
+
let result = {
code: 200,
msg: "done",
@@ -95,9 +112,9 @@ class ArticleController {
article: {
id: article._id,
title: article.title,
- context: article.context,
+ content: article.content,
datetime: article.createdAt,
- section: article.section,
+ section: formatSection(section),
data: {
view: article.data.view,
like: article.data.like,
diff --git a/packages/blog-server/src/services/sectionService.js b/packages/blog-server/src/services/sectionService.js
index 997d798..d17d6d7 100644
--- a/packages/blog-server/src/services/sectionService.js
+++ b/packages/blog-server/src/services/sectionService.js
@@ -4,6 +4,24 @@ const sectionTable = require('../models/sectionTable');
class SectionService {
+ async getSectionTreeById(sectionId) {
+ let child = await this.getSectionById(sectionId);
+ return await this.getSectionTree(child);
+ }
+
+ async getSectionTree(section) {
+ let tree;
+ if(section.parent !== undefined && section.parent !== null) {
+ let parent = await this.getSectionById(section.parent);
+ parent.child = section;
+ tree = await this.getSectionTree(parent);
+ }
+ else {
+ tree = section;
+ }
+ return tree;
+ }
+
async getSectionById(id) {
return await sectionTable.where({_id: ObjectId(id)}).findOne();
}
--
Gitee
From 2e281a3db8f66852bb810850d89c33c39a5b5f9f Mon Sep 17 00:00:00 2001
From: CreatingLiu <773673499@qq.com>
Date: Sun, 26 Sep 2021 10:34:25 +0800
Subject: [PATCH 06/34] =?UTF-8?q?:bug:=20(server)=20=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E4=BA=86=E6=96=87=E7=AB=A0=E8=AF=A6=E6=83=85API=E8=BF=94?=
=?UTF-8?q?=E5=9B=9E=E8=AF=84=E8=AE=BA=E4=B8=8D=E5=AE=8C=E6=95=B4=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/blog-server/src/services/commentService.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/packages/blog-server/src/services/commentService.js b/packages/blog-server/src/services/commentService.js
index c4f0749..525d953 100644
--- a/packages/blog-server/src/services/commentService.js
+++ b/packages/blog-server/src/services/commentService.js
@@ -61,7 +61,8 @@ class CommentService {
}
async getCommentByArticle(articleId) {
- let list = await commentTable.where({article: articleId, parent: null}).projection({_id: 1}).find();
+ let list = await commentTable.where({article: articleId, parent: null}).or({article: articleId, parent: undefined}).projection({_id: 1}).find();
+ console.log(list)
let result = []
for(let i = 0; i < list.length; i++) {
result.push(await this.getComment(list[i]._id.toString()));
--
Gitee
From be41b5657266571c8906903b1c4d50f98d896ebc Mon Sep 17 00:00:00 2001
From: Craipy
Date: Sun, 26 Sep 2021 10:59:55 +0800
Subject: [PATCH 07/34] =?UTF-8?q?:bug:=20(view->global)=20=E4=BF=AE?=
=?UTF-8?q?=E5=A4=8D=E5=85=A8=E5=B1=80=E8=B7=AF=E7=94=B1=E5=92=8C=E7=94=A8?=
=?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96=E7=9A=84bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/blog-view/src/App.vue | 18 ++++++-------
packages/blog-view/src/init.js | 6 +++--
packages/blog-view/src/store/index.js | 38 ++++++++++++---------------
3 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/packages/blog-view/src/App.vue b/packages/blog-view/src/App.vue
index 932989d..11f25ca 100644
--- a/packages/blog-view/src/App.vue
+++ b/packages/blog-view/src/App.vue
@@ -21,16 +21,14 @@ export default {
window.onresize = this.handleSizeChange
},
mounted() {
- // this.$service.user
- // .getUserInfo()
- // .then(userinfo => {
- // console.log(userinfo)
- // this.login(userinfo)
- // })
- // .catch(e => {
- // console.log(e)
- // this.UILoad()
- // })
+ this.$service.user
+ .getUserInfo()
+ .then(userinfo => {
+ this.login(userinfo.data.userInfo)
+ })
+ .catch(e => {
+ this.UILoad()
+ })
},
destroyed() {
window.onresize = null
diff --git a/packages/blog-view/src/init.js b/packages/blog-view/src/init.js
index 6c3afb5..9644e7a 100644
--- a/packages/blog-view/src/init.js
+++ b/packages/blog-view/src/init.js
@@ -19,6 +19,8 @@ function getCookie(cName) {
// 这里获取token逻辑
let token = localStorage.getItem('token')
+// TODO:提交前注释此行代码,调试时打开
+// token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxNGZkOTVjODYwYjBhNzJjOWEzMTg1YyIsInVzZXJuYW1lIjoibGUxMTEiLCJpYXQiOjE2MzI2MjI5NTcsImV4cCI6MTYzMzIyNzc1N30.i9KATzPGjr4NKa6VUDE6FKL3adIy8nQgnviVr031CrwBq0fOShdKJIGk61Mith44kq6ZXDC5X_Hh9GiqlLX_-bE_XJMcXi6xfQb4uYNpBK6gRyiMyhGwQY7Mnu23pfMAcXENI9cHeTgITcPCxyCWkm_C-rrbRiiC2LKxOcfXP5E"
axios.interceptors.request.use(config => {
if(token) {
config.headers['authorization'] = token
@@ -49,7 +51,7 @@ axios.interceptors.response.use(
if (code === 200 || code === 1000) {
return response.data;
} else {
- let isShowNormalError = true;
+ let isShowNormalError = false;
// 用于关闭默认错误提示
const hideNormalError = () => { isShowNormalError = false; };
// 等待业务代码判断是否关闭默认错误提示
@@ -72,7 +74,7 @@ axios.interceptors.response.use(
// // Vue.$router.push('/login')
// }
const isCancel = axios.isCancel(error);
- let isShowNormalError = true;
+ let isShowNormalError = false;
// 可以选择是否采用后端报错信息还是自定义
const hideNormalError = () => { isShowNormalError = false; };
// 对于被取消的请求,不进行弹窗提示
diff --git a/packages/blog-view/src/store/index.js b/packages/blog-view/src/store/index.js
index 517d6d8..6f06b41 100644
--- a/packages/blog-view/src/store/index.js
+++ b/packages/blog-view/src/store/index.js
@@ -8,17 +8,16 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
userinfo: {
- username: 'aaaa',
- desc: '个人简介',
- nickname: String,
- email: '234335435',
- birth: String,
- phone: '12324353',
- image: String,
- sex: String,
- statement: String,
- point: Number,
- level: String
+ username: '',
+ desc: '',
+ nickname: '',
+ email: '',
+ birth: '',
+ phone: '',
+ image: '',
+ sex: '',
+ statement: '',
+ level: ''
},
pageControl: {
UIloadDone: false,
@@ -97,7 +96,7 @@ export default new Vuex.Store({
)
},
isAuthenticated: state => {
- if (state.userinfo.username === '') return true
+ if (state.userinfo.username !== '') return true
else {
return false
}
@@ -109,11 +108,11 @@ export default new Vuex.Store({
mutations: {
logout (state) {
state.userinfo = {
- username: undefined,
- phone: undefined,
- email: undefined,
- desc: undefined,
- avatar: undefined
+ username: '',
+ phone: '',
+ email: '',
+ desc: '',
+ avatar: ''
}
},
openLeftPopup (state) {
@@ -138,14 +137,11 @@ export default new Vuex.Store({
},
login (state, userinfo) {
state.userinfo.username = userinfo.username
- state.userinfo.nickname = userinfo.nickname
state.userinfo.email = userinfo.email
state.userinfo.birth = userinfo.birth
- state.userinfo.image = userinfo.image
+ state.userinfo.image = userinfo.avatar
state.userinfo.sex = userinfo.sex
state.userinfo.statement = userinfo.statement
- state.userinfo.point = userinfo.point
- state.userinfo.level = userinfo.level
state.userinfo.phone = userinfo.phonenum
state.pageControl.UIloadDone = true
},
--
Gitee
From 81c2b679b43734677fc928c744f28616e02c1250 Mon Sep 17 00:00:00 2001
From: CreatingLiu <773673499@qq.com>
Date: Sun, 26 Sep 2021 11:00:12 +0800
Subject: [PATCH 08/34] =?UTF-8?q?:sparkles:=20(server)=20=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E4=BA=86=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8=E7=9A=84?=
=?UTF-8?q?=E6=8C=89=E5=88=86=E7=B1=BB=E7=AD=9B=E9=80=89=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/controllers/article.controller.js | 9 ++++++++-
.../blog-server/src/services/articleService.js | 16 ++++++++--------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/packages/blog-server/src/controllers/article.controller.js b/packages/blog-server/src/controllers/article.controller.js
index edeab44..643dc3f 100644
--- a/packages/blog-server/src/controllers/article.controller.js
+++ b/packages/blog-server/src/controllers/article.controller.js
@@ -10,7 +10,14 @@ const commonResponse = {
}
class ArticleController {
async list(ctx) {
- let list = await articleService.list();
+ let filter = null;
+ if(ctx.request.query.section) {
+ filter = {
+ section: ctx.request.query.section
+ }
+ }
+ let list = await articleService.list(filter);
+
let result = {
code: 200,
msg: "done",
diff --git a/packages/blog-server/src/services/articleService.js b/packages/blog-server/src/services/articleService.js
index 6dbc40f..710064c 100644
--- a/packages/blog-server/src/services/articleService.js
+++ b/packages/blog-server/src/services/articleService.js
@@ -9,18 +9,18 @@ class ArticleService {
* @param {Object} query 参数为空则返回所有公开文章,为对象时按每个字段的值筛选文章,条件为且的关系
* @returns
*/
- async list(query) {
- if (query === undefined) {
- query = {
+ async list(filter) {
+ if (filter === null) {
+ filter = {
published: true
- }
+ };
}
- const projection = {
- // content: 0,
- published: 0
+ if (!filter.includeEditing) {
+ filter.published = true;
}
- return await articleTable.where(query).projection(projection).find();
+
+ return await articleTable.where(filter).find();
}
/**
--
Gitee
From ec73d03fd3ddf3bf675ac5c218a65f1ef00feb44 Mon Sep 17 00:00:00 2001
From: Craipy
Date: Sun, 26 Sep 2021 11:25:04 +0800
Subject: [PATCH 09/34] =?UTF-8?q?:bug:=20(view)=20=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=92=8Cajax=E9=94=99=E8=AF=AF=E6=B6=88?=
=?UTF-8?q?=E6=81=AF=E5=A4=84=E7=90=86=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/blog-view/src/App.vue | 1 +
packages/blog-view/src/init.js | 4 ++--
packages/blog-view/src/router/index.js | 7 ++-----
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/packages/blog-view/src/App.vue b/packages/blog-view/src/App.vue
index 11f25ca..f85dfa1 100644
--- a/packages/blog-view/src/App.vue
+++ b/packages/blog-view/src/App.vue
@@ -27,6 +27,7 @@ export default {
this.login(userinfo.data.userInfo)
})
.catch(e => {
+ e.hideNormalError()
this.UILoad()
})
},
diff --git a/packages/blog-view/src/init.js b/packages/blog-view/src/init.js
index 9644e7a..688ec5d 100644
--- a/packages/blog-view/src/init.js
+++ b/packages/blog-view/src/init.js
@@ -51,7 +51,7 @@ axios.interceptors.response.use(
if (code === 200 || code === 1000) {
return response.data;
} else {
- let isShowNormalError = false;
+ let isShowNormalError = true;
// 用于关闭默认错误提示
const hideNormalError = () => { isShowNormalError = false; };
// 等待业务代码判断是否关闭默认错误提示
@@ -74,7 +74,7 @@ axios.interceptors.response.use(
// // Vue.$router.push('/login')
// }
const isCancel = axios.isCancel(error);
- let isShowNormalError = false;
+ let isShowNormalError = true;
// 可以选择是否采用后端报错信息还是自定义
const hideNormalError = () => { isShowNormalError = false; };
// 对于被取消的请求,不进行弹窗提示
diff --git a/packages/blog-view/src/router/index.js b/packages/blog-view/src/router/index.js
index 8397597..7ecd0cd 100644
--- a/packages/blog-view/src/router/index.js
+++ b/packages/blog-view/src/router/index.js
@@ -1,8 +1,7 @@
import Vue from 'vue'
import Router from 'vue-router'
// eslint-disable-next-line camelcase
-// s这里要记得注释回来!!!!
-// import Index_Main from '@/Index_Main'
+import Index_Main from '@/Index_Main'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Account from '@/pages/Account'
@@ -24,9 +23,7 @@ const router = new Router({
{
path: '/',
name: 'Index_Main',
- // component: Index_Main,
- // 调试用。记得注释,改回原来的主页路由
- component: PersonInfo,
+ component: Index_Main,
redirect: { name: 'home' },
children: [
{
--
Gitee
From f4963ebdb99f0655f9a3083b91588775aecfca02 Mon Sep 17 00:00:00 2001
From: csh1314
Date: Sun, 26 Sep 2021 11:30:00 +0800
Subject: [PATCH 10/34] =?UTF-8?q?:sparkles:=20(server)=20=E5=AE=8C?=
=?UTF-8?q?=E6=88=90=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=20=E5=A4=9A?=
=?UTF-8?q?=E5=9B=BE=E4=B8=8A=E4=BC=A0=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/blog-server/src/app/index.js | 7 +++-
.../src/controllers/file.controller.js | 32 +++++++++++++++++++
packages/blog-server/src/routers/file.js | 14 ++++++++
packages/blog-server/src/utils/read-file.js | 14 ++++++++
4 files changed, 66 insertions(+), 1 deletion(-)
create mode 100644 packages/blog-server/src/controllers/file.controller.js
create mode 100644 packages/blog-server/src/routers/file.js
create mode 100644 packages/blog-server/src/utils/read-file.js
diff --git a/packages/blog-server/src/app/index.js b/packages/blog-server/src/app/index.js
index 5ad5900..43e95a8 100644
--- a/packages/blog-server/src/app/index.js
+++ b/packages/blog-server/src/app/index.js
@@ -8,7 +8,12 @@ app.useRoutes = useRoutes;
// 为应用使用中间件
// 请求体 parse 中间件,用于 parse json 格式请求体
-app.use(koaBody());
+app.use(koaBody({
+ multipart: true,
+ formidable: {
+ maxFileSize: 1000 * 1024 * 1024 //最大10M
+ }
+}));
app.useRoutes()
/** 若后面的路由抛错,则封装为错误响应返回
* 错误响应格式为
diff --git a/packages/blog-server/src/controllers/file.controller.js b/packages/blog-server/src/controllers/file.controller.js
new file mode 100644
index 0000000..136c2f8
--- /dev/null
+++ b/packages/blog-server/src/controllers/file.controller.js
@@ -0,0 +1,32 @@
+const inspirecloud = require('@byteinspire/api');
+
+const readFilePromise = require('../utils/read-file');
+
+
+class FileController {
+ // 多图上传
+ async upload(ctx){
+ const fileList = ctx.request.files.file
+ const urlList = []
+ for(const file of fileList){
+ const buffer = await readFilePromise(file.path)
+ const { url } = await inspirecloud.file.upload(
+ file.name,
+ buffer,
+ {
+ type: file.type
+ }
+ )
+ urlList.push(url)
+ }
+ ctx.body = {
+ code: 200,
+ msg: "文件上传成功",
+ data: {
+ urlList
+ }
+ }
+ }
+}
+
+module.exports = new FileController()
\ No newline at end of file
diff --git a/packages/blog-server/src/routers/file.js b/packages/blog-server/src/routers/file.js
new file mode 100644
index 0000000..0bd8420
--- /dev/null
+++ b/packages/blog-server/src/routers/file.js
@@ -0,0 +1,14 @@
+const Router = require('@koa/router');
+// Koa 的路由在被 use 时是无法指定前缀的, 需要在定义时就指定前缀
+const router = Router({
+ prefix: '/api/upload'
+});
+
+const authMiddleware = require('../middleware/authMiddleware')
+const fileController = require('../controllers/file.controller')
+
+// 组装路由
+router.post('/', authMiddleware.verifyAuth, fileController.upload)
+
+// Koa 的路由需要调用 routes 函数获取实际用于 use 的函数
+module.exports = router;
diff --git a/packages/blog-server/src/utils/read-file.js b/packages/blog-server/src/utils/read-file.js
new file mode 100644
index 0000000..0d1978a
--- /dev/null
+++ b/packages/blog-server/src/utils/read-file.js
@@ -0,0 +1,14 @@
+const fs = require('fs')
+
+const readFilePromise = (path) => {
+ return new Promise((resolve, reject) => {
+ fs.readFile(path, (err, data) => {
+ if(err){
+ reject(err)
+ }
+ resolve(data)
+ });
+ })
+}
+
+module.exports = readFilePromise
\ No newline at end of file
--
Gitee
From 648b468648dcc4dcfc2e5a2c353e1b0df9d88e39 Mon Sep 17 00:00:00 2001
From: CreatingLiu <773673499@qq.com>
Date: Sun, 26 Sep 2021 11:36:47 +0800
Subject: [PATCH 11/34] =?UTF-8?q?:sparkles:=20(server)=20=E7=82=B9?=
=?UTF-8?q?=E8=B5=9EAPI=E6=94=AF=E6=8C=81=E7=BB=99=E8=AF=84=E8=AE=BA?=
=?UTF-8?q?=E7=82=B9=E8=B5=9E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/controllers/article.controller.js | 2 +-
.../src/controllers/like.controller.js | 7 +++----
.../src/services/commentService.js | 19 ++++++++++++++++++-
.../blog-server/src/services/likeService.js | 12 ++++++------
4 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/packages/blog-server/src/controllers/article.controller.js b/packages/blog-server/src/controllers/article.controller.js
index 643dc3f..0a80f1e 100644
--- a/packages/blog-server/src/controllers/article.controller.js
+++ b/packages/blog-server/src/controllers/article.controller.js
@@ -83,7 +83,7 @@ class ArticleController {
id: comment._id,
content: comment.content,
time: comment.createdAt,
- like: comment.like,
+ like: comment.data.like,
replay: replay
}
}
diff --git a/packages/blog-server/src/controllers/like.controller.js b/packages/blog-server/src/controllers/like.controller.js
index ed0a6b7..814de4b 100644
--- a/packages/blog-server/src/controllers/like.controller.js
+++ b/packages/blog-server/src/controllers/like.controller.js
@@ -2,8 +2,7 @@ const likeService = require('../services/likeService')
class LikeController {
async get(ctx) {
- console.log(ctx.userInfo._id.toString(), ctx.query.article)
- if(await likeService.get(ctx.userInfo._id.toString(), ctx.query.article)) {
+ if(await likeService.get(ctx.userInfo._id.toString(), ctx.query.object)) {
ctx.body = {
code: 200,
msg: "已经赞过"
@@ -18,7 +17,7 @@ class LikeController {
}
async post(ctx) {
- if(await likeService.post(ctx.userInfo._id.toString(), ctx.request.body.article, 1))
+ if(await likeService.post(ctx.userInfo._id.toString(), ctx.request.body.object, Number(ctx.request.body.type)))
ctx.body = {
code: 200,
msg: 'done'
@@ -31,7 +30,7 @@ class LikeController {
}
async delete(ctx) {
- if(await likeService.del(ctx.userInfo._id.toString(), ctx.query.article, 1))
+ if(await likeService.del(ctx.userInfo._id.toString(), ctx.query.object))
ctx.body = {
code: 200,
msg: 'done'
diff --git a/packages/blog-server/src/services/commentService.js b/packages/blog-server/src/services/commentService.js
index 525d953..b357504 100644
--- a/packages/blog-server/src/services/commentService.js
+++ b/packages/blog-server/src/services/commentService.js
@@ -10,7 +10,9 @@ class CommentService {
parent: comment.parent,
article: comment.article,
author: comment.author,
- like: 0,
+ data: {
+ like: 0
+ },
children: []
})
.then(result => {
@@ -69,6 +71,21 @@ class CommentService {
}
return result;
}
+
+ /**
+ * 更新data下的参数值
+ * @param {*} commentId 评论ID
+ * @param {*} key 要更新的参数
+ * @param {*} direction 方向,true为自增1,false为自减1
+ */
+ async setData(commentId, key, direction) {
+ let comment = await commentTable.where({_id: ObjectId(commentId)}).projection({data: 1}).findOne();
+ if(direction)
+ comment.data[key]++;
+ else
+ comment.data[key]--;
+ await commentTable.save(comment);
+ }
}
module.exports = new CommentService()
\ No newline at end of file
diff --git a/packages/blog-server/src/services/likeService.js b/packages/blog-server/src/services/likeService.js
index eefea5f..c63a8b0 100644
--- a/packages/blog-server/src/services/likeService.js
+++ b/packages/blog-server/src/services/likeService.js
@@ -2,12 +2,11 @@ const inspirecloud = require('@byteinspire/api');
const ObjectId = inspirecloud.db.ObjectId;
const likeTable = require('../models/likeTable');
const articleService = require('./articleService');
-// const commentTable = require('../models/commentTable');
+const commentService = require('./commentService');
class LikeService {
async get(userid, objectid) {
let check = await likeTable.where({user: ObjectId(userid), object: ObjectId(objectid)}).findOne();
- console.log(check)
return check !== null;
}
@@ -22,7 +21,7 @@ class LikeService {
articleService.setData(objectid, 'like', true);
}
else if(type === 2) {
- // TODO 评论点赞
+ commentService.setData(objectid, 'like', true);
}
else {
// TODO 未知的type
@@ -34,15 +33,16 @@ class LikeService {
}
}
- async del(userid, objectid, type) {
+ async del(userid, objectid) {
if(await this.get(userid, objectid)) {
- let x = await likeTable.where({user: ObjectId(userid), object: ObjectId(objectid)}).projection({_id: 1}).findOne();
+ let x = await likeTable.where({user: ObjectId(userid), object: ObjectId(objectid)}).projection({type: 1}).findOne();
+ let type = x.type;
likeTable.delete(x);
if (type === 1) {
articleService.setData(objectid, 'like', false);
}
else if(type === 2) {
- // TODO 评论取消点赞
+ commentService.setData(objectid, 'like', false);
}
else {
// TODO 未知的type
--
Gitee
From 18ae5220db5153485e5a73aec3ae798e8b812b5c Mon Sep 17 00:00:00 2001
From: yiyu66 <1226572422@qq.com>
Date: Sun, 26 Sep 2021 11:43:35 +0800
Subject: [PATCH 12/34] =?UTF-8?q?:sparkles:=20(=E6=96=87=E7=AB=A0=E6=9F=A5?=
=?UTF-8?q?=E7=9C=8B)=20=E5=A4=84=E7=90=86=E8=AF=84=E8=AE=BA=E5=8C=BA?=
=?UTF-8?q?=E5=8F=8A=E7=9B=B8=E5=BA=94=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
处理评论区及相应接口
---
packages/blog-view/src/api/article.js | 42 +++
.../src/components/page/CommentCard.vue | 161 +++++----
packages/blog-view/src/pages/Topic.vue | 335 ++++++++----------
3 files changed, 283 insertions(+), 255 deletions(-)
diff --git a/packages/blog-view/src/api/article.js b/packages/blog-view/src/api/article.js
index 1e3c1b8..7d1ec6e 100644
--- a/packages/blog-view/src/api/article.js
+++ b/packages/blog-view/src/api/article.js
@@ -13,6 +13,48 @@ export const getArticleList = () => {
return axios.get('/api/article')
}
+// 获取文章内容
+export const getArticleInfo = (params) => {
+ return axios.get(`/api/article/${params}`)
+}
+
+// 获取点赞状态
+export const getLike = params => {
+ return axios.get('/api/like', params)
+}
+
+// 点赞接口
+export const postLike = (params) => {
+ return axios.post(`/api/like`, params)
+}
+
+// 删除点赞接口
+export const deleteLike = (params) => {
+ return axios.delete(`/api/like`, params)
+}
+
+// 评论接口
+export const postComment = (params) => {
+ return axios.post(`/api/comment`, { article: params.article, replay: params.replay, content: params.content })
+}
+// 删除评论接口
+export const deleteComment = (id) => {
+ return axios.delete(`/api/comment`, { comment: id })
+}
+
+// 获取收藏状态
+export const getCollect = (id) => {
+ return axios.get(`/api/collect`, { article: id })
+}
+// 收藏接口
+export const postCollect = (id) => {
+ return axios.post(`/api/collect`, { article: id })
+}
+// 取消收藏接口
+export const deleteCollect = (id) => {
+ return axios.delete(`/api/collect`, { article: id })
+}
+
// export const getindex = params => { return axios.get(`/api/index/`, { params: params }) }
// // 获取城市信息
diff --git a/packages/blog-view/src/components/page/CommentCard.vue b/packages/blog-view/src/components/page/CommentCard.vue
index 5e6cf7a..ca56e7d 100644
--- a/packages/blog-view/src/components/page/CommentCard.vue
+++ b/packages/blog-view/src/components/page/CommentCard.vue
@@ -4,13 +4,14 @@
type="flex"
style="background-color: #fff; border-radius: 20px; padding: 5px 0"
>
+
-
+ > -->
- {{ nickname }}
+ {{ comment.author.username }}
回复
- {{ comment.parentnickname }}
+ {{ comment.author.username }}
{{ comment.time }}
{{ comment.content }}
-
- 查看{{ comment.commentcount }}条回复
-
-
-
-
+
+
+
-
+
@@ -113,57 +110,68 @@ export default {
userimage: '',
username: '',
nickname: '',
- islike: false
+ isliked: false
}
},
created () {
- console.log(this.props)
+ // console.log(this.comment)
+ // console.log('卡片界面')
},
mounted () {
- this.$http
- .get('/account/userimage', { params: { user: this.comment.user } })
- .then((res) => {
- if (res.data.status === 200) {
- this.nickname = res.data.nickname
- this.userimage = res.data.userimage
- }
- })
- .catch((res) => {})
- this.$http
- .get('/islike', { params: { comment_id: this.comment.id } })
- .then((res) => {
- if (res.data.status === 200) {
- this.islike = res.data.islike
- }
- })
- .catch((res) => {})
+ let time = this.comment.time
+ this.comment.time = time.substring(0, 10)
+ // this.getLikeState(this.comment.id)
+ // 获取评论用户的头像
+ // this.$http
+ // .get('/account/userimage', { params: { user: this.comment.user } })
+ // .then((res) => {
+ // if (res.data.status === 200) {
+ // this.nickname = res.data.nickname
+ // this.userimage = res.data.userimage
+ // }
+ // })
+ // .catch((res) => {})
},
methods: {
- addlike () {
- if (this.islike) {
- this.$http
- .get('/like/comment', {
- params: { comment_id: this.comment.id, action: 0 }
- })
- .then((res) => {
- if (res.data.status === 200) {
- this.islike = false
- this.comment.likecount -= 1
+ getLikeState (id) {
+ let params = 'article=' + id
+ this.$service.article
+ .getLike(params)
+ .then(res => {
+ console.log('请求getLike接口')
+ console.log(res)
+ if (res.code === 200) {
+ this.isliked = true
+ } else {
+ this.isliked = false
+ }
+ })
+ },
+ addlike (id) {
+ // let params = 'article=' + id
+ if (!this.isliked) {
+ this.$service.article
+ .postLike({ comment_id: this.comment.id, action: 0 })
+ .then(res => {
+ if (res.code === 200) {
+ console.log(res.msg)
+ console.log('点赞成功')
+ this.comment.likecount += 1
+ this.isliked = true
+ } else if (res.code === 201) {
+ console.log('已经点赞了')
+ this.isliked = true
}
})
- .catch((res) => {})
} else {
- this.$http
- .get('/like/comment', {
- params: { comment_id: this.comment.id, action: 1 }
- })
- .then((res) => {
- if (res.data.status === 200) {
- this.comment.likecount += 1
- this.islike = true
+ this.$service.article
+ .deleteLike({ comment_id: this.comment.id, action: 1 })
+ .then(res => {
+ if (res.code === 200) {
+ this.isliked = false
+ this.comment.likecount -= 1
}
})
- .catch((res) => {})
}
},
opencommentpopup () {
@@ -182,4 +190,7 @@ p {
width: 96%;
text-align: left;
}
+.comment{
+ float: right;
+}
diff --git a/packages/blog-view/src/pages/Topic.vue b/packages/blog-view/src/pages/Topic.vue
index 88b3c96..f9591ff 100644
--- a/packages/blog-view/src/pages/Topic.vue
+++ b/packages/blog-view/src/pages/Topic.vue
@@ -6,7 +6,7 @@
fixed
left-arrow
@click-left="onClickLeft"
- @click-right="onClickRight"
+ @click-right="addCollect"
>
@@ -20,12 +20,14 @@
-
+
+
+
{{ topicData.author.username }}
{{ topicData.article.datetime }}
@@ -34,11 +36,13 @@
-
+
+
+
@@ -48,7 +52,7 @@
align="center"
class="topic-like"
>
-
+
{{ topicData.article.data.like }}
@@ -84,7 +88,7 @@
type="textarea"
rows="1"
:autosize="{ maxHeight: 75, minHeight: 10 }"
- v-model="commenttext"
+ v-model="commentInfo.content"
placeholder="评论"
/>
@@ -93,7 +97,7 @@
-->
{
- // if (res.data.status === 200) {
- // this.topic = res.data.topic
- // // this.loaduser()
- // this.topicData.article.datetime = this.formatDate(
- // this.topicData.article.datetime
- // )
- // }
- // this.pageload.topicload = true
- // })
- // .catch((res) => {})
- // 请求评论列表
- this.$http
- .get('/comment/get', { params: { topic_id: this.$route.query.topic_id } })
- .then((res) => {
- if (res.data.status === 200) {
- this.comments = this.topicData.article.comments
- // 对评论进行排序,依照时间与热门进行排序,热门评论选择点赞大于20%的并且赞数大于5,或者赞数大于100,剩下依据时间排序
- }
- this.pageload.commentload = true
- })
- .catch((res) => {})
- // 请求是否点赞和收藏
- this.$http
- .get('/topic/UATstatus', {
- params: { topic_id: this.$route.query.topic_id }
- })
- .then((res) => {
- if (res.data.status === 200) {
- this.isliked = res.data.isliked
- this.iscollected = res.data.iscollected
- }
- })
- .catch((res) => {})
+ let id = '614ec5c2214711d2b0c79c06'
+ console.log('当前文章ID:' + id)
+ // 加在这里更快,但是没有loading
+ // this.pageload.topicload = true
+ // this.pageload.commentload = true
+ this.getArticle(id)
+ // this.getLikeState(id)
+ // this.getCollectState(id)
},
methods: {
- // 请求某个用户的头像,姓名?
- // loaduser () {
- // this.commen.getUserinfoByUsername(this.topic.user, (res) => {
- // if (res.data.status === 200) {
- // this.nickname = res.data.nickname
- // this.userimage = res.data.userimage
- // // console.log(res.data)
- // }
- // this.pageload.userload = true
- // })
- // },
+ // 请求文章内容
+ getArticle (id) {
+ this.$service.article
+ .getArticleInfo(id)
+ .then(res => {
+ if (res.code === 200) {
+ this.topicData = res.data
+ this.comments = this.topicData.article.comments
+ if (this.topicData.article.img) {
+ this.showArticleimg = true
+ }
+ let time = this.topicData.article.datetime
+ this.topicData.article.datetime = time.substring(0, 10)
+ }
+ this.pageload.topicload = true
+ this.pageload.commentload = true
+ })
+ },
// 点赞
- addlike () {
+ addlike (id) {
+ let params = 'article=' + id
if (!this.isliked) {
- this.$http
- .get('/like/topic', {
- params: { topic_id: this.$route.query.topic_id, action: 1 }
- })
- .then((res) => {
- if (res.data.status === 200) {
+ this.$service.article
+ .postLike(params)
+ .then(res => {
+ if (res.code === 200) {
+ console.log(res.msg)
+ console.log('点赞成功')
+ this.isliked = true
+ } else if (res.code === 201) {
+ console.log('已经点赞了')
this.isliked = true
}
})
- .catch((res) => {})
} else {
- this.$http
- .get('/like/topic', {
- params: { topic_id: this.$route.query.topic_id, action: 0 }
- })
- .then((res) => {
- if (res.data.status === 200) {
+ this.$service.article
+ .deleteLike(params)
+ .then(res => {
+ if (res.code === 200) {
this.isliked = false
}
})
- .catch((res) => {})
}
},
+ // 查询点赞状态
+ getLikeState (id) {
+ let params = 'article=' + id
+ this.$service.article
+ .getLike(params)
+ .then(res => {
+ console.log('请求getLike接口')
+ console.log(res)
+ if (res.code === 200) {
+ this.isliked = true
+ } else {
+ this.isliked = false
+ }
+ })
+ },
// 文章时间戳转为日期格式
formatDate (time) {
time *= 1000
@@ -315,45 +273,62 @@ export default {
},
// 发送评论
sendcomment () {
- this.$http
- .get('/comment', {
- params: { article: this.$route.query.topic_id }
+ this.commentInfo.article = this.topicData.article.id
+ this.$service.article
+ .postComment(this.commentInfo)
+ .then(res => {
+ if (res.code === 200) {
+ console.log(res)
+ console.log('成功提交评论')
+ }
})
- .then((res) => {
- if (res.data.status === 200) {
- this.isliked = res.data.isliked
- this.iscollected = res.data.iscollected
+ },
+ // 删除评论
+ removeComment () {
+ this.$service.article
+ .deleteComment(this.commentInfo)
+ .then(res => {
+ if (res.code === 200) {
+ console.log(res)
+ console.log('成功删除评论')
}
})
- .catch((res) => {})
},
onClickLeft () {
this.$router.go(-1)
},
+ // 查询收藏状态
+ getCollectState (id) {
+ this.$service.article
+ .getCollect(id)
+ .then(res => {
+ if (res.data.code === 200) {
+ this.iscollected = true
+ } else {
+ this.iscollected = false
+ }
+ })
+ },
// 收藏
- onClickRight () {
+ addCollect (id) {
if (!this.iscollected) {
- this.$http
- .get('/collect/add', {
- params: { topic_id: this.$route.query.topic_id }
- })
- .then((res) => {
- if (res.data.status === 200) {
+ this.$service.article
+ .postCollect(id)
+ .then(res => {
+ console.log(res)
+ if (res.code === 200) {
this.iscollected = true
}
})
- .catch((res) => {})
} else {
- this.$http
- .get('/collect/delete', {
- params: { topic_id: this.$route.query.topic_id }
- })
- .then((res) => {
- if (res.data.status === 200) {
+ this.$service.article
+ .deleteCollect(id)
+ .then(res => {
+ console.log(res)
+ if (res.code === 200) {
this.iscollected = false
}
})
- .catch((res) => {})
}
}
},
--
Gitee
From 5faf428c639caf575d68822df43bc47f8938e7a9 Mon Sep 17 00:00:00 2001
From: csh1314
Date: Sun, 26 Sep 2021 11:50:21 +0800
Subject: [PATCH 13/34] =?UTF-8?q?:bug:=20(server)=20=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E5=B1=95=E7=A4=BA=E4=B8=8D?=
=?UTF-8?q?=E5=85=A8=E7=9A=84bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/blog-server/src/controllers/auth.controller.js | 1 +
packages/blog-server/src/middleware/authMiddleware.js | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/packages/blog-server/src/controllers/auth.controller.js b/packages/blog-server/src/controllers/auth.controller.js
index f2ceecd..b28f341 100644
--- a/packages/blog-server/src/controllers/auth.controller.js
+++ b/packages/blog-server/src/controllers/auth.controller.js
@@ -58,6 +58,7 @@ class AuthController {
avatar: "",
password: md5password(password)
})
+ console.log(user)
const ret = await userService.create(user)
console.log(ret)
ctx.body = {
diff --git a/packages/blog-server/src/middleware/authMiddleware.js b/packages/blog-server/src/middleware/authMiddleware.js
index 8c83a54..70d259e 100644
--- a/packages/blog-server/src/middleware/authMiddleware.js
+++ b/packages/blog-server/src/middleware/authMiddleware.js
@@ -16,8 +16,8 @@ const verifyAuth = async (ctx, next) => {
const result = jwt.verify(token, PUBLIC_KEY, {
algorithms: ["RS256"]
});
- const { username } = result;
- const userInfo = await userService.getUserByUsername(username);
+ const { id } = result;
+ const userInfo = await userService.getUserById(id);
ctx.userInfo = userInfo;
ctx.token = authorization;
await next();
--
Gitee
From fca05dd88bb2fcf38b385a9e8c5644c23ebe650e Mon Sep 17 00:00:00 2001
From: CreatingLiu <773673499@qq.com>
Date: Sun, 26 Sep 2021 11:55:46 +0800
Subject: [PATCH 14/34] =?UTF-8?q?:sparkles:=20(server)=20=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E6=B5=8F=E8=A7=88=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../blog-server/src/controllers/view.controller.js | 13 +++++++++++++
packages/blog-server/src/routers/view.js | 13 +++++++++++++
2 files changed, 26 insertions(+)
create mode 100644 packages/blog-server/src/controllers/view.controller.js
create mode 100644 packages/blog-server/src/routers/view.js
diff --git a/packages/blog-server/src/controllers/view.controller.js b/packages/blog-server/src/controllers/view.controller.js
new file mode 100644
index 0000000..3381800
--- /dev/null
+++ b/packages/blog-server/src/controllers/view.controller.js
@@ -0,0 +1,13 @@
+const articleService = require('../services/articleService')
+
+class SectionController {
+ async post(ctx) {
+ articleService.setData(ctx.request.body.article, 'view', true);
+ ctx.body = {
+ code: 200,
+ msg: 'done'
+ }
+ }
+}
+
+module.exports = new SectionController();
\ No newline at end of file
diff --git a/packages/blog-server/src/routers/view.js b/packages/blog-server/src/routers/view.js
new file mode 100644
index 0000000..9b056a9
--- /dev/null
+++ b/packages/blog-server/src/routers/view.js
@@ -0,0 +1,13 @@
+const Router = require('@koa/router');
+// Koa 的路由在被 use 时是无法指定前缀的, 需要在定义时就指定前缀
+const router = Router({
+ prefix: '/api/view'
+});
+
+const viewController = require('../controllers/view.controller');
+
+
+// 组装路由
+router.post('/', viewController.post)
+// Koa 的路由需要调用 routes 函数获取实际用于 use 的函数
+module.exports = router;
--
Gitee
From b66d7907aa4b43abd19f1c0cfe766a79cb5bbb85 Mon Sep 17 00:00:00 2001
From: yl-199807 <846622356@qq.com>
Date: Sun, 26 Sep 2021 11:49:15 +0800
Subject: [PATCH 15/34] =?UTF-8?q?:bug:=20(release)=20=E5=8F=91=E5=B8=83?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/blog-view/src/api/article.js | 5 +++
packages/blog-view/src/pages/Release.vue | 53 ++++++++++--------------
packages/blog-view/src/store/index.js | 4 ++
3 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/packages/blog-view/src/api/article.js b/packages/blog-view/src/api/article.js
index 7d1ec6e..6d4982d 100644
--- a/packages/blog-view/src/api/article.js
+++ b/packages/blog-view/src/api/article.js
@@ -13,6 +13,11 @@ export const getArticleList = () => {
return axios.get('/api/article')
}
+export const postArticle = (param, token) => {
+ axios.defaults.headers['Authorization'] = token
+ return axios.post('/api/article', param)
+}
+
// 获取文章内容
export const getArticleInfo = (params) => {
return axios.get(`/api/article/${params}`)
diff --git a/packages/blog-view/src/pages/Release.vue b/packages/blog-view/src/pages/Release.vue
index 71c33d7..95135b5 100644
--- a/packages/blog-view/src/pages/Release.vue
+++ b/packages/blog-view/src/pages/Release.vue
@@ -108,20 +108,6 @@ export default {
text: v.name,
value: v.id})
})
- // sectionlist.push({
- // text: this.fsection.name,
- // value: this.fsection.id
- // })
- // for (var i in this.pageControl.sectionlist) {
- // if (this.pageControl.sectionlist[i].fsection === this.fsection_value) {
- // sectionlist.push({
- // text: this.pageControl.sectionlist[i].name,
- // value: this.pageControl.sectionlist[i].id
- // })
- // }
- // }
- // // eslint-disable-next-line vue/no-side-effects-in-computed-properties
- // this.csection_value = this.fsection.id
return sectionlist
},
inputfield () {
@@ -200,23 +186,28 @@ export default {
...mapMutations(['openLeftPopup', 'openTopPopup_search']),
save () {},
onSubmit (field) {
- this.$http
- .post('/topic/save', {
- name: this.name,
- intro: this.intro,
- image: this.images[0],
- isanonymous: this.isanonymous,
- section: this.csection_value,
- content: this.content
- })
- .then(res => {
- if (res.data.status === 200) {
- this.$dialog({message: res.data.msg})
- }
- })
- .catch(res => {
- console.log(res)
- })
+ let token = localStorage.getItem('token')
+ this.$service.article.postArticle({
+ title: this.name,
+ content: this.content
+ }, token)
+ // this.$http
+ // .post('/topic/save', {
+ // name: this.name,
+ // intro: this.intro,
+ // image: this.images[0],
+ // isanonymous: this.isanonymous,
+ // section: this.csection_value,
+ // content: this.content
+ // })
+ // .then(res => {
+ // if (res.data.status === 200) {
+ // this.$dialog({message: res.data.msg})
+ // }
+ // })
+ // .catch(res => {
+ // console.log(res)
+ // })
},
updateData (e) {
this.content = e
diff --git a/packages/blog-view/src/store/index.js b/packages/blog-view/src/store/index.js
index 105c7a7..de955db 100644
--- a/packages/blog-view/src/store/index.js
+++ b/packages/blog-view/src/store/index.js
@@ -28,6 +28,7 @@ export default new Vuex.Store({
sectionlist: [
{
tag: Module_TYPE.bug,
+ id: 1,
name: 'bug',
img:
'https://zwc365.com/upload/2020/09/icon-a23e741d3140415496bba57e09edde37.jpg',
@@ -35,6 +36,7 @@ export default new Vuex.Store({
},
{
tag: Module_TYPE.quiz,
+ id: 2,
name: '技术提问',
img:
'https://zwc365.com/upload/2020/09/icon-a23e741d3140415496bba57e09edde37.jpg',
@@ -42,6 +44,7 @@ export default new Vuex.Store({
},
{
tag: Module_TYPE.ProCom,
+ id: 3,
name: '职业交流',
img:
'https://zwc365.com/upload/2020/09/icon-a23e741d3140415496bba57e09edde37.jpg',
@@ -49,6 +52,7 @@ export default new Vuex.Store({
},
{
tag: Module_TYPE.recreation,
+ id: 4,
name: '娱乐交流',
img:
'https://zwc365.com/upload/2020/09/icon-a23e741d3140415496bba57e09edde37.jpg',
--
Gitee
From c02df91f540ea83cbb778407d5936a6956bf8f33 Mon Sep 17 00:00:00 2001
From: csh1314
Date: Sun, 26 Sep 2021 12:06:06 +0800
Subject: [PATCH 16/34] =?UTF-8?q?:sparkles:=20(server)=20=E5=AE=8C?=
=?UTF-8?q?=E6=88=90=E5=A4=B4=E5=83=8F=E4=B8=8A=E4=BC=A0api?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/controllers/file.controller.js | 30 ++++++++++++++++++-
packages/blog-server/src/routers/file.js | 4 ++-
.../blog-server/src/services/userService.js | 14 +++++++++
3 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/packages/blog-server/src/controllers/file.controller.js b/packages/blog-server/src/controllers/file.controller.js
index 136c2f8..679daeb 100644
--- a/packages/blog-server/src/controllers/file.controller.js
+++ b/packages/blog-server/src/controllers/file.controller.js
@@ -2,9 +2,13 @@ const inspirecloud = require('@byteinspire/api');
const readFilePromise = require('../utils/read-file');
+const userService = require('../services/userService')
class FileController {
- // 多图上传
+ /**
+ * 多图上传
+ * @param {Array} fileList ctx.request.files.file
+ */
async upload(ctx){
const fileList = ctx.request.files.file
const urlList = []
@@ -27,6 +31,30 @@ class FileController {
}
}
}
+ /**
+ * 头像上传,绑定到用户
+ * @param {*} file
+ */
+ async avatar(ctx){
+ const file = ctx.request.files.file
+ const buffer = await readFilePromise(file.path)
+ const { url } = await inspirecloud.file.upload(
+ file.name,
+ buffer,
+ {
+ type: file.type
+ }
+ )
+ const { _id } = ctx.userInfo
+ const ret = await userService.avatar({ id:_id, url})
+ ctx.body = {
+ code: 200,
+ msg: "头像上传成功",
+ data: {
+ url
+ }
+ }
+ }
}
module.exports = new FileController()
\ No newline at end of file
diff --git a/packages/blog-server/src/routers/file.js b/packages/blog-server/src/routers/file.js
index 0bd8420..af61fb0 100644
--- a/packages/blog-server/src/routers/file.js
+++ b/packages/blog-server/src/routers/file.js
@@ -8,7 +8,9 @@ const authMiddleware = require('../middleware/authMiddleware')
const fileController = require('../controllers/file.controller')
// 组装路由
+// 上传多张图片
router.post('/', authMiddleware.verifyAuth, fileController.upload)
-
+// 上传用户头像
+router.post('/avatar', authMiddleware.verifyAuth, fileController.avatar)
// Koa 的路由需要调用 routes 函数获取实际用于 use 的函数
module.exports = router;
diff --git a/packages/blog-server/src/services/userService.js b/packages/blog-server/src/services/userService.js
index 72db520..f8dca2f 100644
--- a/packages/blog-server/src/services/userService.js
+++ b/packages/blog-server/src/services/userService.js
@@ -62,6 +62,20 @@ class UserService {
result: user
}
}
+
+ /**
+ * 上传头像
+ * @param {*} id
+ * @param {string} url
+ */
+ async avatar({id, url}) {
+ let user = await userTable.where({_id: id}).findOne()
+ user = Object.assign(user, {avatar:url})
+ await userTable.save(user)
+ return {
+ result: user
+ }
+ }
}
module.exports = new UserService()
\ No newline at end of file
--
Gitee
From 03a1808c08c56ea3b836f1d52b26d9c8ca75bb9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B0=B4=E5=86=B0=E6=B7=BC?= <546483720@qq.com>
Date: Sun, 26 Sep 2021 12:22:37 +0800
Subject: [PATCH 17/34] =?UTF-8?q?:sparkles:=20(=E5=BC=95=E5=85=A5moment?=
=?UTF-8?q?=E5=BA=93)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/blog-view/package-lock.json | 6 ++++++
packages/blog-view/package.json | 5 +++--
packages/blog-view/src/App.vue | 3 +++
packages/blog-view/src/main.js | 6 +++++-
4 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/packages/blog-view/package-lock.json b/packages/blog-view/package-lock.json
index c771ce4..769edfa 100644
--- a/packages/blog-view/package-lock.json
+++ b/packages/blog-view/package-lock.json
@@ -6805,6 +6805,12 @@
"minimist": "^1.2.5"
}
},
+ "moment": {
+ "version": "2.29.1",
+ "resolved": "https://registry.npm.taobao.org/moment/download/moment-2.29.1.tgz",
+ "integrity": "sha1-sr52n6MZQL6e7qZGnAdeNQBvo9M=",
+ "dev": true
+ },
"move-concurrently": {
"version": "1.0.1",
"resolved": "https://registry.nlark.com/move-concurrently/download/move-concurrently-1.0.1.tgz",
diff --git a/packages/blog-view/package.json b/packages/blog-view/package.json
index 8557d97..4d4c2a3 100644
--- a/packages/blog-view/package.json
+++ b/packages/blog-view/package.json
@@ -55,11 +55,12 @@
"eslint-plugin-vue": "^4.0.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
- "friendly-errors-webpack-plugin": "^1.6.1",
"font-awesome": "^4.7.0",
+ "friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"less": "^4.1.1",
"less-loader": "^5.0.0",
+ "moment": "^2.29.1",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
@@ -73,8 +74,8 @@
"style-loader": "^3.2.1",
"typescript": "^4.4.2",
"uglifyjs-webpack-plugin": "^1.1.1",
- "vue-html5-editor": "^1.1.1",
"url-loader": "^0.5.8",
+ "vue-html5-editor": "^1.1.1",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
diff --git a/packages/blog-view/src/App.vue b/packages/blog-view/src/App.vue
index f85dfa1..3b6c394 100644
--- a/packages/blog-view/src/App.vue
+++ b/packages/blog-view/src/App.vue
@@ -21,6 +21,9 @@ export default {
window.onresize = this.handleSizeChange
},
mounted() {
+ // moment使用示例
+ const date = new Date()
+ console.log(this.$moment(date).format('YYYY-MM-DD hh:mm:ss'))
this.$service.user
.getUserInfo()
.then(userinfo => {
diff --git a/packages/blog-view/src/main.js b/packages/blog-view/src/main.js
index 616889a..6c2a25c 100644
--- a/packages/blog-view/src/main.js
+++ b/packages/blog-view/src/main.js
@@ -1,7 +1,7 @@
/*
* @Author: Hook
* @Date: 2021-08-23 20:55:58
- * @LastEditTime: 2021-09-25 14:12:16
+ * @LastEditTime: 2021-09-26 12:07:57
* @LastEditors: Do not edit
* @Description: In User Settings Edit
* @FilePath: \blog\packages\blog-view\src\main.js
@@ -37,6 +37,9 @@ import VueHtml5Editor from 'vue-html5-editor'
// 引入font-awesome
import 'font-awesome/css/font-awesome.css'
+// 引入moment库
+import moment from 'moment'
+
// 全局引入富文本编辑器,并配置
Vue.use(VueHtml5Editor, {
name: 'vue-html5-editor',
@@ -143,6 +146,7 @@ Vue.use(VueHtml5Editor, {
modules: {}
})
+Vue.prototype.$moment = moment
// Vue.use(ApiPlugin, { $default: axios });
Vue.prototype.$md5 = md5
--
Gitee
From e15edd419f3c5057fe4fe518105160e30fd3b2e2 Mon Sep 17 00:00:00 2001
From: Binlue <919760604@qq.com>
Date: Sun, 26 Sep 2021 10:57:35 +0800
Subject: [PATCH 18/34] =?UTF-8?q?:sparkles:=20(=E5=89=8D=E7=AB=AF)=20?=
=?UTF-8?q?=E6=B3=A8=E5=86=8C=E9=A1=B5=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
注册页面修改,路由更正
---
packages/blog-view/src/api/user.js | 8 +-
.../blog-view/src/assets/js/makeformdata.js | 28 +++++++
packages/blog-view/src/pages/Login.vue | 18 ++---
packages/blog-view/src/pages/PersonInfo.vue | 78 ++++++++++++-------
4 files changed, 91 insertions(+), 41 deletions(-)
create mode 100644 packages/blog-view/src/assets/js/makeformdata.js
diff --git a/packages/blog-view/src/api/user.js b/packages/blog-view/src/api/user.js
index 7456f01..28f6858 100644
--- a/packages/blog-view/src/api/user.js
+++ b/packages/blog-view/src/api/user.js
@@ -9,13 +9,17 @@
import axios from 'axios'
// 获取用户信息接口
-export const getUserInfo = (params) => {
+export const getUserInfo = params => {
return axios.get('/api/auth/account', { params })
}
// 更改用户信息
export const changeInfo = query => {
- axios.put('/api/auth/account', query)
+ return axios.put('/api/auth/account', query, {
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ }
+ })
}
// 获取用户Token
diff --git a/packages/blog-view/src/assets/js/makeformdata.js b/packages/blog-view/src/assets/js/makeformdata.js
new file mode 100644
index 0000000..24aa224
--- /dev/null
+++ b/packages/blog-view/src/assets/js/makeformdata.js
@@ -0,0 +1,28 @@
+export function jsToFormData(config) { //对象转formdata格式
+ let formData = new FormData();
+ let obj = config.data;
+ let arrayKey = config.arrayKey;
+ for (var i in obj) {
+ if (isArray(obj[i])) {
+ obj[i].map(item => {
+ if (!arrayKey) {
+ formData.append(i, item)
+ } else {
+ formData.append(i + '[]', item)
+ }
+ })
+ } else if (obj[i] instanceof FileList) {
+ //filelist 文件类型的处理
+ for (var fileItem = 0; fileItem < obj[i].length; fileItem++) {
+ if (!arrayKey) {
+ formData.append(i, obj[i].item(fileItem))
+ } else {
+ formData.append(i + '[]', obj[i].item(fileItem))
+ }
+ }
+ } else {
+ formData.append(i, obj[i])
+ }
+ }
+ return formData;
+}
\ No newline at end of file
diff --git a/packages/blog-view/src/pages/Login.vue b/packages/blog-view/src/pages/Login.vue
index c26cf00..7f88bcc 100644
--- a/packages/blog-view/src/pages/Login.vue
+++ b/packages/blog-view/src/pages/Login.vue
@@ -61,7 +61,6 @@
前往注册
-
@@ -110,10 +109,11 @@ export default {
.then(res => {
if (res.code === 200) {
this.$dialog({ message: res.msg })
- console.log('token为' + res.data['token'])
+ // console.log('token为' + res.data['token'])
window.localStorage.setItem('token', res.data['token'])
- const test = window.localStorage.getItem('token')
- console.log('local已储存' + test)
+ // const test = window.localStorage.getItem('token')
+ // console.log('local已储存')
+ // console.log(test)
this.addUserInfo()
setTimeout(() => {
this.$router.push('/')
@@ -139,15 +139,15 @@ export default {
// 登录成功后将用户信息存储
addUserInfo () {
- console.log('开始存储用户信息')
+ // console.log('开始存储用户信息')
this.$service.user
.getInfo()
.then(res => {
- console.log(res)
+ // console.log(res)
if (res.code === 200) {
// 将用户信息保存至store中
- console.log('开始存储信息')
- console.log(res.data['userInfo'])
+ // console.log('开始存储信息')
+ // console.log(res.data['userInfo'])
this.$store.commit('login', res.data['userInfo'])
} else {
alert('获取用户信息失败')
@@ -157,7 +157,7 @@ export default {
console.log(err)
this.$dialog({ message: err.body.msg })
})
- console.log('store已储存' + this.$store.state.userinfo)
+ // console.log('store已储存' + this.$store.state.userinfo)
// this.$service.login
// .getUserInfo(token)
diff --git a/packages/blog-view/src/pages/PersonInfo.vue b/packages/blog-view/src/pages/PersonInfo.vue
index 16dde44b..103c24b 100644
--- a/packages/blog-view/src/pages/PersonInfo.vue
+++ b/packages/blog-view/src/pages/PersonInfo.vue
@@ -51,6 +51,7 @@