feat: 组织机构按名称检索

This commit is contained in:
fit2cloud-chenyw 2021-03-12 11:31:55 +08:00
parent a708919f70
commit 311cc48341
2 changed files with 51 additions and 9 deletions

View File

@ -162,7 +162,7 @@ public class DeptService {
* @return * @return
*/ */
private List<Long> upTree(List<SimpleTreeNode> allNodes, List<SimpleTreeNode> targetNodes){ private List<Long> upTree(List<SimpleTreeNode> allNodes, List<SimpleTreeNode> targetNodes){
final Map<Long, SimpleTreeNode> map = targetNodes.stream().collect(Collectors.toMap(SimpleTreeNode::getId, node -> node)); final Map<Long, SimpleTreeNode> map = allNodes.stream().collect(Collectors.toMap(SimpleTreeNode::getId, node -> node));
List<Long> results = targetNodes.parallelStream().flatMap(targetNode -> { List<Long> results = targetNodes.parallelStream().flatMap(targetNode -> {
//向上逐级找爹 //向上逐级找爹
List<Long> ids = new ArrayList<>(); List<Long> ids = new ArrayList<>();

View File

@ -4,7 +4,7 @@
<complex-table <complex-table
ref="table" ref="table"
:data="tableData" :data="tableData"
lazy :lazy="isLazy"
:load="loadExpandDatas" :load="loadExpandDatas"
:columns="columns" :columns="columns"
:buttons="buttons" :buttons="buttons"
@ -12,6 +12,7 @@
:search-config="searchConfig" :search-config="searchConfig"
:pagination-config="paginationConfig" :pagination-config="paginationConfig"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
:default-expand-all="isTableExpand"
row-key="deptId" row-key="deptId"
@search="search" @search="search"
> >
@ -22,7 +23,7 @@
<!-- <el-table-column type="selection" fix /> --> <!-- <el-table-column type="selection" fix /> -->
<el-table-column label="名称" prop="name" /> <el-table-column label="名称" prop="name" />
<el-table-column label="下属组织数" prop="subCount" /> <el-table-column label="下属组织数" prop="subCount" />
<el-table-column label="状态" align="center" prop="enabled"> <!-- <el-table-column label="状态" align="center" prop="enabled">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
v-model="scope.row.enabled" v-model="scope.row.enabled"
@ -32,7 +33,7 @@
@change="changeEnabled(scope.row, scope.row.enabled,)" @change="changeEnabled(scope.row, scope.row.enabled,)"
/> />
</template> </template>
</el-table-column> </el-table-column> -->
<el-table-column prop="createTime" label="创建日期"> <el-table-column prop="createTime" label="创建日期">
<template v-slot:default="scope"> <template v-slot:default="scope">
<span>{{ scope.row.createTime | timestampFormatDate }}</span> <span>{{ scope.row.createTime | timestampFormatDate }}</span>
@ -47,7 +48,7 @@
:close-on-click-modal="false" :close-on-click-modal="false"
:title="formType=='add' ? $t('organization.create') : $t('organization.modify')" :title="formType=='add' ? $t('organization.create') : $t('organization.modify')"
:visible.sync="dialogOrgAddVisible" :visible.sync="dialogOrgAddVisible"
width="30%" width="500px"
:destroy-on-close="true" :destroy-on-close="true"
@closed="closeFunc" @closed="closeFunc"
> >
@ -74,7 +75,7 @@
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="enabled"> <el-form-item label="状态" prop="enabled">
<el-radio-group v-model="form.enabled" style="width: 140px"> <el-radio-group v-model="form.enabled" style="width: 140px" disabled>
<el-radio :label="true">启用</el-radio> <el-radio :label="true">启用</el-radio>
<el-radio :label="false">停用</el-radio> <el-radio :label="false">停用</el-radio>
</el-radio-group> </el-radio-group>
@ -176,15 +177,19 @@ export default {
field: 'pid', field: 'pid',
operator: 'eq', operator: 'eq',
value: 0 value: 0
} },
defaultForm: { deptId: null, top: true, enabled: true, pid: null },
isTableExpand: false,
isLazy: true
} }
}, },
activated() { activated() {
this.form = Object.assign({}, this.defaultForm)
this.search() this.search()
}, },
methods: { methods: {
create() { create() {
this.form = Object.assign({}, this.defaultForm)
this.dialogOrgAddVisible = true this.dialogOrgAddVisible = true
this.formType = 'add' this.formType = 'add'
}, },
@ -254,8 +259,20 @@ export default {
} }
return Object.assign({}, condition) return Object.assign({}, condition)
}, },
setTableAttr(isSearch) {
if (isSearch) {
this.lazy = false
this.isTableExpand = true
} else {
this.lazy = true
this.isTableExpand = false
}
},
// //
search(condition) { search(condition) {
this.setTableAttr()
this.tableData = []
let param = {} let param = {}
if (condition && condition.quick) { if (condition && condition.quick) {
const con = this.quick_condition(condition) const con = this.quick_condition(condition)
@ -273,11 +290,36 @@ export default {
} }
return obj return obj
}) })
if (condition && condition.quick) {
data = this.buildTree(data)
this.setTableAttr(true)
}
this.tableData = data this.tableData = data
this.depts = null this.depts = null
}) })
}, },
buildTree(arrs) {
const idMapping = arrs.reduce((acc, el, i) => {
acc[el.deptId] = i
return acc
}, {})
const roots = []
arrs.forEach(el => {
//
if (el.pid === null || el.pid === 0) {
roots.push(el)
return
}
//
const parentEl = arrs[idMapping[el.pid]]
// `children`
parentEl.children = [...(parentEl.children || []), el]
})
return roots
},
// //
loadExpandDatas(row, treeNode, resolve) { loadExpandDatas(row, treeNode, resolve) {
getDeptTree(row.deptId).then(res => { getDeptTree(row.deptId).then(res => {
@ -359,7 +401,7 @@ export default {
id: node.deptId, id: node.deptId,
pid: node.pid, pid: node.pid,
label: node.name, label: node.name,
children: node.children children: node.children || null
} }
}, },
// //