@ -2,65 +2,68 @@
< div >
<!-- 如果是grid 组件 需要新增grid布局包裹 -- >
< template v-if = "schema.component.includes('Grid')" >
< Row v-show = "getIsShow(schema)" :align="(schema.componentProps as any).align"
: gutter = "(schema.componentProps as any).gutter ?? 0" : justify = "(schema.componentProps as any).justify"
type = "flex" >
< Row v-show = "getIsShow(schema)" :align="(schema.componentProps as any).align" :gutter="(schema.componentProps as any).gutter ?? 0" :justify="(schema.componentProps as any).justify" type="flex" >
< Col v-for = "(col, colIndex) in schema.children" :key="colIndex" :span="col.span" >
< template v-for = "childSchema in col.list" :key="childSchema.field" >
< SimpleFormItem v-if = "showComponent(childSchema)" v-model:value="formModel![childSchema.field]"
:form-api = "formApi" :isWorkFlow = "isWorkFlow" :label-col = "labelCol"
:refreshFieldObj = "refreshFieldObj" :schema = "childSchema" / >
< SimpleFormItem v-if = "showComponent(childSchema)" v-model:value="formModel![childSchema.field]" :form-api="formApi" :isWorkFlow="isWorkFlow" :label-col="labelCol" :refreshFieldObj="refreshFieldObj" :schema="childSchema" / >
< / template >
< / Col >
< / Row >
< / template >
<!-- 如果是tab 组件 需要新增tab组件包裹 -- >
< template v-else-if = "schema.component === 'Tab'" >
< Tabs v-show = "getIsShow(schema)" v-model:activeKey="activeKey"
: size = "(schema.componentProps as any).tabSize" : tabPosition = "(schema.componentProps as any).tabPosition"
: type = "(schema.componentProps as any).type" >
< Tabs v-show = "getIsShow(schema)" v-model:activeKey="activeKey" :size="(schema.componentProps as any).tabSize" :tabPosition="(schema.componentProps as any).tabPosition" :type="(schema.componentProps as any).type" >
< TabPane v-for = "(tab, tabIndex) in schema.children" :key="tabIndex" :forceRender="true" :tab="tab.name" >
< template v-for = "childSchema in tab.list" :key="childSchema.field" >
< SimpleFormItem v-if = "showComponent(childSchema)" v-model:value="formModel![childSchema.field]"
:form-api = "formApi" :isWorkFlow = "isWorkFlow" :refreshFieldObj = "refreshFieldObj"
:schema = "childSchema" / >
< SimpleFormItem v-if = "showComponent(childSchema)" v-model:value="formModel![childSchema.field]" :form-api="formApi" :isWorkFlow="isWorkFlow" :refreshFieldObj="refreshFieldObj" :schema="childSchema" / >
< / template >
< / TabPane >
< / Tabs >
< / template >
<!-- 如果是子表单 组件 需要v - model : value = "表单对象[字段名]" -- >
< template v-else-if = "schema.component.includes('Form')" >
< FormItem v-if = "getShow(schema)" v-show="getIsShow(schema)" :key="schema.key"
: label = "getComponentsProps.showLabel ? schema.label : ''" :label-col = "labelCol "
:labelAlign = "formProps?.labelAlign" :name = "schema.field" :wrapperCol = "itemLabelWidthProp.wrapperCol" >
< component :is = "formComponent(schema)" v -model :value = "formModel![schema.field]" :disabled = "getDisable "
:size = "form Props? .size" v-bind = "schema.componentProps" / >
< FormItem
v-if = "getShow(schema) "
v-show = "getIsShow(schema)"
:key = "schema.key "
: label = "getComponents Props.showLabel ? schema.label : ''"
:label-col = "labelCol"
:labelAlign = "formProps?.labelAlign"
:name = "schema.field"
:wrapperCol = "itemLabelWidthProp.wrapperCol"
>
< component :is = "formComponent(schema)" v -model :value = "formModel![schema.field]" :disabled = "getDisable" :size = "formProps?.size" v-bind = "schema.componentProps" / >
< / FormItem >
< / template >
<!-- 如果是子表单 组件 需要v - model : value = "表单对象[字段名]" -- >
< template v-else-if = "schema.component.includes('OneForOne')" >
< FormItem v-if = "getShow(schema)" v-show="getIsShow(schema)" :key="schema.key"
: label = "getComponentsProps.showLabel ? schema.label : ''" :label-col = "labelCol "
:labelAlign = "formProps?.labelAlign" :name = "schema.field" :wrapperCol = "itemLabelWidthProp.wrapperCol" >
< component :is = "componentMap.get(schema.component)" v -model :value = "formModel![ schema.field] "
:disabled = "getDisable" :refreshFieldObj = "refreshFieldObj" :size = "formProps?.size "
v-bind = "schema.componentProps" / >
< FormItem
v-if = "getShow(schema) "
v-show = "getIsShow(schema)"
:key = " schema.key "
: label = "getComponentsProps.showLabel ? schema.label : '' "
:label-col = "labelCol"
:labelAlign = "formProps?.labelAlign"
:name = "schema.field"
:wrapperCol = "itemLabelWidthProp.wrapperCol"
>
< component :is = "componentMap.get(schema.component)" v -model :value = "formModel![schema.field]" :disabled = "getDisable" :refreshFieldObj = "refreshFieldObj" :size = "formProps?.size" v-bind = "schema.componentProps" / >
< / FormItem >
< / template >
< template v-else-if = "schema.component === 'TableLayout'" >
< TableLayoutPreview v-if = "getShow(schema)" v-show="getIsShow(schema)" :element="schema" >
< template # tdElement = "{ tdElement }" >
< div class = "h-full" >
< div : style = "{
< div
: style = "{
height: tdElement.height ? tdElement.height + 'px' : '',
minHeight: (tdElement.height || '42') + 'px',
overflow: 'hidden',
padding: '10px'
}">
}"
>
< template v-for = "childSchema in tdElement.children" :key="childSchema.field" >
< SimpleFormItem v-if = "showComponent(childSchema)"
v -model :value = "formModel![childSchema.field]" :form-api = "formApi"
:isWorkFlow = "isWorkFlow" :refreshFieldObj = "refreshFieldObj" :schema = "childSchema" / >
< SimpleFormItem v-if = "showComponent(childSchema)" v-model:value="formModel![childSchema.field]" :form-api="formApi" :isWorkFlow="isWorkFlow" :refreshFieldObj="refreshFieldObj" :schema="childSchema" / >
< / template >
< / div >
< / div >
@ -69,41 +72,51 @@
< / template >
<!-- 如果是时间区间 组件 需要v - model : startField = "表单对象[字段名]" v - model : endField = "表单对象[字段名]" -- >
< template v-else-if = "schema.component.includes('Range')" >
< FormItem v-if = "getShow(schema)" v-show="getIsShow(schema)" :key="schema.key"
: label = "getComponentsProps.showLabel ? schema.label : ''" :label-col = "labelCol" :name = "schema.field "
:rules = "rules" : validateTrigger = "['blur', 'change']" :wrapperCol = "itemLabelWidthProp.wrapperCol" >
< component :is = "componentMap.get(schema.component)" v -model :endField = "schema.field.split(',')[1] "
v -model :startFi eld = "schema.field.split(',')[0]" v -model :value = "formModel![schema.field] "
:disabled = "getDisable" :size = "formProps?.size" v-bind = "schema.componentProps" / >
< FormItem
v-if = "getShow(schema) "
v-show = "getIsShow(schema)"
:key = "schema.key "
: lab el= "getComponentsProps.showLabel ? schema.label : '' "
:label-col = "labelCol"
:name = "schema.field"
:rules = "rules"
: validateTrigger = "['blur', 'change']"
:wrapperCol = "itemLabelWidthProp.wrapperCol"
>
< template v-if = "getDisable && readonlySupport(schema.component)" >
< readonly :schema = "schema" :model = "formModel" / >
< / template >
< template v-else >
< component
:is = "componentMap.get(schema.component)"
v -model :endField = "schema.field.split(',')[1]"
v -model :startField = "schema.field.split(',')[0]"
v -model :value = "formModel![schema.field]"
:disabled = "getDisable"
:size = "formProps?.size"
v-bind = "schema.componentProps"
/ >
< / template >
< / FormItem >
<!-- 因为Range会变为 开始时间 和 结束时间 2 个属性给与表单数据 所以需要2个隐藏框绑定 starTime 和 endTime -- >
< FormItem v-show = "false" :key="schema.key" :label="getComponentsProps.showLabel ? schema.label : ''"
:name = "schema.field.split(',')[0]" >
< FormItem v-show = "false" :key="schema.key" :label="getComponentsProps.showLabel ? schema.label : ''" :name="schema.field.split(',')[0]" >
< input type = "hidden" / >
< / FormItem >
< FormItem v-show = "false" :key="schema.key" :label="getComponentsProps.showLabel ? schema.label : ''"
:name = "schema.field.split(',')[1]" >
< FormItem v-show = "false" :key="schema.key" :label="getComponentsProps.showLabel ? schema.label : ''" :name="schema.field.split(',')[1]" >
< input type = "hidden" / >
< / FormItem >
< / template >
<!-- 如果checked 或者 switch组件 需要v - model : checked = "表单对象[字段名]" "-->
<template v-else-if=" checkedValueComponents . includes ( schema . component ) ">
<FormItem v-if=" getShow ( schema ) " v-show=" getIsShow ( schema ) " :key=" schema . key "
:label=" getComponentsProps . showLabel ? schema . label : '' " :label-col=" labelCol " :nam e=" schema . field "
:rules=" rules " :wrapperCol=" itemLabelWidthProp . wrapperCol ">
<component :is=" componentMap . get ( schema . component ) " :key=" refreshFieldObj [ schema . field ] "
v-model:checked=" formModel ! [ schema . field ] " :disabled=" getDisable " :size=" formProps ? . size "
v-bind=" getComponentsProps " />
<FormItem v-if=" getShow ( schema ) " v-show=" getIsShow ( schema ) " :key=" schema . key " :label=" getComponentsProps . showLabel ? schema . label : '' " :label-col=" labelCol " :name=" schema . field " :rules=" rules " :wrapperCol=" itemLabelWidthProp . wrapperCol ">
<component :is=" componentMap . get ( schema . component ) " :key=" refreshFieldObj [ schema . field ] " v-model:checked=" formModel ! [ schema . field ] " :disabled=" getDisable " :siz e=" formProps ? . size " v-bind=" getComponentsProps " />
</FormItem>
</template>
<!--如果是card 组件 需要新增card组件包裹-->
<template v-else-if=" schema . component . includes ( 'Card' ) ">
<CollapseContainer v-show=" getIsShow ( schema ) " :bordered=" false " :hasLeftBorder=" true "
:title=" ( schema . componentProps as any ) . title ">
<CollapseContainer v-show=" getIsShow ( schema ) " :bordered=" false " :hasLeftBorder=" true " :title=" ( schema . componentProps as any ) . title ">
<template v-for=" childSchema in schema . children ! [ 0 ] . list " :key=" childSchema . field ">
<SimpleFormItem v-if=" showComponent ( childSchema ) " v-model:value=" formModel ! [ childSchema . field ] "
:form-api=" formApi " :isWorkFlow=" isWorkFlow " :refreshFieldObj=" refreshFieldObj "
:schema=" childSchema " />
<SimpleFormItem v-if=" showComponent ( childSchema ) " v-model:value=" formModel ! [ childSchema . field ] " :form-api=" formApi " :isWorkFlow=" isWorkFlow " :refreshFieldObj=" refreshFieldObj " :schema=" childSchema " />
</template>
</CollapseContainer>
</template>
@ -115,52 +128,64 @@
</template>
<!--如果是 意见簿 组件 需要使用defaultValue直接赋值 -->
<template v-else-if=" schema . component . includes ( 'Opinion' ) ">
<FormItem v-if=" getShow ( schema ) " v-show=" getIsShow ( schema ) " :key=" schema . key "
:label =" getComponentsProps . showLabel ? schema . label : '' " :label-col=" labelCol " :name=" schema . field "
:rules=" rules " :validateTrigger=" [ 'blur' , 'change' ] " :wrapperCol=" itemLabelWidthProp . wrapperCol ">
<component :is=" componentMap . get ( schema . component ) " :key=" refreshFieldObj [ schema . field ] "
:disabled=" getDisable " :size=" form Props ? . size " :value=" schema . defaultValue "
v-bind=" getComponentsProps " />
<FormItem
v-if =" getShow ( schema ) "
v-show=" getIsShow ( schema ) "
:key=" schema . key "
:label=" getComponents Props . showLabel ? schema . label : '' "
:label-col=" labelCol "
:name=" schema . field "
:rules=" rules "
:validateTrigger=" [ 'blur' , 'change' ] "
:wrapperCol=" itemLabelWidthProp . wrapperCol "
>
<component :is=" componentMap . get ( schema . component ) " :key=" refreshFieldObj [ schema . field ] " :disabled=" getDisable " :size=" formProps ? . size " :value=" schema . defaultValue " v-bind=" getComponentsProps " />
</FormItem>
</template>
<template v-else>
<FormItem v-if=" getShow ( schema ) " v-show=" getIsShow ( schema ) " :key=" schema . key "
:label =" getComponentsProps . showLabel ? schema . label : '' " :label-col=" labelCol " :name=" schema . field "
:rules=" rules " :validateTrigger=" [ 'blur' , 'change' ] " :wrapperCol=" itemLabelWidthProp . wrapperCol ">
<FormItem
v-if =" getShow ( schema ) "
v-show=" getIsShow ( schema ) "
:key=" schema . key "
:label=" getComponentsProps . showLabel ? schema . label : '' "
:label-col=" labelCol "
:name=" schema . field "
:rules=" rules "
:validateTrigger=" [ 'blur' , 'change' ] "
:wrapperCol=" itemLabelWidthProp . wrapperCol "
>
<template v-if=" getDisable && readonlySupport ( schema . component ) ">
<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 " :size=" formProps ? . size "
v-bind=" getComponentsProps " />
<component :is=" defaultComponent ( schema ) " :key=" refreshFieldObj [ schema . field ] " v-model:value=" formModel ! [ schema . field ] " :disabled=" getDisable " :size=" formProps ? . size " v-bind=" getComponentsProps " />
</template>
</FormItem>
</template>
</div>
</template>
<script lang=" ts " setup>
import { Form, Col, Row, Tabs, TabPane, Divider } from 'ant-design-vue';
import { isBoolean, isFunction, upperFirst, cloneDeep } from 'lodash-es';
import { computed, onMounted, unref, inject, Ref, watch, ref } from 'vue';
import { componentMap } from '/@/components/Form/src/componentMap';
import { checkedValueComponents } from '/@/components/Form/src/helper';
import { useItemLabelWidth } from '/@/components/Form/src/hooks/useLabelWidth';
import { FormActionType, FormProps, FormSchema } from '/@/components/Form/src/types/form';
import { CollapseContainer } from '/@/components/Container';
import { noShowWorkFlowComponents, noShowGenerateComponents } from '/@/components/Form/src/helper';
import { useMessage } from '/@/hooks/web/useMessage';
import TableLayoutPreview from '/@/components/Form/src/components/TableLayoutPreview.vue';
import { camelCaseString } from '/@/utils/event/design';
import Readonly from '/@/components/Form/src/components/Readonly.vue';
import { Form, Col, Row, Tabs, TabPane, Divider } from 'ant-design-vue';
import { isBoolean, isFunction, upperFirst, cloneDeep } from 'lodash-es';
import { computed, onMounted, unref, inject, Ref, watch, ref } from 'vue';
import { componentMap } from '/@/components/Form/src/componentMap';
import { checkedValueComponents } from '/@/components/Form/src/helper';
import { useItemLabelWidth } from '/@/components/Form/src/hooks/useLabelWidth';
import { FormActionType, FormProps, FormSchema } from '/@/components/Form/src/types/form';
import { CollapseContainer } from '/@/components/Container';
import { noShowWorkFlowComponents, noShowGenerateComponents } from '/@/components/Form/src/helper';
import { useMessage } from '/@/hooks/web/useMessage';
import TableLayoutPreview from '/@/components/Form/src/components/TableLayoutPreview.vue';
import { camelCaseString } from '/@/utils/event/design';
import Readonly from '/@/components/Form/src/components/Readonly.vue';
const FormItem = Form.Item;
const FormItem = Form.Item;
const props = defineProps({
const props = defineProps({
// 表单配置规则
schema: {
type: Object as PropType<FormSchema>,
default: () => { }
default: () => {}
},
value: [Object, String, Number, Boolean, Array],
formApi: {
@ -169,23 +194,23 @@ const props = defineProps({
//刷新api使用
refreshFieldObj: {
type: Object,
default: () => { }
default: () => {}
},
//是否是工作流
isWorkFlow: {
type: Boolean,
default: false
}
});
});
const formModel = inject<Recordable>('formModel');
const formProps = inject<Ref<FormProps>>('formProps');
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(
const formModel = inject<Recordable>('formModel');
const formProps = inject<Ref<FormProps>>('formProps');
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) => {
if (props.isWorkFlow) activeKey.value = val!;
@ -193,8 +218,8 @@ watch(
{
immediate: true
}
);
watch(
);
watch(
() => activeKey?.value,
(val) => {
if (props.isWorkFlow) tabActiveKey.value = val!;
@ -202,43 +227,43 @@ watch(
{
immediate: true
}
);
);
// watch(
// () => props.value,
// (val) => {
// if (!val) return;
// let { componentProps = {} } = props.schema;
// if (componentProps['events']) {
// for (const eventKey in componentProps['events']) {
// try {
// const event = new Function(
// 'schema',
// 'formModel',
// 'formActionType',
// `${componentProps['events'][eventKey]}`,
// );
// event(props.schema, formModel, props.formApi);
// } catch (error) {
// notification.error({
// message: 'Tip',
// description: '触发事件填写有误!',
// });
// }
// }
// }
// },
// {
// immediate: true,
// },
// );
// watch(
// () => props.value,
// (val) => {
// if (!val) return;
// let { componentProps = {} } = props.schema;
// if (componentProps['events']) {
// for (const eventKey in componentProps['events']) {
// try {
// const event = new Function(
// 'schema',
// 'formModel',
// 'formActionType',
// `${componentProps['events'][eventKey]}`,
// );
// event(props.schema, formModel, props.formApi);
// } catch (error) {
// notification.error({
// message: 'Tip',
// description: '触发事件填写有误!',
// });
// }
// }
// }
// },
// {
// immediate: true,
// },
// );
const { notification } = useMessage();
const getSchema = computed(() => {
const { notification } = useMessage();
const getSchema = computed(() => {
return props.schema as FormSchema;
});
});
const getDisable = computed(() => {
const getDisable = computed(() => {
const { disabled: globDisabled } = formProps!.value;
const { dynamicDisabled } = getSchema.value;
const { disabled: itemDisabled = false } = unref(getComponentsProps);
@ -255,9 +280,9 @@ const getDisable = computed(() => {
});
}
return disabled;
});
});
const getComponentsProps = computed(() => {
const getComponentsProps = computed(() => {
let { componentProps = {} } = props.schema;
if (isFunction(componentProps)) {
@ -313,9 +338,9 @@ const getComponentsProps = computed(() => {
}
return componentProps as Recordable;
});
});
const labelCol = computed(() => {
const labelCol = computed(() => {
// 列宽支持两种模式 labelWidthMode = flex为百分比宽度 fix 为定宽
const commonLabelCol = unref(itemLabelWidthProp).labelCol;
const itemLabelCol = unref(getComponentsProps).labelCol;
@ -329,9 +354,9 @@ const labelCol = computed(() => {
};
}
return labelCol;
});
});
const rules = computed(() => {
const rules = computed(() => {
const requiredRule = {
required: unref(getComponentsProps).required || false,
message: `${props.schema.label}是必填项`
@ -340,11 +365,11 @@ const rules = computed(() => {
if (!rulesList) return [requiredRule];
rulesList?.map((item) => (item.pattern = eval(item.pattern)));
return [...rulesList, requiredRule];
});
});
//根据labelwidth 生成labelCol
const itemLabelWidthProp = useItemLabelWidth(getSchema, formProps!);
watch(
//根据labelwidth 生成labelCol
const itemLabelWidthProp = useItemLabelWidth(getSchema, formProps!);
watch(
() => formModel,
() => {
// console.log('formitem watch!!!!!!!!');
@ -360,8 +385,8 @@ watch(
deep: true,
immediate: true
}
);
onMounted(() => {
);
onMounted(() => {
// console.log('onMounted');
// if (
// staticDataComponents.includes(props.schema.component) &&
@ -377,25 +402,25 @@ onMounted(() => {
// emit('update:value', defaultValue);
// }
// }
});
});
const formComponent = (schema) => {
const formComponent = (schema) => {
return componentMap.get(['caseErpApplyDetailList', 'case_erp_apply_detailList', 'CASE_ERP_APPLY_DETAILList'].includes(schema.field) ? 'ErpApply' : schema.component);
};
};
const defaultComponent = (schema) => {
const defaultComponent = (schema) => {
return componentMap.get(schema.key === 'ac18952da41b45c9a66ffba3e42b7f3d' ? 'ErpUpload' : schema.key === 'b3ba87573cf0466d951bc63fd4df1c78' ? 'ErpCheck' : schema.component);
};
};
function showComponent(schema) {
function showComponent(schema) {
return props.isWorkFlow ? !noShowWorkFlowComponents.includes(schema.type) : !noShowGenerateComponents.includes(schema.type);
}
}
function readonlySupport(name) {
return /Input|AutoCodeRule|DatePicker|Text|TimePicker|Info/.test(name)
}
function readonlySupport(name) {
return /Input|AutoCodeRule|DatePicker|Text|TimePicker|Info|Range /.test(name);
}
function getShow(schema: FormSchema): boolean {
function getShow(schema: FormSchema): boolean {
const { show } = schema;
let isIfShow = true;
@ -403,9 +428,9 @@ function getShow(schema: FormSchema): boolean {
isIfShow = show;
}
return isIfShow;
}
}
function getIsShow(schema: FormSchema): boolean {
function getIsShow(schema: FormSchema): boolean {
const { componentProps, show } = schema as any;
let isShow = true;
if (isBoolean(componentProps?.isShow)) {
@ -415,17 +440,17 @@ function getIsShow(schema: FormSchema): boolean {
isShow = show;
}
return isShow;
}
}
</script>
<style lang=" less " scoped>
:deep(.ant-form-item-label > label) {
:deep(.ant-form-item-label > label) {
white-space: normal;
display: inline;
line-height: 28 px;
}
line-height: 3 2px;
}
</style>
<style lang=" less " >
. ant - select - disabled {
. ant - select - disabled {
. ant - select - selector {
border : none ! important ;
background - color : transparent ! important ;
@ -439,5 +464,5 @@ function getIsShow(schema: FormSchema): boolean {
. ant - select - arrow {
display : none ;
}
}
}
< / style >