chore: fix type:check error (#3159)

This commit is contained in:
bowen 2023-10-17 09:29:43 +08:00 committed by GitHub
parent 0bb76a86d2
commit 18222ab0b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 82 additions and 24 deletions

View File

@ -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<T extends object, K extends object>(to: T, _from: K): T & K {
return Object.assign(to, _from);
}
export function toObject<T extends object>(arr: Array<T>): Recordable<T> {
const res = {};
/**
* [
* { name: 'zhangsan', age: 18 },
* { sex: 'male', age: 20 }
* ]
* =>
* { name: 'zhangsan', sex: 'male', age: 20 }
*/
export function toObject<T extends object[]>(arr: T): MergeAll<T> {
const res = {} as MergeAll<T>;
for (let i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);

View File

@ -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<string | number>('');
const openedNames = ref<string[]>([]);
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(() => {

View File

@ -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<PaginationProps>) => void;
setTableData: <T = Recordable>(values: T[]) => void;

View File

@ -46,7 +46,7 @@ export const treeProps = buildProps({
},
renderIcon: {
type: Function as PropType<(params: Recordable) => string>,
type: Function as PropType<(...params: any[]) => string>,
},
helpMessage: {

View File

@ -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;

View File

@ -40,3 +40,26 @@ export type ComponentSize = 'large' | 'medium' | 'small' | 'mini';
export type StyleValue = string | CSSProperties | Array<StyleValue>;
export type Mutable<T> = { -readonly [P in keyof T]: T[P] };
type Merge<O extends object, T extends object> = {
[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<T> = {
* name: string;
* sex: 'male' | 'female';
* age: string
* }
*/
export type MergeAll<T extends object[], R extends object = {}> = T extends [
infer F extends object,
...infer Rest extends object[],
]
? MergeAll<Rest, Merge<R, F>>
: R;

View File

@ -31,7 +31,12 @@
/>
<a-button type="primary" class="my-4" @click="handleCreatePrompt"> Prompt </a-button>
<component :is="currentModal" v-model:open="modalOpen" :userData="userData" />
<component
v-if="currentModal"
:is="currentModal"
v-model:open="modalOpen"
:userData="userData"
/>
<Modal1 @register="register1" :minHeight="100" />
<Modal2 @register="register2" />

View File

@ -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<ContextMenuItem[]> {
const menu = [
{
label: '新增',
handler: () => {
@ -82,6 +84,9 @@
icon: 'bx:bxs-folder-open',
},
];
return new Promise((resolve) => {
resolve(menu);
});
}
const actionList: TreeActionItem[] = [
{

View File

@ -14,17 +14,18 @@
<!-- 处理数组属性placeholder -->
<div v-if="item.children">
<component
v-for="(child, index) of item.children"
:key="index"
v-bind="child.componentProps"
:is="child.component"
v-model:value="formConfig.currentItem.componentProps[item.name][index]"
/>
<template v-for="(child, index) of item.children" :key="index">
<component
v-if="child.component"
v-bind="child.componentProps"
v-model:value="formConfig.currentItem.componentProps[item.name][index]"
:is="child.component"
/>
</template>
</div>
<!-- 如果不是数组则正常处理属性值 -->
<component
v-else
v-else-if="item.component"
class="component-prop"
v-bind="item.componentProps"
:is="item.component"

View File

@ -9,7 +9,7 @@
<div v-for="item of baseItemColumnProps" :key="item.name">
<FormItem :label="item.label" v-if="showProps(item.exclude)">
<component
v-if="formConfig.currentItem.colProps"
v-if="formConfig.currentItem.colProps && item.component"
class="component-props"
v-bind="item.componentProps"
:is="item.component"

View File

@ -9,6 +9,7 @@
<div v-for="item of baseFormItemProps" :key="item.name">
<FormItem :label="item.label" v-if="showProps(item.exclude)">
<component
v-if="item.component"
class="component-props"
v-bind="item.componentProps"
:is="item.component"
@ -19,6 +20,7 @@
<div v-for="item of advanceFormItemProps" :key="item.name">
<FormItem :label="item.label" v-if="showProps(item.exclude)">
<component
v-if="item.component"
class="component-props"
v-bind="item.componentProps"
:is="item.component"
@ -28,6 +30,7 @@
><div v-for="item of advanceFormItemColProps" :key="item.name">
<FormItem :label="item.label" v-if="showProps(item.exclude)">
<component
v-if="item.component"
class="component-props"
v-bind="item.componentProps"
:is="item.component"