Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Springboot Plus
Commits
62046c00
Commit
62046c00
authored
Sep 11, 2019
by
trumansdo
Browse files
正在进行的工作:完成用户角色重构和菜单重构
Signed-off-by:
trumansdo
<
1012243881@qq.com
>
parent
d8a7dc4a
Changes
14
Hide whitespace changes
Inline
Side-by-side
plus-admin/.gitignore
View file @
62046c00
*/target/*
*/target/*
!.gitignore
!.gitignore
*.iml
*.iml
.idea
.idea
\ No newline at end of file
rebel.xml
/logs/*
\ No newline at end of file
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/conf/CustomErrorController.java
View file @
62046c00
package
com.ibeetl.admin.core.conf
;
package
com.ibeetl.admin.core.conf
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.ibeetl.admin.core.util.FormFieldException
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.web.JsonResult
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
org.slf4j.Logger
;
import
org.apache.commons.logging.Log
;
import
org.slf4j.LoggerFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController
;
import
org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController
;
import
org.springframework.boot.web.servlet.error.DefaultErrorAttributes
;
import
org.springframework.boot.web.servlet.error.DefaultErrorAttributes
;
import
org.springframework.boot.web.servlet.error.ErrorController
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.validation.FieldError
;
import
org.springframework.validation.FieldError
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.ModelAndView
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.ibeetl.admin.core.util.FormFieldException
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.web.JsonResult
;
/**
/**
* 自定义的全局错误页面
* 自定义的全局错误页面
*
*
...
@@ -36,7 +32,8 @@ import com.ibeetl.admin.core.web.JsonResult;
...
@@ -36,7 +32,8 @@ import com.ibeetl.admin.core.web.JsonResult;
public
class
CustomErrorController
extends
AbstractErrorController
{
public
class
CustomErrorController
extends
AbstractErrorController
{
private
static
final
String
ERROR_PATH
=
"/error"
;
private
static
final
String
ERROR_PATH
=
"/error"
;
Log
log
=
LogFactory
.
getLog
(
ErrorController
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
CustomErrorController
.
class
);
@Autowired
ObjectMapper
objectMapper
;
@Autowired
ObjectMapper
objectMapper
;
...
@@ -47,6 +44,7 @@ public class CustomErrorController extends AbstractErrorController {
...
@@ -47,6 +44,7 @@ public class CustomErrorController extends AbstractErrorController {
@RequestMapping
(
ERROR_PATH
)
@RequestMapping
(
ERROR_PATH
)
public
ModelAndView
getErrorPath
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
ModelAndView
getErrorPath
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
Map
<
String
,
Object
>
model
=
Collections
.
unmodifiableMap
(
getErrorAttributes
(
request
,
false
));
Map
<
String
,
Object
>
model
=
Collections
.
unmodifiableMap
(
getErrorAttributes
(
request
,
false
));
Throwable
cause
=
getCause
(
request
);
Throwable
cause
=
getCause
(
request
);
int
status
=
(
Integer
)
model
.
get
(
"status"
);
int
status
=
(
Integer
)
model
.
get
(
"status"
);
// 错误信息
// 错误信息
...
@@ -54,12 +52,12 @@ public class CustomErrorController extends AbstractErrorController {
...
@@ -54,12 +52,12 @@ public class CustomErrorController extends AbstractErrorController {
// 友好提示
// 友好提示
String
errorMessage
=
getErrorMessage
(
cause
);
String
errorMessage
=
getErrorMessage
(
cause
);
String
requestPath
=
(
String
)
model
.
get
(
"path"
);
String
requestPath
=
(
String
)
model
.
get
(
"path"
);
/*参数错误*/
List
<
FieldError
>
filedErrors
=
this
.
getFieldError
(
model
,
cause
);
List
<
FieldError
>
filedErrors
=
this
.
getFieldError
(
model
,
cause
);
// 后台打印日志信息方方便查错
// 后台打印日志信息方方便查错
log
.
error
(
status
+
":"
+
message
+
filedErrors
,
cause
);
log
ger
.
error
(
"{} : {} {} {}"
,
status
,
message
,
filedErrors
,
cause
);
log
.
error
(
"requestPath
"
+
":"
+
requestPath
);
log
ger
.
error
(
"requestPath
: {}"
,
requestPath
);
response
.
setStatus
(
status
);
response
.
setStatus
(
status
);
if
(!
isJsonRequest
(
request
))
{
if
(!
isJsonRequest
(
request
))
{
...
@@ -69,9 +67,7 @@ public class CustomErrorController extends AbstractErrorController {
...
@@ -69,9 +67,7 @@ public class CustomErrorController extends AbstractErrorController {
view
.
addObject
(
"filedErrors"
,
filedErrors
);
view
.
addObject
(
"filedErrors"
,
filedErrors
);
view
.
addObject
(
"cause"
,
cause
);
view
.
addObject
(
"cause"
,
cause
);
view
.
addObject
(
"requestPath"
,
requestPath
);
view
.
addObject
(
"requestPath"
,
requestPath
);
return
view
;
return
view
;
}
else
{
}
else
{
if
(
filedErrors
==
null
)
{
if
(
filedErrors
==
null
)
{
if
(
status
==
404
)
{
if
(
status
==
404
)
{
...
@@ -79,9 +75,7 @@ public class CustomErrorController extends AbstractErrorController {
...
@@ -79,9 +75,7 @@ public class CustomErrorController extends AbstractErrorController {
}
else
{
}
else
{
writeJson
(
response
,
JsonResult
.
failMessage
(
getErrorMessage
(
cause
)));
writeJson
(
response
,
JsonResult
.
failMessage
(
getErrorMessage
(
cause
)));
}
}
}
else
{
}
else
{
writeJson
(
response
,
JsonResult
.
fail
(
this
.
wrapFieldErrors
(
filedErrors
)));
writeJson
(
response
,
JsonResult
.
fail
(
this
.
wrapFieldErrors
(
filedErrors
)));
}
}
...
@@ -112,6 +106,12 @@ public class CustomErrorController extends AbstractErrorController {
...
@@ -112,6 +106,12 @@ public class CustomErrorController extends AbstractErrorController {
return
list
;
return
list
;
}
}
/**
* json请求,要么是.json后缀的请求,要么是http请求报文中规定的json请求
*
* @param request
* @return
*/
protected
boolean
isJsonRequest
(
HttpServletRequest
request
)
{
protected
boolean
isJsonRequest
(
HttpServletRequest
request
)
{
String
requestUri
=
(
String
)
request
.
getAttribute
(
"javax.servlet.error.request_uri"
);
String
requestUri
=
(
String
)
request
.
getAttribute
(
"javax.servlet.error.request_uri"
);
if
(
requestUri
!=
null
&&
requestUri
.
endsWith
(
".json"
))
{
if
(
requestUri
!=
null
&&
requestUri
.
endsWith
(
".json"
))
{
...
@@ -144,7 +144,7 @@ public class CustomErrorController extends AbstractErrorController {
...
@@ -144,7 +144,7 @@ public class CustomErrorController extends AbstractErrorController {
Throwable
error
=
(
Throwable
)
request
.
getAttribute
(
"javax.servlet.error.exception"
);
Throwable
error
=
(
Throwable
)
request
.
getAttribute
(
"javax.servlet.error.exception"
);
if
(
error
!=
null
)
{
if
(
error
!=
null
)
{
while
(
error
instanceof
ServletException
&&
error
.
getCause
()
!=
null
)
{
while
(
error
instanceof
ServletException
&&
error
.
getCause
()
!=
null
)
{
error
=
((
ServletException
)
error
)
.
getCause
();
error
=
error
.
getCause
();
}
}
}
}
return
error
;
return
error
;
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/conf/JasonConfig.java
View file @
62046c00
...
@@ -43,19 +43,14 @@ public class JasonConfig {
...
@@ -43,19 +43,14 @@ public class JasonConfig {
public
void
serialize
(
JsonResult
value
,
JsonGenerator
gen
,
SerializerProvider
serializers
)
public
void
serialize
(
JsonResult
value
,
JsonGenerator
gen
,
SerializerProvider
serializers
)
throws
IOException
{
throws
IOException
{
gen
.
writeStartObject
();
gen
.
writeStartObject
();
if
(
value
.
getCode
().
equals
(
"200"
))
{
gen
.
writeObjectField
(
"code"
,
Integer
.
parseInt
(
value
.
getCode
()));
gen
.
writeObjectField
(
"code"
,
0
);
gen
.
writeStringField
(
"msg"
,
value
.
getMessage
());
}
else
{
gen
.
writeObjectField
(
"code"
,
Integer
.
parseInt
(
value
.
getCode
()));
}
gen
.
writeStringField
(
"msg"
,
value
.
getMsg
());
Object
data
=
value
.
getData
();
Object
data
=
value
.
getData
();
if
(
data
instanceof
PageQuery
)
{
if
(
data
instanceof
PageQuery
)
{
PageQuery
query
=
(
PageQuery
)
(
data
);
PageQuery
query
=
(
PageQuery
)
(
data
);
gen
.
writeObjectField
(
"count"
,
query
.
getTotalRow
());
gen
.
writeObjectField
(
"count"
,
query
.
getTotalRow
());
gen
.
writeObjectField
(
"data"
,
query
.
getList
());
gen
.
writeObjectField
(
"data"
,
query
.
getList
());
}
else
{
}
else
{
gen
.
writeObjectField
(
"data"
,
data
);
gen
.
writeObjectField
(
"data"
,
data
);
}
}
gen
.
writeEndObject
();
gen
.
writeEndObject
();
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/conf/MVCConf.java
View file @
62046c00
...
@@ -127,7 +127,7 @@ class SessionInterceptor implements HandlerInterceptor {
...
@@ -127,7 +127,7 @@ class SessionInterceptor implements HandlerInterceptor {
public
boolean
preHandle
(
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
httpRequestLocal
.
set
(
request
);
httpRequestLocal
.
set
(
request
);
if
(
StrUtil
.
containsAny
(
request
.
getRequestURI
(),
"/
user/
login"
,
"/error"
,
"/logout"
))
{
if
(
StrUtil
.
containsAny
(
request
.
getRequestURI
(),
"/login"
,
"/error"
,
"/logout"
))
{
return
true
;
return
true
;
}
}
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/conf/RbacAnnotationConfig.java
View file @
62046c00
...
@@ -24,6 +24,11 @@ import com.ibeetl.admin.core.util.FunctionLocal;
...
@@ -24,6 +24,11 @@ import com.ibeetl.admin.core.util.FunctionLocal;
import
com.ibeetl.admin.core.util.HttpRequestLocal
;
import
com.ibeetl.admin.core.util.HttpRequestLocal
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.util.PlatformException
;
/**
* 在springboot-plus中,有两种权限:功能点(或者说一个个controller方法)和数据权限。
* 菜单实际上也是绑定在了功能点中
* @author 一日看尽长安花
* */
@Aspect
@Aspect
@Component
@Component
public
class
RbacAnnotationConfig
{
public
class
RbacAnnotationConfig
{
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/rbac/AccessType.java
View file @
62046c00
...
@@ -2,7 +2,7 @@ package com.ibeetl.admin.core.rbac;
...
@@ -2,7 +2,7 @@ package com.ibeetl.admin.core.rbac;
/**
/**
* 数据权限算法结果
* 数据权限算法结果
*
*
类似linux的权限设计,owner,group,other
* @author xiandafu
* @author xiandafu
*/
*/
public
enum
AccessType
{
public
enum
AccessType
{
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/CoreUserController.java
View file @
62046c00
package
com.ibeetl.admin.core.web
;
package
com.ibeetl.admin.core.web
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.ibeetl.admin.core.annotation.RequestBodyPlus
;
import
com.ibeetl.admin.core.util.JoseJwtUtil
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
...
@@ -24,6 +31,7 @@ import com.ibeetl.admin.core.util.HttpRequestLocal;
...
@@ -24,6 +31,7 @@ import com.ibeetl.admin.core.util.HttpRequestLocal;
import
com.ibeetl.admin.core.web.dto.FunctionNodeView
;
import
com.ibeetl.admin.core.web.dto.FunctionNodeView
;
import
com.ibeetl.admin.core.web.dto.MenuNodeView
;
import
com.ibeetl.admin.core.web.dto.MenuNodeView
;
import
com.ibeetl.admin.core.web.dto.SystemMenuView
;
import
com.ibeetl.admin.core.web.dto.SystemMenuView
;
import
sun.swing.StringUIClientPropertyKey
;
@Controller
@Controller
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
@@ -78,7 +86,6 @@ public class CoreUserController {
...
@@ -78,7 +86,6 @@ public class CoreUserController {
/**
/**
* 切换部门
* 切换部门
*
*
* @param code
* @param orgId
* @param orgId
* @return
* @return
*/
*/
...
@@ -250,4 +257,45 @@ public class CoreUserController {
...
@@ -250,4 +257,45 @@ public class CoreUserController {
}
}
return
views
;
return
views
;
}
}
@GetMapping
(
"/user/info"
)
@ResponseBody
public
JsonResult
info
(
@RequestBodyPlus
(
"username"
)
String
username
,
@RequestBodyPlus
(
"password"
)
String
password
)
{
Map
<
String
,
Object
>
resultMap
=
MapUtil
.<
String
,
Object
>
builder
()
.
build
();
return
JsonResult
.
success
(
resultMap
);
}
@PostMapping
(
"/user/login"
)
@ResponseBody
public
JsonResult
loginEle
(
@RequestBodyPlus
(
"username"
)
String
username
,
@RequestBodyPlus
(
"password"
)
String
password
)
{
UserLoginInfo
info
=
userService
.
login
(
username
,
password
);
if
(
info
==
null
)
{
throw
new
PlatformException
(
"用户名密码错误"
);
}
CoreUser
user
=
info
.
getUser
();
CoreOrg
currentOrg
=
info
.
getOrgs
().
stream
().
findFirst
().
orElse
(
null
);
for
(
CoreOrg
org
:
info
.
getOrgs
())
{
if
(
org
.
getId
().
equals
(
user
.
getOrgId
()))
{
currentOrg
=
org
;
break
;
}
}
info
.
setCurrentOrg
(
currentOrg
);
// 记录登录信息到session
this
.
platformService
.
setLoginUser
(
info
.
getUser
(),
info
.
getCurrentOrg
(),
info
.
getOrgs
());
Map
<
String
,
Object
>
resultMap
=
MapUtil
.<
String
,
Object
>
builder
()
.
put
(
"token"
,
JoseJwtUtil
.
generateJwtJson
(
String
.
valueOf
(
user
.
getId
())))
.
build
();
return
JsonResult
.
success
(
resultMap
);
}
}
}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/IndexController.java
View file @
62046c00
...
@@ -37,7 +37,7 @@ public class IndexController {
...
@@ -37,7 +37,7 @@ public class IndexController {
return
view
;
return
view
;
}
}
/*
@PostMapping("/login.do")
@PostMapping
(
"/login.do"
)
public
ModelAndView
login
(
String
code
,
String
password
)
{
public
ModelAndView
login
(
String
code
,
String
password
)
{
UserLoginInfo
info
=
userService
.
login
(
code
,
password
);
UserLoginInfo
info
=
userService
.
login
(
code
,
password
);
if
(
info
==
null
)
{
if
(
info
==
null
)
{
...
@@ -57,31 +57,6 @@ public class IndexController {
...
@@ -57,31 +57,6 @@ public class IndexController {
this
.
platformService
.
setLoginUser
(
info
.
getUser
(),
info
.
getCurrentOrg
(),
info
.
getOrgs
());
this
.
platformService
.
setLoginUser
(
info
.
getUser
(),
info
.
getCurrentOrg
(),
info
.
getOrgs
());
ModelAndView
view
=
new
ModelAndView
(
"redirect:/index.do"
);
ModelAndView
view
=
new
ModelAndView
(
"redirect:/index.do"
);
return
view
;
return
view
;
}*/
@PostMapping
(
"/user/login"
)
@ResponseBody
public
Object
login
(
@RequestBodyPlus
(
"username"
)
String
username
,
@RequestBodyPlus
(
"password"
)
String
password
)
{
UserLoginInfo
info
=
userService
.
login
(
username
,
password
);
if
(
info
==
null
)
{
throw
new
PlatformException
(
"用户名密码错误"
);
}
CoreUser
user
=
info
.
getUser
();
CoreOrg
currentOrg
=
info
.
getOrgs
().
get
(
0
);
for
(
CoreOrg
org
:
info
.
getOrgs
())
{
if
(
org
.
getId
().
equals
(
user
.
getOrgId
()))
{
currentOrg
=
org
;
break
;
}
}
info
.
setCurrentOrg
(
currentOrg
);
// 记录登录信息到session
this
.
platformService
.
setLoginUser
(
info
.
getUser
(),
info
.
getCurrentOrg
(),
info
.
getOrgs
());
Map
<
Object
,
Object
>
resultMap
=
MapUtil
.
builder
()
.
put
(
"token"
,
JoseJwtUtil
.
generateJwtJson
(
String
.
valueOf
(
user
.
getId
()))).
build
();
return
JsonResult
.
success
(
resultMap
);
}
}
@RequestMapping
(
"/index.do"
)
@RequestMapping
(
"/index.do"
)
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/JsonResult.java
View file @
62046c00
package
com.ibeetl.admin.core.web
;
package
com.ibeetl.admin.core.web
;
import
cn.hutool.core.map.MapUtil
;
import
com.ibeetl.admin.core.util.JoseJwtUtil
;
import
java.util.Map
;
/**
/**
* 描述: json格式数据返回对象,使用CustomJsonResultSerializer 来序列化
* 描述: json格式数据返回对象,使用CustomJsonResultSerializer 来序列化
*
*
...
@@ -8,7 +12,7 @@ package com.ibeetl.admin.core.web;
...
@@ -8,7 +12,7 @@ package com.ibeetl.admin.core.web;
public
class
JsonResult
<
T
>
{
public
class
JsonResult
<
T
>
{
private
String
code
;
private
String
code
;
private
String
m
sg
;
private
String
m
essage
;
private
T
data
;
private
T
data
;
public
String
getCode
()
{
public
String
getCode
()
{
...
@@ -19,12 +23,12 @@ public class JsonResult<T> {
...
@@ -19,12 +23,12 @@ public class JsonResult<T> {
this
.
code
=
code
;
this
.
code
=
code
;
}
}
public
String
getM
sg
()
{
public
String
getM
essage
()
{
return
m
sg
;
return
m
essage
;
}
}
public
void
setM
sg
(
String
m
sg
)
{
public
void
setM
essage
(
String
m
essage
)
{
this
.
m
sg
=
msg
;
this
.
m
essage
=
message
;
}
}
public
T
getData
()
{
public
T
getData
()
{
...
@@ -37,13 +41,13 @@ public class JsonResult<T> {
...
@@ -37,13 +41,13 @@ public class JsonResult<T> {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"code="
+
code
+
" message="
+
m
sg
+
" data="
+
data
;
return
"code="
+
code
+
" message="
+
m
essage
+
" data="
+
data
;
}
}
public
static
<
T
>
JsonResult
<
T
>
fail
()
{
public
static
<
T
>
JsonResult
<
T
>
fail
()
{
JsonResult
<
T
>
ret
=
new
JsonResult
<
T
>();
JsonResult
<
T
>
ret
=
new
JsonResult
<
T
>();
ret
.
setCode
(
JsonReturnCode
.
FAIL
.
getCode
());
ret
.
setCode
(
JsonReturnCode
.
FAIL
.
getCode
());
ret
.
setM
sg
(
JsonReturnCode
.
FAIL
.
getDesc
());
ret
.
setM
essage
(
JsonReturnCode
.
FAIL
.
getDesc
());
return
ret
;
return
ret
;
}
}
...
@@ -55,20 +59,20 @@ public class JsonResult<T> {
...
@@ -55,20 +59,20 @@ public class JsonResult<T> {
public
static
<
T
>
JsonResult
<
T
>
failMessage
(
String
msg
)
{
public
static
<
T
>
JsonResult
<
T
>
failMessage
(
String
msg
)
{
JsonResult
<
T
>
ret
=
JsonResult
.
fail
();
JsonResult
<
T
>
ret
=
JsonResult
.
fail
();
ret
.
setM
sg
(
msg
);
ret
.
setM
essage
(
msg
);
return
ret
;
return
ret
;
}
}
public
static
<
T
>
JsonResult
<
T
>
successMessage
(
String
msg
)
{
public
static
<
T
>
JsonResult
<
T
>
successMessage
(
String
msg
)
{
JsonResult
<
T
>
ret
=
JsonResult
.
success
();
JsonResult
<
T
>
ret
=
JsonResult
.
success
();
ret
.
setM
sg
(
msg
);
ret
.
setM
essage
(
msg
);
return
ret
;
return
ret
;
}
}
public
static
<
T
>
JsonResult
<
T
>
success
()
{
public
static
<
T
>
JsonResult
<
T
>
success
()
{
JsonResult
<
T
>
ret
=
new
JsonResult
<
T
>();
JsonResult
<
T
>
ret
=
new
JsonResult
<
T
>();
ret
.
setCode
(
JsonReturnCode
.
SUCCESS
.
getCode
());
ret
.
setCode
(
JsonReturnCode
.
SUCCESS
.
getCode
());
ret
.
setM
sg
(
JsonReturnCode
.
SUCCESS
.
getDesc
());
ret
.
setM
essage
(
JsonReturnCode
.
SUCCESS
.
getDesc
());
return
ret
;
return
ret
;
}
}
...
@@ -81,7 +85,7 @@ public class JsonResult<T> {
...
@@ -81,7 +85,7 @@ public class JsonResult<T> {
public
static
<
T
>
JsonResult
<
T
>
http404
(
T
data
)
{
public
static
<
T
>
JsonResult
<
T
>
http404
(
T
data
)
{
JsonResult
<
T
>
ret
=
new
JsonResult
<
T
>();
JsonResult
<
T
>
ret
=
new
JsonResult
<
T
>();
ret
.
setCode
(
JsonReturnCode
.
NOT_FOUND
.
getCode
());
ret
.
setCode
(
JsonReturnCode
.
NOT_FOUND
.
getCode
());
ret
.
setM
sg
(
JsonReturnCode
.
NOT_FOUND
.
getDesc
());
ret
.
setM
essage
(
JsonReturnCode
.
NOT_FOUND
.
getDesc
());
ret
.
setData
(
data
);
ret
.
setData
(
data
);
return
ret
;
return
ret
;
}
}
...
@@ -89,8 +93,9 @@ public class JsonResult<T> {
...
@@ -89,8 +93,9 @@ public class JsonResult<T> {
public
static
<
T
>
JsonResult
<
T
>
http403
(
T
data
)
{
public
static
<
T
>
JsonResult
<
T
>
http403
(
T
data
)
{
JsonResult
<
T
>
ret
=
new
JsonResult
<
T
>();
JsonResult
<
T
>
ret
=
new
JsonResult
<
T
>();
ret
.
setCode
(
JsonReturnCode
.
ACCESS_ERROR
.
getCode
());
ret
.
setCode
(
JsonReturnCode
.
ACCESS_ERROR
.
getCode
());
ret
.
setM
sg
(
JsonReturnCode
.
ACCESS_ERROR
.
getDesc
());
ret
.
setM
essage
(
JsonReturnCode
.
ACCESS_ERROR
.
getDesc
());
ret
.
setData
(
data
);
ret
.
setData
(
data
);
return
ret
;
return
ret
;
}
}
}
}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/web/JsonReturnCode.java
View file @
62046c00
...
@@ -16,7 +16,10 @@ public enum JsonReturnCode {
...
@@ -16,7 +16,10 @@ public enum JsonReturnCode {
SUCCESS
(
"200"
,
"成功"
),
SUCCESS
(
"200"
,
"成功"
),
FAIL
(
"500"
,
"内部失败"
),
FAIL
(
"500"
,
"内部失败"
),
ACCESS_ERROR
(
"403"
,
"禁止访问"
),
ACCESS_ERROR
(
"403"
,
"禁止访问"
),
NOT_FOUND
(
"404"
,
"页面未发现"
);
NOT_FOUND
(
"404"
,
"页面未发现"
),
TOKEN_EXPIRED
(
"50014"
,
"令牌过期"
),
INVALID_TOEKN
(
"50008"
,
"非法令牌"
);
private
String
code
;
private
String
code
;
private
String
desc
;
private
String
desc
;
...
...
ve-admin/admin-web/src/api/user.js
View file @
62046c00
...
@@ -12,7 +12,7 @@ export function getInfo(token) {
...
@@ -12,7 +12,7 @@ export function getInfo(token) {
return
request
({
return
request
({
url
:
'
/user/info
'
,
url
:
'
/user/info
'
,
method
:
'
get
'
,
method
:
'
get
'
,
params
:
{
token
}
//
params: { token }
})
})
}
}
...
...
ve-admin/admin-web/src/store/modules/user.js
View file @
62046c00
...
@@ -49,6 +49,7 @@ const actions = {
...
@@ -49,6 +49,7 @@ const actions = {
// get user info
// get user info
getInfo
({
commit
,
state
})
{
getInfo
({
commit
,
state
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
getInfo
(
state
.
token
)
getInfo
(
state
.
token
)
.
then
(
response
=>
{
.
then
(
response
=>
{
const
{
data
}
=
response
const
{
data
}
=
response
...
...
ve-admin/admin-web/src/utils/auth.js
View file @
62046c00
import
Cookies
from
'
js-cookie
'
import
Cookies
from
'
js-cookie
'
const
TokenKey
=
'
Admin
-Token
'
const
TokenKey
=
'
JWT
-Token
'
export
function
getToken
()
{
export
function
getToken
()
{
return
Cookies
.
get
(
TokenKey
)
return
Cookies
.
get
(
TokenKey
)
...
...
ve-admin/admin-web/src/utils/request.js
View file @
62046c00
...
@@ -17,9 +17,9 @@ service.interceptors.request.use(
...
@@ -17,9 +17,9 @@ service.interceptors.request.use(
if
(
store
.
getters
.
token
)
{
if
(
store
.
getters
.
token
)
{
// let each request carry token
// let each request carry token
// ['
X-Token'] is a custom headers key
// ['
Authorization'] see to MDN explain about "HTTP Authorization"
// please modify it according to the actual situation
// please modify it according to the actual situation
config
.
headers
[
'
X-Toke
n
'
]
=
getToken
()
config
.
headers
[
'
Authorizatio
n
'
]
=
getToken
()
}
}
return
config
return
config
},
},
...
@@ -46,7 +46,7 @@ service.interceptors.response.use(
...
@@ -46,7 +46,7 @@ service.interceptors.response.use(
const
res
=
response
.
data
const
res
=
response
.
data
// if the custom code is not 20000, it is judged as an error.
// if the custom code is not 20000, it is judged as an error.
if
(
res
.
code
!==
200
00
)
{
if
(
res
.
code
!==
200
)
{
Message
({
Message
({
message
:
res
.
message
||
'
Error
'
,
message
:
res
.
message
||
'
Error
'
,
type
:
'
error
'
,
type
:
'
error
'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment