forked from wangjiadong/comp
parent
b1843653bc
commit
055520c299
3 changed files with 159 additions and 120 deletions
@ -1,69 +1,64 @@ |
||||
<template> |
||||
<BasicModal v-bind="$attrs" title="配置路径"> |
||||
<a-directory-tree v-model:expandedKeys="expandedKeys" v-model:selectedKeys="selectedKeys" multiple |
||||
:tree-data="treeData"></a-directory-tree> |
||||
<BasicModal v-bind="$attrs" @register="register" title="配置路径" @visible-change="visChange" @ok="hanOk"> |
||||
<a-tree v-if="ifTree" v-model:expandedKeys="expandedKeys" v-model:selectedKeys="selectedKeys" |
||||
:load-data="onLoadData" @select="hanSelect" :tree-data="treeData" /> |
||||
</BasicModal> |
||||
</template> |
||||
<script lang="ts" setup> |
||||
import { BasicModal } from '/@/components/Modal'; |
||||
import { getPathApi, getPathTreeApi } from '/@/api/sys/user'; |
||||
import { BasicModal, useModalInner } from '/@/components/Modal'; |
||||
|
||||
const [register, { closeModal, setModalProps }] = useModalInner((data: any) => { |
||||
currentlySelecte.value = data.path |
||||
target.value = data.target |
||||
}) |
||||
|
||||
const ifTree = ref(true) |
||||
// tree |
||||
|
||||
import type { TreeProps } from 'ant-design-vue'; |
||||
import { ref } from 'vue'; |
||||
|
||||
const expandedKeys = ref<string[]>(['0-0', '0-1']); |
||||
import type { TreeProps } from 'ant-design-vue'; |
||||
const expandedKeys = ref<string[]>([]); |
||||
const selectedKeys = ref<string[]>([]); |
||||
const treeData: TreeProps['treeData'] = [ |
||||
{ |
||||
title: 'C:\\', |
||||
key: '0-0', |
||||
children: [ |
||||
{ |
||||
title: 'leaf 0-0', |
||||
key: '0-0-0', |
||||
children: [ |
||||
{ |
||||
title: 'child:\\', |
||||
key: '0-0-0-0', |
||||
children: [ |
||||
{ |
||||
title: 'leaf 0-0', |
||||
key: '0-0-0-0-0', |
||||
isLeaf: true, |
||||
}, |
||||
{ |
||||
title: 'leaf 0-1', |
||||
key: '0-0-0-0-1', |
||||
isLeaf: true, |
||||
}, |
||||
], |
||||
}, |
||||
] |
||||
}, |
||||
{ |
||||
title: 'leaf 0-1', |
||||
key: '0-0-1', |
||||
isLeaf: true, |
||||
}, |
||||
], |
||||
}, |
||||
{ |
||||
title: 'parent 1', |
||||
key: '0-1', |
||||
children: [ |
||||
{ |
||||
title: 'leaf 1-0', |
||||
key: '0-1-0', |
||||
isLeaf: true, |
||||
}, |
||||
{ |
||||
title: 'leaf 1-1', |
||||
key: '0-1-1', |
||||
isLeaf: true, |
||||
}, |
||||
], |
||||
}, |
||||
]; |
||||
const currentlySelecte = ref('') |
||||
const target = ref('') |
||||
|
||||
const emit = defineEmits(['confirmPath']) |
||||
function hanOk() { |
||||
closeModal() |
||||
emit('confirmPath', currentlySelecte.value, target.value) |
||||
} |
||||
|
||||
const treeData = ref<TreeProps['treeData']>(); |
||||
const onLoadData: TreeProps['loadData'] = treeNode => { |
||||
return new Promise<void>(resolve => { |
||||
if (treeNode.dataRef.children) { |
||||
resolve(); |
||||
return; |
||||
} |
||||
asGetPathApi(treeNode.key).then(res => { |
||||
treeNode.dataRef.children = res; |
||||
treeData.value = [...treeData.value]; |
||||
resolve(); |
||||
}) |
||||
}); |
||||
}; |
||||
|
||||
|
||||
|
||||
let isOne = true; |
||||
function visChange(visible) { |
||||
if (visible && isOne) { |
||||
getPathApi().then(res => { |
||||
treeData.value = res |
||||
isOne = false |
||||
}) |
||||
} |
||||
} |
||||
|
||||
function asGetPathApi(path) { |
||||
return getPathTreeApi(path); |
||||
} |
||||
function hanSelect(selectedKeys: any[]) { |
||||
currentlySelecte.value = selectedKeys[0] |
||||
} |
||||
</script> |
Loading…
Reference in new issue