diff --git a/docs/docs/.vitepress/utils/sidebar.ts b/docs/docs/.vitepress/utils/sidebar.ts index 53a7eeab8e..ce13f16a2b 100644 --- a/docs/docs/.vitepress/utils/sidebar.ts +++ b/docs/docs/.vitepress/utils/sidebar.ts @@ -114,7 +114,10 @@ export const sidebar = { { text: 'Watermark 水印', link: '/components/watermark' }, { text: 'Ripple 涟漪', link: '/components/ripple' }, { text: 'Calendar 日历', link: '/components/calendar' }, - { text: 'CollapseAnimation 折叠动画', link: '/components/collapse-animation' } + { + text: 'CollapseAnimation 折叠动画', + link: '/components/collapse-animation' + } ] } ] diff --git a/packages/fighting-design/_hooks/use-avatar/index.ts b/packages/fighting-design/_hooks/use-avatar/index.ts index f694cfc504..531e82a5bf 100644 --- a/packages/fighting-design/_hooks/use-avatar/index.ts +++ b/packages/fighting-design/_hooks/use-avatar/index.ts @@ -7,7 +7,7 @@ import type { UseAvatarReturnInterface } from './interface' /** * useAvatar 内部样式 - * + * * @param prop props 列表 * @returns { UseAvatarReturnInterface } */ @@ -46,24 +46,22 @@ export const useAvatar = (prop: AvatarPropsType): UseAvatarReturnInterface => { /** * 样式列表 */ - const styleList: ComputedRef = styles( - [ - 'background', - 'fontColor', - 'fontSize', - /** - * size 配置项需要进行检查是否需要过滤 - * - * 只有是数字的时候才需要过滤,是数字代表是自定义的尺寸 - * - * 字符串代表内部尺寸,用于类名拼接 - */ - { - key: 'size', - callback: (): boolean => isNumber(prop.size) - } - ] - ) + const styleList: ComputedRef = styles([ + 'background', + 'fontColor', + 'fontSize', + /** + * size 配置项需要进行检查是否需要过滤 + * + * 只有是数字的时候才需要过滤,是数字代表是自定义的尺寸 + * + * 字符串代表内部尺寸,用于类名拼接 + */ + { + key: 'size', + callback: (): boolean => isNumber(prop.size) + } + ]) return { nodeClassList, diff --git a/packages/fighting-design/_hooks/use-avatar/interface.d.ts b/packages/fighting-design/_hooks/use-avatar/interface.d.ts index 722c78df10..ed1eeac8e0 100644 --- a/packages/fighting-design/_hooks/use-avatar/interface.d.ts +++ b/packages/fighting-design/_hooks/use-avatar/interface.d.ts @@ -3,7 +3,7 @@ import type { ClassListInterface } from '../../_interface' /** * useAvatar 内部样式 hook 方法返回值类型接口 - * + * * @param nodeClassList img 元素的类名列表 * @param classList 类名列表 * @param styleList 样式列表 diff --git a/packages/fighting-design/_hooks/use-list/index.ts b/packages/fighting-design/_hooks/use-list/index.ts index 9d44e58bca..59ec50365b 100644 --- a/packages/fighting-design/_hooks/use-list/index.ts +++ b/packages/fighting-design/_hooks/use-list/index.ts @@ -13,9 +13,9 @@ import type { FilterParamsInterface } from '../use-props/interface' /** * 自动计算组件所需要的类名列表和样式列表 - * + * * 类名和样式首先通过传入属性列表数组,使用过滤 hook 进行过滤 - * + * * 过滤后的 prop 对象再进行样式或者类名处理 * * @param prop prop 列表 @@ -26,12 +26,11 @@ export const useList: UseListInterface = ( prop: T, name: string ): UseListReturnInterface => { - /** * 过滤 props - * + * * 虽然说 classes 和 styles 都接受一个数组参数可以直接遍历 - * + * * 但是有些参数需要传入特殊的回调进行判断,只能是先过滤后再遍历 */ const { filter } = useProps(prop) @@ -69,7 +68,9 @@ export const useList: UseListInterface = ( * 否则使用值拼接 */ classList.value.push( - `f-${name}__${isBoolean(propList[key]) ? convertFormat(key) : propList[key]}` + `f-${name}__${ + isBoolean(propList[key]) ? convertFormat(key) : propList[key] + }` ) } } @@ -99,16 +100,18 @@ export const useList: UseListInterface = ( if (propList[key]) { /** * @description 为什么要进行 isNumber 判断? - * + * * 因为很多属性是同时支持 number 和 staring 类型的参数 - * + * * 所以这里要进行判断,如果是数字类型,则需要使用 sizeChange 方法进行转换标注单位 - * + * * @description convertFormat 方法描述 - * + * * 因为 prop 参数的键都是驼峰命名法,所以这里要转换为短横线连接命名 */ - styleList[`--f-${name}-${convertFormat(key)}`] = isNumber(propList[key]) + styleList[`--f-${name}-${convertFormat(key)}`] = isNumber( + propList[key] + ) ? sizeChange(propList[key] as number) : propList[key] } diff --git a/packages/fighting-design/_hooks/use-list/interface.d.ts b/packages/fighting-design/_hooks/use-list/interface.d.ts index fda8481fe6..5aa563b69b 100644 --- a/packages/fighting-design/_hooks/use-list/interface.d.ts +++ b/packages/fighting-design/_hooks/use-list/interface.d.ts @@ -27,12 +27,15 @@ export interface UseListInterface { /** * 类名列表方法类型接口 - * - * @param list 类名所需要的 prop 参数 + * + * @param list 类名所需要的 prop 参数 * @param className 其它所需要的类名 */ export interface ClassesInterface { - (list: FilterParamsInterface, className?: string): ComputedRef + ( + list: FilterParamsInterface, + className?: string + ): ComputedRef } /** diff --git a/packages/fighting-design/_hooks/use-message/index.ts b/packages/fighting-design/_hooks/use-message/index.ts index aeb50ed741..a082d15ed1 100644 --- a/packages/fighting-design/_hooks/use-message/index.ts +++ b/packages/fighting-design/_hooks/use-message/index.ts @@ -2,7 +2,7 @@ import messageVue from '../../message/src/message.vue' import notificationVue from '../../notification/src/notification.vue' import { render, createVNode } from 'vue' import { useMassageManage } from '../../_hooks' -import { runCallback } from '../../_utils' +import { runCallback, isString } from '../../_utils' import type { ComponentInternalInstance, VNode } from 'vue' import type { DefaultOptionsInterface, @@ -41,7 +41,7 @@ export const useMessage: UseMessageInterface = ( const container: HTMLDivElement = document.createElement('div') const id = `message-${seed}` - if (typeof options === 'string') { + if (isString(options)) { options = { message: options } as MessageOptions diff --git a/packages/fighting-design/_hooks/use-update-input/index.ts b/packages/fighting-design/_hooks/use-update-input/index.ts index 19d3edb867..adee8522db 100644 --- a/packages/fighting-design/_hooks/use-update-input/index.ts +++ b/packages/fighting-design/_hooks/use-update-input/index.ts @@ -1,4 +1,4 @@ -import { runCallback } from '../../_utils' +import { runCallback, isNumber } from '../../_utils' import type { UseUpdateInputInterface, UseUpdateInputEmitInterface, @@ -29,7 +29,7 @@ export const useUpdateInput: UseUpdateInputInterface = ( const onInput: HandleEventInterface = (evt: Event): void => { emit( 'update:modelValue', - prop.type === 'number' + isNumber(prop.type) ? Number((evt.target as HTMLInputElement).value) : (evt.target as HTMLInputElement).value ) @@ -51,7 +51,7 @@ export const useUpdateInput: UseUpdateInputInterface = ( */ const onClear: OrdinaryFunctionInterface = (): void => { if (prop.disabled) return - emit('update:modelValue', prop.type === 'number' ? 0 : '') + emit('update:modelValue', isNumber(prop.type) ? 0 : '') } return { diff --git a/packages/fighting-design/_utils/utils/index.ts b/packages/fighting-design/_utils/utils/index.ts index b4c4ee94ba..1674b59238 100644 --- a/packages/fighting-design/_utils/utils/index.ts +++ b/packages/fighting-design/_utils/utils/index.ts @@ -8,9 +8,11 @@ import type { UtilsIsStringInterface, UtilsSizeToNumInterface, UtilsIsObjectInterface, - UtilsIsArrayInterface + UtilsIsFunctionInterface } from './interface' +const _toString = Object.prototype.toString + /** * 保留小数点后 no 位 * @@ -59,10 +61,7 @@ export const debounce: UtilsDebounceInterface = ( export const isNumber: UtilsIsNumberInterface = ( target: unknown ): target is number => { - return ( - typeof target === 'number' && - Object.prototype.toString.call(target) === '[object Number]' - ) + return typeof target === 'number' } /** @@ -74,10 +73,7 @@ export const isNumber: UtilsIsNumberInterface = ( export const isBoolean: UtilsIsBooleanInterface = ( target: unknown ): target is boolean => { - return ( - typeof target === 'boolean' && - Object.prototype.toString.call(target) === '[object Boolean]' - ) + return typeof target === 'boolean' } /** @@ -89,10 +85,7 @@ export const isBoolean: UtilsIsBooleanInterface = ( export const isString: UtilsIsStringInterface = ( target: unknown ): target is string => { - return ( - typeof target === 'string' && - Object.prototype.toString.call(target) === '[object String]' - ) + return typeof target === 'string' } /** @@ -104,27 +97,29 @@ export const isString: UtilsIsStringInterface = ( export const isObject: UtilsIsObjectInterface = ( target: unknown ): target is Object => { - return ( - typeof target === 'object' && - Object.prototype.toString.call(target) === '[object Object]' - ) + return _toString.call(target) === '[object Object]' } /** - * 判断一个值是否为 array 类型 + * 判断一个值是否为 function 类型 * * @param target 要检测的值 * @returns { boolean } */ -export const isArray: UtilsIsArrayInterface = ( +export const isFunction: UtilsIsFunctionInterface = ( target: unknown -): target is [] => { - return ( - typeof target === 'object' && - Object.prototype.toString.call(target) === '[object Array]' - ) +): target is Function => { + return typeof target === 'function' } +/** + * 判断一个值是否为 array 类型 + * + * @param target 要检测的值 + * @returns { boolean } + */ +export const isArray = Array.isArray + /** * 给数字小于 10 的数字前面加 0 * @@ -153,7 +148,7 @@ export const sizeChange: UtilsSizeChangeInterface = ( target = 'px' ): string => { if (!size) return '' - return typeof size === 'string' ? size : size + target + return isString(size) ? size : size + target } /** @@ -169,7 +164,7 @@ export const sizeToNum: UtilsSizeToNumInterface = ( size: string | number ): number => { if (!size) return 0 - if (typeof size === 'number') return size + if (isNumber(size)) return size return Number.parseFloat(size) || 0 } diff --git a/packages/fighting-design/_utils/utils/interface.d.ts b/packages/fighting-design/_utils/utils/interface.d.ts index ee0ac69c6c..69425cc1e7 100644 --- a/packages/fighting-design/_utils/utils/interface.d.ts +++ b/packages/fighting-design/_utils/utils/interface.d.ts @@ -64,6 +64,17 @@ export interface UtilsIsObjectInterface { (target: unknown): target is Object } +/** + * 检测一个数据是否为 function 类型方法类型接口 + * + * 传入一个未知的类型,返回布尔值 + * + * @param target 未知参数 + */ +export interface UtilsIsFunctionInterface { + (target: unknown): target is Function +} + /** * 检测一个数据是否为 Array 类型方法类型接口 * diff --git a/packages/fighting-design/avatar/src/props.ts b/packages/fighting-design/avatar/src/props.ts index a5da0f15e5..fbde5f08ae 100644 --- a/packages/fighting-design/avatar/src/props.ts +++ b/packages/fighting-design/avatar/src/props.ts @@ -1,6 +1,7 @@ import type { PropType, ExtractPropTypes, VNode, Component } from 'vue' import type { AvatarFitType, AvatarSizeType } from './interface' import type { HandleEventInterface } from '../../_interface' +import { isString, isNumber } from '../../_utils' export const Props = { /** @@ -78,9 +79,9 @@ export const Props = { type: [String, Number] as PropType, default: (): AvatarSizeType => 'middle', validator: (val: AvatarSizeType | number): boolean => { - if (typeof val === 'string') { + if (isString(val)) { return (['large', 'middle', 'small', 'mini'] as const).includes(val) - } else if (typeof val === 'number') { + } else if (isNumber(val)) { return val >= 1 } return false diff --git a/packages/fighting-design/button-group/src/interface.d.ts b/packages/fighting-design/button-group/src/interface.d.ts index 12869ffbaa..29740d81f1 100644 --- a/packages/fighting-design/button-group/src/interface.d.ts +++ b/packages/fighting-design/button-group/src/interface.d.ts @@ -3,4 +3,4 @@ export type { ButtonGroupPropsType } from './props' /** * 排列方式 */ -export type ButtonGroupDirectionType = 'horizontal' | 'vertical' +export type ButtonGroupDirectionType = 'horizontal' | 'vertical' diff --git a/packages/fighting-design/button-group/src/props.ts b/packages/fighting-design/button-group/src/props.ts index 43fabe9a50..62857b61c4 100644 --- a/packages/fighting-design/button-group/src/props.ts +++ b/packages/fighting-design/button-group/src/props.ts @@ -18,7 +18,7 @@ export const Props = { }, /** * 排列方向 - * + * * @values horizontal vertical * @defaultValue horizontal */ diff --git a/packages/fighting-design/checkbox/src/checkbox.vue b/packages/fighting-design/checkbox/src/checkbox.vue index 60193870bf..57936c0fda 100644 --- a/packages/fighting-design/checkbox/src/checkbox.vue +++ b/packages/fighting-design/checkbox/src/checkbox.vue @@ -1,7 +1,7 @@ diff --git a/packages/fighting-design/menu/src/interface.d.ts b/packages/fighting-design/menu/src/interface.d.ts index 5cb95e2444..8b978557b1 100644 --- a/packages/fighting-design/menu/src/interface.d.ts +++ b/packages/fighting-design/menu/src/interface.d.ts @@ -7,7 +7,7 @@ export type MenuModeType = 'horizontal' | 'vertical' | 'inline' /** * 修改选中 name 回调类型接口 - * + * * @param name 需要设置的 name */ export interface MenuSetActiveNameInterface { @@ -16,7 +16,7 @@ export interface MenuSetActiveNameInterface { /** * 注入的依赖项类型接口 - * + * * @param mode 导航栏模式 * @param defaultActive 默认选中的 name * @param setActiveName 修改选中 name diff --git a/packages/fighting-design/menu/src/props.ts b/packages/fighting-design/menu/src/props.ts index 5b9bd84d70..7076a13393 100644 --- a/packages/fighting-design/menu/src/props.ts +++ b/packages/fighting-design/menu/src/props.ts @@ -4,7 +4,7 @@ import type { MenuModeType } from './interface' export const Props = { /** * 导航栏模式 - * + * * 水平的 垂直的 内联的 * * @values horizontal vertical inline @@ -28,4 +28,5 @@ export const Props = { export type MenuPropsType = ExtractPropTypes -export const MENU_PROVIDE_KEY: InjectionKey = Symbol('menu-provide-key') +export const MENU_PROVIDE_KEY: InjectionKey = + Symbol('menu-provide-key') diff --git a/packages/fighting-design/radio/src/radio.vue b/packages/fighting-design/radio/src/radio.vue index 585bd64caf..1e9ca9a0a5 100644 --- a/packages/fighting-design/radio/src/radio.vue +++ b/packages/fighting-design/radio/src/radio.vue @@ -27,13 +27,13 @@ * 如果父组件有依赖注入则使用 * 否则使用之身 props 参数 */ - get () { + get() { return (INJECT_DEPEND && INJECT_DEPEND.modelValue) || prop.modelValue }, /** * 设置值 */ - set (val) { + set(val) { if (INJECT_DEPEND && !INJECT_DEPEND.disabled) { INJECT_DEPEND.changeEvent(val) return diff --git a/packages/fighting-design/slider/src/drag.ts b/packages/fighting-design/slider/src/drag.ts index 1b8decfe7e..65d5bdf4b0 100644 --- a/packages/fighting-design/slider/src/drag.ts +++ b/packages/fighting-design/slider/src/drag.ts @@ -1,3 +1,5 @@ +import { isFunction } from 'packages/fighting-design/_utils' + function supportTouch (): boolean { return !!( 'ontouchstart' in window || @@ -76,7 +78,7 @@ class Drag { } if (options && options.stop) e.stopPropagation() if (options && options.prevent) e.preventDefault() - if (typeof callback === 'function') callback(e, npos, { end: false }) + if (isFunction(callback)) callback(e, npos, { end: false }) } const end = (e: TouchEvent & MouseEvent): void => { const { x, y } = getEventXY(e) @@ -87,7 +89,7 @@ class Drag { } if (options && options.stop) e.stopPropagation() if (options && options.prevent) e.preventDefault() - if (typeof callback === 'function') callback(e, npos, { end: true }) + if (isFunction(callback)) callback(e, npos, { end: true }) document.removeEventListener(touchmove, move) document.removeEventListener(touchend, end) document.removeEventListener('selectstart', stopselect) diff --git a/packages/fighting-design/submenu/src/submenu.vue b/packages/fighting-design/submenu/src/submenu.vue index d9918d8a9c..a9b5124234 100644 --- a/packages/fighting-design/submenu/src/submenu.vue +++ b/packages/fighting-design/submenu/src/submenu.vue @@ -38,12 +38,12 @@
  • diff --git a/packages/fighting-design/tabs/src/components/tabs-nav/index.vue b/packages/fighting-design/tabs/src/components/tabs-nav/index.vue index a00ece8f23..5a75d89d4b 100644 --- a/packages/fighting-design/tabs/src/components/tabs-nav/index.vue +++ b/packages/fighting-design/tabs/src/components/tabs-nav/index.vue @@ -1,6 +1,6 @@