Skip to content

Commit fdbaf55

Browse files
committed
fix: some ts type issue
1 parent 0d2b882 commit fdbaf55

File tree

17 files changed

+137
-123
lines changed

17 files changed

+137
-123
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"dependencies": {
3232
"@ant-design/icons-vue": "^6.1.0",
33-
"@vueuse/core": "^8.2.3",
33+
"@vueuse/core": "^8.2.4",
3434
"ant-design-vue": "3.1.0-rc.6",
3535
"axios": "^0.26.1",
3636
"core-js": "^3.21.1",
@@ -56,8 +56,8 @@
5656
"@types/lodash-es": "^4.17.6",
5757
"@types/node": "^17.0.23",
5858
"@types/webpack-env": "^1.16.3",
59-
"@typescript-eslint/eslint-plugin": "^5.17.0",
60-
"@typescript-eslint/parser": "^5.17.0",
59+
"@typescript-eslint/eslint-plugin": "^5.18.0",
60+
"@typescript-eslint/parser": "^5.18.0",
6161
"@vue/cli-plugin-babel": "^5.0.4",
6262
"@vue/cli-plugin-eslint": "^5.0.4",
6363
"@vue/cli-plugin-router": "^5.0.4",
@@ -78,7 +78,7 @@
7878
"lint-staged": "^12.3.7",
7979
"path-browserify": "^1.0.1",
8080
"postcss-html": "^1.3.0",
81-
"prettier": "^2.6.1",
81+
"prettier": "^2.6.2",
8282
"regenerator-runtime": "^0.13.9",
8383
"speed-measure-webpack-plugin": "^1.5.0",
8484
"stylelint": "^14.6.1",

src/assets/icons/moon.svg

+1
Loading

src/assets/icons/sun.svg

+1
Loading

src/components/basic/button/button.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
:type="buttonType"
66
:class="[`ant-btn-${type}`]"
77
>
8-
<template v-for="(value, key) in $slots" #[key]>
8+
<template v-for="(_, key) in $slots" #[key]>
99
<slot :name="key"></slot>
1010
</template>
1111
</Button>
1212
</template>
1313
<script lang="ts" setup>
14-
import { computed, type PropType } from 'vue';
14+
import { computed } from 'vue';
1515
import { Button } from 'ant-design-vue';
1616
import { buttonProps, type ButtonType } from './button';
17+
import type { PropType, ComputedRef } from 'vue';
18+
import type { ButtonType as AButtonType } from 'ant-design-vue/es/button';
1719
1820
const props = defineProps({
1921
...buttonProps(),
@@ -31,7 +33,7 @@
3133
: ['danger'].includes(type)
3234
? 'primary'
3335
: 'default';
34-
});
36+
}) as ComputedRef<AButtonType>;
3537
</script>
3638

3739
<style lang="less" scoped>

