Merge remote-tracking branch 'origin/2.2' into 2.2

This commit is contained in:
XieYongHong 2024-08-22 13:49:30 +08:00
commit 004b1667c5
7 changed files with 500 additions and 442 deletions

View File

@ -13,10 +13,9 @@
:key="group.key"
>
<div v-for="(branch, index) in group.children">
<div style="display: flex;align-items: center" v-if="show">
<span v-if="branch.when" style="padding-right: 12px;font-weight: bold;font-size: 16px;width: 46px; display: inline-block;">{{ index === 0 ? '' : '否则' }}</span>
<div style="display: flex;align-items: center" v-if="show && branch.when.length">
<span style="padding-right: 12px;font-weight: bold;font-size: 16px;width: 46px; display: inline-block;">{{ index === 0 ? '当' : '否则' }}</span>
<Terms :when="branch.whenOptions" :data="branch.when" />
</div>
<div class="branches-shakeLimit" v-if="show">
<span class="branches-shakeLimit-action">执行</span>

View File

@ -15,13 +15,12 @@
</div>
<div v-if="_value" class="dropdown-button value">
<AIcon type='icon-canshu' />
{{ _value[0] }}
{{ typeof(_value) === 'object' ? _value[0] : _value}}
</div>
<div v-if="value[2][1]" class="dropdown-button value">
<AIcon type='icon-canshu' />
{{ _value[1] }}
</div>
</div>
</template>

View File

