Commit a98835e18b441ce9e6e5b035ea9aa08c91f6a101

Authored by Vben
1 parent 5b4a41ce

chore: types

src/components/Form/src/components/ApiSelect copy.vue deleted 100644 → 0
1 -<template>  
2 - <Select v-bind="attrs" :options="getOptions" v-model:value="state" @focus="handleFetch">  
3 - <template #[item]="data" v-for="item in Object.keys($slots)">  
4 - <slot :name="item" v-bind="data"></slot>  
5 - </template>  
6 - <template #suffixIcon v-if="loading">  
7 - <LoadingOutlined spin />  
8 - </template>  
9 - <template #notFoundContent v-if="loading">  
10 - <span>  
11 - <LoadingOutlined spin class="mr-1" />  
12 - {{ t('component.form.apiSelectNotFound') }}  
13 - </span>  
14 - </template>  
15 - </Select>  
16 -</template>  
17 -<script lang="ts">  
18 - import { defineComponent, PropType, ref, watchEffect, computed, unref } from 'vue';  
19 - import { Select } from 'ant-design-vue';  
20 - import { isFunction } from '/@/utils/is';  
21 - import { useRuleFormItem } from '/@/hooks/component/useFormItem';  
22 - import { useAttrs } from '/@/hooks/core/useAttrs';  
23 - import { get } from 'lodash-es';  
24 -  
25 - import { LoadingOutlined } from '@ant-design/icons-vue';  
26 - import { useI18n } from '/@/hooks/web/useI18n';  
27 - import { propTypes } from '/@/utils/propTypes';  
28 -  
29 - type OptionsItem = { label: string; value: string; disabled?: boolean };  
30 -  
31 - export default defineComponent({  
32 - name: 'ApiSelect',  
33 - components: {  
34 - Select,  
35 - LoadingOutlined,  
36 - },  
37 - inheritAttrs: false,  
38 - props: {  
39 - value: propTypes.string,  
40 - numberToString: propTypes.bool,  
41 - api: {  
42 - type: Function as PropType<(arg?: Recordable) => Promise<OptionsItem[]>>,  
43 - default: null,  
44 - },  
45 - // api params  
46 - params: {  
47 - type: Object as PropType<Recordable>,  
48 - default: () => {},  
49 - },  
50 - // support xxx.xxx.xx  
51 - resultField: propTypes.string.def(''),  
52 - labelField: propTypes.string.def('label'),  
53 - valueField: propTypes.string.def('value'),  
54 - immediate: propTypes.bool.def(true),  
55 - },  
56 - emits: ['options-change', 'change'],  
57 - setup(props, { emit }) {  
58 - const options = ref<OptionsItem[]>([]);  
59 - const loading = ref(false);  
60 - const isFirstLoad = ref(true);  
61 - const attrs = useAttrs();  
62 - const { t } = useI18n();  
63 -  
64 - // Embedded in the form, just use the hook binding to perform form verification  
65 - const [state] = useRuleFormItem(props);  
66 -  
67 - const getOptions = computed(() => {  
68 - const { labelField, valueField, numberToString } = props;  
69 -  
70 - return unref(options).reduce((prev, next: Recordable) => {  
71 - if (next) {  
72 - const value = next[valueField];  
73 - prev.push({  
74 - label: next[labelField],  
75 - value: numberToString ? `${value}` : value,  
76 - });  
77 - }  
78 - return prev;  
79 - }, [] as OptionsItem[]);  
80 - });  
81 -  
82 - watchEffect(() => {  
83 - if (isFirstLoad.value) {  
84 - props.immediate && fetch();  
85 - } else {  
86 - fetch();  
87 - }  
88 - });  
89 -  
90 - async function fetch() {  
91 - const api = props.api;  
92 - if (!api || !isFunction(api)) return;  
93 -  
94 - try {  
95 - loading.value = true;  
96 - const res = await api(props.params);  
97 - if (Array.isArray(res)) {  
98 - options.value = res;  
99 - emitChange();  
100 - return;  
101 - }  
102 - if (props.resultField) {  
103 - options.value = get(res, props.resultField) || [];  
104 - }  
105 - emitChange();  
106 - } catch (error) {  
107 - console.warn(error);  
108 - } finally {  
109 - loading.value = false;  
110 - }  
111 - }  
112 -  
113 - async function handleFetch() {  
114 - if (!props.immediate) {  
115 - await fetch();  
116 - }  
117 - isFirstLoad.value = false;  
118 - }  
119 -  
120 - function emitChange() {  
121 - emit('options-change', unref(options));  
122 - }  
123 -  
124 - return { state, attrs, getOptions, loading, t, handleFetch };  
125 - },  
126 - });  
127 -</script>  
src/components/Scrollbar/src/bar.ts
@@ -28,7 +28,7 @@ export default defineComponent({ @@ -28,7 +28,7 @@ export default defineComponent({
28 const bar = computed(() => { 28 const bar = computed(() => {
29 return BAR_MAP[props.vertical ? 'vertical' : 'horizontal']; 29 return BAR_MAP[props.vertical ? 'vertical' : 'horizontal'];
30 }); 30 });
31 - const barStore = ref<Indexable>({}); 31 + const barStore = ref<Recordable>({});
32 const cursorDown = ref<any>(null); 32 const cursorDown = ref<any>(null);
33 const clickThumbHandler = (e: any) => { 33 const clickThumbHandler = (e: any) => {
34 // prevent click event of right button 34 // prevent click event of right button
src/components/Table/src/components/editable/index.ts
@@ -41,7 +41,7 @@ export function renderEditCell(column: BasicColumn) { @@ -41,7 +41,7 @@ export function renderEditCell(column: BasicColumn) {
41 }; 41 };
42 } 42 }
43 43
44 -export type EditRecordRow<T = Hash<any>> = Partial< 44 +export type EditRecordRow<T = Recordable> = Partial<
45 { 45 {
46 onEdit: (editable: boolean, submit?: boolean) => Promise<boolean>; 46 onEdit: (editable: boolean, submit?: boolean) => Promise<boolean>;
47 editable: boolean; 47 editable: boolean;
src/components/Table/src/types/table.ts
@@ -402,7 +402,7 @@ export interface BasicColumn extends ColumnProps { @@ -402,7 +402,7 @@ export interface BasicColumn extends ColumnProps {
402 flag?: 'INDEX' | 'DEFAULT' | 'CHECKBOX' | 'RADIO' | 'ACTION'; 402 flag?: 'INDEX' | 'DEFAULT' | 'CHECKBOX' | 'RADIO' | 'ACTION';
403 customTitle?: VueNode; 403 customTitle?: VueNode;
404 404
405 - slots?: Indexable; 405 + slots?: Recordable;
406 406
407 // Whether to hide the column by default, it can be displayed in the column configuration 407 // Whether to hide the column by default, it can be displayed in the column configuration
408 defaultHidden?: boolean; 408 defaultHidden?: boolean;
src/directives/ripple/index.ts
@@ -181,7 +181,7 @@ function rippler({ @@ -181,7 +181,7 @@ function rippler({
181 }; 181 };
182 } 182 }
183 183
184 -function setProps(modifiers: Hash<any>, props: Recordable) { 184 +function setProps(modifiers: Recordable, props: Recordable) {
185 modifiers.forEach((item: Recordable) => { 185 modifiers.forEach((item: Recordable) => {
186 if (isNaN(Number(item))) props.event = item; 186 if (isNaN(Number(item))) props.event = item;
187 else props.transition = item; 187 else props.transition = item;
src/hooks/component/useFormItem.ts
@@ -3,7 +3,7 @@ import { reactive, readonly, computed, getCurrentInstance, watchEffect } from &#39;v @@ -3,7 +3,7 @@ import { reactive, readonly, computed, getCurrentInstance, watchEffect } from &#39;v
3 3
4 import { isEqual } from 'lodash-es'; 4 import { isEqual } from 'lodash-es';
5 5
6 -export function useRuleFormItem<T extends Indexable>( 6 +export function useRuleFormItem<T extends Recordable>(
7 props: T, 7 props: T,
8 key: keyof T = 'value', 8 key: keyof T = 'value',
9 changeEvent = 'change' 9 changeEvent = 'change'
src/layouts/page/transition.ts
@@ -2,7 +2,7 @@ import type { FunctionalComponent } from &#39;vue&#39;; @@ -2,7 +2,7 @@ import type { FunctionalComponent } from &#39;vue&#39;;
2 import type { RouteLocation } from 'vue-router'; 2 import type { RouteLocation } from 'vue-router';
3 3
4 export interface DefaultContext { 4 export interface DefaultContext {
5 - Component: FunctionalComponent & { type: Indexable }; 5 + Component: FunctionalComponent & { type: Recordable };
6 route: RouteLocation; 6 route: RouteLocation;
7 } 7 }
8 8
src/router/guard/permissionGuard.ts
@@ -38,7 +38,7 @@ export function createPermissionGuard(router: Router) { @@ -38,7 +38,7 @@ export function createPermissionGuard(router: Router) {
38 return; 38 return;
39 } 39 }
40 // redirect login page 40 // redirect login page
41 - const redirectData: { path: string; replace: boolean; query?: Indexable<string> } = { 41 + const redirectData: { path: string; replace: boolean; query?: Recordable<string> } = {
42 path: LOGIN_PATH, 42 path: LOGIN_PATH,
43 replace: true, 43 replace: true,
44 }; 44 };
src/utils/http/axios/types.ts
@@ -28,7 +28,7 @@ export interface Result&lt;T = any&gt; { @@ -28,7 +28,7 @@ export interface Result&lt;T = any&gt; {
28 // multipart/form-data: upload file 28 // multipart/form-data: upload file
29 export interface UploadFileParams { 29 export interface UploadFileParams {
30 // Other parameters 30 // Other parameters
31 - data?: Indexable; 31 + data?: Recordable;
32 // File parameter interface field name 32 // File parameter interface field name
33 name?: string; 33 name?: string;
34 // file name 34 // file name
types/global.d.ts
1 -declare interface Fn<T = any, R = T> {  
2 - (...arg: T[]): R; 1 +import type {
  2 + App,
  3 + ComponentRenderProxy,
  4 + VNode,
  5 + ComponentPublicInstance,
  6 + FunctionalComponent,
  7 +} from 'vue';
  8 +declare global {
  9 + declare interface Window {
  10 + // Global vue app instance
  11 + __APP__: App<Element>;
  12 + }
  13 +
  14 + export type Writable<T> = {
  15 + -readonly [P in keyof T]: T[P];
  16 + };
  17 +
  18 + declare type Nullable<T> = T | null;
  19 + declare type NonNullable<T> = T extends null | undefined ? never : T;
  20 + declare type Recordable<T = any> = Record<string, T>;
  21 + declare type ReadonlyRecordable<T = any> = {
  22 + readonly [key: string]: T;
  23 + };
  24 + declare type Indexable<T = any> = {
  25 + [key: string]: T;
  26 + };
  27 + declare type DeepPartial<T> = {
  28 + [P in keyof T]?: DeepPartial<T[P]>;
  29 + };
  30 + declare type TimeoutHandle = ReturnType<typeof setTimeout>;
  31 + declare type IntervalHandle = ReturnType<typeof setInterval>;
  32 +
  33 + declare interface ChangeEvent extends Event {
  34 + target: HTMLInputElement;
  35 + }
  36 +
  37 + declare interface WheelEvent {
  38 + path?: EventTarget[];
  39 + }
  40 + interface ImportMetaEnv extends ViteEnv {
  41 + __: unknown;
  42 + }
  43 +
  44 + declare interface ViteEnv {
  45 + VITE_PORT: number;
  46 + VITE_USE_MOCK: boolean;
  47 + VITE_USE_PWA: boolean;
  48 + VITE_PUBLIC_PATH: string;
  49 + VITE_PROXY: [string, string][];
  50 + VITE_GLOB_APP_TITLE: string;
  51 + VITE_GLOB_APP_SHORT_NAME: string;
  52 + VITE_USE_CDN: boolean;
  53 + VITE_DROP_CONSOLE: boolean;
  54 + VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none';
  55 + VITE_LEGACY: boolean;
  56 + VITE_USE_IMAGEMIN: boolean;
  57 + VITE_GENERATE_UI: string;
  58 + }
  59 +
  60 + declare function parseInt(s: string | number, radix?: number): number;
  61 +
  62 + declare function parseFloat(string: string | number): number;
  63 +
  64 + namespace JSX {
  65 + // tslint:disable no-empty-interface
  66 + type Element = VNode;
  67 + // tslint:disable no-empty-interface
  68 + type ElementClass = ComponentRenderProxy;
  69 + interface ElementAttributesProperty {
  70 + $props: any;
  71 + }
  72 + interface IntrinsicElements {
  73 + [elem: string]: any;
  74 + }
  75 + interface IntrinsicAttributes {
  76 + [elem: string]: any;
  77 + }
  78 + }
3 } 79 }
4 80
5 -declare interface PromiseFn<T = any, R = T> {  
6 - (...arg: T[]): Promise<R>;  
7 -}  
8 -  
9 -declare interface IObj<T = any> {  
10 - [key: string]: T;  
11 - [key: number]: T;  
12 -}  
13 -  
14 -declare function parseInt(s: string | number, radix?: number): number;  
15 -  
16 -declare function parseFloat(string: string | number): number;  
17 -  
18 -declare type Nullable<T> = T | null;  
19 -  
20 -declare type NonNullable<T> = T extends null | undefined ? never : T;  
21 -  
22 -declare type RefType<T> = T | null;  
23 -  
24 -declare type CustomizedHTMLElement<T> = HTMLElement & T;  
25 -  
26 -declare type Indexable<T extends any = any> = {  
27 - [key: string]: T;  
28 -};  
29 -  
30 -declare type Recordable<T extends any = any> = Record<string, T>;  
31 -  
32 -declare type ReadonlyRecordable<T extends any = any> = {  
33 - readonly [key: string]: T;  
34 -};  
35 -  
36 -declare type Hash<T> = Indexable<T>;  
37 -  
38 -declare type DeepPartial<T> = {  
39 - [P in keyof T]?: DeepPartial<T[P]>;  
40 -};  
41 -  
42 -declare type LabelValueOptions = {  
43 - label: string;  
44 - value: any;  
45 -}[];  
46 -  
47 -declare type EmitType = (event: string, ...args: any[]) => void;  
48 -  
49 -declare type TargetContext = '_self' | '_blank';  
50 -  
51 -declare type TimeoutHandle = ReturnType<typeof setTimeout>;  
52 -  
53 -declare type IntervalHandle = ReturnType<typeof setInterval>;  
54 -  
55 -declare interface ComponentElRef<T extends HTMLElement = HTMLDivElement> {  
56 - $el: T;  
57 -}  
58 -  
59 -declare type ComponentRef<T extends HTMLElement = HTMLDivElement> = ComponentElRef<T> | null;  
60 -  
61 -declare type ElRef<T extends HTMLElement = HTMLDivElement> = Nullable<T>;  
62 -  
63 -type IsSame<A, B> = A | B extends A & B ? true : false;  
64 -  
65 -declare interface ChangeEvent extends Event {  
66 - target: HTMLInputElement;  
67 -}  
68 -  
69 -declare interface WheelEvent {  
70 - path?: EventTarget[];  
71 -}  
72 -  
73 -interface ImportMetaEnv extends ViteEnv {  
74 - __: unknown;  
75 -}  
76 -  
77 -declare interface ViteEnv {  
78 - VITE_PORT: number;  
79 - VITE_USE_MOCK: boolean;  
80 - VITE_USE_PWA: boolean;  
81 - VITE_PUBLIC_PATH: string;  
82 - VITE_PROXY: [string, string][];  
83 - VITE_GLOB_APP_TITLE: string;  
84 - VITE_GLOB_APP_SHORT_NAME: string;  
85 - VITE_USE_CDN: boolean;  
86 - VITE_DROP_CONSOLE: boolean;  
87 - VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none';  
88 - VITE_LEGACY: boolean;  
89 - VITE_USE_IMAGEMIN: boolean;  
90 - VITE_GENERATE_UI: string; 81 +declare module 'vue' {
  82 + export type JSXComponent<Props = any> =
  83 + | { new (): ComponentPublicInstance<Props> }
  84 + | FunctionalComponent<Props>;
91 } 85 }
types/index.d.ts 0 → 100644
  1 +declare interface Fn<T = any, R = T> {
  2 + (...arg: T[]): R;
  3 +}
  4 +
  5 +declare interface PromiseFn<T = any, R = T> {
  6 + (...arg: T[]): Promise<R>;
  7 +}
  8 +
  9 +declare type RefType<T> = T | null;
  10 +
  11 +declare type LabelValueOptions = {
  12 + label: string;
  13 + value: any;
  14 +}[];
  15 +
  16 +declare type EmitType = (event: string, ...args: any[]) => void;
  17 +
  18 +declare type TargetContext = '_self' | '_blank';
  19 +
  20 +declare interface ComponentElRef<T extends HTMLElement = HTMLDivElement> {
  21 + $el: T;
  22 +}
  23 +
  24 +declare type ComponentRef<T extends HTMLElement = HTMLDivElement> = ComponentElRef<T> | null;
  25 +
  26 +declare type ElRef<T extends HTMLElement = HTMLDivElement> = Nullable<T>;
types/module.d.ts
  1 +declare module '*.vue' {
  2 + import { defineComponent } from 'vue';
  3 + const Component: ReturnType<typeof defineComponent>;
  4 + export default Component;
  5 +}
  6 +
1 declare module 'ant-design-vue/es/locale/*' { 7 declare module 'ant-design-vue/es/locale/*' {
2 import { Locale } from 'ant-design-vue/types/locale-provider'; 8 import { Locale } from 'ant-design-vue/types/locale-provider';
3 const locale: Locale & ReadonlyRecordable; 9 const locale: Locale & ReadonlyRecordable;
types/tsx.d.ts deleted 100644 → 0
1 -import type { ComponentRenderProxy, VNode } from 'vue';  
2 -  
3 -declare global {  
4 - namespace JSX {  
5 - // tslint:disable no-empty-interface  
6 - type Element = VNode;  
7 - // tslint:disable no-empty-interface  
8 - type ElementClass = ComponentRenderProxy;  
9 - interface ElementAttributesProperty {  
10 - $props: any;  
11 - }  
12 - interface IntrinsicElements {  
13 - [elem: string]: any;  
14 - }  
15 - interface IntrinsicAttributes {  
16 - [elem: string]: any;  
17 - }  
18 - }  
19 -}  
types/vue-app-env.d.ts deleted 100644 → 0
1 -declare module '*.vue' {  
2 - import { defineComponent } from 'vue';  
3 - const Component: ReturnType<typeof defineComponent>;  
4 - export default Component;  
5 -}  
types/window.d.ts deleted 100644 → 0
1 -import type { App } from 'vue';  
2 -  
3 -declare global {  
4 - declare interface Window {  
5 - // Global vue app instance  
6 - __APP__: App<Element>;  
7 - }  
8 -}