src/components/basic/svg-icon/svg-icon.vue

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<script lang="ts" setup>
88
import { computed, type CSSProperties } from 'vue';
99
10+
defineOptions({
11+
name: 'svg-icon',
12+
});
13+
1014
const importAll = (requireContext: __WebpackModuleApi.RequireContext) =>
1115
requireContext.keys().forEach(requireContext);
1216
try {

src/components/core/dynamic-table/src/components/table-action.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<template v-for="(actionItem, index) in actionFilters" :key="`${index}-${actionItem.label}`">
2+
<template v-for="(actionItem, _index) in actionFilters" :key="`${_index}-${actionItem.label}`">
33
<component
44
:is="actionItem.popConfirm ? Popconfirm : 'span'"
55
:title="actionItem.title"

src/components/core/dynamic-table/src/components/table-settings/column-setting.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,17 @@
8383
import { useSortable } from '@/hooks/useSortable';
8484
import { isNullAndUnDef } from '@/utils/is';
8585
86+
type TableColumnType<T = any> = TableColumn<T> & {
87+
/** 目的是解决:类型实例化过深,且可能无限 */
88+
formItemProps?: any;
89+
};
90+
8691
const table = useTableContext();
8792
let inited = false;
88-
const defaultColumns = cloneDeep(table.columns);
93+
const defaultColumns = cloneDeep<TableColumnType[]>(table.columns);
8994
const defaultShowIndex = !!table.showIndex;
9095
const defaultBordered = table.bordered;
91-
const tableColumns = ref<TableColumn<any>[]>([]);
96+
const tableColumns = ref<TableColumnType[]>([]);
9297
9398
const checkAll = computed<boolean>({
9499
get() {

src/components/core/schema-form/src/helper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dayjs from 'dayjs';
2-
import type { ValidationRule } from 'ant-design-vue/es/form/Form';
2+
import type { RuleObject } from 'ant-design-vue/es/form/';
33
import type { ComponentMapType } from './types/component';
44
import { isNumber } from '@/utils/is';
55
import { useI18n } from '@/hooks/useI18n';
@@ -34,7 +34,7 @@ function genType() {
3434
}
3535

3636
export function setComponentRuleType(
37-
rule: ValidationRule,
37+
rule: RuleObject,
3838
component: ComponentMapType,
3939
valueFormat: string,
4040
) {

src/components/core/schema-form/src/schema-form-item.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import type { PropType } from 'vue';
5555
import type { ComponentMapType } from './componentMap';
5656
import type { CustomRenderFn, FormSchema, RenderCallbackParams } from './types/form';
57-
import type { ValidationRule } from 'ant-design-vue/es/form/Form';
57+
import type { RuleObject } from 'ant-design-vue/es/form/';
5858
import type { TableActionType } from '@/components/core/dynamic-table';
5959
import { isBoolean, isNull, isObject, isString } from '@/utils/is';
6060
import BasicHelp from '@/components/basic/basic-help/index.vue';
@@ -275,7 +275,7 @@
275275
});
276276
277277
function setComponentRuleType(
278-
rule: ValidationRule,
278+
rule: RuleObject,
279279
component: ComponentMapType,
280280
valueFormat: string,
281281
) {
@@ -299,10 +299,10 @@
299299
} = props.schema;
300300
301301
if (isFunction(dynamicRules)) {
302-
return dynamicRules(unref(getValues)) as ValidationRule[];
302+
return dynamicRules(unref(getValues)) as RuleObject[];
303303
}
304304
305-
let rules: ValidationRule[] = cloneDeep(defRules) as ValidationRule[];
305+
let rules = cloneDeep<RuleObject[]>(defRules);
306306
const { rulesMessageJoinLabel: globalRulesMessageJoinLabel } = unref(formPropsRef);
307307
308308
const joinLabel = Reflect.has(unref(formPropsRef), 'rulesMessageJoinLabel')

src/components/core/schema-form/src/types/form.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { RowProps } from 'ant-design-vue';
12
import type { NamePath, RuleObject } from 'ant-design-vue/es/form/interface';
2-
import type { FormItemProps } from './formItem';
3+
import type { FormItemProps } from 'ant-design-vue/es/form/FormItem';
34
import type { Component, VNode } from 'vue';
45
import type { ButtonProps as AntdButtonProps } from '@/components/basic/button';
56
import type { ColEx, ComponentMapType, ComponentProps } from './component';
67
// import type { TableActionType } from '/@/components/Table/src/types/table'
7-
import type { RowProps } from 'ant-design-vue';
88
import type { SchemaFormInstance } from '../schema-form';
99
import type { SchemaFormType } from '../hooks';
1010
import type { TableActionType } from '@/components/core/dynamic-table';
@@ -16,6 +16,7 @@ export type FieldMapToTime = [string, [string, string], string?][];
1616
export type Rule = RuleObject & {
1717
trigger?: 'blur' | 'change' | ['change', 'blur'];
1818
};
19+
1920
/** 获取所有字段名 */
2021
export type GetFieldKeys<T> = Exclude<keyof T, symbol | number>;
2122

@@ -86,9 +87,9 @@ export interface FormSchema<T = string> {
8687
labelWidth?: string | number;
8788
// Disable the adjustment of labelWidth with global settings of formModel, and manually set labelCol and wrapperCol by yourself
8889
disabledLabelWidth?: boolean;
89-
// render component
90+
/** 表单项对应的组件,eg: Input */
9091
component?: ComponentMapType | CustomRenderFn<T> | ((opt: RenderCallbackParams<T>) => Component);
91-
// 组件参数
92+
/** 表单组件属性 */
9293
componentProps?:
9394
| ComponentProps
9495
| {

src/components/core/schema-form/src/types/formItem.ts

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from './form';
22
export * from './component';
33
export * from './hooks';
4-
export * from './formItem';

src/layout/header/index.vue

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Breadcrumb.Item>
1010
<TitleI18n :title="routeItem?.meta?.title" />
1111
<template v-if="routeItem?.children?.length" #overlay>
12-
<Menu :selected-keys="[menus[rotueIndex + 1]?.name]">
12+
<Menu :selected-keys="getSelectKeys(rotueIndex)">
1313
<template v-for="childItem in routeItem?.children" :key="childItem.name">
1414
<Menu.Item
1515
v-if="!childItem.meta?.hideInMenu && !childItem.meta?.hideInBreadcrumb"
@@ -31,6 +31,7 @@
3131
<LockOutlined @click="lockscreenStore.setLock(true)" />
3232
</Tooltip>
3333
<FullScreen />
34+
<svg-icon :name="isDark ? 'sun' : 'moon'" @click="toggleDark" />
3435
<LocalePicker />
3536
<Dropdown placement="bottomRight">
3637
<Avatar :src="userInfo.headImg" :alt="userInfo.name">{{ userInfo.name }}</Avatar>
@@ -67,6 +68,7 @@
6768
PoweroffOutlined,
6869
LockOutlined,
6970
} from '@ant-design/icons-vue';
71+
import { useDark, useToggle } from '@vueuse/core';
7072
import {
7173
Layout,
7274
message,
@@ -96,6 +98,8 @@
9698
9799
const router = useRouter();
98100
const route = useRoute();
101+
const isDark = useDark();
102+
const toggleDark = useToggle(isDark);
99103
const userInfo = computed(() => userStore.userInfo);
100104
101105
const menus = computed(() => {
@@ -120,6 +124,10 @@
120124
return route.matched;
121125
});
122126
127+
const getSelectKeys = (rotueIndex: number) => {
128+
return [menus.value[rotueIndex + 1]?.name] as string[];
129+
};
130+
123131
const findLastChild = (route?: RouteRecordRaw) => {
124132
if (typeof route?.redirect === 'object') {
125133
const redirectValues = Object.values(route.redirect);

src/layout/menu/menu-item.vue

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<template>
22
<!-- 目录 -->
3-
<Menu.SubMenu
4-
v-if="props.menuInfo?.meta?.type === 0 || props.menuInfo?.children?.length"
5-
:key="props.menuInfo?.name"
6-
v-bind="$attrs"
7-
>
8-
<template #title>
9-
<span>
10-
<icon-font :type="props.menuInfo.meta?.icon" />
11-
<TitleI18n :title="props.menuInfo?.meta?.title" />
12-
</span>
13-
</template>
14-
<template v-for="item in menuChildren" :key="item.name || item.fullPath">
15-
<!-- 递归生成菜单 -->
16-
<MyMenuItem :menu-info="item" />
17-
</template>
18-
</Menu.SubMenu>
3+
<template v-if="props.menuInfo?.meta?.type === 0 || props.menuInfo?.children?.length">
4+
<Menu.SubMenu :key="props.menuInfo?.name" v-bind="$attrs">
5+
<template #title>
6+
<span>
7+
<icon-font :type="props.menuInfo.meta?.icon" />
8+
<TitleI18n :title="props.menuInfo?.meta?.title" />
9+
</span>
10+
</template>
11+
<template v-for="item in menuChildren" :key="item.name || item.fullPath">
12+
<!-- 递归生成菜单 -->
13+
<MyMenuItem :menu-info="item" />
14+
</template>
15+
</Menu.SubMenu>
16+
</template>
1917
<!-- 菜单 -->
2018
<template v-else>
2119
<Menu.Item :key="props.menuInfo?.name">

src/layout/menu/menu.vue

+13-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<script setup lang="ts">
2020
import { reactive, computed, watch } from 'vue';
21-
import { type RouteRecordName, useRoute, useRouter } from 'vue-router';
21+
import { useRoute, useRouter } from 'vue-router';
2222
import { Menu } from 'ant-design-vue';
2323
import MenuItem from './menu-item.vue';
2424
import { useUserStore } from '@/store/modules/user';
@@ -35,8 +35,8 @@
3535
const currentRoute = useRoute();
3636
const router = useRouter();
3737
const state = reactive({
38-
openKeys: [] as (RouteRecordName | undefined)[],
39-
selectedKeys: [currentRoute.name],
38+
openKeys: [] as string[],
39+
selectedKeys: [currentRoute.name] as string[],
4040
});
4141
4242
const menus = computed(() => {
@@ -52,24 +52,26 @@
5252
};
5353
5454
// 获取当前打开的子菜单
55-
function getOpenKeys() {
55+
const getOpenKeys = () => {
5656
const meta = currentRoute.meta;
5757
if (meta?.activeMenu) {
5858
const targetMenu = getTargetMenuByActiveMenuName(meta.activeMenu);
5959
return targetMenu?.meta?.namePath ?? [meta?.activeMenu];
6060
}
6161
62-
return meta?.hideInMenu
63-
? state?.openKeys || []
64-
: currentRoute.meta?.namePath ?? currentRoute.matched.slice(1).map((n) => n.name);
65-
}
62+
return (
63+
meta?.hideInMenu
64+
? state?.openKeys || []
65+
: currentRoute.meta?.namePath ?? currentRoute.matched.slice(1).map((n) => n.name)
66+
) as string[];
67+
};
6668
6769
// 监听菜单收缩状态
6870
watch(
6971
() => props.collapsed,
7072
(newVal) => {
7173
state.openKeys = newVal ? [] : getOpenKeys();
72-
state.selectedKeys = [currentRoute.name];
74+
state.selectedKeys = [currentRoute.name] as string[];
7375
},
7476
);
7577
@@ -82,9 +84,9 @@
8284
const meta = currentRoute.meta;
8385
if (meta?.activeMenu) {
8486
const targetMenu = getTargetMenuByActiveMenuName(meta.activeMenu);
85-
state.selectedKeys = [targetMenu?.name ?? meta?.activeMenu];
87+
state.selectedKeys = [targetMenu?.name ?? meta?.activeMenu] as string[];
8688
} else {
87-
state.selectedKeys = [currentRoute.meta?.activeMenu ?? currentRoute.name];
89+
state.selectedKeys = [currentRoute.meta?.activeMenu ?? currentRoute.name] as string[];
8890
}
8991
},
9092
{

src/views/demos/tables/search-table/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
const [DynamicTable, dynamicTableInstance] = useTable();
2424
25-
const loadData = async (params) => {
25+
const loadData = async (params): Promise<API.TableListResult> => {
2626
return new Promise((resolve) => {
2727
setTimeout(() => {
2828
resolve({

0 commit comments

Comments
 (0)