提交 c2023d3b authored 作者: liuluyu's avatar liuluyu

更新流程记录表单

上级 5cf77944
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
<!-- <template #footer> <!-- <template #footer>
<div class="drawer-footer"> <div class="drawer-footer">
<a-button @click="handleClose">取消123</a-button> <a-button @click="handleClose">取消</a-button>
<a-button type="primary" :loading="submitLoading" @click="handleSubmit"> 提交 </a-button> <a-button type="primary" :loading="submitLoading" @click="handleSubmit"> 提交 </a-button>
</div> </div>
</template> --> </template> -->
......
...@@ -89,12 +89,10 @@ ...@@ -89,12 +89,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ref, reactive, nextTick } from 'vue'; import { ref, reactive, nextTick } from 'vue';
import { FileTextOutlined, UserOutlined, CalendarOutlined, ClockCircleOutlined, FormOutlined } from '@ant-design/icons-vue'; import { FileTextOutlined, UserOutlined, CalendarOutlined, ClockCircleOutlined, FormOutlined } from '@ant-design/icons-vue';
import { flowRecord } from '/@/components/Process/api/finished'; import { flowRecord } from '/@/components/Process/api/finished';
import { flowXmlAndNode } from '/@/components/Process/api/definition'; import { flowXmlAndNode } from '/@/components/Process/api/definition';
import { findFlowFormVal } from '/@/components/Process/api/todo'; import { findFlowFormVal } from '/@/components/Process/api/todo';
import { flowFormData } from '/@/components/Process/api/process'; import { flowFormData } from '/@/components/Process/api/process';
import BpmnViewer from '/@/components/Process/viewer/index.vue'; import BpmnViewer from '/@/components/Process/viewer/index.vue';
import FlowInnerForm from '/@/views/flowable/task/components/FlowInnerForm.vue'; import FlowInnerForm from '/@/views/flowable/task/components/FlowInnerForm.vue';
...@@ -133,7 +131,6 @@ ...@@ -133,7 +131,6 @@
const refInnerForm = ref(); const refInnerForm = ref();
// 遮罩层 // 遮罩层
const loading = ref(true);
const flowRecordList = ref<FlowRecordItem[]>([]); const flowRecordList = ref<FlowRecordItem[]>([]);
const taskForm = reactive<TaskForm>({ const taskForm = reactive<TaskForm>({
returnTaskShow: false, returnTaskShow: false,
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
</a-card> </a-card>
<ShowFormModal @register="registerShowFormModal" @submit="handleShowFormSubmit" /> <ShowFormModal @register="registerShowFormModal" />
</div> </div>
</template> </template>
...@@ -229,36 +229,55 @@ ...@@ -229,36 +229,55 @@
}; };
const showNodeFormData = (data) => { const showNodeFormData = (data) => {
// 调试:打印传入的数据结构
console.log('showNodeFormData 传入数据:', data);
console.log('showNodeFormData taskDataObj:', taskDataObj.value);
// Build workflowNodes list for the drawer. Adjust component paths as needed. // Build workflowNodes list for the drawer. Adjust component paths as needed.
const nodes = [ const nodes = [
{ id: 'stplanman', name: '主表单', formUrl: '/views/project/plan/components/StPlanManForm.vue' }, { id: 'stplanman', name: '主表单', formUrl: '/project/plan/components/StPlanManForm.vue' },
{ id: 'stplanexcute', name: '执行表单', formUrl: '/views/project/plan/components/StPlanExcuteForm.vue' }, { id: 'stplanexcute', name: '执行表单', formUrl: '/project/plan/components/StPlanExcuteForm.vue' },
]; ];
// pick which node to show — customize the rule as necessary // pick which node to show — customize the rule as necessary
const currentIndex = (data?.taskName || '').includes('执行') ? 1 : 0; const currentIndex = (data?.taskName || '').includes('执行') ? 1 : 0;
// externalFormData: map node id -> form data object // 获取当前节点
const externalFormData = { const currentNode = nodes[currentIndex];
[nodes[currentIndex].id]: data?.data || {},
// 获取业务数据ID:优先级为 id -> dataId -> procInsId
let businessDataId = taskDataObj.value?.id || taskDataObj.value?.dataId || taskDataObj.value?.procInsId;
console.log('获取到的业务数据ID:', businessDataId);
// 准备表单数据
const formData = {
id: businessDataId || '',
// 将taskDataObj中的数据合并到formData中
...taskDataObj.value,
}; };
console.log('准备的表单数据:', formData);
// externalFormData: map node id -> form data object
const externalFormData = {};
// 所有节点都传递相同的formData,包括可编辑节点和只读节点
nodes.forEach((node) => {
externalFormData[node.id] = formData;
});
console.log('传递给ShowFormModal的externalFormData:', externalFormData);
showFormModalApi.openModal(true, { showFormModalApi.openModal(true, {
workflowNodes: nodes, workflowNodes: nodes,
currentNodeIndex: currentIndex, currentNodeIndex: currentIndex,
externalFormData, externalFormData,
title: data?.taskName || '表单', title: data?.taskName || '表单',
showFooter: true, showFooter: false,
}); });
}; };
// Handle submit event emitted from ShowFormModal
const handleShowFormSubmit = (payload) => {
console.log('ShowFormModal submit payload:', payload);
// payload contains: { nodeId, nodeName, formData, procDefId, formComponent }
// Add your handling logic here (e.g., call API, close modal, refresh list)
};
defineExpose({ defineExpose({
iniData, iniData,
}); });
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { BasicForm, useForm } from '/@/components/Form/index'; import { BasicForm, useForm } from '/@/components/Form/index';
import { computed, ref, onMounted, watchEffect, toRaw, watch } from 'vue'; import { computed, ref, onMounted, watchEffect, toRaw, watch, nextTick } from 'vue';
import { defHttp } from '/@/utils/http/axios'; import { defHttp } from '/@/utils/http/axios';
import { getBpmFormSchema } from '../StPlanMan.data'; import { getBpmFormSchema } from '../StPlanMan.data';
import { saveOrUpdate } from '../StPlanMan.api'; import { saveOrUpdate } from '../StPlanMan.api';
...@@ -76,13 +76,26 @@ ...@@ -76,13 +76,26 @@
// watch incoming prop and populate the form when provided // watch incoming prop and populate the form when provided
watch( watch(
() => props.formData, () => props.formData,
(v) => { async (v) => {
if (v && Object.keys(v).length > 0) { if (v && Object.keys(v).length > 0) {
formData.value = { ...v }; formData.value = { ...v };
// 延迟调用setFieldsValue,确保表单已经初始化
// 当选项卡切换时,表单可能还没有完全准备好
await nextTick();
try { try {
setFieldsValue(v); await setFieldsValue(v);
console.log('setFieldsValue 成功:', v);
} catch (e) { } catch (e) {
console.warn('setFieldsValue failed:', e); console.warn('setFieldsValue failed (first attempt):', e);
// 如果第一次失败,延迟后重试
await new Promise((resolve) => setTimeout(resolve, 100));
try {
await setFieldsValue(v);
console.log('setFieldsValue 成功 (retry):', v);
} catch (e2) {
console.warn('setFieldsValue failed (retry):', e2);
}
} }
} }
}, },
...@@ -145,12 +158,25 @@ ...@@ -145,12 +158,25 @@
// 初始化表单数据 // 初始化表单数据
const initFormData = async () => { const initFormData = async () => {
try { try {
// 如果props.formData已经有数据,说明是从流程表单打开,不需要再调用接口
if (props.formData && Object.keys(props.formData).length > 0 && props.formData.id) {
console.log('表单数据已从props传入,跳过queryById接口调用');
return;
}
loading.value = true; loading.value = true;
const timestamp = new Date().getTime(); const timestamp = new Date().getTime();
let tid = toRaw(route.query).id; let tid = toRaw(route.query).id;
// 如果URL中也没有id,则不调用接口
if (!tid) {
console.warn('未找到id参数,既非URL query参数也非props传入');
loading.value = false;
return;
}
const queryByIdUrl = '/plan.main/stPlanMan/queryById'; const queryByIdUrl = '/plan.main/stPlanMan/queryById';
const data = await defHttp.get({ const data = await defHttp.get({
url: queryByIdUrl, url: queryByIdUrl,
...@@ -167,7 +193,10 @@ ...@@ -167,7 +193,10 @@
await setProps({ disabled: formDisabled.value }); await setProps({ disabled: formDisabled.value });
} catch (error) { } catch (error) {
console.error('初始化表单数据失败:', error); console.error('初始化表单数据失败:', error);
createMessage.error('初始化表单数据失败'); // 只有在非预期情况下才提示错误
if (!props.formData?.id) {
createMessage.error('初始化表单数据失败');
}
} finally { } finally {
loading.value = false; loading.value = false;
} }
...@@ -192,7 +221,12 @@ ...@@ -192,7 +221,12 @@
}; };
onMounted(() => { onMounted(() => {
initFormData(); // 如果formData已经通过props传入,则不需要再调用initFormData
if (props.formData && Object.keys(props.formData).length > 0 && props.formData.id) {
console.log('form data已通过props传入,跳过接口调用');
} else {
initFormData();
}
}); });
// expose getFormData so parent modal can read current values // expose getFormData so parent modal can read current values
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论