|
|
@ -21,11 +21,9 @@ |
|
|
|
<ns-icon name="actionMore" size="14" class="actionMore" /> |
|
|
|
<template #overlay> |
|
|
|
<a-menu> |
|
|
|
<template v-for="(item, index) in actionList" :key="index"> |
|
|
|
<template v-for="(item, index) in filterAction(actionList, data)" :key="index"> |
|
|
|
<!-- 全部节点只需要新增子节点 --> |
|
|
|
<a-menu-item |
|
|
|
v-if="data.id !== 'all' || item.key === 'addNodeSon'" |
|
|
|
@click="item.func(data)"> |
|
|
|
<a-menu-item @click="item.func(data)"> |
|
|
|
<span>{{ item.title }}</span> |
|
|
|
</a-menu-item> |
|
|
|
</template> |
|
|
@ -82,10 +80,12 @@ |
|
|
|
|
|
|
|
const addNodeSon = (data) => { |
|
|
|
console.log(data); |
|
|
|
|
|
|
|
nsModalFormConfig.value.title = '新增'; |
|
|
|
nsModalFormConfig.value.data = { |
|
|
|
isCreate: true, |
|
|
|
orgId: result, |
|
|
|
energyType: data.formModel?.energyType, |
|
|
|
}; |
|
|
|
if (data.id !== 'all') { |
|
|
|
nsModalFormConfig.value.data.pid = data.id; |
|
|
@ -94,13 +94,18 @@ |
|
|
|
modalFormRef.value?.toggle(); |
|
|
|
}; |
|
|
|
const editNode = (data) => { |
|
|
|
console.log(data); |
|
|
|
nsModalFormConfig.value.title = '编辑'; |
|
|
|
setTimeout(() => { |
|
|
|
nsModalFormConfig.value.data = data; |
|
|
|
}, 1); |
|
|
|
modalFormRef.value?.toggle(); |
|
|
|
}; |
|
|
|
const moveNode = (data, type: opType) => { |
|
|
|
console.log(data); |
|
|
|
const flag = type === 'up'; |
|
|
|
http.post(group.move, { ...data, isUp: flag }).then(() => { |
|
|
|
treeRef.value?.treeReload(); |
|
|
|
NsMessage.success('操作成功'); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
const deleteNode = (record) => { |
|
|
@ -111,12 +116,33 @@ |
|
|
|
onOk: () => { |
|
|
|
http.post(group.del, { id: record.id }).then(() => { |
|
|
|
treeRef.value?.treeReload(); |
|
|
|
NsMessage.success('删除成功'); |
|
|
|
treeRef.value?.clearSelectedKeys(); |
|
|
|
NsMessage.success('操作成功'); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}); |
|
|
|
}; |
|
|
|
const filterAction = (data) => {}; |
|
|
|
const filterAction = (actions, data) => { |
|
|
|
let list: string | any[] = ['addNodeSon', 'editNode', 'deleteNode']; |
|
|
|
//判断逻辑先后不可颠倒 |
|
|
|
// 最后一个以及中间的不会包含isFirst,即支持上移 |
|
|
|
if (!data?.isFirst) { |
|
|
|
list.push('moveUp'); |
|
|
|
} |
|
|
|
// 第一个以及中间的不会包含isEnd,即支持下移 |
|
|
|
if (!data?.isEnd) { |
|
|
|
list.push('moveDown'); |
|
|
|
} |
|
|
|
// 只有一条即不支持上移也不支持下移 |
|
|
|
if (data.isOnlyOne) { |
|
|
|
list = ['addNodeSon', 'editNode', 'deleteNode']; |
|
|
|
} |
|
|
|
// 全部根节点 |
|
|
|
if (data.id === 'all') { |
|
|
|
list = ['addNodeSon']; |
|
|
|
} |
|
|
|
return actions.filter(({ key }) => list.includes(key)); |
|
|
|
}; |
|
|
|
const actionList = [ |
|
|
|
{ title: '新增子节点', key: 'addNodeSon', func: (data) => addNodeSon(data) }, |
|
|
|
{ title: '编辑', key: 'editNode', func: (data) => editNode(data) }, |
|
|
|