@ -267,7 +267,10 @@ export const handleGroupAndFilter = (branches: any[], when: any[]) =>{
branches.forEach((item, index) => {
if (when) {
item.whenOptions = when[index]
// item.whenOptions = when[index]
item.whenOptions = when.find((i)=>{
return item?.branchId === i.key
})
}
if (index === 0 || item.executeAnyway) {

View File

@ -1,10 +1,15 @@
<template>
<div class='actions-terms'>
<TitleComponent data='执行动作' style='font-size: 14px;' >
<div class="actions-terms">
<TitleComponent data="执行动作" style="font-size: 14px">
</TitleComponent>
<!-- <template v-if='open'>-->
<!-- <template v-if='open'>-->
<div>
<j-tabs type="editable-card" v-model:activeKey="activeKey" @edit="addGroup" @tabClick="showEditCondition">
<j-tabs
type="editable-card"
v-model:activeKey="activeKey"
@edit="addGroup"
@tabClick="showEditCondition"
>
<j-tab-pane
v-for="(b, i) in group"
:key="b.id"
@ -12,42 +17,63 @@
:forceRender="true"
>
<template #tab>
<TermsTabPane :showClose="group.length > 1" @close="() => addGroup(b.id, 'close')">
{{ b.branchName || `条件${i+1}` }}
<TermsTabPane
:showClose="group.length > 1"
@close="() => addGroup(b.id, 'close')"
>
{{ b.branchName || `条件${i + 1}` }}
</TermsTabPane>
</template>
<div class="filterConditionSwitch">
<span>执行</span>
<j-switch
v-model:checked='b.openFilter'
@change='(e)=>change(e,b,i)'
checkedChildren='开'
unCheckedChildren='关'
style='margin-left: 4px;'
v-model:checked="b.openFilter"
@change="(e) => change(e, b, i)"
checkedChildren="开"
unCheckedChildren="关"
style="margin-left: 4px"
/>
</div>
<template v-for='(item, index) in data.branches'>
<template v-if="index >= b.start && index < (b.start + b.len)">
<template v-for="(item, index) in data.branches">
<template
v-if="index >= b.start && index < b.start + b.len"
>
<Branches
v-if='!!item'
:data='item'
:isFirst='index === b.start'
:name='index'
:branches_Index='item.branches_Index'
v-if="!!item"
:data="item"
:isFirst="index === b.start"
:name="index"
:branches_Index="item.branches_Index"
:groupLen="b.start + b.len"
:groupIndex="i + 1"
:key='item.key'
:key="item.key"
:showGroupDelete="group.length !== 1"
@delete='branchesDelete(index)'
@deleteAll='branchesDeleteAll'
@delete="branchesDelete(index)"
@deleteAll="branchesDeleteAll"
@add="branchesAdd"
/>
<div v-else class='actions-terms-warp' :style='{ marginTop: data.branches.length === 2 ? 0 : 24 }'>
<div class='actions-terms-title' style='padding: 0;margin-bottom: 24px;'>
<div
v-else
class="actions-terms-warp"
:style="{
marginTop:
data.branches.length === 2 ? 0 : 24,
}"
>
<div
class="actions-terms-title"
style="padding: 0; margin-bottom: 24px"
>
否则
</div>
<div class='actions-terms-options no-when'>
<AIcon type='PlusOutlined' class='when-add-button' @click='() => addBranches(b.start + b.len)' />
<div class="actions-terms-options no-when">
<AIcon
type="PlusOutlined"
class="when-add-button"
@click="
() => addBranches(b.start + b.len)
"
/>
</div>
</div>
</template>
@ -56,19 +82,19 @@
</j-tabs>
</div>
<!-- </template>-->
<!-- <div v-else class='actions-branches-item'>-->
<!-- <j-form-item-->
<!-- :name='["branches", 0, "then"]'-->
<!-- :rules='thenRules'-->
<!-- >-->
<!-- <Action-->
<!-- :name='0'-->
<!-- :openShakeLimit="true"-->
<!-- :thenOptions='data.branches[0]?.then'-->
<!-- />-->
<!-- </j-form-item>-->
<!-- </div>-->
<!-- </template>-->
<!-- <div v-else class='actions-branches-item'>-->
<!-- <j-form-item-->
<!-- :name='["branches", 0, "then"]'-->
<!-- :rules='thenRules'-->
<!-- >-->
<!-- <Action-->
<!-- :name='0'-->
<!-- :openShakeLimit="true"-->
<!-- :thenOptions='data.branches[0]?.then'-->
<!-- />-->
<!-- </j-form-item>-->
<!-- </div>-->
</div>
<BranchesNameEdit
v-if="editConditionVisible"
@ -78,32 +104,35 @@
/>
</template>
<script setup lang='ts' name='Terms'>
<script setup lang="ts" name="Terms">
import { storeToRefs } from 'pinia';
import { useSceneStore } from '@/store/scene'
import { cloneDeep } from 'lodash-es'
import { provide } from 'vue'
import { ContextKey, handleParamsData } from './util'
import {getParseTerm} from '@/api/rule-engine/scene'
import type { FormModelType} from '@/views/rule-engine/Scene/typings'
import Branches from './Branches.vue'
import {randomNumber, randomString} from "@/utils/utils";
import TermsTabPane from './TermsTabPane.vue'
import BranchesNameEdit from "./BranchesNameEdit.vue";
import {Modal} from "ant-design-vue";
import {queryBindScene, unBindAlarmMultiple} from "@/api/rule-engine/configuration";
import { useSceneStore } from '@/store/scene';
import { cloneDeep } from 'lodash-es';
import { provide } from 'vue';
import { ContextKey, handleParamsData } from './util';
import { getParseTerm } from '@/api/rule-engine/scene';
import type { FormModelType } from '@/views/rule-engine/Scene/typings';
import Branches from './Branches.vue';
import { randomNumber, randomString } from '@/utils/utils';
import TermsTabPane from './TermsTabPane.vue';
import BranchesNameEdit from './BranchesNameEdit.vue';
import { Modal } from 'ant-design-vue';
import {
queryBindScene,
unBindAlarmMultiple,
} from '@/api/rule-engine/configuration';
const sceneStore = useSceneStore()
const { data } = storeToRefs(sceneStore)
const columnOptions = ref<any>([])
const group = ref<Array<{ id: string, len: number}>>([])
const activeKey = ref('')
const sceneStore = useSceneStore();
const { data } = storeToRefs(sceneStore);
const columnOptions = ref<any>([]);
const group = ref<Array<{ id: string; len: number }>>([]);
const activeKey = ref('');
const editConditionVisible = ref(false);
const conditionName = ref<any>()
const conditionName = ref<any>();
provide(ContextKey, columnOptions)
provide(ContextKey, columnOptions);
const change = (e: boolean,groupItem:any,index:number) => {
const change = (e: boolean, groupItem: any, index: number) => {
// group.value = []
// activeKey.value = ''
// if (!e) {
@ -130,14 +159,19 @@ const change = (e: boolean,groupItem:any,index:number) => {
// },
// ]
// }
const start = groupItem.start
const len = groupItem.len
if(!e){
data.value.branches?.splice(start + 1 , len - 1)
data.value.branches![start].when = []
data.value.options!.when.splice(start,len - 1)
}else{
data.value.branches!.splice(start + 1,0,null)
const start = groupItem.start;
const len = groupItem.len;
if (!e) {
data.value.branches?.splice(start + 1, len - 1);
data.value.branches![start].when = [];
// data.value.options!.when.splice(start,len - 1)
data.value.options!.when[start].terms = [
{
terms: [['', 'eq', '', 'and']],
},
];
} else {
data.value.branches!.splice(start + 1, 0, null);
data.value.branches![start].when = [
{
terms: [
@ -145,7 +179,7 @@ const change = (e: boolean,groupItem:any,index:number) => {
column: undefined,
value: {
source: 'fixed',
value: undefined
value: undefined,
},
termType: undefined,
key: `params_${randomString()}`,
@ -155,20 +189,24 @@ const change = (e: boolean,groupItem:any,index:number) => {
type: 'and',
key: `terms_${randomString()}`,
},
]
];
}
}
};
const queryColumn = (dataModel: FormModelType) => {
const cloneDevice = cloneDeep(dataModel)
cloneDevice.branches = cloneDevice.branches?.filter(item => !!item)
getParseTerm(cloneDevice).then(res => {
columnOptions.value = handleParamsData(res.result as any[], 'column', '0')
})
}
const cloneDevice = cloneDeep(dataModel);
cloneDevice.branches = cloneDevice.branches?.filter((item) => !!item);
getParseTerm(cloneDevice).then((res) => {
columnOptions.value = handleParamsData(
res.result as any[],
'column',
'0',
);
});
};
const addBranches = (len: number) => {
const key = randomNumber()
const key = randomNumber();
const branchesItem = {
when: [],
key: key,
@ -179,28 +217,31 @@ const addBranches = (len: number) => {
alarmFirst: false,
},
then: [],
branchId: key
}
branchId: key,
};
// const lastIndex = data.value.branches!.length - 1 || 0
data.value.branches?.splice(len - 1, 1, branchesItem)
data.value.branches?.splice(len - 1, 1, branchesItem);
data.value.options!.when.splice(len - 1, 1, {
terms: [],
key
})
}
key,
});
};
const branchesDelete = (index: any) => {
groupDelete({
groupDelete(
{
start: index,
len: 1
}, -1)
}
len: 1,
},
-1,
);
};
const addGroup = (targetKey: string, action: string) => {
if (action === 'add') {
const lastGroup = group.value[group.value.length - 1]
const lastIndex = (lastGroup?.groupIndex || group.value.length) + 1
const key = randomNumber()
const lastGroup = group.value[group.value.length - 1];
const lastIndex = (lastGroup?.groupIndex || group.value.length) + 1;
const key = randomNumber();
const branchesItem: any = {
when: [
@ -210,7 +251,7 @@ const addGroup = (targetKey: string, action: string) => {
column: undefined,
value: {
source: 'fixed',
value: undefined
value: undefined,
},
termType: undefined,
key: `params_${randomString()}`,
@ -231,196 +272,208 @@ const addGroup = (targetKey: string, action: string) => {
then: [],
executeAnyway: true,
branchId: key,
branchName: ''
}
data.value.branches?.push(branchesItem, null)
branchName: '',
};
data.value.branches?.push(branchesItem, null);
// data.value.branches?.push(null as any)
activeKey.value = key
activeKey.value = key;
data.value.options!.when.push({
terms: [{
terms: [['','eq','','and']],
}],
terms: [
{
terms: [['', 'eq', '', 'and']],
},
],
branchName: '',
key,
executeAnyway: true,
groupIndex: lastIndex
})
groupIndex: lastIndex,
});
} else {
const index = group.value.findIndex(item => item.branchId === targetKey)
groupDelete(group.value[index], index)
const index = group.value.findIndex(
(item) => item.branchId === targetKey,
);
groupDelete(group.value[index], index);
}
}
};
const branchesDeleteAll = () => {
}
const branchesDeleteAll = () => {};
const groupDelete = async (g: any, index: number) => {
//
let actionLen = 0
let alarmTerms: Array<Record<string, string>> = []
let actionLen = 0;
let alarmTerms: Array<Record<string, string>> = [];
for (let i = g.start; i < g.start + g.len; i++) {
const item = data.value.branches[i]
const item = data.value.branches[i];
if (item) {
item.then?.forEach(thenItem => {
actionLen += thenItem.actions.length
item.then?.forEach((thenItem) => {
actionLen += thenItem.actions.length;
if (thenItem.actions) {
thenItem.actions.forEach((actionItem) => {
const _actionId = actionItem.actionId
const _actionId = actionItem.actionId;
if (actionItem.executor === 'alarm') {
alarmTerms.push({
column: 'branchIndex',
value: _actionId || item.branchId,
type: 'or'
})
type: 'or',
});
}
})
});
}
})
});
}
}
if (actionLen) {
if (alarmTerms.length) {
const resp = await queryBindScene({
terms: alarmTerms
})
terms: alarmTerms,
});
Modal.confirm({
title: `已关联 ${resp.result.total} 条告警,删除该条件会同步解除对应的关联告警,确认删除?`,
onOk() {
const _data = resp.result.data.map(item => {
const _data = resp.result.data.map((item) => {
return {
"alarmId": item.alarmId,
"ruleId": item.ruleId,
"branchIndex": item.branchIndex
}
})
unBindAlarmMultiple(_data)
removeBranchesData(g, index)
}
})
alarmId: item.alarmId,
ruleId: item.ruleId,
branchIndex: item.branchIndex,
};
});
unBindAlarmMultiple(_data);
removeBranchesData(g, index);
},
});
} else {
Modal.confirm({
title: '该条件下有执行动作,确认删除?',
onOk() {
removeBranchesData(g, index)
}
})
removeBranchesData(g, index);
},
});
}
} else {
removeBranchesData(g, index)
removeBranchesData(g, index);
}
}
};
const removeBranchesData = (g: any, index: number) => {
const removeBranches = data.value.branches.splice(g.start, g.len)
const removeBranches = data.value.branches.splice(g.start, g.len);
removeBranches.forEach(item => {
removeBranches.forEach((item) => {
if (item) {
let _index = data.value.options!.when.findIndex(whenItem => whenItem.key === item.branchId)
let _index = data.value.options!.when.findIndex(
(whenItem) => whenItem.key === item.branchId,
);
if (_index !== -1) {
_index = item.branches_Index
_index = item.branches_Index;
}
data.value.options!.when.splice(_index, 1)
data.value.options!.when.splice(_index, 1);
}
})
});
if (index >= 0) { //
group.value.splice(index, 1)
if (index >= 0) {
//
group.value.splice(index, 1);
if (g.id === activeKey.value) { //
let _moveIndex = index - 1
if (g.id === activeKey.value) {
//
let _moveIndex = index - 1;
if (_moveIndex < 0) { //
_moveIndex = 0
if (_moveIndex < 0) {
//
_moveIndex = 0;
}
activeKey.value = group.value[_moveIndex].id
activeKey.value = group.value[_moveIndex].id;
}
} else { //
const groupItem = group.value.find(item => item.id === activeKey.value) //
groupItem!.len -= 1
const branchesItem = data.value.branches[g.start]
if (branchesItem === undefined || branchesItem?.executeAnyway) { // undefined null
data.value.branches?.splice(g.start, 0, null)
} else {
//
const groupItem = group.value.find(
(item) => item.id === activeKey.value,
); //
groupItem!.len -= 1;
const branchesItem = data.value.branches[g.start];
if (branchesItem === undefined || branchesItem?.executeAnyway) {
// undefined null
data.value.branches?.splice(g.start, 0, null);
}
}
}
};
const branchesAdd = () => {
// const groupItem = group.value.find(item => item.id === activeKey.value) //
// groupItem!.len += 1
}
};
const showEditCondition = (key:any) =>{
if(key === activeKey.value){
const showEditCondition = (key: any) => {
if (key === activeKey.value) {
editConditionVisible.value = true;
conditionName.value = group.value.find((i:any)=>{
return i.branchId === key
})?.branchName
conditionName.value = group.value.find((i: any) => {
return i.branchId === key;
})?.branchName;
}
}
};
const changeBranchName = (name: string) =>{
let _activeKey = activeKey.value
const changeBranchName = (name: string) => {
let _activeKey = activeKey.value;
data.value.branches?.forEach((item:any)=>{
if(item?.branchId === _activeKey){
item.branchName = name
data.value.branches?.forEach((item: any) => {
if (item?.branchId === _activeKey) {
item.branchName = name;
}
})
});
let optionsItem = data.value.options!.when.find(item => item.key === _activeKey)
let optionsItem = data.value.options!.when.find(
(item) => item.key === _activeKey,
);
if (!optionsItem) {
const _index = group.value.findIndex(item => item.branchId === _activeKey)
const _index = group.value.findIndex(
(item) => item.branchId === _activeKey,
);
if (_index !== -1) {
data.value.options!.when[_index].branchName = name
data.value.options!.when[_index].branchName = name;
}
} else {
optionsItem.branchName = name
optionsItem.branchName = name;
}
editConditionVisible.value =false
}
editConditionVisible.value = false;
};
const changePaneIndex = (index) => {
const _groupItem = group.value.find(item => {
return item.start >= index && index < (item.start + item.len)
})
const _groupItem = group.value.find((item) => {
return item.start >= index && index < item.start + item.len;
});
if (_groupItem) {
activeKey.value = _groupItem.branchId
activeKey.value = _groupItem.branchId;
}
}
};
watchEffect(() => {
if (data.value.trigger?.device) {
queryColumn({ trigger: data.value.trigger })
queryColumn({ trigger: data.value.trigger });
}
})
});
watchEffect(() => {
const branches = data.value.branches
let _group = []
let _branchesIndex = 0
const branches = data.value.branches;
let _group = [];
let _branchesIndex = 0;
if (branches) {
branches.forEach((item, index) => {
const lastIndex = _group.length - 1;
const lastIndex = _group.length - 1
let whenItem = data.value.options!.when.find(when => item?.branchId === when.key)
let whenItem = data.value.options!.when.find(
(when) => item?.branchId === when.key,
);
if (!whenItem) {
whenItem = data.value.options!.when[_branchesIndex]
whenItem = data.value.options!.when[_branchesIndex];
}
if (index === 0 || item?.executeAnyway) {
_group[lastIndex + 1] = {
id: item.branchId,
@ -429,39 +482,38 @@ watchEffect(() => {
branchKey: item.key,
branchId: item.branchId,
// branchName: item.branchName || whenItem?.branchName || ` ${_branchesIndex + 1}`,
branchName: item.branchName || whenItem?.branchName || `条件`,
branchName:
item.branchName || whenItem?.branchName || `条件`,
groupIndex: _branchesIndex,
openFilter: !!item.when.length
}
openFilter: !!item.when.length,
};
} else {
_group[lastIndex].len += 1
_group[lastIndex].len += 1;
}
if (item) {
item.branches_Index = _branchesIndex
_branchesIndex += 1
item.branches_Index = _branchesIndex;
_branchesIndex += 1;
}
})
});
// branches.filter(item => item).forEach((item, index) => {
// item.branches_Index = index
// })
group.value = _group
group.value = _group;
if (!activeKey.value) {
activeKey.value = _group[0].id
activeKey.value = _group[0].id;
}
}
})
});
defineExpose({
changePaneIndex
})
changePaneIndex,
});
</script>
<style scoped lang='less'>
<style scoped lang="less">
.actions-terms {
:deep(.ant-tabs-tab-active) {
.ant-tabs-tab-remove {
@ -469,7 +521,7 @@ defineExpose({
}
}
}
.filterConditionSwitch{
.filterConditionSwitch {
display: flex;
gap: 16px;
align-items: center;

View File

@ -154,9 +154,7 @@ const requestCard = reactive<cardType>({
// schemaJava
if (!_ref) {
const type = schema.type || '';
console.log(type,'type')
requestCard.codeText = dealNoRef(type, schema);
console.log(requestCard.codeText)
} else {
const schemaName = _ref?.split('/').pop();
const type = schema.type || '';
@ -180,6 +178,7 @@ const requestCard = reactive<cardType>({
})),
},
];
// console.log(requestCard,'requestCard')
}
},
});

