Skip to content

Commit

Permalink
不共用文章列表
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyueyi committed Nov 26, 2022
1 parent f8a2bf9 commit a70909f
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 99 deletions.
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,39 @@ mvn clean install -DskipTests=true -Pprod
**配置文件说明**

- resources
- application.yml: 主配置文件入口
- application-config.yml: 全局的站点信息配置文件
- logback-spring.xml: 日志打印相关配置文件
- schema-all.sql: 项目中所有表结构定义sql文件
- init-data.sql: 初始化数据sql文件
- schema.sql, test-data.sql: 开发阶段的sql文件,后续会删除,不用关注
- application.yml: 主配置文件入口
- application-config.yml: 全局的站点信息配置文件
- logback-spring.xml: 日志打印相关配置文件
- schema-all.sql: 项目中所有表结构定义sql文件
- init-data.sql: 初始化数据sql文件
- schema.sql, test-data.sql: 开发阶段的sql文件,后续会删除,不用关注
- resources-env
- xxx/application-dal.yml: 定义数据库相关的配置信息
- xxx/application-image.yml: 定义上传图片的相关配置信息
- xxx/application-web.yml: 定义web相关的配置信息
- xxx/application-dal.yml: 定义数据库相关的配置信息
- xxx/application-image.yml: 定义上传图片的相关配置信息
- xxx/application-web.yml: 定义web相关的配置信息

### 前端工程结构说明

前端页面都放在 ui 模块中

- resources/static: 静态资源文件,如css/js/image,放在这里
- resources/templates: html相关页面
- views: 业务相关的页面
- 定义:
- 页面/index.html: 这个index.html表示的是这个业务对应的主页面
- 页面/模块/xxx.html: 若主页面又可以拆分为多个模块页面进行组合,则在这个页面下,新建一个模块目录,下面放对应的html文件
- article-category-list: 对应 分类文章列表页面,
- article-detail: 对应文章详情页
- side-float-action-bar: 文章详情,左边的点赞/收藏/评论浮窗
- side-recommend-bar: 文章详情右边侧边栏的sidebar
- article-edit: 对应文章发布页
- article-search-list: 对应文章搜索页
- article-tag-list: 对应标签文章列表
- column-detail:对应专栏阅读详情页
- column-home: 对应专栏首页
- home: 全站主页
- login: 登录页面
- notice: 通知页面
- user: 用户个人页
- error: 错误页面
- components: 公用的前端页面组件
2 changes: 0 additions & 2 deletions forum-ui/src/main/resources/static/js/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ $('#mockLogin').click(function () {
console.log("data", data);
if (!data) {
toastr.error(data.message);
} else {
toastr.info("登录成功!");
}
},
error: function (data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<script src="/js/biz/toolaction.js"></script>
<script src="/js/biz/login.js"></script>
<script src="/js/simplemde.min.js"></script>
<script src="/js/mock.js" th:if="${!#strings.equals(global.env, 'prod')}"></script>
<th:block th:replace="${links}" />
<th:block th:replace="${scripts}" />
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ <h5 class="modal-title" id="loginModalDropLabel">二维码登录</h5>
</div>
</div>
</div>

<script src="/js/mock.js" th:if="${!#strings.equals(global.env, 'prod')}"></script>
<script th:inline="javascript">
$(".nav-article").click(() => {
if ([[${global.isLogin}]]) {
Expand Down Expand Up @@ -252,27 +252,6 @@ <h5 class="modal-title" id="loginModalDropLabel">二维码登录</h5>
}
})
})


$('#mockLogin').click(function () {
console.log("mock loign 登录!!!");
const code = this.dataset.verifyCode;
$.ajax({
method: 'POST',
url: "/wx/callback",
contentType: 'application/xml',
data: "<xml><URL><![CDATA[https://hhui.top]]></URL><ToUserName><![CDATA[一灰灰blog]]></ToUserName><FromUserName><![CDATA[demoUser1234]]></FromUserName><CreateTime>1655700579</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + code + "]]></Content><MsgId>11111111</MsgId></xml>",
success: function (data) {
console.log("data", data);
if (!data) {
toastr.error(data.message);
}
},
error: function (data) {
toastr.error(data);
}
});
})
</script>
</div>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<!-- 文章列表 -->
<div class="category-list">
<div id="articleList">
<div th:replace="components/article/list">文章列表</div>
<div th:replace="views/article-category-list/article/list">文章列表</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- 文章列表 -->
<div th:each="article : ${vo.articles.list}">
<div th:replace="components/article/article-card :: article_card(${article})">正文</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- 文章列表 -->
<div th:each="article : ${vo.articles.list}">
<div th:replace="components/article/article-card :: article_card(${article})">正文</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,45 @@
height: calc(100vh - 60px);
overflow-y: auto;
}

