Skip to content

Commit 134cd2d

Browse files
author
David
committed
添加搜索文章名称
1 parent ef9231e commit 134cd2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2383
-89
lines changed

.DS_Store

0 Bytes
Binary file not shown.

BlogBack/.idea/workspace.xml

Lines changed: 76 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BlogBack/src/main/java/com/luobo/common/dto/PageDto.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.luobo.common.dto;
22

3+
import com.luobo.entity.Blog;
34
import lombok.Data;
45

56
/**
@@ -10,8 +11,15 @@
1011
* @Version 1.0
1112
**/
1213
@Data
13-
public class PageDto {
14-
private Integer userId;
14+
public class PageDto extends Blog {
1515
private Integer currentPage;
1616
private Integer pageSize;
17+
18+
@Override
19+
public String getTitle() {
20+
if(null == super.getTitle() || super.getTitle().isEmpty()){
21+
return "";
22+
}
23+
return super.getTitle();
24+
}
1725
}

BlogBack/src/main/java/com/luobo/controller/BlogController.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.luobo.common.dto.PageDto;
1010
import com.luobo.common.lang.Result;
1111
import com.luobo.entity.Blog;
12-
import com.luobo.entity.Vote;
1312
import com.luobo.service.BlogService;
1413
import com.luobo.service.CommentService;
1514
import com.luobo.service.UserService;
@@ -18,13 +17,11 @@
1817
import com.luobo.util.JwtUtils;
1918
import com.luobo.util.ShiroUtil;
2019
import io.jsonwebtoken.Claims;
21-
import org.apache.shiro.SecurityUtils;
2220
import org.apache.shiro.authz.annotation.RequiresAuthentication;
2321
import org.apache.shiro.util.Assert;
2422
import org.springframework.beans.factory.annotation.Autowired;
2523
import org.springframework.validation.annotation.Validated;
2624
import org.springframework.web.bind.annotation.*;
27-
import redis.clients.jedis.Jedis;
2825

2926
import javax.servlet.ServletRequest;
3027
import javax.servlet.http.HttpServletRequest;
@@ -34,8 +31,6 @@
3431
* <p>
3532
* 前端控制器
3633
* </p>
37-
*
38-
* @author 关注公众号:MarkerHub
3934
* @since 2020-08-06
4035
*/
4136
@RestController
@@ -102,7 +97,8 @@ public Result blogs(@RequestBody PageDto pageParams, ServletRequest servletReque
10297
if(null != claims){
10398
currentUserId =Long.parseLong(claims.get("sub").toString());
10499
}
105-
IPage pageData =blogService.GetBlogsLeftInUser(page, new QueryWrapper<Blog>().orderByDesc("created"),currentUserId);
100+
101+
IPage pageData =blogService.GetBlogsLeftInUser(page, new QueryWrapper<Blog>().orderByDesc("created"),currentUserId,pageParams);
106102
return Result.succ(pageData);
107103
}
108104

@@ -183,4 +179,5 @@ public Result getBlgs(@Validated @RequestBody PageDto pageParams){
183179
}
184180

185181

182+
186183
}

BlogBack/src/main/java/com/luobo/mapper/BlogMapper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
44
import com.baomidou.mybatisplus.core.toolkit.Constants;
55
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6+
import com.luobo.common.dto.PageDto;
67
import com.luobo.entity.Blog;
78
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
89
import org.apache.ibatis.annotations.Param;
@@ -26,7 +27,7 @@ public interface BlogMapper extends BaseMapper<Blog> {
2627
* @updateTime 2020/11/2 16:59
2728
* @return: java.util.List<com.luobo.entity.Blog>
2829
*/
29-
List<Blog> findBlogs(Page<Blog> page, @Param(Constants.WRAPPER) QueryWrapper<Blog> wrapper, Long currentUserId);
30+
List<Blog> findBlogs(Page<Blog> page, @Param(Constants.WRAPPER) QueryWrapper<Blog> wrapper, Long currentUserId, String title);
3031

3132
/**
3233
* @title findBlogsByUserId
@@ -37,5 +38,6 @@ public interface BlogMapper extends BaseMapper<Blog> {
3738
* @updateTime 2020/11/26 11:01
3839
* @return: java.util.List<com.luobo.entity.Blog>
3940
*/
40-
List<Blog> findBlogsByUserId(Page<Blog> page, Integer userId);
41+
List<Blog> findBlogsByUserId(Page<Blog> page, Long userId);
42+
4143
}

BlogBack/src/main/java/com/luobo/service/BlogService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
44
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5+
import com.luobo.common.dto.PageDto;
56
import com.luobo.entity.Blog;
67
import com.baomidou.mybatisplus.extension.service.IService;
78

@@ -23,7 +24,7 @@ public interface BlogService extends IService<Blog> {
2324
* @updateTime 2020/11/26 11:02
2425
* @return: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.luobo.entity.Blog>
2526
*/
26-
Page<Blog> GetBlogsLeftInUser (Page<Blog> page, QueryWrapper<Blog> wrapper,Long currentuserId);
27+
Page<Blog> GetBlogsLeftInUser (Page<Blog> page, QueryWrapper<Blog> wrapper, Long currentuserId, PageDto pageParams);
2728

2829
/**
2930
* @title GetBlogsByuUserId
@@ -34,5 +35,7 @@ public interface BlogService extends IService<Blog> {
3435
* @updateTime 2020/11/26 11:03
3536
* @return: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.luobo.entity.Blog>
3637
*/
37-
Page<Blog> GetBlogsByuUserId (Page<Blog> page, Integer userId);
38+
Page<Blog> GetBlogsByuUserId (Page<Blog> page, Long userId);
39+
40+
3841
}

BlogBack/src/main/java/com/luobo/service/impl/BlogServiceImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
44
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5+
import com.luobo.common.dto.PageDto;
56
import com.luobo.entity.Blog;
67
import com.luobo.mapper.BlogMapper;
78
import com.luobo.service.BlogService;
@@ -33,8 +34,8 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements Bl
3334
* @return: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.luobo.entity.Blog>
3435
*/
3536
@Override
36-
public Page<Blog> GetBlogsLeftInUser(Page<Blog> page, QueryWrapper<Blog> wrapper,Long currentuserId) {
37-
return page.setRecords(blogMapper.findBlogs(page,wrapper,currentuserId));
37+
public Page<Blog> GetBlogsLeftInUser(Page<Blog> page, QueryWrapper<Blog> wrapper, Long currentuserId, PageDto pageParams) {
38+
return page.setRecords(blogMapper.findBlogs(page,wrapper,currentuserId,pageParams.getTitle()));
3839
}
3940

4041
/**
@@ -47,7 +48,9 @@ public Page<Blog> GetBlogsLeftInUser(Page<Blog> page, QueryWrapper<Blog> wrapper
4748
* @return: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.luobo.entity.Blog>
4849
*/
4950
@Override
50-
public Page<Blog> GetBlogsByuUserId(Page<Blog> page, Integer userId) {
51+
public Page<Blog> GetBlogsByuUserId(Page<Blog> page, Long userId) {
5152
return page.setRecords(blogMapper.findBlogsByUserId(page,userId));
5253
}
54+
55+
5356
}

BlogBack/src/main/resources/mapper/BlogMapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
SELECT b.*, u.username ,m.id as is_vote FROM m_blog b
1313
LEFT JOIN m_user u on b.user_id = u.id
1414
LEFT JOIN (SELECT * from m_vote v
15-
WHERE v.user_id = #{currentUserId}) m on m.voteable_id = b.id ${ew.customSqlSegment}
15+
WHERE v.user_id = #{currentUserId}) m on m.voteable_id = b.id where b.title like concat(#{title},'%') ${ew.customSqlSegment}
1616
</select>
1717

1818
<!-- 根据用户ID获取文章 -->
114 Bytes
Binary file not shown.
114 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

BlogBack/target/classes/mapper/BlogMapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
SELECT b.*, u.username ,m.id as is_vote FROM m_blog b
1313
LEFT JOIN m_user u on b.user_id = u.id
1414
LEFT JOIN (SELECT * from m_vote v
15-
WHERE v.user_id = #{currentUserId}) m on m.voteable_id = b.id ${ew.customSqlSegment}
15+
WHERE v.user_id = #{currentUserId}) m on m.voteable_id = b.id where b.title like concat(#{title},'%') ${ew.customSqlSegment}
1616
</select>
1717

1818
<!-- 根据用户ID获取文章 -->

BlogVue/src/components/Header.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
</li> -->
228228
<li class="m-person-theme-default nav-item search">
229229
<div class="search-form-theme-default ">
230-
<searchbtn></searchbtn>
230+
<searchbtn @matrix-input-value="searchBlog"></searchbtn>
231231
</div>
232232
</li>
233233
<li
@@ -345,6 +345,17 @@ export default {
345345
}
346346
},
347347
methods: {
348+
/**
349+
* @description: 组件函数回调 搜索按钮被点击
350+
* @param {*}
351+
* @return {*}
352+
* @Date: 2021-05-16 15:06:07
353+
* @Author: David
354+
*/
355+
356+
searchBlog(keyword) {
357+
this.$emit("matrix-search", keyword);
358+
},
348359
/**
349360
* @description: 点击回到主页
350361
* @param {*}

BlogVue/src/components/bloglist/BlogList.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,17 @@ export default {
221221
/**
222222
* @description: 获得文章
223223
* @param {Object} category 文章的分类 推荐、关注。。。。。
224+
* @param {String} keyword 文章的标题。。。。。
224225
* @return {*}
225226
* @Date: 2020-10-31 15:31:00
226227
* @Author: David
227228
*/
228-
articles(category) {
229+
articles(category, keyword) {
229230
const _this = this;
230231
let params = {
231232
currentPage: this.currentPage,
232-
pageSize: this.pageSize
233+
pageSize: this.pageSize,
234+
title: keyword
233235
};
234236
this.$axios.post(APIConfig.Base.Blogs, params).then(res => {
235237
let resp = res.resp;
@@ -244,6 +246,12 @@ export default {
244246
});
245247
},
246248
249+
searchByKeyword(keyword) {
250+
this.currentPage = 1;
251+
this.aritcleList = [];
252+
this.articles("", keyword);
253+
},
254+
247255
/**
248256
* @description: 文章点赞
249257
* @param {Object} blog 文章ID

BlogVue/src/components/input/Input.vue

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
* @Author: David
33
* @Date: 2020-10-27 21:51:10
4-
* @LastEditTime: 2021-03-03 20:57:07
4+
* @LastEditTime: 2021-05-16 15:17:40
55
* @LastEditors: David
66
* @Description: 搜索输入框
77
* @FilePath: /BlogVue/src/components/input/Input.vue
@@ -11,14 +11,38 @@
1111
<template>
1212
<div class="input-theme-default">
1313
<form role="search" class="search-form">
14-
<input type="search" placeholder="搜索摘要/标签" class="search-input" />
15-
<i class="fa fa-search"></i>
14+
<input
15+
type="search"
16+
placeholder="搜索文章名"
17+
v-model="keyword"
18+
class="search-input"
19+
/>
20+
<i class="fa fa-search" @click="searchBlogByKeyword()"></i>
1621
</form>
1722
</div>
1823
</template>
1924

2025
<script>
21-
export default {};
26+
export default {
27+
data() {
28+
return {
29+
keyword: ""
30+
};
31+
},
32+
methods: {
33+
/**
34+
* @description: 根据关键字搜索博客
35+
* @param {*}
36+
* @return {*}
37+
* @Date: 2021-05-16 15:03:00
38+
* @Author: David
39+
*/
40+
41+
searchBlogByKeyword() {
42+
this.$emit("matrix-input-value", this.keyword);
43+
}
44+
}
45+
};
2246
</script>
2347

2448
<style lang="scss" scoped>

BlogVue/src/components/userInfoComponents/Article.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
* @Author: David
33
* @Date: 2020-11-07 10:05:11
4-
* @LastEditTime: 2021-04-26 17:15:28
4+
* @LastEditTime: 2021-05-15 10:01:28
55
* @LastEditors: David
66
* @Description: 用户自己的文章列表界面
77
* @FilePath: /BlogVue/src/components/userInfoComponents/Article.vue

BlogVue/src/page/blogs/Blogs.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="m-container">
3-
<Header></Header>
3+
<Header @matrix-search="searchBlogs"></Header>
44
<!-- <nav role="navigation" class="view-nav" v-show="showBlogList"> -->
55
<!-- <ul class="nav-list left"> -->
66
<!-- <li class="nav-item active" @click="searchParams($event)">推荐</li> -->
@@ -16,7 +16,7 @@
1616
</li> -->
1717
<!-- </ul> -->
1818
<!-- </nav> -->
19-
<blog-list v-show="showBlogList"></blog-list>
19+
<blog-list v-show="showBlogList" ref="blogList"></blog-list>
2020
<router-view v-show="!showBlogList"></router-view>
2121
</div>
2222
</template>
@@ -67,6 +67,19 @@ export default {
6767
}
6868
}
6969
e.target.classList.add("active");
70+
},
71+
72+
/**
73+
* @description: 搜索关键字
74+
* @param {*} keyword
75+
* @return {*}
76+
* @Date: 2021-05-16 15:13:47
77+
* @Author: David
78+
*/
79+
80+
searchBlogs(keyword) {
81+
console.log(12);
82+
this.$refs.blogList.searchByKeyword(keyword);
7083
}
7184
},
7285
mounted() {}

