diff --git a/modeler/src/views/decision/communication/api.ts b/modeler/src/views/decision/communication/api.ts index 9bb20a1..9f41d12 100644 --- a/modeler/src/views/decision/communication/api.ts +++ b/modeler/src/views/decision/communication/api.ts @@ -8,7 +8,8 @@ */ import { HttpRequestClient } from '@/utils/request'; -import type { PlatformWithComponentsResponse, ScenarioPageableResponse, ScenarioRequest, Scenario } from './types'; +import type { Scenario, ScenarioPageableResponse, ScenarioRequest } from './types'; +import type { PlatformWithComponentsResponse } from '../types'; import type { BasicResponse } from '@/types'; const req = HttpRequestClient.create({ diff --git a/modeler/src/views/decision/communication/nodes-card.vue b/modeler/src/views/decision/communication/nodes-card.vue index 745febd..da5ebc1 100644 --- a/modeler/src/views/decision/communication/nodes-card.vue +++ b/modeler/src/views/decision/communication/nodes-card.vue @@ -27,10 +27,11 @@ \ No newline at end of file diff --git a/modeler/src/views/decision/rule/api.ts b/modeler/src/views/decision/rule/api.ts index 30b1d34..d7d2ae3 100644 --- a/modeler/src/views/decision/rule/api.ts +++ b/modeler/src/views/decision/rule/api.ts @@ -9,6 +9,7 @@ import { HttpRequestClient } from '@/utils/request'; import type { FireRule, FireRulePageableResponse, FireRuleRequest } from './types'; +import type { PlatformWithComponentsResponse } from '../types'; import type { BasicResponse } from '@/types'; const req = HttpRequestClient.create({ @@ -31,5 +32,8 @@ export const deleteFireRule = (id: number): Promise => { return req.delete(`/system/rule/${id}`); }; +export const findAllPlatformWithComponents = (): Promise => { + return req.get(`/system/firerule/platforms`); +}; \ No newline at end of file diff --git a/modeler/src/views/decision/rule/management.vue b/modeler/src/views/decision/rule/management.vue index ab2d29a..24cca0b 100644 --- a/modeler/src/views/decision/rule/management.vue +++ b/modeler/src/views/decision/rule/management.vue @@ -75,18 +75,52 @@ - + +
+
+ + + + + + + + + + + +
+
+
- + +
+
+ + + + + + + + + + + +
+
+
import { onMounted, ref } from 'vue'; import { type FormInstance, message } from 'ant-design-vue'; -import { PlusOutlined } from '@ant-design/icons-vue'; +import { MinusCircleOutlined, PlusCircleOutlined, PlusOutlined } from '@ant-design/icons-vue'; import Layout from '../layout.vue'; import { createFireRule, deleteFireRule, findFireRuleByQuery, updateFireRule } from './api'; import type { FireRule, FireRuleRequest } from './types'; import { substring } from '@/utils/strings'; +import PlatformSelect from './PlatformSelect.vue'; +import type { PlatformComponentPayload } from '../types'; const query = ref>({ pageNum: 1, @@ -155,8 +191,20 @@ const defaultFireRule: FireRule = { sceneType: null, // 触发条件(JSON格式) conditions: null, + conditionsArray: [ + { + platform: null, + component: null, + } + ], // 响应动作(JSON格式) actions: null, + actionsArray: [ + { + platform: null, + component: null, + } + ], // 优先级(数值越小优先级越高) priority: 0, // 是否启用(0禁用,1启用) @@ -174,20 +222,47 @@ const getSceneTypeName = (item: FireRule): string => { }; const resolveItem = (item: FireRule) => { - let newItem = JSON.parse(JSON.stringify(item)); + let newItem = JSON.parse(JSON.stringify(item)) as FireRule; + try{ + newItem.conditionsArray = JSON.parse(newItem.conditions as string); + } catch(e: any){ + } + if(!newItem.conditionsArray) { + newItem.conditionsArray = [] + } + if(newItem.conditionsArray.length===0){ + newItem.conditionsArray.push({ + platform: null, + component: null, + }) + } + + try{ + newItem.actionsArray = JSON.parse(newItem.actions as string); + } catch(e: any){ + } + if(!newItem.actionsArray){ + newItem.actionsArray = [] + } + if(newItem.actionsArray.length===0){ + newItem.actionsArray.push({ + platform: null, + component: null, + }) + } return newItem; }; const datasource = ref([]); const datasourceTotal = ref(0); -const selectedFireRule = ref(resolveItem(defaultFireRule)); +const selectedFireRule = ref({...defaultFireRule}); const formRef = ref(null); const load = () => { datasource.value = []; datasourceTotal.value = 0; formRef.value?.resetFields(); - selectedFireRule.value = resolveItem(defaultFireRule); + selectedFireRule.value = {...defaultFireRule}; findFireRuleByQuery(query.value).then(r => { datasource.value = r.rows ?? []; @@ -197,7 +272,7 @@ const load = () => { const handleCreate = () => { - selectedFireRule.value = resolveItem(defaultFireRule); + selectedFireRule.value = {...defaultFireRule}; }; const handleSelect = (item: FireRule) => { @@ -223,6 +298,8 @@ const handleSave = () => { formRef.value.validate().then(() => { let res = null; let savedValue: FireRule = JSON.parse(JSON.stringify(selectedFireRule.value)) as any as FireRule; + savedValue.conditions = JSON.stringify(savedValue.conditionsArray ?? null) as string; + savedValue.actions = JSON.stringify(savedValue.actionsArray ?? null) as string; if (savedValue.id > 0) { res = updateFireRule(savedValue); } else { @@ -242,6 +319,65 @@ const handleSave = () => { } }; +const handleMinusCondition = (index: number) => { + if(selectedFireRule.value){ + const paramList = selectedFireRule.value.conditionsArray; + if (index === 0 && selectedFireRule.value.conditionsArray.length === 1) { + selectedFireRule.value.conditionsArray = [{ + platform: null, + component: null, + }]; + } 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){ + selectedFireRule.value.conditionsArray.push({ + platform: null, + component: null, + }) + } +} + +const handleMinusAction = (index: number) => { + if(selectedFireRule.value){ + const paramList = selectedFireRule.value.actionsArray; + if (index === 0 && selectedFireRule.value.actionsArray.length === 1) { + selectedFireRule.value.actionsArray = [{ + platform: null, + component: null, + }]; + } 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)=> { + 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) => { query.value.pageNum = page; diff --git a/modeler/src/views/decision/rule/types.ts b/modeler/src/views/decision/rule/types.ts index 37c80a1..721326b 100644 --- a/modeler/src/views/decision/rule/types.ts +++ b/modeler/src/views/decision/rule/types.ts @@ -8,6 +8,7 @@ */ import type { NullableString, PageableResponse } from '@/types'; +import type { PlatformComponentPayload } from '../types'; export interface FireRule { id: number, @@ -17,8 +18,10 @@ export interface FireRule { sceneType: Number | null, // 触发条件(JSON格式) conditions: NullableString, - // 响应动作(JSON格式) - actions: NullableString, + conditionsArray: PlatformComponentPayload[], + // 响应动作(JSON格式) + actions: NullableString, + actionsArray: PlatformComponentPayload[], // 优先级(数值越小优先级越高) priority: number, // 是否启用(0禁用,1启用) diff --git a/modeler/src/views/decision/types/index.ts b/modeler/src/views/decision/types/index.ts new file mode 100644 index 0000000..0a425d0 --- /dev/null +++ b/modeler/src/views/decision/types/index.ts @@ -0,0 +1,10 @@ +/* + * This file is part of the kernelstudio package. + * + * (c) 2014-2026 zlin + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +export * from './platform' \ No newline at end of file diff --git a/modeler/src/views/decision/types/platform.ts b/modeler/src/views/decision/types/platform.ts new file mode 100644 index 0000000..02707a5 --- /dev/null +++ b/modeler/src/views/decision/types/platform.ts @@ -0,0 +1,40 @@ +/* + * This file is part of the kernelstudio package. + * + * (c) 2014-2026 zlin + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +import type { ApiDataResponse, NullableString } from '@/types'; + +export interface Platform { + id: number, + name: NullableString, + description: NullableString, + scenarioId: number, + + [key: string]: unknown; +} + +export interface PlatformComponent { + id: number, + name: NullableString, + type: NullableString, + description: NullableString, + platformId: number, +} + +export interface PlatformWithComponents extends Platform { + components: PlatformComponent[], +} + +export interface PlatformComponentPayload { + platform: Platform | null; + component: PlatformComponent | null; +} + +export interface PlatformWithComponentsResponse extends ApiDataResponse { + +}