【代码优化】BPM:OA 请假界面

This commit is contained in:
YunaiV 2025-03-23 07:54:42 +08:00
parent 6197c144b6
commit a186806456

View File

@ -1,8 +1,8 @@
<template>
<ContentWrap :bodyStyle="{ padding: '10px 20px 0' }">
<el-row :gutter="20">
<el-col :span="16"
><el-form
<el-row :gutter="20">
<el-col :span="16">
<ContentWrap title="申请信息">
<el-form
ref="formRef"
v-loading="formLoading"
:model="formData"
@ -41,35 +41,39 @@
<el-input v-model="formData.reason" placeholder="请输入请假原因" type="textarea" />
</el-form-item>
<el-form-item>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button :disabled="formLoading" type="primary" @click="submitForm">
</el-button>
</el-form-item>
</el-form></el-col
>
<!-- 新增 ====== begin ======== -->
<el-col :span="8"
><!-- 流程时间线 -->
</el-form>
</ContentWrap>
</el-col>
<!-- 审批相关流程信息 -->
<el-col :span="8">
<ContentWrap title="审批流程" :bodyStyle="{ padding: '0 20px 0' }">
<ProcessInstanceTimeline
ref="timelineRef"
:activity-nodes="activityNodes"
:show-status-icon="false"
@select-user-confirm="selectUserConfirm"
/>
</el-col>
<!-- 新增 ====== end ======== -->
</el-row>
</ContentWrap>
</ContentWrap>
</el-col>
</el-row>
</template>
<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as LeaveApi from '@/api/bpm/leave'
import { useTagsViewStore } from '@/store/modules/tagsView'
// import
import * as DefinitionApi from '@/api/bpm/definition'
// ====== begin ========
import ProcessInstanceTimeline from '../../processInstance/detail/ProcessInstanceTimeline.vue'
import ProcessInstanceTimeline from '@/views/bpm/processInstance/detail/ProcessInstanceTimeline.vue'
import * as ProcessInstanceApi from '@/api/bpm/processInstance'
import { CandidateStrategy, NodeId } from '@/components/SimpleProcessDesignerV2/src/consts'
import { ApprovalNodeInfo } from '@/api/bpm/processInstance'
// ====== end ========
defineOptions({ name: 'BpmOALeaveCreate' })
const message = useMessage() //
@ -91,22 +95,21 @@ const formRules = reactive({
})
const formRef = ref() // Ref
//
//
const processDefineKey = 'oa_leave' // Key
const startUserSelectTasks = ref([]) //
const startUserSelectAssignees = ref({}) //
// ====== begin ========
const tempStartUserSelectAssignees = ref({}) //
const activityNodes = ref<ProcessInstanceApi.ApprovalNodeInfo[]>([]) //
const processDefinitionId = ref('')
// ====== end ========
/** 提交表单 */
const submitForm = async () => {
//
// 1.1
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
// 1.2
if (startUserSelectTasks.value?.length > 0) {
for (const userTask of startUserSelectTasks.value) {
if (
@ -118,11 +121,11 @@ const submitForm = async () => {
}
}
//
// 2.
formLoading.value = true
try {
const data = { ...formData.value } as unknown as LeaveApi.LeaveVO
//
//
if (startUserSelectTasks.value?.length > 0) {
data.startUserSelectAssignees = startUserSelectAssignees.value
}
@ -136,12 +139,12 @@ const submitForm = async () => {
}
}
// ====== begin ========
/** 获取审批详情 */
/** 审批相关:获取审批详情 */
const getApprovalDetail = async () => {
try {
const data = await ProcessInstanceApi.getApprovalDetail({
processDefinitionId: processDefinitionId.value,
// TODO processDefinitionKey
activityId: NodeId.START_USER_NODE_ID,
processVariablesStr: JSON.stringify({ day: daysDifference() }) // GET String JSON
})
@ -174,21 +177,22 @@ const getApprovalDetail = async () => {
}
}
/** 选择发起人 */
/** 审批相关:选择发起人 */
const selectUserConfirm = (id: string, userList: any[]) => {
startUserSelectAssignees.value[id] = userList?.map((item: any) => item.id)
}
//
// TODO @ formatTime dayjs
const daysDifference = () => {
const oneDay = 24 * 60 * 60 * 1000 //
const diffTime = Math.abs(Number(formData.value.endTime) - Number(formData.value.startTime))
return Math.floor(diffTime / oneDay)
}
// ====== end ========
/** 初始化 */
onMounted(async () => {
// TODO @ getApprovalDetail
const processDefinitionDetail = await DefinitionApi.getProcessDefinition(
undefined,
processDefineKey
@ -200,13 +204,12 @@ onMounted(async () => {
}
processDefinitionId.value = processDefinitionDetail.id
startUserSelectTasks.value = processDefinitionDetail.startUserSelectTasks
// ====== begin ========
// ,
getApprovalDetail()
// ====== end ========
//
await getApprovalDetail()
})
// ====== begin ========
/** 预测流程节点会因为输入的参数值而产生新的预测结果值,所以需重新预测一次, formData.value可改成实际业务中的特定字段 */
/** 审批相关:预测流程节点会因为输入的参数值而产生新的预测结果值,所以需重新预测一次, formData.value可改成实际业务中的特定字段 */
watch(
formData.value,
(newValue, oldValue) => {
@ -224,6 +227,5 @@ watch(
{
immediate: true
}
// ====== end ========
)
</script>