Commit 819127e807123cccc7ae50f0fdffb43a662465d4
1 parent
b71e4e51
fix: fix descriotions title not work
Showing
4 changed files
with
55 additions
and
88 deletions
src/components/Description/index.ts
1 | -export { default as Description } from './src/index'; | 1 | +import DescriptionLib from './src/index'; |
2 | + | ||
3 | +import { withInstall } from '../util'; | ||
4 | + | ||
2 | export * from './src/types'; | 5 | export * from './src/types'; |
3 | export { useDescription } from './src/useDescription'; | 6 | export { useDescription } from './src/useDescription'; |
7 | + | ||
8 | +export const Description = withInstall(DescriptionLib); |
src/components/Description/src/index.tsx
@@ -2,7 +2,9 @@ import type { DescOptions, DescInstance, DescItem } from './types'; | @@ -2,7 +2,9 @@ import type { DescOptions, DescInstance, DescItem } from './types'; | ||
2 | 2 | ||
3 | import { defineComponent, computed, ref, unref, CSSProperties } from 'vue'; | 3 | import { defineComponent, computed, ref, unref, CSSProperties } from 'vue'; |
4 | import { Descriptions } from 'ant-design-vue'; | 4 | import { Descriptions } from 'ant-design-vue'; |
5 | +import { DescriptionsProps } from 'ant-design-vue/es/descriptions/index'; | ||
5 | import { CollapseContainer, CollapseContainerOptions } from '/@/components/Container/index'; | 6 | import { CollapseContainer, CollapseContainerOptions } from '/@/components/Container/index'; |
7 | + | ||
6 | import descProps from './props'; | 8 | import descProps from './props'; |
7 | 9 | ||
8 | import { isFunction } from '/@/utils/is'; | 10 | import { isFunction } from '/@/utils/is'; |
@@ -17,29 +19,27 @@ export default defineComponent({ | @@ -17,29 +19,27 @@ export default defineComponent({ | ||
17 | emits: ['register'], | 19 | emits: ['register'], |
18 | setup(props, { attrs, slots, emit }) { | 20 | setup(props, { attrs, slots, emit }) { |
19 | const propsRef = ref<Partial<DescOptions> | null>(null); | 21 | const propsRef = ref<Partial<DescOptions> | null>(null); |
22 | + | ||
20 | // Custom title component: get title | 23 | // Custom title component: get title |
21 | const getMergeProps = computed(() => { | 24 | const getMergeProps = computed(() => { |
22 | return { | 25 | return { |
23 | ...props, | 26 | ...props, |
24 | - ...unref(propsRef), | ||
25 | - }; | 27 | + ...(unref(propsRef) as any), |
28 | + } as DescOptions; | ||
26 | }); | 29 | }); |
27 | 30 | ||
28 | const getProps = computed(() => { | 31 | const getProps = computed(() => { |
29 | const opt = { | 32 | const opt = { |
30 | - ...props, | ||
31 | - ...(unref(propsRef) || {}), | 33 | + ...unref(getMergeProps), |
32 | title: undefined, | 34 | title: undefined, |
33 | }; | 35 | }; |
34 | - return opt; | 36 | + return opt as DescOptions; |
35 | }); | 37 | }); |
36 | 38 | ||
37 | /** | 39 | /** |
38 | * @description: Whether to setting title | 40 | * @description: Whether to setting title |
39 | */ | 41 | */ |
40 | - const useWrapper = computed(() => { | ||
41 | - return !!unref(getMergeProps).title; | ||
42 | - }); | 42 | + const useWrapper = computed(() => !!unref(getMergeProps).title); |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * @description: Get configuration Collapse | 45 | * @description: Get configuration Collapse |
@@ -54,6 +54,10 @@ export default defineComponent({ | @@ -54,6 +54,10 @@ export default defineComponent({ | ||
54 | } | 54 | } |
55 | ); | 55 | ); |
56 | 56 | ||
57 | + const getDescriptionsProps = computed(() => { | ||
58 | + return { ...attrs, ...unref(getProps) } as DescriptionsProps; | ||
59 | + }); | ||
60 | + | ||
57 | /** | 61 | /** |
58 | * @description:设置desc | 62 | * @description:设置desc |
59 | */ | 63 | */ |
@@ -63,12 +67,6 @@ export default defineComponent({ | @@ -63,12 +67,6 @@ export default defineComponent({ | ||
63 | propsRef.value = cloneDeep(mergeProps); | 67 | propsRef.value = cloneDeep(mergeProps); |
64 | } | 68 | } |
65 | 69 | ||
66 | - const methods: DescInstance = { | ||
67 | - setDescProps, | ||
68 | - }; | ||
69 | - | ||
70 | - emit('register', methods); | ||
71 | - | ||
72 | // Prevent line breaks | 70 | // Prevent line breaks |
73 | function renderLabel({ label, labelMinWidth, labelStyle }: DescItem) { | 71 | function renderLabel({ label, labelMinWidth, labelStyle }: DescItem) { |
74 | if (!labelStyle && !labelMinWidth) { | 72 | if (!labelStyle && !labelMinWidth) { |
@@ -87,33 +85,27 @@ export default defineComponent({ | @@ -87,33 +85,27 @@ export default defineComponent({ | ||
87 | const { schema } = unref(getProps); | 85 | const { schema } = unref(getProps); |
88 | return unref(schema).map((item) => { | 86 | return unref(schema).map((item) => { |
89 | const { render, field, span, show, contentMinWidth } = item; | 87 | const { render, field, span, show, contentMinWidth } = item; |
90 | - const { data } = unref(getProps) as any; | 88 | + const { data } = unref(getProps) as DescOptions; |
91 | 89 | ||
92 | if (show && isFunction(show) && !show(data)) { | 90 | if (show && isFunction(show) && !show(data)) { |
93 | return null; | 91 | return null; |
94 | } | 92 | } |
95 | 93 | ||
96 | const getContent = () => | 94 | const getContent = () => |
97 | - isFunction(render) | ||
98 | - ? render(data && data[field], data) | ||
99 | - : unref(data) && unref(data)[field]; | 95 | + isFunction(render) ? render(data?.[field], data) : unref(data) && unref(data)[field]; |
100 | 96 | ||
101 | const width = contentMinWidth; | 97 | const width = contentMinWidth; |
102 | return ( | 98 | return ( |
103 | <Descriptions.Item label={renderLabel(item)} key={field} span={span}> | 99 | <Descriptions.Item label={renderLabel(item)} key={field} span={span}> |
104 | - {() => | ||
105 | - contentMinWidth ? ( | ||
106 | - <div | ||
107 | - style={{ | ||
108 | - minWidth: `${width}px`, | ||
109 | - }} | ||
110 | - > | ||
111 | - {getContent()} | ||
112 | - </div> | ||
113 | - ) : ( | ||
114 | - getContent() | ||
115 | - ) | ||
116 | - } | 100 | + {() => { |
101 | + if (!contentMinWidth) { | ||
102 | + return getContent(); | ||
103 | + } | ||
104 | + const style: CSSProperties = { | ||
105 | + minWidth: `${width}px`, | ||
106 | + }; | ||
107 | + return <div style={style}>{getContent()}</div>; | ||
108 | + }} | ||
117 | </Descriptions.Item> | 109 | </Descriptions.Item> |
118 | ); | 110 | ); |
119 | }); | 111 | }); |
@@ -121,7 +113,7 @@ export default defineComponent({ | @@ -121,7 +113,7 @@ export default defineComponent({ | ||
121 | 113 | ||
122 | const renderDesc = () => { | 114 | const renderDesc = () => { |
123 | return ( | 115 | return ( |
124 | - <Descriptions class={`${prefixCls}`} {...{ ...attrs, ...(unref(getProps) as any) }}> | 116 | + <Descriptions class={`${prefixCls}`} {...(unref(getDescriptionsProps) as any)}> |
125 | {() => renderItem()} | 117 | {() => renderItem()} |
126 | </Descriptions> | 118 | </Descriptions> |
127 | ); | 119 | ); |
@@ -130,19 +122,29 @@ export default defineComponent({ | @@ -130,19 +122,29 @@ export default defineComponent({ | ||
130 | const renderContainer = () => { | 122 | const renderContainer = () => { |
131 | const content = props.useCollapse ? renderDesc() : <div>{renderDesc()}</div>; | 123 | const content = props.useCollapse ? renderDesc() : <div>{renderDesc()}</div>; |
132 | // Reduce the dom level | 124 | // Reduce the dom level |
133 | - const { title, canExpand, helpMessage } = unref(getCollapseOptions); | ||
134 | - return props.useCollapse ? ( | 125 | + |
126 | + if (!props.useCollapse) { | ||
127 | + return content; | ||
128 | + } | ||
129 | + | ||
130 | + const { canExpand, helpMessage } = unref(getCollapseOptions); | ||
131 | + const { title } = unref(getMergeProps); | ||
132 | + | ||
133 | + return ( | ||
135 | <CollapseContainer title={title} canExpan={canExpand} helpMessage={helpMessage}> | 134 | <CollapseContainer title={title} canExpan={canExpand} helpMessage={helpMessage}> |
136 | {{ | 135 | {{ |
137 | default: () => content, | 136 | default: () => content, |
138 | action: () => getSlot(slots, 'action'), | 137 | action: () => getSlot(slots, 'action'), |
139 | }} | 138 | }} |
140 | </CollapseContainer> | 139 | </CollapseContainer> |
141 | - ) : ( | ||
142 | - content | ||
143 | ); | 140 | ); |
144 | }; | 141 | }; |
145 | 142 | ||
143 | + const methods: DescInstance = { | ||
144 | + setDescProps, | ||
145 | + }; | ||
146 | + | ||
147 | + emit('register', methods); | ||
146 | return () => (unref(useWrapper) ? renderContainer() : renderDesc()); | 148 | return () => (unref(useWrapper) ? renderContainer() : renderDesc()); |
147 | }, | 149 | }, |
148 | }); | 150 | }); |
src/components/Description/src/props.ts
@@ -5,15 +5,20 @@ import type { DescItem } from './types'; | @@ -5,15 +5,20 @@ import type { DescItem } from './types'; | ||
5 | import { propTypes } from '/@/utils/propTypes'; | 5 | import { propTypes } from '/@/utils/propTypes'; |
6 | export default { | 6 | export default { |
7 | useCollapse: propTypes.bool.def(true), | 7 | useCollapse: propTypes.bool.def(true), |
8 | + | ||
8 | title: propTypes.string.def(''), | 9 | title: propTypes.string.def(''), |
10 | + | ||
9 | size: propTypes.oneOf(['small', 'default', 'middle', undefined]).def('small'), | 11 | size: propTypes.oneOf(['small', 'default', 'middle', undefined]).def('small'), |
12 | + | ||
10 | bordered: propTypes.bool.def(true), | 13 | bordered: propTypes.bool.def(true), |
14 | + | ||
11 | column: { | 15 | column: { |
12 | type: [Number, Object] as PropType<number | any>, | 16 | type: [Number, Object] as PropType<number | any>, |
13 | default: () => { | 17 | default: () => { |
14 | return { xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }; | 18 | return { xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }; |
15 | }, | 19 | }, |
16 | }, | 20 | }, |
21 | + | ||
17 | collapseOptions: { | 22 | collapseOptions: { |
18 | type: Object as PropType<CollapseContainerOptions>, | 23 | type: Object as PropType<CollapseContainerOptions>, |
19 | default: null, | 24 | default: null, |
src/components/Description/src/types.ts
1 | -import type { VNode } from 'vue'; | 1 | +import type { VNode, CSSProperties } from 'vue'; |
2 | import type { CollapseContainerOptions } from '/@/components/Container/index'; | 2 | import type { CollapseContainerOptions } from '/@/components/Container/index'; |
3 | +import type { DescriptionsProps } from 'ant-design-vue/es/descriptions/index'; | ||
3 | 4 | ||
4 | export interface DescItem { | 5 | export interface DescItem { |
5 | labelMinWidth?: number; | 6 | labelMinWidth?: number; |
6 | 7 | ||
7 | contentMinWidth?: number; | 8 | contentMinWidth?: number; |
8 | 9 | ||
9 | - labelStyle?: any; | 10 | + labelStyle?: CSSProperties; |
10 | 11 | ||
11 | field: string; | 12 | field: string; |
12 | - label: any; | 13 | + label: string | VNode | JSX.Element; |
13 | // Merge column | 14 | // Merge column |
14 | span?: number; | 15 | span?: number; |
15 | show?: (...arg: any) => boolean; | 16 | show?: (...arg: any) => boolean; |
16 | // render | 17 | // render |
17 | - render?: (val: string, data: any) => VNode | undefined | Element | string | number; | 18 | + render?: (val: string, data: any) => VNode | undefined | JSX.Element | Element | string | number; |
18 | } | 19 | } |
19 | 20 | ||
20 | -export interface DescOptions { | 21 | +export interface DescOptions extends DescriptionsProps { |
21 | // Whether to include the collapse component | 22 | // Whether to include the collapse component |
22 | useCollapse?: boolean; | 23 | useCollapse?: boolean; |
23 | /** | 24 | /** |
@@ -35,52 +36,6 @@ export interface DescOptions { | @@ -35,52 +36,6 @@ export interface DescOptions { | ||
35 | * @type CollapseContainerOptions | 36 | * @type CollapseContainerOptions |
36 | */ | 37 | */ |
37 | collapseOptions?: CollapseContainerOptions; | 38 | collapseOptions?: CollapseContainerOptions; |
38 | - /** | ||
39 | - * descriptions size type | ||
40 | - * @default 'default' | ||
41 | - * @type string | ||
42 | - */ | ||
43 | - size?: 'default' | 'middle' | 'small'; | ||
44 | - | ||
45 | - /** | ||
46 | - * custom prefixCls | ||
47 | - * @type string | ||
48 | - */ | ||
49 | - prefixCls?: string; | ||
50 | - | ||
51 | - /** | ||
52 | - * whether descriptions have border | ||
53 | - * @default false | ||
54 | - * @type boolean | ||
55 | - */ | ||
56 | - bordered?: boolean; | ||
57 | - | ||
58 | - /** | ||
59 | - * custom title | ||
60 | - * @type any | ||
61 | - */ | ||
62 | - title?: any; | ||
63 | - | ||
64 | - /** | ||
65 | - * the number of descriptionsitem in one line | ||
66 | - * @default 3 | ||
67 | - * @type number | object | ||
68 | - */ | ||
69 | - column?: number | object; | ||
70 | - | ||
71 | - /** | ||
72 | - * descriptions layout | ||
73 | - * @default 'horizontal' | ||
74 | - * @type string | ||
75 | - */ | ||
76 | - layout?: 'horizontal' | 'vertical'; | ||
77 | - | ||
78 | - /** | ||
79 | - * whether have colon in descriptionsitem | ||
80 | - * @default true | ||
81 | - * @type boolean | ||
82 | - */ | ||
83 | - colon?: boolean; | ||
84 | } | 39 | } |
85 | 40 | ||
86 | export interface DescInstance { | 41 | export interface DescInstance { |