View File

@ -6,7 +6,7 @@ import { schemaObjType } from "./typing";
* @param schemas map
* @param schemaName
*/
export function findData(schemas: object, schemaName: string) {
export function findData(schemas: object, schemaName: string , paths:string[]=[]) {
const basicType = ['string', 'integer', 'boolean','number'];
if (!schemaName || !schemas[schemaName]) {
@ -16,17 +16,21 @@ export function findData(schemas: object, schemaName: string) {
const schema = schemas[schemaName];
Object.entries(schema.properties).forEach((item: [string, any]) => {
const paramsType =
item[1].type ||
(item[1].$ref && item[1].$ref.split('/').pop()) ||
(item[1].items && item[1].items.$ref.split('/').pop()) ||
(item[1].items?.$ref && item[1].items.$ref.split('/').pop()) ||
item[1].item?.type ||
item[1].type ||
'';
const schemaObj: schemaObjType = {
paramsName: item[0],
paramsType,
desc: item[1].description || '',
};
if (!basicType.includes(paramsType))
if (!basicType.includes(paramsType) && paths.filter(path=>path === schemaName).length >=2 ){
paths.push(schemaName)
schemaObj.children = findData(schemas, paramsType);
}
result.push(schemaObj);
});
@ -68,16 +72,18 @@ export function getCodeText(
default: {
const properties = schemas[item.paramsType]?.properties as object || {};
const newArr = Object.entries(properties).map(
(item: [string, any]) => ({
(item: [string, any]) => {
return{
paramsName: item[0],
paramsType: level
? (item[1].$ref && item[1].$ref.split('/').pop()) ||
(item[1].items &&
(item[1].items?.$ref &&
item[1].items.$ref.split('/').pop()) ||
item[1].item?.type ||
item[1].type ||
''
: item[1].type,
}),
}},
);
result[item.paramsName] = getCodeText(
schemas,

View File

@ -96,8 +96,8 @@ export default defineConfig(({ mode}) => {
// target: 'http://192.168.32.244:8881',
// target: 'http://192.168.32.217:8844', //张本地
// target: 'http://120.77.179.54:8844', // 120测试
// target: 'http://192.168.33.46:8844', // 本地开发环境
target: 'http://192.168.33.97:8844', // 本地开发环境1
target: 'http://192.168.33.46:8844', // 本地开发环境
// target: 'http://192.168.33.99:8844', // 本地开发环境1
// target: 'http://192.168.33.6:38848', // 社区版开发环境
// target: 'http://192.168.32.207:8844', // 刘本地
// target: 'http://192.168.32.187:8844', // 谭本地