权限配置、默认用户、角色配置.
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
import { KafkaClusterApi, AuthApi } from "@/utils/api";
|
||||
import request from "@/utils/request";
|
||||
import { mapMutations, mapState } from "vuex";
|
||||
import {deleteToken, deleteUsername, getClusterInfo, getUsername} from "@/utils/local-cache";
|
||||
import {deleteToken, deleteUsername, getClusterInfo, getPermissions, getUsername} from "@/utils/local-cache";
|
||||
import notification from "ant-design-vue/lib/notification";
|
||||
import { AUTH, CLUSTER } from "@/store/mutation-types";
|
||||
|
||||
@@ -71,9 +71,11 @@ export default {
|
||||
switchCluster: CLUSTER.SWITCH,
|
||||
enableAuth: AUTH.ENABLE,
|
||||
setUsername: AUTH.SET_USERNAME,
|
||||
setPermissions: AUTH.SET_PERMISSIONS,
|
||||
}),
|
||||
beforeLoadFn() {
|
||||
this.setUsername(getUsername());
|
||||
this.setPermissions(getPermissions());
|
||||
},
|
||||
intAuthState() {
|
||||
request({
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import Vue from "vue";
|
||||
import Store from "@/store";
|
||||
|
||||
const action = Vue.directive("action", {
|
||||
inserted: function (el, binding) {
|
||||
const actionName = binding.arg;
|
||||
if (actionName != "action") {
|
||||
const enableAuth = Store.state.auth.enable;
|
||||
const permissions = Store.state.auth.permissions;
|
||||
if (enableAuth && (!permissions || permissions.indexOf(actionName) < 0)) {
|
||||
(el.parentNode && el.parentNode.removeChild(el)) ||
|
||||
(el.style.display = "none");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import Vue from "vue";
|
||||
import Vuex from "vuex";
|
||||
import { CLUSTER, AUTH } from "@/store/mutation-types";
|
||||
import { setClusterInfo, setToken, setUsername } from "@/utils/local-cache";
|
||||
import {
|
||||
setClusterInfo,
|
||||
setPermissions,
|
||||
setToken,
|
||||
setUsername,
|
||||
} from "@/utils/local-cache";
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
@@ -15,6 +20,7 @@ export default new Vuex.Store({
|
||||
auth: {
|
||||
enable: false,
|
||||
username: "",
|
||||
permissions: [],
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
@@ -42,6 +48,10 @@ export default new Vuex.Store({
|
||||
setUsername(username);
|
||||
state.auth.username = username;
|
||||
},
|
||||
[AUTH.SET_PERMISSIONS](state, permissions) {
|
||||
setPermissions(permissions);
|
||||
state.auth.permissions = permissions;
|
||||
},
|
||||
},
|
||||
actions: {},
|
||||
modules: {},
|
||||
|
||||
@@ -6,4 +6,5 @@ export const AUTH = {
|
||||
ENABLE: "enable",
|
||||
SET_TOKEN: "setToken",
|
||||
SET_USERNAME: "setUsername",
|
||||
SET_PERMISSIONS: "setPermissions",
|
||||
};
|
||||
|
||||
@@ -8,4 +8,5 @@ export const Cache = {
|
||||
token: "access_token",
|
||||
username: "login_user",
|
||||
enableAuth: "enable_auth",
|
||||
permissions: "permissions",
|
||||
};
|
||||
|
||||
@@ -37,6 +37,14 @@ export function getUsername() {
|
||||
return localStorage.getItem(Cache.username);
|
||||
}
|
||||
|
||||
export function setPermissions(permissions) {
|
||||
localStorage.setItem(Cache.permissions, permissions);
|
||||
}
|
||||
|
||||
export function getPermissions() {
|
||||
return localStorage.getItem(Cache.permissions);
|
||||
}
|
||||
|
||||
// export function setEnableAuth(enable) {
|
||||
// localStorage.setItem()
|
||||
// }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<a-card v-action:action title="控制台默认配置" class="card-style">
|
||||
<a-card title="控制台默认配置" class="card-style">
|
||||
<p v-for="(v, k) in config" :key="k">{{ k }}={{ v }}</p>
|
||||
</a-card>
|
||||
<p></p>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
href="javascript:;"
|
||||
class="operation-btn"
|
||||
@click="openBrokerConfigDialog(record, false)"
|
||||
v-action:cluster:property-config
|
||||
>属性配置
|
||||
</a-button>
|
||||
<a-button
|
||||
|
||||
@@ -66,6 +66,7 @@ export default {
|
||||
if (res.code == 0) {
|
||||
this.setToken(res.data.token);
|
||||
this.setUsername(params.username);
|
||||
this.setPermissions(res.data.permissions);
|
||||
this.$router.push("/");
|
||||
} else {
|
||||
notification.error({
|
||||
@@ -80,6 +81,7 @@ export default {
|
||||
...mapMutations({
|
||||
setToken: AUTH.SET_TOKEN,
|
||||
setUsername: AUTH.SET_USERNAME,
|
||||
setPermissions: AUTH.SET_PERMISSIONS,
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user