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 }}条回复 - - - {{ comment.likecount }} - - - - - - - +
+ + + {{ comment.like }} + + + + + + +
+ +
- + @@ -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" >