表单创建页面及只读页面修改,formlist列表跳转修改

This commit is contained in:
GAOANG
2024-04-02 14:18:15 +08:00
parent 6fa16313cc
commit 528e8038bb
6 changed files with 546 additions and 508 deletions

View File

@ -142,6 +142,16 @@ componentMap.set('ErpApply', ErpApply);
componentMap.set('ErpUpload', ErpUpload); componentMap.set('ErpUpload', ErpUpload);
componentMap.set('ErpCheck', ErpCheck); componentMap.set('ErpCheck', ErpCheck);
componentMap.set('AutoComplete', AutoComplete); componentMap.set('AutoComplete', AutoComplete);
const readonlySupportList = [
"Input",
"AutoCodeRule",
"DatePicker",
"TimePicker",
"Info",
"Text",
'InputTextArea',
'InputNumber'
]
export function add(compName: ComponentType, component: Component) { export function add(compName: ComponentType, component: Component) {
componentMap.set(compName, component); componentMap.set(compName, component);
@ -151,4 +161,10 @@ export function del(compName: ComponentType) {
componentMap.delete(compName); componentMap.delete(compName);
} }
export { componentMap }; export function isreadComponent() {
let str = readonlySupportList.join('|')
const reg = new RegExp(str);
return reg
}
export { componentMap, readonlySupportList };

View File

@ -3,40 +3,41 @@
</template> </template>
<script setup> <script setup>
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { readonlySupportList } from '/@/components/Form/src/componentMap';
const props = defineProps({ const props = defineProps({
value: String, value: String,
schema: Object, schema: Object,
}); });
const fieldValue = ref(genFieldValue(props.value)); const fieldValue = ref(genFieldValue(props.value));
function genFieldValue(val) { function genFieldValue(val) {
if (!props?.schema || (!val && val !== 0)) { if (!props?.schema || (!val && val !== 0)) {
return ''; return '';
} }
const schema = props.schema; const schema = props.schema;
const { componentProps, component } = schema; const { componentProps, component } = schema;
if (['Input', 'AutoCodeRule', 'DatePicker', 'InputTextArea', 'InputNumber'].includes(component)) { if (readonlySupportList.includes(component)) {
return `${componentProps?.addonBefore || ''}${val}${componentProps?.addonAfter || ''}`; return `${componentProps?.addonBefore || ''}${val}${componentProps?.addonAfter || ''}`;
} }
if (component === 'Switch') { if (component === 'Switch') {
return val === 1 ? '是' : '否'; return val === 1 ? '是' : '否';
} }
} }
watch( watch(
() => props.value, () => props.value,
(newValue) => { (newValue) => {
fieldValue.value = genFieldValue(newValue); fieldValue.value = genFieldValue(newValue);
}, },
); );
</script> </script>
<style> <style>
.field-readonly { .field-readonly {
white-space: pre-wrap; white-space: pre-wrap;
} }
</style> </style>

View File

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

View File

@ -523,7 +523,7 @@ export function buildListCode(model: GeneratorConfig): string {
hasBatchDeleteButton || hasTemplatePrint || (hasSetUserIdButton && isSetDataAuth) hasBatchDeleteButton || hasTemplatePrint || (hasSetUserIdButton && isSetDataAuth)
? `:row-selection="{ selectedRowKeys: selectedKeys, onChange: onSelectChange }"` ? `:row-selection="{ selectedRowKeys: selectedKeys, onChange: onSelectChange }"`
: '' : ''
}> } @row-dbClick="dbClickRow">
${ ${
hasFilterButton hasFilterButton
? `<template #customFilterIcon="{ filtered, column }" > ? `<template #customFilterIcon="{ filtered, column }" >
@ -988,6 +988,43 @@ ${hasTemplatePrint ? ' reactive ' : ''}
} }
}); });
function dbClickRow(record) {
if (!record.workflowData.schemaId && !record.workflowData.taskIds) {
${
formType === 'modal'
? `
router.push({
path: '/form/${lowerClassName}/' + record.id + '/viewForm',
query: {
formPath: '${model.outputConfig.outputValue}/${lowerClassName}'
}
});`
: `
openDrawer(true, {
isView: true,
id: record.${camelCaseString(mainTable.pkField)},
});`
}
} else if (record.workflowData.taskIds && record.workflowData.taskIds.length) {
const { processId, taskIds, schemaId } = record.workflowData;
router.push({
path: '/flow/' + schemaId + '/' + (processId || '') + '/approveFlow',
query: {
taskId: taskIds[0]
}
});
} else {
const { processId, schemaId } = record.workflowData;
router.push({
path: '/flow/' + schemaId + '/' + (processId || '') + '/approveFlow',
query: {
readonly: 1,
taskId: ''
}
});
}
}
function buttonClick(code) { function buttonClick(code) {
${ ${
hasTemplatePrint hasTemplatePrint
@ -1682,6 +1719,7 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
systemFormRef.value, systemFormRef.value,
formProps.schemas); //表单事件:加载表单 formProps.schemas); //表单事件:加载表单
} }
emits('form-mounted', formProps);
} catch (error) { } catch (error) {
} }

View File

