mirror of
https://gitee.com/ssssssss-team/magic-api.git
synced 2026-06-20 12:32:23 +08:00
增加注销登录
This commit is contained in:
@@ -101,6 +101,26 @@ public class MagicWorkbenchController extends MagicController implements MagicEx
|
||||
return new JsonBean<>(true);
|
||||
}
|
||||
|
||||
@RequestMapping("/user")
|
||||
@ResponseBody
|
||||
public JsonBean<MagicUser> user(HttpServletRequest request){
|
||||
if (configuration.getAuthorizationInterceptor().requireLogin()) {
|
||||
try {
|
||||
return new JsonBean<>(configuration.getAuthorizationInterceptor().getUserByToken(request.getHeader(Constants.MAGIC_TOKEN_HEADER)));
|
||||
} catch (MagicLoginException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
return new JsonBean<>(MagicUser.guest());
|
||||
}
|
||||
|
||||
@RequestMapping("/logout")
|
||||
@ResponseBody
|
||||
public JsonBean<Void> logout(HttpServletRequest request){
|
||||
configuration.getAuthorizationInterceptor().logout(request.getHeader(Constants.MAGIC_TOKEN_HEADER));
|
||||
return new JsonBean<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建控制台输出
|
||||
|
||||
@@ -31,6 +31,13 @@ public interface AuthorizationInterceptor {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
default void logout(String token){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否拥有页面按钮的权限
|
||||
*/
|
||||
|
||||
@@ -37,4 +37,8 @@ public class MagicUser {
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public static MagicUser guest(){
|
||||
return new MagicUser(null, "guest", null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.ma-icon-logout:before {
|
||||
content: "\e65a";
|
||||
}
|
||||
|
||||
.ma-icon-datasource:before {
|
||||
content: "\e615";
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -192,6 +192,7 @@ export default {
|
||||
bus.$on('doTest', this.doTest)
|
||||
bus.$on('doContinue', this.doContinue)
|
||||
bus.$on('doStepInto', this.doStepInto)
|
||||
bus.$on('logout', this.closeAll)
|
||||
bus.$on('ready-delete', () => {
|
||||
if (this.info) {
|
||||
bus.$emit('delete-api', this.info)
|
||||
@@ -757,6 +758,12 @@ export default {
|
||||
bus.$emit('opened', {empty: true})
|
||||
}
|
||||
},
|
||||
closeAll() {
|
||||
let items = [...this.scripts]
|
||||
items.forEach(element => {
|
||||
this.close(element.id || element.tmp_id)
|
||||
})
|
||||
},
|
||||
changed(info) {
|
||||
if (info && info === this.selected) {
|
||||
let index = -1
|
||||
@@ -816,10 +823,7 @@ export default {
|
||||
{
|
||||
label: '全部关闭',
|
||||
onClick: () => {
|
||||
let items = [...this.scripts]
|
||||
items.forEach(element => {
|
||||
this.close(element.id || element.tmp_id)
|
||||
})
|
||||
this.closeAll()
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
@@ -65,6 +65,9 @@ export default {
|
||||
}
|
||||
})
|
||||
bus.$on('opened', info => {
|
||||
if(info.empty){
|
||||
return;
|
||||
}
|
||||
this.isApi = info._type === 'api';
|
||||
this.info = info
|
||||
if (this.isApi) {
|
||||
@@ -156,6 +159,7 @@ export default {
|
||||
color: var(--icon-color);
|
||||
padding: 0 2px;
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.ma-bottom-tab li:hover {
|
||||
|
||||
@@ -1,27 +1,51 @@
|
||||
<template>
|
||||
<div>
|
||||
{{ message }}
|
||||
<div class="ma-status-container">
|
||||
<div>{{ message }}</div>
|
||||
<div class="ma-user-info" v-if="user && user.id && user.username" @click="logout"><i class="ma-icon ma-icon-logout"/>{{ user.username }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import bus from '@/scripts/bus.js'
|
||||
import request from '@/api/request.js'
|
||||
import contants from '@/scripts/contants.js'
|
||||
import store from '@/scripts/store.js'
|
||||
|
||||
export default {
|
||||
name: 'MagicStatusBar',
|
||||
data() {
|
||||
return {
|
||||
user: null,
|
||||
message: ''
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
bus.$on('status', (message) => this.message = message)
|
||||
bus.$on('login',() => {
|
||||
request.send('/user').success(user => this.user = user)
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
logout(){
|
||||
this.$magicConfirm({
|
||||
title: '注销登录',
|
||||
content: `是否要注销登录`,
|
||||
onOk: () => {
|
||||
request.send('/logout').success(() => {
|
||||
this.user = null;
|
||||
contants.HEADER_MAGIC_TOKEN_VALUE = 'unauthorization';
|
||||
store.remove(contants.HEADER_MAGIC_TOKEN);
|
||||
bus.$emit('logout')
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
div {
|
||||
.ma-status-container {
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
height: 24px;
|
||||
@@ -33,5 +57,22 @@ div {
|
||||
flex: none;
|
||||
text-align: left;
|
||||
color: var(--color);
|
||||
display: flex;
|
||||
}
|
||||
.ma-status-container > div {
|
||||
flex: 1;
|
||||
}
|
||||
.ma-status-container .ma-user-info{
|
||||
flex: none;
|
||||
padding: 0 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ma-status-container .ma-user-info i{
|
||||
color: var(--icon-color);
|
||||
padding: 0 2px;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
.ma-status-container .ma-user-info:hover{
|
||||
background: var(--hover-background);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -89,6 +89,7 @@ export default {
|
||||
this.$refs.apiList.initData()
|
||||
this.$refs.functionList.initData()
|
||||
this.$refs.datasourceList.initData()
|
||||
bus.$emit('login');
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -179,6 +180,7 @@ export default {
|
||||
this.toolbarIndex = 1
|
||||
}
|
||||
})
|
||||
bus.$on('logout', ()=> this.showLogin = true)
|
||||
},
|
||||
destroyed() {
|
||||
bus.$off();
|
||||
|
||||
@@ -753,6 +753,7 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.bus.$on('logout', () => this.tree = [])
|
||||
this.bus.$on('opened', item => {
|
||||
this.currentFileItem = item
|
||||
})
|
||||
|
||||
@@ -106,7 +106,6 @@ export default {
|
||||
},
|
||||
// 初始化数据
|
||||
initData() {
|
||||
this.tree = []
|
||||
request.send('datasource/list').success(data => {
|
||||
this.datasources = data;
|
||||
JavaClass.setExtensionAttribute('org.ssssssss.magicapi.modules.SQLModule',this.datasources.filter(it => it.key).map(it => {
|
||||
@@ -274,6 +273,7 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.bus.$on('logout', () => this.datasources = []);
|
||||
this.bus.$on('refresh-resource',() => {
|
||||
this.initData()
|
||||
})
|
||||
|
||||
@@ -702,6 +702,7 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
JavaClass.setupOnlineFunction(this.doFindFunction);
|
||||
this.bus.$on('logout', () => this.tree = []);
|
||||
this.bus.$on('opened', item => {
|
||||
this.currentFileItem = item
|
||||
})
|
||||
|
||||
@@ -9,6 +9,10 @@ class Store {
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
|
||||
remove(key) {
|
||||
localStorage.removeItem(key)
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return localStorage.getItem(key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user