mirror of https://github.com/halo-dev/halo
👽 完善页面系统最基础的部分,已经可以正常使用
parent
42ff37b6c2
commit
5e2a3d3025
|
@ -26,6 +26,8 @@ Fast,simple,powerful blog system powered by Java.
|
|||
**Halo** [ˈheɪloʊ],意为光环。当然,你也可以当成拼音读(哈喽)。<br>
|
||||
轻快,简洁,功能强大,使用Java开发的博客系统。
|
||||
|
||||
**Halo交流群:** 162747721
|
||||
|
||||
## Quickstart 快速开始
|
||||
|
||||
```bash
|
||||
|
|
|
@ -76,10 +76,11 @@ public interface PostRepository extends JpaRepository<Post,Long>{
|
|||
/**
|
||||
* 根据路径查询文章
|
||||
*
|
||||
* @param postUrl postUrl
|
||||
* @param postUrl 路径
|
||||
* @param postType post or page
|
||||
* @return Post
|
||||
*/
|
||||
Post findPostByPostUrl(String postUrl);
|
||||
Post findPostByPostUrlAndPostType(String postUrl,String postType);
|
||||
|
||||
/**
|
||||
* 查询之后文章
|
||||
|
|
|
@ -107,10 +107,11 @@ public interface PostService {
|
|||
/**
|
||||
* 根据文章路径查询
|
||||
*
|
||||
* @param postUrl postUrl
|
||||
* @return post
|
||||
* @param postUrl 路径
|
||||
* @param postType post or page
|
||||
* @return Post
|
||||
*/
|
||||
Post findByPostUrl(String postUrl);
|
||||
Post findByPostUrl(String postUrl,String postType);
|
||||
|
||||
/**
|
||||
* 查询前五条数据
|
||||
|
|
|
@ -158,12 +158,13 @@ public class PostServiceImpl implements PostService {
|
|||
/**
|
||||
* 根据文章路径查询
|
||||
*
|
||||
* @param postUrl postUrl
|
||||
* @return post
|
||||
* @param postUrl 路径
|
||||
* @param postType post or page
|
||||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
public Post findByPostUrl(String postUrl) {
|
||||
return postRepository.findPostByPostUrl(postUrl);
|
||||
public Post findByPostUrl(String postUrl,String postType) {
|
||||
return postRepository.findPostByPostUrlAndPostType(postUrl,postType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -203,7 +203,7 @@ public class PageController {
|
|||
/**
|
||||
* 跳转到新建页面
|
||||
*
|
||||
* @return 模板路径
|
||||
* @return 模板路径admin/admin_page_md_editor
|
||||
*/
|
||||
@GetMapping(value = "/new")
|
||||
public String newPage(Model model){
|
||||
|
@ -230,4 +230,35 @@ public class PageController {
|
|||
log.error("未知错误:{0}",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到修改页面
|
||||
*
|
||||
* @param pageId 页面编号
|
||||
* @param model model
|
||||
* @return admin/admin_page_md_editor
|
||||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String editPage(@PathParam("pageId") Long pageId,Model model){
|
||||
Optional<Post> post = postService.findByPostId(pageId);
|
||||
model.addAttribute("post",post.get());
|
||||
return "admin/admin_page_md_editor";
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查该路径是否已经存在
|
||||
*
|
||||
* @param postUrl postUrl
|
||||
* @return true or false
|
||||
*/
|
||||
@GetMapping(value = "/checkUrl")
|
||||
@ResponseBody
|
||||
public boolean checkUrlExists(@PathParam("postUrl") String postUrl){
|
||||
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_PAGE);
|
||||
// TODO 还没写完
|
||||
if(null!=post || StringUtils.equals("archives",postUrl) || StringUtils.equals("galleries",postUrl)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -211,7 +211,7 @@ public class PostController extends BaseController{
|
|||
* @return 重定向到/admin/posts
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String removePost(@PathParam("postId") Long postId){
|
||||
public String removePost(@PathParam("postId") Long postId,@PathParam("postType") String postType){
|
||||
try{
|
||||
Optional<Post> post = postService.findByPostId(postId);
|
||||
postService.removeByPostId(postId);
|
||||
|
@ -219,8 +219,11 @@ public class PostController extends BaseController{
|
|||
}catch (Exception e){
|
||||
log.error("未知错误:{0}",e.getMessage());
|
||||
}
|
||||
if(StringUtils.equals(HaloConst.POST_TYPE_POST,postType)){
|
||||
return "redirect:/admin/posts?status=2";
|
||||
}
|
||||
return "redirect:/admin/page";
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到编辑文章页面
|
||||
|
@ -231,14 +234,10 @@ public class PostController extends BaseController{
|
|||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String editPost(@PathParam("postId") Long postId, Model model){
|
||||
try {
|
||||
Optional<Post> post = postService.findByPostId(postId);
|
||||
model.addAttribute("post",post.get());
|
||||
List<Category> categories = categoryService.findAllCategories();
|
||||
model.addAttribute("categories",categories);
|
||||
}catch (Exception e){
|
||||
log.error("未知错误:{0}",e.getMessage());
|
||||
}
|
||||
return "admin/admin_post_md_editor";
|
||||
}
|
||||
|
||||
|
@ -269,7 +268,7 @@ public class PostController extends BaseController{
|
|||
@GetMapping(value = "/checkUrl")
|
||||
@ResponseBody
|
||||
public boolean checkUrlExists(@PathParam("postUrl") String postUrl){
|
||||
Post post = postService.findByPostUrl(postUrl);
|
||||
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST);
|
||||
if(null!=post){
|
||||
return true;
|
||||
}else{
|
||||
|
|
|
@ -88,7 +88,7 @@ public class ArchivesController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "{postUrl}")
|
||||
public String getPost(@PathVariable String postUrl, Model model){
|
||||
Post post = postService.findByPostUrl(postUrl);
|
||||
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST);
|
||||
//获得当前文章的发布日期
|
||||
Date postDate = post.getPostDate();
|
||||
try {
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.web.controller.front;
|
|||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
import cc.ryanc.halo.model.domain.Link;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.service.GalleryService;
|
||||
import cc.ryanc.halo.service.LinkService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -32,19 +33,6 @@ public class PagesController extends BaseController {
|
|||
@Autowired
|
||||
private LinkService linkService;
|
||||
|
||||
|
||||
/**
|
||||
* 渲染关于页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径/themes/{theme}/about
|
||||
*/
|
||||
@GetMapping(value = "/about")
|
||||
public String about(Model model){
|
||||
model.addAttribute("about","709831589");
|
||||
return this.render("about");
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到图库页面
|
||||
*
|
||||
|
@ -78,9 +66,9 @@ public class PagesController extends BaseController {
|
|||
* @param model model
|
||||
* @return 模板路径/themes/{theme}/post
|
||||
*/
|
||||
@GetMapping(value = "/{postUrl}")
|
||||
public String getPage(@PathVariable String postUrl,Model model){
|
||||
Post post = postService.findByPostUrl(postUrl);
|
||||
@GetMapping(value = "/p/{postUrl}")
|
||||
public String getPage(@PathVariable(value = "postUrl") String postUrl,Model model){
|
||||
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_PAGE);
|
||||
model.addAttribute("post",post);
|
||||
return this.render("post");
|
||||
}
|
||||
|
|
|
@ -84,6 +84,8 @@
|
|||
<tr>
|
||||
<th>标题</th>
|
||||
<th>路径</th>
|
||||
<th>评论</th>
|
||||
<th>日期</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -92,10 +94,13 @@
|
|||
<#list pages as page>
|
||||
<tr>
|
||||
<td>${page.postTitle}</td>
|
||||
<td>${page.postUrl}</td>
|
||||
<td>/p/${page.postUrl}</td>
|
||||
<td>${page.comments?size}</td>
|
||||
<td>${page.postDate?string("yyyy-MM-dd HH:mm")}</td>
|
||||
<td>
|
||||
<a href="/${page.postUrl}" class="btn btn-info btn-xs " target="_blank">预览</a>
|
||||
<a data-pjax="true" href="#" class="btn btn-primary btn-xs ">编辑</a>
|
||||
<a href="/p/${page.postUrl}" class="btn btn-info btn-xs " target="_blank">预览</a>
|
||||
<a href="/admin/page/edit?pageId=${page.postId}" class="btn btn-primary btn-xs ">编辑</a>
|
||||
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/posts/remove?postId=${page.postId}&postType=${page.postType}','确定永久删除?(不可逆)')">永久删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</#list>
|
||||
|
@ -113,6 +118,36 @@
|
|||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- 删除确认弹出层 -->
|
||||
<div class="modal fade" id="removePostModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content message_align">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">提示信息</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p id="message"></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<input type="hidden" id="url"/>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||
<a onclick="removeIt()" class="btn btn-danger" data-dismiss="modal">确定</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function modelShow(url,message) {
|
||||
$('#url').val(url);
|
||||
$('#message').html(message);
|
||||
$('#removePostModal').modal();
|
||||
}
|
||||
function removeIt(){
|
||||
var url=$.trim($("#url").val());
|
||||
window.location.href=url;
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
<#include "module/_footer.ftl">
|
||||
</div>
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<div style="display: block;margin-bottom: 10px;">
|
||||
<span>
|
||||
永久链接:
|
||||
<a href="#">${options.blog_url}/<span id="postUrl"><#if post??>${post.postUrl}</#if></span>/</a>
|
||||
<a href="#">${options.blog_url}/p/<span id="postUrl"><#if post??>${post.postUrl}</#if></span>/</a>
|
||||
<button class="btn btn-default btn-sm " id="btn_input_postUrl">编辑</button>
|
||||
<button class="btn btn-default btn-sm " id="btn_change_postUrl" onclick="UrlOnBlurAuto()" style="display: none;">确定</button>
|
||||
</span>
|
||||
|
@ -152,7 +152,7 @@
|
|||
}
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/admin/posts/checkUrl',
|
||||
url: '/admin/page/checkUrl',
|
||||
async: false,
|
||||
data: {
|
||||
'postUrl': $('#newPostUrl').val()
|
||||
|
|
|
@ -80,9 +80,7 @@
|
|||
</#if>
|
||||
</td>
|
||||
<td>
|
||||
<#if post.getComments()??>
|
||||
${post.getComments()?size}
|
||||
</#if>
|
||||
</td>
|
||||
<td>${post.postDate?if_exists?string("yyyy-MM-dd HH:mm")}</td>
|
||||
<td>
|
||||
|
@ -99,7 +97,7 @@
|
|||
<#break >
|
||||
<#case 2>
|
||||
<a href="/admin/posts/revert?postId=${post.postId}&status=2" class="btn btn-primary btn-xs ">还原</a>
|
||||
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/posts/remove?postId=${post.postId}','确定永久删除?(不可逆)')">永久删除</button>
|
||||
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/posts/remove?postId=${post.postId}&postType=${post.postType}','确定永久删除?(不可逆)')">永久删除</button>
|
||||
<#break >
|
||||
</#switch>
|
||||
</td>
|
||||
|
|
Loading…
Reference in New Issue