修改文章列表 2021年11月10日15:21:00

master
zhangmeng 2021-11-10 15:21:16 +08:00
parent 0e3f85214e
commit dd31a658bd
11 changed files with 119 additions and 45 deletions

View File

@ -1,6 +1,7 @@
package com.zhangmeng.admin.manager.controller; package com.zhangmeng.admin.manager.controller;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.zhangmeng.admin.manager.utils.UserUtil;
import com.zhangmeng.api.service.admin_manager.UserControllerApi; import com.zhangmeng.api.service.admin_manager.UserControllerApi;
import com.zhangmeng.model.base.baseController.BaseController; import com.zhangmeng.model.base.baseController.BaseController;
import com.zhangmeng.model.base.baseUtil.CommonUtil; import com.zhangmeng.model.base.baseUtil.CommonUtil;
@ -33,6 +34,9 @@ public class UserController extends BaseController implements UserControllerApi
@Autowired @Autowired
private TokenTools tokenTools; private TokenTools tokenTools;
@Autowired
private UserUtil userUtil;
@Override @Override
@PostMapping("/save") @PostMapping("/save")
public Result save(@RequestParam @RequestBody Map<String, Object> parms) { public Result save(@RequestParam @RequestBody Map<String, Object> parms) {
@ -80,9 +84,8 @@ public class UserController extends BaseController implements UserControllerApi
@Override @Override
@GetMapping("/current") @GetMapping("/current")
public Result current(){ public User current(){
Map<String, Object> userInfo = this.tokenTools.getUserInfo(); return this.userUtil.currentUser();
return new Result(true,StatusCode.OK,"查询成功",userInfo);
} }
@Override @Override

View File

@ -6,6 +6,8 @@ var admin_manager_url = "mystyle-cloud-admin-manager";
var user_oauth_url = "mystyle-cloud-oauth"; var user_oauth_url = "mystyle-cloud-oauth";
//博客微服务 //博客微服务
var blog_url = "mystyle-cloud-blog"; var blog_url = "mystyle-cloud-blog";
//文件微服务
var file_url = "mystyle-cloud-file";
//验证码 //验证码
var v_code = gate_way_url + "/" + admin_manager_url + "/verificationCode/generate"; var v_code = gate_way_url + "/" + admin_manager_url + "/verificationCode/generate";
var access_token = localStorage.getItem("access_token"); var access_token = localStorage.getItem("access_token");
@ -61,6 +63,23 @@ var permission_batchRemove_url = gate_way_url + "/" + admin_manager_url + "";
//----------------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------------
//文章列表 //文章列表
var article_list_url = gate_way_url + "/" + blog_url + "/article/list"; var article_list_url = gate_way_url + "/" + blog_url + "/article/list";
//添加文章
var article_add_url = gate_way_url + "/" + admin_manager_url + "/article/add" + access_token_url;
//修改文章
var article_edit_url = gate_way_url + "/" + admin_manager_url + "/article/edit" + access_token_url;
//md 上传
var upload_md_url = gate_way_url + "/" + file_url + "/upload/md" + access_token_url;
//文章保存
var article_save_url = gate_way_url + "/" + blog_url + "/article/save";
//文章删除
var article_delete_url = gate_way_url + "/" + blog_url + "/article/delete";
//文章批量删除
var article_batchRemove_url = gate_way_url + "/" + blog_url + "/article/batchRemove";
//-----------------------------------------------------------------------------------------------------------------
//文件上传
var file_upload_url = gate_way_url + "/" + file_url + "/upload/file";
//页面跳转 //页面跳转
function postToPage(url, token) { function postToPage(url, token) {

View File

@ -3,9 +3,9 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>文章添加</title> <title>文章添加</title>
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/system/component/layui/css/layui.css"/> <link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/layui/css/layui.css"/>
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/system/component/pear/css/pear.css"/> <link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/css/pear.css"/>
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/editor/css/editormd.min.css"> <link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/editor/css/editormd.min.css">
</head> </head>
<body> <body>
<form class="layui-form" action=""> <form class="layui-form" action="">
@ -98,10 +98,11 @@
</div> </div>
</div> </div>
</form> </form>
<script src="${springMacroRequestContext.contextPath}/system/component/layui/layui.js"></script> <script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/layui/layui.js"></script>
<script src="${springMacroRequestContext.contextPath}/js/jquery.min.js"></script> <script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/js/jquery.min.js"></script>
<script src="${springMacroRequestContext.contextPath}/editor/editormd.min.js"></script> <script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/editor/editormd.min.js"></script>
<script src="${springMacroRequestContext.contextPath}/system/component/pear/pear.js"></script> <script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/pear.js"></script>
<script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/admin/js/mystyle-admin.js"></script>
<script> <script>
var editor; var editor;
@ -112,15 +113,15 @@
width: "91.5%", width: "91.5%",
height: 600, height: 600,
syncScrolling: "single", syncScrolling: "single",
path: "/editor/lib/", path: "/" + admin_manager_url + "/editor/lib/",
pluginPath: "/editor/plugins/", pluginPath: "/" + admin_manager_url + "/editor/plugins/",
saveHTMLToTextarea: true, // 保存HTML到Textarea saveHTMLToTextarea: true, // 保存HTML到Textarea
//editorTheme: "pastel-on-dark", //editorTheme: "pastel-on-dark",
//theme: "gray", //theme: "gray",
//previewTheme: "dark", //previewTheme: "dark",
imageUpload: true, imageUpload: true,
imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"], imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL: "/file/md", imageUploadURL: upload_md_url,
markdown: "", markdown: "",
searchReplace: true, searchReplace: true,
htmlDecode: "style,script,iframe|on*", htmlDecode: "style,script,iframe|on*",
@ -142,12 +143,11 @@
let upload = layui.upload; let upload = layui.upload;
form.on('submit(article-save)', function (data) { form.on('submit(article-save)', function (data) {
var obj = data.field; var obj = data.field;
obj['token'] = localStorage.getItem("token"); obj['access_token'] = access_token;
$.ajax({ $.ajax({
url: '/article/save', url: article_save_url,
data: obj, data: obj,
type: 'post', type: 'post',
success: function (result) { success: function (result) {
@ -167,11 +167,11 @@
//拖拽上传 //拖拽上传
upload.render({ upload.render({
elem: '#title_upload_image' elem: '#title_upload_image'
, url: '/upload/file' , url: file_upload_url
, field: 'file' , field: 'file'
, data: { , data: {
type: 'images', type: 'images',
token: localStorage.getItem("token") access_token: access_token
} }
//改成您自己的上传接口 //改成您自己的上传接口
, done: function (res) { , done: function (res) {

View File

@ -3,9 +3,9 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>文章添加</title> <title>文章添加</title>
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/system/component/layui/css/layui.css"/> <link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/layui/css/layui.css"/>
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/system/component/pear/css/pear.css"/> <link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/css/pear.css"/>
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/editor/css/editormd.min.css"> <link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/editor/css/editormd.min.css">
</head> </head>
<body> <body>
<form class="layui-form" action=""> <form class="layui-form" action="">
@ -108,16 +108,17 @@
重置 重置
</button> </button>
<input type="hidden" name="article_upload_image" id="article_upload_image" value="${article.photoPath}"> <input type="hidden" name="article_upload_image" id="article_upload_image" value="${article.photoPath!}">
<input type="hidden" name="file_id" id="file_id" value="${article.photo_id!}"> <input type="hidden" name="file_id" id="file_id" value="${article.photo_id!}">
<input type="hidden" name="articleId" id="articleId" value="${article.id!}"> <input type="hidden" name="articleId" id="articleId" value="${article.id!}">
</div> </div>
</div> </div>
</form> </form>
<script src="${springMacroRequestContext.contextPath}/system/component/layui/layui.js"></script> <script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/layui/layui.js"></script>
<script src="${springMacroRequestContext.contextPath}/js/jquery.min.js"></script> <script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/js/jquery.min.js"></script>
<script src="${springMacroRequestContext.contextPath}/editor/editormd.min.js"></script> <script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/editor/editormd.min.js"></script>
<script src="${springMacroRequestContext.contextPath}/system/component/pear/pear.js"></script> <script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/pear.js"></script>
<script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/admin/js/mystyle-admin.js"></script>
<script> <script>
var editor; var editor;
@ -128,15 +129,15 @@
width: "91.5%", width: "91.5%",
height: 600, height: 600,
syncScrolling: "single", syncScrolling: "single",
path: "/editor/lib/", path: "/" + admin_manager_url + "/editor/lib/",
pluginPath: "/editor/plugins/", pluginPath: "/" + admin_manager_url + "/editor/plugins/",
saveHTMLToTextarea: true, // 保存HTML到Textarea saveHTMLToTextarea: true, // 保存HTML到Textarea
//editorTheme: "pastel-on-dark", //editorTheme: "pastel-on-dark",
//theme: "gray", //theme: "gray",
//previewTheme: "dark", //previewTheme: "dark",
imageUpload: true, imageUpload: true,
imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"], imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL: "/upload/md?token=" + localStorage.getItem("token"), imageUploadURL: upload_md_url,
searchReplace: true, searchReplace: true,
htmlDecode: "style,script,iframe|on*", htmlDecode: "style,script,iframe|on*",
tex: true, // 开启科学公式TeX语言支持默认关闭 tex: true, // 开启科学公式TeX语言支持默认关闭
@ -155,9 +156,9 @@
let upload = layui.upload; let upload = layui.upload;
form.on('submit(article-save)', function (data) { form.on('submit(article-save)', function (data) {
var obj = data.field; var obj = data.field;
obj['token'] = localStorage.getItem("token"); obj['access_token'] = access_token;
$.ajax({ $.ajax({
url: '/article/save', url: article_save_url,
data: obj, data: obj,
type: 'post', type: 'post',
success: function (result) { success: function (result) {
@ -177,11 +178,11 @@
//拖拽上传 //拖拽上传
upload.render({ upload.render({
elem: '#title_upload_image' elem: '#title_upload_image'
, url: '/upload/file' , url: file_upload_url
, field: 'file' , field: 'file'
, data: { , data: {
type: 'images', type: 'images',
token: localStorage.getItem("token") access_token: access_token
} }
//改成您自己的上传接口 //改成您自己的上传接口
, done: function (res) { , done: function (res) {

View File

@ -93,7 +93,7 @@
{{# {{#
} else { } else {
}} }}
<img src="{{d.photoPath}}" width="80px" height="80px"> <img src="{{d.photoPath}}" >
{{# {{#
} }
}} }}
@ -213,6 +213,8 @@
window.add(); window.add();
} else if (obj.event === 'refresh') { } else if (obj.event === 'refresh') {
window.refresh(); window.refresh();
} else if (obj.remove === 'remove') {
window.remove(obj);
} else if (obj.event === 'batchRemove') { } else if (obj.event === 'batchRemove') {
window.batchRemove(obj); window.batchRemove(obj);
} }
@ -235,7 +237,7 @@
title: '添加文章', title: '添加文章',
shade: 0.1, shade: 0.1,
area: [common.isModile()?'100%':'1400px', common.isModile()?'100%':'800px'], area: [common.isModile()?'100%':'1400px', common.isModile()?'100%':'800px'],
content: '/article/add?token=' + token content: article_add_url
}); });
}; };
@ -245,7 +247,7 @@
title: '修改文章', title: '修改文章',
shade: 0.1, shade: 0.1,
area: ['1400px', '800px'], area: ['1400px', '800px'],
content: '/article/edit?articleId='+obj.data.id+'&token=' + token content: article_edit_url + "&articleId="+obj.data.id
}); });
}; };
@ -257,10 +259,10 @@
layer.close(index); layer.close(index);
let loading = layer.load(); let loading = layer.load();
$.ajax({ $.ajax({
url: "/article/delete", url: article_delete_url,
data:{ data:{
articleId:obj.data['id'], articleId:obj.data['id'],
token:token access_token:access_token
}, },
type: 'post', type: 'post',
success: function(result) { success: function(result) {
@ -300,10 +302,10 @@
layer.close(index); layer.close(index);
let loading = layer.load(); let loading = layer.load();
$.ajax({ $.ajax({
url: "/article/batchRemove", url: article_batchRemove_url,
data:{ data:{
ids:checkIds, ids:checkIds,
token:token access_token:access_token
}, },
type: 'post', type: 'post',
success: function(result) { success: function(result) {

View File

@ -28,7 +28,7 @@ public interface UserControllerApi {
public Result reg_save(@RequestParam @RequestBody Map<String, Object> parms); public Result reg_save(@RequestParam @RequestBody Map<String, Object> parms);
@ApiOperation("获取当前用户") @ApiOperation("获取当前用户")
public Result current(); public User current();
@ApiOperation("个人资料修改") @ApiOperation("个人资料修改")
public Result personUpdate(@RequestParam @RequestBody Map<String, Object> map); public Result personUpdate(@RequestParam @RequestBody Map<String, Object> map);

View File

@ -0,0 +1,37 @@
package com.zhangmeng.blog.config.feign;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
/**
*
*/
@Configuration
public class FeignOauth2RequestInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
// 获取的全部请求信息
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null){
HttpServletRequest request = attributes.getRequest();
// 获取所有的请求头信息
Enumeration<String> headerNames = request.getHeaderNames();
if (headerNames != null){
while (headerNames.hasMoreElements()){
// 获取请求头的key
String element = headerNames.nextElement();
// 获取请求头的value
String value = request.getHeader(element);
// 将请求头信息放入到请求头
requestTemplate.header(element,value);
}
}
}
}
}

View File

@ -10,6 +10,7 @@ import com.zhangmeng.model.base.baseUtil.CommonUtil;
import com.zhangmeng.model.dto.query.QueryParams; import com.zhangmeng.model.dto.query.QueryParams;
import com.zhangmeng.model.entity.Article; import com.zhangmeng.model.entity.Article;
import com.zhangmeng.model.entity.Category; import com.zhangmeng.model.entity.Category;
import com.zhangmeng.model.entity.User;
import com.zhangmeng.model.vo.Result; import com.zhangmeng.model.vo.Result;
import com.zhangmeng.model.vo.StatusCode; import com.zhangmeng.model.vo.StatusCode;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -105,8 +106,9 @@ public class ArticleController extends BaseController implements ArticleControll
} }
if (flag){ if (flag){
article.setViews(0); article.setViews(0);
article.setUser_id(this.userFeign.getCurrentUser() == null ? 1L:this.userFeign.getCurrentUser().getId()); User currentUser = this.userFeign.getCurrentUser();
article.setUsername(this.userFeign.getCurrentUser() == null? "admin":this.userFeign.getCurrentUser().getUsername()); article.setUser_id(currentUser == null ? 1L : currentUser.getId());
article.setUsername(currentUser == null? "admin":currentUser.getUsername());
this.articleService.save(article); this.articleService.save(article);
//存放链接 //存放链接
article.setLinks("/blog/details/"+article.getId()); article.setLinks("/blog/details/"+article.getId());

View File

@ -5,9 +5,9 @@ import com.zhangmeng.model.entity.User;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@FeignClient(SysConstant.mystyle_cloud_blog) @FeignClient(SysConstant.mystyle_cloud_admin_manager)
public interface UserFeign { public interface UserFeign {
@GetMapping("") @GetMapping("/user/current")
public User getCurrentUser(); public User getCurrentUser();
} }

View File

@ -31,6 +31,10 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: 127.0.0.1:8848 server-addr: 127.0.0.1:8848
servlet:
multipart:
max-file-size: 4GB
max-request-size: 4GB
mybatis: mybatis:
type-aliases-package: com.zhangmeng.model.entity type-aliases-package: com.zhangmeng.model.entity
configuration: configuration:

View File

@ -52,5 +52,11 @@ spring:
uri: lb://mystyle-cloud-blog uri: lb://mystyle-cloud-blog
predicates: predicates:
- Path=/mystyle-cloud-blog/** - Path=/mystyle-cloud-blog/**
filters:
- StripPrefix=1
- id: mystyle-cloud-file
uri: lb://mystyle-cloud-file
predicates:
- Path=/mystyle-cloud-file/**
filters: filters:
- StripPrefix=1 - StripPrefix=1