refactor(tree): 树形组件重构优化暂存
This commit is contained in:
parent
520ac36d24
commit
44a19891c8
@ -119,7 +119,7 @@ export default {
|
|||||||
:::
|
:::
|
||||||
|
|
||||||
| Name | Description | Accepted Values |
|
| Name | Description | Accepted Values |
|
||||||
| ------- | -------- | -------------- |
|
| ----------- | ----------- | --------------- |
|
||||||
| v-model | 当前激活 | -- |
|
| v-model | 当前激活 | -- |
|
||||||
| type | 主题样式 | -- |
|
| type | 主题样式 | -- |
|
||||||
| allow-close | 允许关闭 | `true` `false` |
|
| allow-close | 允许关闭 | `true` `false` |
|
||||||
@ -129,6 +129,6 @@ export default {
|
|||||||
:::
|
:::
|
||||||
|
|
||||||
| Name | Description | Accepted Params |
|
| Name | Description | Accepted Params |
|
||||||
| -------- | ---- | ----------------------- |
|
| ------ | ----------- | --------------- |
|
||||||
| change | 选中切换 | -- |
|
| change | 选中切换 | -- |
|
||||||
| close | 关闭事件 | -- |
|
| close | 关闭事件 | -- |
|
||||||
|
@ -68,29 +68,37 @@ const nodeIconType = (node: TreeData): string => {
|
|||||||
return 'layui-icon-file'
|
return 'layui-icon-file'
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleNodeClick (args: { label: string, value: string }, node: TreeData) {
|
function handleNodeClick(
|
||||||
|
args: { label: string; value: string },
|
||||||
|
node: TreeData
|
||||||
|
) {
|
||||||
emit('node-click', args, node)
|
emit('node-click', args, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
function recursiveNodeClick (args: { label: string, value: string }, node: TreeData) {
|
function recursiveNodeClick(
|
||||||
|
args: { label: string; value: string },
|
||||||
|
node: TreeData
|
||||||
|
) {
|
||||||
emit('node-click', args, node)
|
emit('node-click', args, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setChildrenChecked (checked: boolean, nodes: TreeData[]) {
|
function setChildrenChecked(checked: boolean, nodes: TreeData[]) {
|
||||||
const len = nodes.length
|
const len = nodes.length
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
nodes[i].isChecked.value = checked
|
nodes[i].isChecked.value = checked
|
||||||
nodes[i].children && nodes[i].children.length > 0 && (setChildrenChecked(checked, nodes[i].children))
|
nodes[i].children &&
|
||||||
|
nodes[i].children.length > 0 &&
|
||||||
|
setChildrenChecked(checked, nodes[i].children)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setParentChecked (checked: boolean, parent: TreeData) {
|
function setParentChecked(checked: boolean, parent: TreeData) {
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
parent.isChecked.value = checked
|
parent.isChecked.value = checked
|
||||||
const pChild = parent.children
|
const pChild = parent.children
|
||||||
const pChildChecked = pChild.some(c => c.isChecked.value)
|
const pChildChecked = pChild.some((c) => c.isChecked.value)
|
||||||
if (pChildChecked) {
|
if (pChildChecked) {
|
||||||
parent.isChecked.value = true
|
parent.isChecked.value = true
|
||||||
}
|
}
|
||||||
@ -111,7 +119,7 @@ function handleChange(checked: boolean, node: TreeData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleIconClick (node: TreeData) {
|
function handleIconClick(node: TreeData) {
|
||||||
node.isLeaf.value = !node.isLeaf.value
|
node.isLeaf.value = !node.isLeaf.value
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -134,17 +142,18 @@ function handleIconClick (node: TreeData) {
|
|||||||
{ 'layui-tree-iconClick': true },
|
{ 'layui-tree-iconClick': true },
|
||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<LayIcon
|
<LayIcon :type="nodeIconType(node)" @click="handleIconClick(node)" />
|
||||||
:type="nodeIconType(node)"
|
|
||||||
@click="handleIconClick(node)"
|
|
||||||
/>
|
|
||||||
</span>
|
</span>
|
||||||
<LayCheckbox
|
<LayCheckbox
|
||||||
v-if="showCheckbox"
|
v-if="showCheckbox"
|
||||||
v-model:checked="node.isChecked.value"
|
v-model:checked="node.isChecked.value"
|
||||||
:disabled="node.isDisabled.value"
|
:disabled="node.isDisabled.value"
|
||||||
skin="primary"
|
skin="primary"
|
||||||
@change="({ checked }) => { handleChange(checked, node) }"
|
@change="
|
||||||
|
({ checked }) => {
|
||||||
|
handleChange(checked, node)
|
||||||
|
}
|
||||||
|
"
|
||||||
>
|
>
|
||||||
</LayCheckbox>
|
</LayCheckbox>
|
||||||
<span
|
<span
|
||||||
|
@ -57,7 +57,7 @@ function getNode(
|
|||||||
|
|
||||||
const parent = nodeMap.get(parentKey)
|
const parent = nodeMap.get(parentKey)
|
||||||
if (parent) {
|
if (parent) {
|
||||||
console.log(parent.isChecked.value);
|
console.log(parent.isChecked.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log((parent && parent.isChecked.value) || checkedKeys.includes(nodeKey))
|
// console.log((parent && parent.isChecked.value) || checkedKeys.includes(nodeKey))
|
||||||
|
Loading…
Reference in New Issue
Block a user