Skip to content

Commit

Permalink
fix: 修复部分类型错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyh2001 committed Apr 1, 2023
1 parent ae13937 commit 2a4b7d8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 35 deletions.
20 changes: 18 additions & 2 deletions packages/fighting-design/_hooks/use-global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface UseGlobalReturn {
* @param { Object } prop 组件的 prop
* @returns { Object } 根据优先级返回需要的参数
*/
export const useGlobal = <T extends UseGlobalProp>(prop: T): UseGlobalReturn => {
export const useGlobal = <T extends UseGlobalProp>(prop?: T): UseGlobalReturn => {
/** 获取全局配置组件注入的依赖项 */
const global: FightingGlobalProps | null = inject(FIGHTING_GLOBAL_PROPS_KEY, null)

Expand All @@ -56,6 +56,11 @@ export const useGlobal = <T extends UseGlobalProp>(prop: T): UseGlobalReturn =>
*/
const getType = (def: string | FightingType = 'default'): ComputedRef<FightingType> => {
return computed((): FightingType => {

if (!prop) {
return def as FightingType
}

/** 如果校验不通过则返回默认值 */
if (prop.type && !FIGHTING_TYPE.includes(prop.type)) {
return def as FightingType
Expand All @@ -77,6 +82,11 @@ export const useGlobal = <T extends UseGlobalProp>(prop: T): UseGlobalReturn =>
parentSize?: FightingSize | null
): ComputedRef<FightingSize> => {
return computed((): FightingSize => {

if (!prop) {
return def as FightingSize
}

/**
* 校验格式
*
Expand Down Expand Up @@ -156,8 +166,14 @@ export const useGlobal = <T extends UseGlobalProp>(prop: T): UseGlobalReturn =>
})
}

if (prop) {
return reactive({
...toRefs(prop),
...prams
})
}

return reactive({
...toRefs(prop),
...prams
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { nextTick, getCurrentInstance, ref, computed, onMounted, onUnmounted } from 'vue'
import { sizeToNum } from '../../_utils'
import type { TabsNavProps } from '../../tabs/src/components'
import type { TabsNavProps } from '../../tabs/components'
import type { TabsNavInstance } from '../../tabs'
import type { ComponentInternalInstance, CSSProperties, ComputedRef, Ref } from 'vue'

Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/_utils/props/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { PropType } from 'vue'
*
* @param { * } val 校验的值
*/
export type Validator = (val) => boolean
export type Validator = (val: string) => boolean

/**
* 返回值类型接口
Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/select/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { VNode } from 'vue'

export type { SelectProps } from './select'
export type { SelectProps } from './props'

/** 绑定值类型 */
export type SelectModelValue = string | number | boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/submenu/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type { SubmenuProps } from './prop'
export type { SubmenuProps } from './props'
32 changes: 3 additions & 29 deletions start/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
<script lang="ts" setup>
import { ref } from 'vue'
<script lang="ts" setup></script>

const num = ref(10)
<template></template>

const sun = (): void => {
if (num.value > 0) {
num.value -= 10
}
}
const add = (): void => {
if (num.value < 100) {
num.value += 10
}
}
</script>

<template>
<f-progress type="default" :percentage="num" state="circle" :show-text="false" />
<f-progress type="primary" :percentage="num" />
<f-progress type="success" :percentage="num" />
<f-progress type="danger" :percentage="num" />
<f-progress type="warning" :percentage="num" />
<f-progress type="info" :percentage="num" />

<f-button-group>
<f-button simple round type="primary" :on-click="sun">减少</f-button>
<f-button simple round type="primary" :on-click="add">增加</f-button>
</f-button-group>
</template>
<style lang="scss" scoped></style>

0 comments on commit 2a4b7d8

Please sign in to comment.