前端权限管理:修复组件数据结构和路由参数处理
修复内容: - 修复 ApiPermissions.vue 中的路由参数处理,支持 id 和 projectId 两种参数 - 修复 ApiEndpointPermissions.vue 中的权限数据结构处理 - 修复 PermissionMonitoring.vue 中的缓存统计显示 - 修复 ProjectPermissionsModule.vue 中的权限矩阵更新逻辑 - 优化保存逻辑,保存后重新加载数据以确保同步 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,7 +157,9 @@ const filteredEndpoints = computed(() => {
|
|||||||
// 检查端点是否允许
|
// 检查端点是否允许
|
||||||
const isEndpointAllowed = (endpoint_key: string, role: string): boolean => {
|
const isEndpointAllowed = (endpoint_key: string, role: string): boolean => {
|
||||||
if (!props.matrix || !props.matrix[role]) return false;
|
if (!props.matrix || !props.matrix[role]) return false;
|
||||||
return props.matrix[role][endpoint_key]?.allowed ?? false;
|
const perm = props.matrix[role][endpoint_key];
|
||||||
|
if (!perm) return false;
|
||||||
|
return typeof perm === "boolean" ? perm : perm.allowed;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取方法的标签类型
|
// 获取方法的标签类型
|
||||||
@@ -181,7 +183,7 @@ const onPermissionChange = (endpoint_key: string, role: string, allowed: boolean
|
|||||||
updatedMatrix[role] = {};
|
updatedMatrix[role] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedMatrix[role][endpoint_key] = { allowed };
|
updatedMatrix[role][endpoint_key] = allowed;
|
||||||
|
|
||||||
emit("update", updatedMatrix);
|
emit("update", updatedMatrix);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
|
|
||||||
<div class="cache-stat">
|
<div class="cache-stat">
|
||||||
<div class="stat-label">缓存项目数</div>
|
<div class="stat-label">缓存项目数</div>
|
||||||
<div class="stat-value">{{ cacheStats?.cache_items.total_count || 0 }}</div>
|
<div class="stat-value">{{ health?.cache_stats?.cache_items.total_count || 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="cache-stat">
|
<div class="cache-stat">
|
||||||
@@ -136,7 +136,7 @@ defineProps<Props>();
|
|||||||
defineEmits<Emits>();
|
defineEmits<Emits>();
|
||||||
|
|
||||||
const cacheStats = computed(() => {
|
const cacheStats = computed(() => {
|
||||||
// 从 health 中提取 cache_stats
|
// 从 health 中提取 cache_stats,如果没有则返回 null
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ const tableData = computed(() => {
|
|||||||
const onPermissionChange = () => {
|
const onPermissionChange = () => {
|
||||||
if (!props.matrix) return;
|
if (!props.matrix) return;
|
||||||
|
|
||||||
const updatedMatrix = {
|
const updatedMatrix: ProjectRolePermissionsResponse = {
|
||||||
...props.matrix,
|
modules: props.matrix.modules,
|
||||||
roles: { ...props.matrix.roles },
|
roles: { ...props.matrix.roles },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,10 @@ const saving = ref(false);
|
|||||||
const resetting = ref(false);
|
const resetting = ref(false);
|
||||||
|
|
||||||
const project = computed(() => studyStore.currentStudy);
|
const project = computed(() => studyStore.currentStudy);
|
||||||
const studyId = computed(() => route.params.id as string);
|
const studyId = computed(() => {
|
||||||
|
const id = route.params.id || route.params.projectId;
|
||||||
|
return typeof id === "string" ? id : (id as string[])[0];
|
||||||
|
});
|
||||||
|
|
||||||
// 权限数据
|
// 权限数据
|
||||||
const moduleMatrix = ref<ProjectRolePermissionsResponse | null>(null);
|
const moduleMatrix = ref<ProjectRolePermissionsResponse | null>(null);
|
||||||
@@ -183,6 +186,9 @@ const save = async () => {
|
|||||||
|
|
||||||
dirty.value = false;
|
dirty.value = false;
|
||||||
ElMessage.success("权限已保存");
|
ElMessage.success("权限已保存");
|
||||||
|
|
||||||
|
// 重新加载数据以确保同步
|
||||||
|
await loadPermissionData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ElMessage.error("保存权限失败");
|
ElMessage.error("保存权限失败");
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user