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 06e23d9 commit a844376
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/fighting-design/_hooks/use-tabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const useTabs = (prop: TabsProps, emit: SetActiveNameEmit): UseTabsReturn
label: item.slots['label'] || item.prop.label
} as const
})
)
) as TabsNavInstance[]
})

/** prop.modelValue 同步到 currentName 中 */
Expand Down
17 changes: 8 additions & 9 deletions packages/fighting-design/_hooks/use-tips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ export type TipsInstances = Partial<{
*
* @param { Object | string } options 传入选项参数或者字符串
*/
interface RenderInstanceFn {
(options: TipsOptions | string): TipsInstance
}
export type RenderInstanceFn = (options: TipsOptions | string) => TipsInstance

/**
* renderInstance 方法状态
*
* @param { string } text 提示信息
*/
type RenderInstanceFnWith = {
// [key in FightingType]: (text: string) => TipsInstance
export type RenderInstanceFnWith = {
[key in FightingType]: (text: string) => void
}

Expand All @@ -61,7 +58,7 @@ type RenderInstanceFnWith = {
*
* 具有两种状态
*/
export type RenderInstance = RenderInstanceFn & Partial<RenderInstanceFnWith>
export type RenderInstance = RenderInstanceFn | Partial<RenderInstanceFnWith>

/**
* useMassageManage 返回值类型接口
Expand All @@ -79,7 +76,8 @@ export interface UseTipsReturn {
) => number
removeInstance: (placement: MessagePlacement, id: string) => void
createInstance: (instance: TipsInstance, placement: MessagePlacement) => TipsInstance
renderInstance: RenderInstance
// renderInstance: RenderInstance
renderInstance: RenderInstanceFn
}

/** 组件实例对象 */
Expand Down Expand Up @@ -212,7 +210,8 @@ export const useTips = (component?: Component): UseTipsReturn => {
* @param { Object } options 传入的对象参数
* @returns { Object } 组件实例
*/
const renderInstance: RenderInstance = (options: TipsOptions): TipsInstance => {
// const renderInstance: RenderInstance = (options: TipsOptions): TipsInstance => {
const renderInstance: RenderInstanceFn = (options: TipsOptions | string): TipsInstance => {
/** 创建容器盒子 */
const container: HTMLDivElement = document.createElement('div')
/** 每个 message 的唯一 id */
Expand Down Expand Up @@ -278,7 +277,7 @@ export const useTips = (component?: Component): UseTipsReturn => {
* @example FNotification.primary('xxx')
*/
FIGHTING_TYPE.forEach((type: FightingType): void => {
renderInstance[type] = (text: string): TipsInstance => {
(renderInstance as Partial<RenderInstanceFnWith>)[type] = (text: string): TipsInstance => {
return renderInstance({ message: text, type })
}
})
Expand Down
13 changes: 8 additions & 5 deletions packages/fighting-design/select/src/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { EMIT_UPDATE } from '../../_tokens'
import type { VNode, Slots } from 'vue'
import type { SelectProvide, SelectModelValue, SelectChildren } from './interface'
import type { OptionProps } from '../../option'
const prop = defineProps(Props)
const slot: Slots = useSlots()
Expand Down Expand Up @@ -70,13 +69,17 @@
if (!currentOption.length) return ''
/** 获取到当前满足要求的子元素 */
const children = currentOption[0]
const firstChildren: VNode = currentOption[0]
/** 获取到当前子元素的插槽内容 */
const slot: string | undefined = children?.children?.default()[0].children
const slot: string | undefined =
firstChildren.children &&
(firstChildren.children as { default: Function }).default()[0].children
/** 获取到当前子元素的 label 参数 */
const label: string | undefined = children.props?.label
const label: string | undefined = firstChildren.props?.label
/** 获取到当前子元素的 value 参数 */
const value: string | undefined = children.props?.value
const value: string | undefined = firstChildren.props?.value
/** 返回优先级:插槽 > label > value */
return slot || label || (value && value.toString()) || ''
},
Expand Down
2 changes: 1 addition & 1 deletion packages/fighting-design/tabs-pane/src/tabs-pane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
})
/** 在组件插入及卸载时都要更新父级的 pane 列表 */
onMounted(() => {
onMounted((): void => {
parentInject && parentInject.registerChild(pane)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/fighting-design/tabs/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Ref, Slot } from 'vue'
import type { Slot } from 'vue'

export type { TabsProps } from './props'

Expand Down Expand Up @@ -50,6 +50,6 @@ export type TabsEdit = (
* @param { * } label 标签的 label
*/
export interface TabsNavInstance {
name: Ref<TabsModelValue>
name: TabsModelValue
label: string | Slot
}
26 changes: 11 additions & 15 deletions start/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<script lang="ts" setup></script>
<script lang="ts" setup>
import { ref } from 'vue'
const value = ref('')
</script>

<template>
<f-tabs>
<f-tabs-pane label="如烟">
<p>七岁的那一年,抓住那只蝉,以为能抓住夏天;</p>
<p>十七岁的那年,吻过他的脸,就以为和他能永远。</p>
</f-tabs-pane>
<f-tabs-pane label="盛夏光年">
<p>长大 难道是人必经的溃烂。</p>
</f-tabs-pane>
<f-tabs-pane label="我心中尚未崩坏的地方">
<p>就算会有一天,没人与我合唱,至少在我的心中,还有个尚未崩坏的地方。</p>
</f-tabs-pane>
</f-tabs>
<f-select v-model="value" placeholder="请选择……">
<f-option :value="1">香蕉</f-option>
<f-option :value="2">苹果</f-option>
<f-option :value="3">哈密瓜</f-option>
<f-option :value="4">樱桃</f-option>
</f-select>
</template>

<style lang="scss" scoped></style>

0 comments on commit a844376

Please sign in to comment.