This commit is contained in:
dap
2024-09-15 09:16:26 +08:00
28 changed files with 127 additions and 78 deletions

View File

@@ -177,7 +177,7 @@ export class FormApi {
}
unmounted() {
this.state = null;
// this.state = null;
this.isMounted = false;
this.stateHandler.reset();
}

View File

@@ -16,7 +16,7 @@ import {
import { cn, isFunction, isObject, isString } from '@vben-core/shared/utils';
import { toTypedSchema } from '@vee-validate/zod';
import { useFormValues } from 'vee-validate';
import { useFieldError, useFormValues } from 'vee-validate';
import { injectRenderFormProps, useFormContext } from './context';
import useDependencies from './dependencies';
@@ -43,8 +43,11 @@ const {
const { componentBindEventMap, componentMap, isVertical } = useFormContext();
const formRenderProps = injectRenderFormProps();
const values = useFormValues();
const errors = useFieldError(fieldName);
const formApi = formRenderProps.form;
const isInValid = computed(() => errors.value?.length > 0);
const fieldComponent = computed(() => {
const finalComponent = isString(component)
? componentMap.value[component]
@@ -217,6 +220,7 @@ function createComponentProps(slotProps: Record<string, any>) {
<FormItem
v-show="isShow"
:class="{
'form-valid-error': isInValid,
'flex-col': isVertical,
'flex-row items-center': !isVertical,
}"
@@ -248,10 +252,14 @@ function createComponentProps(slotProps: Record<string, any>) {
...slotProps,
...createComponentProps(slotProps),
disabled: shouldDisabled,
isInValid,
}"
>
<component
:is="fieldComponent"
:class="{
'border-destructive focus:border-destructive': isInValid,
}"
v-bind="createComponentProps(slotProps)"
:disabled="shouldDisabled"
>

View File

@@ -1,7 +1,8 @@
import type { ModalState } from '../modal';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { ModalApi } from '../modal-api'; // 假设 ModalApi 位于同一目录
import type { ModalState } from '../modal';
import { ModalApi } from '../modal-api';
vi.mock('@vben-core/shared/store', () => {
return {

View File

@@ -52,7 +52,9 @@ defineExpose({
<template>
<DialogPortal>
<DialogOverlay v-if="open && modal" @click="() => emits('close')" />
<Transition name="fade">
<DialogOverlay v-if="open && modal" @click="() => emits('close')" />
</Transition>
<DialogContent
ref="contentRef"
v-bind="forwarded"

View File

@@ -5,7 +5,7 @@ useScrollLock();
</script>
<template>
<div
class="data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 bg-overlay fixed inset-0 z-[1000]"
class="bg-overlay fixed inset-0 z-[1000]"
data-dismissable-modal="true"
></div>
</template>

View File

@@ -46,7 +46,9 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
<template>
<DialogPortal>
<SheetOverlay v-if="open && modal" />
<Transition name="fade">
<SheetOverlay v-if="open && modal" />
</Transition>
<DialogContent
:class="cn(sheetVariants({ side }), 'z-[1000]', props.class)"
v-bind="{ ...forwarded, ...$attrs }"

View File

@@ -5,7 +5,7 @@ useScrollLock();
</script>
<template>
<div
class="bg-overlay data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-[1000]"
class="bg-overlay fixed inset-0 z-[1000]"
data-dismissable-modal="true"
></div>
</template>