diff --git a/packages/fighting-design/_hooks/use-input/index.ts b/packages/fighting-design/_hooks/use-input/index.ts index 054e2bfc67..637eb4145f 100644 --- a/packages/fighting-design/_hooks/use-input/index.ts +++ b/packages/fighting-design/_hooks/use-input/index.ts @@ -42,7 +42,7 @@ export interface UseInputReturn { */ export const useInput = ( prop: Partial, - modelValue: Ref + modelValue: Ref ): UseInputReturn => { const { run } = useRun() diff --git a/packages/fighting-design/_hooks/use-offset/index.ts b/packages/fighting-design/_hooks/use-offset/index.ts index f7e7d05a7a..71635ea7e9 100644 --- a/packages/fighting-design/_hooks/use-offset/index.ts +++ b/packages/fighting-design/_hooks/use-offset/index.ts @@ -1,5 +1,4 @@ import { ref, onMounted, onUnmounted } from 'vue' -import { EMIT_UPDATE } from '../../_tokens' import type { Ref } from 'vue' import type { SliderProps } from '../../slider' @@ -22,13 +21,13 @@ export interface UseOffsetReturn { * @author Tyh2001 * @param { Object } el 小球元素节点 * @param { Object } step 步长 - * @param { Function } emit 回调方法 + * @param { Object } modelValue 绑定值 * @returns { Object } 包括:偏移距离、距离左侧的偏移量、设置偏移量方法 */ export const useOffset = ( el: Ref, prop: SliderProps, - emit: (event: 'update:modelValue', val: number) => void + modelValue: Ref ): UseOffsetReturn => { /** 距离左侧的偏移量 */ const offsetLeft = ref(0) @@ -118,7 +117,7 @@ export const useOffset = ( offset.value = value - emit(EMIT_UPDATE, value) + modelValue.value = value } return { offset, offsetLeft, setPosition } diff --git a/packages/fighting-design/_hooks/use-tabs/index.ts b/packages/fighting-design/_hooks/use-tabs/index.ts index fa3f6e0a53..1609336b65 100644 --- a/packages/fighting-design/_hooks/use-tabs/index.ts +++ b/packages/fighting-design/_hooks/use-tabs/index.ts @@ -9,7 +9,6 @@ import { } from 'vue' import { useChildren } from '../../_utils' import { useRun } from '../../_hooks' -import { EMIT_UPDATE } from '../../_tokens' import { TABS_PROPS_KEY } from '../../tabs/src/props' import type { ComponentInternalInstance, ComputedRef, Ref } from 'vue' import type { TabsModelValue, TabsProps, TabsNavInstance, TabsEdit } from '../../tabs' @@ -40,14 +39,6 @@ export type TabsProvide = { activeName: Ref } & UseChildrenReturn -/** - * setActiveName 回调类型 - * - * @param { string } event 回调事件名 - * @param { string | number } val 回调参数 - */ -export type SetActiveNameEmit = (event: 'update:modelValue', val: string | number) => void - /** * 设置绑定值回调类型 * @@ -63,7 +54,7 @@ export type SetActiveName = (name: TabsModelValue) => void * @param { Function } emit 回调函数 * @returns { Object } */ -export const useTabs = (prop: TabsProps, emit: SetActiveNameEmit): UseTabsReturn => { +export const useTabs = (prop: TabsProps, modelValue: Ref): UseTabsReturn => { const { run } = useRun() /** 获取当前组件实例 */ const instance = getCurrentInstance() as ComponentInternalInstance @@ -80,7 +71,7 @@ export const useTabs = (prop: TabsProps, emit: SetActiveNameEmit): UseTabsReturn const setActiveName = (name: TabsModelValue): void => { activeName.value = name /** 回调更新绑定值 */ - emit(EMIT_UPDATE, name) + modelValue.value = name } /** diff --git a/packages/fighting-design/_hooks/use-visible/index.ts b/packages/fighting-design/_hooks/use-visible/index.ts index 4dea666f76..3efeb6a949 100644 --- a/packages/fighting-design/_hooks/use-visible/index.ts +++ b/packages/fighting-design/_hooks/use-visible/index.ts @@ -1,28 +1,17 @@ -import { watch, ref } from 'vue' import { useRun } from '..' -import { EMIT_VISIBLE } from '../../_tokens' import type { Ref } from 'vue' /** * useVisible 返回值类型接口 * - * @param { Object } isVisible 展示状态 * @param { Function } closeVisible 关闭方法 + * @param { Function } maskClose 遮罩层关闭方法 */ export interface UseVisibleReturn { - isVisible: Ref closeVisible: () => void maskClose: () => void } -/** - * 回调函数类型 - * - * @param { String } event 回调事件名 - * @param { Boolean } val 回调参数 - */ -export type UseVisibleEmit = (event: 'update:visible', val: boolean) => void - /** * 控制 dialog 和 drawer 组件显示隐藏方法 * @@ -33,58 +22,27 @@ export type UseVisibleEmit = (event: 'update:visible', val: boolean) => void * @returns { Object } */ export const useVisible = ( - prop: { visible: boolean, maskClose: boolean }, - emit: UseVisibleEmit, + prop: { maskClose: boolean }, + visible: Ref, callback?: Function ): UseVisibleReturn => { const { run } = useRun() - /** 是否展示 */ - const isVisible = ref(prop.visible) - /** * 关闭 * * @param { Object } [evt] 事件对象 */ const closeVisible = (evt?: MouseEvent): void => { - emit(EMIT_VISIBLE, false) + visible.value = false run(callback, evt) } - /** 监视绑定值的变化,如果为假则关闭 */ - watch( - (): boolean => isVisible.value, - /** - * @param { boolean } newVal 最新值 - */ - (newVal: boolean): void => { - if (!newVal) { - closeVisible() - } - } - ) - - /** 监视数据更新绑定值 */ - watch( - (): boolean => prop.visible, - /** - * @param { boolean } newVal 最新值 - */ - (newVal: boolean): void => { - isVisible.value = newVal - } - ) - /** 点击遮罩层关闭 */ const maskClose = (): void => { if (!prop.maskClose) return closeVisible() } - return { - isVisible, - closeVisible, - maskClose - } + return { closeVisible, maskClose } } diff --git a/packages/fighting-design/date-picker/src/date-picker.vue b/packages/fighting-design/date-picker/src/date-picker.vue index e6af56c072..8444bcc7c5 100644 --- a/packages/fighting-design/date-picker/src/date-picker.vue +++ b/packages/fighting-design/date-picker/src/date-picker.vue @@ -4,8 +4,6 @@ import { FInput } from '../../input' import { FTrigger } from '../../trigger' import { FCalendar } from '../../calendar' - import { EMIT_DATE } from '../../_tokens' - import { useModel } from '../../_hooks' import { addZero, warning, isFunction } from '../../_utils' import { FIconCalendar } from '../../_svg' import type { TriggerInstance } from '../../trigger' @@ -13,18 +11,11 @@ defineOptions({ name: 'FDatePicker' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_DATE]) + const dateModelValue = defineModel('date', { required: true, default: '' }) /** 传递给日历组件的当前时间 */ const date = new Date() - const { keyword } = useModel( - (): string => prop.date, - (val: string): void => { - emit(EMIT_DATE, val) - } - ) - /** trigger 组件实例 */ const triggerInstance = ref() @@ -58,14 +49,10 @@ ) } - // keyword.value = `${year}/${prop.addZero ? addZero(month) : month}/${ - // prop.addZero ? addZero(date) : date - // }` - setDateFun = (): void => { /** 将绑定值设置为格式化后的日期 */ // keyword.value = formatDate - keyword.value = `${year}/${prop.addZero ? addZero(month) : month}/${ + dateModelValue.value = `${year}/${prop.addZero ? addZero(month) : month}/${ prop.addZero ? addZero(date) : date }` } @@ -95,7 +82,7 @@ setDateFun = (): void => { /** 将绑定值设置为格式化后的日期 */ - keyword.value = formatDate + dateModelValue.value = formatDate } } @@ -120,7 +107,7 @@ ('visible', { required: true, default: false }) const { styles, classes } = useList(prop, 'dialog') - const { isVisible, closeVisible, maskClose } = useVisible(prop, emit) + const { closeVisible, maskClose } = useVisible(prop, visible) const { handleOpen, handleOpenEnd, handleClose, handleCloseEnd } = useTransition(prop) /** 样式列表 */ @@ -34,7 +33,7 @@ @after-leave="handleCloseEnd" >
-
+
diff --git a/packages/fighting-design/drawer/src/drawer.vue b/packages/fighting-design/drawer/src/drawer.vue index ef0a978fdb..2cfba912d4 100644 --- a/packages/fighting-design/drawer/src/drawer.vue +++ b/packages/fighting-design/drawer/src/drawer.vue @@ -3,15 +3,14 @@ import { FCloseBtn } from '../../close-btn' import { useTransition } from '../../_hooks' import { useVisible, useList } from '../../_hooks' - import { EMIT_VISIBLE } from '../../_tokens' defineOptions({ name: 'FDrawer' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_VISIBLE]) + const visible = defineModel('visible', { required: true, default: false }) const { styles, classes } = useList(prop, 'drawer') - const { isVisible, closeVisible, maskClose } = useVisible(prop, emit) + const { closeVisible, maskClose } = useVisible(prop, visible) const { handleOpen, handleOpenEnd, handleClose, handleCloseEnd } = useTransition(prop) /** 样式列表 */ @@ -34,7 +33,7 @@ @after-leave="handleCloseEnd" >
-
+
diff --git a/packages/fighting-design/image-preview/src/image-preview.vue b/packages/fighting-design/image-preview/src/image-preview.vue index f8d731e47b..b17a9e8e5f 100644 --- a/packages/fighting-design/image-preview/src/image-preview.vue +++ b/packages/fighting-design/image-preview/src/image-preview.vue @@ -16,12 +16,11 @@ FIconZoomOut } from '../../_svg' import { useOperationImg, useRun } from '../../_hooks' - import { EMIT_VISIBLE } from '../../_tokens' defineOptions({ name: 'FImagePreview' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_VISIBLE]) + const visible = defineModel('visible', { required: true, default: false }) const { run } = useRun() const { @@ -112,7 +111,7 @@ * @param { Object } evt 事件对象 */ const handelClose = (evt: MouseEvent): void => { - emit(EMIT_VISIBLE, false) + visible.value = false run(prop.onClose, evt) } diff --git a/packages/fighting-design/input-number/src/input-number.vue b/packages/fighting-design/input-number/src/input-number.vue index e13de9e5b2..e6d7e006de 100644 --- a/packages/fighting-design/input-number/src/input-number.vue +++ b/packages/fighting-design/input-number/src/input-number.vue @@ -10,33 +10,14 @@ import { FInput } from '../../input' import { FButton } from '../../button' import { isNumber } from '../../_utils' - import { useRun, useModel } from '../../_hooks' - import { EMIT_UPDATE } from '../../_tokens' + import { useRun } from '../../_hooks' defineOptions({ name: 'FInputNumber' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_UPDATE]) + const modelValue = defineModel({ required: true, default: 0 }) const { run } = useRun() - const { keyword } = useModel( - (): number => { - const { modelValue, precision } = prop - - /** 如果传入的是非数字的参数,则默认返回 0 */ - if (!isNumber(modelValue)) { - return 0 - } - - /** - * @see Number.prototype.toFixed() https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed - */ - return Number(modelValue.toFixed(isNumber(precision) ? precision : 0)) - }, - (val: number): void => { - emit(EMIT_UPDATE, Number(val)) - } - ) /** 最小值禁用 */ const minDisabled = computed((): boolean => { @@ -49,7 +30,7 @@ /** * @see Math.abs() https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/abs */ - return keyword.value - Math.abs(step) < min + return modelValue.value - Math.abs(step) < min }) /** 最大值禁用 */ @@ -60,7 +41,7 @@ return false } - return keyword.value + Math.abs(step) > max + return modelValue.value + Math.abs(step) > max }) /** @@ -77,16 +58,16 @@ const map = { /** 减少 */ minus: (): void => { - keyword.value -= step + modelValue.value -= step }, /** 增加 */ plus: (): void => { - keyword.value += step + modelValue.value += step } } run(map[target]) - run(prop.onChange, keyword.value) + run(prop.onChange, modelValue.value) } @@ -104,7 +85,7 @@
() + const modelValue = defineModel({ required: true, default: '' }) const { run } = useRun() const { getLang, getProp } = useGlobal(prop as unknown as UseGlobalProp) diff --git a/packages/fighting-design/rate/src/rate.vue b/packages/fighting-design/rate/src/rate.vue index 6288ade486..f78ec9ff14 100644 --- a/packages/fighting-design/rate/src/rate.vue +++ b/packages/fighting-design/rate/src/rate.vue @@ -6,12 +6,11 @@ import { useRun } from '../../_hooks' import { ref, watch, unref, computed } from 'vue' import { isNumber } from '../../_utils' - import { EMIT_UPDATE } from '../../_tokens' defineOptions({ name: 'FRate' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_UPDATE]) + const modelValue = defineModel({ required: true, default: 0 }) const { run } = useRun() @@ -42,7 +41,7 @@ const handleClick = (index: number): void => { if (prop.readonly) return starValue.value = index - emit(EMIT_UPDATE, index) + modelValue.value = index run(prop.onChange, index) } diff --git a/packages/fighting-design/select/src/interface.ts b/packages/fighting-design/select/src/interface.ts index 9e61eaa868..f5599ba8d9 100644 --- a/packages/fighting-design/select/src/interface.ts +++ b/packages/fighting-design/select/src/interface.ts @@ -3,7 +3,7 @@ import type { VNode } from 'vue' export type { SelectProps } from './props' /** 绑定值类型 */ -export type SelectModelValue = string | number | boolean +export type SelectModelValue = string | number /** * 绑定值发生改变时触发的回调 diff --git a/packages/fighting-design/slider/src/slider.vue b/packages/fighting-design/slider/src/slider.vue index 43b7015b08..b93e89f997 100644 --- a/packages/fighting-design/slider/src/slider.vue +++ b/packages/fighting-design/slider/src/slider.vue @@ -2,12 +2,11 @@ import { Props } from './props' import { onMounted, ref } from 'vue' import { useList, useSlider, useOffset } from '../../_hooks' - import { EMIT_UPDATE } from '../../_tokens' defineOptions({ name: 'FSlider' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_UPDATE]) + const modelValue = defineModel({ required: true, default: 0 }) const { styles, classes } = useList(prop, 'slider') @@ -17,7 +16,7 @@ /** 滑块小球 dom 元素 */ const circleEl = ref() - const { offset, offsetLeft, setPosition } = useOffset(sliderEl, prop, emit) + const { offset, offsetLeft, setPosition } = useOffset(sliderEl, prop, modelValue) onMounted((): void => { /** 如果元素节点存在 */ diff --git a/packages/fighting-design/swap/src/swap.vue b/packages/fighting-design/swap/src/swap.vue index fd405b350c..8950d460e2 100644 --- a/packages/fighting-design/swap/src/swap.vue +++ b/packages/fighting-design/swap/src/swap.vue @@ -2,12 +2,11 @@ import { Props } from './props' import { FSvgIcon } from '../../svg-icon' import { useRun, useList } from '../../_hooks' - import { EMIT_UPDATE } from '../../_tokens' defineOptions({ name: 'FSwap' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_UPDATE]) + const modelValue = defineModel({ required: true, default: false }) const { run } = useRun() const { classes } = useList(prop, 'swap') @@ -18,7 +17,7 @@ * @param { Object } evt 事件对象 */ const handelClick = (evt: MouseEvent): void => { - emit(EMIT_UPDATE, !prop.modelValue) + modelValue.value = !modelValue.value run(prop.onChange, evt, !prop.modelValue) } diff --git a/packages/fighting-design/switch/src/switch.vue b/packages/fighting-design/switch/src/switch.vue index 1cb4d4a9df..7da0a4e4ad 100644 --- a/packages/fighting-design/switch/src/switch.vue +++ b/packages/fighting-design/switch/src/switch.vue @@ -2,12 +2,11 @@ import { Props } from './props' import { FSvgIcon } from '../../svg-icon' import { useList, useRun, useGlobal } from '../../_hooks' - import { EMIT_UPDATE } from '../../_tokens' defineOptions({ name: 'FSwitch' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_UPDATE]) + const modelValue = defineModel({ required: true, default: false }) const { run } = useRun() const { getProp } = useGlobal(prop) @@ -16,7 +15,7 @@ /** 点击切换 */ const handleClick = (): void => { if (prop.disabled) return - emit(EMIT_UPDATE, !prop.modelValue) + modelValue.value = !modelValue.value run(prop.onChange, !prop.modelValue) } diff --git a/packages/fighting-design/tabs/src/tabs.vue b/packages/fighting-design/tabs/src/tabs.vue index 3a6715b810..ab13c10877 100644 --- a/packages/fighting-design/tabs/src/tabs.vue +++ b/packages/fighting-design/tabs/src/tabs.vue @@ -4,15 +4,14 @@ import { TabsNav } from '../components' import { useTabs } from '../../_hooks' import { warning } from '../../_utils' - import { EMIT_UPDATE } from '../../_tokens' import type { TabsPosition } from './interface' defineOptions({ name: 'FTabs' }) const prop = defineProps(Props) - const emit = defineEmits([EMIT_UPDATE]) + const modelValue = defineModel({ default: null }) - const { navs, activeName, setEdit, setActiveName } = useTabs(prop, emit) + const { navs, activeName, setEdit, setActiveName } = useTabs(prop, modelValue) /** 选项卡标签位置 */ const tabsPosition = computed((): TabsPosition => { diff --git a/packages/fighting-design/time-picker/src/time-picker.vue b/packages/fighting-design/time-picker/src/time-picker.vue index ae9af6eac8..e06a946de8 100644 --- a/packages/fighting-design/time-picker/src/time-picker.vue +++ b/packages/fighting-design/time-picker/src/time-picker.vue @@ -3,24 +3,15 @@ import { reactive, ref, nextTick, watch } from 'vue' import { FInput } from '../../input' import { FTrigger } from '../../trigger' - import { useModel } from '../../_hooks' import { addZero, isString, isBoolean } from '../../_utils' import { FIconClockTime } from '../../_svg' - import { EMIT_TIME } from '../../_tokens' import type { TriggerInstance } from '../../trigger' import type { TimePickerTimeList } from './interface' defineOptions({ name: 'FTimePicker' }) - const prop = defineProps(Props) - const emit = defineEmits([EMIT_TIME]) - - const { keyword } = useModel( - (): string => prop.time, - (val: string): void => { - emit(EMIT_TIME, val) - } - ) + defineProps(Props) + const dateModelValue = defineModel('time', { required: true, default: '' }) /** 获取当前的时间 */ const nowDate: Date = new Date() @@ -49,7 +40,7 @@ * 这里要判断是否为真,并且不是字符串参数 */ if (target && !isString(target)) { - keyword.value = `${timeList.hour}:${timeList.minute}:${timeList.second}` + dateModelValue.value = `${timeList.hour}:${timeList.minute}:${timeList.second}` } if (target === 'now') { @@ -148,7 +139,7 @@ :on-open="scrollNow" > ('files', { required: true, default: [] }) const { run } = useRun() @@ -40,7 +39,7 @@ fileList.value = files } - emit(EMIT_FILES, fileList.value) + filesModelValue.value = fileList.value run(prop.onLoad, files) } diff --git a/start/src/App.vue b/start/src/App.vue index b3fdcd36f1..b71ec2bcbf 100644 --- a/start/src/App.vue +++ b/start/src/App.vue @@ -5,7 +5,16 @@