Skip to content

Commit 4112337

Browse files
Merge branch 'master' of https://github.com/callmehui/easyblog
2 parents d7b5d9f + 8172090 commit 4112337

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

blogvue/vue.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = {
6363
devServer: {
6464
proxy: {
6565
'/api': { // 以/api开头的接口都代理到target指定的域名下
66-
target: 'https://immortalboy.cn'
66+
target: 'http://127.0.0.1:7001'
6767
}
6868
}
6969
}

service/app/controller/blog/index.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,28 @@ class IndexController extends controller {
1010

1111
async getUserInfoById() {
1212
const id = this.ctx.params.id;
13+
console.log('id', id);
1314
const selectSql = `SELECT username as username, portrait as portrait, bg_img as bgImg,
1415
qq_account as qqAccount, wechat_account as weChatAccount, github_url as githubUrl,
1516
logo_name as logoName, logo_sub as logoSub
1617
FROM admin_user WHERE id = ?`;
17-
const selectResult = await this.app.mysql.query(selectSql, [ id ]);
18-
const articleCountResult = await this.app.mysql.query('SELECT count(*) as count from article');
19-
const talkCountResult = await this.app.mysql.query('SELECT count(*) as count from talk');
20-
const novelCountResult = await this.app.mysql.query('SELECT count(*) as count from novel');
21-
if (selectResult.length > 0) {
22-
const dataObj = selectResult[0];
18+
const userInfoPromise = this.app.mysql.query(selectSql, [ id ]);
19+
const articleCountPromise = this.app.mysql.query('SELECT count(id) as count from article');
20+
const talkCountPromise = this.app.mysql.query('SELECT count(id) as count from talk');
21+
const novelCountPromise = this.app.mysql.query('SELECT (max(id)-min(id)+1) as count from novel where is_deleted = 0');
22+
const [userInfoResult, articleCountResult, talkCountResult, novelCountResult] = await Promise.all([userInfoPromise, articleCountPromise, talkCountPromise, novelCountPromise])
23+
if (userInfoResult.length > 0) {
24+
const dataObj = userInfoResult[0];
2325
dataObj.articleCount = articleCountResult[0].count;
2426
dataObj.talkCount = talkCountResult[0].count;
2527
dataObj.novelCount = novelCountResult[0].count;
28+
console.log('dataObj', dataObj);
2629
this.ctx.body = { success: true, data: dataObj };
30+
console.log(this.ctx.body);
2731
} else {
2832
this.ctx.body = { success: false, message: '获取个人信息失败' };
2933
}
34+
3035
}
3136

3237
async getAdverList() {
@@ -53,19 +58,21 @@ class IndexController extends controller {
5358
article_type.name as type
5459
FROM article LEFT JOIN article_type
5560
ON article.type_id = article_type.id WHERE article.is_publish = 1 ORDER BY article.publish_time DESC LIMIT ?,?`;
56-
const result = await this.app.mysql.query(sql, [ request.offset, request.limit ]);
57-
const countResult = await this.app.mysql.query('SELECT count(*) as total FROM article');
58-
if (result.length > 0) {
59-
for (const item of result) {
61+
const articleListPromise = this.app.mysql.query(sql, [ request.offset, request.limit ]);
62+
const countPromise = this.app.mysql.query('SELECT (max(id)-min(id)+1) as count from novel where is_deleted = 0');
63+
const [articleListResult, countResult] = await Promise.all([articleListPromise, countPromise])
64+
if (articleListResult.length > 0) {
65+
for (const item of articleListResult) {
6066
item.listType = 'article';
6167
}
6268
this.ctx.body = {
6369
success: true,
6470
data: {
6571
total: countResult[0].total,
66-
list: result,
72+
list: articleListResult,
6773
},
6874
};
75+
console.log(this.ctx.body);
6976
} else {
7077
this.ctx.body = {
7178
success: false,
@@ -82,7 +89,7 @@ class IndexController extends controller {
8289
LEFT JOIN admin_user AS user ON talk.user_id = user.id
8390
ORDER BY talk.publish_time DESC LIMIT ?,?`;
8491
const result = await this.app.mysql.query(sql, [ request.offset, request.limit ]);
85-
const countResult = await this.app.mysql.query('SELECT count(*) as total FROM talk');
92+
const countResult = await this.app.mysql.query('SELECT count(id) as total FROM talk');
8693
if (result.length > 0) {
8794
const commentsql = 'SELECT count(*) as count FROM visitor_comment as comment WHERE comment.talk_id = ?';
8895
for (const item of result) {
@@ -118,7 +125,7 @@ class IndexController extends controller {
118125
LEFT JOIN novel ON chapter.novel_id = novel.id
119126
ORDER BY chapter.updatetime DESC LIMIT ?,?`;
120127
const sqlResult = await this.app.mysql.query(sql, [ request.offset, request.limit ]);
121-
const countResult = await this.app.mysql.query('SELECT count(*) as total FROM novel_chapter');
128+
const countResult = await this.app.mysql.query('SELECT (max(id)-min(id)+1) as count from novel_chapter where is_deleted = 0');
122129
if (sqlResult.length > 0) {
123130
for (const item of sqlResult) {
124131
item.listType = 'novel';
@@ -156,8 +163,8 @@ class IndexController extends controller {
156163

157164
async getIndexListApp() {
158165
const request = this.ctx.request.body;
159-
const chapterCountResult = await this.app.mysql.query('SELECT count(*) AS total FROM novel_chapter');
160-
const articleCountResult = await this.app.mysql.query('SELECT count(*) AS total FROM article');
166+
const chapterCountResult = await this.app.mysql.query('SELECT (max(id)-min(id)+1) AS total FROM novel_chapter where is_deleted = 0');
167+
const articleCountResult = await this.app.mysql.query('SELECT (max(id)-min(id)+1) AS total FROM article where is_deleted = 0');
161168
const chapterSql = 'SELECT id AS chapterId, updatetime AS updateTime FROM novel_chapter';
162169
const articleSql = 'SELECT id AS articleId, publish_time AS updateTime FROM article';
163170
const chapterList = await this.app.mysql.query(chapterSql);
@@ -224,7 +231,7 @@ class IndexController extends controller {
224231
introduce_img AS introduceImg, view_count AS viewCount
225232
FROM article where title like '%${request.searchValue}%' AND is_publish = 1 ORDER BY publish_time DESC LIMIT ?,?`;
226233
const sqlResult = await this.app.mysql.query(sql, [ request.offset, request.limit ]);
227-
const countResult = await this.app.mysql.query('SELECT count(*) as total FROM article');
234+
const countResult = await this.app.mysql.query('SELECT (max(id)-min(id)+1) as total FROM article where is_deleted = 0');
228235
if (sqlResult.length > 0) {
229236
for (const item of sqlResult) {
230237
item.listType = 'article';
@@ -251,7 +258,7 @@ class IndexController extends controller {
251258
LEFT JOIN novel ON chapter.novel_id = novel.id
252259
WHERE chapter.name like '%${request.searchValue}%' ORDER BY updatetime DESC LIMIT ?,?`;
253260
const sqlResult = await this.app.mysql.query(sql, [ request.offset, request.limit ]);
254-
const countResult = await this.app.mysql.query('SELECT count(*) as total FROM novel_chapter');
261+
const countResult = await this.app.mysql.query('SELECT (max(id)-min(id)+1) as total FROM novel_chapter where is_deleted = 0');
255262
if (sqlResult.length > 0) {
256263
for (const item of sqlResult) {
257264
item.listType = 'novel';

0 commit comments

Comments
 (0)