Files
orion-visor/orion-ops-ui/src/views/asset/grant/index.vue

145 lines
3.6 KiB
Vue
Raw Normal View History

2023-11-10 19:02:38 +08:00
<template>
2023-11-23 19:16:57 +08:00
<div v-if="render" class="view-container">
<a-tabs v-if="render"
class="tabs-container"
2023-12-01 01:54:50 +08:00
position="left"
2023-11-23 19:16:57 +08:00
:destroy-on-hide="true"
:justify="true"
:lazy-load="true">
<!-- 左侧导航 -->
2023-12-01 01:54:50 +08:00
<a-tab-pane :key="1"
title="分组配置"
v-permission="['asset:host-group:query']">
2023-11-23 19:16:57 +08:00
<host-group-view-setting />
<template #title>
<icon-unordered-list />
2023-12-01 01:54:50 +08:00
2023-11-23 19:16:57 +08:00
</template>
</a-tab-pane>
<!-- 角色分配 -->
<a-tab-pane :key="2" v-permission="['asset:host-group:grant']">
<host-group-view-role-grant />
<template #title>
<icon-safe />
角色授权
</template>
</a-tab-pane>
<!-- 用户分配 -->
<a-tab-pane :key="3" v-permission="['asset:host-group:grant']">
<host-group-view-user-grant />
<template #title>
<icon-user />
2023-12-01 01:54:50 +08:00
用户授权2323
2023-11-23 19:16:57 +08:00
</template>
</a-tab-pane>
</a-tabs>
2023-11-10 19:02:38 +08:00
</div>
</template>
<script lang="ts">
export default {
2023-12-01 01:54:50 +08:00
name: 'assetGrant'
2023-11-10 19:02:38 +08:00
};
</script>
<script lang="ts" setup>
2023-11-23 19:16:57 +08:00
import { ref, onBeforeMount, onUnmounted } from 'vue';
import { useCacheStore } from '@/store';
2023-11-14 15:05:47 +08:00
import { getHostList } from '@/api/asset/host';
2023-11-23 19:16:57 +08:00
import { Message } from '@arco-design/web-vue';
import HostGroupViewSetting from './components/host-group-view-setting.vue';
import HostGroupViewRoleGrant from './components/host-group-view-role-grant.vue';
import HostGroupViewUserGrant from './components/host-group-view-user-grant.vue';
2023-11-24 02:07:52 +08:00
import { getUserList } from '@/api/user/user';
import { getRoleList } from '@/api/user/role';
import usePermission from '@/hooks/permission';
2023-11-10 19:02:38 +08:00
const render = ref(false);
const cacheStore = useCacheStore();
2023-11-24 02:07:52 +08:00
const { hasPermission } = usePermission();
2023-11-10 19:02:38 +08:00
2023-11-14 15:05:47 +08:00
// 加载主机列表
const loadHostList = async () => {
2023-11-10 19:02:38 +08:00
try {
2023-11-14 15:05:47 +08:00
const { data } = await getHostList();
2023-11-10 19:02:38 +08:00
// 设置到缓存
2023-11-14 15:05:47 +08:00
cacheStore.set('hosts', data);
} catch (e) {
2023-11-24 02:07:52 +08:00
Message.error('主机列表加载失败');
}
};
// 加载用户列表
const loadUserList = async () => {
try {
const { data } = await getUserList();
// 设置到缓存
cacheStore.set('users', data);
} catch (e) {
Message.error('用户列表加载失败');
}
};
// 加载角色列表
const loadRoleList = async () => {
try {
const { data } = await getRoleList();
// 设置到缓存
cacheStore.set('roles', data);
} catch (e) {
Message.error('角色列表加载失败');
2023-11-10 19:02:38 +08:00
}
};
onBeforeMount(async () => {
2023-11-24 02:07:52 +08:00
if (hasPermission('asset:host-group:query')) {
// 加载主机列表 tab1
await loadHostList();
render.value = true;
}
if (hasPermission('asset:host-group:grant')) {
// 加载角色列表 tab2
await loadRoleList();
render.value = true;
// 加载用户列表 tab3
await loadUserList();
}
2023-11-10 19:02:38 +08:00
});
// 卸载时清除 cache
onUnmounted(() => {
2023-11-24 02:07:52 +08:00
cacheStore.reset('users', 'roles', 'hosts', 'hostGroups');
2023-11-10 19:02:38 +08:00
});
</script>
<style lang="less" scoped>
2023-11-23 19:16:57 +08:00
.view-container {
display: flex;
2023-11-10 19:02:38 +08:00
width: 100%;
height: 100%;
2023-11-23 19:16:57 +08:00
position: relative;
2023-11-10 19:02:38 +08:00
padding: 16px;
}
2023-11-23 19:16:57 +08:00
.tabs-container {
display: flex;
width: 100%;
height: 100%;
position: relative;
2023-11-30 22:21:25 +08:00
background: var(--color-bg-2);
2023-11-23 19:16:57 +08:00
}
2023-12-01 01:54:50 +08:00
:deep(.arco-tabs-tab-title) {
2023-11-24 14:42:58 +08:00
user-select: none;
}
2023-11-23 19:16:57 +08:00
:deep(.arco-tabs-content) {
padding-top: 0;
}
2023-11-24 02:07:52 +08:00
:deep(.arco-tabs-content) {
position: relative;
}
2023-11-10 19:02:38 +08:00
</style>