diff --git a/src/components/AdminBadge.vue b/src/components/AdminBadge.vue index a1e625d..d6a5527 100644 --- a/src/components/AdminBadge.vue +++ b/src/components/AdminBadge.vue @@ -12,10 +12,14 @@ import { computed } from 'vue' import { isDefaultServer, hasAdminVerifyArg } from '@/utils/serverScope' -const props = defineProps<{ +const props = withDefaults(defineProps<{ /** 是否显示,默认 true。设为 false 可强制隐藏 */ visible?: boolean -}>() +}>(), { + // visible 必须显式给默认值 true:Vue 会把「未传的 Boolean prop」强制转成 false, + // 不给默认值时 props.visible 恒为 false,`visible !== false` 判定失败 → 横幅永不显示 + visible: true, +}) // 综合判断:外部未隐藏,且满足特权模式触发条件之一 const show = computed( diff --git a/src/components/CrudTable.vue b/src/components/CrudTable.vue index f5ba46e..e5bd32a 100644 --- a/src/components/CrudTable.vue +++ b/src/components/CrudTable.vue @@ -20,7 +20,7 @@ function isAutoTimestampField(field: string): boolean { * 用法: * 带行选择与详情跳转: */ -const props = defineProps<{ +const props = withDefaults(defineProps<{ /** 表名(对应后端实体) */ table: string /** 标题 */ @@ -86,7 +86,12 @@ const props = defineProps<{ * (用于 role_scope 非管理员场景,如 Products/Orders 仅管理员可改)。 */ editable?: boolean -}>() +}>(), { + // editable 必须显式给默认值 true:Vue 会把「未传的 Boolean prop」强制转成 false, + // 不给默认值时 props.editable 恒为 false,canEdit 判定失败 → 所有未传 editable 的 + // 表格都退化成只读(新增/批量删除/行内编辑/删除全消失,操作栏只剩「查看」) + editable: true, +}) // 是否可写:editable 未传视为可写;传 false 时隐藏新增/编辑/删除入口(只读视图) const canEdit = computed(() => props.editable !== false)