update 优化 增加请求流程后端发起demo案例

dev
疯狂的狮子Li 5 months ago
parent 95cbd2f3af
commit c785a9fb7f

@ -39,6 +39,18 @@ export const addLeave = (data: LeaveForm): AxiosPromise<LeaveVO> => {
}); });
}; };
/**
*
* @param data
*/
export const submitAndFlowStart = (data: LeaveForm): AxiosPromise<LeaveVO> => {
return request({
url: '/workflow/leave/submitAndFlowStart',
method: 'post',
data: data
});
};
/** /**
* *
* @param data * @param data

@ -1,8 +1,8 @@
<template> <template>
<div style="display: flex; justify-content: space-between"> <div style="display: flex; justify-content: space-between">
<div> <div>
<el-button v-if="submitButtonShow" :loading="props.buttonLoading" type="info" @click="submitForm('draft')"></el-button> <el-button v-if="submitButtonShow" :loading="props.buttonLoading" type="info" @click="submitForm('draft', mode)"></el-button>
<el-button v-if="submitButtonShow" :loading="props.buttonLoading" type="primary" @click="submitForm('submit')"> </el-button> <el-button v-if="submitButtonShow" :loading="props.buttonLoading" type="primary" @click="submitForm('submit', mode)"> </el-button>
<el-button v-if="approvalButtonShow" :loading="props.buttonLoading" type="primary" @click="approvalVerifyOpen"></el-button> <el-button v-if="approvalButtonShow" :loading="props.buttonLoading" type="primary" @click="approvalVerifyOpen"></el-button>
<el-button v-if="props.id && props.status !== 'draft'" type="primary" @click="handleApprovalRecord"></el-button> <el-button v-if="props.id && props.status !== 'draft'" type="primary" @click="handleApprovalRecord"></el-button>
<slot /> <slot />
@ -19,12 +19,13 @@ const props = defineProps({
status: propTypes.string.def(''), status: propTypes.string.def(''),
pageType: propTypes.string.def(''), pageType: propTypes.string.def(''),
buttonLoading: propTypes.bool.def(false), buttonLoading: propTypes.bool.def(false),
id: propTypes.string.def('') || propTypes.number.def() id: propTypes.string.def('') || propTypes.number.def(),
mode: propTypes.bool.def(false)
}); });
const emits = defineEmits(['submitForm', 'approvalVerifyOpen', 'handleApprovalRecord']); const emits = defineEmits(['submitForm', 'approvalVerifyOpen', 'handleApprovalRecord']);
// //
const submitForm = async (type) => { const submitForm = async (type, mode) => {
emits('submitForm', type); emits('submitForm', type, mode);
}; };
// //
const approvalVerifyOpen = async () => { const approvalVerifyOpen = async () => {

@ -1,6 +1,7 @@
<template> <template>
<div class="p-2"> <div class="p-2">
<el-card shadow="never"> <el-card shadow="never">
<!-- mode用于直接后端发起流程 默认前端发起 不同接口实现方式可查看具体后端代码 -->
<approvalButton <approvalButton
@submitForm="submitForm" @submitForm="submitForm"
@approvalVerifyOpen="approvalVerifyOpen" @approvalVerifyOpen="approvalVerifyOpen"
@ -9,6 +10,7 @@
:id="form.id" :id="form.id"
:status="form.status" :status="form.status"
:pageType="routeParams.type" :pageType="routeParams.type"
:mode="true"
/> />
</el-card> </el-card>
<el-card shadow="never" style="height: 78vh; overflow-y: auto"> <el-card shadow="never" style="height: 78vh; overflow-y: auto">
@ -51,7 +53,7 @@
</template> </template>
<script setup name="Leave" lang="ts"> <script setup name="Leave" lang="ts">
import { addLeave, getLeave, updateLeave } from '@/api/workflow/leave'; import { addLeave, getLeave, submitAndFlowStart, updateLeave } from '@/api/workflow/leave';
import { LeaveForm, LeaveQuery, LeaveVO } from '@/api/workflow/leave/types'; import { LeaveForm, LeaveQuery, LeaveVO } from '@/api/workflow/leave/types';
import { startWorkFlow } from '@/api/workflow/task'; import { startWorkFlow } from '@/api/workflow/task';
import SubmitVerify from '@/components/Process/submitVerify.vue'; import SubmitVerify from '@/components/Process/submitVerify.vue';
@ -183,7 +185,7 @@ const getInfo = () => {
}; };
/** 提交按钮 */ /** 提交按钮 */
const submitForm = (status: string) => { const submitForm = (status: string, mode: boolean) => {
if (leaveTime.value.length === 0) { if (leaveTime.value.length === 0) {
proxy?.$modal.msgError('请假时间不能为空'); proxy?.$modal.msgError('请假时间不能为空');
return; return;
@ -194,20 +196,30 @@ const submitForm = (status: string) => {
form.value.endDate = leaveTime.value[1]; form.value.endDate = leaveTime.value[1];
if (valid) { if (valid) {
buttonLoading.value = true; buttonLoading.value = true;
let res: AxiosResponse<LeaveVO>; // 稿
if (form.value.id) { if (mode && status != 'draft') {
res = await updateLeave(form.value).finally(() => (buttonLoading.value = false)); let res = await submitAndFlowStart(form.value).finally(() => (buttonLoading.value = false));
} else { form.value = res.data;
res = await addLeave(form.value).finally(() => (buttonLoading.value = false));
}
form.value = res.data;
if (status === 'draft') {
buttonLoading.value = false; buttonLoading.value = false;
proxy?.$modal.msgSuccess('暂存成功'); proxy?.$modal.msgSuccess('操作成功');
proxy.$tab.closePage(proxy.$route); proxy.$tab.closePage(proxy.$route);
proxy.$router.go(-1); proxy.$router.go(-1);
} else { } else{
await handleStartWorkFlow(res.data); let res;
if (form.value.id) {
res = await updateLeave(form.value).finally(() => (buttonLoading.value = false));
} else {
res = await addLeave(form.value).finally(() => (buttonLoading.value = false));
}
form.value = res.data;
if (status === 'draft') {
buttonLoading.value = false;
proxy?.$modal.msgSuccess('暂存成功');
proxy.$tab.closePage(proxy.$route);
proxy.$router.go(-1);
} else {
await handleStartWorkFlow(res.data);
}
} }
} }
}); });

Loading…
Cancel
Save