🎉 2.6.1发布,增加登陆验证码,支持Seata1.0

This commit is contained in:
smallchill 2020-02-12 01:01:20 +08:00
parent d6e7dd61b5
commit 1e8cf13587
7 changed files with 272 additions and 206 deletions

View File

@ -1,5 +1,5 @@
<p align="center"> <p align="center">
<img src="https://img.shields.io/badge/Release-V2.6.0-green.svg" alt="Downloads"> <img src="https://img.shields.io/badge/Release-V2.6.1-green.svg" alt="Downloads">
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" alt="Build Status"> <img src="https://img.shields.io/badge/JDK-1.8+-green.svg" alt="Build Status">
<img src="https://img.shields.io/badge/license-Apache%202-blue.svg" alt="Build Status"> <img src="https://img.shields.io/badge/license-Apache%202-blue.svg" alt="Build Status">
<img src="https://img.shields.io/badge/Spring%20Cloud-Hoxton.SR1-blue.svg" alt="Coverage Status"> <img src="https://img.shields.io/badge/Spring%20Cloud-Hoxton.SR1-blue.svg" alt="Coverage Status">
@ -56,8 +56,9 @@ SpringBlade
* 官网地址:[https://bladex.vip](https://bladex.vip) * 官网地址:[https://bladex.vip](https://bladex.vip)
* 问答社区:[https://sns.bladex.vip](https://sns.bladex.vip) * 问答社区:[https://sns.bladex.vip](https://sns.bladex.vip)
* 会员计划:[SpringBlade会员计划](https://gitee.com/smallc/SpringBlade/wikis/SpringBlade会员计划) * 会员计划:[SpringBlade会员计划](https://gitee.com/smallc/SpringBlade/wikis/SpringBlade会员计划)
* 交流一群:`477853168` * 交流一群:`477853168`(满)
* 交流二群:`751253339` * 交流二群:`751253339`(满)
* 交流三群:`784729540`
## 在线演示 ## 在线演示
* Saber-基于Vue[https://saber.bladex.vip](https://saber.bladex.vip) * Saber-基于Vue[https://saber.bladex.vip](https://saber.bladex.vip)

View File

@ -1,6 +1,6 @@
{ {
"name": "saber-admin", "name": "saber-admin",
"version": "2.5.4", "version": "2.6.1",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",

View File

@ -1,16 +1,21 @@
import request from '@/router/axios'; import request from '@/router/axios';
import {baseUrl} from '@/config/env'; import {baseUrl} from '@/config/env';
export const loginByUsername = (tenantId, account, password, type) => request({ export const loginByUsername = (tenantId, account, password, type, key, code) => request({
url: '/api/blade-auth/token', url: '/api/blade-auth/token',
method: 'post', method: 'post',
headers: {
'Captcha-Key': key,
'Captcha-Code': code,
},
params: { params: {
grantType: 'captcha',
tenantId, tenantId,
account, account,
password, password,
type type
} }
}) });
export const getButtons = () => request({ export const getButtons = () => request({
url: '/api/blade-system/menu/buttons', url: '/api/blade-system/menu/buttons',
@ -32,6 +37,11 @@ export const getMenu = () => request({
method: 'get' method: 'get'
}); });
export const getCaptcha = () => request({
url: '/api/blade-auth/captcha',
method: 'get'
});
export const getTopMenu = () => request({ export const getTopMenu = () => request({
url: baseUrl + '/user/getTopMenu', url: baseUrl + '/user/getTopMenu',
method: 'get' method: 'get'

View File

@ -39,18 +39,39 @@
class="icon-mima"></i> class="icon-mima"></i>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item prop="code">
<el-row :span="24">
<el-col :span="16">
<el-input size="small"
@keyup.enter.native="handleLogin"
v-model="loginForm.code"
auto-complete="off"
:placeholder="$t('login.code')">
<i slot="prefix" class="icon-yanzhengma"/>
</el-input>
</el-col>
<el-col :span="8">
<div class="login-code">
<img :src="loginForm.image" class="login-code-img" @click="refreshCode"
/>
</div>
</el-col>
</el-row>
</el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" <el-button type="primary"
size="small" size="small"
@click.native.prevent="handleLogin" @click.native.prevent="handleLogin"
class="login-submit">{{$t('login.submit')}}</el-button> class="login-submit">{{$t('login.submit')}}
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script> <script>
import { mapGetters } from "vuex"; import {mapGetters} from "vuex";
import website from '@/config/website'; import website from '@/config/website';
import {getCaptcha} from "@/api/user";
export default { export default {
name: "userlogin", name: "userlogin",
@ -58,35 +79,55 @@
return { return {
tenantMode: website.tenantMode, tenantMode: website.tenantMode,
loginForm: { loginForm: {
//ID
tenantId: "000000", tenantId: "000000",
//
username: "admin", username: "admin",
//
password: "admin", password: "admin",
type: "account" //
type: "account",
//
code: "",
//
key: "",
//
image: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
}, },
loginRules: { loginRules: {
tenantId: [ tenantId: [
{ required: false, message: "请输入租户ID", trigger: "blur" } {required: false, message: "请输入租户ID", trigger: "blur"}
], ],
username: [ username: [
{ required: true, message: "请输入用户名", trigger: "blur" } {required: true, message: "请输入用户名", trigger: "blur"}
], ],
password: [ password: [
{ required: true, message: "请输入密码", trigger: "blur" }, {required: true, message: "请输入密码", trigger: "blur"},
{ min: 1, message: "密码长度最少为6位", trigger: "blur" } {min: 1, message: "密码长度最少为6位", trigger: "blur"}
] ]
}, },
passwordType: "password" passwordType: "password"
}; };
}, },
created() {}, created() {
mounted() {}, this.refreshCode();
},
mounted() {
},
computed: { computed: {
...mapGetters(["tagWel"]) ...mapGetters(["tagWel"])
}, },
props: [], props: [],
methods: { methods: {
refreshCode() {
getCaptcha().then(res => {
const data = res.data.data;
this.loginForm.key = data.key;
this.loginForm.image = data.image;
})
},
showPassword() { showPassword() {
this.passwordType == "" this.passwordType === ""
? (this.passwordType = "password") ? (this.passwordType = "password")
: (this.passwordType = ""); : (this.passwordType = "");
}, },
@ -99,7 +140,7 @@
spinner: "el-icon-loading" spinner: "el-icon-loading"
}); });
this.$store.dispatch("LoginByUsername", this.loginForm).then(() => { this.$store.dispatch("LoginByUsername", this.loginForm).then(() => {
this.$router.push({ path: this.tagWel.value }); this.$router.push({path: this.tagWel.value});
loading.close(); loading.close();
}).catch(() => { }).catch(() => {
loading.close() loading.close()

View File

@ -1,198 +1,201 @@
import { setToken, removeToken } from '@/util/auth' import {setToken, removeToken} from '@/util/auth'
import { setStore, getStore } from '@/util/store' import {setStore, getStore} from '@/util/store'
import { isURL, validatenull } from '@/util/validate' import {isURL, validatenull} from '@/util/validate'
import { deepClone } from '@/util/util' import {deepClone} from '@/util/util'
import webiste from '@/config/website' import webiste from '@/config/website'
import { loginByUsername, getUserInfo, getMenu, getTopMenu, logout, refeshToken, getButtons } from '@/api/user' import {loginByUsername, getUserInfo, getMenu, getTopMenu, logout, refeshToken, getButtons} from '@/api/user'
function addPath(ele, first) { function addPath(ele, first) {
const menu = webiste.menu; const menu = webiste.menu;
const propsConfig = menu.props; const propsConfig = menu.props;
const propsDefault = { const propsDefault = {
label: propsConfig.label || 'name', label: propsConfig.label || 'name',
path: propsConfig.path || 'path', path: propsConfig.path || 'path',
icon: propsConfig.icon || 'icon', icon: propsConfig.icon || 'icon',
children: propsConfig.children || 'children' children: propsConfig.children || 'children'
} };
const icon = ele[propsDefault.icon]; const icon = ele[propsDefault.icon];
ele[propsDefault.icon] = validatenull(icon) ? menu.iconDefault : icon; ele[propsDefault.icon] = validatenull(icon) ? menu.iconDefault : icon;
const isChild = ele[propsDefault.children] && ele[propsDefault.children].length !== 0; const isChild = ele[propsDefault.children] && ele[propsDefault.children].length !== 0;
if (!isChild) ele[propsDefault.children] = []; if (!isChild) ele[propsDefault.children] = [];
if (!isChild && first && !isURL(ele[propsDefault.path])) { if (!isChild && first && !isURL(ele[propsDefault.path])) {
ele[propsDefault.path] = ele[propsDefault.path] + '/index' ele[propsDefault.path] = ele[propsDefault.path] + '/index'
} else { } else {
ele[propsDefault.children].forEach(child => { ele[propsDefault.children].forEach(child => {
addPath(child); addPath(child);
}) })
} }
} }
const user = {
state: {
userInfo: getStore({ name: 'userInfo' }) || [],
permission: getStore({ name: 'permission' }) || {},
roles: [],
menu: getStore({ name: 'menu' }) || [],
menuAll: [],
token: getStore({ name: 'token' }) || '',
},
actions: {
//根据用户名登录
LoginByUsername({ commit }, userInfo) {
return new Promise((resolve, reject) => {
loginByUsername(userInfo.tenantId, userInfo.username, userInfo.password, userInfo.type).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data.accessToken);
commit('SET_USERIFNO', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
resolve();
}).catch(error => {
reject(error);
})
})
},
GetButtons({ commit }) {
return new Promise((resolve) => {
getButtons().then(res => {
const data = res.data.data;
commit('SET_PERMISSION', data);
resolve();
})
})
},
//根据手机号登录
LoginByPhone({ commit }, userInfo) {
return new Promise((resolve) => {
loginByUsername(userInfo.phone, userInfo.code).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
resolve();
})
})
},
GetUserInfo({ commit }) {
return new Promise((resolve, reject) => {
getUserInfo().then((res) => {
const data = res.data.data;
commit('SET_ROLES', data.roles);
resolve(data);
}).catch(err => {
reject(err);
})
})
},
//刷新token
RefeshToken({ state, commit }) {
return new Promise((resolve, reject) => {
refeshToken(state.refeshToken).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data);
resolve(data);
}).catch(error => {
reject(error)
})
})
},
// 登出
LogOut({ commit }) {
return new Promise((resolve, reject) => {
logout().then(() => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
commit('SET_ROLES', [])
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
removeToken()
resolve()
}).catch(error => {
reject(error)
})
})
},
//注销session
FedLogOut({ commit }) {
return new Promise(resolve => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
commit('SET_ROLES', [])
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
removeToken()
resolve()
})
},
GetTopMenu() {
return new Promise(resolve => {
getTopMenu().then((res) => {
const data = res.data.data || []
resolve(data)
})
})
},
//获取系统菜单
GetMenu({ commit, dispatch }, parentId) {
return new Promise(resolve => {
getMenu(parentId).then((res) => {
const data = res.data.data
let menu = deepClone(data);
menu.forEach(ele => {
addPath(ele, true);
})
commit('SET_MENU', menu)
dispatch('GetButtons');
resolve(menu)
})
})
},
},
mutations: {
SET_TOKEN: (state, token) => {
setToken(token)
state.token = token;
setStore({ name: 'token', content: state.token, type: 'session' })
},
SET_USERIFNO: (state, userInfo) => {
state.userInfo = userInfo;
setStore({ name: 'userInfo', content: state.userInfo })
},
SET_MENU: (state, menu) => {
state.menu = menu
setStore({ name: 'menu', content: state.menu, type: 'session' })
},
SET_MENU_ALL: (state, menuAll) => {
state.menuAll = menuAll;
},
SET_ROLES: (state, roles) => {
state.roles = roles;
},
SET_PERMISSION: (state, permission) => {
let result = [];
function getCode(list) {
list.forEach(ele => {
if (typeof (ele) === 'object') {
const chiildren = ele.children;
const code = ele.code;
if (chiildren) {
getCode(chiildren)
} else {
result.push(code);
}
}
}) const user = {
state: {
userInfo: getStore({name: 'userInfo'}) || [],
permission: getStore({name: 'permission'}) || {},
roles: [],
menu: getStore({name: 'menu'}) || [],
menuAll: [],
token: getStore({name: 'token'}) || '',
},
actions: {
//根据用户名登录
LoginByUsername({commit}, userInfo) {
return new Promise((resolve, reject) => {
loginByUsername(userInfo.tenantId, userInfo.username, userInfo.password, userInfo.type, userInfo.key, userInfo.code).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data.accessToken);
commit('SET_USERIFNO', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
resolve();
}).catch(error => {
reject(error);
})
})
},
GetButtons({commit}) {
return new Promise((resolve) => {
getButtons().then(res => {
const data = res.data.data;
commit('SET_PERMISSION', data);
resolve();
})
})
},
//根据手机号登录
LoginByPhone({commit}, userInfo) {
return new Promise((resolve) => {
loginByUsername(userInfo.phone, userInfo.code).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
resolve();
})
})
},
GetUserInfo({commit}) {
return new Promise((resolve, reject) => {
getUserInfo().then((res) => {
const data = res.data.data;
commit('SET_ROLES', data.roles);
resolve(data);
}).catch(err => {
reject(err);
})
})
},
//刷新token
RefeshToken({state, commit}) {
return new Promise((resolve, reject) => {
refeshToken(state.refeshToken).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data);
resolve(data);
}).catch(error => {
reject(error)
})
})
},
// 登出
LogOut({commit}) {
return new Promise((resolve, reject) => {
logout().then(() => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
commit('SET_ROLES', [])
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
removeToken()
resolve()
}).catch(error => {
reject(error)
})
})
},
//注销session
FedLogOut({commit}) {
return new Promise(resolve => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
commit('SET_ROLES', [])
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
removeToken()
resolve()
})
},
GetTopMenu() {
return new Promise(resolve => {
getTopMenu().then((res) => {
const data = res.data.data || []
resolve(data)
})
})
},
//获取系统菜单
GetMenu({commit, dispatch}, parentId) {
return new Promise(resolve => {
getMenu(parentId).then((res) => {
const data = res.data.data
let menu = deepClone(data);
menu.forEach(ele => {
addPath(ele, true);
})
commit('SET_MENU', menu)
dispatch('GetButtons');
resolve(menu)
})
})
},
},
mutations: {
SET_TOKEN: (state, token) => {
setToken(token)
state.token = token;
setStore({name: 'token', content: state.token, type: 'session'})
},
SET_USERIFNO: (state, userInfo) => {
state.userInfo = userInfo;
setStore({name: 'userInfo', content: state.userInfo})
},
SET_MENU: (state, menu) => {
state.menu = menu
setStore({name: 'menu', content: state.menu, type: 'session'})
},
SET_MENU_ALL: (state, menuAll) => {
state.menuAll = menuAll;
},
SET_ROLES: (state, roles) => {
state.roles = roles;
},
SET_PERMISSION: (state, permission) => {
let result = [];
function getCode(list) {
list.forEach(ele => {
if (typeof (ele) === 'object') {
const chiildren = ele.children;
const code = ele.code;
if (chiildren) {
getCode(chiildren)
} else {
result.push(code);
} }
getCode(permission); }
state.permission = {};
result.forEach(ele => { })
state.permission[ele] = true; }
});
setStore({ name: 'permission', content: state.permission, type: 'session' }) getCode(permission);
} state.permission = {};
result.forEach(ele => {
state.permission[ele] = true;
});
setStore({name: 'permission', content: state.permission, type: 'session'})
} }
}
} }
export default user export default user

