From f83471ed9f6476ac18c6532c709aceb2e37507c9 Mon Sep 17 00:00:00 2001 From: Eiinu Date: Thu, 11 Apr 2024 10:35:05 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=20provide/inject=20=E4=BD=BF=E7=94=A8=20(#3027)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/__VUE/audio/index.vue | 4 ++-- src/packages/__VUE/audio/types.ts | 2 ++ src/packages/__VUE/audiooperate/index.vue | 4 ++-- src/packages/__VUE/audiooperate/types.ts | 1 - src/packages/__VUE/form/common.ts | 1 + src/packages/__VUE/form/form.taro.vue | 4 ++-- src/packages/__VUE/form/form.vue | 4 ++-- src/packages/__VUE/formitem/form-item.taro.vue | 4 ++-- src/packages/__VUE/formitem/form-item.vue | 4 ++-- src/packages/__VUE/tabpane/index.taro.vue | 3 ++- src/packages/__VUE/tabpane/index.vue | 3 ++- src/packages/__VUE/tabs/index.taro.vue | 4 ++-- src/packages/__VUE/tabs/index.vue | 4 ++-- src/packages/__VUE/tabs/types.ts | 1 + 14 files changed, 24 insertions(+), 19 deletions(-) delete mode 100644 src/packages/__VUE/audiooperate/types.ts diff --git a/src/packages/__VUE/audio/index.vue b/src/packages/__VUE/audio/index.vue index 63b642721b..eba633d367 100644 --- a/src/packages/__VUE/audio/index.vue +++ b/src/packages/__VUE/audio/index.vue @@ -64,7 +64,7 @@ import { toRefs, ref, onMounted, reactive, watch, provide, type PropType } from import { createComponent } from '@/packages/utils/create' import { Service } from '@nutui/icons-vue' import NutRange from '../range/index.vue' -import type { AudioType } from './types' +import { AUDIO_KEY, type AudioType } from './types' const { create } = createComponent('audio') export default create({ @@ -257,7 +257,7 @@ export default create({ } ) - provide('audioParent', { + provide(AUDIO_KEY, { children: [], props, audioData, diff --git a/src/packages/__VUE/audio/types.ts b/src/packages/__VUE/audio/types.ts index c87f8fbe9d..ee860da2dc 100644 --- a/src/packages/__VUE/audio/types.ts +++ b/src/packages/__VUE/audio/types.ts @@ -1 +1,3 @@ export type AudioType = 'progress' | 'icon' | 'controls' | 'none' +export type AudioOperateType = 'play' | 'back' | 'forward' | 'mute' +export const AUDIO_KEY = Symbol('nut-audio') diff --git a/src/packages/__VUE/audiooperate/index.vue b/src/packages/__VUE/audiooperate/index.vue index 2d33825e51..0056572011 100644 --- a/src/packages/__VUE/audiooperate/index.vue +++ b/src/packages/__VUE/audiooperate/index.vue @@ -32,7 +32,7 @@ import { toRefs, ref, useSlots, reactive, inject, type PropType } from 'vue' import { createComponent } from '@/packages/utils/create' import NutButton from '../button' import { useLocale } from '@/packages/utils/useLocale' -import type { AudioOperateType } from './types' +import { type AudioOperateType, AUDIO_KEY } from '../audio/types' const { create } = createComponent('audio-operate') const cN = 'NutAudioOperate' @@ -52,7 +52,7 @@ export default create({ setup(props) { const translate = useLocale(cN) - const audio: any = inject('audioParent') + const audio: any = inject(AUDIO_KEY) const parent: { children: [] audioData: any diff --git a/src/packages/__VUE/audiooperate/types.ts b/src/packages/__VUE/audiooperate/types.ts deleted file mode 100644 index a6c6945b34..0000000000 --- a/src/packages/__VUE/audiooperate/types.ts +++ /dev/null @@ -1 +0,0 @@ -export type AudioOperateType = 'play' | 'back' | 'forward' | 'mute' diff --git a/src/packages/__VUE/form/common.ts b/src/packages/__VUE/form/common.ts index 692dc73644..7a51f820a7 100644 --- a/src/packages/__VUE/form/common.ts +++ b/src/packages/__VUE/form/common.ts @@ -4,6 +4,7 @@ import type { ComputedRef, Ref } from 'vue' export const FORM_KEY = Symbol('nut-form') export const FORM_DISABLED_KEY = Symbol('nut-form-disabled') +export const FORM_TIP_KEY = Symbol('nut-form-tip') export const useFormDisabled = (disabled: Ref): ComputedRef => { const { parent } = useParent(FORM_DISABLED_KEY) diff --git a/src/packages/__VUE/form/form.taro.vue b/src/packages/__VUE/form/form.taro.vue index ac5ca568ed..468372a043 100644 --- a/src/packages/__VUE/form/form.taro.vue +++ b/src/packages/__VUE/form/form.taro.vue @@ -10,7 +10,7 @@ import { reactive, computed, provide, watch } from 'vue' import { useChildren, getPropByPath, isPromise } from '@/packages/utils' import NutCellGroup from '../cellgroup/index.taro' import type { FormErrorMessage, FormLabelPosition, FormRule, FormRules, FormStarPosition, FormItemRule } from './types' -import { FORM_KEY, FORM_DISABLED_KEY } from './common' +import { FORM_KEY, FORM_DISABLED_KEY, FORM_TIP_KEY } from './common' defineOptions({ name: 'NutForm' @@ -42,7 +42,7 @@ linkChildren2({ props }) const formErrorTip = computed(() => reactive({})) -provide('formErrorTip', formErrorTip) +provide(FORM_TIP_KEY, formErrorTip) const clearErrorTips = () => { Object.keys(formErrorTip.value).forEach((item) => { formErrorTip.value[item] = '' diff --git a/src/packages/__VUE/form/form.vue b/src/packages/__VUE/form/form.vue index bc1ad2f5c9..48181fa450 100644 --- a/src/packages/__VUE/form/form.vue +++ b/src/packages/__VUE/form/form.vue @@ -10,7 +10,7 @@ import { reactive, computed, provide, watch } from 'vue' import { useChildren, getPropByPath, isPromise } from '@/packages/utils' import NutCellGroup from '../cellgroup' import type { FormErrorMessage, FormLabelPosition, FormRule, FormRules, FormStarPosition, FormItemRule } from './types' -import { FORM_KEY, FORM_DISABLED_KEY } from './common' +import { FORM_KEY, FORM_DISABLED_KEY, FORM_TIP_KEY } from './common' defineOptions({ name: 'NutForm' @@ -42,7 +42,7 @@ linkChildren2({ props }) const formErrorTip = computed(() => reactive({})) -provide('formErrorTip', formErrorTip) +provide(FORM_TIP_KEY, formErrorTip) const clearErrorTips = () => { Object.keys(formErrorTip.value).forEach((item) => { formErrorTip.value[item] = '' diff --git a/src/packages/__VUE/formitem/form-item.taro.vue b/src/packages/__VUE/formitem/form-item.taro.vue index 94c0dbb5c3..112a40e259 100644 --- a/src/packages/__VUE/formitem/form-item.taro.vue +++ b/src/packages/__VUE/formitem/form-item.taro.vue @@ -28,7 +28,7 @@ import { pxCheck } from '@/packages/utils/pxCheck' import { computed, inject, CSSProperties } from 'vue' import type { FormItemRule, FormLabelPosition, FormStarPosition } from '../form/types' import NutCell from '../cell/index.taro' -import { FORM_KEY } from '../form/common' +import { FORM_KEY, FORM_TIP_KEY } from '../form/common' import { useParent } from '@/packages/utils' defineOptions({ @@ -84,7 +84,7 @@ const starPositionClass = computed(() => { return position !== 'left' ? `nut-form-item__star-${position}` : '' }) -const parent = inject('formErrorTip') as any +const parent = inject(FORM_TIP_KEY) as any const labelStyle = computed(() => { return { diff --git a/src/packages/__VUE/formitem/form-item.vue b/src/packages/__VUE/formitem/form-item.vue index 90dce612aa..7254e2a43b 100644 --- a/src/packages/__VUE/formitem/form-item.vue +++ b/src/packages/__VUE/formitem/form-item.vue @@ -28,7 +28,7 @@ import { pxCheck } from '@/packages/utils/pxCheck' import { computed, inject, CSSProperties } from 'vue' import type { FormItemRule, FormLabelPosition, FormStarPosition } from '../form/types' import NutCell from '../cell' -import { FORM_KEY } from '../form/common' +import { FORM_KEY, FORM_TIP_KEY } from '../form/common' import { useParent } from '@/packages/utils' defineOptions({ @@ -84,7 +84,7 @@ const starPositionClass = computed(() => { return position !== 'left' ? `nut-form-item__star-${position}` : '' }) -const parent = inject('formErrorTip') as any +const parent = inject(FORM_TIP_KEY) as any const labelStyle = computed(() => { return { diff --git a/src/packages/__VUE/tabpane/index.taro.vue b/src/packages/__VUE/tabpane/index.taro.vue index 7067ac1ce8..895721ce1b 100644 --- a/src/packages/__VUE/tabpane/index.taro.vue +++ b/src/packages/__VUE/tabpane/index.taro.vue @@ -6,6 +6,7 @@