fix: api请求示例逻辑代码优化

* fix: api请求示例逻辑代码优化
This commit is contained in:
XieYongHong 2024-08-22 13:48:36 +08:00 committed by GitHub
parent 827b824451
commit 9a587e276e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 500 additions and 442 deletions

View File

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

View File

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

View File

@ -267,7 +267,10 @@ export const handleGroupAndFilter = (branches: any[], when: any[]) =>{
branches.forEach((item, index) => { branches.forEach((item, index) => {
if (when) { 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) { if (index === 0 || item.executeAnyway) {

View File

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

View File

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

View File

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

View File

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