From c98547ff1be9f2fb3decd8c31a91addc86af3d97 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Tue, 29 Sep 2026 13:20:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(components):=20=E4=BF=AE=E6=AD=A3=20Boolean?= =?UTF-8?q?=20prop=20=E7=BC=BA=E9=BB=98=E8=AE=A4=E5=80=BC=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=A1=A8=E6=A0=BC=E9=80=80=E5=8C=96=E4=B8=BA=E5=8F=AA?= =?UTF-8?q?=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vue 会把未传的 Boolean prop 强制转成 false,而代码按未传=undefined 判定:CrudTable 的 editable 未声明默认值,使 canEdit 恒为 false,所有未传 :editable 的表格操作栏只剩查看,新增/批量删除/行内编辑/删除全部消失(部门详情页部门员工子表即此现象);AdminBadge 的 visible 同样缺默认值,导致特权模式横幅从未显示。 两处均改用 withDefaults 显式声明默认 true,并同步部署产物(entry assets/index-Chv4xcO_.js)。 --- src/components/AdminBadge.vue | 8 ++++++-- src/components/CrudTable.vue | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) 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)