review:【全局】Description 组件
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
<script lang="tsx">
|
||||
import type { DescriptionItemSchema, DescriptionsOptions } from './typing';
|
||||
import type { DescriptionsProps } from 'ant-design-vue';
|
||||
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
import { Descriptions, DescriptionsItem } from 'ant-design-vue';
|
||||
import type { DescriptionItemSchema, DescriptionsOptions } from './typing';
|
||||
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
import { Descriptions, DescriptionsItem } from 'ant-design-vue';
|
||||
|
||||
/** 对 Descriptions 进行二次封装 */
|
||||
const Description = defineComponent({
|
||||
name: 'Descriptions',
|
||||
@@ -27,15 +29,21 @@ const Description = defineComponent({
|
||||
},
|
||||
|
||||
setup(props: DescriptionsOptions) {
|
||||
// TODO @puhui999:每个 field 的 slot 的考虑
|
||||
// TODO @puhui999:from 5.0:extra: () => getSlot(slots, 'extra')
|
||||
/** 过滤掉不需要展示的 */
|
||||
const shouldShowItem = (item: DescriptionItemSchema) => {
|
||||
if (item.hidden === undefined) return true;
|
||||
return typeof item.hidden === 'function' ? !item.hidden(props.data) : !item.hidden;
|
||||
return typeof item.hidden === 'function'
|
||||
? !item.hidden(props.data)
|
||||
: !item.hidden;
|
||||
};
|
||||
/** 渲染内容 */
|
||||
const renderContent = (item: DescriptionItemSchema) => {
|
||||
if (item.content) {
|
||||
return typeof item.content === 'function' ? item.content(props.data) : item.content;
|
||||
return typeof item.content === 'function'
|
||||
? item.content(props.data)
|
||||
: item.content;
|
||||
}
|
||||
return item.field ? props.data?.[item.field] : null;
|
||||
};
|
||||
@@ -67,5 +75,6 @@ const Description = defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
// TODO @puhui999:from 5.0:emits: ['register'] 事件
|
||||
export default Description;
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user