chore: Fix ts type error (#3112)
This commit is contained in:
parent
ae09d3cfd6
commit
8289332214
|
|
@ -117,14 +117,19 @@
|
||||||
const getSchema = computed((): FormSchema[] => {
|
const getSchema = computed((): FormSchema[] => {
|
||||||
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
|
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
|
||||||
for (const schema of schemas) {
|
for (const schema of schemas) {
|
||||||
const { defaultValue, component, componentProps,isHandleDateDefaultValue = true } = schema;
|
const {
|
||||||
|
defaultValue,
|
||||||
|
component,
|
||||||
|
componentProps,
|
||||||
|
isHandleDateDefaultValue = true,
|
||||||
|
} = schema;
|
||||||
// handle date type
|
// handle date type
|
||||||
if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) {
|
if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) {
|
||||||
const valueFormat =componentProps ? componentProps['valueFormat'] : null;
|
const valueFormat = componentProps ? componentProps['valueFormat'] : null;
|
||||||
if (!Array.isArray(defaultValue)) {
|
if (!Array.isArray(defaultValue)) {
|
||||||
schema.defaultValue = valueFormat
|
schema.defaultValue = valueFormat
|
||||||
? dateUtil(defaultValue).format(valueFormat)
|
? dateUtil(defaultValue).format(valueFormat)
|
||||||
: dateUtil(defaultValue);
|
: dateUtil(defaultValue);
|
||||||
} else {
|
} else {
|
||||||
const def: any[] = [];
|
const def: any[] = [];
|
||||||
defaultValue.forEach((item) => {
|
defaultValue.forEach((item) => {
|
||||||
|
|
|
||||||
|
|
@ -88,15 +88,15 @@ export function useForm(props?: Props): UseFormReturnType {
|
||||||
return unref(formRef)?.getFieldsValue() as T;
|
return unref(formRef)?.getFieldsValue() as T;
|
||||||
},
|
},
|
||||||
|
|
||||||
setFieldsValue: async <T>(values: T) => {
|
setFieldsValue: async <T extends Recordable<any>>(values: T) => {
|
||||||
const form = await getForm();
|
const form = await getForm();
|
||||||
form.setFieldsValue<T>(values);
|
form.setFieldsValue(values);
|
||||||
},
|
},
|
||||||
|
|
||||||
appendSchemaByField: async (
|
appendSchemaByField: async (
|
||||||
schema: FormSchema | FormSchema[],
|
schema: FormSchema | FormSchema[],
|
||||||
prefixField: string | undefined,
|
prefixField: string | undefined,
|
||||||
first: boolean,
|
first?: boolean,
|
||||||
) => {
|
) => {
|
||||||
const form = await getForm();
|
const form = await getForm();
|
||||||
form.appendSchemaByField(schema, prefixField, first);
|
form.appendSchemaByField(schema, prefixField, first);
|
||||||
|
|
@ -107,7 +107,7 @@ export function useForm(props?: Props): UseFormReturnType {
|
||||||
return form.submit();
|
return form.submit();
|
||||||
},
|
},
|
||||||
|
|
||||||
validate: async (nameList?: NamePath[]): Promise<Recordable> => {
|
validate: async (nameList?: NamePath[] | false): Promise<Recordable> => {
|
||||||
const form = await getForm();
|
const form = await getForm();
|
||||||
return form.validate(nameList);
|
return form.validate(nameList);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,11 @@ export function renderThumbStyle({ move, size, bar }) {
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extend<T, K>(to: T, _from: K): T & K {
|
function extend<T extends object, K extends object>(to: T, _from: K): T & K {
|
||||||
return Object.assign(to, _from);
|
return Object.assign(to, _from);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toObject<T>(arr: Array<T>): Recordable<T> {
|
export function toObject<T extends object>(arr: Array<T>): Recordable<T> {
|
||||||
const res = {};
|
const res = {};
|
||||||
for (let i = 0; i < arr.length; i++) {
|
for (let i = 0; i < arr.length; i++) {
|
||||||
if (arr[i]) {
|
if (arr[i]) {
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,12 @@ import { mitt } from '/@/utils/mitt';
|
||||||
import type { RouteLocationNormalized } from 'vue-router';
|
import type { RouteLocationNormalized } from 'vue-router';
|
||||||
import { getRawRoute } from '/@/utils';
|
import { getRawRoute } from '/@/utils';
|
||||||
|
|
||||||
const emitter = mitt();
|
|
||||||
|
|
||||||
const key = Symbol();
|
const key = Symbol();
|
||||||
|
|
||||||
|
const emitter = mitt<{
|
||||||
|
[key]: RouteLocationNormalized;
|
||||||
|
}>();
|
||||||
|
|
||||||
let lastChangeTab: RouteLocationNormalized;
|
let lastChangeTab: RouteLocationNormalized;
|
||||||
|
|
||||||
export function setRouteChange(lastChangeRoute: RouteLocationNormalized) {
|
export function setRouteChange(lastChangeRoute: RouteLocationNormalized) {
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,9 @@ function genBem(name: string, mods?: Mods): string {
|
||||||
return ` ${name}--${mods}`;
|
return ` ${name}--${mods}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArrayConstructor.isArray(arg: any): arg is any[]
|
||||||
if (Array.isArray(mods)) {
|
if (Array.isArray(mods)) {
|
||||||
return mods.reduce<string>((ret, item) => ret + genBem(name, item), '');
|
return (mods as Mod[]).reduce<string>((ret, item) => ret + genBem(name, item), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.keys(mods).reduce((ret, key) => ret + (mods[key] ? genBem(name, key) : ''), '');
|
return Object.keys(mods).reduce((ret, key) => ret + (mods[key] ? genBem(name, key) : ''), '');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue