更新角色管理相关内容
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><Plus /></el-icon>
|
||||
添加角色
|
||||
添加自定义角色
|
||||
</el-button>
|
||||
<el-button @click="refresh">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
@@ -19,8 +19,8 @@
|
||||
<div class="filter-bar">
|
||||
<el-radio-group v-model="typeFilter">
|
||||
<el-radio-button :value="'all'">全部</el-radio-button>
|
||||
<el-radio-button :value="1">平台角色</el-radio-button>
|
||||
<el-radio-button :value="2">租户角色</el-radio-button>
|
||||
<el-radio-button :value="'custom'">自定义角色</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
|
||||
@@ -39,11 +39,13 @@
|
||||
min-width="150"
|
||||
align="center"
|
||||
/>
|
||||
<el-table-column prop="cid" label="类型" width="120" align="center">
|
||||
<el-table-column prop="cid" label="类型" width="150" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.cid === 1 ? 'warning' : 'primary'" size="small">
|
||||
{{ row.cid === 1 ? "平台角色" : "租户角色" }}
|
||||
<el-tag v-if="row.cid === 1" type="danger" size="small">平台角色</el-tag>
|
||||
<el-tag v-else-if="Number(row.is_custom) === 1" type="warning" size="small">
|
||||
自定义角色
|
||||
</el-tag>
|
||||
<el-tag v-else type="primary" size="small">租户角色</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="100" align="center">
|
||||
@@ -71,7 +73,6 @@
|
||||
详情
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="userInfo?.id === 2"
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
@@ -81,7 +82,7 @@
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="userInfo?.id === 2"
|
||||
v-if="Number(row.is_custom) === 1"
|
||||
size="small"
|
||||
type="danger"
|
||||
link
|
||||
@@ -114,23 +115,18 @@
|
||||
import { ref, computed, onMounted } from "vue";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { Plus, View, Edit, Delete, Refresh } from "@element-plus/icons-vue";
|
||||
import {
|
||||
getAllPlatformRoles,
|
||||
deletePlatformRole,
|
||||
} from "@/api/platformRole";
|
||||
import { getAllRoles, deleteRole } from "@/api/role";
|
||||
import RoleEditDialog from "./components/edit.vue";
|
||||
import RoleDetailDialog from "./components/detail.vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
// 使用 auth store 获取用户信息
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const roles = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref("");
|
||||
const typeFilter = ref<string | number>("all");
|
||||
const displayRoles = computed(() => {
|
||||
// custom = 本租户自建的自定义角色;2 = 租户角色(含系统预置)
|
||||
if (typeFilter.value === "all") return roles.value;
|
||||
if (typeFilter.value === "custom") return roles.value.filter((r) => Number(r.is_custom) === 1);
|
||||
return roles.value.filter((r) => Number(r.cid) === Number(typeFilter.value));
|
||||
});
|
||||
|
||||
@@ -139,22 +135,12 @@ const detailDialogVisible = ref(false);
|
||||
const currentRole = ref<any>(null);
|
||||
const currentRoleId = ref<number | null>(null);
|
||||
|
||||
// 获取用户信息
|
||||
const userInfo = authStore.user;
|
||||
if (userInfo && userInfo.id) {
|
||||
// console.log('用户名:', userInfo.username || userInfo.nickname);
|
||||
// console.log('用户ID:', userInfo.id);
|
||||
// console.log('角色:', userInfo.role);
|
||||
} else {
|
||||
// console.log('未找到用户信息或用户未登录');
|
||||
}
|
||||
|
||||
// 获取角色列表
|
||||
// 获取角色列表:仅返回当前登录租户名下的租户角色(服务端按租户隔离)
|
||||
const fetchRoles = async () => {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const res = await getAllPlatformRoles();
|
||||
const res = await getAllRoles();
|
||||
if (res.code === 200) {
|
||||
roles.value = res.data || [];
|
||||
// console.log('角色列表:', roles.value);
|
||||
@@ -207,7 +193,7 @@ async function handleDelete(row: any) {
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await deletePlatformRole(row.id);
|
||||
const res = await deleteRole(row.id);
|
||||
if (res.code === 200) {
|
||||
ElMessage.success("删除成功");
|
||||
fetchRoles();
|
||||
|
||||
Reference in New Issue
Block a user