Commit 59a3065b authored by 何小勇's avatar 何小勇

组织树优化

parent 21251d37
...@@ -281,7 +281,7 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -281,7 +281,7 @@ import { downloadFileFormatNew } from '@/services/helper'
router.push({ router.push({
path: "/system/organization/org-detail", path: "/system/organization/org-detail",
query: { query: {
id: selectTreeData.value.organization_id id: selectOrgNode.value.organization_id
} }
}) })
...@@ -389,7 +389,9 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -389,7 +389,9 @@ import { downloadFileFormatNew } from '@/services/helper'
const tableTotal = ref(0); const tableTotal = ref(0);
const orgTree = ref(null); const orgTree = ref(null);
const selectTreeData = ref(null) const selectTreeData = ref(null)
const actionTreeData = ref(null)
const selectTreeDataType = ref(2); const selectTreeDataType = ref(2);
const selectOrgNode = ref(null);
const dialogDelNode = ref(false) const dialogDelNode = ref(false)
const router = useRouter(); const router = useRouter();
const filter = reactive({ const filter = reactive({
...@@ -437,7 +439,7 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -437,7 +439,7 @@ import { downloadFileFormatNew } from '@/services/helper'
router.push({ router.push({
path: "/system/organization/org-user", path: "/system/organization/org-user",
query: { query: {
orgId: selectTreeData.value.organization_id orgId: selectOrgNode.value.organization_id
} }
}) })
}else { }else {
...@@ -448,11 +450,6 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -448,11 +450,6 @@ import { downloadFileFormatNew } from '@/services/helper'
} }
} }
const treeSelected = ref(null);
const handleNodeClick = (data) => {
treeSelected.value = data.dept
console.log(treeSelected.value)
}
const changeSize = (size) => { const changeSize = (size) => {
...@@ -507,7 +504,7 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -507,7 +504,7 @@ import { downloadFileFormatNew } from '@/services/helper'
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
$message.success(res.data.msg) $message.success(res.data.msg)
orgTree.value.getOrgTree(); orgTree.value.getOrgTree(res.data.data.id);
}else { }else {
$message.error(res.data.data) $message.error(res.data.data)
} }
...@@ -518,11 +515,11 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -518,11 +515,11 @@ import { downloadFileFormatNew } from '@/services/helper'
name: data.name, name: data.name,
data_type: 0 data_type: 0
} }
$axios.put(`/apaas/system/v5/org/${selectTreeData.value.id}`, params) $axios.put(`/apaas/system/v5/org/${actionTreeData.value.id}`, params)
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
$message.success(res.data.msg) $message.success(res.data.msg)
orgTree.value.getOrgTree(); orgTree.value.getOrgTree(actionTreeData.value.id);
}else { }else {
$message.error(res.data.data) $message.error(res.data.data)
} }
...@@ -557,7 +554,7 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -557,7 +554,7 @@ import { downloadFileFormatNew } from '@/services/helper'
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
$message.success(res.data.msg) $message.success(res.data.msg)
orgTree.value.getOrgTree(); orgTree.value.getOrgTree(res.data.data.id);
}else { }else {
$message.error(res.data.data) $message.error(res.data.data)
} }
...@@ -572,11 +569,11 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -572,11 +569,11 @@ import { downloadFileFormatNew } from '@/services/helper'
attachment: data.attachment && data.attachment.length > 0 ? data.attachment.map(item => item.url).join(',') : '', attachment: data.attachment && data.attachment.length > 0 ? data.attachment.map(item => item.url).join(',') : '',
data_type: 1 data_type: 1
} }
$axios.put(`/apaas/system/v5/org/${selectTreeData.value.id}`, params) $axios.put(`/apaas/system/v5/org/${actionTreeData.value.id}`, params)
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
$message.success(res.data.msg) $message.success(res.data.msg)
orgTree.value.getOrgTree(); orgTree.value.getOrgTree(actionTreeData.value.id);
}else { }else {
$message.error(res.data.data) $message.error(res.data.data)
} }
...@@ -592,11 +589,11 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -592,11 +589,11 @@ import { downloadFileFormatNew } from '@/services/helper'
//删除目录/组织 //删除目录/组织
const confirmDelNode = () => { const confirmDelNode = () => {
$axios.delete(`/apaas/system/v5/org/${selectTreeData.value.id}`) $axios.delete(`/apaas/system/v5/org/${actionTreeData.value.id}`)
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
$message.success(res.data.msg) $message.success(res.data.msg)
orgTree.value.getOrgTree(); orgTree.value.getOrgTree(actionTreeData.value.id === selectTreeData.value.id ? null : selectTreeData.value.id);
}else { }else {
$message.error(res.data.data) $message.error(res.data.data)
} }
...@@ -609,7 +606,7 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -609,7 +606,7 @@ import { downloadFileFormatNew } from '@/services/helper'
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
$message.success(res.data.msg) $message.success(res.data.msg)
orgTree.value.getOrgTree(); orgTree.value.getOrgTree(selectTreeData.value.id);
}else { }else {
$message.error(res.data.data) $message.error(res.data.data)
} }
...@@ -662,10 +659,15 @@ import { downloadFileFormatNew } from '@/services/helper' ...@@ -662,10 +659,15 @@ import { downloadFileFormatNew } from '@/services/helper'
} }
const treeSelect = (data) => { const treeSelect = (data) => {
selectTreeData.value = data.value; if(data.type === 'action') {
if(data.value.data_type === 1 || data.value.data_type === 2) { actionTreeData.value = data.data.value;
selectTreeDataType.value = data.value.data_type; }else {
selectTreeData.value = data.data.value;
}
if(data.type === 'click' && (data.data.value.data_type === 1 || data.data.value.data_type === 2)) {
selectTreeDataType.value = data.data.value.data_type;
selectOrgNode.value = data.data.value;
getTableRows(); getTableRows();
} }
} }
......
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
node-key="id" node-key="id"
:highlight-current="true" :highlight-current="true"
:filter-node-method="filterNode" :filter-node-method="filterNode"
:expand-on-click-node="false"
:default-expand-all="true"> :default-expand-all="true">
<template #default="{ node, data }"> <template #default="{ node, data }">
<div class="custom_tree_node"> <div class="custom_tree_node">
<span <span
class="label-text " class="label-text "
:class="{'is_active': selectData && selectData.id === data.id}"
:title="data.name" :title="data.name"
>{{ data.name }} >{{ data.name }}
</span> </span>
...@@ -48,14 +49,14 @@ ...@@ -48,14 +49,14 @@
<div v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'org',action: 'create',target: 'child'})">新建下级组织</div> <div v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'org',action: 'create',target: 'child'})">新建下级组织</div>
<div v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'directory',action: 'edit',target: 'local'})">编辑目录</div> <div v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'directory',action: 'edit',target: 'local'})">编辑目录</div>
<div v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'directory',action: 'delete',target: 'local'})">删除</div> <div v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'directory',action: 'delete',target: 'local'})">删除</div>
<div v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'directory',action: 'mvup',target: 'local'})">上移</div> <div :class="{'disable': mvDataParent.indexOf(selectData) === 0 }" v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'directory',action: 'mvup',target: 'local'})">上移</div>
<div v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'directory',action: 'mvdown',target: 'local'})">下移</div> <div :class="{'disable': mvDataParent.indexOf(selectData) === (mvDataParent.length-1) }" v-if="selectData && selectData.data_type === 0" class="action" @click="treeAction({type: 'directory',action: 'mvdown',target: 'local'})">下移</div>
<!-- 组织 --> <!-- 组织 -->
<div v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'create',target: 'local'})">新建本级组织</div> <div v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'create',target: 'local'})">新建本级组织</div>
<div v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'edit',target: 'local'})">编辑组织</div> <div v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'edit',target: 'local'})">编辑组织</div>
<div v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'delete',target: 'local'})">删除</div> <div v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'delete',target: 'local'})">删除</div>
<div v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'mvup',target: 'local'})">上移</div> <div :class="{'disable': mvDataParent.indexOf(selectData) === 0 }" v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'mvup',target: 'local'})">上移</div>
<div v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'mvdown',target: 'local'})">下移</div> <div :class="{'disable': mvDataParent.indexOf(selectData) === (mvDataParent.length-1) }" v-if="selectData && selectData.data_type === 1" class="action" @click="treeAction({type: 'org',action: 'mvdown',target: 'local'})">下移</div>
</div> </div>
</Teleport> </Teleport>
</template> </template>
...@@ -83,15 +84,21 @@ import { useRouter } from 'vue-router'; ...@@ -83,15 +84,21 @@ import { useRouter } from 'vue-router';
value: 'organization_id' value: 'organization_id'
} }
const getOrgTree = () => { const getOrgTree = (data) => {
$axios.get(`/apaas/system/v5/org/tree`) $axios.get(`/apaas/system/v5/org/tree`)
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
orgData.value = res.data.data || []; orgData.value = res.data.data || [];
if(data) {
nextTick(() =>{ nextTick(() =>{
treeRef.value.setCurrentNode(orgData.value[0],true) setCurrentNode(data)
emit('select',ref(orgData.value[0]));
}) })
}else {
nextTick(() =>{
setCurrentNode(orgData.value[0].id)
})
}
}else { }else {
$message.error(res.data.data) $message.error(res.data.data)
...@@ -104,6 +111,19 @@ import { useRouter } from 'vue-router'; ...@@ -104,6 +111,19 @@ import { useRouter } from 'vue-router';
treeRef.value.filter(val) treeRef.value.filter(val)
} }
const setCurrentNode = (data) => {
if(data) {
treeRef.value.setCurrentKey(data,true);
const curNode = treeRef.value.getCurrentNode();
emit('select',{data:ref(curNode),type: 'click'});
}else {
treeRef.value.setCurrentKey(orgData.value[0].id,true);
const curNode = treeRef.value.getCurrentNode();
emit('select',{data:ref(curNode),type: 'click'});
}
}
const filterNode = (value, data) => { const filterNode = (value, data) => {
if (!value) return true if (!value) return true
return data.name.includes(value) return data.name.includes(value)
...@@ -136,13 +156,13 @@ import { useRouter } from 'vue-router'; ...@@ -136,13 +156,13 @@ import { useRouter } from 'vue-router';
const emit = defineEmits(['action','select']) const emit = defineEmits(['action','select'])
const handleNodeClick = (node,nodeAttr,treeNode,event) => { const handleNodeClick = (node,nodeAttr,treeNode,event) => {
selectData.value = node; selectData.value = node;
emit('select',selectData); emit('select',{data: selectData,type: 'click'});
//只读则无操作事件 //只读则无操作事件
closeAction(); closeAction();
} }
const treeAction = (params) => { const treeAction = (params) => {
emit('select',selectData); emit('select',{data:selectData,type: 'action'});
let data = null; let data = null;
if(params.action === 'create') { if(params.action === 'create') {
if(params.target === 'local') { if(params.target === 'local') {
...@@ -154,7 +174,7 @@ import { useRouter } from 'vue-router'; ...@@ -154,7 +174,7 @@ import { useRouter } from 'vue-router';
} }
}else if(params.action === 'mvup') { }else if(params.action === 'mvup') {
if(mvDataParent.value.indexOf(selectData.value) === 0) { if(mvDataParent.value.indexOf(selectData.value) === 0) {
$message.error('已经是第一个元素,不可上移') // $message.error('已经是第一个元素,不可上移')
return 0; return 0;
}else { }else {
let brother = mvDataParent.value[mvDataParent.value.indexOf(selectData.value) - 1]; let brother = mvDataParent.value[mvDataParent.value.indexOf(selectData.value) - 1];
...@@ -163,7 +183,7 @@ import { useRouter } from 'vue-router'; ...@@ -163,7 +183,7 @@ import { useRouter } from 'vue-router';
}else if(params.action === 'mvdown') { }else if(params.action === 'mvdown') {
if(mvDataParent.value.indexOf(selectData.value) === (mvDataParent.value.length-1)) { if(mvDataParent.value.indexOf(selectData.value) === (mvDataParent.value.length-1)) {
$message.error('已经是最后一个元素,不可下移') // $message.error('已经是最后一个元素,不可下移')
return 0; return 0;
}else { }else {
let brother = mvDataParent.value[mvDataParent.value.indexOf(selectData.value) + 1]; let brother = mvDataParent.value[mvDataParent.value.indexOf(selectData.value) + 1];
...@@ -190,7 +210,7 @@ import { useRouter } from 'vue-router'; ...@@ -190,7 +210,7 @@ import { useRouter } from 'vue-router';
}) })
defineExpose({getOrgTree, filterTree }) defineExpose({getOrgTree, filterTree, setCurrentNode })
</script> </script>
...@@ -302,4 +322,13 @@ import { useRouter } from 'vue-router'; ...@@ -302,4 +322,13 @@ import { useRouter } from 'vue-router';
height: 36px!important; height: 36px!important;
} }
.tree-action .disable{
cursor: not-allowed;
color: #616f94;
}
.tree-action .disable:hover{
background-color: #fff;
color: #616f94;
}
</style> </style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment