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

View File

@ -6,6 +6,8 @@ var admin_manager_url = "mystyle-cloud-admin-manager";
var user_oauth_url = "mystyle-cloud-oauth";
//博客微服务
var blog_url = "mystyle-cloud-blog";
//文件微服务
var file_url = "mystyle-cloud-file";
//验证码
var v_code = gate_way_url + "/" + admin_manager_url + "/verificationCode/generate";
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_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) {

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ public interface UserControllerApi {
public Result reg_save(@RequestParam @RequestBody Map<String, Object> parms);
@ApiOperation("获取当前用户")
public Result current();
public User current();
@ApiOperation("个人资料修改")
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.entity.Article;
import com.zhangmeng.model.entity.Category;
import com.zhangmeng.model.entity.User;
import com.zhangmeng.model.vo.Result;
import com.zhangmeng.model.vo.StatusCode;
import io.swagger.annotations.Api;
@ -105,8 +106,9 @@ public class ArticleController extends BaseController implements ArticleControll
}
if (flag){
article.setViews(0);
article.setUser_id(this.userFeign.getCurrentUser() == null ? 1L:this.userFeign.getCurrentUser().getId());
article.setUsername(this.userFeign.getCurrentUser() == null? "admin":this.userFeign.getCurrentUser().getUsername());
User currentUser = this.userFeign.getCurrentUser();
article.setUser_id(currentUser == null ? 1L : currentUser.getId());
article.setUsername(currentUser == null? "admin":currentUser.getUsername());
this.articleService.save(article);
//存放链接
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.web.bind.annotation.GetMapping;
@FeignClient(SysConstant.mystyle_cloud_blog)
@FeignClient(SysConstant.mystyle_cloud_admin_manager)
public interface UserFeign {
@GetMapping("")
@GetMapping("/user/current")
public User getCurrentUser();
}

View File

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

View File

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