feat: desc 支持 嵌套字段

This commit is contained in:
xingyu4j
2025-10-21 14:40:20 +08:00
parent e5d69952cb
commit cc4a99c47d

View File

@@ -5,9 +5,9 @@ import type { CSSProperties, PropType, Slots } from 'vue';
import type { DescriptionItemSchema, DescriptionProps } from './typing'; import type { DescriptionItemSchema, DescriptionProps } from './typing';
import { computed, defineComponent, ref, toRefs, unref, useAttrs } from 'vue'; import { computed, defineComponent, ref, unref, useAttrs } from 'vue';
import { get, isFunction } from '@vben/utils'; import { get, getNestedValue, isFunction } from '@vben/utils';
import { Card, Descriptions } from 'ant-design-vue'; import { Card, Descriptions } from 'ant-design-vue';
@@ -110,15 +110,17 @@ export default defineComponent({
if (!_data) { if (!_data) {
return null; return null;
} }
const getField = get(_data, field); const getField = field.includes('.')
if ( ? (getNestedValue(_data, field) ?? get(_data, field))
getField && : get(_data, field);
!Object.prototype.hasOwnProperty.call(toRefs(_data), field) // if (
) { // getField &&
return isFunction(render) ? render!('', _data) : ''; // !Object.prototype.hasOwnProperty.call(toRefs(_data), field)
} // ) {
// return isFunction(render) ? render('', _data) : (getField ?? '');
// }
return isFunction(render) return isFunction(render)
? render!(getField, _data) ? render(getField, _data)
: (getField ?? ''); : (getField ?? '');
} }