fix(components): 修正 Boolean prop 缺默认值导致表格退化为只读
Vue 会把未传的 Boolean prop 强制转成 false,而代码按未传=undefined 判定:CrudTable 的 editable 未声明默认值,使 canEdit 恒为 false,所有未传 :editable 的表格操作栏只剩查看,新增/批量删除/行内编辑/删除全部消失(部门详情页部门员工子表即此现象);AdminBadge 的 visible 同样缺默认值,导致特权模式横幅从未显示。 两处均改用 withDefaults 显式声明默认 true,并同步部署产物(entry assets/index-Chv4xcO_.js)。
This commit is contained in:
1 parent
4c5def2533
commit
c98547ff1b
2 files changed
+13
-4
No files matched your search
@@ -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(
|
||||
|
||||
@@ -20,7 +20,7 @@ function isAutoTimestampField(field: string): boolean {
|
||||
* 用法:<CrudTable table="User" />
|
||||
* 带行选择与详情跳转:<CrudTable table="User" selectable :on-view="goDetail" />
|
||||
*/
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user