登录保存stationCode参数
master
xins 8 months ago
parent 04ca4eb29c
commit 7de8f4c03c

@ -63,6 +63,11 @@ public class LoginUser implements Serializable
*/ */
private Long stationId; private Long stationId;
/**
*
*/
private String stationCode;
public String getToken() public String getToken()
{ {
return token; return token;
@ -160,4 +165,12 @@ public class LoginUser implements Serializable
public void setStationId(Long stationId) { public void setStationId(Long stationId) {
this.stationId = stationId; this.stationId = stationId;
} }
public String getStationCode() {
return stationCode;
}
public void setStationCode(String stationCode) {
this.stationCode = stationCode;
}
} }

@ -44,6 +44,7 @@ public class TokenController
// 用户登录 // 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
userInfo.setStationId(form.getStationId()); userInfo.setStationId(form.getStationId());
userInfo.setStationCode(form.getStationCode());
// 获取登录token // 获取登录token
return R.ok(tokenService.createToken(userInfo)); return R.ok(tokenService.createToken(userInfo));
} }

@ -23,6 +23,10 @@ public class LoginBody
*/ */
private Long stationId; private Long stationId;
/**
*
*/
private String stationCode;
public String getUsername() public String getUsername()
{ {
@ -51,4 +55,12 @@ public class LoginBody
public void setStationId(Long stationId) { public void setStationId(Long stationId) {
this.stationId = stationId; this.stationId = stationId;
} }
public String getStationCode() {
return stationCode;
}
public void setStationCode(String stationCode) {
this.stationCode = stationCode;
}
} }

@ -52,4 +52,9 @@ public class SecurityConstants
* ID * ID
*/ */
public static final String DETAILS_STATION_ID = "station_id"; public static final String DETAILS_STATION_ID = "station_id";
/**
*
*/
public static final String DETAILS_STATION_CODE = "station_code";
} }

@ -107,4 +107,14 @@ public class SecurityContextHolder
set(SecurityConstants.DETAILS_STATION_ID, stationId); set(SecurityConstants.DETAILS_STATION_ID, stationId);
} }
public static String getStationCode()
{
return get(SecurityConstants.DETAILS_STATION_CODE);
}
public static void setStationCode(String stationCode)
{
set(SecurityConstants.DETAILS_STATION_CODE, stationCode);
}
} }

@ -133,4 +133,14 @@ public class JwtUtils
return getValue(claims, SecurityConstants.DETAILS_STATION_ID); return getValue(claims, SecurityConstants.DETAILS_STATION_ID);
} }
/**
*
*
* @param claims
* @return
*/
public static String getStationCode(Claims claims)
{
return getValue(claims, SecurityConstants.DETAILS_STATION_CODE);
}
} }

@ -32,6 +32,7 @@ public class HeaderInterceptor implements AsyncHandlerInterceptor
SecurityContextHolder.setUserName(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USERNAME)); SecurityContextHolder.setUserName(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USERNAME));
SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY)); SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY));
SecurityContextHolder.setStationId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_STATION_ID)); SecurityContextHolder.setStationId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_STATION_ID));
SecurityContextHolder.setStationCode(ServletUtils.getHeader(request, SecurityConstants.DETAILS_STATION_CODE));
String token = SecurityUtils.getToken(); String token = SecurityUtils.getToken();
if (StringUtils.isNotEmpty(token)) if (StringUtils.isNotEmpty(token))

@ -62,6 +62,7 @@ public class TokenService
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId); claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName); claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
claimsMap.put(SecurityConstants.DETAILS_STATION_ID, loginUser.getStationId()); claimsMap.put(SecurityConstants.DETAILS_STATION_ID, loginUser.getStationId());
claimsMap.put(SecurityConstants.DETAILS_STATION_CODE, loginUser.getStationCode());
// 接口返回信息 // 接口返回信息
Map<String, Object> rspMap = new HashMap<String, Object>(); Map<String, Object> rspMap = new HashMap<String, Object>();

@ -48,6 +48,14 @@ public class SecurityUtils
return SecurityContextHolder.getStationId(); return SecurityContextHolder.getStationId();
} }
/**
*
*/
public static String getStationCode()
{
return SecurityContextHolder.getStationCode();
}
/** /**
* *
*/ */

