mirror of https://github.com/halo-dev/halo-admin
222 lines
7.6 KiB
Vue
222 lines
7.6 KiB
Vue
<script lang="ts" setup>
|
|
import {
|
|
IconAddCircle,
|
|
IconArrowDown,
|
|
IconSettings,
|
|
IconShieldUser,
|
|
VButton,
|
|
VCard,
|
|
VPageHeader,
|
|
VPagination,
|
|
VSpace,
|
|
VTag,
|
|
} from "@halo-dev/components";
|
|
import RoleCreationModal from "./components/RoleCreationModal.vue";
|
|
import { useRouter } from "vue-router";
|
|
import { computed, onMounted, ref } from "vue";
|
|
import type { Role } from "@/types/extension";
|
|
import { axiosInstance } from "@halo-dev/admin-shared";
|
|
|
|
const createVisible = ref(false);
|
|
const roles = ref<Role[]>([]);
|
|
|
|
const basicRoles = computed(() => {
|
|
return roles.value.filter(
|
|
(role) =>
|
|
role.metadata?.labels?.["plugin.halo.run/role-template"] !== "true"
|
|
);
|
|
});
|
|
|
|
const router = useRouter();
|
|
|
|
const handleFetchRoles = async () => {
|
|
try {
|
|
const { data } = await axiosInstance.get("/api/v1alpha1/roles");
|
|
roles.value = data;
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
};
|
|
|
|
const handleRouteToDetail = (name: string) => {
|
|
router.push({ name: "RoleDetail", params: { name } });
|
|
};
|
|
|
|
onMounted(() => {
|
|
handleFetchRoles();
|
|
});
|
|
</script>
|
|
<template>
|
|
<RoleCreationModal
|
|
v-model:visible="createVisible"
|
|
@close="handleFetchRoles"
|
|
/>
|
|
|
|
<VPageHeader title="角色">
|
|
<template #icon>
|
|
<IconShieldUser class="mr-2 self-center" />
|
|
</template>
|
|
<template #actions>
|
|
<VButton type="secondary" @click="createVisible = true">
|
|
<template #icon>
|
|
<IconAddCircle class="h-full w-full" />
|
|
</template>
|
|
新建角色
|
|
</VButton>
|
|
</template>
|
|
</VPageHeader>
|
|
|
|
<div class="m-0 md:m-4">
|
|
<VCard :body-class="['!p-0']">
|
|
<template #header>
|
|
<div class="block w-full bg-gray-50 px-4 py-3">
|
|
<div
|
|
class="relative flex flex-col items-start sm:flex-row sm:items-center"
|
|
>
|
|
<div class="flex w-full flex-1 sm:w-auto">
|
|
<FormKit placeholder="输入关键词搜索" type="text"></FormKit>
|
|
</div>
|
|
<div class="mt-4 flex sm:mt-0">
|
|
<VSpace spacing="lg">
|
|
<FloatingDropdown>
|
|
<div
|
|
class="flex cursor-pointer select-none items-center text-sm text-gray-700 hover:text-black"
|
|
>
|
|
<span class="mr-0.5">状态</span>
|
|
<span>
|
|
<IconArrowDown />
|
|
</span>
|
|
</div>
|
|
<template #popper>
|
|
<div class="w-52 p-4">
|
|
<ul class="space-y-1">
|
|
<li
|
|
class="flex cursor-pointer items-center rounded px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900"
|
|
>
|
|
<span class="truncate">正常</span>
|
|
</li>
|
|
<li
|
|
class="flex cursor-pointer items-center rounded px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900"
|
|
>
|
|
<span class="truncate">已禁用</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</template>
|
|
</FloatingDropdown>
|
|
<FloatingDropdown>
|
|
<div
|
|
class="flex cursor-pointer select-none items-center text-sm text-gray-700 hover:text-black"
|
|
>
|
|
<span class="mr-0.5">类型</span>
|
|
<span>
|
|
<IconArrowDown />
|
|
</span>
|
|
</div>
|
|
<template #popper>
|
|
<div class="w-52 p-4">
|
|
<ul class="space-y-1">
|
|
<li
|
|
class="flex cursor-pointer items-center rounded px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900"
|
|
>
|
|
<span class="truncate">系统保留</span>
|
|
</li>
|
|
<li
|
|
class="flex cursor-pointer items-center rounded px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900"
|
|
>
|
|
<span class="truncate">自定义</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</template>
|
|
</FloatingDropdown>
|
|
<FloatingDropdown>
|
|
<div
|
|
class="flex cursor-pointer select-none items-center text-sm text-gray-700 hover:text-black"
|
|
>
|
|
<span class="mr-0.5">排序</span>
|
|
<span>
|
|
<IconArrowDown />
|
|
</span>
|
|
</div>
|
|
<template #popper>
|
|
<div class="w-72 p-4">
|
|
<ul class="space-y-1">
|
|
<li
|
|
class="flex cursor-pointer items-center rounded px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900"
|
|
>
|
|
<span class="truncate">更高权限</span>
|
|
</li>
|
|
<li
|
|
class="flex cursor-pointer items-center rounded px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900"
|
|
>
|
|
<span class="truncate">更低权限</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</template>
|
|
</FloatingDropdown>
|
|
</VSpace>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
<ul class="box-border h-full w-full divide-y divide-gray-100" role="list">
|
|
<li
|
|
v-for="(role, index) in basicRoles"
|
|
:key="index"
|
|
@click="handleRouteToDetail(role.metadata.name)"
|
|
>
|
|
<div
|
|
class="relative block cursor-pointer px-4 py-3 transition-all hover:bg-gray-50"
|
|
>
|
|
<div class="relative flex flex-row items-center">
|
|
<div class="flex-1">
|
|
<div class="flex flex-row items-center">
|
|
<span class="mr-2 truncate text-sm font-medium text-gray-900">
|
|
{{
|
|
role.metadata.annotations?.[
|
|
"plugin.halo.run/display-name"
|
|
] || role.metadata.name
|
|
}}
|
|
</span>
|
|
</div>
|
|
<div class="mt-2 flex">
|
|
<span class="text-xs text-gray-500"> 包含 0 个权限 </span>
|
|
</div>
|
|
</div>
|
|
<div class="flex">
|
|
<div
|
|
class="inline-flex flex-col flex-col-reverse items-end gap-4 sm:flex-row sm:items-center sm:gap-6"
|
|
>
|
|
<a
|
|
class="hidden text-sm text-gray-500 hover:text-gray-900 sm:block"
|
|
target="_blank"
|
|
>
|
|
0 个用户
|
|
</a>
|
|
<VTag> 系统保留</VTag>
|
|
<time class="text-sm text-gray-500" datetime="2020-01-07">
|
|
2020-01-07
|
|
</time>
|
|
<span class="cursor-pointer">
|
|
<IconSettings />
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
|
|
<template #footer>
|
|
<div class="flex items-center justify-end bg-white">
|
|
<div class="flex flex-1 items-center justify-end">
|
|
<VPagination :page="1" :size="10" :total="20" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</VCard>
|
|
</div>
|
|
</template>
|