style(sj_map_reduce): 工作流开始节点上下文组件优化
This commit is contained in:
parent
3c19775395
commit
cdf91334a8
@ -11,7 +11,7 @@ defineOptions({
|
|||||||
});
|
});
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
modelValue: string;
|
modelValue?: string;
|
||||||
lang?: NaiveUI.CodeMirrorLang;
|
lang?: NaiveUI.CodeMirrorLang;
|
||||||
height?: string;
|
height?: string;
|
||||||
fontSize?: string;
|
fontSize?: string;
|
||||||
@ -25,7 +25,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
readonly: false,
|
readonly: false,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
fontSize: '13px'
|
fontSize: '13px',
|
||||||
|
modelValue: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
|
@ -51,6 +51,20 @@ const boolenOptions = [
|
|||||||
value: 1
|
value: 1
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const handleUpdateType = (index: number) => {
|
||||||
|
if (content.value[index].type === 'string') {
|
||||||
|
content.value[index].value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content.value[index].type === 'boolean') {
|
||||||
|
content.value[index].value = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content.value[index].type === 'number') {
|
||||||
|
content.value[index].value = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -86,7 +100,7 @@ const boolenOptions = [
|
|||||||
@keydown.enter.prevent
|
@keydown.enter.prevent
|
||||||
/>
|
/>
|
||||||
<NSelect
|
<NSelect
|
||||||
v-if="content[index].type === 'boolen'"
|
v-if="content[index].type === 'boolean'"
|
||||||
v-model:value="content[index].value as number"
|
v-model:value="content[index].value as number"
|
||||||
:options="boolenOptions"
|
:options="boolenOptions"
|
||||||
placeholder="value"
|
placeholder="value"
|
||||||
@ -106,6 +120,7 @@ const boolenOptions = [
|
|||||||
:options="typeOptions"
|
:options="typeOptions"
|
||||||
placeholder="字段类型"
|
placeholder="字段类型"
|
||||||
@keydown.enter.prevent
|
@keydown.enter.prevent
|
||||||
|
@update:value="handleUpdateType(index)"
|
||||||
/>
|
/>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<div class="ml-3px h-34px lh-34px">)</div>
|
<div class="ml-3px h-34px lh-34px">)</div>
|
||||||
|
@ -11,7 +11,6 @@ defineOptions({
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title?: string;
|
title?: string;
|
||||||
show?: boolean;
|
|
||||||
drawer?: boolean;
|
drawer?: boolean;
|
||||||
type?: 'job' | 'retry';
|
type?: 'job' | 'retry';
|
||||||
taskData?: Api.Job.JobTask | Api.RetryLog.RetryLog | Api.RetryTask.RetryTask;
|
taskData?: Api.Job.JobTask | Api.RetryLog.RetryLog | Api.RetryTask.RetryTask;
|
||||||
@ -20,20 +19,14 @@ interface Props {
|
|||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
title: undefined,
|
title: undefined,
|
||||||
show: false,
|
|
||||||
drawer: true,
|
drawer: true,
|
||||||
type: 'job',
|
type: 'job',
|
||||||
taskData: undefined,
|
taskData: undefined,
|
||||||
modelValue: () => []
|
modelValue: () => []
|
||||||
});
|
});
|
||||||
|
|
||||||
interface Emits {
|
const visible = defineModel<boolean>('show', {
|
||||||
(e: 'update:show', show: boolean): void;
|
default: false
|
||||||
}
|
|
||||||
|
|
||||||
const emit = defineEmits<Emits>();
|
|
||||||
const visible = defineModel<boolean>('visible', {
|
|
||||||
default: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const syncTime = ref(1);
|
const syncTime = ref(1);
|
||||||
@ -103,9 +96,8 @@ onBeforeUnmount(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.show,
|
() => visible.value,
|
||||||
async val => {
|
async val => {
|
||||||
visible.value = val;
|
|
||||||
if (val) {
|
if (val) {
|
||||||
if (props.modelValue) {
|
if (props.modelValue) {
|
||||||
logList.value = props.modelValue;
|
logList.value = props.modelValue;
|
||||||
@ -125,10 +117,6 @@ watch(
|
|||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
const onUpdateShow = (value: boolean) => {
|
|
||||||
emit('update:show', value);
|
|
||||||
};
|
|
||||||
|
|
||||||
function timestampToDate(timestamp: string): string {
|
function timestampToDate(timestamp: string): string {
|
||||||
const date = new Date(Number.parseInt(timestamp?.toString(), 10));
|
const date = new Date(Number.parseInt(timestamp?.toString(), 10));
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear();
|
||||||
@ -264,7 +252,7 @@ const SnailLogComponent = defineComponent({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NDrawer v-if="drawer" v-model:show="visible" width="100%" display-directive="if" @update:show="onUpdateShow">
|
<NDrawer v-if="drawer" v-model:show="visible" width="100%" display-directive="if">
|
||||||
<NDrawerContent closable>
|
<NDrawerContent closable>
|
||||||
<template #header>
|
<template #header>
|
||||||
<div class="flex-center">
|
<div class="flex-center">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue';
|
import { ref, watch } from 'vue';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import { blockStrategyRecord, triggerTypeRecord, workFlowNodeStatusRecord } from '@/constants/business';
|
import { blockStrategyRecord, triggerTypeRecord, workFlowNodeStatusRecord } from '@/constants/business';
|
||||||
|
|
||||||
@ -36,14 +36,6 @@ watch(
|
|||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
emit('update:open', false);
|
emit('update:open', false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const wfContext = computed(() => {
|
|
||||||
try {
|
|
||||||
return JSON.parse(props.modelValue?.wfContext || '{}').init;
|
|
||||||
} catch {
|
|
||||||
return props.modelValue.wfContext;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -60,7 +52,7 @@ const wfContext = computed(() => {
|
|||||||
|
|
||||||
<NDescriptionsItem label="执行超时时间">{{ modelValue.executorTimeout }} 秒</NDescriptionsItem>
|
<NDescriptionsItem label="执行超时时间">{{ modelValue.executorTimeout }} 秒</NDescriptionsItem>
|
||||||
<NDescriptionsItem label="阻塞策略">{{ $t(blockStrategyRecord[modelValue.blockStrategy!]) }}</NDescriptionsItem>
|
<NDescriptionsItem label="阻塞策略">{{ $t(blockStrategyRecord[modelValue.blockStrategy!]) }}</NDescriptionsItem>
|
||||||
<NDescriptionsItem label="工作流上下文">{{ wfContext }}</NDescriptionsItem>
|
<NDescriptionsItem label="工作流上下文">{{ modelValue.wfContext }}</NDescriptionsItem>
|
||||||
<NDescriptionsItem label="工作流状态">
|
<NDescriptionsItem label="工作流状态">
|
||||||
{{ $t(workFlowNodeStatusRecord[modelValue.workflowStatus!]) }}
|
{{ $t(workFlowNodeStatusRecord[modelValue.workflowStatus!]) }}
|
||||||
</NDescriptionsItem>
|
</NDescriptionsItem>
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from 'vue';
|
import { ref, watch } from 'vue';
|
||||||
import type { FormInst, FormRules } from 'naive-ui';
|
import type { FormInst, FormRules } from 'naive-ui';
|
||||||
import CodeMirror from 'vue-codemirror6';
|
|
||||||
import { oneDark } from '@codemirror/theme-one-dark';
|
|
||||||
import { javascript } from '@codemirror/lang-javascript';
|
|
||||||
import EditableInput from '@/components/common/editable-input.vue';
|
import EditableInput from '@/components/common/editable-input.vue';
|
||||||
import { fetchCheckNodeExpression } from '@/service/api';
|
import { fetchCheckNodeExpression } from '@/service/api';
|
||||||
import { expressionOptions } from '@/constants/business';
|
import { expressionOptions } from '@/constants/business';
|
||||||
@ -36,21 +33,11 @@ const form = ref<Workflow.ConditionNodeType>({
|
|||||||
decision: {
|
decision: {
|
||||||
logicalCondition: 1,
|
logicalCondition: 1,
|
||||||
expressionType: 1,
|
expressionType: 1,
|
||||||
|
nodeExpression: '',
|
||||||
checkContents: []
|
checkContents: []
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const theme = ref({
|
|
||||||
'.cm-line': {
|
|
||||||
fontSize: '18px'
|
|
||||||
},
|
|
||||||
'.cm-scroller': {
|
|
||||||
height: '500px',
|
|
||||||
overflowY: 'auto',
|
|
||||||
overflowX: 'hidden'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.open,
|
() => props.open,
|
||||||
val => {
|
val => {
|
||||||
@ -147,14 +134,7 @@ const rules: FormRules = {
|
|||||||
</NRadioGroup>
|
</NRadioGroup>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem path="decision.nodeExpression" label="条件表达式">
|
<NFormItem path="decision.nodeExpression" label="条件表达式">
|
||||||
<CodeMirror
|
<CodeMirror v-model="form.decision!.nodeExpression" placeholder="请输入条件表达式" />
|
||||||
v-model="form.decision!.nodeExpression"
|
|
||||||
class="sj-code-mirror"
|
|
||||||
:theme="theme"
|
|
||||||
basic
|
|
||||||
:lang="javascript()"
|
|
||||||
:extensions="[oneDark]"
|
|
||||||
/>
|
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem path="decision.checkContents" label="模拟上下文">
|
<NFormItem path="decision.checkContents" label="模拟上下文">
|
||||||
<DynamicInput v-model:value="form.decision!.checkContents!" path="decision.checkContents" />
|
<DynamicInput v-model:value="form.decision!.checkContents!" path="decision.checkContents" />
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
} from '@/constants/business';
|
} from '@/constants/business';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import { fetchGetAllGroupNameList } from '@/service/api';
|
import { fetchGetAllGroupNameList } from '@/service/api';
|
||||||
import { isNotNull } from '@/utils/common';
|
import { isNotNull, parseContent, stringToContent } from '@/utils/common';
|
||||||
import { useWorkflowStore } from '@/store/modules/workflow';
|
import { useWorkflowStore } from '@/store/modules/workflow';
|
||||||
import EditableInput from '@/components/common/editable-input.vue';
|
import EditableInput from '@/components/common/editable-input.vue';
|
||||||
|
|
||||||
@ -24,7 +24,9 @@ interface Props {
|
|||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
open: false,
|
open: false,
|
||||||
modelValue: () => ({})
|
modelValue: () => ({
|
||||||
|
wfContexts: []
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
@ -38,7 +40,9 @@ const store = useWorkflowStore();
|
|||||||
|
|
||||||
let title: string = '';
|
let title: string = '';
|
||||||
const drawer = ref<boolean>(false);
|
const drawer = ref<boolean>(false);
|
||||||
const form = ref<Workflow.NodeDataType>({});
|
const form = ref<Workflow.NodeDataType>({
|
||||||
|
wfContexts: []
|
||||||
|
});
|
||||||
const groupNameList = ref<string[]>([]);
|
const groupNameList = ref<string[]>([]);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
@ -64,7 +68,8 @@ watch(
|
|||||||
title = '请选择组';
|
title = '请选择组';
|
||||||
}
|
}
|
||||||
if (val.wfContext) {
|
if (val.wfContext) {
|
||||||
form.value.wfContext = JSON.parse(val.wfContext).init;
|
form.value.wfContext = JSON.parse(val.wfContext);
|
||||||
|
form.value.wfContexts = stringToContent(val.wfContext);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
@ -81,7 +86,7 @@ const save = () => {
|
|||||||
formRef.value
|
formRef.value
|
||||||
?.validate(errors => {
|
?.validate(errors => {
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
form.value.wfContext = JSON.stringify({ init: form.value.wfContext });
|
form.value.wfContext = JSON.stringify(parseContent(form.value.wfContexts) || {});
|
||||||
close();
|
close();
|
||||||
emit('save', form.value);
|
emit('save', form.value);
|
||||||
}
|
}
|
||||||
@ -206,7 +211,7 @@ const rules: Record<RuleKey, FormItemRule> = {
|
|||||||
</NGi>
|
</NGi>
|
||||||
</NGrid>
|
</NGrid>
|
||||||
<NFormItem path="wfContext" label="工作流上下文">
|
<NFormItem path="wfContext" label="工作流上下文">
|
||||||
<CodeMirror v-model="form.wfContext" lang="json" placeholder="请输入工作流上下文" />
|
<DynamicInput v-model:value="form.wfContexts!" path="wfContexts" />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem path="workflowStatus" label="节点状态">
|
<NFormItem path="workflowStatus" label="节点状态">
|
||||||
<NRadioGroup v-model:value="form.workflowStatus">
|
<NRadioGroup v-model:value="form.workflowStatus">
|
||||||
|
1
src/typings/workflow.d.ts
vendored
1
src/typings/workflow.d.ts
vendored
@ -17,6 +17,7 @@ declare namespace Workflow {
|
|||||||
executorTimeout?: number;
|
executorTimeout?: number;
|
||||||
/** 方法参数 */
|
/** 方法参数 */
|
||||||
wfContext?: string;
|
wfContext?: string;
|
||||||
|
wfContexts?: { key: string; value: string | number | boolean; type: string }[];
|
||||||
/** 工作流状态 */
|
/** 工作流状态 */
|
||||||
workflowStatus?: Api.Common.WorkFlowNodeStatus;
|
workflowStatus?: Api.Common.WorkFlowNodeStatus;
|
||||||
/** 描述 */
|
/** 描述 */
|
||||||
|
@ -179,3 +179,44 @@ export function parseContent(value?: { key: string; value: string | number | boo
|
|||||||
return obj;
|
return obj;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function stringToContent(
|
||||||
|
jsonString?: string
|
||||||
|
): { key: string; value: string | number | boolean; type: string }[] {
|
||||||
|
if (!jsonString) return [];
|
||||||
|
// 尝试解析JSON字符串
|
||||||
|
let parsedObj = jsonString;
|
||||||
|
|
||||||
|
if (typeof jsonString === 'string') {
|
||||||
|
try {
|
||||||
|
parsedObj = JSON.parse(jsonString);
|
||||||
|
} catch (e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建结果数组
|
||||||
|
const result = [];
|
||||||
|
|
||||||
|
// 遍历对象的键值对
|
||||||
|
for (const [key, value] of Object.entries(parsedObj)) {
|
||||||
|
// 根据值的类型确定type字段
|
||||||
|
let type = 'string';
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
type = 'number';
|
||||||
|
} else if (typeof value === 'boolean') {
|
||||||
|
type = 'boolean';
|
||||||
|
} else {
|
||||||
|
type = 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将转换后的对象添加到结果数组中
|
||||||
|
result.push({
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return result as any;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user