Skip to content

Commit c7c95dd

Browse files
committed
chore: type Descrition,Drawer,Excel,Dropdown
1 parent 6dbbdba commit c7c95dd

File tree

21 files changed

+129
-138
lines changed

21 files changed

+129
-138
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import Description from './src/Description.vue';
1+
import { withInstall } from '/@/utils';
2+
import description from './src/Description.vue';
23

3-
export { Description };
4-
export * from './src/types';
4+
export * from './src/typing';
55
export { useDescription } from './src/useDescription';
6+
export const Description = withInstall(description);

src/components/Description/src/Description.vue

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
11
<script lang="tsx">
2-
import type { DescOptions, DescInstance, DescItem } from './types';
2+
import type { DescriptionProps, DescInstance, DescItem } from './typing';
33
import type { DescriptionsProps } from 'ant-design-vue/es/descriptions/index';
44
import type { CSSProperties } from 'vue';
55
import type { CollapseContainerOptions } from '/@/components/Container/index';
6-
76
import { defineComponent, computed, ref, unref } from 'vue';
87
import { get } from 'lodash-es';
98
import { Descriptions } from 'ant-design-vue';
109
import { CollapseContainer } from '/@/components/Container/index';
11-
1210
import { useDesign } from '/@/hooks/web/useDesign';
13-
1411
import { isFunction } from '/@/utils/is';
1512
import { getSlot } from '/@/utils/helper/tsxHelper';
16-
17-
import descProps from './props';
1813
import { useAttrs } from '/@/hooks/core/useAttrs';
1914
15+
const props = {
16+
useCollapse: { type: Boolean, default: true },
17+
title: { type: String, default: '' },
18+
size: {
19+
type: String,
20+
validator: (v) => ['small', 'default', 'middle', undefined].includes(v),
21+
default: 'small',
22+
},
23+
bordered: { type: Boolean, default: true },
24+
column: {
25+
type: [Number, Object] as PropType<number | Recordable>,
26+
default: () => {
27+
return { xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 };
28+
},
29+
},
30+
collapseOptions: {
31+
type: Object as PropType<CollapseContainerOptions>,
32+
default: null,
33+
},
34+
schema: {
35+
type: Array as PropType<DescItem[]>,
36+
default: () => [],
37+
},
38+
data: { type: Object },
39+
};
40+
2041
export default defineComponent({
2142
name: 'Description',
22-
props: descProps,
43+
props,
2344
emits: ['register'],
2445
setup(props, { slots, emit }) {
25-
const propsRef = ref<Partial<DescOptions> | null>(null);
46+
const propsRef = ref<Partial<DescriptionProps> | null>(null);
2647
2748
const { prefixCls } = useDesign('description');
2849
const attrs = useAttrs();
@@ -32,15 +53,15 @@
3253
return {
3354
...props,
3455
...(unref(propsRef) as Recordable),
35-
} as DescOptions;
56+
} as DescriptionProps;
3657
});
3758
3859
const getProps = computed(() => {
3960
const opt = {
4061
...unref(getMergeProps),
4162
title: undefined,
4263
};
43-
return opt as DescOptions;
64+
return opt as DescriptionProps;
4465
});
4566
4667
/**
@@ -66,7 +87,7 @@
6687
/**
6788
* @description:设置desc
6889
*/
69-
function setDescProps(descProps: Partial<DescOptions>): void {
90+
function setDescProps(descProps: Partial<DescriptionProps>): void {
7091
// Keep the last setDrawerProps
7192
propsRef.value = { ...(unref(propsRef) as Recordable), ...descProps } as Recordable;
7293
}
@@ -79,7 +100,6 @@
79100
80101
const labelStyles: CSSProperties = {
81102
...labelStyle,
82-
83103
minWidth: `${labelMinWidth}px `,
84104
};
85105
return <div style={labelStyles}>{label}</div>;
@@ -97,7 +117,9 @@
97117
98118
const getContent = () => {
99119
const _data = unref(getProps)?.data;
100-
if (!_data) return null;
120+
if (!_data) {
121+
return null;
122+
}
101123
const getField = get(_data, field);
102124
return isFunction(render) ? render(getField, _data) : getField ?? '';
103125
};
@@ -131,7 +153,6 @@
131153
const renderContainer = () => {
132154
const content = props.useCollapse ? renderDesc() : <div>{renderDesc()}</div>;
133155
// Reduce the dom level
134-
135156
if (!props.useCollapse) {
136157
return content;
137158
}

src/components/Description/src/props.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import type { DescriptionsProps } from 'ant-design-vue/es/descriptions/index';
44

55
export interface DescItem {
66
labelMinWidth?: number;
7-
87
contentMinWidth?: number;
9-
108
labelStyle?: CSSProperties;
11-
129
field: string;
1310
label: string | VNode | JSX.Element;
1411
// Merge column
@@ -21,7 +18,7 @@ export interface DescItem {
2118
) => VNode | undefined | JSX.Element | Element | string | number;
2219
}
2320

24-
export interface DescOptions extends DescriptionsProps {
21+
export interface DescriptionProps extends DescriptionsProps {
2522
// Whether to include the collapse component
2623
useCollapse?: boolean;
2724
/**
@@ -42,7 +39,7 @@ export interface DescOptions extends DescriptionsProps {
4239
}
4340

4441
export interface DescInstance {
45-
setDescProps(descProps: Partial<DescOptions>): void;
42+
setDescProps(descProps: Partial<DescriptionProps>): void;
4643
}
4744

4845
export type Register = (descInstance: DescInstance) => void;

src/components/Description/src/useDescription.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
import type { DescriptionProps, DescInstance, UseDescReturnType } from './typing';
12
import { ref, getCurrentInstance, unref } from 'vue';
23
import { isProdMode } from '/@/utils/env';
34

4-
import type { DescOptions, DescInstance, UseDescReturnType } from './types';
5-
6-
export function useDescription(props?: Partial<DescOptions>): UseDescReturnType {
5+
export function useDescription(props?: Partial<DescriptionProps>): UseDescReturnType {
76
if (!getCurrentInstance()) {
8-
throw new Error('Please put useDescription function in the setup function!');
7+
throw new Error('useDescription() can only be used inside setup() or functional components!');
98
}
10-
const descRef = ref<Nullable<DescInstance>>(null);
11-
const loadedRef = ref(false);
9+
const desc = ref<Nullable<DescInstance>>(null);
10+
const loaded = ref(false);
1211

1312
function register(instance: DescInstance) {
14-
if (unref(loadedRef) && isProdMode()) return;
15-
descRef.value = instance;
13+
if (unref(loaded) && isProdMode()) {
14+
return;
15+
}
16+
desc.value = instance;
1617
props && instance.setDescProps(props);
17-
loadedRef.value = true;
18+
loaded.value = true;
1819
}
1920

2021
const methods: DescInstance = {
21-
setDescProps: (descProps: Partial<DescOptions>): void => {
22-
unref(descRef)?.setDescProps(descProps);
22+
setDescProps: (descProps: Partial<DescriptionProps>): void => {
23+
unref(desc)?.setDescProps(descProps);
2324
},
2425
};
2526

src/components/Drawer/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import BasicDrawer from './src/BasicDrawer.vue';
1+
import { withInstall } from '/@/utils';
2+
import basicDrawer from './src/BasicDrawer.vue';
23

3-
export { BasicDrawer };
4-
export * from './src/types';
4+
export const BasicDrawer = withInstall(basicDrawer);
5+
export * from './src/typing';
56
export { useDrawer, useDrawerInner } from './src/useDrawer';

src/components/Drawer/src/BasicDrawer.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
</Drawer>
3232
</template>
3333
<script lang="ts">
34-
import type { DrawerInstance, DrawerProps } from './types';
34+
import type { DrawerInstance, DrawerProps } from './typing';
3535
import type { CSSProperties } from 'vue';
36-
3736
import {
3837
defineComponent,
3938
ref,
@@ -46,15 +45,12 @@
4645
getCurrentInstance,
4746
} from 'vue';
4847
import { Drawer } from 'ant-design-vue';
49-
5048
import { useI18n } from '/@/hooks/web/useI18n';
51-
5249
import { isFunction, isNumber } from '/@/utils/is';
5350
import { deepMerge } from '/@/utils';
5451
import DrawerFooter from './components/DrawerFooter.vue';
5552
import DrawerHeader from './components/DrawerHeader.vue';
5653
import { ScrollContainer } from '/@/components/Container';
57-
5854
import { basicProps } from './props';
5955
import { useDesign } from '/@/hooks/web/useDesign';
6056
import { useAttrs } from '/@/hooks/core/useAttrs';
@@ -167,7 +163,7 @@
167163
168164
function setDrawerProps(props: Partial<DrawerProps>): void {
169165
// Keep the last setDrawerProps
170-
propsRef.value = deepMerge(unref(propsRef) || {}, props);
166+
propsRef.value = deepMerge((unref(propsRef) as any) || {}, props);
171167
172168
if (Reflect.has(props, 'visible')) {
173169
visibleRef.value = !!props.visible;

src/components/Drawer/src/components/DrawerHeader.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
function handleClose() {
4141
emit('close');
4242
}
43+
4344
return { prefixCls, handleClose };
4445
},
4546
});

src/components/Drawer/src/props.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11
import type { PropType } from 'vue';
22

33
import { useI18n } from '/@/hooks/web/useI18n';
4-
import { propTypes } from '/@/utils/propTypes';
54
const { t } = useI18n();
65

76
export const footerProps = {
8-
confirmLoading: propTypes.bool,
7+
confirmLoading: { type: Boolean },
98
/**
109
* @description: Show close button
1110
*/
12-
showCancelBtn: propTypes.bool.def(true),
11+
showCancelBtn: { type: Boolean, default: true },
1312
cancelButtonProps: Object as PropType<Recordable>,
14-
cancelText: propTypes.string.def(t('common.cancelText')),
13+
cancelText: { type: String, default: t('common.cancelText') },
1514
/**
1615
* @description: Show confirmation button
1716
*/
18-
showOkBtn: propTypes.bool.def(true),
17+
showOkBtn: { type: Boolean, default: true },
1918
okButtonProps: Object as PropType<Recordable>,
20-
okText: propTypes.string.def(t('common.okText')),
21-
okType: propTypes.string.def('primary'),
22-
showFooter: propTypes.bool,
19+
okText: { type: String, default: t('common.okText') },
20+
okType: { type: String, default: 'primary' },
21+
showFooter: { type: Boolean },
2322
footerHeight: {
2423
type: [String, Number] as PropType<string | number>,
2524
default: 60,
2625
},
2726
};
2827
export const basicProps = {
29-
isDetail: propTypes.bool,
30-
title: propTypes.string.def(''),
31-
loadingText: propTypes.string,
32-
showDetailBack: propTypes.bool.def(true),
33-
visible: propTypes.bool,
34-
loading: propTypes.bool,
35-
maskClosable: propTypes.bool.def(true),
28+
isDetail: { type: Boolean },
29+
title: { type: String, default: '' },
30+
loadingText: { type: String },
31+
showDetailBack: { type: Boolean, default: true },
32+
visible: { type: Boolean },
33+
loading: { type: Boolean },
34+
maskClosable: { type: Boolean, default: true },
3635
getContainer: {
3736
type: [Object, String] as PropType<any>,
3837
},
@@ -44,7 +43,7 @@ export const basicProps = {
4443
type: [Function, Object] as PropType<any>,
4544
default: null,
4645
},
47-
triggerWindowResize: propTypes.bool,
48-
destroyOnClose: propTypes.bool,
46+
triggerWindowResize: { type: Boolean },
47+
destroyOnClose: { type: Boolean },
4948
...footerProps,
5049
};
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ export interface DrawerProps extends DrawerFooterProps {
181181
placement?: 'top' | 'right' | 'bottom' | 'left';
182182
afterVisibleChange?: (visible?: boolean) => void;
183183
keyboard?: boolean;
184-
185184
/**
186185
* Specify a callback that will be called when a user clicks mask, close button or Cancel button.
187186
*/

0 commit comments

Comments
 (0)