Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vue-gojs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴斌
vue-gojs
Commits
67d0df75
Commit
67d0df75
authored
Nov 13, 2023
by
吴斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
2913e9a5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
33 deletions
+41
-33
App.vue
src/App.vue
+16
-5
ModelData.ts
src/kit/ModelData.ts
+3
-25
Rule.ts
src/kit/rule/Rule.ts
+22
-3
No files found.
src/App.vue
View file @
67d0df75
...
...
@@ -369,8 +369,12 @@ function changeDiagramConfig(key:string, value:string){
function
importData
(){
let
json
=
diagramModelData
[
'diagramData'
]
myDiagram
.
model
=
go
.
Model
.
fromJson
(
json
)
rules
.
splice
(
0
,
rules
.
length
)
for
(
let
rule
of
diagramModelData
[
'ruleData'
]){
rules
.
push
(
rule
)
}
getRuleList
()
deviceMap
.
value
=
getDeviceMapData
(
myDiagram
)
changeDiagramConfig
(
'mode'
,
'readonly'
)
}
...
...
@@ -468,7 +472,6 @@ function initDiagram(){
function
listenDiagram
(){
myDiagram
.
addDiagramListener
(
'BackgroundSingleClicked'
,
()
=>
{
console
.
log
(
myDiagram
.
model
.
toJson
())
})
myDiagram
.
addDiagramListener
(
'Modified'
,
()
=>
{
})
...
...
@@ -505,10 +508,20 @@ function listenDiagram(){
})
});
myDiagram
.
addModelChangedListener
(
function
(
e
:
any
){
if
(
e
.
isTransactionFinished
)
runAllEnableRule
(
getDeviceMapData
(
myDiagram
));
if
(
e
.
isTransactionFinished
)
{
runAllEnableRule
(
getDeviceMapData
(
myDiagram
))
}
})
}
// function cancelListenDiagram(){
// myDiagram.removeModelChangedListener(function(e:any){
// if (e.isTransactionFinished) {
// runAllEnableRule(getDeviceMapData(myDiagram))
// }
// })
// }
function
freshSelectionNode
(){
let
selectedNodeKey
=
myDiagram
.
selection
.
first
()?.
data
?.
key
selectedNode
.
value
=
myDiagram
.
findNodeForKey
(
selectedNodeKey
)
...
...
@@ -767,7 +780,6 @@ function showAddRuleDialog(){
ruleDialog
.
value
.
visible
=
true
ruleDialog
.
value
.
type
=
'add'
// 图表有修改,需要更新设备列表
deviceMap
.
value
=
getDeviceMapData
(
myDiagram
)
ruleDialog
.
value
.
data
=
{
name
:
""
,
inputs
:[],
...
...
@@ -787,7 +799,6 @@ function addRuleParam(){
}
function
confirmAddRule
(){
let
ruleData
=
ruleDialog
.
value
.
data
console
.
log
(
ruleData
)
if
(
!
ruleData
.
name
)
{
ElMessage
.
error
(
'规则名称不能为空'
)
return
...
...
src/kit/ModelData.ts
View file @
67d0df75
...
...
@@ -127,31 +127,9 @@ export const diagramModelData = {
"key"
:
"f78b6be4-4cc2-4812-96e1-aa065118398a"
,
"valueKey"
:
"failurePossibility"
}],
func
:
'function a(data) {if(data
<0.1)alert("测试小于0.1
"+data)}'
,
func
:
'function a(data) {if(data
>0.0005)alert("当前冷却器失效可能性为:
"+data)}'
,
enable
:
true
,
description
:
"测试小于0.1"
,
},
{
id
:
"51b9d15b-8eea-4c4e-92a2-5bb9d99d298t"
,
name
:
"测试脚本"
,
inputs
:[{
"key"
:
"f78b6be4-4cc2-4812-96e1-aa065118398a"
,
"valueKey"
:
"failurePossibility"
}],
func
:
'function a(data) {if(data ===0);alert("测试等于零"+data)}'
,
enable
:
true
,
description
:
"测试等于零"
,
},
{
id
:
"51b9d16b-8eea-4c4e-92a2-5bb9599d298t"
,
name
:
"测试脚本"
,
inputs
:[{
"key"
:
"f78b6be4-4cc2-4812-96e1-aa065118398a"
,
"valueKey"
:
"failurePossibility"
}],
func
:
'function a(data) {if(data < 0)alert("测试小于零"+data)}'
,
enable
:
true
,
description
:
"测试<0"
,
},
description
:
"冷却器失效可能性大于0.0005"
,
}
]
}
src/kit/rule/Rule.ts
View file @
67d0df75
import
{
uuid
}
from
"vue3-uuid"
;
import
{
diagramModelData
}
from
"../ModelData.ts"
;
export
const
rules
:
Record
<
string
,
any
>
[]
=
diagramModelData
[
'ruleData'
]
export
var
rules
:
Record
<
string
,
any
>
[]
=
[]
/**
* 添加规则
* @param name 规则名称
...
...
@@ -66,16 +65,32 @@ export function runRule(rule:any, deviceMap:Record<string, any>){
}
/**
* 函数“runAllEnableRule”在给定的设备映射上运行所有启用的规则。
* @param deviceMap - 将设备名称映射到其相应信息或数据的记录对象。
*/
export
function
runAllEnableRule
(
deviceMap
:
Record
<
string
,
any
>
){
rules
.
forEach
((
item
:
any
)
=>
{
if
(
item
[
'enabled'
])
runRule
(
item
,
deviceMap
)
if
(
item
[
'enable'
].
toString
()
===
'true'
)
{
runRule
(
item
,
deviceMap
)
}
})
}
/**
* 函数“runRuleById”通过 ID 查找规则并使用给定的设备映射运行它。
* @param {string} id - “id”参数是一个字符串,表示规则的唯一标识符。它用于在“rules”数组中查找规则。
* @param deviceMap - “deviceMap”参数是一个记录对象,它将设备名称映射到其相应的信息或状态。它用于提供运行规则所需的数据。
*/
export
function
runRuleById
(
id
:
string
,
deviceMap
:
Record
<
string
,
any
>
){
let
rule
=
rules
.
find
((
item
:
any
)
=>
item
.
id
==
id
)
runRule
(
rule
,
deviceMap
)
}
/**
* 函数“testRule”将规则对象作为输入,从规则中提取测试数据,从规则的函数字符串创建一个新函数,然后使用测试数据作为参数执行该函数。
* @param {any} rule - “rule”参数是包含有关特定规则的信息的对象。
*/
export
function
testRule
(
rule
:
any
){
let
inputData
=
[]
let
runFunc
=
null
...
...
@@ -92,6 +107,10 @@ export function testRule(rule:any){
}
}
/**
* 函数“testRuleById”通过 ID 查找规则,然后测试该规则。
* @param {string} id - “id”参数是一个字符串,表示规则的唯一标识符。
*/
export
function
testRuleById
(
id
:
string
){
let
rule
=
rules
.
find
((
item
:
any
)
=>
item
.
id
==
id
)
testRule
(
rule
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment