mirror of https://github.com/veops/cmdb.git
feat: update model export
This commit is contained in:
parent
688f4e0ea4
commit
dd4f3b0e9c
|
@ -33,7 +33,7 @@
|
||||||
>
|
>
|
||||||
<template
|
<template
|
||||||
slot="children"
|
slot="children"
|
||||||
slot-scope="{ props: { direction, selectedKeys }, on: { itemSelect } }"
|
slot-scope="{ props: { direction, selectedKeys }, on: { itemSelect, itemSelectAll } }"
|
||||||
>
|
>
|
||||||
<a-tree
|
<a-tree
|
||||||
v-if="direction === 'left'"
|
v-if="direction === 'left'"
|
||||||
|
@ -41,15 +41,15 @@
|
||||||
checkable
|
checkable
|
||||||
:checkedKeys="[...selectedKeys, ...targetKeys]"
|
:checkedKeys="[...selectedKeys, ...targetKeys]"
|
||||||
:treeData="treeData"
|
:treeData="treeData"
|
||||||
:checkStrictly="true"
|
:checkStrictly="false"
|
||||||
@check="
|
@check="
|
||||||
(_, props) => {
|
(_, props) => {
|
||||||
onChecked(_, props, [...selectedKeys, ...targetKeys], itemSelect);
|
onChecked(_, props, [...selectedKeys, ...targetKeys], itemSelect, itemSelectAll);
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
@select="
|
@select="
|
||||||
(_, props) => {
|
(_, props) => {
|
||||||
onChecked(_, props, [...selectedKeys, ...targetKeys], itemSelect);
|
onChecked(_, props, [...selectedKeys, ...targetKeys], itemSelect, itemSelectAll);
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
|
@ -108,7 +108,6 @@ export default {
|
||||||
key,
|
key,
|
||||||
title: child?.alias || child?.name || this.$t('other'),
|
title: child?.alias || child?.name || this.$t('other'),
|
||||||
disabled,
|
disabled,
|
||||||
checkable: true,
|
|
||||||
children: []
|
children: []
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -118,8 +117,6 @@ export default {
|
||||||
children,
|
children,
|
||||||
childrenKeys,
|
childrenKeys,
|
||||||
disabled: children.every((item) => item.disabled),
|
disabled: children.every((item) => item.disabled),
|
||||||
checkable: false,
|
|
||||||
selectable: false
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log('treeData', newTreeData)
|
console.log('treeData', newTreeData)
|
||||||
|
@ -130,13 +127,40 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onChange(targetKeys, direction, moveKeys) {
|
onChange(targetKeys, direction, moveKeys) {
|
||||||
this.targetKeys = targetKeys
|
const childKeys = []
|
||||||
|
const newTargetKeys = [...targetKeys]
|
||||||
|
|
||||||
|
if (direction === 'right') {
|
||||||
|
// 如果是选中父节点,添加时去除父节点,添加其子节点
|
||||||
|
this.treeData.forEach((item) => {
|
||||||
|
const parentIndex = newTargetKeys.findIndex((key) => item.key === key)
|
||||||
|
if (parentIndex !== -1) {
|
||||||
|
newTargetKeys.splice(parentIndex, 1)
|
||||||
|
childKeys.push(...item.childrenKeys)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniqTargetKeys = _.uniq([...newTargetKeys, ...childKeys])
|
||||||
|
this.targetKeys = uniqTargetKeys
|
||||||
},
|
},
|
||||||
onChecked(_, e, checkedKeys, itemSelect) {
|
onChecked(_, e, checkedKeys, itemSelect, itemSelectAll) {
|
||||||
const { eventKey } = e.node
|
const { eventKey } = e.node
|
||||||
const selected = checkedKeys.indexOf(eventKey) === -1
|
const selected = checkedKeys.indexOf(eventKey) === -1
|
||||||
|
const childrenKeys = this.treeData.find((item) => item.key === eventKey)?.childrenKeys || []
|
||||||
|
|
||||||
itemSelect(eventKey, selected)
|
// 如果当前点击是子节点,处理其联动父节点
|
||||||
|
this.treeData.forEach((item) => {
|
||||||
|
if (item.childrenKeys.includes(eventKey)) {
|
||||||
|
if (selected && item.childrenKeys.every((childKey) => [eventKey, ...checkedKeys].includes(childKey))) {
|
||||||
|
itemSelect(item.key, true)
|
||||||
|
} else if (!selected) {
|
||||||
|
itemSelect(item.key, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
itemSelectAll([eventKey, ...childrenKeys], selected)
|
||||||
},
|
},
|
||||||
handleCancel() {
|
handleCancel() {
|
||||||
this.$emit('cancel')
|
this.$emit('cancel')
|
||||||
|
@ -187,14 +211,26 @@ export default {
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.model-export-transfer {
|
.model-export-transfer {
|
||||||
/deep/ .ant-transfer-list-body {
|
/deep/ .ant-transfer-list {
|
||||||
overflow: auto;
|
.ant-transfer-list-body {
|
||||||
}
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
/deep/ .ant-transfer-list-header-title {
|
&:first-child {
|
||||||
color: @primary-color;
|
.ant-transfer-list-header {
|
||||||
font-weight: 400;
|
.ant-transfer-list-header-selected {
|
||||||
font-size: 12px;
|
span:first-child {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-transfer-list-header-title {
|
||||||
|
color: @primary-color;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue