mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-26 08:36:19 +08:00
fix(form): improve warning prompt, fix #538
This commit is contained in:
@@ -35,17 +35,7 @@
|
||||
import type { AdvanceState } from './types/hooks';
|
||||
import type { CSSProperties, Ref } from 'vue';
|
||||
|
||||
import {
|
||||
defineComponent,
|
||||
reactive,
|
||||
ref,
|
||||
computed,
|
||||
unref,
|
||||
onMounted,
|
||||
watch,
|
||||
toRefs,
|
||||
nextTick,
|
||||
} from 'vue';
|
||||
import { defineComponent, reactive, ref, computed, unref, onMounted, watch, nextTick } from 'vue';
|
||||
import { Form, Row } from 'ant-design-vue';
|
||||
import FormItem from './components/FormItem.vue';
|
||||
import FormAction from './components/FormAction.vue';
|
||||
@@ -143,13 +133,8 @@
|
||||
defaultValueRef,
|
||||
});
|
||||
|
||||
const { transformDateFunc, fieldMapToTime, autoFocusFirstItem } = toRefs(
|
||||
unref(getProps)
|
||||
) as any;
|
||||
|
||||
const { handleFormValues, initDefault } = useFormValues({
|
||||
transformDateFuncRef: transformDateFunc,
|
||||
fieldMapToTimeRef: fieldMapToTime,
|
||||
getProps,
|
||||
defaultValueRef,
|
||||
getSchema,
|
||||
formModel,
|
||||
@@ -157,7 +142,7 @@
|
||||
|
||||
useAutoFocus({
|
||||
getSchema,
|
||||
autoFocusFirstItem,
|
||||
getProps,
|
||||
isInitedDefault: isInitedDefaultRef,
|
||||
formElRef: formElRef as Ref<FormActionType>,
|
||||
});
|
||||
|
@@ -1,22 +1,22 @@
|
||||
import type { ComputedRef, Ref } from 'vue';
|
||||
import type { FormSchema, FormActionType } from '../types/form';
|
||||
import type { FormSchema, FormActionType, FormProps } from '../types/form';
|
||||
|
||||
import { unref, nextTick, watchEffect } from 'vue';
|
||||
|
||||
interface UseAutoFocusContext {
|
||||
getSchema: ComputedRef<FormSchema[]>;
|
||||
autoFocusFirstItem: Ref<boolean>;
|
||||
getProps: ComputedRef<FormProps>;
|
||||
isInitedDefault: Ref<boolean>;
|
||||
formElRef: Ref<FormActionType>;
|
||||
}
|
||||
export async function useAutoFocus({
|
||||
getSchema,
|
||||
autoFocusFirstItem,
|
||||
getProps,
|
||||
formElRef,
|
||||
isInitedDefault,
|
||||
}: UseAutoFocusContext) {
|
||||
watchEffect(async () => {
|
||||
if (unref(isInitedDefault) || !unref(autoFocusFirstItem)) return;
|
||||
if (unref(isInitedDefault) || !unref(getProps).autoFocusFirstItem) return;
|
||||
await nextTick();
|
||||
const schemas = unref(getSchema);
|
||||
const formEl = unref(formElRef);
|
||||
|
@@ -3,21 +3,19 @@ import { dateUtil } from '/@/utils/dateUtil';
|
||||
|
||||
import { unref } from 'vue';
|
||||
import type { Ref, ComputedRef } from 'vue';
|
||||
import type { FieldMapToTime, FormSchema } from '../types/form';
|
||||
import type { FormProps, FormSchema } from '../types/form';
|
||||
|
||||
interface UseFormValuesContext {
|
||||
transformDateFuncRef: Ref<Fn>;
|
||||
fieldMapToTimeRef: Ref<FieldMapToTime>;
|
||||
defaultValueRef: Ref<any>;
|
||||
getSchema: ComputedRef<FormSchema[]>;
|
||||
getProps: ComputedRef<FormProps>;
|
||||
formModel: Recordable;
|
||||
}
|
||||
export function useFormValues({
|
||||
transformDateFuncRef,
|
||||
fieldMapToTimeRef,
|
||||
defaultValueRef,
|
||||
getSchema,
|
||||
formModel,
|
||||
getProps,
|
||||
}: UseFormValuesContext) {
|
||||
// Processing form values
|
||||
function handleFormValues(values: Recordable) {
|
||||
@@ -31,12 +29,12 @@ export function useFormValues({
|
||||
if ((isArray(value) && value.length === 0) || isFunction(value)) {
|
||||
continue;
|
||||
}
|
||||
const transformDateFunc = unref(transformDateFuncRef);
|
||||
const transformDateFunc = unref(getProps).transformDateFunc;
|
||||
if (isObject(value)) {
|
||||
value = transformDateFunc(value);
|
||||
value = transformDateFunc?.(value);
|
||||
}
|
||||
if (isArray(value) && value[0]?._isAMomentObject && value[1]?._isAMomentObject) {
|
||||
value = value.map((item) => transformDateFunc(item));
|
||||
value = value.map((item) => transformDateFunc?.(item));
|
||||
}
|
||||
// Remove spaces
|
||||
if (isString(value)) {
|
||||
@@ -51,7 +49,7 @@ export function useFormValues({
|
||||
* @description: Processing time interval parameters
|
||||
*/
|
||||
function handleRangeTimeValue(values: Recordable) {
|
||||
const fieldMapToTime = unref(fieldMapToTimeRef);
|
||||
const fieldMapToTime = unref(getProps).fieldMapToTime;
|
||||
|
||||
if (!fieldMapToTime || !Array.isArray(fieldMapToTime)) {
|
||||
return values;
|
||||
|
Reference in New Issue
Block a user