|
|
@@ -1,324 +1,140 @@
|
|
|
<template>
|
|
|
- <!-- 异常触发节点 -->
|
|
|
<div>
|
|
|
- <BasicForm>
|
|
|
- <!-- 动态参数 -->
|
|
|
- <template #dynamicParams>
|
|
|
- <el-row>
|
|
|
- <el-col :span="12">
|
|
|
- <el-form-item prop="param1Type">
|
|
|
- <el-select placeholder="请选择类型">
|
|
|
- <el-option label="文本" value="1" />
|
|
|
- <el-option label="数字" value="2" />
|
|
|
- <el-option label="日期" value="3" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- </el-col>
|
|
|
- <el-col :span="12">
|
|
|
- <el-form-item prop="param1Desc">
|
|
|
- <el-input placeholder="请输入参数1说明" />
|
|
|
- </el-form-item>
|
|
|
- </el-col>
|
|
|
- </el-row>
|
|
|
+ <BasicForm :model="nodeData">
|
|
|
+ <template #templateID="{ model }">
|
|
|
+ <el-select-v2
|
|
|
+ v-model="model.templateID"
|
|
|
+ :options="
|
|
|
+ templateList.map((item) => ({
|
|
|
+ label: item.templateName,
|
|
|
+ value: item.templateID
|
|
|
+ }))
|
|
|
+ "
|
|
|
+ placeholder="请选择操作模板"
|
|
|
+ @change="handleTemplateChange"
|
|
|
+ />
|
|
|
</template>
|
|
|
</BasicForm>
|
|
|
</div>
|
|
|
</template>
|
|
|
-
|
|
|
-<script setup lang="ts">
|
|
|
- import { ref, reactive, computed, onMounted } from 'vue'
|
|
|
- import type { FormInstance, FormRules } from 'element-plus'
|
|
|
- import { FormItemSchema, useForm } from '@/components/form'
|
|
|
-
|
|
|
- const schema: FormItemSchema[] = [
|
|
|
- {
|
|
|
- prop: 'roleId',
|
|
|
- label: '节点角色',
|
|
|
- component: 'ApiSelect',
|
|
|
- colSpan: 24,
|
|
|
- componentProps: {
|
|
|
- api: '/role/list',
|
|
|
- labelField: 'roleName',
|
|
|
- valueField: 'roleID',
|
|
|
- title: '角色'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- prop: 'templateID',
|
|
|
- label: '故障模板',
|
|
|
- component: 'ApiSelect',
|
|
|
- colSpan: 24,
|
|
|
- componentProps: {
|
|
|
- api: '/templatefault/list',
|
|
|
- labelField: 'templateName',
|
|
|
- valueField: 'templateID',
|
|
|
- title: '故障模板'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- prop: 'category',
|
|
|
- label: '节点分类',
|
|
|
- component: 'Input',
|
|
|
- colSpan: 24,
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入分类'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- prop: 'param1Type',
|
|
|
- label: '节点参数',
|
|
|
- component: 'Select',
|
|
|
- colSpan: 10,
|
|
|
- componentProps: {
|
|
|
- placeholder: '请选择类型',
|
|
|
- options: [
|
|
|
- { label: '文本', value: 1 },
|
|
|
- { label: '数字', value: 2 },
|
|
|
- { label: '日期', value: 3 }
|
|
|
- ]
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- prop: 'param2Desc',
|
|
|
- label: '',
|
|
|
- labelWidth: '0px',
|
|
|
- component: 'Input',
|
|
|
- colSpan: 14,
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入参数2说明'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- prop: 'dynamicParams',
|
|
|
- label: '',
|
|
|
- labelWidth: '0px',
|
|
|
- component: 'Input',
|
|
|
- colSpan: 24,
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入动态参数'
|
|
|
+<script setup lang="ts" name="DrawerOperation">
|
|
|
+ import { useForm } from '@/components/form'
|
|
|
+ import { EasyProcess } from '../common/process.type'
|
|
|
+ import { ProcessFault, ProcessServer } from '@/api/course.api'
|
|
|
+
|
|
|
+ const props = withDefaults(defineProps<{ node: EasyProcess.FaultNode }>(), {})
|
|
|
+
|
|
|
+ const nodeData = ref<Record<string, unknown>>(props.node.nodeData || {})
|
|
|
+ const templateList = ref<ProcessFault[]>([])
|
|
|
+ const templateSelected = ref<ProcessFault>()
|
|
|
+
|
|
|
+ const [BasicForm, formApi] = useForm({
|
|
|
+ labelWidth: '100px',
|
|
|
+ schema: [
|
|
|
+ { prop: 'role', label: '选择角色', component: 'ApiSelect', componentProps: { api: '/role/list', labelField: 'roleName', valueField: 'roleID' } },
|
|
|
+ { prop: 'templateID', label: '操作模', component: 'Input' },
|
|
|
+ { prop: 'templateType', label: '操作模板类型', component: 'Input' },
|
|
|
+ { prop: 'category', label: '节点分类', component: 'Input' },
|
|
|
+ { prop: 'categoryName', label: '分类名称', component: 'Input' },
|
|
|
+ { prop: 'subCategory', label: '子分类', component: 'Input' },
|
|
|
+ { prop: 'subCategoryName', label: '子分类名称', component: 'Input' },
|
|
|
+ {
|
|
|
+ prop: 'param1Type',
|
|
|
+ label: '参数1类型',
|
|
|
+ component: 'Select',
|
|
|
+ colSpan: 10,
|
|
|
+ componentProps: {
|
|
|
+ placeholder: '请选择类型',
|
|
|
+ options: [
|
|
|
+ { label: '文本', value: 1 },
|
|
|
+ { label: '数字', value: 2 },
|
|
|
+ { label: '日期', value: 3 }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ ifShow: () => templateSelected.value?.param1Type != -1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ prop: 'param1Desc',
|
|
|
+ label: '',
|
|
|
+ labelWidth: '0px',
|
|
|
+ component: 'Input',
|
|
|
+ componentProps: () => ({ placeholder: templateSelected.value?.param1Desc || '请输入参数' }),
|
|
|
+ colSpan: 14,
|
|
|
+ ifShow: () => templateSelected.value?.param1Type != -1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ prop: 'param2Type',
|
|
|
+ label: '参数2类型',
|
|
|
+ component: 'ApiDict',
|
|
|
+ componentProps: { code: 'gender' },
|
|
|
+ colSpan: 10,
|
|
|
+ ifShow: () => templateSelected.value?.param2Type != -1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ prop: 'param2Desc',
|
|
|
+ label: '',
|
|
|
+ labelWidth: '0px',
|
|
|
+ component: 'Input',
|
|
|
+ componentProps: () => ({ placeholder: templateSelected.value?.param2Desc || '请输入参数' }),
|
|
|
+ colSpan: 14,
|
|
|
+ ifShow: () => templateSelected.value?.param2Type != -1
|
|
|
+ },
|
|
|
+ { prop: 'param3Type', label: '参数3类型', component: 'Select', colSpan: 10, ifShow: () => templateSelected.value?.param3Type != -1 },
|
|
|
+ {
|
|
|
+ prop: 'param3Desc',
|
|
|
+ label: '',
|
|
|
+ labelWidth: '0px',
|
|
|
+ component: 'Input',
|
|
|
+ componentProps: () => ({ placeholder: templateSelected.value?.param3Desc || '请输入参数' }),
|
|
|
+ colSpan: 14,
|
|
|
+ ifShow: () => templateSelected.value?.param3Type != -1
|
|
|
+ },
|
|
|
+ { prop: 'param4Type', label: '参数4类型', component: 'Select', colSpan: 10, ifShow: () => templateSelected.value?.param4Type != -1 },
|
|
|
+ {
|
|
|
+ prop: 'param4Desc',
|
|
|
+ label: '',
|
|
|
+ labelWidth: '0px',
|
|
|
+ component: 'Input',
|
|
|
+ componentProps: () => ({ placeholder: templateSelected.value?.param4Desc || '请输入参数' }),
|
|
|
+ colSpan: 14,
|
|
|
+ ifShow: () => templateSelected.value?.param4Type != -1
|
|
|
+ },
|
|
|
+ { prop: 'param5Type', label: '参数5类型', component: 'Select', colSpan: 10, ifShow: () => templateSelected.value?.param5Type != -1 },
|
|
|
+ {
|
|
|
+ prop: 'param5Desc',
|
|
|
+ label: '',
|
|
|
+ labelWidth: '0px',
|
|
|
+ component: 'Input',
|
|
|
+ componentProps: () => ({ placeholder: templateSelected.value?.param5Desc || '请输入参数' }),
|
|
|
+ colSpan: 14,
|
|
|
+ ifShow: () => templateSelected.value?.param5Type != -1
|
|
|
}
|
|
|
- }
|
|
|
- ]
|
|
|
- // 表单验证规则
|
|
|
- const rules: FormRules = {
|
|
|
- roleId: [{ required: true, message: '请选择节点角色', trigger: 'change' }],
|
|
|
- templateID: [{ required: true, message: '请选择故障模板', trigger: 'change' }],
|
|
|
- category: [{ required: true, message: '请选择分类', trigger: 'change' }]
|
|
|
- }
|
|
|
- const [BasicForm, formApi] = useForm({ labelWidth: '100px', schema: schema, rules: rules })
|
|
|
-
|
|
|
- /**
|
|
|
- * 故障类模板
|
|
|
- */
|
|
|
- export interface Fault {
|
|
|
- templateID: number /** 模板ID */
|
|
|
- templateName: string /** 模板名称 */
|
|
|
- category: number /** 分类 */
|
|
|
- categoryName: string /** 分类名称 */
|
|
|
- faultLogicMap: number /** 故障逻辑映射 */
|
|
|
- param1Desc: string /** 参数1说明 */
|
|
|
- param1Type: number /** 参数1类型 */
|
|
|
- param2Desc: string /** 参数2说明 */
|
|
|
- param2Type: number /** 参数2类型 */
|
|
|
- param3Desc: string /** 参数3说明 */
|
|
|
- param3Type: number /** 参数3类型 */
|
|
|
- param4Desc: string /** 参数4说明 */
|
|
|
- param4Type: number /** 参数4类型 */
|
|
|
- param5Desc: string /** 参数5说明 */
|
|
|
- param5Type: number /** 参数5类型 */
|
|
|
- subCategory: number /** 子分类 */
|
|
|
- subCategoryName: string /** 子分类名称 */
|
|
|
- }
|
|
|
-
|
|
|
- // Props
|
|
|
- interface Props {
|
|
|
- config?: Partial<Fault>
|
|
|
- }
|
|
|
-
|
|
|
- const props = withDefaults(defineProps<Props>(), {
|
|
|
- config: () => ({})
|
|
|
+ ]
|
|
|
})
|
|
|
|
|
|
- // Emits
|
|
|
- const emit = defineEmits<{
|
|
|
- 'update:config': [value: Partial<Fault>]
|
|
|
- change: [value: Partial<Fault>]
|
|
|
- }>()
|
|
|
-
|
|
|
- // 表单引用
|
|
|
- const formRef = ref<FormInstance>()
|
|
|
-
|
|
|
- // 故障数据
|
|
|
- const fault = reactive<Partial<Fault>>({
|
|
|
- templateID: 0,
|
|
|
- templateName: '',
|
|
|
- category: undefined,
|
|
|
- categoryName: '',
|
|
|
- faultLogicMap: undefined,
|
|
|
- param1Desc: '',
|
|
|
- param1Type: undefined,
|
|
|
- param2Desc: '',
|
|
|
- param2Type: undefined,
|
|
|
- param3Desc: '',
|
|
|
- param3Type: undefined,
|
|
|
- param4Desc: '',
|
|
|
- param4Type: undefined,
|
|
|
- param5Desc: '',
|
|
|
- param5Type: undefined,
|
|
|
- subCategory: undefined,
|
|
|
- subCategoryName: '',
|
|
|
- ...props.config
|
|
|
- })
|
|
|
-
|
|
|
- // 选项数据
|
|
|
- const categoryOptions = ref([
|
|
|
- { label: '硬件故障', value: 1 },
|
|
|
- { label: '软件故障', value: 2 },
|
|
|
- { label: '网络故障', value: 3 },
|
|
|
- { label: '系统故障', value: 4 }
|
|
|
- ])
|
|
|
-
|
|
|
- const subCategoryOptions = ref([
|
|
|
- { label: 'CPU故障', value: 1, category: 1 },
|
|
|
- { label: '内存故障', value: 2, category: 1 },
|
|
|
- { label: '硬盘故障', value: 3, category: 1 },
|
|
|
- { label: '应用崩溃', value: 1, category: 2 },
|
|
|
- { label: '服务异常', value: 2, category: 2 },
|
|
|
- { label: '网络中断', value: 1, category: 3 },
|
|
|
- { label: '网络延迟', value: 2, category: 3 },
|
|
|
- { label: '系统资源不足', value: 1, category: 4 },
|
|
|
- { label: '系统崩溃', value: 2, category: 4 }
|
|
|
- ])
|
|
|
-
|
|
|
- const paramTypeOptions = ref([
|
|
|
- { label: '字符串', value: 1 },
|
|
|
- { label: '数字', value: 2 },
|
|
|
- { label: '布尔值', value: 3 },
|
|
|
- { label: '枚举', value: 4 },
|
|
|
- { label: '时间', value: 5 }
|
|
|
- ])
|
|
|
-
|
|
|
- const faultLogicOptions = ref([
|
|
|
- { label: '立即触发', value: 1 },
|
|
|
- { label: '延迟触发', value: 2 },
|
|
|
- { label: '条件触发', value: 3 },
|
|
|
- { label: '累计触发', value: 4 }
|
|
|
- ])
|
|
|
-
|
|
|
- // 计算属性:过滤子分类选项
|
|
|
- const filteredSubCategoryOptions = computed(() => {
|
|
|
- if (!fault.category) return []
|
|
|
- return subCategoryOptions.value.filter((item) => item.category === fault.category)
|
|
|
- })
|
|
|
-
|
|
|
- // 处理方法
|
|
|
- const handleCategoryChange = (value: number) => {
|
|
|
- // 清除已选择的子分类
|
|
|
- fault.subCategory = undefined
|
|
|
- fault.subCategoryName = ''
|
|
|
-
|
|
|
- // 设置分类名称
|
|
|
- const category = categoryOptions.value.find((item) => item.value === value)
|
|
|
- if (category) {
|
|
|
- fault.categoryName = category.label
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 表单验证
|
|
|
- const validate = (): Promise<boolean> => {
|
|
|
- return new Promise((resolve) => {
|
|
|
- if (!formRef.value) {
|
|
|
- resolve(false)
|
|
|
- return
|
|
|
+ const handleTemplateChange = (val: string) => {
|
|
|
+ if (val) {
|
|
|
+ const template = templateList.value.find((item) => item.templateID == val)
|
|
|
+ if (template) {
|
|
|
+ templateSelected.value = template
|
|
|
}
|
|
|
-
|
|
|
- formRef.value.validate((valid) => {
|
|
|
- resolve(valid)
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- // 重置表单
|
|
|
- const resetForm = () => {
|
|
|
- if (formRef.value) {
|
|
|
- formRef.value.resetFields()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取表单数据
|
|
|
- const getFormData = (): Partial<Fault> => {
|
|
|
- return { ...fault }
|
|
|
- }
|
|
|
-
|
|
|
- // 监听数据变化
|
|
|
- watch(
|
|
|
- () => fault,
|
|
|
- (newValue) => {
|
|
|
- emit('update:config', newValue)
|
|
|
- emit('change', newValue)
|
|
|
- },
|
|
|
- { deep: true }
|
|
|
- )
|
|
|
+ onMounted(async () => {
|
|
|
+ const { data } = await ProcessServer.faultList()
|
|
|
+ templateList.value = data || []
|
|
|
+ })
|
|
|
|
|
|
- // 监听子分类变化
|
|
|
- watch(
|
|
|
- () => fault.subCategory,
|
|
|
- (value) => {
|
|
|
- if (value) {
|
|
|
- const subCategory = subCategoryOptions.value.find((item) => item.value === value)
|
|
|
- if (subCategory) {
|
|
|
- fault.subCategoryName = subCategory.label
|
|
|
+ defineExpose({
|
|
|
+ getNodeData: (callback: (nodeData: Record<string, unknown>) => void) => {
|
|
|
+ formApi.validate().then((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ callback(nodeData.value)
|
|
|
+ } else {
|
|
|
+ ElMessage.error('请检查节点配置是否完整')
|
|
|
}
|
|
|
- }
|
|
|
+ })
|
|
|
}
|
|
|
- )
|
|
|
-
|
|
|
- // 暴露方法给父组件
|
|
|
- defineExpose({
|
|
|
- validate,
|
|
|
- resetForm,
|
|
|
- getFormData
|
|
|
- })
|
|
|
-
|
|
|
- onMounted(() => {
|
|
|
- // 初始化逻辑
|
|
|
- console.log('FaultTrigger component mounted')
|
|
|
})
|
|
|
</script>
|
|
|
-
|
|
|
-<style lang="scss" scoped>
|
|
|
- .fault-trigger-config {
|
|
|
- padding: 16px;
|
|
|
-
|
|
|
- .header {
|
|
|
- font-size: 16px;
|
|
|
- font-weight: 600;
|
|
|
- margin-bottom: 20px;
|
|
|
- color: #303133;
|
|
|
- padding-bottom: 8px;
|
|
|
- border-bottom: 1px solid #e4e7ed;
|
|
|
- }
|
|
|
-
|
|
|
- .form-container {
|
|
|
- max-width: 600px;
|
|
|
-
|
|
|
- .param-row {
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
-
|
|
|
- .el-input,
|
|
|
- .el-select {
|
|
|
- flex-shrink: 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- .el-form-item {
|
|
|
- margin-bottom: 20px;
|
|
|
-
|
|
|
- &:last-child {
|
|
|
- margin-bottom: 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-</style>
|