@ -70,6 +70,7 @@ public class AuthFilter implements GlobalFilter, Ordered
String userid = JwtUtils.getUserId(claims); String userid = JwtUtils.getUserId(claims);
String username = JwtUtils.getUserName(claims); String username = JwtUtils.getUserName(claims);
String stationId = JwtUtils.getStationId(claims); String stationId = JwtUtils.getStationId(claims);
String stationCode = JwtUtils.getStationCode(claims);
if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username))
{ {
return unauthorizedResponse(exchange, "令牌验证失败"); return unauthorizedResponse(exchange, "令牌验证失败");
@ -80,6 +81,7 @@ public class AuthFilter implements GlobalFilter, Ordered
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid); addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username); addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
addHeader(mutate, SecurityConstants.DETAILS_STATION_ID, stationId); addHeader(mutate, SecurityConstants.DETAILS_STATION_ID, stationId);
addHeader(mutate, SecurityConstants.DETAILS_STATION_CODE, stationCode);
// 内部请求来源参数清除 // 内部请求来源参数清除
removeHeader(mutate, SecurityConstants.FROM_SOURCE); removeHeader(mutate, SecurityConstants.FROM_SOURCE);
return chain.filter(exchange.mutate().request(mutate.build()).build()); return chain.filter(exchange.mutate().request(mutate.build()).build());

@ -1,7 +1,7 @@
import request from '@/utils/request' import request from '@/utils/request'
// 登录方法 // 登录方法
export function login(username, password, code, uuid, stationId) { export function login(username, password, code, uuid, stationId,stationCode) {
return request({ return request({
url: '/auth/login', url: '/auth/login',
headers: { headers: {
@ -9,7 +9,7 @@ export function login(username, password, code, uuid, stationId) {
repeatSubmit: false repeatSubmit: false
}, },
method: 'post', method: 'post',
data: {username, password, code, uuid, stationId} data: {username, password, code, uuid, stationId,stationCode}
}) })
} }

@ -43,8 +43,9 @@ const user = {
const code = userInfo.code const code = userInfo.code
const uuid = userInfo.uuid const uuid = userInfo.uuid
const stationId = userInfo.stationId || '' const stationId = userInfo.stationId || ''
const stationCode = userInfo.stationCode || ''
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login(username, password, code, uuid,stationId).then(res => { login(username, password, code, uuid,stationId,stationCode).then(res => {
let data = res.data let data = res.data
setToken(data.access_token) setToken(data.access_token)
commit('SET_TOKEN', data.access_token) commit('SET_TOKEN', data.access_token)

@ -1,7 +1,7 @@
<template> <template>
<div class="login"> <div class="login">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
<h3 class="title">京源环保办公系统</h3> <h3 class="title">京源环保MES系统</h3>
<el-form-item prop="username"> <el-form-item prop="username">
<el-input <el-input
v-model="loginForm.username" v-model="loginForm.username"
@ -24,11 +24,14 @@
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item v-if="isStationId" prop="stationId"> <el-form-item v-if="isStationId" prop="stationId">
<el-select v-model="loginForm.stationId" placeholder="请选择工位" style="width: 100%"> <el-select v-model="loginForm.stationId" placeholder="请选择工位" style="width: 100%" @change="changeStation">
<el-option v-for="item in options" :key="item.stationId" :label="item.stationName" <el-option v-for="item in options" :key="item.stationId" :label="item.stationName"
:value="item.stationId"></el-option> :value="item.stationId"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="工位编号" prop="stationCode" v-if="false">
<el-input v-model="loginForm.stationCode"/>
</el-form-item>
<el-form-item v-if="captchaEnabled" prop="code"> <el-form-item v-if="captchaEnabled" prop="code">
<el-input <el-input
v-model="loginForm.code" v-model="loginForm.code"
@ -82,6 +85,7 @@ export default {
password: "admin123", password: "admin123",
rememberMe: false, rememberMe: false,
stationId: '', stationId: '',
stationCode:'',
code: "", code: "",
uuid: "" uuid: ""
}, },
@ -204,6 +208,12 @@ export default {
}); });
} }
}); });
},
changeStation(stationId){
let station = this.options.find(v=>v.stationId === stationId)
this.loginForm.stationCode = station.stationCode;
} }
} }
}; };

Loading…
Cancel
Save