diff --git a/src/api/workflow/process.ts b/src/api/workflow/process.ts index 2f96a25..a7bcaf1 100644 --- a/src/api/workflow/process.ts +++ b/src/api/workflow/process.ts @@ -74,12 +74,14 @@ export async function postDraft( schemaId: string, formData: Array, dataId?: string, + processId='', + taskId='', mode: ErrorMessageMode = 'modal', ) { return defHttp.post( { url: Api.Draft, - params: { formData, schemaId, dataId }, + params: { formData, schemaId, dataId, processId, taskId }, }, { errorMessageMode: mode, @@ -109,12 +111,14 @@ export async function putDraft( formData: Array, id: string, dataId?: string, + processId='', + taskId='', mode: ErrorMessageMode = 'modal', ) { return defHttp.put( { url: Api.Draft, - params: { formData, schemaId, id, dataId }, + params: { formData, schemaId, id, dataId, processId, taskId }, }, { errorMessageMode: mode, @@ -139,7 +143,7 @@ export async function deleteDraft(ids: string[], mode: ErrorMessageMode = 'modal /** * @description: 获取草稿详情 */ -export async function getDraftInfo(id: string, mode: ErrorMessageMode = 'modal') { +export async function getDraftInfo(id: string, taskId, userId, mode: ErrorMessageMode = 'modal') { return defHttp.get<{ formData: string; name: string; @@ -148,7 +152,7 @@ export async function getDraftInfo(id: string, mode: ErrorMessageMode = 'modal') }>( { url: Api.DraftInfo, - params: { id }, + params: { id, taskId, userId }, }, { errorMessageMode: mode, diff --git a/src/views/secondDev/approveFlowPage.vue b/src/views/secondDev/approveFlowPage.vue index 9b91881..d935f1d 100644 --- a/src/views/secondDev/approveFlowPage.vue +++ b/src/views/secondDev/approveFlowPage.vue @@ -10,6 +10,12 @@ 关闭 + + 暂存 + + + 从草稿导入 + @@ -86,6 +92,9 @@ import { useI18n } from '/@/hooks/web/useI18n'; import { useMessage } from '/@/hooks/web/useMessage'; import { useUserStore } from '/@/store/modules/user'; + import { deleteDraft, postDraft, putDraft, getDraftInfo } from '/@/api/workflow/process'; + import { TaskTypeUrl } from '/@/enums/workflowEnum'; + const spinning = ref(false); const userStore = useUserStore(); @@ -105,6 +114,7 @@ const taskId = ref(rQuery.taskId); const processId = ref(rParams.arg2); const readonly = ref(!!rQuery.readonly); // 查看流程会触发只读模式 + const rDraftsId = ref(rQuery.draftId || '') const renderKey = ref(''); const formConfigs = ref(); const opinionDlg = ref(); @@ -115,7 +125,13 @@ const hasBtnApprove = ref(true); const hasBtnReject = ref(false); const hasBtnFinish = ref(false); + let draftData = {} const drawNode = ref(''); + const props = defineProps({ + rowKeyData: { + type: String + } + }); let approvalData = reactive({ isCountersign: false, @@ -135,7 +151,6 @@ nextTaskUser: {} // 格式为taskKey: 用户id(逗号分隔) }); let approvedType = ref(ApproveType.AGREE); - function onMoreClick(e) { const key = e.key; if (key === 'flowchart') { @@ -194,6 +209,56 @@ function close() { tabStore.closeTab(currentRoute, router); } + async function setDraft(needModal = true) { + let formData = []; + let params = { + taskId: taskId.value, + userId: userStore.getUserInfo.id, + } + let res = await getDraftInfo('', taskId.value, userStore.getUserInfo.id) + if(res) { + draftData = JSON.parse(res.formData) + rDraftsId.value = res.id + if(!needModal) return + Modal.confirm({ + title: () => '提示', + content: () => '确认使用草稿覆盖当前数据?', + onOk: async () => { + data.formInfos.forEach((item) => { + if (draftData && item.formConfig && item.formConfig.key && draftData[item.formConfig.key]) { + formData.push(item.formConfig.key ? draftData[item.formConfig.key] : {}); + } + }); + await formInformation.value.setFormData(formData); + } + }); + } + } + async function saveDraft() { + try { + spinning.value = true; + let formModels = await formInformation.value.saveDraftData(); + if (rDraftsId.value) { + let res = await putDraft(schemaId.value, formModels, rDraftsId.value, props.rowKeyData, processId.value, taskId.value); + showResult(res, '保存草稿'); + } else { + let res = await postDraft(schemaId.value, formModels, props.rowKeyData, processId.value, taskId.value ); + showResult(res, '保存草稿'); + } + setDraft(false) + spinning.value = false; + } catch (error) { + spinning.value = false; + notificationError('保存草稿'); + } + } + function showResult(res, title) { + if (res) { + notificationSuccess(title); + } else { + notificationError(title); + } + } async function onApproveClick(isAutoAgreeBreak = false) { openSpinning(); @@ -360,6 +425,7 @@ } renderKey.value = Math.random() + ''; getBackNode(); + setDraft() } catch (error) {} }); diff --git a/src/views/workflow/task/components/processTasks/DraftsV2.vue b/src/views/workflow/task/components/processTasks/DraftsV2.vue index 47c66f9..e7c8ab0 100644 --- a/src/views/workflow/task/components/processTasks/DraftsV2.vue +++ b/src/views/workflow/task/components/processTasks/DraftsV2.vue @@ -97,18 +97,29 @@ function tableActions(record) { async function handleEdit(record) { try { - let res = await getDraftInfo(record.id); /*processData.draftsId = record.id; processData.schemaId = res.schemaId; processData.draftsJsonStr = res.formData; processData.visible = true;*/ - localStorage.setItem('draftsJsonStr', res.formData); - router.push({ - path: `/flow/${res.schemaId}/${record.id}/createFlow`, - query: { - createType: 'drafts' - } - }); + const { schemaId, processId, taskId, id } = record; + if(taskId){ + router.push({ + path: '/flow/' + schemaId + '/' + (processId || '') + '/approveFlow', + query: { + taskId: taskId, + draftId: id, + } + }); + } else { + let res = await getDraftInfo(record.id); + localStorage.setItem('draftsJsonStr', res.formData); + router.push({ + path: `/flow/${schemaId}/${id}/createFlow`, + query: { + createType: 'drafts' + } + }); + } } catch (error) { } }