Merge branch 'master' of http://101.43.238.71:3000/zouju/auto-solution
This commit is contained in:
@@ -59,10 +59,15 @@ public class FireRuleController extends BaseController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/platforms/{scenarioId}")
|
@GetMapping("/platforms/{scenarioId}")
|
||||||
public AjaxResult platforms(@PathVariable Integer scenarioId){
|
public AjaxResult platformsScenarioId(@PathVariable Integer scenarioId){
|
||||||
return success(ruleService.findPlatformComponents(scenarioId));
|
return success(ruleService.findPlatformComponents(scenarioId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/platforms")
|
||||||
|
public AjaxResult platforms(){
|
||||||
|
return success(ruleService.findAllPlatformComponents());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据平台id获取平台下所有组件
|
* 根据平台id获取平台下所有组件
|
||||||
* @param platformId
|
* @param platformId
|
||||||
|
|||||||
@@ -42,4 +42,6 @@ public interface FireRuleMapper {
|
|||||||
List<PlatformComponent> getComponents(Integer platformId);
|
List<PlatformComponent> getComponents(Integer platformId);
|
||||||
|
|
||||||
List<Platform> findPlatformComponents(Integer scenarioId);
|
List<Platform> findPlatformComponents(Integer scenarioId);
|
||||||
|
|
||||||
|
List<Platform> findAllPlatformComponents();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,4 +45,6 @@ public interface FireRuleService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Platform> findPlatformComponents(Integer scenarioId);
|
List<Platform> findPlatformComponents(Integer scenarioId);
|
||||||
|
|
||||||
|
List<Platform> findAllPlatformComponents();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,4 +176,9 @@ public class FireRuleServiceImpl implements FireRuleService {
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Platform> findAllPlatformComponents() {
|
||||||
|
return ruleMapper.findAllPlatformComponents();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,4 +118,9 @@
|
|||||||
ORDER BY p.name
|
ORDER BY p.name
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="findAllPlatformComponents" resultMap="VPlatformMap">
|
||||||
|
SELECT *
|
||||||
|
FROM platform
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -18,6 +18,12 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.solution</groupId>
|
||||||
|
<artifactId>solution-rule</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 通用工具-->
|
<!-- 通用工具-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.solution</groupId>
|
<groupId>com.solution</groupId>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.solution.common.core.domain.AjaxResult;
|
|||||||
import com.solution.common.core.page.TableDataInfo;
|
import com.solution.common.core.page.TableDataInfo;
|
||||||
import com.solution.common.enums.BusinessType;
|
import com.solution.common.enums.BusinessType;
|
||||||
import com.solution.scene.domain.AfsimScenario;
|
import com.solution.scene.domain.AfsimScenario;
|
||||||
|
import com.solution.scene.domain.AfsimScenarioForm;
|
||||||
import com.solution.scene.service.SceneService;
|
import com.solution.scene.service.SceneService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -32,7 +33,7 @@ public class SceneController extends BaseController {
|
|||||||
@ApiOperation("保存场景配置")
|
@ApiOperation("保存场景配置")
|
||||||
@PostMapping("/saveSceneConfig")
|
@PostMapping("/saveSceneConfig")
|
||||||
@Log(title = "行为树主", businessType = BusinessType.INSERT)
|
@Log(title = "行为树主", businessType = BusinessType.INSERT)
|
||||||
public AjaxResult saveSceneConfig(@RequestBody AfsimScenario afsimScenario)
|
public AjaxResult saveSceneConfig(@RequestBody AfsimScenarioForm afsimScenario)
|
||||||
{
|
{
|
||||||
return toAjax(sceneService.saveOrUpdate(afsimScenario));
|
return toAjax(sceneService.saveOrUpdate(afsimScenario));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.solution.scene.domain;
|
||||||
|
/*
|
||||||
|
* This file is part of the kernelstudio package.
|
||||||
|
*
|
||||||
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
|
* that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AfsimScenarioForm extends AfsimScenario {
|
||||||
|
|
||||||
|
private List<ScenarioRelation> relations;
|
||||||
|
|
||||||
|
public List<ScenarioRelation> getRelations() {
|
||||||
|
return relations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelations(List<ScenarioRelation> relations) {
|
||||||
|
this.relations = relations;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package com.solution.scene.domain;
|
||||||
|
/*
|
||||||
|
* This file is part of the kernelstudio package.
|
||||||
|
*
|
||||||
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
|
* that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.solution.rule.domain.Platform;
|
||||||
|
import com.solution.rule.domain.PlatformComponent;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class ScenarioRelation implements Serializable {
|
||||||
|
|
||||||
|
private String edgeId;
|
||||||
|
|
||||||
|
private String sourceId;
|
||||||
|
|
||||||
|
private String sourcePort;
|
||||||
|
|
||||||
|
private Platform sourcePlatform;
|
||||||
|
|
||||||
|
private PlatformComponent sourceComponent;
|
||||||
|
|
||||||
|
private String targetId;
|
||||||
|
|
||||||
|
private String targetPort;
|
||||||
|
|
||||||
|
private Platform targetPlatform;
|
||||||
|
|
||||||
|
private PlatformComponent targetComponent;
|
||||||
|
|
||||||
|
public String getEdgeId() {
|
||||||
|
return edgeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEdgeId(String edgeId) {
|
||||||
|
this.edgeId = edgeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSourceId() {
|
||||||
|
return sourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceId(String sourceId) {
|
||||||
|
this.sourceId = sourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSourcePort() {
|
||||||
|
return sourcePort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourcePort(String sourcePort) {
|
||||||
|
this.sourcePort = sourcePort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Platform getSourcePlatform() {
|
||||||
|
return sourcePlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourcePlatform(Platform sourcePlatform) {
|
||||||
|
this.sourcePlatform = sourcePlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlatformComponent getSourceComponent() {
|
||||||
|
return sourceComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceComponent(PlatformComponent sourceComponent) {
|
||||||
|
this.sourceComponent = sourceComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetId() {
|
||||||
|
return targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetId(String targetId) {
|
||||||
|
this.targetId = targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetPort() {
|
||||||
|
return targetPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetPort(String targetPort) {
|
||||||
|
this.targetPort = targetPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Platform getTargetPlatform() {
|
||||||
|
return targetPlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetPlatform(Platform targetPlatform) {
|
||||||
|
this.targetPlatform = targetPlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlatformComponent getTargetComponent() {
|
||||||
|
return targetComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetComponent(PlatformComponent targetComponent) {
|
||||||
|
this.targetComponent = targetComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.solution.scene.mapper;
|
package com.solution.scene.mapper;
|
||||||
|
|
||||||
import com.solution.scene.domain.AfsimScenario;
|
import com.solution.scene.domain.AfsimScenario;
|
||||||
|
import com.solution.scene.domain.AfsimScenarioForm;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,9 +14,9 @@ public interface SceneMapper {
|
|||||||
* @param afsimScenario
|
* @param afsimScenario
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int insert(AfsimScenario afsimScenario);
|
int insert(AfsimScenarioForm afsimScenario);
|
||||||
|
|
||||||
int update(AfsimScenario afsimScenario);
|
int update(AfsimScenarioForm afsimScenario);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.solution.scene.service;
|
package com.solution.scene.service;
|
||||||
|
|
||||||
import com.solution.scene.domain.AfsimScenario;
|
import com.solution.scene.domain.AfsimScenario;
|
||||||
|
import com.solution.scene.domain.AfsimScenarioForm;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -11,11 +12,11 @@ public interface SceneService {
|
|||||||
* @param afsimScenario
|
* @param afsimScenario
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int insert(AfsimScenario afsimScenario);
|
int insert(AfsimScenarioForm afsimScenario);
|
||||||
|
|
||||||
int update(AfsimScenario afsimScenario);
|
int update(AfsimScenarioForm afsimScenario);
|
||||||
|
|
||||||
int saveOrUpdate(AfsimScenario afsimScenario);
|
int saveOrUpdate(AfsimScenarioForm afsimScenario);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取场景列表
|
* 获取场景列表
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.solution.scene.service.impl;
|
package com.solution.scene.service.impl;
|
||||||
|
|
||||||
import com.solution.scene.domain.AfsimScenario;
|
import com.solution.scene.domain.AfsimScenario;
|
||||||
|
import com.solution.scene.domain.AfsimScenarioForm;
|
||||||
import com.solution.scene.mapper.SceneMapper;
|
import com.solution.scene.mapper.SceneMapper;
|
||||||
import com.solution.scene.service.SceneService;
|
import com.solution.scene.service.SceneService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -16,17 +17,17 @@ public class SceneServiceImpl implements SceneService {
|
|||||||
private SceneMapper sceneMapper;
|
private SceneMapper sceneMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insert(AfsimScenario afsimScenario) {
|
public int insert(AfsimScenarioForm afsimScenario) {
|
||||||
return sceneMapper.insert(afsimScenario);
|
return sceneMapper.insert(afsimScenario);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(AfsimScenario afsimScenario) {
|
public int update(AfsimScenarioForm afsimScenario) {
|
||||||
return sceneMapper.update(afsimScenario);
|
return sceneMapper.update(afsimScenario);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int saveOrUpdate(AfsimScenario afsimScenario) {
|
public int saveOrUpdate(AfsimScenarioForm afsimScenario) {
|
||||||
if (null != afsimScenario.getId() && afsimScenario.getId() > 0) {
|
if (null != afsimScenario.getId() && afsimScenario.getId() > 0) {
|
||||||
return sceneMapper.update(afsimScenario);
|
return sceneMapper.update(afsimScenario);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { HttpRequestClient } from '@/utils/request';
|
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';
|
import type { BasicResponse } from '@/types';
|
||||||
|
|
||||||
const req = HttpRequestClient.create<BasicResponse>({
|
const req = HttpRequestClient.create<BasicResponse>({
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ import { createGraphScenarioElement, createGraphTaskElementFromScenario } from '
|
|||||||
import PlatformCard from './platform-card.vue';
|
import PlatformCard from './platform-card.vue';
|
||||||
import NodesCard from './nodes-card.vue';
|
import NodesCard from './nodes-card.vue';
|
||||||
import { saveScenario } from './api';
|
import { saveScenario } from './api';
|
||||||
|
import {resolveConnectionRelation} from './relation'
|
||||||
|
|
||||||
const TeleportContainer = defineComponent(getTeleport());
|
const TeleportContainer = defineComponent(getTeleport());
|
||||||
|
|
||||||
@@ -194,7 +195,6 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSelect = (scenario: Scenario) => {
|
const handleSelect = (scenario: Scenario) => {
|
||||||
console.info('handleSelect', scenario);
|
|
||||||
let nodeGraph: GraphContainer | null = null;
|
let nodeGraph: GraphContainer | null = null;
|
||||||
try {
|
try {
|
||||||
nodeGraph = JSON.parse(scenario.communicationGraph as unknown as string) as unknown as GraphContainer;
|
nodeGraph = JSON.parse(scenario.communicationGraph as unknown as string) as unknown as GraphContainer;
|
||||||
@@ -210,10 +210,10 @@ export default defineComponent({
|
|||||||
currentScenario.value = {
|
currentScenario.value = {
|
||||||
...scenario,
|
...scenario,
|
||||||
graph: nodeGraph,
|
graph: nodeGraph,
|
||||||
|
relations: []
|
||||||
};
|
};
|
||||||
currentScenarioEditing.value = true;
|
currentScenarioEditing.value = true;
|
||||||
createElements();
|
createElements();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const createElements = () => {
|
const createElements = () => {
|
||||||
@@ -228,7 +228,6 @@ export default defineComponent({
|
|||||||
if (currentScenario.value?.graph.nodes) {
|
if (currentScenario.value?.graph.nodes) {
|
||||||
currentScenario.value?.graph.nodes.forEach(ele => {
|
currentScenario.value?.graph.nodes.forEach(ele => {
|
||||||
const node = createGraphScenarioElement(ele as GraphTaskElement);
|
const node = createGraphScenarioElement(ele as GraphTaskElement);
|
||||||
console.info('create node: ', ele);
|
|
||||||
// 将节点添加到画布
|
// 将节点添加到画布
|
||||||
graph.value?.addNode(node as Node);
|
graph.value?.addNode(node as Node);
|
||||||
});
|
});
|
||||||
@@ -255,10 +254,11 @@ export default defineComponent({
|
|||||||
name: null,
|
name: null,
|
||||||
description: null,
|
description: null,
|
||||||
communicationGraph: null,
|
communicationGraph: null,
|
||||||
|
relations: [],
|
||||||
graph: {
|
graph: {
|
||||||
edges: [],
|
edges: [],
|
||||||
nodes: [],
|
nodes: [],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
currentGraph.value = {
|
currentGraph.value = {
|
||||||
edges: [],
|
edges: [],
|
||||||
@@ -341,6 +341,10 @@ export default defineComponent({
|
|||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
const graphData: GraphContainer = resolveGraph(graph.value as Graph);
|
const graphData: GraphContainer = resolveGraph(graph.value as Graph);
|
||||||
|
|
||||||
|
const relations = resolveConnectionRelation(graph.value as Graph);
|
||||||
|
console.error('relations',relations)
|
||||||
|
|
||||||
console.info('handleSave', graphData);
|
console.info('handleSave', graphData);
|
||||||
if (!currentScenario.value) {
|
if (!currentScenario.value) {
|
||||||
message.error('当前决策树不存在');
|
message.error('当前决策树不存在');
|
||||||
@@ -350,6 +354,7 @@ export default defineComponent({
|
|||||||
...currentScenario.value,
|
...currentScenario.value,
|
||||||
graph: graphData,
|
graph: graphData,
|
||||||
communicationGraph: JSON.stringify(graphData),
|
communicationGraph: JSON.stringify(graphData),
|
||||||
|
relations: relations
|
||||||
};
|
};
|
||||||
if (!newScenario.name) {
|
if (!newScenario.name) {
|
||||||
message.error('场景名称不能为空.');
|
message.error('场景名称不能为空.');
|
||||||
|
|||||||
@@ -23,9 +23,11 @@
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
:data-port="`in-${item.id || index}`"
|
:data-port="`in-${item.id || index}`"
|
||||||
|
:port="`in-${item.id || index}`"
|
||||||
:title="`入桩: ${item.name}`"
|
:title="`入桩: ${item.name}`"
|
||||||
class="port port-in"
|
class="port port-in"
|
||||||
magnet="passive"
|
magnet="passive"
|
||||||
|
:data-item="JSON.stringify(item)"
|
||||||
>
|
>
|
||||||
<div class="triangle-left"></div>
|
<div class="triangle-left"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -38,9 +40,11 @@
|
|||||||
<!-- 右侧出桩:只能作为连线源 -->
|
<!-- 右侧出桩:只能作为连线源 -->
|
||||||
<div
|
<div
|
||||||
:data-port="`out-${item.id || index}`"
|
:data-port="`out-${item.id || index}`"
|
||||||
|
:port="`out-${item.id || index}`"
|
||||||
:title="`出桩: ${item.name}`"
|
:title="`出桩: ${item.name}`"
|
||||||
class="port port-out"
|
class="port port-out"
|
||||||
magnet="active"
|
magnet="active"
|
||||||
|
:data-item="JSON.stringify(item)"
|
||||||
>
|
>
|
||||||
<div class="triangle-right" ></div>
|
<div class="triangle-right" ></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -130,7 +134,6 @@ export default defineComponent({
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
_props.node?.on('change:data', handleDataChange);
|
_props.node?.on('change:data', handleDataChange);
|
||||||
console.error('element',element.value)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|||||||
@@ -27,10 +27,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, onMounted, type PropType, ref } from 'vue';
|
import { defineComponent, type PropType, ref, watch } from 'vue';
|
||||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||||
import {findPlatformWithComponents} from './api'
|
import { findPlatformWithComponents } from './api';
|
||||||
import { type PlatformWithComponents, type Scenario } from './types';
|
import { type Scenario } from './types';
|
||||||
|
import { type PlatformWithComponents } from '../types';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
emits: ['drag-item-start', 'drag-item-end'],
|
emits: ['drag-item-start', 'drag-item-end'],
|
||||||
@@ -40,20 +41,13 @@ export default defineComponent({
|
|||||||
required: true,
|
required: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup(_props, { emit }) {
|
setup(props, { emit }) {
|
||||||
|
|
||||||
const activeKey = ref<number>(1);
|
const activeKey = ref<number>(1);
|
||||||
const templateData = ref<PlatformWithComponents[]>([]);
|
const templateData = ref<PlatformWithComponents[]>([]);
|
||||||
const isDraggingOver = ref<boolean>(false);
|
const isDraggingOver = ref<boolean>(false);
|
||||||
const draggedNodeData = ref<PlatformWithComponents | null>(null);
|
const draggedNodeData = ref<PlatformWithComponents | null>(null);
|
||||||
const currentScenario = ref<Scenario|null>(_props.scenario)
|
const currentScenario = ref<Scenario|null>(props.scenario)
|
||||||
|
|
||||||
const loadTress = () => {
|
|
||||||
templateData.value = []
|
|
||||||
findPlatformWithComponents(_props.scenario?.id).then(r => {
|
|
||||||
templateData.value = r.data ?? []
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDragStart = (e: DragEvent, nm: PlatformWithComponents) => {
|
const handleDragStart = (e: DragEvent, nm: PlatformWithComponents) => {
|
||||||
let dragNode: PlatformWithComponents = { ...nm };
|
let dragNode: PlatformWithComponents = { ...nm };
|
||||||
@@ -92,16 +86,17 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const load = ()=> {
|
const load = (id: number)=> {
|
||||||
findPlatformWithComponents(1).then(re=> {
|
findPlatformWithComponents(id).then(re=> {
|
||||||
console.error(re);
|
templateData.value = re.data ?? []
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
watch(()=> props.scenario,(n: Scenario|null|undefined )=> {
|
||||||
loadTress();
|
if(n){
|
||||||
load();
|
load(n.id);
|
||||||
});
|
}
|
||||||
|
}, {deep: true, immediate: true} )
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeKey,
|
activeKey,
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ export default defineComponent({
|
|||||||
findScenarioByQuery(scenarioQuery.value).then(r => {
|
findScenarioByQuery(scenarioQuery.value).then(r => {
|
||||||
scenario.value = r.rows;
|
scenario.value = r.rows;
|
||||||
totalTress.value = r.total ?? 0;
|
totalTress.value = r.total ?? 0;
|
||||||
|
// emit('select', r.rows[0]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
134
modeler/src/views/decision/communication/relation.ts
Normal file
134
modeler/src/views/decision/communication/relation.ts
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the kernelstudio package.
|
||||||
|
*
|
||||||
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
|
* that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Graph, Node,Edge } from '@antv/x6';
|
||||||
|
import type { Platform, PlatformComponent, PlatformRelation } from './types';
|
||||||
|
import type { GraphTaskElement } from '../graph';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析节点端口连接关系(去重版)
|
||||||
|
* @param graph X6 画布实例
|
||||||
|
* @returns 去重后的端口连接关系列表
|
||||||
|
*/
|
||||||
|
export function resolveConnectionRelation(graph: Graph): PlatformRelation[] {
|
||||||
|
const edges: Edge[] = graph.getEdges();
|
||||||
|
const items: PlatformRelation[] = [];
|
||||||
|
const existsKeys: Set<string> = new Set(); // 改用 Set 提升查询性能
|
||||||
|
const tempEdgeIds: Set<string> = new Set(); // 存储临时边 ID
|
||||||
|
|
||||||
|
// 过滤无效/临时边
|
||||||
|
const validEdges = edges.filter(edge => {
|
||||||
|
// 过滤临时边(X6 拖拽连线时生成的未完成边)
|
||||||
|
const isTempEdge = edge?.attr('line/stroke') === 'transparent' || edge.id.includes('temp');
|
||||||
|
if (isTempEdge) {
|
||||||
|
tempEdgeIds.add(edge.id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤未正确关联节点的边
|
||||||
|
const sourceCell = edge.getSourceCell();
|
||||||
|
const targetCell = edge.getTargetCell();
|
||||||
|
if (!sourceCell || !targetCell || !(sourceCell instanceof Node) || !(targetCell instanceof Node)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤端口 ID 为空的边
|
||||||
|
const sourcePortId = edge.getSourcePortId();
|
||||||
|
const targetPortId = edge.getTargetPortId();
|
||||||
|
if (!sourcePortId || !targetPortId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
validEdges.forEach(edge => {
|
||||||
|
try {
|
||||||
|
const sourceCell = edge.getSourceCell() as Node;
|
||||||
|
const targetCell = edge.getTargetCell() as Node;
|
||||||
|
|
||||||
|
const sourcePortId = edge.getSourcePortId()!;
|
||||||
|
const targetPortId = edge.getTargetPortId()!;
|
||||||
|
|
||||||
|
// 1. 获取端口 DOM 元素和数据
|
||||||
|
const sourceView = graph.findViewByCell(sourceCell);
|
||||||
|
const targetView = graph.findViewByCell(targetCell);
|
||||||
|
if (!sourceView || !targetView) return;
|
||||||
|
|
||||||
|
const sourcePortEl = sourceView.container.querySelector(`[data-port="${sourcePortId}"]`);
|
||||||
|
const targetPortEl = targetView.container.querySelector(`[data-port="${targetPortId}"]`);
|
||||||
|
if (!sourcePortEl || !targetPortEl) return;
|
||||||
|
|
||||||
|
// 2. 解析端口数据
|
||||||
|
let sourcePortData: PlatformComponent | null = null;
|
||||||
|
let targetPortData: PlatformComponent | null = null;
|
||||||
|
try {
|
||||||
|
const sourceDataAttr = sourcePortEl.getAttribute('data-item');
|
||||||
|
sourcePortData = sourceDataAttr ? JSON.parse(sourceDataAttr) : null;
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`解析源节点 ${sourceCell.id} 端口 ${sourcePortId} 数据失败`, e);
|
||||||
|
return; // 数据解析失败直接跳过
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const targetDataAttr = targetPortEl.getAttribute('data-item');
|
||||||
|
targetPortData = targetDataAttr ? JSON.parse(targetDataAttr) : null;
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`解析目标节点 ${targetCell.id} 端口 ${targetPortId} 数据失败`, e);
|
||||||
|
return; // 数据解析失败直接跳过
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤端口数据为空的情况
|
||||||
|
if (!sourcePortData || !targetPortData) return;
|
||||||
|
|
||||||
|
// 解析节点平台数据
|
||||||
|
const sourceData = sourceCell.getData() as GraphTaskElement;
|
||||||
|
const targetData = targetCell.getData() as GraphTaskElement;
|
||||||
|
|
||||||
|
// 过滤平台数据不完整的节点
|
||||||
|
if (!sourceData.platformId || !targetData.platformId) return;
|
||||||
|
|
||||||
|
const sourcePlatform: Platform = {
|
||||||
|
id: sourceData.platformId as number,
|
||||||
|
key: sourceData.key,
|
||||||
|
name: sourceData.name,
|
||||||
|
description: sourceData.description,
|
||||||
|
scenarioId: sourceData.scenarioId as number,
|
||||||
|
};
|
||||||
|
|
||||||
|
const targetPlatform: Platform = {
|
||||||
|
id: targetData.platformId as number,
|
||||||
|
key: targetData.key,
|
||||||
|
name: targetData.name,
|
||||||
|
description: targetData.description,
|
||||||
|
scenarioId: targetData.scenarioId as number,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 生成唯一标识(支持单向/双向去重
|
||||||
|
const uniqueKey = `${sourceCell.id}@${sourcePortId}->${targetCell.id}@${targetPortId}`;
|
||||||
|
|
||||||
|
if (!existsKeys.has(uniqueKey)) {
|
||||||
|
existsKeys.add(uniqueKey);
|
||||||
|
items.push({
|
||||||
|
sourceId: sourceCell.id,
|
||||||
|
sourcePort: sourcePortId,
|
||||||
|
sourcePlatform: sourcePlatform,
|
||||||
|
sourceComponent: sourcePortData,
|
||||||
|
targetId: targetCell.id,
|
||||||
|
targetPort: targetPortId,
|
||||||
|
targetPlatform: targetPlatform,
|
||||||
|
targetComponent: targetPortData,
|
||||||
|
edgeId: edge.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`解析边 ${edge.id} 连接关系失败`, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return items;
|
||||||
|
}
|
||||||
@@ -10,6 +10,20 @@
|
|||||||
|
|
||||||
import type { ApiDataResponse, NullableString, PageableResponse } from '@/types';
|
import type { ApiDataResponse, NullableString, PageableResponse } from '@/types';
|
||||||
import type { GraphContainer } from '../graph';
|
import type { GraphContainer } from '../graph';
|
||||||
|
import type { Platform, PlatformComponent } from '../types';
|
||||||
|
|
||||||
|
export interface PlatformRelation {
|
||||||
|
sourceId: NullableString,
|
||||||
|
sourcePort: NullableString,
|
||||||
|
sourcePlatform: Platform,
|
||||||
|
sourceComponent: PlatformComponent,
|
||||||
|
targetId: NullableString,
|
||||||
|
targetPort: NullableString,
|
||||||
|
targetPlatform: Platform,
|
||||||
|
targetComponent: PlatformComponent,
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface Scenario {
|
export interface Scenario {
|
||||||
id: number,
|
id: number,
|
||||||
@@ -18,6 +32,7 @@ export interface Scenario {
|
|||||||
// 用于存储场景中的通讯关系
|
// 用于存储场景中的通讯关系
|
||||||
communicationGraph: NullableString,
|
communicationGraph: NullableString,
|
||||||
graph: GraphContainer
|
graph: GraphContainer
|
||||||
|
relations: PlatformRelation[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScenarioRequest extends Scenario {
|
export interface ScenarioRequest extends Scenario {
|
||||||
@@ -29,25 +44,3 @@ export interface ScenarioPageableResponse extends PageableResponse<Scenario> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Platform {
|
|
||||||
id: number,
|
|
||||||
name: NullableString,
|
|
||||||
description: NullableString,
|
|
||||||
scenarioId: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PlatformComponent {
|
|
||||||
id: number,
|
|
||||||
name: NullableString,
|
|
||||||
type: NullableString,
|
|
||||||
description: NullableString,
|
|
||||||
platformId: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PlatformWithComponents extends Platform {
|
|
||||||
components: PlatformComponent[],
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PlatformWithComponentsResponse extends ApiDataResponse<PlatformWithComponents[]> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -44,6 +44,33 @@ export const createGraphTaskElementFromScenario = (
|
|||||||
} as GraphTaskElement;
|
} as GraphTaskElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const portsGroups = {
|
||||||
|
in: {
|
||||||
|
position: 'left', // 入桩在左侧
|
||||||
|
attrs: {
|
||||||
|
circle: {
|
||||||
|
r: 6,
|
||||||
|
magnet: 'passive', // 被动吸附(仅作为连线目标)
|
||||||
|
stroke: '#5da1df',
|
||||||
|
strokeWidth: 2,
|
||||||
|
fill: '#fff',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
out: {
|
||||||
|
position: 'right', // 出桩在右侧
|
||||||
|
attrs: {
|
||||||
|
circle: {
|
||||||
|
r: 6,
|
||||||
|
magnet: 'active', // 主动吸附(作为连线源)
|
||||||
|
stroke: '#5da1df',
|
||||||
|
strokeWidth: 2,
|
||||||
|
fill: '#5da1df',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const createGraphScenarioElement = (element: GraphTaskElement): any => {
|
export const createGraphScenarioElement = (element: GraphTaskElement): any => {
|
||||||
let realHeight = 120;
|
let realHeight = 120;
|
||||||
let width: number = 250;
|
let width: number = 250;
|
||||||
@@ -58,6 +85,24 @@ export const createGraphScenarioElement = (element: GraphTaskElement): any => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const portsItems = (element.components || []).map((comp, index) => {
|
||||||
|
// const compId = comp.id || index;
|
||||||
|
// return [
|
||||||
|
// // 入桩(对应 DOM: data-port="in-${compId}")
|
||||||
|
// {
|
||||||
|
// id: `in-${compId}`, // portId 必须和 DOM 的 data-port 一致
|
||||||
|
// group: 'in',
|
||||||
|
// data: comp, // 直接存储 port 数据,避免后续解析 DOM
|
||||||
|
// },
|
||||||
|
// // 出桩(对应 DOM: data-port="out-${compId}")
|
||||||
|
// {
|
||||||
|
// id: `out-${compId}`,
|
||||||
|
// group: 'out',
|
||||||
|
// data: comp,
|
||||||
|
// },
|
||||||
|
// ];
|
||||||
|
// }).flat(); // 扁平化数组
|
||||||
|
|
||||||
return {
|
return {
|
||||||
shape: 'scenario',
|
shape: 'scenario',
|
||||||
id: element.key,
|
id: element.key,
|
||||||
@@ -75,5 +120,9 @@ export const createGraphScenarioElement = (element: GraphTaskElement): any => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: element,
|
data: element,
|
||||||
|
// ports: {
|
||||||
|
// groups: portsGroups,
|
||||||
|
// items: portsItems,
|
||||||
|
// },
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -58,7 +58,7 @@ export const createGraphConnectingAttributes = (): Partial<Connecting> => {
|
|||||||
...lineOptions.attrs?.line,
|
...lineOptions.attrs?.line,
|
||||||
targetMarker: null,
|
targetMarker: null,
|
||||||
sourceMarker: null,
|
sourceMarker: null,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
animation: lineOptions.animation,
|
animation: lineOptions.animation,
|
||||||
markup: lineOptions.markup,
|
markup: lineOptions.markup,
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export interface GraphBaseElement {
|
|||||||
position: GraphPosition;
|
position: GraphPosition;
|
||||||
category: NullableString;
|
category: NullableString;
|
||||||
element?: GraphDraggableElement;
|
element?: GraphDraggableElement;
|
||||||
components?: GraphComponentElement[]
|
components?: GraphComponentElement[];
|
||||||
|
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ export const useGraphCanvas = (readonly: boolean = false): UseGraphCanvas => {
|
|||||||
|
|
||||||
const createCanvas = (c: HTMLDivElement): Graph => {
|
const createCanvas = (c: HTMLDivElement): Graph => {
|
||||||
container.value = c;
|
container.value = c;
|
||||||
|
|
||||||
graph.value = createGraphCanvas(c, readonly);
|
graph.value = createGraphCanvas(c, readonly);
|
||||||
initEvents();
|
initEvents();
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@
|
|||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './line'
|
export * from './line';
|
||||||
export * from './ports'
|
export * from './ports';
|
||||||
export * from './element'
|
export * from './element';
|
||||||
export * from './canvas'
|
export * from './canvas';
|
||||||
export * from './hooks'
|
export * from './hooks';
|
||||||
export * from './props'
|
export * from './props';
|
||||||
export * from './utils'
|
export * from './utils';
|
||||||
@@ -74,8 +74,10 @@ export const resolveGraphEdgeElements = (graph: Graph): GraphEdgeElement[] => {
|
|||||||
key: edge.id,
|
key: edge.id,
|
||||||
type: 'edge',
|
type: 'edge',
|
||||||
status: nodeData?.status,
|
status: nodeData?.status,
|
||||||
|
sourcePort: edge.getSourcePortId(),
|
||||||
source: edge.getSource() ? edge.getSource() as unknown as string : null,
|
source: edge.getSource() ? edge.getSource() as unknown as string : null,
|
||||||
target: edge.getSource() ? edge.getTarget() as unknown as string : null,
|
target: edge.getSource() ? edge.getTarget() as unknown as string : null,
|
||||||
|
targetPort: edge.getTargetPortId(),
|
||||||
attrs: edge.getAttrs() ?? {},
|
attrs: edge.getAttrs() ?? {},
|
||||||
router: edge.getRouter() ?? {},
|
router: edge.getRouter() ?? {},
|
||||||
connector: edge.getConnector() ?? null,
|
connector: edge.getConnector() ?? null,
|
||||||
|
|||||||
168
modeler/src/views/decision/rule/PlatformSelect.vue
Normal file
168
modeler/src/views/decision/rule/PlatformSelect.vue
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
<template>
|
||||||
|
<a-space>
|
||||||
|
<!-- 平台选择框 -->
|
||||||
|
<a-select
|
||||||
|
style="width:280px"
|
||||||
|
v-model:value="selectedPlatformId"
|
||||||
|
:placeholder="'请选择平台'"
|
||||||
|
>
|
||||||
|
<a-select-option
|
||||||
|
v-for="item in platforms"
|
||||||
|
:key="item.id"
|
||||||
|
:value="item.id"
|
||||||
|
>
|
||||||
|
{{ item.description || item.name || '未命名平台' }}
|
||||||
|
</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
|
||||||
|
<!-- 组件选择框 -->
|
||||||
|
<a-select
|
||||||
|
style="width:280px;"
|
||||||
|
v-model:value="selectedComponentId"
|
||||||
|
:placeholder="'请选择组件'"
|
||||||
|
:disabled="!selectedPlatform"
|
||||||
|
>
|
||||||
|
<a-select-option
|
||||||
|
v-for="item in selectedPlatformComponents"
|
||||||
|
:key="item.id"
|
||||||
|
:value="item.id"
|
||||||
|
>
|
||||||
|
{{ item.description || item.name || '未命名组件' }}
|
||||||
|
</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
</a-space>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { computed, defineComponent, onMounted, type PropType, ref, watch } from 'vue';
|
||||||
|
import type { Platform, PlatformComponent, PlatformComponentPayload, PlatformWithComponents } from '../types';
|
||||||
|
import { findAllPlatformWithComponents } from './api';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
props: {
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
type: [Object,null] as PropType<PlatformComponentPayload | null>,
|
||||||
|
required: false,
|
||||||
|
default: ({
|
||||||
|
platform: null,
|
||||||
|
component: null,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: [
|
||||||
|
'change',
|
||||||
|
],
|
||||||
|
setup(props, { emit }) {
|
||||||
|
const platforms = ref<PlatformWithComponents[]>([]);
|
||||||
|
const platformMapping = ref<Map<number, PlatformWithComponents>>(new Map());
|
||||||
|
const componentsMapping = ref<Map<number, PlatformComponent>>(new Map());
|
||||||
|
|
||||||
|
const selectedPlatformComponents = ref<PlatformComponent[]>([])
|
||||||
|
|
||||||
|
const selectedPlatform = ref<PlatformWithComponents|null>(null);
|
||||||
|
const selectedPlatformId = ref<number|null>(null);
|
||||||
|
|
||||||
|
const selectedComponent = ref<PlatformComponent|null>(null);
|
||||||
|
const selectedComponentId = ref<number|null>(null);
|
||||||
|
|
||||||
|
const load = () => {
|
||||||
|
platforms.value = [];
|
||||||
|
platformMapping.value.clear();
|
||||||
|
componentsMapping.value.clear();
|
||||||
|
|
||||||
|
findAllPlatformWithComponents().then(re => {
|
||||||
|
platforms.value = re.data ?? [];
|
||||||
|
platforms.value.forEach(platform => {
|
||||||
|
platformMapping.value.set(platform.id, platform);
|
||||||
|
if(platform.components){
|
||||||
|
platform.components.forEach(comp=> {
|
||||||
|
componentsMapping.value.set(comp.id, comp)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('加载平台组件数据失败:', err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const triggerChange = ()=> {
|
||||||
|
emit('change', {
|
||||||
|
platform: selectedPlatform.value ? {
|
||||||
|
id: selectedPlatform.value?.id,
|
||||||
|
name: selectedPlatform.value?.name,
|
||||||
|
description: selectedPlatform.value?.description,
|
||||||
|
} : null,
|
||||||
|
component: selectedComponent.value ? {
|
||||||
|
id: selectedComponent.value.id,
|
||||||
|
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)=> {
|
||||||
|
if(n && n.platform){
|
||||||
|
selectedPlatform.value = platformMapping.value.get(n.platform?.id) ?? null;
|
||||||
|
selectedPlatformId.value = selectedPlatform.value?.id ?? null;
|
||||||
|
selectedPlatformComponents.value = selectedPlatform.value?.components ?? []
|
||||||
|
} else {
|
||||||
|
selectedPlatform.value = null;
|
||||||
|
selectedPlatformId.value = null;
|
||||||
|
selectedPlatformComponents.value = []
|
||||||
|
}
|
||||||
|
|
||||||
|
if(n && n.component){
|
||||||
|
selectedComponent.value = n.component;
|
||||||
|
selectedComponentId.value = selectedComponent.value?.id ?? null;
|
||||||
|
} else {
|
||||||
|
selectedComponent.value = null;
|
||||||
|
selectedComponentId.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error('watch',n)
|
||||||
|
}, {deep: true, immediate: true})
|
||||||
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
platforms,
|
||||||
|
selectedPlatformComponents,
|
||||||
|
selectedPlatform,
|
||||||
|
selectedPlatformId,
|
||||||
|
selectedComponent,
|
||||||
|
selectedComponentId,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
import { HttpRequestClient } from '@/utils/request';
|
import { HttpRequestClient } from '@/utils/request';
|
||||||
import type { FireRule, FireRulePageableResponse, FireRuleRequest } from './types';
|
import type { FireRule, FireRulePageableResponse, FireRuleRequest } from './types';
|
||||||
|
import type { PlatformWithComponentsResponse } from '../types';
|
||||||
import type { BasicResponse } from '@/types';
|
import type { BasicResponse } from '@/types';
|
||||||
|
|
||||||
const req = HttpRequestClient.create<BasicResponse>({
|
const req = HttpRequestClient.create<BasicResponse>({
|
||||||
@@ -31,5 +32,8 @@ export const deleteFireRule = (id: number): Promise<BasicResponse> => {
|
|||||||
return req.delete(`/system/rule/${id}`);
|
return req.delete(`/system/rule/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const findAllPlatformWithComponents = (): Promise<PlatformWithComponentsResponse> => {
|
||||||
|
return req.get(`/system/firerule/platforms`);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -75,18 +75,52 @@
|
|||||||
|
|
||||||
<a-form-item
|
<a-form-item
|
||||||
label="触发条件"
|
label="触发条件"
|
||||||
:rules="[{ required: true, message: '请输入触发条件!', trigger: ['input', 'change'] }]"
|
:rules="[{ required: true, message: '请输入触发条件!', trigger: [ 'change'] }]"
|
||||||
:name="['conditions']"
|
:name="['conditionsArray']"
|
||||||
>
|
>
|
||||||
<a-input v-model:value="selectedFireRule.conditions" placeholder="请输入触发条件" />
|
<a-form-item-rest>
|
||||||
|
<div class="ks-sidebar-list-param-list">
|
||||||
|
<div class="ks-sidebar-list-param-item" v-for="(item,index) in selectedFireRule.conditionsArray">
|
||||||
|
<a-row :gutter="15">
|
||||||
|
<a-col :span="21">
|
||||||
|
<PlatformSelect @change="(payload: PlatformComponentPayload)=> handleUpdateCondition(payload, index)"
|
||||||
|
:payload="item"/>
|
||||||
|
</a-col>
|
||||||
|
<a-col :span="3">
|
||||||
|
<a-space class="ks-sidebar-list-param-actions">
|
||||||
|
<MinusCircleOutlined @click="()=> handleMinusCondition(index)" />
|
||||||
|
<PlusCircleOutlined @click="()=> handleAddCondition(index)" v-if="index === 0" />
|
||||||
|
</a-space>
|
||||||
|
</a-col>
|
||||||
|
</a-row>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a-form-item-rest>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item
|
<a-form-item
|
||||||
label="响应动作"
|
label="响应动作"
|
||||||
:rules="[{ required: true, message: '请输入响应动作!', trigger: ['input', 'change'] }]"
|
:rules="[{ required: true, message: '请输入响应动作!', trigger: ['change'] }]"
|
||||||
:name="['actions']"
|
:name="['actionsArray']"
|
||||||
>
|
>
|
||||||
<a-input v-model:value="selectedFireRule.actions" placeholder="请输入响应动作" />
|
<a-form-item-rest>
|
||||||
|
<div class="ks-sidebar-list-param-list">
|
||||||
|
<div class="ks-sidebar-list-param-item" v-for="(item,index) in selectedFireRule.actionsArray">
|
||||||
|
<a-row :gutter="15">
|
||||||
|
<a-col :span="21">
|
||||||
|
<PlatformSelect @change="(payload: PlatformComponentPayload)=> handleUpdateAction(payload, index)"
|
||||||
|
:payload="item"/>
|
||||||
|
</a-col>
|
||||||
|
<a-col :span="3">
|
||||||
|
<a-space class="ks-sidebar-list-param-actions">
|
||||||
|
<MinusCircleOutlined @click="()=> handleMinusAction(index)" />
|
||||||
|
<PlusCircleOutlined @click="()=> handleAddAction(index)" v-if="index === 0" />
|
||||||
|
</a-space>
|
||||||
|
</a-col>
|
||||||
|
</a-row>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a-form-item-rest>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item
|
<a-form-item
|
||||||
@@ -134,13 +168,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref, nextTick } from 'vue';
|
||||||
import { type FormInstance, message } from 'ant-design-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 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, FireRuleRequest } from './types';
|
||||||
import { substring } from '@/utils/strings';
|
import { substring } from '@/utils/strings';
|
||||||
|
import PlatformSelect from './PlatformSelect.vue';
|
||||||
|
import type { PlatformComponentPayload } from '../types';
|
||||||
|
|
||||||
const query = ref<Partial<FireRuleRequest>>({
|
const query = ref<Partial<FireRuleRequest>>({
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
@@ -155,8 +191,20 @@ const defaultFireRule: FireRule = {
|
|||||||
sceneType: null,
|
sceneType: null,
|
||||||
// 触发条件(JSON格式)
|
// 触发条件(JSON格式)
|
||||||
conditions: null,
|
conditions: null,
|
||||||
|
conditionsArray: [
|
||||||
|
{
|
||||||
|
platform: null,
|
||||||
|
component: null,
|
||||||
|
}
|
||||||
|
],
|
||||||
// 响应动作(JSON格式)
|
// 响应动作(JSON格式)
|
||||||
actions: null,
|
actions: null,
|
||||||
|
actionsArray: [
|
||||||
|
{
|
||||||
|
platform: null,
|
||||||
|
component: null,
|
||||||
|
}
|
||||||
|
],
|
||||||
// 优先级(数值越小优先级越高)
|
// 优先级(数值越小优先级越高)
|
||||||
priority: 0,
|
priority: 0,
|
||||||
// 是否启用(0禁用,1启用)
|
// 是否启用(0禁用,1启用)
|
||||||
@@ -174,20 +222,56 @@ const getSceneTypeName = (item: FireRule): string => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const resolveItem = (item: FireRule) => {
|
const resolveItem = (item: FireRule) => {
|
||||||
let newItem = JSON.parse(JSON.stringify(item));
|
let newItem: FireRule = JSON.parse(JSON.stringify(item)) as FireRule;
|
||||||
|
if (typeof item.conditions === 'string') {
|
||||||
|
try{
|
||||||
|
newItem.conditionsArray = JSON.parse(item.conditions as string);
|
||||||
|
} catch(e: any){
|
||||||
|
newItem.conditionsArray = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!newItem.conditionsArray) {
|
||||||
|
newItem.conditionsArray = []
|
||||||
|
}
|
||||||
|
if(newItem.conditionsArray.length===0){
|
||||||
|
newItem.conditionsArray.push({
|
||||||
|
platform: null,
|
||||||
|
component: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof item.actions === 'string') {
|
||||||
|
try{
|
||||||
|
newItem.actionsArray = JSON.parse(item.actions as string);
|
||||||
|
} catch(e: any){
|
||||||
|
newItem.actionsArray = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!newItem.actionsArray){
|
||||||
|
newItem.actionsArray = []
|
||||||
|
}
|
||||||
|
if(newItem.actionsArray.length===0){
|
||||||
|
newItem.actionsArray.push({
|
||||||
|
platform: null,
|
||||||
|
component: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return newItem;
|
return newItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
const datasource = ref<FireRule[]>([]);
|
const datasource = ref<FireRule[]>([]);
|
||||||
const datasourceTotal = ref<number>(0);
|
const datasourceTotal = ref<number>(0);
|
||||||
const selectedFireRule = ref<FireRule>(resolveItem(defaultFireRule));
|
const selectedFireRule = ref<FireRule>({...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();
|
formRef.value?.resetFields();
|
||||||
selectedFireRule.value = resolveItem(defaultFireRule);
|
selectedFireRule.value = {...defaultFireRule};
|
||||||
|
|
||||||
findFireRuleByQuery(query.value).then(r => {
|
findFireRuleByQuery(query.value).then(r => {
|
||||||
datasource.value = r.rows ?? [];
|
datasource.value = r.rows ?? [];
|
||||||
@@ -197,12 +281,16 @@ const load = () => {
|
|||||||
|
|
||||||
|
|
||||||
const handleCreate = () => {
|
const handleCreate = () => {
|
||||||
selectedFireRule.value = resolveItem(defaultFireRule);
|
selectedFireRule.value = {...defaultFireRule};
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelect = (item: FireRule) => {
|
const handleSelect = (item: FireRule) => {
|
||||||
selectedFireRule.value = resolveItem(item);
|
// 1. 先重置表单
|
||||||
formRef.value?.resetFields();
|
formRef.value?.resetFields();
|
||||||
|
// 2. 再赋值(使用nextTick确保DOM更新完成)
|
||||||
|
nextTick(() => {
|
||||||
|
selectedFireRule.value = resolveItem(item);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
@@ -223,6 +311,8 @@ const handleSave = () => {
|
|||||||
formRef.value.validate().then(() => {
|
formRef.value.validate().then(() => {
|
||||||
let res = null;
|
let res = null;
|
||||||
let savedValue: FireRule = JSON.parse(JSON.stringify(selectedFireRule.value)) as any as FireRule;
|
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) {
|
if (savedValue.id > 0) {
|
||||||
res = updateFireRule(savedValue);
|
res = updateFireRule(savedValue);
|
||||||
} else {
|
} else {
|
||||||
@@ -242,6 +332,66 @@ 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)=> {
|
||||||
|
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;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { NullableString, PageableResponse } from '@/types';
|
import type { NullableString, PageableResponse } from '@/types';
|
||||||
|
import type { PlatformComponentPayload } from '../types';
|
||||||
|
|
||||||
export interface FireRule {
|
export interface FireRule {
|
||||||
id: number,
|
id: number,
|
||||||
@@ -17,8 +18,10 @@ export interface FireRule {
|
|||||||
sceneType: Number | null,
|
sceneType: Number | null,
|
||||||
// 触发条件(JSON格式)
|
// 触发条件(JSON格式)
|
||||||
conditions: NullableString,
|
conditions: NullableString,
|
||||||
|
conditionsArray: PlatformComponentPayload[],
|
||||||
// 响应动作(JSON格式)
|
// 响应动作(JSON格式)
|
||||||
actions: NullableString,
|
actions: NullableString,
|
||||||
|
actionsArray: PlatformComponentPayload[],
|
||||||
// 优先级(数值越小优先级越高)
|
// 优先级(数值越小优先级越高)
|
||||||
priority: number,
|
priority: number,
|
||||||
// 是否启用(0禁用,1启用)
|
// 是否启用(0禁用,1启用)
|
||||||
|
|||||||
10
modeler/src/views/decision/types/index.ts
Normal file
10
modeler/src/views/decision/types/index.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the kernelstudio package.
|
||||||
|
*
|
||||||
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
|
* that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from './platform'
|
||||||
43
modeler/src/views/decision/types/platform.ts
Normal file
43
modeler/src/views/decision/types/platform.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the kernelstudio package.
|
||||||
|
*
|
||||||
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||||
|
*
|
||||||
|
* 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,
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlatformWithComponents extends Platform {
|
||||||
|
components: PlatformComponent[],
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlatformComponentPayload {
|
||||||
|
platform: Platform | null;
|
||||||
|
component: PlatformComponent | null;
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlatformWithComponentsResponse extends ApiDataResponse<PlatformWithComponents[]> {
|
||||||
|
|
||||||
|
}
|
||||||
4
modeler/types/components.d.ts
vendored
4
modeler/types/components.d.ts
vendored
@@ -15,6 +15,7 @@ declare module 'vue' {
|
|||||||
ABadge: typeof import('ant-design-vue/es')['Badge']
|
ABadge: typeof import('ant-design-vue/es')['Badge']
|
||||||
AButton: typeof import('ant-design-vue/es')['Button']
|
AButton: typeof import('ant-design-vue/es')['Button']
|
||||||
ACard: typeof import('ant-design-vue/es')['Card']
|
ACard: typeof import('ant-design-vue/es')['Card']
|
||||||
|
ACascader: typeof import('ant-design-vue/es')['Cascader']
|
||||||
ACol: typeof import('ant-design-vue/es')['Col']
|
ACol: typeof import('ant-design-vue/es')['Col']
|
||||||
ACollapse: typeof import('ant-design-vue/es')['Collapse']
|
ACollapse: typeof import('ant-design-vue/es')['Collapse']
|
||||||
ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']
|
ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']
|
||||||
@@ -44,6 +45,7 @@ declare module 'vue' {
|
|||||||
ASelect: typeof import('ant-design-vue/es')['Select']
|
ASelect: typeof import('ant-design-vue/es')['Select']
|
||||||
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
||||||
ASpace: typeof import('ant-design-vue/es')['Space']
|
ASpace: typeof import('ant-design-vue/es')['Space']
|
||||||
|
ASwitch: typeof import('ant-design-vue/es')['Switch']
|
||||||
ATabPane: typeof import('ant-design-vue/es')['TabPane']
|
ATabPane: typeof import('ant-design-vue/es')['TabPane']
|
||||||
ATabs: typeof import('ant-design-vue/es')['Tabs']
|
ATabs: typeof import('ant-design-vue/es')['Tabs']
|
||||||
ATextarea: typeof import('ant-design-vue/es')['Textarea']
|
ATextarea: typeof import('ant-design-vue/es')['Textarea']
|
||||||
@@ -58,6 +60,7 @@ declare global {
|
|||||||
const ABadge: typeof import('ant-design-vue/es')['Badge']
|
const ABadge: typeof import('ant-design-vue/es')['Badge']
|
||||||
const AButton: typeof import('ant-design-vue/es')['Button']
|
const AButton: typeof import('ant-design-vue/es')['Button']
|
||||||
const ACard: typeof import('ant-design-vue/es')['Card']
|
const ACard: typeof import('ant-design-vue/es')['Card']
|
||||||
|
const ACascader: typeof import('ant-design-vue/es')['Cascader']
|
||||||
const ACol: typeof import('ant-design-vue/es')['Col']
|
const ACol: typeof import('ant-design-vue/es')['Col']
|
||||||
const ACollapse: typeof import('ant-design-vue/es')['Collapse']
|
const ACollapse: typeof import('ant-design-vue/es')['Collapse']
|
||||||
const ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']
|
const ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']
|
||||||
@@ -87,6 +90,7 @@ declare global {
|
|||||||
const ASelect: typeof import('ant-design-vue/es')['Select']
|
const ASelect: typeof import('ant-design-vue/es')['Select']
|
||||||
const ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
const ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
||||||
const ASpace: typeof import('ant-design-vue/es')['Space']
|
const ASpace: typeof import('ant-design-vue/es')['Space']
|
||||||
|
const ASwitch: typeof import('ant-design-vue/es')['Switch']
|
||||||
const ATabPane: typeof import('ant-design-vue/es')['TabPane']
|
const ATabPane: typeof import('ant-design-vue/es')['TabPane']
|
||||||
const ATabs: typeof import('ant-design-vue/es')['Tabs']
|
const ATabs: typeof import('ant-design-vue/es')['Tabs']
|
||||||
const ATextarea: typeof import('ant-design-vue/es')['Textarea']
|
const ATextarea: typeof import('ant-design-vue/es')['Textarea']
|
||||||
|
|||||||
Reference in New Issue
Block a user