Commit ce93e46faf1d7250dd3acd3fd97ccd6382b2f822

Authored by Vben
1 parent ee5fb223

fix(description): ensure that props respond

README.md
@@ -148,7 +148,7 @@ Support modern browsers, not IE @@ -148,7 +148,7 @@ Support modern browsers, not IE
148 148
149 ## Maintainer 149 ## Maintainer
150 150
151 -[@Vben](https://github.com/anncwb) 151 +[@Vben](https://github.com/anncwb)
152 152
153 ## Donate 153 ## Donate
154 154
@@ -156,7 +156,7 @@ If you think this project is helpful to you, you can help the author buy a cup o @@ -156,7 +156,7 @@ If you think this project is helpful to you, you can help the author buy a cup o
156 156
157 ![donate](https://anncwb.github.io/anncwb/images/sponsor.png) 157 ![donate](https://anncwb.github.io/anncwb/images/sponsor.png)
158 158
159 -[Paypal Me](https://www.paypal.com/paypalme/cvvben) 159 +<a style="display: block;width: 100px;height: 50px;line-height: 50px; color: #fff;text-align: center; background: #408aed;border-radius: 4px;" href="https://www.paypal.com/paypalme/cvvben">Paypal Me</a>
160 160
161 ## Discord 161 ## Discord
162 162
README.zh-CN.md
@@ -156,7 +156,7 @@ yarn build @@ -156,7 +156,7 @@ yarn build
156 156
157 ![donate](https://anncwb.github.io/anncwb/images/sponsor.png) 157 ![donate](https://anncwb.github.io/anncwb/images/sponsor.png)
158 158
159 -[Paypal Me](https://www.paypal.com/paypalme/cvvben) 159 +<a style="display: block;width: 100px;height: 50px;line-height: 50px; color: #fff;text-align: center; background: #408aed;border-radius: 4px;" href="https://www.paypal.com/paypalme/cvvben">Paypal Me</a>
160 160
161 ## 交流 161 ## 交流
162 162
src/components/Description/index.ts
1 // import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent'; 1 // import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
2 // export const Description = createAsyncComponent(() => import('./src/index')); 2 // export const Description = createAsyncComponent(() => import('./src/index'));
3 3
4 -import Description from './src/index'; 4 +import Description from './src/index.vue';
5 5
6 export { Description }; 6 export { Description };
7 export * from './src/types'; 7 export * from './src/types';
src/components/Description/src/index.tsx renamed to src/components/Description/src/index.vue
1 -import type { DescOptions, DescInstance, DescItem } from './types';  
2 -  
3 -import { defineComponent, computed, ref, unref, CSSProperties } from 'vue';  
4 -import { get } from 'lodash-es';  
5 -import { Descriptions } from 'ant-design-vue';  
6 -import { DescriptionsProps } from 'ant-design-vue/es/descriptions/index';  
7 -import { CollapseContainer, CollapseContainerOptions } from '/@/components/Container/index';  
8 -  
9 -import descProps from './props';  
10 -  
11 -import { isFunction } from '/@/utils/is';  
12 -import { getSlot } from '/@/utils/helper/tsxHelper';  
13 -import { cloneDeep } from 'lodash-es';  
14 -import { deepMerge } from '/@/utils';  
15 -  
16 -const prefixCls = 'description';  
17 -export default defineComponent({  
18 - name: 'Description',  
19 - props: descProps,  
20 - emits: ['register'],  
21 - setup(props, { attrs, slots, emit }) {  
22 - const propsRef = ref<Partial<DescOptions> | null>(null);  
23 -  
24 - // Custom title component: get title  
25 - const getMergeProps = computed(() => {  
26 - return {  
27 - ...props,  
28 - ...(unref(propsRef) as Recordable),  
29 - } as DescOptions;  
30 - });  
31 -  
32 - const getProps = computed(() => {  
33 - const opt = {  
34 - ...unref(getMergeProps),  
35 - title: undefined,  
36 - };  
37 - return opt as DescOptions;  
38 - });  
39 -  
40 - /**  
41 - * @description: Whether to setting title  
42 - */  
43 - const useWrapper = computed(() => !!unref(getMergeProps).title);  
44 -  
45 - /**  
46 - * @description: Get configuration Collapse  
47 - */  
48 - const getCollapseOptions = computed(  
49 - (): CollapseContainerOptions => { 1 +<script lang="tsx">
  2 + import type { DescOptions, DescInstance, DescItem } from './types';
  3 + import type { DescriptionsProps } from 'ant-design-vue/es/descriptions/index';
  4 + import type { CSSProperties } from 'vue';
  5 + import type { CollapseContainerOptions } from '/@/components/Container/index';
  6 +
  7 + import { defineComponent, computed, ref, unref } from 'vue';
  8 + import { get } from 'lodash-es';
  9 + import { Descriptions } from 'ant-design-vue';
  10 + import { CollapseContainer } from '/@/components/Container/index';
  11 +
  12 + import { useDesign } from '/@/hooks/web/useDesign';
  13 +
  14 + import { isFunction } from '/@/utils/is';
  15 + import { getSlot } from '/@/utils/helper/tsxHelper';
  16 + import { cloneDeep } from 'lodash-es';
  17 + import { deepMerge } from '/@/utils';
  18 +
  19 + import descProps from './props';
  20 + import { useAttrs } from '/@/hooks/core/useAttrs';
  21 +
  22 + export default defineComponent({
  23 + name: 'Description',
  24 + props: descProps,
  25 + emits: ['register'],
  26 + setup(props, { slots, emit }) {
  27 + const propsRef = ref<Partial<DescOptions> | null>(null);
  28 +
  29 + const { prefixCls } = useDesign('description');
  30 + const attrs = useAttrs();
  31 +
  32 + // Custom title component: get title
  33 + const getMergeProps = computed(() => {
50 return { 34 return {
51 - // Cannot be expanded by default  
52 - canExpand: false,  
53 - ...unref(getProps).collapseOptions, 35 + ...props,
  36 + ...(unref(propsRef) as Recordable),
  37 + } as DescOptions;
  38 + });
  39 +
  40 + const getProps = computed(() => {
  41 + const opt = {
  42 + ...unref(getMergeProps),
  43 + title: undefined,
54 }; 44 };
55 - }  
56 - );  
57 -  
58 - const getDescriptionsProps = computed(() => {  
59 - return { ...attrs, ...unref(getProps) } as DescriptionsProps;  
60 - });  
61 -  
62 - /**  
63 - * @description:设置desc  
64 - */  
65 - function setDescProps(descProps: Partial<DescOptions>): void {  
66 - // Keep the last setDrawerProps  
67 - const mergeProps = deepMerge(unref(propsRef) || {}, descProps);  
68 - propsRef.value = cloneDeep(mergeProps);  
69 - }  
70 -  
71 - // Prevent line breaks  
72 - function renderLabel({ label, labelMinWidth, labelStyle }: DescItem) {  
73 - if (!labelStyle && !labelMinWidth) {  
74 - return label;  
75 - } 45 + return opt as DescOptions;
  46 + });
  47 +
  48 + /**
  49 + * @description: Whether to setting title
  50 + */
  51 + const useWrapper = computed(() => !!unref(getMergeProps).title);
  52 +
  53 + /**
  54 + * @description: Get configuration Collapse
  55 + */
  56 + const getCollapseOptions = computed(
  57 + (): CollapseContainerOptions => {
  58 + return {
  59 + // Cannot be expanded by default
  60 + canExpand: false,
  61 + ...unref(getProps).collapseOptions,
  62 + };
  63 + }
  64 + );
76 65
77 - const labelStyles: CSSProperties = {  
78 - ...labelStyle, 66 + const getDescriptionsProps = computed(() => {
  67 + return { ...unref(attrs), ...unref(getProps) } as DescriptionsProps;
  68 + });
79 69
80 - minWidth: `${labelMinWidth}px `,  
81 - };  
82 - return <div style={labelStyles}>{label}</div>;  
83 - }  
84 -  
85 - function renderItem() {  
86 - const { schema, data } = unref(getProps);  
87 - return unref(schema)  
88 - .map((item) => {  
89 - const { render, field, span, show, contentMinWidth } = item;  
90 -  
91 - if (show && isFunction(show) && !show(data)) {  
92 - return null;  
93 - }  
94 -  
95 - const getContent = () => {  
96 - const _data = unref(data);  
97 - const getField = get(_data, field);  
98 - return isFunction(render) ? render(getField, _data) : getField ?? '';  
99 - }; 70 + /**
  71 + * @description:设置desc
  72 + */
  73 + function setDescProps(descProps: Partial<DescOptions>): void {
  74 + // Keep the last setDrawerProps
  75 + propsRef.value = { ...(unref(propsRef) as Recordable), ...descProps } as Recordable;
  76 + }
100 77
101 - const width = contentMinWidth;  
102 - return (  
103 - <Descriptions.Item label={renderLabel(item)} key={field} span={span}>  
104 - {() => {  
105 - if (!contentMinWidth) {  
106 - return getContent();  
107 - }  
108 - const style: CSSProperties = {  
109 - minWidth: `${width}px`,  
110 - };  
111 - return <div style={style}>{getContent()}</div>;  
112 - }}  
113 - </Descriptions.Item>  
114 - );  
115 - })  
116 - .filter((item) => !!item);  
117 - }  
118 -  
119 - const renderDesc = () => {  
120 - return (  
121 - <Descriptions class={`${prefixCls}`} {...(unref(getDescriptionsProps) as any)}>  
122 - {renderItem()}  
123 - </Descriptions>  
124 - );  
125 - }; 78 + // Prevent line breaks
  79 + function renderLabel({ label, labelMinWidth, labelStyle }: DescItem) {
  80 + if (!labelStyle && !labelMinWidth) {
  81 + return label;
  82 + }
126 83
127 - const renderContainer = () => {  
128 - const content = props.useCollapse ? renderDesc() : <div>{renderDesc()}</div>;  
129 - // Reduce the dom level 84 + const labelStyles: CSSProperties = {
  85 + ...labelStyle,
130 86
131 - if (!props.useCollapse) {  
132 - return content; 87 + minWidth: `${labelMinWidth}px `,
  88 + };
  89 + return <div style={labelStyles}>{label}</div>;
133 } 90 }
134 91
135 - const { canExpand, helpMessage } = unref(getCollapseOptions);  
136 - const { title } = unref(getMergeProps); 92 + function renderItem() {
  93 + const { schema, data } = unref(getProps);
  94 + return unref(schema)
  95 + .map((item) => {
  96 + const { render, field, span, show, contentMinWidth } = item;
  97 +
  98 + if (show && isFunction(show) && !show(data)) {
  99 + return null;
  100 + }
  101 +
  102 + const getContent = () => {
  103 + const _data = unref(getProps)?.data;
  104 + if (!_data) return null;
  105 + const getField = get(_data, field);
  106 + return isFunction(render) ? render(getField, _data) : getField ?? '';
  107 + };
  108 +
  109 + const width = contentMinWidth;
  110 + return (
  111 + <Descriptions.Item label={renderLabel(item)} key={field} span={span}>
  112 + {() => {
  113 + if (!contentMinWidth) {
  114 + return getContent();
  115 + }
  116 + const style: CSSProperties = {
  117 + minWidth: `${width}px`,
  118 + };
  119 + return <div style={style}>{getContent()}</div>;
  120 + }}
  121 + </Descriptions.Item>
  122 + );
  123 + })
  124 + .filter((item) => !!item);
  125 + }
137 126
138 - return (  
139 - <CollapseContainer title={title} canExpan={canExpand} helpMessage={helpMessage}>  
140 - {{  
141 - default: () => content,  
142 - action: () => getSlot(slots, 'action'),  
143 - }}  
144 - </CollapseContainer>  
145 - );  
146 - }; 127 + const renderDesc = () => {
  128 + return (
  129 + <Descriptions class={`${prefixCls}`} {...(unref(getDescriptionsProps) as any)}>
  130 + {renderItem()}
  131 + </Descriptions>
  132 + );
  133 + };
  134 +
  135 + const renderContainer = () => {
  136 + const content = props.useCollapse ? renderDesc() : <div>{renderDesc()}</div>;
  137 + // Reduce the dom level
  138 +
  139 + if (!props.useCollapse) {
  140 + return content;
  141 + }
  142 +
  143 + const { canExpand, helpMessage } = unref(getCollapseOptions);
  144 + const { title } = unref(getMergeProps);
  145 +
  146 + return (
  147 + <CollapseContainer title={title} canExpan={canExpand} helpMessage={helpMessage}>
  148 + {{
  149 + default: () => content,
  150 + action: () => getSlot(slots, 'action'),
  151 + }}
  152 + </CollapseContainer>
  153 + );
  154 + };
147 155
148 - const methods: DescInstance = {  
149 - setDescProps,  
150 - }; 156 + const methods: DescInstance = {
  157 + setDescProps,
  158 + };
151 159
152 - emit('register', methods);  
153 - return () => (unref(useWrapper) ? renderContainer() : renderDesc());  
154 - },  
155 -}); 160 + emit('register', methods);
  161 + return () => (unref(useWrapper) ? renderContainer() : renderDesc());
  162 + },
  163 + });
  164 +</script>
src/components/Description/src/props.ts
1 import type { PropType } from 'vue'; 1 import type { PropType } from 'vue';
2 import type { CollapseContainerOptions } from '/@/components/Container'; 2 import type { CollapseContainerOptions } from '/@/components/Container';
3 import type { DescItem } from './types'; 3 import type { DescItem } from './types';
4 -  
5 import { propTypes } from '/@/utils/propTypes'; 4 import { propTypes } from '/@/utils/propTypes';
6 export default { 5 export default {
7 useCollapse: propTypes.bool.def(true), 6 useCollapse: propTypes.bool.def(true),
8 -  
9 title: propTypes.string.def(''), 7 title: propTypes.string.def(''),
10 -  
11 size: propTypes.oneOf(['small', 'default', 'middle', undefined]).def('small'), 8 size: propTypes.oneOf(['small', 'default', 'middle', undefined]).def('small'),
12 -  
13 bordered: propTypes.bool.def(true), 9 bordered: propTypes.bool.def(true),
14 -  
15 column: { 10 column: {
16 type: [Number, Object] as PropType<number | Recordable>, 11 type: [Number, Object] as PropType<number | Recordable>,
17 default: () => { 12 default: () => {
18 return { xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }; 13 return { xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 };
19 }, 14 },
20 }, 15 },
21 -  
22 collapseOptions: { 16 collapseOptions: {
23 type: Object as PropType<CollapseContainerOptions>, 17 type: Object as PropType<CollapseContainerOptions>,
24 default: null, 18 default: null,
src/components/Page/src/PageFooter.vue
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 17
18 export default defineComponent({ 18 export default defineComponent({
19 name: 'PageFooter', 19 name: 'PageFooter',
  20 + inheritAttrs: false,
20 setup() { 21 setup() {
21 const { prefixCls } = useDesign('page-footer'); 22 const { prefixCls } = useDesign('page-footer');
22 const { getCalcContentWidth } = useMenuSetting(); 23 const { getCalcContentWidth } = useMenuSetting();
src/components/Page/src/PageWrapper.vue
@@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
37 import { PageHeader } from 'ant-design-vue'; 37 import { PageHeader } from 'ant-design-vue';
38 export default defineComponent({ 38 export default defineComponent({
39 name: 'PageWrapper', 39 name: 'PageWrapper',
  40 + inheritAttrs: false,
40 components: { PageFooter, PageHeader }, 41 components: { PageFooter, PageHeader },
41 props: { 42 props: {
42 dense: propTypes.bool, 43 dense: propTypes.bool,
src/views/demo/comp/desc/index.vue
@@ -72,12 +72,13 @@ @@ -72,12 +72,13 @@
72 schema: schema, 72 schema: schema,
73 }); 73 });
74 74
75 - const [register1] = useDescription({ 75 + const [register1, { setDescProps }] = useDescription({
76 title: '无边框', 76 title: '无边框',
77 bordered: false, 77 bordered: false,
78 data: mockData, 78 data: mockData,
79 schema: schema, 79 schema: schema,
80 }); 80 });
  81 +
81 return { mockData, schema, register, register1 }; 82 return { mockData, schema, register, register1 };
82 }, 83 },
83 }); 84 });