View File

@ -160,4 +160,5 @@
line-height: 38px; line-height: 38px;
text-indent: 5px; text-indent: 5px;
text-align: center; text-align: center;
} cursor:pointer!important;
}

View File

@ -2,10 +2,10 @@
<div> <div>
<basic-container> <basic-container>
<p style="text-align: center;"> <p style="text-align: center;">
<img src="https://img.shields.io/badge/Release-V2.6.0-green.svg" alt="Downloads"/> <img src="https://img.shields.io/badge/Release-V2.6.1-green.svg" alt="Downloads"/>
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" alt="Build Status"/> <img src="https://img.shields.io/badge/JDK-1.8+-green.svg" alt="Build Status"/>
<img src="https://img.shields.io/badge/Spring%20Cloud-Hoxton.SR1-blue.svg" alt="Coverage Status"/> <img src="https://img.shields.io/badge/Spring%20Cloud-Hoxton.SR1-blue.svg" alt="Coverage Status"/>
<img src="https://img.shields.io/badge/Spring%20Boot-2.2.2.RELEASE-blue.svg" alt="Downloads"/> <img src="https://img.shields.io/badge/Spring%20Boot-2.2.4.RELEASE-blue.svg" alt="Downloads"/>
<a target="_blank" href="https://bladex.vip"> <a target="_blank" href="https://bladex.vip">
<img src="https://img.shields.io/badge/Saber%20Author-Small%20Chill-ff69b4.svg" alt="Downloads"/> <img src="https://img.shields.io/badge/Saber%20Author-Small%20Chill-ff69b4.svg" alt="Downloads"/>
</a> </a>
@ -124,6 +124,16 @@
<el-row> <el-row>
<basic-container> <basic-container>
<el-collapse v-model="logActiveNames" @change="handleChange"> <el-collapse v-model="logActiveNames" @change="handleChange">
<el-collapse-item title="2.6.1发布 增加登陆验证码支持seata1.0" name="15">
<div>1.升级SpringBoot 2.2.4.RELEASE</div>
<div>2.升级Alibaba Cloud 2.2.0.RELEASE</div>
<div>3.升级Mybatis-Plus 3.3.1</div>
<div>4.增加登陆验证码功能</div>
<div>5.增加验证码对应的CaptchaTokenGranter</div>
<div>6.增加RedisUtil方便业务操作</div>
<div>7.增加Condition类getQueryWrapper自定义排除参数的入口</div>
<div>8.优化Seata封装完美支持1.0.0版本</div>
</el-collapse-item>
<el-collapse-item title="2.6.0发布 升级Hoxton.SR1 适配最新架构" name="14"> <el-collapse-item title="2.6.0发布 升级Hoxton.SR1 适配最新架构" name="14">
<div>1.升级SpringCloud Hoxton.SR1</div> <div>1.升级SpringCloud Hoxton.SR1</div>
<div>2.升级SpringBoot 2.2.2.RELEASE</div> <div>2.升级SpringBoot 2.2.2.RELEASE</div>