2024-12-12 16:07:42 +08:00
|
|
|
|
<script setup lang="ts">
|
2024-12-16 21:01:30 +08:00
|
|
|
|
import type { StartWorkFlowReqData } from '#/api/workflow/task/model';
|
|
|
|
|
|
2024-12-16 16:48:18 +08:00
|
|
|
|
import { computed, onMounted } from 'vue';
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
2024-12-12 16:07:42 +08:00
|
|
|
|
|
2024-12-16 21:01:30 +08:00
|
|
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
|
|
|
|
2024-12-12 16:07:42 +08:00
|
|
|
|
import { Card } from 'ant-design-vue';
|
|
|
|
|
import dayjs from 'dayjs';
|
2024-12-16 21:01:30 +08:00
|
|
|
|
import { cloneDeep, omit } from 'lodash-es';
|
2024-12-12 16:07:42 +08:00
|
|
|
|
|
|
|
|
|
import { useVbenForm } from '#/adapter/form';
|
2024-12-16 21:01:30 +08:00
|
|
|
|
import { startWorkFlow } from '#/api/workflow/task';
|
2024-12-12 16:07:42 +08:00
|
|
|
|
|
2024-12-16 21:01:30 +08:00
|
|
|
|
import { applyModal } from '../components';
|
|
|
|
|
import { leaveAdd, leaveInfo, leaveUpdate } from './api';
|
2024-12-12 16:07:42 +08:00
|
|
|
|
import { modalSchema } from './data';
|
|
|
|
|
|
|
|
|
|
const route = useRoute();
|
2024-12-16 16:48:18 +08:00
|
|
|
|
const readonly = route.query?.readonly === 'true';
|
2024-12-12 16:07:42 +08:00
|
|
|
|
const id = route.query?.id as string;
|
|
|
|
|
|
2024-12-16 16:48:18 +08:00
|
|
|
|
/**
|
|
|
|
|
* id存在&readonly时候
|
|
|
|
|
*/
|
|
|
|
|
const showActionBtn = computed(() => {
|
2024-12-16 21:01:30 +08:00
|
|
|
|
return !readonly;
|
2024-12-16 16:48:18 +08:00
|
|
|
|
});
|
|
|
|
|
|
2024-12-12 16:07:42 +08:00
|
|
|
|
const [BasicForm, formApi] = useVbenForm({
|
|
|
|
|
commonConfig: {
|
|
|
|
|
// 默认占满两列
|
|
|
|
|
formItemClass: 'col-span-2',
|
|
|
|
|
// 默认label宽度 px
|
2024-12-16 21:01:30 +08:00
|
|
|
|
labelWidth: 100,
|
2024-12-12 16:07:42 +08:00
|
|
|
|
// 通用配置项 会影响到所有表单项
|
|
|
|
|
componentProps: {
|
|
|
|
|
class: 'w-full',
|
2024-12-16 16:48:18 +08:00
|
|
|
|
disabled: readonly,
|
2024-12-12 16:07:42 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2024-12-16 21:01:30 +08:00
|
|
|
|
schema: modalSchema(!readonly),
|
2024-12-12 16:07:42 +08:00
|
|
|
|
showDefaultActions: false,
|
|
|
|
|
wrapperClass: 'grid-cols-2',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
// 只读 获取信息赋值
|
2024-12-16 16:48:18 +08:00
|
|
|
|
if (id) {
|
2024-12-12 16:07:42 +08:00
|
|
|
|
const resp = await leaveInfo(id);
|
|
|
|
|
await formApi.setValues(resp);
|
|
|
|
|
const dateRange = [dayjs(resp.startDate), dayjs(resp.endDate)];
|
|
|
|
|
await formApi.setFieldValue('dateRange', dateRange);
|
2024-12-17 09:23:54 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* window.parent(最近的上一级父页面)
|
|
|
|
|
* 主要解决内嵌iframe卡顿的问题
|
|
|
|
|
*/
|
|
|
|
|
if (readonly) {
|
|
|
|
|
window.parent.postMessage('mounted', '*');
|
|
|
|
|
}
|
2024-12-12 16:07:42 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2024-12-16 16:48:18 +08:00
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
2024-12-16 21:01:30 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提取通用逻辑
|
|
|
|
|
*/
|
|
|
|
|
async function handleSaveOrUpdate() {
|
|
|
|
|
const { valid } = await formApi.validate();
|
|
|
|
|
if (!valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let data = cloneDeep(await formApi.getValues()) as any;
|
|
|
|
|
data = omit(data, 'flowType');
|
|
|
|
|
// 处理日期
|
|
|
|
|
data.startDate = dayjs(data.dateRange[0]).format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
data.endDate = dayjs(data.dateRange[1]).format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
if (id) {
|
|
|
|
|
data.id = id;
|
|
|
|
|
return await leaveUpdate(data);
|
|
|
|
|
} else {
|
|
|
|
|
return await leaveAdd(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [ApplyModal, applyModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: applyModal,
|
|
|
|
|
});
|
|
|
|
|
/**
|
|
|
|
|
* 暂存 草稿状态
|
|
|
|
|
*/
|
2024-12-16 16:48:18 +08:00
|
|
|
|
async function handleTempSave() {
|
|
|
|
|
try {
|
2024-12-16 21:01:30 +08:00
|
|
|
|
await handleSaveOrUpdate();
|
2024-12-16 16:48:18 +08:00
|
|
|
|
router.push('/demo/leave');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-16 21:01:30 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存业务 & 发起流程
|
|
|
|
|
*/
|
|
|
|
|
async function handleStartWorkFlow() {
|
|
|
|
|
try {
|
|
|
|
|
// 保存业务
|
|
|
|
|
const leaveResp = await handleSaveOrUpdate();
|
|
|
|
|
// 启动流程
|
|
|
|
|
const taskVariables = {
|
|
|
|
|
leaveDays: leaveResp!.leaveDays,
|
|
|
|
|
userList: ['1', '3', '4'],
|
|
|
|
|
};
|
|
|
|
|
const formValues = await formApi.getValues();
|
|
|
|
|
const flowCode = formValues?.flowType ?? 'leave1';
|
|
|
|
|
const startWorkFlowData: StartWorkFlowReqData = {
|
2024-12-18 09:32:53 +08:00
|
|
|
|
businessId: leaveResp!.id,
|
2024-12-16 21:01:30 +08:00
|
|
|
|
flowCode,
|
|
|
|
|
variables: taskVariables,
|
|
|
|
|
};
|
|
|
|
|
const { taskId } = await startWorkFlow(startWorkFlowData);
|
|
|
|
|
// 打开窗口
|
|
|
|
|
applyModalApi.setData({
|
|
|
|
|
taskId,
|
|
|
|
|
taskVariables,
|
|
|
|
|
variables: {},
|
|
|
|
|
});
|
|
|
|
|
applyModalApi.open();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleComplete() {
|
2024-12-17 19:16:55 +08:00
|
|
|
|
formApi.resetForm();
|
2024-12-16 21:01:30 +08:00
|
|
|
|
router.push('/demo/leave');
|
|
|
|
|
}
|
2024-12-12 16:07:42 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Card>
|
2024-12-16 13:53:58 +08:00
|
|
|
|
<div id="leave-form">
|
|
|
|
|
<BasicForm />
|
2024-12-16 16:48:18 +08:00
|
|
|
|
<div v-if="showActionBtn" class="flex justify-end gap-2">
|
|
|
|
|
<a-button @click="handleTempSave">暂存</a-button>
|
2024-12-16 21:01:30 +08:00
|
|
|
|
<a-button type="primary" @click="handleStartWorkFlow">提交</a-button>
|
2024-12-16 16:48:18 +08:00
|
|
|
|
</div>
|
2024-12-16 21:01:30 +08:00
|
|
|
|
<ApplyModal @complete="handleComplete" />
|
2024-12-16 13:53:58 +08:00
|
|
|
|
</div>
|
2024-12-12 16:07:42 +08:00
|
|
|
|
</Card>
|
|
|
|
|
</template>
|
2024-12-16 13:53:58 +08:00
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
/**
|
|
|
|
|
去除 '菜单加载中' 主要是iframe内嵌使用
|
|
|
|
|
*/
|
|
|
|
|
html:has(#leave-form) {
|
|
|
|
|
.ant-message-notice-content:has(.ant-message-loading) {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|