@ -173,7 +173,6 @@ function getTaskRecords() {
} }
onMounted(async () => { onMounted(async () => {
if (unref(taskId)) {
try { try {
let res = await getApprovalProcess(unref(taskId), unref(processId)); let res = await getApprovalProcess(unref(taskId), unref(processId));
initProcessData(res); initProcessData(res);
@ -197,8 +196,6 @@ onMounted(async () => {
} }
renderKey.value = Math.random() + ''; renderKey.value = Math.random() + '';
} catch (error) { } } catch (error) { }
} else {
}
}); });
async function submit() { async function submit() {

View File

@ -21,53 +21,54 @@
</template> </template>
<script setup> <script setup>
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { FromPageType } from '/@/enums/workflowEnum'; import { FromPageType } from '/@/enums/workflowEnum';
import { ref, computed, onMounted, onBeforeMount, nextTick, defineAsyncComponent } from 'vue'; import { ref, computed, onMounted, onBeforeMount, nextTick, defineAsyncComponent } from 'vue';
import { useMessage } from '/@/hooks/web/useMessage'; import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { CheckCircleOutlined, StopOutlined, CloseOutlined } from '@ant-design/icons-vue'; import { CheckCircleOutlined, StopOutlined, CloseOutlined } from '@ant-design/icons-vue';
import { useMultipleTabStore } from '/@/store/modules/multipleTab'; import { useMultipleTabStore } from '/@/store/modules/multipleTab';
import useEventBus from '/@/hooks/event/useEventBus'; import useEventBus from '/@/hooks/event/useEventBus';
const dynamicComponent = ref(null); const dynamicComponent = ref(null);
const formType = ref('2'); // 0 新建 1 修改 2 查看 const formType = ref('2'); // 0 新建 1 修改 2 查看
const formRef = ref(); const formRef = ref();
const props = defineProps({}); const props = defineProps({});
const { bus, FORM_LIST_MODIFIED } = useEventBus(); const { bus, FORM_LIST_MODIFIED } = useEventBus();
const router = useRouter(); const router = useRouter();
const { currentRoute } = router; const { currentRoute } = router;
const { formPath } = currentRoute.value.query; const { formPath } = currentRoute.value.query;
const pathArr = formPath.split('/'); const pathArr = formPath.split('/');
const tabStore = useMultipleTabStore(); const tabStore = useMultipleTabStore();
const formProps = ref(null); const formProps = ref(null);
const formId = ref(currentRoute.value?.params?.id); console.error(currentRoute.value)
const formId = ref(currentRoute.value?.params?.id);
const { notification } = useMessage(); const { notification } = useMessage();
const { t } = useI18n(); const { t } = useI18n();
const hash = location.hash; const hash = location.hash;
const mode = ref('read'); const mode = ref('read');
if (hash.indexOf('createForm') > 0) { if (hash.indexOf('createForm') > 0) {
mode.value = 'create'; mode.value = 'create';
} else if (hash.indexOf('updateForm') > 0) { } else if (hash.indexOf('updateForm') > 0) {
mode.value = 'update'; mode.value = 'update';
} else if (hash.indexOf('viewForm') > 0) { } else if (hash.indexOf('viewForm') > 0) {
mode.value = 'view'; mode.value = 'view';
} }
dynamicComponent.value = defineAsyncComponent({ dynamicComponent.value = defineAsyncComponent({
loader: () => import(`./../../views/${pathArr[0]}/${pathArr[1]}/components/Form.vue`) loader: () => import(`./../../views/${pathArr[0]}/${pathArr[1]}/components/Form.vue`)
}); });
function onFormMounted(_formProps) { function onFormMounted(_formProps) {
formProps.value = _formProps; formProps.value = _formProps;
setFormType(); setFormType();
} }
async function setFormType() { async function setFormType() {
const _mode = mode.value; const _mode = mode.value;
if (_mode === 'create') { if (_mode === 'create') {
return; return;
@ -76,14 +77,15 @@
if (_mode === 'view') { if (_mode === 'view') {
await formRef.value.setDisabledForm(); await formRef.value.setDisabledForm();
} }
// console.error(55555, _formProps)
await formRef.value.setFormDataFromId(formId.value); await formRef.value.setFormDataFromId(formId.value);
} }
function close() { function close() {
tabStore.closeTab(currentRoute.value, router); tabStore.closeTab(currentRoute.value, router);
} }
async function handleSubmit() { async function handleSubmit() {
try { try {
const saveSuccess = await saveModal(); const saveSuccess = await saveModal();
if (saveSuccess) { if (saveSuccess) {
@ -99,9 +101,9 @@
} }
} finally { } finally {
} }
} }
async function saveModal() { async function saveModal() {
let saveSuccess = false; let saveSuccess = false;
const _mode = mode.value; const _mode = mode.value;
try { try {
@ -120,22 +122,22 @@
saveSuccess = await formRef.value.update({ values, rowId: formId.value }); saveSuccess = await formRef.value.update({ values, rowId: formId.value });
} }
return saveSuccess; return saveSuccess;
} catch (error) {} } catch (error) { }
} }
} catch (error) { } catch (error) {
console.error('saveModal Error: ', error); console.error('saveModal Error: ', error);
} }
} }
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.page-bg-wrap { .page-bg-wrap {
background-color: #fff; background-color: #fff;
} }
.top-toolbar { .top-toolbar {
min-height: 40px; min-height: 40px;
margin-bottom: 8px; margin-bottom: 8px;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
} }
</style> </style>