--添加测试模块
This commit is contained in:
@ -86,7 +86,9 @@
|
||||
});
|
||||
|
||||
const getSchemas = computed<FormSchema[]>(() => {
|
||||
return (unref(getProps).schemas as any) || unref(schemaRef);
|
||||
let schemas = (unref(getProps).schemas as any) || unref(schemaRef)
|
||||
getComponent(schemas);
|
||||
return schemas;
|
||||
});
|
||||
|
||||
// Get the basic configuration of the form
|
||||
@ -110,7 +112,7 @@
|
||||
}
|
||||
|
||||
function getColWidth(schema: any) {
|
||||
const compProps = schema.componentProps;
|
||||
const compProps = schema?.componentProps;
|
||||
if (compProps?.responsive) {
|
||||
if (compProps.respNewRow) {
|
||||
return 24; // 响应式布局下独立成行
|
||||
@ -125,7 +127,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
return schema.colProps?.span;
|
||||
return schema?.colProps?.span;
|
||||
}
|
||||
|
||||
const debGetWrapSize = debounce(getWrapSize, 300);
|
||||
@ -148,7 +150,7 @@
|
||||
});
|
||||
|
||||
function showComponent(schema) {
|
||||
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema.type) : !noShowGenerateComponents.includes(schema.type);
|
||||
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema?.type) : !noShowGenerateComponents.includes(schema?.type);
|
||||
}
|
||||
|
||||
function getIsShow(schema: FormSchema, itemValue: any): boolean {
|
||||
@ -175,22 +177,24 @@
|
||||
}
|
||||
|
||||
function getIfShow(schema: FormSchema, itemValue: any): boolean {
|
||||
const { ifShow } = schema;
|
||||
|
||||
let isIfShow = true;
|
||||
|
||||
if (isBoolean(ifShow)) {
|
||||
isIfShow = ifShow;
|
||||
const { componentProps, show } = schema;
|
||||
let isShow = true;
|
||||
if (isBoolean(componentProps?.isShow)) {
|
||||
isShow = componentProps?.isShow;
|
||||
}
|
||||
if (isFunction(ifShow)) {
|
||||
isIfShow = ifShow({
|
||||
// if (isBoolean(show)) {
|
||||
// isShow = show;
|
||||
// }
|
||||
|
||||
if (isFunction(componentProps?.isShow)) {
|
||||
isShow = componentProps.isShow({
|
||||
values: itemValue,
|
||||
model: formModel!,
|
||||
schema: schema,
|
||||
field: schema.field
|
||||
});
|
||||
}
|
||||
return isIfShow;
|
||||
return isShow;
|
||||
}
|
||||
|
||||
const formModel = reactive<Recordable>(props.formModel);
|
||||
@ -218,8 +222,6 @@
|
||||
|
||||
const refreshFieldObj = ref<object>({});
|
||||
|
||||
getComponent(getSchemas.value);
|
||||
|
||||
function getComponent(component) {
|
||||
const layoutComponents = ['tab', 'grid', 'card'];
|
||||
component?.map((info) => {
|
||||
@ -253,8 +255,10 @@
|
||||
|
||||
function setComponentDefault(item) {
|
||||
if ((staticDataComponents.includes(item.component) && (item.componentProps as any)?.datasourceType === 'staticData') || (needDicDefaultValue.includes(item.type) && (item.componentProps as any)?.datasourceType === 'dic')) {
|
||||
let { defaultSelect } = item.componentProps as any;
|
||||
formModel[item.field] = defaultSelect;
|
||||
if(formModel[item.field]==undefined) {
|
||||
let { defaultSelect } = item.componentProps as any;
|
||||
formModel[item.field] = defaultSelect;
|
||||
}
|
||||
return;
|
||||
}
|
||||
let { defaultValue } = item;
|
||||
@ -277,7 +281,9 @@
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
formModel[item.field] = item.component === 'SubForm' ? [] : defaultValue;
|
||||
if(formModel[item.field]==undefined){
|
||||
formModel[item.field] = item.component === 'SubForm' ? [] : defaultValue;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -413,7 +419,8 @@
|
||||
* 修改bug #5090
|
||||
* 为了保证表单赋值触发所有组件的change事件
|
||||
*/
|
||||
const executeEvent = (allSchemas: FormSchema[]) => {
|
||||
const executeEvent = (allSchemas: FormSchema[] = []) => {
|
||||
if(!allSchemas) return;
|
||||
for (const schema of allSchemas) {
|
||||
//如果是这几个组件 需要查询子级
|
||||
if (['Card', 'Tab', 'Grid'].includes(schema.component)) {
|
||||
@ -442,9 +449,9 @@
|
||||
try {
|
||||
if (typeof handler === 'string') {
|
||||
const event = new Function('schema', 'formModel', 'formActionType', 'extParams', handler);
|
||||
event(schema, formModel, formApi, { formData, allSchemas });
|
||||
event(schema, formModel, formApi, { formData, allSchemas, isPersonChange: false });
|
||||
} else if (typeof handler === 'function') {
|
||||
handler(schema, formModel, formApi, { formData, allSchemas });
|
||||
handler(schema, formModel, formApi, { formData, allSchemas, isPersonChange: false });
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error', error);
|
||||
@ -675,7 +682,7 @@
|
||||
schema.componentProps.style = { ...schema.componentProps.style, ...style };
|
||||
};
|
||||
|
||||
const formApi: FormActionType = {
|
||||
const formApi = {
|
||||
submit,
|
||||
validate,
|
||||
clearValidate,
|
||||
@ -694,9 +701,10 @@
|
||||
httpRequest,
|
||||
refreshAPI,
|
||||
changeStyle,
|
||||
setDefaultValue
|
||||
setDefaultValue,
|
||||
formModel
|
||||
};
|
||||
|
||||
//将表单方法 导出 给父组件使用。
|
||||
defineExpose<FormActionType>(formApi);
|
||||
defineExpose(formApi);
|
||||
</script>
|
||||
|
||||
@ -110,7 +110,7 @@
|
||||
}
|
||||
|
||||
function getColWidth(schema: any) {
|
||||
const compProps = schema.componentProps;
|
||||
const compProps = schema?.componentProps;
|
||||
if (compProps?.responsive) {
|
||||
if (compProps.respNewRow) {
|
||||
return 24; // 响应式布局下独立成行
|
||||
@ -125,7 +125,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
return schema.colProps?.span;
|
||||
return schema?.colProps?.span;
|
||||
}
|
||||
|
||||
const debGetWrapSize = debounce(getWrapSize, 300);
|
||||
@ -148,7 +148,7 @@
|
||||
});
|
||||
|
||||
function showComponent(schema) {
|
||||
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema.type) : !noShowGenerateComponents.includes(schema.type);
|
||||
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema.type) : !noShowGenerateComponents.includes(schema?.type);
|
||||
}
|
||||
|
||||
function getIsShow(schema: FormSchema, itemValue: any): boolean {
|
||||
@ -175,22 +175,15 @@
|
||||
}
|
||||
|
||||
function getIfShow(schema: FormSchema, itemValue: any): boolean {
|
||||
const { ifShow } = schema;
|
||||
|
||||
let isIfShow = true;
|
||||
|
||||
if (isBoolean(ifShow)) {
|
||||
isIfShow = ifShow;
|
||||
const { componentProps, show } = schema;
|
||||
let isShow = true;
|
||||
if (isBoolean(componentProps?.isShow)) {
|
||||
isShow = componentProps?.isShow;
|
||||
}
|
||||
if (isFunction(ifShow)) {
|
||||
isIfShow = ifShow({
|
||||
values: itemValue,
|
||||
model: formModel!,
|
||||
schema: schema,
|
||||
field: schema.field
|
||||
});
|
||||
}
|
||||
return isIfShow;
|
||||
// if (isBoolean(show)) {
|
||||
// isShow = show;
|
||||
// }
|
||||
return isShow;
|
||||
}
|
||||
|
||||
const formModel = reactive<Recordable>(props.formModel);
|
||||
@ -413,7 +406,8 @@
|
||||
* 修改bug #5090
|
||||
* 为了保证表单赋值触发所有组件的change事件
|
||||
*/
|
||||
const executeEvent = (allSchemas: FormSchema[]) => {
|
||||
const executeEvent = (allSchemas: FormSchema[] = []) => {
|
||||
if(!allSchemas) return;
|
||||
for (const schema of allSchemas) {
|
||||
//如果是这几个组件 需要查询子级
|
||||
if (['Card', 'Tab', 'Grid'].includes(schema.component)) {
|
||||
@ -442,9 +436,9 @@
|
||||
try {
|
||||
if (typeof handler === 'string') {
|
||||
const event = new Function('schema', 'formModel', 'formActionType', 'extParams', handler);
|
||||
event(schema, formModel, formApi, { formData, allSchemas });
|
||||
event(schema, formModel, formApi, { formData, allSchemas, isPersonChange: false });
|
||||
} else if (typeof handler === 'function') {
|
||||
handler(schema, formModel, formApi, { formData, allSchemas });
|
||||
handler(schema, formModel, formApi, { formData, allSchemas, isPersonChange: false });
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error', error);
|
||||
@ -672,12 +666,15 @@
|
||||
httpRequest,
|
||||
refreshAPI,
|
||||
changeStyle,
|
||||
setDefaultValue
|
||||
setDefaultValue,
|
||||
formModel
|
||||
};
|
||||
|
||||
//将表单方法 导出 给父组件使用。
|
||||
expose({
|
||||
...formApi
|
||||
...formApi,
|
||||
formModel,
|
||||
getSchemas
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@ -31,6 +31,9 @@
|
||||
:labelAlign="formProps?.labelAlign"
|
||||
:name="schema.field"
|
||||
:wrapperCol="itemLabelWidthProp.wrapperCol"
|
||||
:style="{
|
||||
overflow:'hidden'
|
||||
}"
|
||||
>
|
||||
<component :is="formComponent(schema)" v-model:value="formModel![schema.field]" :disabled="getDisable" :size="formProps?.size" v-bind="schema.componentProps" />
|
||||
</FormItem>
|
||||
@ -84,7 +87,7 @@
|
||||
:wrapperCol="itemLabelWidthProp.wrapperCol"
|
||||
>
|
||||
<template v-if="getDisable && readonlySupport(schema.component)">
|
||||
<readonly :model="formModel" :schema="schema" />
|
||||
<readonly :schema="schema" :model="formModel"/>
|
||||
<component
|
||||
:is="componentMap.get(schema.component)"
|
||||
v-show="false"
|
||||
@ -164,11 +167,11 @@
|
||||
:validateTrigger="['blur', 'change']"
|
||||
:wrapperCol="itemLabelWidthProp.wrapperCol"
|
||||
>
|
||||
<template v-if="getDisable && readonlySupport(schema.component)">
|
||||
<template v-if="getDisable && readonlySupport(schema.component) && !getDisabledShowBorder">
|
||||
<readonly :schema="schema" :value="formModel![schema.field]" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<component :is="defaultComponent(schema)" :key="refreshFieldObj[schema.field]" v-model:value="formModel![schema.field]" :disabled="getDisable" :formData="formModel" :size="formProps?.size" v-bind="getComponentsProps" />
|
||||
<component :is="defaultComponent(schema)" :key="refreshFieldObj[schema.field]" v-model:value="formModel![schema.field]" :disabled="getDisable" :formData="formModel" :size="formProps?.size" v-bind="{...getComponentsProps, placeholder: getDisable ? '' : getComponentsProps.placeholder, disabledShowBorder: getDisabledShowBorder}" :title="readonlySupport(schema.component) ? formModel![schema.field] : ''"/>
|
||||
</template>
|
||||
</FormItem>
|
||||
</template>
|
||||
@ -218,7 +221,8 @@
|
||||
const tabActiveKey = inject<Ref<number>>('tabActiveKey', ref(0));
|
||||
const activeKey = ref<number>(0);
|
||||
const isCamelCase = inject<boolean>('isCamelCase', false);
|
||||
|
||||
// 注入整个表单的配置,formProps是个计算属性,不能修改,formData则来自每个业务的表单页面。
|
||||
const formData = inject('formData', { noInject: true });
|
||||
watch(
|
||||
() => tabActiveKey?.value,
|
||||
(val) => {
|
||||
@ -262,6 +266,17 @@
|
||||
return disabled;
|
||||
});
|
||||
|
||||
const getDisabledShowBorder = computed(() => {
|
||||
let disabledShowBorder = false
|
||||
if (getComponentsProps.value?.disabledShowBorder) {
|
||||
disabledShowBorder = true;
|
||||
}
|
||||
if(import.meta.env?.VITE_GLOB_READ_ONLY_BORDER_DISABLED) {
|
||||
disabledShowBorder = import.meta.env?.VITE_GLOB_READ_ONLY_BORDER_DISABLED == 'true'
|
||||
}
|
||||
return disabledShowBorder
|
||||
})
|
||||
|
||||
const getComponentsProps = computed(() => {
|
||||
let { componentProps = {} } = props.schema;
|
||||
|
||||
@ -356,9 +371,9 @@
|
||||
// console.log('formitem watch!!!!!!!!');
|
||||
//填值以后需要手动校验的组件
|
||||
const validateComponents = ['User', 'RichTextEditor', 'Upload', 'SelectMap'];
|
||||
if (validateComponents.includes(props.schema.component) && formModel![props.schema.field]) {
|
||||
if (validateComponents.includes(props.schema?.component) && formModel![props.schema?.field]) {
|
||||
setTimeout(() => {
|
||||
props.formApi?.validateFields([props.schema.field]);
|
||||
props.formApi?.validateFields([props.schema?.field]);
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
@ -394,32 +409,53 @@
|
||||
};
|
||||
|
||||
function showComponent(schema) {
|
||||
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema.type) : !noShowGenerateComponents.includes(schema.type);
|
||||
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema?.type) : !noShowGenerateComponents.includes(schema?.type);
|
||||
}
|
||||
|
||||
function readonlySupport(name) {
|
||||
return /^(Input|AutoCodeRule|DatePicker|Text|TimePicker|Range|RichTextEditor|TimeRangePicker|RangePicker|InputTextArea)$/.test(name);
|
||||
return /^(Input|AutoCodeRule|DatePicker|Text|TimePicker|Range|RichTextEditor|TimeRangePicker|RangePicker)$/.test(name);
|
||||
}
|
||||
|
||||
function getShow(schema: FormSchema): boolean {
|
||||
const { show } = schema;
|
||||
let isIfShow = true;
|
||||
|
||||
if (isBoolean(show)) {
|
||||
isIfShow = show;
|
||||
}
|
||||
return isIfShow;
|
||||
}
|
||||
|
||||
function getIsShow(schema: FormSchema): boolean {
|
||||
const { componentProps, show } = schema as any;
|
||||
const { componentProps, show } = schema;
|
||||
let isShow = true;
|
||||
if (isBoolean(componentProps?.isShow)) {
|
||||
isShow = componentProps?.isShow;
|
||||
}
|
||||
// if (isBoolean(show)) {
|
||||
// isShow = show;
|
||||
// }
|
||||
|
||||
if (isFunction(componentProps?.isShow)) {
|
||||
isShow = componentProps.isShow({
|
||||
values:formModel![schema.field],
|
||||
model: formModel!,
|
||||
schema: schema,
|
||||
field: schema.field
|
||||
});
|
||||
}
|
||||
|
||||
return isShow;
|
||||
}
|
||||
|
||||
function getIsShow(schema: FormSchema): boolean {
|
||||
const { show } = schema;
|
||||
|
||||
let isShow = true;
|
||||
|
||||
if (isBoolean(show)) {
|
||||
isShow = show;
|
||||
}
|
||||
if (isFunction(show)) {
|
||||
isShow = show({
|
||||
values:formModel![schema.field],
|
||||
model: formModel!,
|
||||
schema: schema,
|
||||
field: schema.field
|
||||
});
|
||||
}
|
||||
|
||||
isShow = isShow;
|
||||
return isShow;
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -53,6 +53,8 @@
|
||||
const tabActiveKey = inject<Ref<number>>('tabActiveKey', ref(0));
|
||||
const activeKey = ref<number>(0);
|
||||
const isCamelCase = inject<boolean>('isCamelCase', false);
|
||||
// 注入整个表单的配置,formProps是个计算属性,不能修改,formData则来自每个业务的表单页面。
|
||||
const formData = inject('formData', { noInject: true });
|
||||
watch(
|
||||
() => tabActiveKey?.value,
|
||||
(val) => {
|
||||
@ -122,7 +124,7 @@
|
||||
let field = camelCaseString(item);
|
||||
if (field) cloneFormModel[field] = cloneFormModel[item];
|
||||
}
|
||||
event(props.schema, isCamelCase ? cloneFormModel : formModel, props.formApi, {});
|
||||
event(props.schema, isCamelCase ? cloneFormModel : formModel, props.formApi, { formData });
|
||||
|
||||
if (isCamelCase) {
|
||||
for (let item in formModel) {
|
||||
@ -188,7 +190,7 @@
|
||||
// console.log('formitem watch!!!!!!!!');
|
||||
//填值以后需要手动校验的组件
|
||||
const validateComponents = ['User', 'RichTextEditor', 'Upload', 'SelectMap'];
|
||||
if (validateComponents.includes(props.schema.component) && formModel![props.schema.field]) {
|
||||
if (validateComponents.includes(props.schema?.component) && formModel![props.schema.field]) {
|
||||
setTimeout(() => {
|
||||
props.formApi?.validateFields([props.schema.field]);
|
||||
}, 100);
|
||||
@ -209,7 +211,7 @@
|
||||
};
|
||||
|
||||
function showComponent(schema) {
|
||||
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema.type) : !noShowGenerateComponents.includes(schema.type);
|
||||
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema?.type) : !noShowGenerateComponents.includes(schema?.type);
|
||||
}
|
||||
|
||||
function readonlySupport(name) {
|
||||
@ -217,24 +219,35 @@
|
||||
}
|
||||
|
||||
function getShow(schema: FormSchema): boolean {
|
||||
const { show } = schema;
|
||||
let isIfShow = true;
|
||||
|
||||
if (isBoolean(show)) {
|
||||
isIfShow = show;
|
||||
}
|
||||
return isIfShow;
|
||||
}
|
||||
|
||||
function getIsShow(schema: FormSchema): boolean {
|
||||
const { componentProps, show } = schema as any;
|
||||
const { componentProps, show } = schema;
|
||||
let isShow = true;
|
||||
if (isBoolean(componentProps?.isShow)) {
|
||||
isShow = componentProps?.isShow;
|
||||
}
|
||||
// if (isBoolean(show)) {
|
||||
// isShow = show;
|
||||
// }
|
||||
return isShow;
|
||||
}
|
||||
|
||||
function getIsShow(schema: FormSchema): boolean {
|
||||
const { show } = schema;
|
||||
|
||||
let isShow = true;
|
||||
|
||||
if (isBoolean(show)) {
|
||||
isShow = show;
|
||||
}
|
||||
if (isFunction(show)) {
|
||||
isShow = show({
|
||||
values: itemValue,
|
||||
model: formModel!,
|
||||
schema: schema,
|
||||
field: schema.field
|
||||
});
|
||||
}
|
||||
|
||||
isShow = isShow;
|
||||
return isShow;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user