|
@@ -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;
|