86 lines
3.5 KiB
Vue
86 lines
3.5 KiB
Vue
|
|
<template>
|
||
|
|
<el-form ref="formRef" :model="formData" label-width="auto">
|
||
|
|
<el-table v-if="formData.tableData.length" :data="formData.tableData" default-expand-all style="width: 100%">
|
||
|
|
<el-table-column type="expand">
|
||
|
|
<template #default="{ row: flowItem, $index: flowIndex }">
|
||
|
|
<el-table v-if="flowItem.config.length" :data="flowItem.config" row-key="name" default-expand-all>
|
||
|
|
<el-table-column prop="name" label="参数名称">
|
||
|
|
<template #default="{ row }">
|
||
|
|
<span>{{ row.name }}</span>
|
||
|
|
<span v-if="row.required" class="required-mark">*</span>
|
||
|
|
</template>
|
||
|
|
</el-table-column>
|
||
|
|
<el-table-column prop="type" label="类型" width="90">
|
||
|
|
<template #default="{ row }"><el-tag size="small">{{ row.type }}</el-tag></template>
|
||
|
|
</el-table-column>
|
||
|
|
<el-table-column prop="value" label="本次执行值" min-width="160">
|
||
|
|
<template #default="{ row }">
|
||
|
|
<el-form-item
|
||
|
|
v-if="row.type !== 'object' && !row.type.includes('array')"
|
||
|
|
label=""
|
||
|
|
:prop="`tableData.${flowIndex}.config${row.propPath}value`"
|
||
|
|
:rules="row.required ? [{ required: true, message: `请输入${row.name}`, trigger: ['blur', 'change'] }] : []"
|
||
|
|
>
|
||
|
|
<el-input v-if="row.type === 'string'" v-model="row.value" />
|
||
|
|
<el-input-number v-else-if="row.type === 'number'" v-model="row.value" :controls="false" />
|
||
|
|
<el-switch v-else-if="row.type === 'boolean'" v-model="row.value" />
|
||
|
|
<el-input v-else v-model="row.value" />
|
||
|
|
</el-form-item>
|
||
|
|
</template>
|
||
|
|
</el-table-column>
|
||
|
|
</el-table>
|
||
|
|
</template>
|
||
|
|
</el-table-column>
|
||
|
|
<el-table-column label="执行顺序" prop="orderNum" width="90" align="center" />
|
||
|
|
<el-table-column label="流程项" prop="itemName" show-overflow-tooltip />
|
||
|
|
</el-table>
|
||
|
|
<el-empty v-else description="当前任务没有需要填写的运行参数" :image-size="52" />
|
||
|
|
</el-form>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script setup>
|
||
|
|
import { reactive, ref, watch } from 'vue'
|
||
|
|
import { addValueProperty, formatTableData } from '@/utils/flow'
|
||
|
|
|
||
|
|
const props = defineProps({ items: { type: Array, default: () => [] } })
|
||
|
|
const formRef = ref()
|
||
|
|
const formData = reactive({ tableData: [] })
|
||
|
|
|
||
|
|
const parseConfig = (config) => {
|
||
|
|
if (!config) return []
|
||
|
|
const schema = typeof config === 'string' ? JSON.parse(config) : config
|
||
|
|
return addValueProperty(JSON.parse(JSON.stringify(schema || [])))
|
||
|
|
}
|
||
|
|
|
||
|
|
const resetItems = (items) => {
|
||
|
|
formData.tableData = (items || []).map((item, index) => ({
|
||
|
|
...item,
|
||
|
|
orderNum: item.orderNum ?? index + 1,
|
||
|
|
config: parseConfig(item.config),
|
||
|
|
}))
|
||
|
|
}
|
||
|
|
|
||
|
|
const validate = async () => !formRef.value || formRef.value.validate().catch(() => false)
|
||
|
|
|
||
|
|
const getRunParams = () => {
|
||
|
|
const occurrences = new Map()
|
||
|
|
const result = {}
|
||
|
|
formData.tableData.forEach((item) => {
|
||
|
|
const itemId = String(item.itemId)
|
||
|
|
const occurrence = (occurrences.get(itemId) || 0) + 1
|
||
|
|
occurrences.set(itemId, occurrence)
|
||
|
|
result[`${itemId}:${occurrence}`] = formatTableData(item.config, {})
|
||
|
|
})
|
||
|
|
return result
|
||
|
|
}
|
||
|
|
|
||
|
|
watch(() => props.items, resetItems, { immediate: true, deep: true })
|
||
|
|
defineExpose({ validate, getRunParams, resetItems })
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<style scoped>
|
||
|
|
.required-mark { margin-left: 6px; color: var(--el-color-danger); }
|
||
|
|
:deep(.el-form-item) { margin-bottom: 0; }
|
||
|
|
:deep(.el-input-number) { width: 100%; }
|
||
|
|
</style>
|