Skip to content

Commit

Permalink
style: 优化代码风格
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyh2001 committed Apr 15, 2024
1 parent 373de09 commit 5cff8bb
Show file tree
Hide file tree
Showing 40 changed files with 127 additions and 113 deletions.
2 changes: 1 addition & 1 deletion packages/fighting-design/_hooks/use-alert-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const useAlertList = (node: HTMLElement): UseAlertListReturn => {
*
* 控制动画执行
*/
const timer: NodeJS.Timer = setInterval((): void => {
const timer: NodeJS.Timer = setInterval(() => {
from += dis

if (from >= to) {
Expand Down
8 changes: 4 additions & 4 deletions packages/fighting-design/_hooks/use-count-down/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const useCountDown = (options: UseCountDownOptions): UseCountDownReturn =

/** 逐帧计算倒计时 */
const tick = (): void => {
/** 非浏览器环境,时间不走 */
// 非浏览器环境,时间不走
if (!isBrowser) {
return
}
Expand Down Expand Up @@ -167,7 +167,7 @@ export const useCountDown = (options: UseCountDownOptions): UseCountDownReturn =

/** 毫秒级渲染 */
const microTick = (): void => {
rafId = raf((): void => {
rafId = raf(() => {
if (isCounting) {
/** 设置剩余时间为此次调用时的剩余时间 */
setRemain(getCurrentRemain())
Expand All @@ -182,7 +182,7 @@ export const useCountDown = (options: UseCountDownOptions): UseCountDownReturn =

/** 秒级渲染 */
const macroTick = (): void => {
rafId = raf((): void => {
rafId = raf(() => {
if (isCounting) {
/** 获取此次调用的剩余时间 */
const remainRemain = getCurrentRemain()
Expand All @@ -195,7 +195,7 @@ export const useCountDown = (options: UseCountDownOptions): UseCountDownReturn =
setRemain(remainRemain)
}

/** 当还有剩余时间时,继续 */
// 当还有剩余时间时,继续
if (remain.value > 0) {
macroTick()
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fighting-design/_hooks/use-form-check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const useFormCheck = (prop: FormProps): UseFormCheckReturn => {
const children = getChildren(slot.default(), 'FFormItem')

// 遍历添每个节点判断是否验证通过
children.forEach((item: VNode): void => {
children.forEach((item: VNode) => {
// 必须有 name 和 rules 才能触发表单校验
if (item.props && item.props.name && item.props.rules) {
// 初始状态下默认设置全部没有通过校验
Expand Down Expand Up @@ -127,7 +127,7 @@ export const useFormCheck = (prop: FormProps): UseFormCheckReturn => {
* 获取到每个子组件,检测输入的内容是否符合规则
*/
const validate = (): boolean => {
getChildrenList.value.forEach((item: VNode): void => {
getChildrenList.value.forEach((item: VNode) => {
/** 子组件规则 */
const _rules: FormItemProps['rules'] = item.props && item.props.rules
/** 子组件名字 */
Expand Down
9 changes: 5 additions & 4 deletions packages/fighting-design/_hooks/use-global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const useGlobal = (prop?: Partial<UseGlobalProp>): UseGlobalReturn => {
const lang: FightingLang = (global && global.lang) || 'zh-CN'
/** 获取当前的语音对象 */
const langList = LANG[lang]

// 返回指定组件的语言内容
return langList[componentName]
})
Expand Down Expand Up @@ -144,15 +145,15 @@ export const useGlobal = (prop?: Partial<UseGlobalProp>): UseGlobalReturn => {
size?: ComputedRef<FightingSize | FightingType>
} = {}

/** 必须是数组才遍历,提前拦截错误 */
// 必须是数组才遍历,提前拦截错误
if (isArray(target)) {
target.forEach((item: 'type' | 'size', index: number): void => {
/** 检测映射对象中是否存在该属性 */
target.forEach((item: 'type' | 'size', index: number) => {
// 检测映射对象中是否存在该属性
if (getPropMap[item]) {
/** 获取默认值 */
const defaultValue: string | undefined = def && def[index]

/** 将需要更改的树形改为指定参数 */
// 将需要更改的树形改为指定参数
prams[item] = getPropMap[item](defaultValue)
}
})
Expand Down
30 changes: 15 additions & 15 deletions packages/fighting-design/_hooks/use-message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ const updatePosition = (closeInstance: ComponentInternalInstance): void => {
instances[placement] as ComponentInternalInstance[]
)[index]

/** 减少后面的组件实例偏移量 */
;(instance.exposed as Record<string, Ref<number>>).offsetVal.value -=
getNextElementInterval(closeInstance)
// 减少后面的组件实例偏移量
; (instance.exposed as Record<string, Ref<number>>).offsetVal.value -=
getNextElementInterval(closeInstance)
}
}

Expand All @@ -137,13 +137,13 @@ export const removeInstance = (instance: ComponentInternalInstance): void => {
/** 当前组件的方位 */
const placement: MessagePlacement | NotificationPlacement = getPlacement(instance)

/**
* @see Array.prototype.splice() https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
*/
;(instances[placement] as ComponentInternalInstance[]).splice(
getIndexByInstance(instance),
1
)
/**
* @see Array.prototype.splice() https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
*/
; (instances[placement] as ComponentInternalInstance[]).splice(
getIndexByInstance(instance),
1
)
}

/**
Expand All @@ -170,10 +170,10 @@ export const useMessage = (
const placement: MessagePlacement | NotificationPlacement = getPlacement(instance)

if (instances[placement]) {
/** 如果对象中存在当前方位数组,则往数组中追加组件实例 */
// 如果对象中存在当前方位数组,则往数组中追加组件实例
(instances[placement] as ComponentInternalInstance[]).push(instance)
} else {
/** 否则新建一个数组存储当前组件实例 */
// 否则新建一个数组存储当前组件实例
instances[placement] = [instance]
}
}
Expand All @@ -192,11 +192,11 @@ export const useMessage = (
/** 获取到当前方位的组件实例集合 */
const placementInstance: ComponentInternalInstance[] | undefined =
instances[
options.placement ? options.placement : name === 'message' ? 'top' : 'top-right'
options.placement ? options.placement : name === 'message' ? 'top' : 'top-right'
]

if (placementInstance) {
placementInstance.forEach((instance: ComponentInternalInstance): void => {
placementInstance.forEach((instance: ComponentInternalInstance) => {
result += getNextElementInterval(instance)
})
}
Expand Down Expand Up @@ -267,7 +267,7 @@ export const useMessage = (
...options
}

/** 如何传入的时间不是一个数字,则强制修改成为数字类型 */
// 如果传入的时间不是一个数字,则强制修改成为数字类型
if (!isNumber(defaultOptions.duration)) {
defaultOptions.duration = 2500

Expand Down
12 changes: 8 additions & 4 deletions packages/fighting-design/_hooks/use-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,21 @@ export const usePage = (

/** 翻页映射方法 */
const changeMap = {
/** 下一页切换 */
next: (): void => {
/**
* 下一页切换
*/
next: () => {
const newCurrent: number =
prop.current === maxCount.value ? maxCount.value : prop.current + 1

modelValue.currentModelValue.value = newCurrent
run(prop.onNext, newCurrent, prop.pageSize)
run(prop.onChange, newCurrent, prop.pageSize)
},
/**上一页切换 */
prev: (): void => {
/**
* 上一页切换
*/
prev: () => {
newCurrent = prop.current === 1 ? 1 : prop.current - 1
modelValue.currentModelValue.value = newCurrent
run(prop.onPrev, newCurrent, prop.pageSize)
Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/_hooks/use-props/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const useProps = <T extends object>(prop: T): UsePropsReturn => {
/** 过滤的 prop 结果 */
const result: Record<string, any> = reactive({})

list.forEach((item: string | FilterParamsList): void => {
list.forEach((item: string | FilterParamsList) => {
/**
* 判断如果是字符串参数
*
Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/_hooks/use-ripples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const useRipples = (
* @param { Object } node dom 元素
*/
const removeElement = (node: HTMLElement): void => {
setTimeout((): void => {
setTimeout(() => {
/**
* @see Element.remove() https://developer.mozilla.org/zh-CN/docs/Web/API/Element/remove
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/fighting-design/_hooks/use-trigger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const useTrigger = (
return
}

setPosition()
setPosition() // 设置内容位置

visible.value = true
contentVisible = true
Expand Down Expand Up @@ -143,7 +143,7 @@ export const useTrigger = (
return
}

setTimeout((): void => {
setTimeout(() => {
if (!contentVisible) {
_()
}
Expand Down
1 change: 1 addition & 0 deletions packages/fighting-design/_hooks/use-turn-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const useTurnPage = (
if (prop.current > maxValue) {
modelValue.currentModelValue.value = maxValue
}

modelValue.pageSizeModelValue.value = Number(newValue)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/fighting-design/_utils/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type Install<T> = T & {
* @returns { Object } 组件实例
*/
export const install = <T extends Component>(main: T): Install<T> => {
(main as Record<string, unknown>).install = (app: App): void => {
(main as Record<string, unknown>).install = (app: App) => {
const { name } = main
name && app.component(name, main)
}
Expand All @@ -26,7 +26,7 @@ export const install = <T extends Component>(main: T): Install<T> => {
* @returns { Object } 组件实例
*/
export const installFn = <T>(main: T, name: string): Install<T> => {
(main as Install<T>).install = (app: App): void => {
(main as Install<T>).install = (app: App) => {
app.config.globalProperties[name] = main as Install<T>
}
return main as Install<T>
Expand All @@ -43,7 +43,7 @@ export const installDirective = <T extends Directive>(
main: T,
name: string
): Install<T> => {
(main as Install<T>).install = (app: App): void => {
(main as Install<T>).install = (app: App) => {
app.directive(name, main as Install<T>)
}
return main as Install<T>
Expand Down
6 changes: 3 additions & 3 deletions packages/fighting-design/_utils/tips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param { string } location 位置
* @param { string } message 警告信息
*/
export const warning = (location: string, message: string): void => {
export const warning = (location: string, message: string) => {
console.warn(`[fighting-design/${location}]: ${message}`)
}

Expand All @@ -16,7 +16,7 @@ export const warning = (location: string, message: string): void => {
* @param { string } location 位置
* @param { string } message 警告信息
*/
export const error = (location: string, message: string): void => {
export const error = (location: string, message: string) => {
console.error(`[fighting-design/${location}]: ${message}`)
}

Expand All @@ -28,6 +28,6 @@ export const error = (location: string, message: string): void => {
* @param { string } location 位置
* @param { string } message 警告信息
*/
export const throwError = (location: string, message: string): never => {
export const throwError = (location: string, message: string) => {
throw new Error(`[fighting-design/${location}]: ${message}`)
}
4 changes: 2 additions & 2 deletions packages/fighting-design/_utils/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export const debounce = <T extends (...args: unknown[]) => void>(
/** 计时器实例 */
let timeout: ReturnType<typeof setTimeout> | undefined

return (...args: Parameters<T>): void => {
return (...args: Parameters<T>) => {
if (timeout) {
clearTimeout(timeout)
}

timeout = setTimeout((): void => {
timeout = setTimeout(() => {
func(...args)
}, delay)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/alert/__test__/alert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('FAlert', () => {
})

test('type', () => {
FIGHTING_TYPE.forEach((item: FightingType): void => {
FIGHTING_TYPE.forEach((item: FightingType) => {
const wrapper = mount(FAlert, {
props: { type: item }
})
Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/avatar-group/src/avatar-group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// 必须在子元素存在的时候,设置 zIndex 层级样式
if (avatars && avatars.length) {
avatars.forEach((item: HTMLDivElement, i: number): void => {
avatars.forEach((item: HTMLDivElement, i: number) => {
item.style.zIndex = (avatars.length - i).toString()
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fighting-design/avatar/__test__/avatar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('FAvatar', () => {
})

test('fit', () => {
FIGHTING_FIT.forEach((item: FightingFit): void => {
FIGHTING_FIT.forEach((item: FightingFit) => {
const wrapper = mount(FAvatar, {
props: { fit: item }
})
Expand All @@ -35,7 +35,7 @@ describe('FAvatar', () => {
})

test('size', () => {
FIGHTING_SIZE.forEach((item: FightingSize): void => {
FIGHTING_SIZE.forEach((item: FightingSize) => {
const wrapper = mount(FAvatar, {
props: { size: item }
})
Expand Down
4 changes: 2 additions & 2 deletions packages/fighting-design/back-top/src/back-top.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @returns { Function } 防抖函数
*/
const handleScroll = (node?: HTMLElement): (() => void) => {
return debounce((): void => {
return debounce(() => {
/**
* 当前滚动的距离
*
Expand Down Expand Up @@ -122,7 +122,7 @@
})
// 卸载组件移除监听
onUnmounted((): void => {
onUnmounted(() => {
document.removeEventListener('scroll', cachedHandleScroll)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/badge/__test__/badge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('FBadge', () => {
})

test('type', () => {
FIGHTING_TYPE.forEach((item: FightingType): void => {
FIGHTING_TYPE.forEach((item: FightingType) => {
const wrapper = mount(FBadge, {
props: { type: item }
})
Expand Down
8 changes: 4 additions & 4 deletions packages/fighting-design/button/__test__/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('FButton', () => {
})

test('size', () => {
FIGHTING_SIZE.forEach((item: FightingSize): void => {
FIGHTING_SIZE.forEach((item: FightingSize) => {
const wrapper = mount(FButton, {
props: { size: item }
})
Expand All @@ -90,7 +90,7 @@ describe('FButton', () => {
})

test('target', () => {
FIGHTING_TARGET.forEach((item: ButtonTarget): void => {
FIGHTING_TARGET.forEach((item: ButtonTarget) => {
const wrapper = mount(FButton, {
props: { href: 'https://tianyuhao.cn', target: item }
})
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('FButton', () => {
})

test('type', () => {
FIGHTING_TYPE.forEach((item: FightingType): void => {
FIGHTING_TYPE.forEach((item: FightingType) => {
const wrapper = mount(FButton, {
props: { type: item }
})
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('FButton', () => {

test('nativeType', () => {
const nativeTypes: ButtonNative[] = ['button', 'submit', 'reset']
nativeTypes.forEach((item: ButtonNative): void => {
nativeTypes.forEach((item: ButtonNative) => {
const wrapper = mount(FButton, {
props: { nativeType: item }
})
Expand Down
Loading

0 comments on commit 5cff8bb

Please sign in to comment.