diff --git a/src/components/Scrollbar/src/util.ts b/src/components/Scrollbar/src/util.ts index c98b0b8ba..c6b689a62 100644 --- a/src/components/Scrollbar/src/util.ts +++ b/src/components/Scrollbar/src/util.ts @@ -1,4 +1,5 @@ import type { BarMap } from './types'; +import type { MergeAll } from '/@/utils/types'; export const BAR_MAP: BarMap = { vertical: { @@ -40,8 +41,16 @@ function extend(to: T, _from: K): T & K { return Object.assign(to, _from); } -export function toObject(arr: Array): Recordable { - const res = {}; +/** + * [ + * { name: 'zhangsan', age: 18 }, + * { sex: 'male', age: 20 } + * ] + * => + * { name: 'zhangsan', sex: 'male', age: 20 } + */ +export function toObject(arr: T): MergeAll { + const res = {} as MergeAll; for (let i = 0; i < arr.length; i++) { if (arr[i]) { extend(res, arr[i]); diff --git a/src/components/SimpleMenu/src/components/Menu.vue b/src/components/SimpleMenu/src/components/Menu.vue index 28e0b3e6b..6a967aced 100644 --- a/src/components/SimpleMenu/src/components/Menu.vue +++ b/src/components/SimpleMenu/src/components/Menu.vue @@ -45,11 +45,18 @@ }, emits: ['select', 'open-change'], setup(props, { emit }) { - const rootMenuEmitter = mitt(); + const rootMenuEmitter = mitt<{ + 'on-update-opened': (string | number)[]; + 'on-menu-item-select': string | number; + 'open-name-change': { + name: string; + opened: boolean; + }; + }>(); const instance = getCurrentInstance(); const currentActiveName = ref(''); - const openedNames = ref([]); + const openedNames = ref<(string | number)[]>([]); const { prefixCls } = useDesign('menu'); @@ -95,13 +102,13 @@ rootMenuEmitter.emit('on-update-opened', openedNames.value); } - function addSubMenu(name: string) { + function addSubMenu(name: string | number) { if (openedNames.value.includes(name)) return; openedNames.value.push(name); updateOpened(); } - function removeSubMenu(name: string) { + function removeSubMenu(name: string | number) { openedNames.value = openedNames.value.filter((item) => item !== name); updateOpened(); } @@ -131,7 +138,7 @@ onMounted(() => { openedNames.value = !props.collapse ? [...props.openNames] : []; updateOpened(); - rootMenuEmitter.on('on-menu-item-select', (name: string) => { + rootMenuEmitter.on('on-menu-item-select', (name: string | number) => { currentActiveName.value = name; nextTick(() => { diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts index d9e9ce686..80d74f8ab 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -5,6 +5,7 @@ import type { TableRowSelection as ITableRowSelection, Key, } from 'ant-design-vue/lib/table/interface'; + import type { ColumnProps } from 'ant-design-vue/lib/table'; import { ComponentType } from './componentType'; @@ -94,7 +95,7 @@ export interface TableActionType { expandRows: (keys: (string | number)[]) => void; collapseAll: () => void; scrollTo: (pos: string) => void; // pos: id | "top" | "bottom" - getSelectRowKeys: () => string[]; + getSelectRowKeys: () => Key[]; deleteSelectRowByKey: (key: string) => void; setPagination: (info: Partial) => void; setTableData: (values: T[]) => void; diff --git a/src/components/Tree/src/types/tree.ts b/src/components/Tree/src/types/tree.ts index 8988d5986..785b7f2f2 100644 --- a/src/components/Tree/src/types/tree.ts +++ b/src/components/Tree/src/types/tree.ts @@ -46,7 +46,7 @@ export const treeProps = buildProps({ }, renderIcon: { - type: Function as PropType<(params: Recordable) => string>, + type: Function as PropType<(...params: any[]) => string>, }, helpMessage: { diff --git a/src/layouts/default/header/components/notify/NoticeList.vue b/src/layouts/default/header/components/notify/NoticeList.vue index 022feea25..6203718a9 100644 --- a/src/layouts/default/header/components/notify/NoticeList.vue +++ b/src/layouts/default/header/components/notify/NoticeList.vue @@ -113,11 +113,15 @@ const isTitleClickable = computed(() => !!props.onTitleClick); const getPagination = computed(() => { const { list, pageSize } = props; - if (pageSize > 0 && list && list.length > pageSize) { + + // compatible line 104 + // if typeof pageSize is boolean, Number(true) && 5 = 5, Number(false) && 5 = 0 + const size = isNumber(pageSize) ? pageSize : Number(pageSize) && 5; + + if (size > 0 && list && list.length > size) { return { total: list.length, - pageSize, - //size: 'small', + pageSize: size, current: unref(current), onChange(page) { current.value = page; diff --git a/src/utils/types.ts b/src/utils/types.ts index 4453ec4ab..a853855ce 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -40,3 +40,26 @@ export type ComponentSize = 'large' | 'medium' | 'small' | 'mini'; export type StyleValue = string | CSSProperties | Array; export type Mutable = { -readonly [P in keyof T]: T[P] }; + +type Merge = { + [K in keyof O | keyof T]: K extends keyof T ? T[K] : K extends keyof O ? O[K] : never; +}; + +/** + * T = [ + * { name: string; age: number; }, + * { sex: 'male' | 'female'; age: string } + * ] + * => + * MergeAll = { + * name: string; + * sex: 'male' | 'female'; + * age: string + * } + */ +export type MergeAll = T extends [ + infer F extends object, + ...infer Rest extends object[], +] + ? MergeAll> + : R; diff --git a/src/views/demo/comp/modal/index.vue b/src/views/demo/comp/modal/index.vue index 8a44fb2d3..180b5a3c0 100644 --- a/src/views/demo/comp/modal/index.vue +++ b/src/views/demo/comp/modal/index.vue @@ -31,7 +31,12 @@ /> Prompt - + diff --git a/src/views/demo/tree/EditTree.vue b/src/views/demo/tree/EditTree.vue index c2f2ad492..d11005ed4 100644 --- a/src/views/demo/tree/EditTree.vue +++ b/src/views/demo/tree/EditTree.vue @@ -58,6 +58,8 @@ import { PlusOutlined, DeleteOutlined } from '@ant-design/icons-vue'; import { PageWrapper } from '/@/components/Page'; + import { EventDataNode } from 'ant-design-vue/es/vc-tree/interface'; + export default defineComponent({ components: { BasicTree, PageWrapper, Row, Col }, setup() { @@ -65,8 +67,8 @@ console.log(node); } - function getRightMenuList(node: any): ContextMenuItem[] { - return [ + function getRightMenuList(node: EventDataNode): Promise { + const menu = [ { label: '新增', handler: () => { @@ -82,6 +84,9 @@ icon: 'bx:bxs-folder-open', }, ]; + return new Promise((resolve) => { + resolve(menu); + }); } const actionList: TreeActionItem[] = [ { diff --git a/src/views/form-design/components/VFormDesign/components/ComponentProps.vue b/src/views/form-design/components/VFormDesign/components/ComponentProps.vue index 994cc9fa4..2736b37a9 100644 --- a/src/views/form-design/components/VFormDesign/components/ComponentProps.vue +++ b/src/views/form-design/components/VFormDesign/components/ComponentProps.vue @@ -14,17 +14,18 @@
- +