Browse Source

chore: cleanup

main
刘凯 1 year ago
parent
commit
de29a110da
  1. 2
      src/components/Form/src/components/ApiTree.vue
  2. 1
      src/components/Form/src/components/ApiTreeSelect.vue
  3. 1
      src/components/Form/src/components/FormItem.vue
  4. 2
      src/components/Scrollbar/src/Scrollbar.vue
  5. 22
      src/components/Scrollbar/src/util.ts
  6. 2
      src/hooks/event/useWindowSizeFn.ts
  7. 28
      src/types/utils.d.ts
  8. 2
      src/utils/props.ts
  9. 82
      src/utils/types.ts

2
src/components/Form/src/components/ApiTree.vue

@ -7,7 +7,7 @@ import type { DataNode } from 'ant-design-vue/es/tree'
import { isArray, isFunction } from '@/utils/is'
import { handleTree as handleTreeFn } from '@/utils/tree'
import { propTypes } from '@/utils/propTypes'
import type { AnyFunction, Recordable } from '@/utils/types'
import type { AnyFunction } from '@/types/utils'
import { useRuleFormItem } from '@/hooks/component/useFormItem'
defineOptions({ name: 'ApiTree' })

1
src/components/Form/src/components/ApiTreeSelect.vue

@ -5,7 +5,6 @@ import { get, set } from 'lodash-es'
import { LoadingOutlined } from '@ant-design/icons-vue'
import { isArray, isFunction } from '@/utils/is'
import { propTypes } from '@/utils/propTypes'
import type { Recordable } from '@/utils/types'
import { handleTree as handleTreeFn } from '@/utils/tree'
defineOptions({ name: 'ApiTreeSelect' })

1
src/components/Form/src/components/FormItem.vue

@ -13,7 +13,6 @@ import type { TableActionType } from '@/components/Table'
import { BasicHelp } from '@/components/Basic'
import { isBoolean, isFunction, isNull } from '@/utils/is'
import { getSlot } from '@/utils/helper/tsxHelper'
import type { Nullable, Recordable } from '@/utils/types'
import { useI18n } from '@/hooks/web/useI18n'
export default defineComponent({

2
src/components/Scrollbar/src/Scrollbar.vue

@ -3,7 +3,7 @@ import type { PropType } from 'vue'
import { nextTick, onBeforeUnmount, onMounted, provide, ref, unref, watch } from 'vue'
import Bar from './bar'
import { addResizeListener, removeResizeListener } from '@/utils/event'
import type { StyleValue } from '@/utils/types'
import type { StyleValue } from '@/types/utils'
import componentSetting from '@/settings/componentSetting'
defineOptions({ name: 'Scrollbar' })

22
src/components/Scrollbar/src/util.ts

@ -1,5 +1,4 @@
import type { BarMap } from './types'
import type { MergeAll } from '@/utils/types'
export const BAR_MAP: BarMap = {
vertical: {
@ -35,24 +34,3 @@ export function renderThumbStyle({ move, size, bar }) {
return style
}
function extend<T extends object, K extends object>(to: T, _from: K): T & K {
return Object.assign(to as any, _from)
}
/**
* [
* { 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])
}
return res
}

2
src/hooks/event/useWindowSizeFn.ts

@ -1,5 +1,5 @@
import { tryOnMounted, tryOnUnmounted, useDebounceFn } from '@vueuse/core'
import type { AnyFunction } from '@/utils/types'
import type { AnyFunction } from '@/types/utils'
interface UseWindowSizeOptions {
wait?: number

28
src/types/utils.d.ts vendored

@ -1,14 +1,24 @@
import type { ComputedRef, Ref } from 'vue'
import type { CSSProperties, ComputedRef, Ref } from 'vue'
export type DynamicProps<T> = {
[P in keyof T]: Ref<T[P]> | T[P] | ComputedRef<T[P]>
}
export type StringLiteralsToType<T extends 'string' | 'number' | 'boolean'>
= T extends 'string'
? string
: T extends 'number'
? number
: T extends 'boolean'
? boolean
: never
export type StyleValue = string | CSSProperties | Array<StyleValue>
/**
*
*/
export type AnyPromiseFunction = (...arg: any[]) => PromiseLike<any>
/**
*
*/
export type AnyNormalFunction = (...arg: any[]) => any
/**
*
*/
export type AnyFunction = AnyNormalFunction | AnyPromiseFunction
export type Mutable<T> = { -readonly [P in keyof T]: T[P] }

2
src/utils/props.ts

@ -3,7 +3,7 @@
import { warn } from 'vue'
import { fromPairs } from 'lodash-es'
import type { ExtractPropTypes } from 'vue'
import type { Mutable } from './types'
import type { Mutable } from '@/types/utils'
import { isObject } from '@/utils/is'
const wrapperKey = Symbol('wrapperKey')

82
src/utils/types.ts

@ -1,82 +0,0 @@
// copy from element-plus
import type { CSSProperties, Plugin } from 'vue'
type OptionalKeys<T extends Record<string, unknown>> = {
[K in keyof T]: T extends Record<K, T[K]> ? never : K
}[keyof T]
type RequiredKeys<T extends Record<string, unknown>> = Exclude<keyof T, OptionalKeys<T>>
type MonoArgEmitter<T, Keys extends keyof T> = <K extends Keys>(evt: K, arg?: T[K]) => void
type BiArgEmitter<T, Keys extends keyof T> = <K extends Keys>(evt: K, arg: T[K]) => void
export type EventEmitter<T extends Record<string, unknown>> = MonoArgEmitter<T, OptionalKeys<T>> & BiArgEmitter<T, RequiredKeys<T>>
/**
*
*/
export type AnyPromiseFunction = (...arg: any[]) => PromiseLike<any>
/**
*
*/
export type AnyNormalFunction = (...arg: any[]) => any
/**
*
*/
export type AnyFunction = AnyNormalFunction | AnyPromiseFunction
export type PartialReturnType<T extends (...args: unknown[]) => unknown> = Partial<ReturnType<T>>
export type SFCWithInstall<T> = T & Plugin
export type Nullable<T> = T | null
/**
*
*/
export type Recordable<T = any> = Record<string, T>
export type RefElement = Nullable<HTMLElement>
export type CustomizedHTMLElement<T> = HTMLElement & T
export interface Indexable<T> {
[key: string]: T
}
export type Hash<T> = Indexable<T>
export type TimeoutHandle = ReturnType<typeof globalThis.setTimeout>
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 = object> = T extends [
infer F extends object,
...infer Rest extends object[],
]
? MergeAll<Rest, Merge<R, F>>
: R
Loading…
Cancel
Save