UPDATE: VERSION-20260317

This commit is contained in:
libertyspy
2026-03-17 10:06:55 +08:00
parent d13359c803
commit 185e490560
3 changed files with 259 additions and 283 deletions

View File

@@ -274,8 +274,11 @@ const getAlgorithmTypeName = (type: NullableString): NullableString => {
const load = () => { const load = () => {
algorithms.value = []; algorithms.value = [];
algorithmsTotal.value = 0; algorithmsTotal.value = 0;
formRef.value?.resetFields();
selectedAlgorithm.value = resolveItem(defaultAlgorithm); if(selectedAlgorithm.value.id <= 0){
formRef.value?.resetFields();
selectedAlgorithm.value = resolveItem(defaultAlgorithm);
}
findAlgorithmsByQuery(query.value).then(r => { findAlgorithmsByQuery(query.value).then(r => {
algorithms.value = r.rows ?? []; algorithms.value = r.rows ?? [];

View File

@@ -3,12 +3,13 @@
<!-- 平台选择框 --> <!-- 平台选择框 -->
<a-select <a-select
style="width:280px" style="width:280px"
v-model:value="selectedPlatformId" v-model:value="innerPlatformId"
:placeholder="'请选择平台'" placeholder="请选择平台"
:disabled="loading"
> >
<a-select-option <a-select-option
v-for="item in platforms" v-for="item in platforms"
:key="item.id" :key="`platform-${item.id}`"
:value="item.id" :value="item.id"
> >
{{ item.description || item.name || '未命名平台' }} {{ item.description || item.name || '未命名平台' }}
@@ -18,13 +19,13 @@
<!-- 组件选择框 --> <!-- 组件选择框 -->
<a-select <a-select
style="width:280px;" style="width:280px;"
v-model:value="selectedComponentId" v-model:value="innerComponentId"
:placeholder="'请选择组件'" placeholder="请选择组件"
:disabled="!selectedPlatform" :disabled="!innerPlatformId || loading"
> >
<a-select-option <a-select-option
v-for="item in selectedPlatformComponents" v-for="item in selectedPlatformComponents"
:key="item.id" :key="`component-${item.id}`"
:value="item.id" :value="item.id"
> >
{{ item.description || item.name || '未命名组件' }} {{ item.description || item.name || '未命名组件' }}
@@ -35,134 +36,116 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent, onMounted, type PropType, ref, watch } from 'vue'; import { computed, defineComponent, onMounted, type PropType, ref, watch } from 'vue';
import type { Platform, PlatformComponent, PlatformComponentPayload, PlatformWithComponents } from '../types'; import type { Platform, PlatformComponent, PlatformComponentPayload, PlatformWithComponents, PlatformWithComponentsResponse } from '../types';
import { findAllPlatformWithComponents } from './api'; import { findAllPlatformWithComponents } from './api';
export default defineComponent({ export default defineComponent({
name: 'PlatformSelect',
props: { props: {
placeholder: { platformId: {
type: String, type: [Number, null] as PropType<number | null>,
default: '',
},
payload: {
type: [Object,null] as PropType<PlatformComponentPayload | null>,
required: false, required: false,
default: ({ default: null,
platform: null, },
component: null, componentId: {
}), type: [Number, null] as PropType<number | null>,
required: false,
default: null,
}, },
}, },
emits: [ emits: {
'change', change: (payload: PlatformComponentPayload) => true,
], },
setup(props, { emit }) { setup(props, { emit }) {
const loading = ref<boolean>(true);
const platforms = ref<PlatformWithComponents[]>([]); const platforms = ref<PlatformWithComponents[]>([]);
const platformMapping = ref<Map<number, PlatformWithComponents>>(new Map()); const platformMap = ref<Map<number, Platform>>(new Map());
const componentsMapping = ref<Map<number, PlatformComponent>>(new Map()); const componentMap = ref<Map<number, PlatformComponent>>(new Map());
const selectedPlatformComponents = ref<PlatformComponent[]>([]) const innerPlatformId = ref<number | null>(null);
const innerComponentId = ref<number | null>(null);
const selectedPlatform = ref<PlatformWithComponents|null>(null); const selectedPlatformComponents = computed(() => {
const selectedPlatformId = ref<number|null>(null); const platform = platforms.value.find(p => p.id === innerPlatformId.value);
return platform?.components || [];
});
const selectedComponent = ref<PlatformComponent|null>(null); const loadData = async () => {
const selectedComponentId = ref<number|null>(null); try {
loading.value = true;
const res: PlatformWithComponentsResponse = await findAllPlatformWithComponents();
const data = res.data || [];
const load = () => { platforms.value = data;
platforms.value = []; platformMap.value.clear();
platformMapping.value.clear(); componentMap.value.clear();
componentsMapping.value.clear();
findAllPlatformWithComponents().then(re => { data.forEach(platform => {
platforms.value = re.data ?? []; platformMap.value.set(platform.id, platform);
platforms.value.forEach(platform => { platform.components?.forEach(component => {
platformMapping.value.set(platform.id, platform); componentMap.value.set(component.id, component);
if(platform.components){ });
platform.components.forEach(comp=> {
componentsMapping.value.set(comp.id, comp)
})
}
}); });
}).catch(err => {
console.error('加载平台组件数据失败:', err); innerPlatformId.value = props.platformId;
}); innerComponentId.value = props.componentId;
} catch (err) {
console.error('加载平台组件失败:', err);
} finally {
loading.value = false;
}
}; };
const triggerChange = ()=> { const emitChange = () => {
// 根据ID获取完整对象
const platform = platformMap.value.get(innerPlatformId.value || -1) || null;
const component = componentMap.value.get(innerComponentId.value || -1) || null;
const validComponent = component && component.platformId === innerPlatformId.value
? component
: null;
emit('change', { emit('change', {
platform: selectedPlatform.value ? { platform: platform ? {
id: selectedPlatform.value?.id, id: platform.id,
name: selectedPlatform.value?.name, name: platform.name,
description: selectedPlatform.value?.description, description: platform.description,
scenarioId: platform.scenarioId,
} : null, } : null,
component: selectedComponent.value ? { component: validComponent,
id: selectedComponent.value.id, } as PlatformComponentPayload);
name: selectedComponent.value.name, };
description: selectedComponent.value.description,
num: selectedComponent.value.num,
platformId: selectedComponent.value.platformId,
type: selectedComponent.value.type,
} : null,
})
}
watch(()=> props.payload, (n: PlatformComponentPayload | null | undefined)=> { watch([() => props.platformId, () => props.componentId],
if(n && n.platform){ ([newPlatformId, newComponentId]) => {
selectedPlatform.value = platformMapping.value.get(n.platform?.id) ?? null; if (!loading.value) {
selectedPlatformId.value = selectedPlatform.value?.id ?? null; innerPlatformId.value = newPlatformId;
selectedPlatformComponents.value = selectedPlatform.value?.components ?? [] innerComponentId.value = newComponentId;
} else { }
selectedPlatform.value = null; },
selectedPlatformId.value = null; { immediate: true, deep: false },
selectedPlatformComponents.value = [] );
watch(innerPlatformId, (newVal) => {
if (newVal !== innerPlatformId.value) {
innerComponentId.value = null;
} }
emitChange();
});
if(n && n.component){ watch(innerComponentId, emitChange);
selectedComponent.value = n.component;
selectedComponentId.value = selectedComponent.value?.id ?? null;
} else {
selectedComponent.value = null;
selectedComponentId.value = null;
}
console.error('watch',n) onMounted(() => {
}, {deep: true, immediate: true}) loadData();
});
watch(()=> selectedPlatformId.value,(n: null | number)=> {
if(n && platformMapping.value.get(n)){
selectedPlatform.value = platformMapping.value.get(n) ?? null;
selectedPlatformComponents.value = selectedPlatform.value?.components ?? []
} else {
selectedPlatform.value = null;
selectedPlatformComponents.value = []
}
selectedComponentId.value = null;
triggerChange();
})
watch(()=> selectedComponentId.value,(n: null | number)=> {
if(n && componentsMapping.value.get(n)){
selectedComponent.value = componentsMapping.value.get(n) ?? null;
} else {
selectedComponent.value = null;
}
triggerChange();
})
onMounted(() => load());
return { return {
loading,
platforms, platforms,
selectedPlatformComponents, selectedPlatformComponents,
selectedPlatform, innerPlatformId,
selectedPlatformId, innerComponentId,
selectedComponent,
selectedComponentId,
}; };
}, }
}); });
</script> </script>

View File

@@ -32,9 +32,7 @@
</template> </template>
<div class="w-full h-full"> <div class="w-full h-full">
<a-card class="ks-page-card ks-algorithm-card"> <a-card class="ks-page-card ks-algorithm-card">
<template #title> <template #title>
<a-space> <a-space>
<span class="point"></span> <span class="point"></span>
@@ -43,7 +41,6 @@
</template> </template>
<div class="ks-scrollable" style="height: 80.5vh;overflow-y: auto;padding-right: 10px"> <div class="ks-scrollable" style="height: 80.5vh;overflow-y: auto;padding-right: 10px">
<a-row :gutter="15"> <a-row :gutter="15">
<a-col :span="16"> <a-col :span="16">
<a-form <a-form
@@ -57,14 +54,14 @@
<a-form-item <a-form-item
label="规则名称" label="规则名称"
:rules="[{ required: true, message: '请输入规则名称!', trigger: ['input', 'change'] }]" :rules="[{ required: true, message: '请输入规则名称!', trigger: ['input', 'change'] }]"
:name="['name']" name="name"
> >
<a-input v-model:value="selectedFireRule.name" placeholder="请输入规则名称" /> <a-input v-model:value="selectedFireRule.name" placeholder="请输入规则名称" />
</a-form-item> </a-form-item>
<a-form-item <a-form-item
label="场景类型" label="场景类型"
:name="['sceneType']" name="sceneType"
> >
<a-select v-model:value="selectedFireRule.sceneType" placeholder="请选择场景类型"> <a-select v-model:value="selectedFireRule.sceneType" placeholder="请选择场景类型">
<a-select-option :value="null">通用</a-select-option> <a-select-option :value="null">通用</a-select-option>
@@ -73,23 +70,32 @@
</a-select> </a-select>
</a-form-item> </a-form-item>
<!-- 触发条件 - 传递ID保持PlatformComponentPayload结构 -->
<a-form-item <a-form-item
label="触发条件" label="触发条件"
:rules="[{ required: true, message: '请输入触发条件!', trigger: [ 'change'] }]" :rules="[{ required: true, message: '请输入触发条件!', trigger: ['change'] }]"
:name="['conditionsArray']" name="conditionsArray"
> >
<a-form-item-rest> <a-form-item-rest>
<div class="ks-sidebar-list-param-list"> <div class="ks-sidebar-list-param-list">
<div class="ks-sidebar-list-param-item" v-for="(item,index) in selectedFireRule.conditionsArray"> <div
class="ks-sidebar-list-param-item"
v-for="(item,index) in selectedFireRule.conditionsArray"
:key="`condition-${index}-${item.platform?.id || 'null'}-${item.component?.id || 'null'}`"
>
<a-row :gutter="15"> <a-row :gutter="15">
<a-col :span="21"> <a-col :span="21">
<PlatformSelect @change="(payload: PlatformComponentPayload)=> handleUpdateCondition(payload, index)" <!-- 只传递ID参数 -->
:payload="item"/> <PlatformSelect
:platform-id="item.platform?.id || null"
:component-id="item.component?.id || null"
@change="(payload)=> handleUpdateCondition(payload, index)"
/>
</a-col> </a-col>
<a-col :span="3"> <a-col :span="3">
<a-space class="ks-sidebar-list-param-actions"> <a-space class="ks-sidebar-list-param-actions">
<MinusCircleOutlined @click="()=> handleMinusCondition(index)" /> <MinusCircleOutlined @click.stop="()=> handleMinusCondition(index)" />
<PlusCircleOutlined @click="()=> handleAddCondition(index)" v-if="index === 0" /> <PlusCircleOutlined @click.stop="()=> handleAddCondition()" v-if="index === 0" />
</a-space> </a-space>
</a-col> </a-col>
</a-row> </a-row>
@@ -98,23 +104,32 @@
</a-form-item-rest> </a-form-item-rest>
</a-form-item> </a-form-item>
<!-- 响应动作 - 传递ID保持PlatformComponentPayload结构 -->
<a-form-item <a-form-item
label="响应动作" label="响应动作"
:rules="[{ required: true, message: '请输入响应动作!', trigger: ['change'] }]" :rules="[{ required: true, message: '请输入响应动作!', trigger: ['change'] }]"
:name="['actionsArray']" name="actionsArray"
> >
<a-form-item-rest> <a-form-item-rest>
<div class="ks-sidebar-list-param-list"> <div class="ks-sidebar-list-param-list">
<div class="ks-sidebar-list-param-item" v-for="(item,index) in selectedFireRule.actionsArray"> <div
class="ks-sidebar-list-param-item"
v-for="(item,index) in selectedFireRule.actionsArray"
:key="`action-${index}-${item.platform?.id || 'null'}-${item.component?.id || 'null'}`"
>
<a-row :gutter="15"> <a-row :gutter="15">
<a-col :span="21"> <a-col :span="21">
<PlatformSelect @change="(payload: PlatformComponentPayload)=> handleUpdateAction(payload, index)" <!-- 只传递ID参数 -->
:payload="item"/> <PlatformSelect
:platform-id="item.platform?.id || null"
:component-id="item.component?.id || null"
@change="(payload)=> handleUpdateAction(payload, index)"
/>
</a-col> </a-col>
<a-col :span="3"> <a-col :span="3">
<a-space class="ks-sidebar-list-param-actions"> <a-space class="ks-sidebar-list-param-actions">
<MinusCircleOutlined @click="()=> handleMinusAction(index)" /> <MinusCircleOutlined @click.stop="()=> handleMinusAction(index)" />
<PlusCircleOutlined @click="()=> handleAddAction(index)" v-if="index === 0" /> <PlusCircleOutlined @click.stop="()=> handleAddAction()" v-if="index === 0" />
</a-space> </a-space>
</a-col> </a-col>
</a-row> </a-row>
@@ -126,24 +141,21 @@
<a-form-item <a-form-item
label="优先级(数值越小优先级越高)" label="优先级(数值越小优先级越高)"
:rules="[{ required: true, message: '请输入优先级!', trigger: ['input', 'change'] }]" :rules="[{ required: true, message: '请输入优先级!', trigger: ['input', 'change'] }]"
:name="['priority']" name="priority"
> >
<a-input-number style="width:100%;" v-model:value="selectedFireRule.priority" placeholder="请输入优先级" /> <a-input-number style="width:100%;" v-model:value="selectedFireRule.priority" placeholder="请输入优先级" />
</a-form-item> </a-form-item>
<a-form-item <a-form-item
label="是否启用" label="是否启用"
:name="['priority']" name="enabled"
> >
<a-switch v-model:checked="selectedFireRule.enabled" /> <a-switch v-model:checked="selectedFireRule.enabled" />
</a-form-item> </a-form-item>
<a-form-item <a-form-item :wrapper-col="{offset: 6}">
:wrapper-col="{offset: 6}"
>
<a-space> <a-space>
<a-button @click="handleSave" type="primary">保存规则</a-button> <a-button @click="handleSave" type="primary">保存规则</a-button>
<a-popconfirm <a-popconfirm
v-if="selectedFireRule && selectedFireRule.id > 0" v-if="selectedFireRule && selectedFireRule.id > 0"
title="确定删除?" title="确定删除?"
@@ -151,112 +163,90 @@
> >
<a-button danger>删除规则</a-button> <a-button danger>删除规则</a-button>
</a-popconfirm> </a-popconfirm>
</a-space> </a-space>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-col> </a-col>
</a-row> </a-row>
</div> </div>
</a-card> </a-card>
</div> </div>
</Layout> </Layout>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref, nextTick } from 'vue'; import { nextTick, onMounted, ref } from 'vue';
import { type FormInstance, message } from 'ant-design-vue'; import { type FormInstance, message } from 'ant-design-vue';
import { MinusCircleOutlined, PlusCircleOutlined, PlusOutlined } from '@ant-design/icons-vue'; import { MinusCircleOutlined, PlusCircleOutlined, PlusOutlined } from '@ant-design/icons-vue';
import Layout from '../layout.vue'; import Layout from '../layout.vue';
import { createFireRule, deleteFireRule, findFireRuleByQuery, updateFireRule } from './api'; import { createFireRule, deleteFireRule, findFireRuleByQuery, updateFireRule } from './api';
import type { FireRule, FireRuleRequest } from './types'; import type { FireRule, FireRulePageableResponse, FireRuleRequest } from './types';
import type { PlatformComponentPayload } from '../types';
import { substring } from '@/utils/strings'; import { substring } from '@/utils/strings';
import PlatformSelect from './PlatformSelect.vue'; import PlatformSelect from './PlatformSelect.vue';
import type { PlatformComponentPayload } from '../types';
const query = ref<Partial<FireRuleRequest>>({ const query = ref<FireRuleRequest>({
id: 0,
name: '',
sceneType: null,
conditions: '',
conditionsArray: [],
actions: '',
actionsArray: [],
priority: 0,
enabled: true,
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
}); });
const defaultPayload: PlatformComponentPayload = {
platform: null,
component: null,
};
const defaultFireRule: FireRule = { const defaultFireRule: FireRule = {
id: 0, id: 0,
// 规则名称 name: '',
name: null,
// 场景类型0-防御1-空降null表示通用
sceneType: null, sceneType: null,
// 触发条件JSON格式 conditions: '',
conditions: null, conditionsArray: [JSON.parse(JSON.stringify(defaultPayload))],
conditionsArray: [ actions: '',
{ actionsArray: [JSON.parse(JSON.stringify(defaultPayload))],
platform: null,
component: null,
}
],
// 响应动作JSON格式
actions: null,
actionsArray: [
{
platform: null,
component: null,
}
],
// 优先级(数值越小优先级越高)
priority: 0, priority: 0,
// 是否启用0禁用1启用
enabled: true, enabled: true,
}; };
const getSceneTypeName = (item: FireRule): string => { const getSceneTypeName = (item: FireRule): string => {
if (0 === item.sceneType) { if (item.sceneType === 0) return '防御';
return '防御'; if (item.sceneType === 1) return '空降';
}
if (1 === item.sceneType) {
return '空降';
}
return '通用'; return '通用';
}; };
const resolveItem = (item: FireRule) => { const resolveItem = (item: FireRule) => {
let newItem: FireRule = JSON.parse(JSON.stringify(item)) as FireRule; const newItem: FireRule = JSON.parse(JSON.stringify(item)) as FireRule;
if (typeof item.conditions === 'string') {
try{ try {
newItem.conditionsArray = JSON.parse(item.conditions as string); newItem.conditionsArray = item.conditions
} catch(e: any){ ? (JSON.parse(item.conditions) as PlatformComponentPayload[])
newItem.conditionsArray = [] : [JSON.parse(JSON.stringify(defaultPayload))];
} } catch (e) {
newItem.conditionsArray = [JSON.parse(JSON.stringify(defaultPayload))];
} }
if(!newItem.conditionsArray) { try {
newItem.conditionsArray = [] newItem.actionsArray = item.actions
} ? (JSON.parse(item.actions) as PlatformComponentPayload[])
if(newItem.conditionsArray.length===0){ : [JSON.parse(JSON.stringify(defaultPayload))];
newItem.conditionsArray.push({ } catch (e) {
platform: null, newItem.actionsArray = [JSON.parse(JSON.stringify(defaultPayload))];
component: null,
})
} }
if (typeof item.actions === 'string') { // 确保数组不为空
try{ if (!Array.isArray(newItem.conditionsArray) || newItem.conditionsArray.length === 0) {
newItem.actionsArray = JSON.parse(item.actions as string); newItem.conditionsArray = [JSON.parse(JSON.stringify(defaultPayload))];
} catch(e: any){
newItem.actionsArray = []
}
} }
if (!Array.isArray(newItem.actionsArray) || newItem.actionsArray.length === 0) {
if(!newItem.actionsArray){ newItem.actionsArray = [JSON.parse(JSON.stringify(defaultPayload))];
newItem.actionsArray = []
}
if(newItem.actionsArray.length===0){
newItem.actionsArray.push({
platform: null,
component: null,
})
} }
return newItem; return newItem;
@@ -264,41 +254,43 @@ const resolveItem = (item: FireRule) => {
const datasource = ref<FireRule[]>([]); const datasource = ref<FireRule[]>([]);
const datasourceTotal = ref<number>(0); const datasourceTotal = ref<number>(0);
const selectedFireRule = ref<FireRule>({...defaultFireRule}); const selectedFireRule = ref<FireRule>(JSON.parse(JSON.stringify(defaultFireRule)));
const formRef = ref<FormInstance | null>(null); const formRef = ref<FormInstance | null>(null);
const load = () => { const load = () => {
datasource.value = []; datasource.value = [];
datasourceTotal.value = 0; datasourceTotal.value = 0;
formRef.value?.resetFields(); if(selectedFireRule.value.id <= 0){
selectedFireRule.value = {...defaultFireRule}; selectedFireRule.value = JSON.parse(JSON.stringify(defaultFireRule));
nextTick(() => {
formRef.value?.resetFields();
});
}
findFireRuleByQuery(query.value).then(r => { findFireRuleByQuery(query.value).then((r: FireRulePageableResponse) => {
datasource.value = r.rows ?? []; datasource.value = r.rows ?? [];
datasourceTotal.value = r.total ?? 0; datasourceTotal.value = r.total ?? 0;
}); });
}; };
const handleCreate = () => { const handleCreate = () => {
selectedFireRule.value = {...defaultFireRule}; formRef.value?.resetFields();
selectedFireRule.value = JSON.parse(JSON.stringify(defaultFireRule));
}; };
const handleSelect = (item: FireRule) => { const handleSelect = (item: FireRule) => {
// 1. 先重置表单
formRef.value?.resetFields(); formRef.value?.resetFields();
// 2. 再赋值使用nextTick确保DOM更新完成
nextTick(() => { nextTick(() => {
selectedFireRule.value = resolveItem(item); selectedFireRule.value = resolveItem(item);
}); });
}; };
const handleDelete = () => { const handleDelete = () => {
if (selectedFireRule.value && selectedFireRule.value.id > 0) { if (selectedFireRule.value?.id > 0) {
deleteFireRule(selectedFireRule.value.id).then(r => { deleteFireRule(selectedFireRule.value.id).then(r => {
if (r.code === 200) { if (r.code === 200) {
load(); load();
message.info(r.msg ?? '删除成功'); message.success(r.msg ?? '删除成功');
} else { } else {
message.error(r.msg ?? '删除失败'); message.error(r.msg ?? '删除失败');
} }
@@ -307,91 +299,90 @@ const handleDelete = () => {
}; };
const handleSave = () => { const handleSave = () => {
if (formRef.value) { formRef.value?.validate().then(() => {
formRef.value.validate().then(() => { const savedValue: FireRule = JSON.parse(JSON.stringify(selectedFireRule.value));
let res = null;
let savedValue: FireRule = JSON.parse(JSON.stringify(selectedFireRule.value)) as any as FireRule; savedValue.conditions = JSON.stringify(savedValue.conditionsArray);
savedValue.conditions = JSON.stringify(savedValue.conditionsArray ?? null) as string; savedValue.actions = JSON.stringify(savedValue.actionsArray);
savedValue.actions = JSON.stringify(savedValue.actionsArray ?? null) as string;
if (savedValue.id > 0) { const request = savedValue.id > 0
res = updateFireRule(savedValue); ? updateFireRule(savedValue)
: createFireRule(savedValue);
request.then(r => {
if (r.code === 200) {
load();
message.success(r.msg ?? '操作成功');
} else { } else {
res = createFireRule(savedValue); message.error(r.msg ?? '操作失败');
}
if (res) {
res.then(r => {
if (r.code === 200) {
load();
message.info(r.msg ?? '操作成功');
} else {
message.error(r.msg ?? '操作失败');
}
});
} }
}).catch(err => {
message.error('请求失败:' + err.message);
}); });
}).catch(err => {
message.error('表单验证失败:' + err.message);
});
};
const handleUpdateCondition = (payload: PlatformComponentPayload, index: number) => {
if (selectedFireRule.value && selectedFireRule.value.conditionsArray[index]) {
const newArray = [...selectedFireRule.value.conditionsArray];
newArray[index] = {
platform: payload.platform,
component: payload.component,
};
selectedFireRule.value.conditionsArray = newArray;
} }
}; };
const handleUpdateAction = (payload: PlatformComponentPayload, index: number) => {
if (selectedFireRule.value && selectedFireRule.value.actionsArray[index]) {
const newArray = [...selectedFireRule.value.actionsArray];
newArray[index] = {
platform: payload.platform,
component: payload.component,
};
selectedFireRule.value.actionsArray = newArray;
}
};
// 添加触发条件
const handleAddCondition = () => {
if (selectedFireRule.value) {
selectedFireRule.value.conditionsArray.push(JSON.parse(JSON.stringify(defaultPayload)));
}
};
// 删除触发条件
const handleMinusCondition = (index: number) => { const handleMinusCondition = (index: number) => {
if(selectedFireRule.value){ if (!selectedFireRule.value) return;
const paramList = selectedFireRule.value.conditionsArray; const list = [...selectedFireRule.value.conditionsArray];
if (index === 0 && selectedFireRule.value.conditionsArray.length === 1) { if (list.length <= 1) {
selectedFireRule.value.conditionsArray = [{ selectedFireRule.value.conditionsArray = [JSON.parse(JSON.stringify(defaultPayload))];
platform: null, } else {
component: null, list.splice(index, 1);
}]; selectedFireRule.value.conditionsArray = list;
} else if (index >= 0 && index < paramList.length && paramList.length > 1) {
paramList.splice(index, 1);
selectedFireRule.value.conditionsArray = [...paramList];
}
} }
} };
const handleAddCondition = (index: number)=> { // 添加响应动作
if(selectedFireRule.value){ const handleAddAction = () => {
selectedFireRule.value.conditionsArray.push({ if (selectedFireRule.value) {
platform: null, selectedFireRule.value.actionsArray.push(JSON.parse(JSON.stringify(defaultPayload)));
component: null,
})
} }
} };
// 删除响应动作
const handleMinusAction = (index: number) => { const handleMinusAction = (index: number) => {
if(selectedFireRule.value){ if (!selectedFireRule.value) return;
const paramList = selectedFireRule.value.actionsArray; const list = [...selectedFireRule.value.actionsArray];
if (index === 0 && selectedFireRule.value.actionsArray.length === 1) { if (list.length <= 1) {
selectedFireRule.value.actionsArray = [{ selectedFireRule.value.actionsArray = [JSON.parse(JSON.stringify(defaultPayload))];
platform: null, } else {
component: null, list.splice(index, 1);
}]; selectedFireRule.value.actionsArray = list;
} else if (index >= 0 && index < paramList.length && paramList.length > 1) {
paramList.splice(index, 1);
selectedFireRule.value.actionsArray = [...paramList];
}
} }
} };
const handleAddAction = (_index: number)=> {
if(selectedFireRule.value){
selectedFireRule.value.actionsArray.push({
platform: null,
component: null,
})
}
}
const handleUpdateCondition = (payload: PlatformComponentPayload, index: number)=> {
console.error('handleUpdateCondition', payload)
if(selectedFireRule.value && selectedFireRule.value.conditionsArray[index]){
selectedFireRule.value.conditionsArray[index] = payload;
}
}
const handleUpdateAction = (payload: PlatformComponentPayload, index: number)=> {
if(selectedFireRule.value && selectedFireRule.value.actionsArray[index]){
selectedFireRule.value.actionsArray[index] = payload;
}
}
const handleChange = (page: number, pageSize: number) => { const handleChange = (page: number, pageSize: number) => {
query.value.pageNum = page; query.value.pageNum = page;
@@ -400,5 +391,4 @@ const handleChange = (page: number, pageSize: number) => {
}; };
onMounted(() => load()); onMounted(() => load());
</script> </script>