mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2025-12-30 09:42:25 +00:00
feat: 修改流程变量
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type { TaskInfo } from '../task/model';
|
import type { TaskInfo } from '../task/model';
|
||||||
import type { FlowInfoResponse } from './model';
|
import type { FlowInfoResponse, FlowInstanceVariableResp } from './model';
|
||||||
|
|
||||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||||
|
|
||||||
@@ -104,8 +104,8 @@ export function flowInfo(businessId: string) {
|
|||||||
* @returns Map<string,any>
|
* @returns Map<string,any>
|
||||||
*/
|
*/
|
||||||
export function instanceVariable(instanceId: string) {
|
export function instanceVariable(instanceId: string) {
|
||||||
return requestClient.get<Record<string, any>>(
|
return requestClient.get<FlowInstanceVariableResp>(
|
||||||
`/workflow/instance/variable/${instanceId}`,
|
`/workflow/instance/instanceVariable/${instanceId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,3 +118,22 @@ export function workflowInstanceInvalid(data: {
|
|||||||
}) {
|
}) {
|
||||||
return requestClient.postWithMsg<void>('/workflow/instance/invalid', data);
|
return requestClient.postWithMsg<void>('/workflow/instance/invalid', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改流程参数
|
||||||
|
* @param data 参数
|
||||||
|
* @param data.instanceId 实例ID
|
||||||
|
* @param data.key 参数key
|
||||||
|
* @param data.value 值
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
|
export function updateFlowVariable(data: {
|
||||||
|
instanceId: string;
|
||||||
|
key: string;
|
||||||
|
value: any;
|
||||||
|
}) {
|
||||||
|
return requestClient.putWithMsg<void>(
|
||||||
|
'/workflow/instance/updateVariable',
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
export {};
|
||||||
|
|
||||||
export interface Flow {
|
export interface Flow {
|
||||||
id: string;
|
id: string;
|
||||||
createTime: string;
|
createTime: string;
|
||||||
@@ -39,3 +41,14 @@ export interface FlowInfoResponse {
|
|||||||
instanceId: string;
|
instanceId: string;
|
||||||
list: Flow[];
|
list: Flow[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FlowInstanceVariableResp {
|
||||||
|
/**
|
||||||
|
* json字符串 流程变量
|
||||||
|
*/
|
||||||
|
variable: string;
|
||||||
|
variableList: {
|
||||||
|
key: string;
|
||||||
|
value: any;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|||||||
@@ -150,9 +150,10 @@ const [InstanceVariableModal, instanceVariableModalApi] = useVbenModal({
|
|||||||
connectedComponent: instanceVariableModal,
|
connectedComponent: instanceVariableModal,
|
||||||
});
|
});
|
||||||
function handleVariable(row: Recordable<any>) {
|
function handleVariable(row: Recordable<any>) {
|
||||||
instanceVariableModalApi.setData({ record: row.variable });
|
instanceVariableModalApi.setData({ instanceId: row.id });
|
||||||
instanceVariableModalApi.open();
|
instanceVariableModalApi.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
const [FlowInfoModal, flowInfoModalApi] = useVbenModal({
|
const [FlowInfoModal, flowInfoModalApi] = useVbenModal({
|
||||||
connectedComponent: flowInfoModal,
|
connectedComponent: flowInfoModal,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,28 +1,214 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="tsx">
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { JsonPreview, useVbenModal } from '@vben/common-ui';
|
import { JsonPreview, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { cn, getPopupContainer } from '@vben/utils';
|
||||||
|
|
||||||
|
import { message, Modal, Tag } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import { instanceVariable, updateFlowVariable } from '#/api/workflow/instance';
|
||||||
|
|
||||||
|
interface ModalData {
|
||||||
|
/**
|
||||||
|
* 变量 json字符串
|
||||||
|
*/
|
||||||
|
record: string;
|
||||||
|
instanceId: string;
|
||||||
|
}
|
||||||
|
|
||||||
const data = ref({});
|
const data = ref({});
|
||||||
const [BasicModal, modalApi] = useVbenModal({
|
const [BasicModal, modalApi] = useVbenModal({
|
||||||
title: '流程变量',
|
title: '流程变量',
|
||||||
fullscreenButton: false,
|
fullscreenButton: false,
|
||||||
footer: false,
|
footer: false,
|
||||||
onOpenChange: (visible) => {
|
onOpenChange: async (visible) => {
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
data.value = {};
|
data.value = {};
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const recordString = modalApi.getData().record;
|
modalApi.modalLoading(true);
|
||||||
data.value = JSON.parse(recordString);
|
|
||||||
|
await loadData();
|
||||||
|
|
||||||
|
modalApi.modalLoading(false);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const fieldTypeColors = {
|
||||||
|
string: 'cyan',
|
||||||
|
number: 'blue',
|
||||||
|
boolean: 'orange',
|
||||||
|
object: 'purple',
|
||||||
|
};
|
||||||
|
function getFieldTypeColor(fieldType: string) {
|
||||||
|
return (
|
||||||
|
fieldTypeColors[fieldType as keyof typeof fieldTypeColors] ?? 'default'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadData() {
|
||||||
|
const { instanceId } = modalApi.getData() as ModalData;
|
||||||
|
const resp = await instanceVariable(instanceId);
|
||||||
|
const jsonObj = JSON.parse(resp.variable);
|
||||||
|
data.value = jsonObj;
|
||||||
|
|
||||||
|
// 表单
|
||||||
|
const objEntry = Object.entries(jsonObj);
|
||||||
|
|
||||||
|
interface OptionsType {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
fieldType: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
formApi.updateSchema([
|
||||||
|
{
|
||||||
|
fieldName: 'key',
|
||||||
|
componentProps: {
|
||||||
|
options: objEntry.map(
|
||||||
|
([key, value]) =>
|
||||||
|
({
|
||||||
|
label: key,
|
||||||
|
value: key,
|
||||||
|
fieldType: typeof value,
|
||||||
|
}) as OptionsType,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
renderComponentContent: () => ({
|
||||||
|
option: (option: OptionsType) => (
|
||||||
|
<div>
|
||||||
|
{option.label}
|
||||||
|
<Tag class="ml-1" color={getFieldTypeColor(option.fieldType)}>
|
||||||
|
{option.fieldType}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
labelWidth: 80,
|
||||||
|
},
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
fieldName: 'key',
|
||||||
|
component: 'Select',
|
||||||
|
label: '变量名称',
|
||||||
|
rules: 'selectRequired',
|
||||||
|
componentProps: {
|
||||||
|
getPopupContainer,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'valueType',
|
||||||
|
component: 'Select',
|
||||||
|
label: '变量类型',
|
||||||
|
rules: 'selectRequired',
|
||||||
|
componentProps: {
|
||||||
|
getPopupContainer,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'string',
|
||||||
|
value: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'boolean | number | object (使用JSON.parse)',
|
||||||
|
value: 'object',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'value',
|
||||||
|
component: 'Input',
|
||||||
|
label: '变量值',
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
resetButtonOptions: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
submitButtonOptions: {
|
||||||
|
content: '修改',
|
||||||
|
},
|
||||||
|
handleSubmit: async (values) => {
|
||||||
|
console.log(values);
|
||||||
|
Modal.confirm({
|
||||||
|
title: '修改流程变量',
|
||||||
|
content: '确认修改流程变量吗?',
|
||||||
|
centered: true,
|
||||||
|
okButtonProps: {
|
||||||
|
danger: true,
|
||||||
|
},
|
||||||
|
onOk: async () => {
|
||||||
|
await handleSubmit(values);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleSubmit(values: any) {
|
||||||
|
try {
|
||||||
|
modalApi.lock(true);
|
||||||
|
|
||||||
|
const { instanceId } = modalApi.getData() as ModalData;
|
||||||
|
|
||||||
|
let transformValue = values.value;
|
||||||
|
if (values.valueType !== 'string') {
|
||||||
|
try {
|
||||||
|
transformValue = JSON.parse(values.value);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
if (error instanceof Error) {
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改
|
||||||
|
const requestData = {
|
||||||
|
instanceId,
|
||||||
|
key: values.key,
|
||||||
|
value: transformValue,
|
||||||
|
};
|
||||||
|
await updateFlowVariable(requestData);
|
||||||
|
await formApi.resetForm();
|
||||||
|
|
||||||
|
// 查询修改后的
|
||||||
|
const resp = await instanceVariable(instanceId);
|
||||||
|
const jsonObj = JSON.parse(resp.variable);
|
||||||
|
data.value = jsonObj;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
modalApi.lock(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<BasicModal>
|
<BasicModal>
|
||||||
<div class="min-h-[400px] overflow-y-auto">
|
<div
|
||||||
|
:class="cn('min-h-[400px] overflow-y-auto border', 'rounded-[4px] p-2')"
|
||||||
|
>
|
||||||
<JsonPreview :data="data" />
|
<JsonPreview :data="data" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-2 break-all text-sm font-medium text-orange-500">
|
||||||
|
需要支持变量类型需要更改后端代码(原版只支持string类型)
|
||||||
|
<div>
|
||||||
|
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/bo/FlowVariableBo.java
|
||||||
|
</div>
|
||||||
|
将value的类型改为Object才能使用
|
||||||
|
</div>
|
||||||
|
<Form class="mt-2" />
|
||||||
</BasicModal>
|
</BasicModal>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user