bowen
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
22 additions and
14 deletions
-
src/components/Form/src/BasicForm.vue
-
src/components/Form/src/hooks/useForm.ts
-
src/components/Scrollbar/src/util.ts
-
src/logics/mitt/routeChange.ts
-
src/utils/bem.ts
|
|
|
@ -117,14 +117,19 @@ |
|
|
|
const getSchema = computed((): FormSchema[] => { |
|
|
|
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any); |
|
|
|
for (const schema of schemas) { |
|
|
|
const { defaultValue, component, componentProps,isHandleDateDefaultValue = true } = schema; |
|
|
|
const { |
|
|
|
defaultValue, |
|
|
|
component, |
|
|
|
componentProps, |
|
|
|
isHandleDateDefaultValue = true, |
|
|
|
} = schema; |
|
|
|
// handle date type |
|
|
|
if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) { |
|
|
|
const valueFormat =componentProps ? componentProps['valueFormat'] : null; |
|
|
|
const valueFormat = componentProps ? componentProps['valueFormat'] : null; |
|
|
|
if (!Array.isArray(defaultValue)) { |
|
|
|
schema.defaultValue = valueFormat |
|
|
|
? dateUtil(defaultValue).format(valueFormat) |
|
|
|
: dateUtil(defaultValue); |
|
|
|
schema.defaultValue = valueFormat |
|
|
|
? dateUtil(defaultValue).format(valueFormat) |
|
|
|
: dateUtil(defaultValue); |
|
|
|
} else { |
|
|
|
const def: any[] = []; |
|
|
|
defaultValue.forEach((item) => { |
|
|
|
|
|
|
|
@ -88,15 +88,15 @@ export function useForm(props?: Props): UseFormReturnType { |
|
|
|
return unref(formRef)?.getFieldsValue() as T; |
|
|
|
}, |
|
|
|
|
|
|
|
setFieldsValue: async <T>(values: T) => { |
|
|
|
setFieldsValue: async <T extends Recordable<any>>(values: T) => { |
|
|
|
const form = await getForm(); |
|
|
|
form.setFieldsValue<T>(values); |
|
|
|
form.setFieldsValue(values); |
|
|
|
}, |
|
|
|
|
|
|
|
appendSchemaByField: async ( |
|
|
|
schema: FormSchema | FormSchema[], |
|
|
|
prefixField: string | undefined, |
|
|
|
first: boolean, |
|
|
|
first?: boolean, |
|
|
|
) => { |
|
|
|
const form = await getForm(); |
|
|
|
form.appendSchemaByField(schema, prefixField, first); |
|
|
|
@ -107,7 +107,7 @@ export function useForm(props?: Props): UseFormReturnType { |
|
|
|
return form.submit(); |
|
|
|
}, |
|
|
|
|
|
|
|
validate: async (nameList?: NamePath[]): Promise<Recordable> => { |
|
|
|
validate: async (nameList?: NamePath[] | false): Promise<Recordable> => { |
|
|
|
const form = await getForm(); |
|
|
|
return form.validate(nameList); |
|
|
|
}, |
|
|
|
|
|
|
|
@ -36,11 +36,11 @@ export function renderThumbStyle({ move, size, bar }) { |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
export function toObject<T>(arr: Array<T>): Recordable<T> { |
|
|
|
export function toObject<T extends object>(arr: Array<T>): Recordable<T> { |
|
|
|
const res = {}; |
|
|
|
for (let i = 0; i < arr.length; i++) { |
|
|
|
if (arr[i]) { |
|
|
|
|
|
|
|
@ -6,10 +6,12 @@ import { mitt } from '/@/utils/mitt'; |
|
|
|
import type { RouteLocationNormalized } from 'vue-router'; |
|
|
|
import { getRawRoute } from '/@/utils'; |
|
|
|
|
|
|
|
const emitter = mitt(); |
|
|
|
|
|
|
|
const key = Symbol(); |
|
|
|
|
|
|
|
const emitter = mitt<{ |
|
|
|
[key]: RouteLocationNormalized; |
|
|
|
}>(); |
|
|
|
|
|
|
|
let lastChangeTab: RouteLocationNormalized; |
|
|
|
|
|
|
|
export function setRouteChange(lastChangeRoute: RouteLocationNormalized) { |
|
|
|
|
|
|
|
@ -14,8 +14,9 @@ function genBem(name: string, mods?: Mods): string { |
|
|
|
return ` ${name}--${mods}`; |
|
|
|
} |
|
|
|
|
|
|
|
// ArrayConstructor.isArray(arg: any): arg is any[]
|
|
|
|
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) : ''), ''); |
|
|
|
|