.search-wrap {
width: 1200px;
margin: 0 auto;
padding: 20px;
}

.search-list {
padding: 20px;
background-color: #fff;
border-radius: 8px;
}
</style>
<body id="body">
<!-- 导航栏 -->
<div th:replace="components/layout/navbar :: navbar"></div>
<!-- 导航栏 -->
<div th:replace="components/layout/navbar :: navbar"></div>

<!-- 正文内容 -->
<div class="search-wrap-out">
<div class="search-wrap">
<!-- 文章列表 -->
<div class="search-list" th:each="article : ${vo.articles.list}">
<div th:replace="components/article/article-card :: article_card(${article})">
正文
</div>
</div>

<div th:if="${#lists.isEmpty(vo.articles.list)}">
<a>没有查询到任何记录。</a>
</div>
<!-- 正文内容 -->
<div class="search-wrap-out">
<div class="search-wrap">
<!-- 文章列表 -->
<div class="search-list" id="articleList">
<div th:replace="views/article-search-list/article/list">文章列表</div>
</div>
</div>
</div>

<div th:if="${#lists.isEmpty(vo.articles.list)}">
<a>没有查询到任何记录。</a>
</div>
</div>
</div>

<!-- 底部信息 -->
<!-- <div th:replace="layout/footer :: footer"></div> -->
<script src="/js/biz/loadMore.js"></script>
<script th:inline="javascript">
const archiveId = [[${ vo.archiveId }]]
const params = {
"page": 2
}
loadMore(".search-wrap-out", '/article/api/list/tag/' + archiveId, params, "articleList");
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- 文章列表 -->
<div th:each="article : ${vo.articles.list}">
<div th:replace="components/article/article-card :: article_card(${article})">正文</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<div th:replace="components/layout/header :: head(~{::title}, ~{}, ~{})">
<div th:replace="components/layout/header :: head(~{::title}, ~{}, ~{})">
<title th:text="${global.siteInfo.websiteName}">技术派</title>
</div>
<style>
</div>
<style>
.tag-wrap-out {
height: calc(100vh - 60px);
overflow-y: auto;
height: calc(100vh - 60px);
overflow-y: auto;
}

.tag-wrap {
width: 1200px;
margin: 0 auto;
padding: 20px;
width: 1200px;
margin: 0 auto;
padding: 20px;
}

.tag-list {
padding: 20px;
background-color: #fff;
border-radius: 8px;
padding: 20px;
background-color: #fff;
border-radius: 8px;
}
</style>
</style>

<body id="body">
<!-- 导航栏 -->
<div th:replace="components/layout/navbar :: navbar"></div>
<body id="body">
<!-- 导航栏 -->
<div th:replace="components/layout/navbar :: navbar"></div>

<!-- 正文内容 -->
<div class="tag-wrap-out">
<div class="tag-wrap">
<!-- 正文内容 -->
<div class="tag-wrap-out">
<div class="tag-wrap">
<!-- 文章列表 -->
<div class="tag-list">
<div id="articleList">
<div th:replace="components/article/list">文章列表</div>
</div>
<div id="articleList">
<div th:replace="views/article-tag-list/article/list">文章列表</div>
</div>
</div>
</div>
<!-- 底部信息 -->
<!-- <div th:replace="layout/footer :: footer"></div> -->
</div>
<script src="/js/biz/loadMore.js"></script>
<script th:inline="javascript">
const archiveId = [[${ vo.archiveId }]]
const params = {
"page": 2
}
loadMore(".tag-wrap-out", '/article/api/list/tag/' + archiveId, params, "articleList");
</script>
</body>
<!-- 底部信息 -->
<!-- <div th:replace="layout/footer :: footer"></div> -->
</div>
<script src="/js/biz/loadMore.js"></script>
<script th:inline="javascript">
const archiveId = [[${ vo.archiveId }]]
const params = {
"page": 2
}
loadMore(".tag-wrap-out", '/article/api/list/tag/' + archiveId, params, "articleList");
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@
import com.github.liueyueyi.forum.api.model.vo.PageParam;
import com.github.liueyueyi.forum.api.model.vo.ResVo;
import com.github.liueyueyi.forum.api.model.vo.article.dto.ArticleDTO;
import com.github.liueyueyi.forum.api.model.vo.constants.StatusEnum;
import com.github.liuyueyi.forum.service.article.service.ArticleReadService;
import com.github.liuyueyi.forum.service.article.service.CategoryService;
import com.github.liuyueyi.forum.web.component.TemplateEngineHelper;
import com.github.liuyueyi.forum.web.global.BaseViewController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.Optional;

