Skip to content

Commit

Permalink
Merge pull request #2534 from lhzzforever/dev/develop_ci_resource_tree
Browse files Browse the repository at this point in the history
fix: 处理四级数据级以上拓扑数据报错问题
  • Loading branch information
ielgnaw authored Feb 29, 2024
2 parents cad2191 + ab4abd4 commit 6a7bbcb
Show file tree
Hide file tree
Showing 40 changed files with 690 additions and 130 deletions.
24 changes: 14 additions & 10 deletions frontend/src/components/choose-ip/grade.vue
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,10 @@
params.action_system_id = this.curChain[chainLen - 1].system_id;
params.action_id = '';
} else {
params.system_id = this.curChain[node.level].system_id;
params.type = this.curChain[node.level].id;
params.action_system_id = this.curChain[node.level].system_id;
const curLevelNode = this.curChain[node.level] || this.curChain[chainLen - 1];
params.system_id = curLevelNode.system_id;
params.type = curLevelNode.id;
params.action_system_id = curLevelNode.system_id;
params.action_id = '';
}
if (node.parentChain.length) {
Expand Down Expand Up @@ -953,13 +954,14 @@
? this.curChain[node.level + 1].system_id
: this.curChain[chainLen - 1].system_id;
params.type = isExistNextChain ? this.curChain[node.level + 1].id : this.curChain[chainLen - 1].id;
parentType = this.curChain[node.level].id;
placeholder = isExistNextChain
? this.curChain[node.level + 1].name
: this.curChain[chainLen - 1].name;
ancestorItem.system_id = this.curChain[node.level].system_id;
ancestorItem.type = this.curChain[node.level].id;
if (this.curChain[node.level]) {
parentType = this.curChain[node.level].id;
ancestorItem.system_id = this.curChain[node.level].system_id;
ancestorItem.type = this.curChain[node.level].id;
}
}
ancestorItem.id = node.id;
Expand Down Expand Up @@ -993,7 +995,8 @@
name: node.name,
id: node.id,
type: parentType,
system_id: node.childType !== '' ? this.curChain[chainLen - 1].system_id : this.curChain[node.level].system_id,
system_id: !node.childType && this.curChain[node.level]
? this.curChain[node.level].system_id : this.curChain[chainLen - 1].system_id,
child_type: node.childType || ''
});
const childNodes = data.results.map(item => {
Expand Down Expand Up @@ -1131,8 +1134,9 @@
params.type = this.curChain[chainLen - 1].id;
// params.parent_type = this.curChain[chainLen - 1].id || '';
} else {
params.system_id = this.curChain[node.level].system_id;
params.type = this.curChain[node.level].id;
const curLevelNode = this.curChain[node.level] || this.curChain[chainLen - 1];
params.system_id = curLevelNode.system_id;
params.type = curLevelNode.id;
}
if (node.parentChain.length) {
const parentData = node.parentChain.reduce((p, e) => {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/choose-ip/grade/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1341,15 +1341,16 @@
} else {
// 针对用户管理的自身递归的逻辑做的兼容处理
const tempData = this.curChain[node.level + 1] ? this.curChain[node.level + 1] : this.curChain[chainLen - 1];
const curLevelNode = this.curChain[node.level] || this.curChain[chainLen - 1];
params.system_id = tempData.system_id;
params.type = tempData.id;
// params.action_system_id = tempData.system_id;
params.action_system_id = this.systemParams.system_id || '';
params.action_id = this.systemParams.action_id || '';
parentType = this.curChain[node.level] ? this.curChain[node.level].id : this.curChain[chainLen - 1].id;
parentType = curLevelNode.id;
placeholder = tempData.name;
ancestorItem.system_id = this.curChain[node.level].system_id;
ancestorItem.type = this.curChain[node.level].id;
ancestorItem.system_id = curLevelNode.system_id;
ancestorItem.type = curLevelNode.id;
}
ancestorItem.id = node.id;
if (node.parentChain.length) {
Expand Down
16 changes: 10 additions & 6 deletions frontend/src/components/choose-ip/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1076,12 +1076,14 @@
params.type = isExistNextChain
? this.curChain[node.level + 1].id
: this.curChain[chainLen - 1].id;
parentType = this.curChain[node.level].id;
placeholder = isExistNextChain
? this.curChain[node.level + 1].name
: this.curChain[chainLen - 1].name;
ancestorItem.system_id = this.curChain[node.level].system_id;
ancestorItem.type = this.curChain[node.level].id;
if (this.curChain[node.level]) {
parentType = this.curChain[node.level].id;
ancestorItem.system_id = this.curChain[node.level].system_id;
ancestorItem.type = this.curChain[node.level].id;
}
}
ancestorItem.id = node.id;
if (node.parentChain.length) {
Expand Down Expand Up @@ -1110,11 +1112,12 @@
const totalPage = Math.ceil(data.count / this.limit);
let isAsync = this.curChain.length > (curLevel + 1);
const parentChain = _.cloneDeep(node.parentChain);
const curLevelNode = this.curChain[node.level] || this.curChain[chainLen - 1];
parentChain.push({
name: node.name,
id: node.id,
type: parentType,
system_id: node.childType !== '' ? this.curChain[chainLen - 1].system_id : this.curChain[node.level].system_id,
system_id: node.childType !== '' ? this.curChain[chainLen - 1].system_id : curLevelNode.system_id,
child_type: node.childType || ''
});
const childNodes = data.results.map(item => {
Expand Down Expand Up @@ -1273,8 +1276,9 @@
params.action_id = this.systemParams.action_id || '';
// params.parent_type = this.curChain[chainLen - 1].id || '';
} else {
params.system_id = this.curChain[node.level].system_id;
params.type = this.curChain[node.level].id;
const curNode = this.curChain[node.level] ? this.curChain[node.level] : this.curChain[chainLen - 1];
params.system_id = curNode.system_id;
params.type = curNode.id;
// params.action_system_id = this.curChain[node.level].system_id;
params.action_system_id = this.systemParams.system_id || '';
params.action_id = this.systemParams.action_id || '';
Expand Down
24 changes: 17 additions & 7 deletions frontend/src/components/choose-ip/topology-tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
const asyncLevelWidth = 30;
// 左右边距各16px加上距离复选框的编剧以及当前item的padding
const paddingWidth = 32 + 10 + 12;
const distance = offsetWidth - ((payload.level + 1) * this.leftBaseIndent) - paddingWidth;
if (!payload.level) {
if (payload.loading) {
return {
Expand All @@ -518,17 +519,22 @@
} else {
if (payload.async || flag) {
return {
maxWidth: `${offsetWidth - (payload.level + 1) * this.leftBaseIndent - asyncLevelWidth - paddingWidth}px`
maxWidth: `${distance - asyncLevelWidth}px`
};
}
}
if (isSameLevelExistSync && ['search', 'search-empty'].includes(payload.type)) {
return {
maxWidth: `${offsetWidth - (payload.level + 1) * this.leftBaseIndent - paddingWidth}px`
maxWidth: `${distance}px`
};
}
if (payload.level + 1 >= 4) {
return {
maxWidth: `${distance - asyncLevelWidth - 10}px`
};
}
return {
maxWidth: `${offsetWidth - (payload.level + 1) * this.leftBaseIndent - asyncLevelWidth - paddingWidth}px`
maxWidth: `${distance - asyncLevelWidth}px`
};
};
},
Expand Down Expand Up @@ -999,8 +1005,8 @@
.map((v) => v.ids).flat(this.curChain.length);
if (defaultSelectList.length) {
let childrenIdList = [];
const result = !(defaultSelectList.includes(`${payload.id}&${this.curChain[payload.level].id}`)
|| defaultSelectList.includes(`${this.selectNodeData.id}&${this.curChain[payload.level - 1].id}`));
const result = !(defaultSelectList.includes(`${payload.id}&${this.curChain[payload.level] ? this.curChain[payload.level].id : this.curChain[this.curChain.length - 1]}`)
|| defaultSelectList.includes(`${this.selectNodeData.id}&${this.curChain[payload.level - 1] ? this.curChain[payload.level - 1].id : this.curChain[this.curChain.length - 1].id}`));
// 处理多层资源权限搜索只支持单选
if (this.resourceValue
|| (this.curSelectTreeNode.children
Expand All @@ -1026,7 +1032,9 @@
// 处理有的资源全选只能勾选一项
if (this.resourceValue && this.curSelectedValues.length) {
singleCheckedData = this.curSelectedValues.map((v) => v.ids).flat(this.curChain.length);
return singleCheckedData.includes(`${payload.id}&${this.curChain[payload.level].id}`);
const curLevelNodeId = this.curChain[payload.level]
? this.curChain[payload.level].id : this.curChain[this.curChain.length - 1].id;
return singleCheckedData.includes(`${payload.id}&${curLevelNodeId}`);
}
return !selectNodeList.includes(`${payload.name}&${payload.id}`);
},
Expand Down Expand Up @@ -1120,7 +1128,9 @@
if (this.curTreeTableData.children && this.curTreeTableData.children.length) {
const nodeItem = _.cloneDeep(this.curTreeTableData.children[0]);
if (!nodeItem.parentChain.length) {
const { id, system_id } = this.curChain[this.curTreeTableData.level];
const curLevelNode
= this.curChain[this.curTreeTableData.level] || this.curChain[this.curChain.length - 1];
const { id, system_id } = curLevelNode;
nodeItem.parentChain = [
{
name: this.curTreeTableData.name,
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export const beforeEach = async (to, from, next) => {

async function getExternalRole () {
const { role_id: externalRoleId } = to.query;
currentRoleId = externalRoleId;
curRoleId = externalRoleId;
try {
await store.dispatch('role/updateCurrentRole', { id: Number(externalRoleId) });
await store.dispatch('userInfo');
Expand Down Expand Up @@ -135,8 +137,9 @@ export const beforeEach = async (to, from, next) => {
window.localStorage.setItem('index', index);
}

// 如果进入没有权限,重新找roleList
if (['', 'staff'].includes(curRole) && navIndex > 0) {
// 如果进入没有权限,重新找roleList, 蓝盾交互不需要判断
const isEXternal = !(existValue('externalApp') || to.query.hasOwnProperty('role_id'));
if (['', 'staff'].includes(curRole) && navIndex > 0 && isEXternal) {
const roleList = await store.dispatch('roleList', {
cancelWhenRouteChange: false,
cancelPrevious: false
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/views/group/add-perm/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@
},
handleAddCancel (payload) {
const { customPerm } = payload;
const { customPerm, templateList } = payload;
if (customPerm) {
this.hasAddCustomList = [...customPerm];
if (!customPerm.length) {
if (!customPerm.length && !templateList.length) {
this.tableList = [];
this.tableListBackup = [];
}
Expand Down Expand Up @@ -849,7 +849,7 @@
this.isShowAddActionSideslider = true;
} else {
this.isShowAddSideslider = true;
this.permSideWidth = 1160;
this.permSideWidth = 960;
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/views/group/components/add-action-sideslider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<script>
import _ from 'lodash';
import { leaveConfirm } from '@/common/leave-confirm';
import { guid, formatCodeData } from '@/common/util';
import { guid, formatCodeData, existValue } from '@/common/util';
import RenderActionTag from '@/components/common-action';
import { mapGetters } from 'vuex';
import { bus } from '@/common/bus';
Expand Down Expand Up @@ -674,7 +674,9 @@
}
let allChecked = true;
let allDisabled = true;
// item.actions = item.actions.filter(v => !v.hidden);
if (existValue('externalApp') || this.externalSystemId) {
item.actions = item.actions.filter(v => !v.hidden);
}
item.actions.forEach(act => {
act.$id = `${payload}&${act.id}`;
act.related_resource_types.forEach(v => {
Expand All @@ -693,7 +695,9 @@
this.linearAction.push(act);
});
item.sub_groups.forEach(act => {
// act.actions = act.actions.filter(v => !v.hidden);
if (existValue('externalApp') || this.externalSystemId) {
act.actions = act.actions.filter(v => !v.hidden);
}
(act.actions || []).forEach(v => {
v.$id = `${payload}&${v.id}`;
v.related_resource_types.forEach(subItem => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@
}
cancelHandler.then(() => {
this.$emit('update:isShow', false);
this.$emit('on-cancel', { customPerm: this.customPerm });
this.$emit('on-cancel', { customPerm: this.customPerm, templateList: this.tempalteDetailList });
this.resetData();
}, _ => _);
} else {
this.$emit('on-cancel', { customPerm: this.customPerm });
this.$emit('on-cancel', { customPerm: this.customPerm, templateList: this.tempalteDetailList });
this.$emit('update:isShow', false);
}
},
Expand Down
26 changes: 16 additions & 10 deletions frontend/src/views/group/components/render-instance-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
@row-mouse-enter="handleRowMouseEnter"
@row-mouse-leave="handleRowMouseLeave">
<!-- eslint-disable max-len -->
<bk-table-column :resizable="false" :label="$t(`m.common['模板名称']`)" width="180" v-if="isCreateMode">
<bk-table-column :resizable="false" :label="$t(`m.common['模板名称']`)" v-if="isCreateMode">
<template slot-scope="{ row }">
<span>{{ !!row.isAggregate ? row.actions[0].detail.name || row.actions[0].displayName : row.displayName }}</span>
</template>
</bk-table-column>
<bk-table-column :resizable="false" :label="$t(`m.common['操作']`)" width="180">
<bk-table-column :resizable="false" :label="$t(`m.common['操作']`)">
<template slot-scope="{ row }">
<div v-if="!!row.isAggregate" style="padding: 10px 0;">
<span class="action-name" :title="row.name">{{ row.name }}</span>
Expand All @@ -26,12 +26,12 @@
</div>
</template>
</bk-table-column>
<bk-table-column :resizable="false" :label="$t(`m.common['所属系统']`)" width="180" v-if="isCreateMode">
<bk-table-column :resizable="false" :label="$t(`m.common['所属系统']`)" v-if="isCreateMode">
<template slot-scope="{ row }">
<span>{{ !!row.isAggregate ? row.system_name : row.detail.system.name }}</span>
</template>
</bk-table-column>
<bk-table-column :resizable="false" :label="$t(`m.common['资源实例']`)" min-width="450">
<bk-table-column :resizable="false" :label="$t(`m.common['资源实例']`)" :min-width="450">
<template slot-scope="{ row, $index }">
<template v-if="!isEdit">
<template v-if="!row.isEmpty">
Expand Down Expand Up @@ -851,8 +851,7 @@
if (customData) {
const curCondition = customData.resource_groups[this.curGroupIndex]
.related_resource_types[this.curResIndex].conditionBackup;
// conditionBackup代表的是接口返回的缓存数据,处理新增未提交的资源实例删除
console.log(curCondition, 5655);
// conditionBackup代表的是接口返回的缓存数据,处理新增未提交的资源实例删
const curPaths
= curCondition.length
&& curCondition.reduce((prev, next) => {
Expand Down Expand Up @@ -1854,8 +1853,12 @@
? attribute.map(({ id, name, values }) => ({ id, name, values }))
: [];
const instanceList = (instance && instance.length > 0)
? instance.map(({ name, type, paths }) => {
const tempPath = _.cloneDeep(paths);
? instance.map(({ name, type, path, paths }) => {
// 这里paths和path存在数据不同步问题,所以当paths为空时,需要判断path是否存在数据
let tempPath = _.cloneDeep(paths);
if (!tempPath.length && path && path.length) {
tempPath = _.cloneDeep(path);
}
tempPath.forEach(pathItem => {
pathItem.forEach(pathSubItem => {
delete pathSubItem.disabled;
Expand Down Expand Up @@ -1998,8 +2001,11 @@
? attribute.map(({ id, name, values }) => ({ id, name, values }))
: [];
const instanceList = (instance && instance.length > 0)
? instance.map(({ name, type, paths }) => {
const tempPath = _.cloneDeep(paths);
? instance.map(({ name, type, path, paths }) => {
let tempPath = _.cloneDeep(paths);
if (!tempPath.length && path && path.length) {
tempPath = _.cloneDeep(path);
}
tempPath.forEach(pathItem => {
pathItem.forEach(pathSubItem => {
delete pathSubItem.disabled;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/group/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@
* handleAddCancel
*/
handleAddCancel (payload) {
const { customPerm } = payload;
const { customPerm, templateList } = payload;
if (customPerm) {
this.hasAddCustomList = [...customPerm];
if (!customPerm.length) {
if (!customPerm.length && !templateList.length) {
this.tableList = [];
this.tableListBackup = [];
}
Expand Down
Loading

0 comments on commit 6a7bbcb

Please sign in to comment.