BlogVue3/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local

BlogVue3/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Vue 3 + Typescript + Vite
2+
3+
This template should help get you started developing with Vue 3 and Typescript in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VSCode](https://code.visualstudio.com/) + [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur). Make sure to enable `vetur.experimental.templateInterpolationService` in settings!
8+
9+
### If Using `<script setup>`
10+
11+
[`<script setup>`](https://github.com/vuejs/rfcs/pull/227) is a feature that is currently in RFC stage. To get proper IDE support for the syntax, use [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) instead of Vetur (and disable Vetur).
12+
13+
## Type Support For `.vue` Imports in TS
14+
15+
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can use the following:
16+
17+
### If Using Volar
18+
19+
Run `Volar: Switch TS Plugin on/off` from VSCode command palette.
20+
21+
### If Using Vetur
22+
23+
1. Install and add `@vuedx/typescript-plugin-vue` to the [plugins section](https://www.typescriptlang.org/tsconfig#plugins) in `tsconfig.json`
24+
2. Delete `src/shims-vue.d.ts` as it is no longer needed to provide module info to Typescript
25+
3. Open `src/main.ts` in VSCode
26+
4. Open the VSCode command palette
27+
5. Search and run "Select TypeScript version" -> "Use workspace version"

BlogVue3/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)