提交
This commit is contained in:
1 parent
f9676f8759
commit
725774ef0c
155 files changed
+50675
-5242
No files matched your search
@@ -0,0 +1,419 @@
|
||||
<!-- 工作流配置(备用金) -->
|
||||
<!-- eslint-disable vue/no-v-model-argument -->
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<section class="panel">
|
||||
<div class="panel-top">
|
||||
<h2 class="title-bar-heading">审批流程节点</h2>
|
||||
</div>
|
||||
|
||||
<div class="wf-info-bar">
|
||||
<span><b>流程名称:</b>{{ wfDef.wfName || '-' }}</span>
|
||||
<span>
|
||||
<b>状态:</b>
|
||||
<el-tag :type="statusTagType(wfDef.status)" size="small">
|
||||
{{ statusLabel(wfDef.status) }}
|
||||
</el-tag>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="list-toolbar">
|
||||
<div class="list-toolbar-row">
|
||||
<div class="list-toolbar-selected">
|
||||
已选 <span class="sel-num">0</span> 项
|
||||
</div>
|
||||
<el-button class="btn-main" type="primary" @click="openAddDialog">
|
||||
<el-icon><Plus /></el-icon>新增节点
|
||||
</el-button>
|
||||
<el-button class="btn-ghost" :loading="loadingMap.save" @click="saveNodes">
|
||||
<el-icon><Upload /></el-icon>保存配置
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list-body list-wrap">
|
||||
<el-table class="list-table" :data="nodes" v-loading="loading" stripe>
|
||||
<el-table-column type="index" label="序号" min-width="68" align="center" header-align="center" />
|
||||
<el-table-column
|
||||
prop="nodeName"
|
||||
label="节点名称"
|
||||
min-width="180"
|
||||
align="center"
|
||||
header-align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column prop="nodeOrder" label="节点顺序" min-width="100" align="center" header-align="center" />
|
||||
<el-table-column
|
||||
prop="approverName"
|
||||
label="审批人"
|
||||
min-width="120"
|
||||
align="center"
|
||||
header-align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column label="配置状态" min-width="110" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="(row.approverId ?? row.approver_id) ? 'success' : 'warning'" size="small">
|
||||
{{ (row.approverId ?? row.approver_id) ? '已配置' : '未配置' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" min-width="360" fixed="right" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<div style="display: flex; justify-content: center; gap: 8px; flex-wrap: nowrap">
|
||||
<el-button class="btn-op-item" @click="openEditDialog(row)">
|
||||
<el-icon><EditPen /></el-icon>编辑
|
||||
</el-button>
|
||||
<el-button class="btn-op-item" :loading="loadingMap.rowDelete" @click="deleteNode(row)">
|
||||
<el-icon><Delete /></el-icon>删除
|
||||
</el-button>
|
||||
<el-button class="btn-op-item" @click="moveUp(row)">
|
||||
<el-icon><ArrowUp /></el-icon>上移
|
||||
</el-button>
|
||||
<el-button class="btn-op-item" @click="moveDown(row)">
|
||||
<el-icon><ArrowDown /></el-icon>下移
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<el-dialog
|
||||
v-model="dialogs.addNode"
|
||||
title="新增节点"
|
||||
width="560px"
|
||||
class="dialog-form-layout"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form
|
||||
ref="addFormRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-position="top"
|
||||
scroll-to-error
|
||||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||||
>
|
||||
<div class="form-grid-2">
|
||||
<el-form-item label="节点名称" prop="nodeName">
|
||||
<el-input v-model="formData.nodeName" placeholder="请输入节点名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="节点顺序">
|
||||
<el-input-number v-model="formData.nodeOrder" controls-position="right" :min="1" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="审批人" style="grid-column: 1 / -1">
|
||||
<el-select
|
||||
v-model="formData.approverId"
|
||||
placeholder="请选择审批人"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="handleApproverChange"
|
||||
>
|
||||
<el-option v-for="u in userOptions" :key="u.id" :label="u.displayName" :value="u.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="dialogs.addNode = false">
|
||||
<el-icon><Close /></el-icon>取消
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" :loading="loadingMap.addNodeSubmit" @click="submitAddNode">
|
||||
<el-icon><Check /></el-icon>确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
v-model="dialogs.editNode"
|
||||
title="编辑节点"
|
||||
width="560px"
|
||||
class="dialog-form-layout"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form
|
||||
ref="editFormRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-position="top"
|
||||
scroll-to-error
|
||||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||||
>
|
||||
<div class="form-grid-2">
|
||||
<el-form-item label="节点名称" prop="nodeName">
|
||||
<el-input v-model="formData.nodeName" placeholder="请输入节点名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="节点顺序">
|
||||
<el-input-number v-model="formData.nodeOrder" controls-position="right" :min="1" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="审批人" style="grid-column: 1 / -1">
|
||||
<el-select
|
||||
v-model="formData.approverId"
|
||||
placeholder="请选择审批人"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="handleApproverChange"
|
||||
>
|
||||
<el-option v-for="u in userOptions" :key="u.id" :label="u.displayName" :value="u.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="dialogs.editNode = false">
|
||||
<el-icon><Close /></el-icon>取消
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" :loading="loadingMap.editNodeSubmit" @click="submitEditNode">
|
||||
<el-icon><Check /></el-icon>确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, computed, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import {
|
||||
Plus,
|
||||
EditPen,
|
||||
Delete,
|
||||
Close,
|
||||
Check,
|
||||
Upload,
|
||||
ArrowUp,
|
||||
ArrowDown
|
||||
} from '@element-plus/icons-vue'
|
||||
import { workflowApi } from '@/api/bx'
|
||||
import { fetchUserOptions } from '@/api/admin'
|
||||
import { statusLabel, statusTagType } from '@/utils/bx/format'
|
||||
|
||||
type DialogKey = 'addNode' | 'editNode'
|
||||
|
||||
const loadingMap = reactive<Record<string, boolean>>({})
|
||||
const dialogs = reactive<Record<DialogKey, boolean>>({
|
||||
addNode: false,
|
||||
editNode: false
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
const wfDef = ref<Record<string, any>>({})
|
||||
const nodes = computed(() => wfDef.value.nodes || [])
|
||||
const userOptions = ref<
|
||||
{ id: string; realName: string; username: string; roles: string; displayName: string }[]
|
||||
>([])
|
||||
|
||||
const formData = reactive({
|
||||
nodeName: '',
|
||||
nodeOrder: 1,
|
||||
approverId: null as string | null,
|
||||
approverName: ''
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
nodeName: [{ required: true, message: '节点名称不能为空', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const addFormRef = ref<FormInstance>()
|
||||
const editFormRef = ref<FormInstance>()
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const res = await fetchUserOptions()
|
||||
const data: any = (res as any)?.data ?? res ?? []
|
||||
userOptions.value = (Array.isArray(data) ? data : []).map((u: any) => {
|
||||
const name = u.label || u.nickName || ''
|
||||
const account = u.userNo || ''
|
||||
return {
|
||||
id: String(u.value ?? u.id ?? ''),
|
||||
realName: name,
|
||||
username: account,
|
||||
roles: '',
|
||||
displayName: account ? `${name}(${account})` : name
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
userOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function loadWfDef() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await workflowApi.getByBizType('advance')
|
||||
wfDef.value = res.data ?? {}
|
||||
} catch {
|
||||
wfDef.value = {}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadWfDef()
|
||||
loadUsers()
|
||||
})
|
||||
|
||||
function buildNodePayload(list: Record<string, any>[]) {
|
||||
return list.map((n, i) => ({
|
||||
nodeName: n.nodeName,
|
||||
nodeOrder: i + 1,
|
||||
approverId: n.approverId ?? n.approver_id ?? null,
|
||||
approverName: n.approverName ?? n.approver_name ?? ''
|
||||
}))
|
||||
}
|
||||
|
||||
async function saveNodes() {
|
||||
loadingMap.save = true
|
||||
try {
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(nodes.value))
|
||||
ElMessage.success('保存成功')
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '保存失败')
|
||||
} finally {
|
||||
loadingMap.save = false
|
||||
}
|
||||
}
|
||||
|
||||
function openAddDialog() {
|
||||
Object.assign(formData, {
|
||||
nodeName: '',
|
||||
nodeOrder: nodes.value.length + 1,
|
||||
approverId: null,
|
||||
approverName: ''
|
||||
})
|
||||
dialogs.addNode = true
|
||||
}
|
||||
|
||||
function openEditDialog(node: Record<string, any>) {
|
||||
Object.assign(formData, {
|
||||
nodeName: node.nodeName,
|
||||
nodeOrder: node.nodeOrder,
|
||||
approverId: node.approverId ?? node.approver_id ?? null,
|
||||
approverName: node.approverName ?? node.approver_name ?? ''
|
||||
})
|
||||
dialogs.editNode = true
|
||||
}
|
||||
|
||||
function handleApproverChange(userId: string | null) {
|
||||
if (userId == null) {
|
||||
formData.approverName = ''
|
||||
return
|
||||
}
|
||||
const found = userOptions.value.find((u) => u.id === userId)
|
||||
formData.approverName = found ? found.realName : ''
|
||||
}
|
||||
|
||||
async function submitAddNode() {
|
||||
const valid = await addFormRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
loadingMap.addNodeSubmit = true
|
||||
try {
|
||||
const newNodes = [
|
||||
...nodes.value,
|
||||
{
|
||||
nodeName: formData.nodeName,
|
||||
nodeOrder: formData.nodeOrder,
|
||||
approverId: formData.approverId,
|
||||
approverName: formData.approverName
|
||||
}
|
||||
]
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(newNodes))
|
||||
ElMessage.success('新增成功')
|
||||
dialogs.addNode = false
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '新增失败')
|
||||
} finally {
|
||||
loadingMap.addNodeSubmit = false
|
||||
}
|
||||
}
|
||||
|
||||
async function submitEditNode() {
|
||||
const valid = await editFormRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
loadingMap.editNodeSubmit = true
|
||||
try {
|
||||
const newNodes = nodes.value.map((n: Record<string, any>) =>
|
||||
n.nodeOrder === formData.nodeOrder
|
||||
? {
|
||||
...n,
|
||||
nodeName: formData.nodeName,
|
||||
approverId: formData.approverId,
|
||||
approverName: formData.approverName
|
||||
}
|
||||
: n
|
||||
)
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(newNodes))
|
||||
ElMessage.success('编辑成功')
|
||||
dialogs.editNode = false
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '编辑失败')
|
||||
} finally {
|
||||
loadingMap.editNodeSubmit = false
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteNode(node: Record<string, any>) {
|
||||
await ElMessageBox.confirm(`确定要删除节点「${node.nodeName}」吗?`, '删除确认', {
|
||||
confirmButtonText: '确定删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
loadingMap.rowDelete = true
|
||||
try {
|
||||
const newNodes = nodes.value.filter((n: Record<string, any>) => n.id !== node.id)
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(newNodes))
|
||||
ElMessage.success('删除成功')
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
if (e !== 'cancel') ElMessage.error(e.message || '删除失败')
|
||||
} finally {
|
||||
loadingMap.rowDelete = false
|
||||
}
|
||||
}
|
||||
|
||||
async function moveUp(node: Record<string, any>) {
|
||||
const idx = nodes.value.findIndex((n: Record<string, any>) => n.id === node.id)
|
||||
if (idx <= 0) return
|
||||
const arr = [...nodes.value]
|
||||
const temp = arr[idx]
|
||||
arr[idx] = arr[idx - 1]
|
||||
arr[idx - 1] = temp
|
||||
arr.forEach((n: Record<string, any>, i: number) => (n.nodeOrder = i + 1))
|
||||
try {
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(arr))
|
||||
ElMessage.success('上移成功')
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '上移失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function moveDown(node: Record<string, any>) {
|
||||
const arr = [...nodes.value]
|
||||
const idx = arr.findIndex((n: Record<string, any>) => n.id === node.id)
|
||||
if (idx < 0 || idx >= arr.length - 1) return
|
||||
const temp = arr[idx]
|
||||
arr[idx] = arr[idx + 1]
|
||||
arr[idx + 1] = temp
|
||||
arr.forEach((n: Record<string, any>, i: number) => (n.nodeOrder = i + 1))
|
||||
try {
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(arr))
|
||||
ElMessage.success('下移成功')
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '下移失败')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,419 @@
|
||||
<!-- 工作流配置(报销单) -->
|
||||
<!-- eslint-disable vue/no-v-model-argument -->
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<section class="panel">
|
||||
<div class="panel-top">
|
||||
<h2 class="title-bar-heading">审批流程节点</h2>
|
||||
</div>
|
||||
|
||||
<div class="wf-info-bar">
|
||||
<span><b>流程名称:</b>{{ wfDef.wfName || '-' }}</span>
|
||||
<span>
|
||||
<b>状态:</b>
|
||||
<el-tag :type="statusTagType(wfDef.status)" size="small">
|
||||
{{ statusLabel(wfDef.status) }}
|
||||
</el-tag>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="list-toolbar">
|
||||
<div class="list-toolbar-row">
|
||||
<div class="list-toolbar-selected">
|
||||
已选 <span class="sel-num">0</span> 项
|
||||
</div>
|
||||
<el-button class="btn-main" type="primary" @click="openAddDialog">
|
||||
<el-icon><Plus /></el-icon>新增节点
|
||||
</el-button>
|
||||
<el-button class="btn-ghost" :loading="loadingMap.save" @click="saveNodes">
|
||||
<el-icon><Upload /></el-icon>保存配置
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list-body list-wrap">
|
||||
<el-table class="list-table" :data="nodes" v-loading="loading" stripe>
|
||||
<el-table-column type="index" label="序号" min-width="68" align="center" header-align="center" />
|
||||
<el-table-column
|
||||
prop="nodeName"
|
||||
label="节点名称"
|
||||
min-width="180"
|
||||
align="center"
|
||||
header-align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column prop="nodeOrder" label="节点顺序" min-width="100" align="center" header-align="center" />
|
||||
<el-table-column
|
||||
prop="approverName"
|
||||
label="审批人"
|
||||
min-width="120"
|
||||
align="center"
|
||||
header-align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column label="配置状态" min-width="110" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="(row.approverId ?? row.approver_id) ? 'success' : 'warning'" size="small">
|
||||
{{ (row.approverId ?? row.approver_id) ? '已配置' : '未配置' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" min-width="360" fixed="right" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<div style="display: flex; justify-content: center; gap: 8px; flex-wrap: nowrap">
|
||||
<el-button class="btn-op-item" @click="openEditDialog(row)">
|
||||
<el-icon><EditPen /></el-icon>编辑
|
||||
</el-button>
|
||||
<el-button class="btn-op-item" :loading="loadingMap.rowDelete" @click="deleteNode(row)">
|
||||
<el-icon><Delete /></el-icon>删除
|
||||
</el-button>
|
||||
<el-button class="btn-op-item" @click="moveUp(row)">
|
||||
<el-icon><ArrowUp /></el-icon>上移
|
||||
</el-button>
|
||||
<el-button class="btn-op-item" @click="moveDown(row)">
|
||||
<el-icon><ArrowDown /></el-icon>下移
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<el-dialog
|
||||
v-model="dialogs.addNode"
|
||||
title="新增节点"
|
||||
width="560px"
|
||||
class="dialog-form-layout"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form
|
||||
ref="addFormRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-position="top"
|
||||
scroll-to-error
|
||||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||||
>
|
||||
<div class="form-grid-2">
|
||||
<el-form-item label="节点名称" prop="nodeName">
|
||||
<el-input v-model="formData.nodeName" placeholder="请输入节点名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="节点顺序">
|
||||
<el-input-number v-model="formData.nodeOrder" controls-position="right" :min="1" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="审批人" style="grid-column: 1 / -1">
|
||||
<el-select
|
||||
v-model="formData.approverId"
|
||||
placeholder="请选择审批人"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="handleApproverChange"
|
||||
>
|
||||
<el-option v-for="u in userOptions" :key="u.id" :label="u.displayName" :value="u.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="dialogs.addNode = false">
|
||||
<el-icon><Close /></el-icon>取消
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" :loading="loadingMap.addNodeSubmit" @click="submitAddNode">
|
||||
<el-icon><Check /></el-icon>确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
v-model="dialogs.editNode"
|
||||
title="编辑节点"
|
||||
width="560px"
|
||||
class="dialog-form-layout"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form
|
||||
ref="editFormRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-position="top"
|
||||
scroll-to-error
|
||||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||||
>
|
||||
<div class="form-grid-2">
|
||||
<el-form-item label="节点名称" prop="nodeName">
|
||||
<el-input v-model="formData.nodeName" placeholder="请输入节点名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="节点顺序">
|
||||
<el-input-number v-model="formData.nodeOrder" controls-position="right" :min="1" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="审批人" style="grid-column: 1 / -1">
|
||||
<el-select
|
||||
v-model="formData.approverId"
|
||||
placeholder="请选择审批人"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="handleApproverChange"
|
||||
>
|
||||
<el-option v-for="u in userOptions" :key="u.id" :label="u.displayName" :value="u.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="dialogs.editNode = false">
|
||||
<el-icon><Close /></el-icon>取消
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" :loading="loadingMap.editNodeSubmit" @click="submitEditNode">
|
||||
<el-icon><Check /></el-icon>确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, computed, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import {
|
||||
Plus,
|
||||
EditPen,
|
||||
Delete,
|
||||
Close,
|
||||
Check,
|
||||
Upload,
|
||||
ArrowUp,
|
||||
ArrowDown
|
||||
} from '@element-plus/icons-vue'
|
||||
import { workflowApi } from '@/api/bx'
|
||||
import { fetchUserOptions } from '@/api/admin'
|
||||
import { statusLabel, statusTagType } from '@/utils/bx/format'
|
||||
|
||||
type DialogKey = 'addNode' | 'editNode'
|
||||
|
||||
const loadingMap = reactive<Record<string, boolean>>({})
|
||||
const dialogs = reactive<Record<DialogKey, boolean>>({
|
||||
addNode: false,
|
||||
editNode: false
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
const wfDef = ref<Record<string, any>>({})
|
||||
const nodes = computed(() => wfDef.value.nodes || [])
|
||||
const userOptions = ref<
|
||||
{ id: string; realName: string; username: string; roles: string; displayName: string }[]
|
||||
>([])
|
||||
|
||||
const formData = reactive({
|
||||
nodeName: '',
|
||||
nodeOrder: 1,
|
||||
approverId: null as string | null,
|
||||
approverName: ''
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
nodeName: [{ required: true, message: '节点名称不能为空', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const addFormRef = ref<FormInstance>()
|
||||
const editFormRef = ref<FormInstance>()
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const res = await fetchUserOptions()
|
||||
const data: any = (res as any)?.data ?? res ?? []
|
||||
userOptions.value = (Array.isArray(data) ? data : []).map((u: any) => {
|
||||
const name = u.label || u.nickName || ''
|
||||
const account = u.userNo || ''
|
||||
return {
|
||||
id: String(u.value ?? u.id ?? ''),
|
||||
realName: name,
|
||||
username: account,
|
||||
roles: '',
|
||||
displayName: account ? `${name}(${account})` : name
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
userOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function loadWfDef() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await workflowApi.getByBizType('reimburse')
|
||||
wfDef.value = res.data ?? {}
|
||||
} catch {
|
||||
wfDef.value = {}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadWfDef()
|
||||
loadUsers()
|
||||
})
|
||||
|
||||
function buildNodePayload(list: Record<string, any>[]) {
|
||||
return list.map((n, i) => ({
|
||||
nodeName: n.nodeName,
|
||||
nodeOrder: i + 1,
|
||||
approverId: n.approverId ?? n.approver_id ?? null,
|
||||
approverName: n.approverName ?? n.approver_name ?? ''
|
||||
}))
|
||||
}
|
||||
|
||||
async function saveNodes() {
|
||||
loadingMap.save = true
|
||||
try {
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(nodes.value))
|
||||
ElMessage.success('保存成功')
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '保存失败')
|
||||
} finally {
|
||||
loadingMap.save = false
|
||||
}
|
||||
}
|
||||
|
||||
function openAddDialog() {
|
||||
Object.assign(formData, {
|
||||
nodeName: '',
|
||||
nodeOrder: nodes.value.length + 1,
|
||||
approverId: null,
|
||||
approverName: ''
|
||||
})
|
||||
dialogs.addNode = true
|
||||
}
|
||||
|
||||
function openEditDialog(node: Record<string, any>) {
|
||||
Object.assign(formData, {
|
||||
nodeName: node.nodeName,
|
||||
nodeOrder: node.nodeOrder,
|
||||
approverId: node.approverId ?? node.approver_id ?? null,
|
||||
approverName: node.approverName ?? node.approver_name ?? ''
|
||||
})
|
||||
dialogs.editNode = true
|
||||
}
|
||||
|
||||
function handleApproverChange(userId: string | null) {
|
||||
if (userId == null) {
|
||||
formData.approverName = ''
|
||||
return
|
||||
}
|
||||
const found = userOptions.value.find((u) => u.id === userId)
|
||||
formData.approverName = found ? found.realName : ''
|
||||
}
|
||||
|
||||
async function submitAddNode() {
|
||||
const valid = await addFormRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
loadingMap.addNodeSubmit = true
|
||||
try {
|
||||
const newNodes = [
|
||||
...nodes.value,
|
||||
{
|
||||
nodeName: formData.nodeName,
|
||||
nodeOrder: formData.nodeOrder,
|
||||
approverId: formData.approverId,
|
||||
approverName: formData.approverName
|
||||
}
|
||||
]
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(newNodes))
|
||||
ElMessage.success('新增成功')
|
||||
dialogs.addNode = false
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '新增失败')
|
||||
} finally {
|
||||
loadingMap.addNodeSubmit = false
|
||||
}
|
||||
}
|
||||
|
||||
async function submitEditNode() {
|
||||
const valid = await editFormRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
loadingMap.editNodeSubmit = true
|
||||
try {
|
||||
const newNodes = nodes.value.map((n: Record<string, any>) =>
|
||||
n.nodeOrder === formData.nodeOrder
|
||||
? {
|
||||
...n,
|
||||
nodeName: formData.nodeName,
|
||||
approverId: formData.approverId,
|
||||
approverName: formData.approverName
|
||||
}
|
||||
: n
|
||||
)
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(newNodes))
|
||||
ElMessage.success('编辑成功')
|
||||
dialogs.editNode = false
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '编辑失败')
|
||||
} finally {
|
||||
loadingMap.editNodeSubmit = false
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteNode(node: Record<string, any>) {
|
||||
await ElMessageBox.confirm(`确定要删除节点「${node.nodeName}」吗?`, '删除确认', {
|
||||
confirmButtonText: '确定删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
loadingMap.rowDelete = true
|
||||
try {
|
||||
const newNodes = nodes.value.filter((n: Record<string, any>) => n.id !== node.id)
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(newNodes))
|
||||
ElMessage.success('删除成功')
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
if (e !== 'cancel') ElMessage.error(e.message || '删除失败')
|
||||
} finally {
|
||||
loadingMap.rowDelete = false
|
||||
}
|
||||
}
|
||||
|
||||
async function moveUp(node: Record<string, any>) {
|
||||
const idx = nodes.value.findIndex((n: Record<string, any>) => n.id === node.id)
|
||||
if (idx <= 0) return
|
||||
const arr = [...nodes.value]
|
||||
const temp = arr[idx]
|
||||
arr[idx] = arr[idx - 1]
|
||||
arr[idx - 1] = temp
|
||||
arr.forEach((n: Record<string, any>, i: number) => (n.nodeOrder = i + 1))
|
||||
try {
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(arr))
|
||||
ElMessage.success('上移成功')
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '上移失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function moveDown(node: Record<string, any>) {
|
||||
const arr = [...nodes.value]
|
||||
const idx = arr.findIndex((n: Record<string, any>) => n.id === node.id)
|
||||
if (idx < 0 || idx >= arr.length - 1) return
|
||||
const temp = arr[idx]
|
||||
arr[idx] = arr[idx + 1]
|
||||
arr[idx + 1] = temp
|
||||
arr.forEach((n: Record<string, any>, i: number) => (n.nodeOrder = i + 1))
|
||||
try {
|
||||
await workflowApi.saveNodes(wfDef.value.id, buildNodePayload(arr))
|
||||
ElMessage.success('下移成功')
|
||||
await loadWfDef()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '下移失败')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user