From 5a046509376ee6b58fa50c8931e58ad272fe1c79 Mon Sep 17 00:00:00 2001 From: devin Date: Wed, 4 Jan 2023 09:56:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96provide=E4=B9=A6=E5=86=99?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/_shared/constant.ts | 2 - .../src/components/_shared/global.ts | 9 ----- .../src/components/option/OOption.vue | 39 +++++++++++-------- .../opendesign/src/components/option/types.ts | 4 ++ .../src/components/select/OSelect.vue | 9 +++-- .../src/components/select/provide.ts | 9 +++++ .../opendesign/src/components/select/types.ts | 6 ++- 7 files changed, 45 insertions(+), 33 deletions(-) delete mode 100644 packages/opendesign/src/components/_shared/constant.ts create mode 100644 packages/opendesign/src/components/select/provide.ts diff --git a/packages/opendesign/src/components/_shared/constant.ts b/packages/opendesign/src/components/_shared/constant.ts deleted file mode 100644 index 814b4a97..00000000 --- a/packages/opendesign/src/components/_shared/constant.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const PROVIDE_KEY_UPTION_UPDATE = Symbol('provide-option/update'); -export const PROVIDE_KEY_UPTION_VALUE = Symbol('provide-option/value'); diff --git a/packages/opendesign/src/components/_shared/global.ts b/packages/opendesign/src/components/_shared/global.ts index cca90c63..8e90de33 100644 --- a/packages/opendesign/src/components/_shared/global.ts +++ b/packages/opendesign/src/components/_shared/global.ts @@ -13,12 +13,3 @@ export function initSize(type: SizeT) { export type ShapeT = 'round' | 'normal' export const defaultShape = ref('normal'); - -export function initShape(shape: ShapeT) { - defaultShape.value = shape; -} - -export interface OptionValueT { - label: string; - value: string | number; -} \ No newline at end of file diff --git a/packages/opendesign/src/components/option/OOption.vue b/packages/opendesign/src/components/option/OOption.vue index 83d4a0bc..82b2bdad 100644 --- a/packages/opendesign/src/components/option/OOption.vue +++ b/packages/opendesign/src/components/option/OOption.vue @@ -1,37 +1,44 @@ diff --git a/packages/opendesign/src/components/option/types.ts b/packages/opendesign/src/components/option/types.ts index e69de29b..cb71603b 100644 --- a/packages/opendesign/src/components/option/types.ts +++ b/packages/opendesign/src/components/option/types.ts @@ -0,0 +1,4 @@ +export interface OptionItemT { + label: string; + value: string | number; +} \ No newline at end of file diff --git a/packages/opendesign/src/components/select/OSelect.vue b/packages/opendesign/src/components/select/OSelect.vue index e6dc56e8..a7c79345 100644 --- a/packages/opendesign/src/components/select/OSelect.vue +++ b/packages/opendesign/src/components/select/OSelect.vue @@ -2,10 +2,10 @@ import { provide, ref } from 'vue'; import { defaultSize, defaultShape } from '../_shared/global'; import type { SizeT, ShapeT } from '../_shared/global'; -import { PROVIDE_KEY_UPTION_UPDATE, PROVIDE_KEY_UPTION_VALUE } from '../_shared/constant'; -import type { OptionValueT } from '../_shared/global'; import { IconArrowTraingleDown } from '../icons'; import { OPopup, PopupPositionT } from '../popup'; +import { selectOptionUpdateFnInjectKey, selectOptionValueInjectKey } from './provide'; +import { SelectOptionT } from './types'; interface SelectPropT { size?: SizeT; @@ -33,7 +33,7 @@ const emits = defineEmits(['update:modelValue']); const selectRef = ref(); const showOption = ref(false); -provide(PROVIDE_KEY_UPTION_UPDATE, (val: OptionValueT, emit?: boolean) => { +provide(selectOptionUpdateFnInjectKey, (val: SelectOptionT, emit?: boolean) => { activeLabel.value = val.label; if (emit) { emits('update:modelValue', val.value); @@ -42,7 +42,8 @@ provide(PROVIDE_KEY_UPTION_UPDATE, (val: OptionValueT, emit?: boolean) => { } }); -provide(PROVIDE_KEY_UPTION_VALUE, activeVal); +provide(selectOptionValueInjectKey, activeVal); + const onOptionChange = (visible: boolean) => { if (visible) { console.log(selectRef.value?.clientWidth); diff --git a/packages/opendesign/src/components/select/provide.ts b/packages/opendesign/src/components/select/provide.ts new file mode 100644 index 00000000..48ccc966 --- /dev/null +++ b/packages/opendesign/src/components/select/provide.ts @@ -0,0 +1,9 @@ +import { InjectionKey, Ref } from 'vue'; +import { SelectOptionT } from './types'; + + +export const selectOptionUpdateFnInjectKey: InjectionKey<(val: SelectOptionT, emit?: boolean) => void> = + Symbol('provide-select-option/updateFn'); + +export const selectOptionValueInjectKey: InjectionKey> = + Symbol('provide-select-option/value'); diff --git a/packages/opendesign/src/components/select/types.ts b/packages/opendesign/src/components/select/types.ts index 139597f9..859f1ef1 100644 --- a/packages/opendesign/src/components/select/types.ts +++ b/packages/opendesign/src/components/select/types.ts @@ -1,2 +1,4 @@ - - +export interface SelectOptionT { + label: string; + value: string | number; +} \ No newline at end of file -- Gitee From b85ac27b4948998161bb897d826cb30f0a91a247 Mon Sep 17 00:00:00 2001 From: devin Date: Wed, 4 Jan 2023 10:00:14 +0800 Subject: [PATCH 2/2] rm --- packages/opendesign/src/components/option/index.ts | 2 -- packages/opendesign/src/components/option/types.ts | 4 ---- 2 files changed, 6 deletions(-) delete mode 100644 packages/opendesign/src/components/option/types.ts diff --git a/packages/opendesign/src/components/option/index.ts b/packages/opendesign/src/components/option/index.ts index 34f7ead8..45c30c0f 100644 --- a/packages/opendesign/src/components/option/index.ts +++ b/packages/opendesign/src/components/option/index.ts @@ -1,8 +1,6 @@ import _OOption from './OOption.vue'; import type { App } from 'vue'; -// export * from './types'; - const OOption = Object.assign(_OOption, { install(app: App) { app.component(_OOption.name, _OOption); diff --git a/packages/opendesign/src/components/option/types.ts b/packages/opendesign/src/components/option/types.ts deleted file mode 100644 index cb71603b..00000000 --- a/packages/opendesign/src/components/option/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface OptionItemT { - label: string; - value: string | number; -} \ No newline at end of file -- Gitee