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,10 +1,15 @@
<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
type="editable-card"
v-model:activeKey="activeKey"
@edit="addGroup"
@tabClick="showEditCondition"
>
<j-tab-pane <j-tab-pane
v-for="(b, i) in group" v-for="(b, i) in group"
:key="b.id" :key="b.id"
@ -12,42 +17,63 @@
:forceRender="true" :forceRender="true"
> >
<template #tab> <template #tab>
<TermsTabPane :showClose="group.length > 1" @close="() => addGroup(b.id, 'close')"> <TermsTabPane
{{ b.branchName || `条件${i+1}` }} :showClose="group.length > 1"
@close="() => addGroup(b.id, 'close')"
>
{{ b.branchName || `条件${i + 1}` }}
</TermsTabPane> </TermsTabPane>
</template> </template>
<div class="filterConditionSwitch"> <div class="filterConditionSwitch">
<span>执行</span> <span>执行</span>
<j-switch <j-switch
v-model:checked='b.openFilter' v-model:checked="b.openFilter"
@change='(e)=>change(e,b,i)' @change="(e) => change(e, b, i)"
checkedChildren='开' checkedChildren="开"
unCheckedChildren='关' unCheckedChildren="关"
style='margin-left: 4px;' style="margin-left: 4px"
/> />
</div> </div>
<template v-for='(item, index) in data.branches'> <template v-for="(item, index) in data.branches">
<template v-if="index >= b.start && index < (b.start + b.len)"> <template
v-if="index >= b.start && index < b.start + b.len"
>
<Branches <Branches
v-if='!!item' v-if="!!item"
:data='item' :data="item"
:isFirst='index === b.start' :isFirst="index === b.start"
:name='index' :name="index"
:branches_Index='item.branches_Index' :branches_Index="item.branches_Index"
:groupLen="b.start + b.len" :groupLen="b.start + b.len"
:groupIndex="i + 1" :groupIndex="i + 1"
:key='item.key' :key="item.key"
:showGroupDelete="group.length !== 1" :showGroupDelete="group.length !== 1"
@delete='branchesDelete(index)' @delete="branchesDelete(index)"
@deleteAll='branchesDeleteAll' @deleteAll="branchesDeleteAll"
@add="branchesAdd" @add="branchesAdd"
/> />
<div v-else class='actions-terms-warp' :style='{ marginTop: data.branches.length === 2 ? 0 : 24 }'> <div
<div class='actions-terms-title' style='padding: 0;margin-bottom: 24px;'> 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>
<div class='actions-terms-options no-when'> <div class="actions-terms-options no-when">
<AIcon type='PlusOutlined' class='when-add-button' @click='() => addBranches(b.start + b.len)' /> <AIcon
type="PlusOutlined"
class="when-add-button"
@click="
() => addBranches(b.start + b.len)
"
/>
</div> </div>
</div> </div>
</template> </template>
@ -56,19 +82,19 @@
</j-tabs> </j-tabs>
</div> </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"
@ -78,32 +104,35 @@
/> />
</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) {
@ -130,14 +159,19 @@ const change = (e: boolean,groupItem:any,index:number) => {
// }, // },
// ] // ]
// } // }
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) {
terms: [['', 'eq', '', 'and']],
},
];
} else {
data.value.branches!.splice(start + 1, 0, null);
data.value.branches![start].when = [ data.value.branches![start].when = [
{ {
terms: [ terms: [
@ -145,7 +179,7 @@ const change = (e: boolean,groupItem:any,index:number) => {
column: undefined, column: undefined,
value: { value: {
source: 'fixed', source: 'fixed',
value: undefined value: undefined,
}, },
termType: undefined, termType: undefined,
key: `params_${randomString()}`, key: `params_${randomString()}`,
@ -155,20 +189,24 @@ const change = (e: boolean,groupItem:any,index:number) => {
type: 'and', type: 'and',
key: `terms_${randomString()}`, 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,
@ -179,28 +217,31 @@ const addBranches = (len: number) => {
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, start: index,
len: 1 len: 1,
}, -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: [
@ -210,7 +251,7 @@ const addGroup = (targetKey: string, action: string) => {
column: undefined, column: undefined,
value: { value: {
source: 'fixed', source: 'fixed',
value: undefined value: undefined,
}, },
termType: undefined, termType: undefined,
key: `params_${randomString()}`, key: `params_${randomString()}`,
@ -231,196 +272,208 @@ const addGroup = (targetKey: string, action: string) => {
then: [], then: [],
executeAnyway: true, executeAnyway: true,
branchId: key, branchId: key,
branchName: '' branchName: '',
} };
data.value.branches?.push(branchesItem, null) data.value.branches?.push(branchesItem, null);
// data.value.branches?.push(null as any) // data.value.branches?.push(null as any)
activeKey.value = key activeKey.value = key;
data.value.options!.when.push({ data.value.options!.when.push({
terms: [{ terms: [
terms: [['','eq','','and']], {
}], terms: [['', 'eq', '', 'and']],
},
],
branchName: '', branchName: '',
key, key,
executeAnyway: true, executeAnyway: true,
groupIndex: lastIndex groupIndex: lastIndex,
}) });
} else { } else {
const index = group.value.findIndex(item => item.branchId === targetKey) const index = group.value.findIndex(
groupDelete(group.value[index], index) (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 actionLen = 0;
let alarmTerms: Array<Record<string, string>> = [] let alarmTerms: Array<Record<string, string>> = [];
for (let i = g.start; i < g.start + g.len; i++) { 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) { if (item) {
item.then?.forEach(thenItem => { item.then?.forEach((thenItem) => {
actionLen += thenItem.actions.length actionLen += thenItem.actions.length;
if (thenItem.actions) { if (thenItem.actions) {
thenItem.actions.forEach((actionItem) => { thenItem.actions.forEach((actionItem) => {
const _actionId = actionItem.actionId const _actionId = actionItem.actionId;
if (actionItem.executor === 'alarm') { if (actionItem.executor === 'alarm') {
alarmTerms.push({ alarmTerms.push({
column: 'branchIndex', column: 'branchIndex',
value: _actionId || item.branchId, value: _actionId || item.branchId,
type: 'or' 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 { } else {
Modal.confirm({ Modal.confirm({
title: '该条件下有执行动作,确认删除?', title: '该条件下有执行动作,确认删除?',
onOk() { onOk() {
removeBranchesData(g, index) removeBranchesData(g, index);
} },
}) });
} }
} else { } else {
removeBranchesData(g, index) 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(
(whenItem) => whenItem.key === item.branchId,
);
if (_index !== -1) { 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) { // if (index >= 0) {
group.value.splice(index, 1) //
group.value.splice(index, 1);
if (g.id === activeKey.value) { // if (g.id === activeKey.value) {
let _moveIndex = index - 1 //
let _moveIndex = index - 1;
if (_moveIndex < 0) { // if (_moveIndex < 0) {
_moveIndex = 0 //
_moveIndex = 0;
} }
activeKey.value = group.value[_moveIndex].id activeKey.value = group.value[_moveIndex].id;
} }
} else { // } else {
const groupItem = group.value.find(item => item.id === activeKey.value) // //
groupItem!.len -= 1 const groupItem = group.value.find(
const branchesItem = data.value.branches[g.start] (item) => item.id === activeKey.value,
if (branchesItem === undefined || branchesItem?.executeAnyway) { // undefined null ); //
data.value.branches?.splice(g.start, 0, null) 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) =>{ const changeBranchName = (name: string) => {
let _activeKey = activeKey.value let _activeKey = activeKey.value;
data.value.branches?.forEach((item:any)=>{ data.value.branches?.forEach((item: any) => {
if(item?.branchId === _activeKey){ if (item?.branchId === _activeKey) {
item.branchName = name 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) { if (!optionsItem) {
const _index = group.value.findIndex(item => item.branchId === _activeKey) const _index = group.value.findIndex(
(item) => item.branchId === _activeKey,
);
if (_index !== -1) { if (_index !== -1) {
data.value.options!.when[_index].branchName = name data.value.options!.when[_index].branchName = name;
} }
} else { } else {
optionsItem.branchName = name optionsItem.branchName = name;
} }
editConditionVisible.value =false 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(() => { watchEffect(() => {
if (data.value.trigger?.device) { if (data.value.trigger?.device) {
queryColumn({ trigger: data.value.trigger }) queryColumn({ trigger: data.value.trigger });
} }
}) });
watchEffect(() => { watchEffect(() => {
const branches = data.value.branches const branches = data.value.branches;
let _group = [] let _group = [];
let _branchesIndex = 0 let _branchesIndex = 0;
if (branches) { if (branches) {
branches.forEach((item, index) => { 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) { if (!whenItem) {
whenItem = data.value.options!.when[_branchesIndex] whenItem = data.value.options!.when[_branchesIndex];
} }
if (index === 0 || item?.executeAnyway) { if (index === 0 || item?.executeAnyway) {
_group[lastIndex + 1] = { _group[lastIndex + 1] = {
id: item.branchId, id: item.branchId,
@ -429,39 +482,38 @@ watchEffect(() => {
branchKey: item.key, branchKey: item.key,
branchId: item.branchId, branchId: item.branchId,
// branchName: item.branchName || whenItem?.branchName || ` ${_branchesIndex + 1}`, // branchName: item.branchName || whenItem?.branchName || ` ${_branchesIndex + 1}`,
branchName: item.branchName || whenItem?.branchName || `条件`, branchName:
item.branchName || whenItem?.branchName || `条件`,
groupIndex: _branchesIndex, groupIndex: _branchesIndex,
openFilter: !!item.when.length openFilter: !!item.when.length,
} };
} else { } else {
_group[lastIndex].len += 1 _group[lastIndex].len += 1;
} }
if (item) { if (item) {
item.branches_Index = _branchesIndex item.branches_Index = _branchesIndex;
_branchesIndex += 1 _branchesIndex += 1;
} }
}) });
// branches.filter(item => item).forEach((item, index) => { // branches.filter(item => item).forEach((item, index) => {
// item.branches_Index = index // item.branches_Index = index
// }) // })
group.value = _group group.value = _group;
if (!activeKey.value) { if (!activeKey.value) {
activeKey.value = _group[0].id 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 {
@ -469,7 +521,7 @@ defineExpose({
} }
} }
} }
.filterConditionSwitch{ .filterConditionSwitch {
display: flex; display: flex;
gap: 16px; gap: 16px;
align-items: center; align-items: center;

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,7 +6,7 @@ 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]) {
@ -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))
if (!basicType.includes(paramsType) && paths.filter(path=>path === schemaName).length >=2 ){
paths.push(schemaName)
schemaObj.children = findData(schemas, paramsType); 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].item?.type ||
item[1].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', // 谭本地