/**
* 文章列表
*
Expand All @@ -44,7 +37,7 @@ public ResVo<NextPageHtmlVo> categoryList(@PathVariable("category") Long categor
@RequestParam(name = "size", required = false) Long size) {
PageParam pageParam = buildPageParam(page, size);
PageListVo<ArticleDTO> list = articleService.queryArticlesByCategory(categoryId, pageParam);
String html = templateEngineHelper.renderToVo("components/article/list", "articles", list);
String html = templateEngineHelper.renderToVo("views/article-category-list/article/list", "articles", list);
return ResVo.ok(new NextPageHtmlVo(html, list.getHasMore()));
}

Expand All @@ -62,7 +55,7 @@ public ResVo<NextPageHtmlVo> tagList(@PathVariable("tag") Long tagId,
@RequestParam(name = "size", required = false) Long size) {
PageParam pageParam = buildPageParam(page, size);
PageListVo<ArticleDTO> list = articleService.queryArticlesByTag(tagId, pageParam);
String html = templateEngineHelper.renderToVo("components/article/list", "articles", list);
String html = templateEngineHelper.renderToVo("views/article-tag-list/article/list", "articles", list);
return ResVo.ok(new NextPageHtmlVo(html, list.getHasMore()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.github.liuyueyi.forum.service.user.repository.entity.UserFootDO;
import com.github.liuyueyi.forum.service.user.service.UserFootService;
import com.github.liuyueyi.forum.web.component.TemplateEngineHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -73,7 +72,7 @@ public ResVo<NextPageHtmlVo> recommend(@RequestParam(value = "articleId") Long a
size = Optional.ofNullable(size).orElse(PageParam.DEFAULT_PAGE_SIZE);
size = Math.min(size, PageParam.DEFAULT_PAGE_SIZE);
PageListVo<ArticleDTO> articles = articleRecommendService.relatedRecommend(articleId, PageParam.newPageInstance(page, size));
String html = templateEngineHelper.renderToVo("components/article/list", "articles", articles);
String html = templateEngineHelper.renderToVo("views/article-detail/article/list", "articles", articles);
return ResVo.ok(new NextPageHtmlVo(html, articles.getHasMore()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.github.liuyueyi.forum.web.front.search.rest;

import com.github.liueyueyi.forum.api.model.vo.NextPageHtmlVo;
import com.github.liueyueyi.forum.api.model.vo.PageListVo;
import com.github.liueyueyi.forum.api.model.vo.PageParam;
import com.github.liueyueyi.forum.api.model.vo.ResVo;
import com.github.liueyueyi.forum.api.model.vo.article.dto.ArticleDTO;
import com.github.liueyueyi.forum.api.model.vo.article.dto.SimpleArticleDTO;
import com.github.liuyueyi.forum.service.article.service.ArticleReadService;
import com.github.liuyueyi.forum.web.component.TemplateEngineHelper;
import com.github.liuyueyi.forum.web.front.search.vo.SearchHintsVo;
import com.github.liuyueyi.forum.web.global.BaseViewController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -20,11 +26,14 @@
*/
@RequestMapping(path = "search/api")
@RestController
public class SearchRestController {
public class SearchRestController extends BaseViewController {

@Autowired
private ArticleReadService articleReadService;

@Autowired
private TemplateEngineHelper templateEngineHelper;

/**
* 根据关键词给出搜索下拉框
*
Expand All @@ -38,4 +47,21 @@ public ResVo<SearchHintsVo> recommend(@RequestParam(name = "key", required = fal
vo.setItems(list);
return ResVo.ok(vo);
}


/**
* 分类下的文章列表
*
* @param key
* @return
*/
@GetMapping(path = "list")
public ResVo<NextPageHtmlVo> searchList(@RequestParam(name = "key", required = false) String key,
@RequestParam(name = "page") Long page,
@RequestParam(name = "size", required = false) Long size) {
PageParam pageParam = buildPageParam(page, size);
PageListVo<ArticleDTO> list = articleReadService.queryArticlesBySearchKey(key, pageParam);
String html = templateEngineHelper.renderToVo("views/article-search-list/article/list", "articles", list);
return ResVo.ok(new NextPageHtmlVo(html, list.getHasMore()));
}
}

0 comments on commit a70909f

Please sign in to comment.