提交 d99229dd authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

refactor: 优化分享组织树

上级 a065ffda
...@@ -5,6 +5,7 @@ import com.github.pagehelper.Page; ...@@ -5,6 +5,7 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.auth.api.dto.CurrentUserDto; import io.dataease.auth.api.dto.CurrentUserDto;
import io.dataease.base.domain.SysRole;
import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.PageUtils; import io.dataease.commons.utils.PageUtils;
import io.dataease.commons.utils.Pager; import io.dataease.commons.utils.Pager;
...@@ -116,4 +117,14 @@ public class SysUserController { ...@@ -116,4 +117,14 @@ public class SysUserController {
public List<RoleUserItem> all(){ public List<RoleUserItem> all(){
return sysRoleService.allRoles(); return sysRoleService.allRoles();
} }
@ApiOperation("查询角色")
@PostMapping("/roleGrid/{goPage}/{pageSize}")
public Pager<List<SysRole>> roleGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody BaseGridRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
Pager<List<SysRole>> listPager = PageUtils.setPageInfo(page, sysRoleService.query(request));
return listPager;
}
} }
...@@ -5,9 +5,11 @@ package io.dataease.service.sys; ...@@ -5,9 +5,11 @@ package io.dataease.service.sys;
import io.dataease.base.domain.SysUsersRolesExample; import io.dataease.base.domain.SysUsersRolesExample;
import io.dataease.base.mapper.SysRoleMapper; import io.dataease.base.mapper.SysRoleMapper;
import io.dataease.base.mapper.SysUsersRolesMapper;*/ import io.dataease.base.mapper.SysUsersRolesMapper;*/
import io.dataease.base.domain.SysRole;
import io.dataease.base.mapper.ext.ExtSysRoleMapper; import io.dataease.base.mapper.ext.ExtSysRoleMapper;
/*import io.dataease.controller.sys.base.BaseGridRequest; /*import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.controller.sys.request.RoleMenusRequest;*/ import io.dataease.controller.sys.request.RoleMenusRequest;*/
import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.controller.sys.response.RoleUserItem; import io.dataease.controller.sys.response.RoleUserItem;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/*import org.springframework.transaction.annotation.Transactional;*/ /*import org.springframework.transaction.annotation.Transactional;*/
...@@ -55,12 +57,13 @@ public class SysRoleService { ...@@ -55,12 +57,13 @@ public class SysRoleService {
return mapper.deleteByPrimaryKey(roleId); return mapper.deleteByPrimaryKey(roleId);
} }
*/
public List<SysRole> query(BaseGridRequest request){ public List<SysRole> query(BaseGridRequest request){
List<SysRole> result = extSysRoleMapper.query(request.convertExample()); List<SysRole> result = extSysRoleMapper.query(request.convertExample());
return result; return result;
} }
/*
public List<Long> menuIds(Long roleId){ public List<Long> menuIds(Long roleId){
return extSysRoleMapper.menuIds(roleId); return extSysRoleMapper.menuIds(roleId);
......
...@@ -89,4 +89,13 @@ export const allRoles = () => { ...@@ -89,4 +89,13 @@ export const allRoles = () => {
}) })
} }
export default { editPassword, delUser, editUser, addUser, userLists, editStatus, persionInfo, updatePerson, updatePersonPwd, allRoles } export function roleGrid(pageIndex, pageSize, data) {
return request({
url: '/api/user/roleGrid/' + pageIndex + '/' + pageSize,
method: 'post',
data,
loading: true
})
}
export default { editPassword, delUser, editUser, addUser, userLists, editStatus, persionInfo, updatePerson, updatePersonPwd, allRoles, roleGrid }
<template> <template>
<div class="my_table"> <el-col>
<el-table <el-row class="tree-head">
ref="table" <span style="float: left;padding-left: 10px">{{ $t('panel.all_org') }}</span>
:data="data"
lazy </el-row>
:show-header="true" <el-row style="margin-top: 5px">
:load="loadExpandDatas"
style="width: 100%" <el-tree
:row-style="{height: '35px'}" ref="tree"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}" :data="data"
row-key="deptId" lazy
> :load="loadTree"
<el-table-column :label="$t('panel.all_org')" prop="name" /> style="width: 100%"
<el-table-column type="selection" fixd /> :props="defaultProps"
<!-- <el-table-column label="分享给" prop="deptId" width="80" fixed="right"> :default-expanded-keys="expandNodeIds"
<template slot-scope="scope"> node-key="deptId"
<el-checkbox :v-model="scope.row.deptId===0" /> >
</template> <span slot-scope="{ node, data }" class="custom-tree-node">
</el-table-column> --> <span>
</el-table> <span style="margin-left: 6px">{{ data.name }}</span>
</div> </span>
<span @click.stop>
<div>
<span class="auth-span">
<el-checkbox v-model="data.checked" />
</span>
</div>
</span>
</span>
</el-tree>
</el-row>
</el-col>
</template> </template>
<script> <script>
import { getDeptTree, loadTable } from '@/api/system/dept' import { getDeptTree, loadTable } from '@/api/system/dept'
import { saveShare, loadShares } from '@/api/panel/share' import { loadShares } from '@/api/panel/share'
export default { export default {
name: 'GrantDept', name: 'GrantDept',
props: { props: {
...@@ -48,7 +60,15 @@ export default { ...@@ -48,7 +60,15 @@ export default {
type: 2, // 类型2代表组织 type: 2, // 类型2代表组织
shares: [], shares: [],
changeIndex: 0, changeIndex: 0,
timeMachine: null timeMachine: null,
defaultProps: {
children: 'children',
label: 'name',
isLeaf: (data, node) => {
return !data.hasChildren
}
},
expandNodeIds: []
} }
}, },
watch: { watch: {
...@@ -81,9 +101,9 @@ export default { ...@@ -81,9 +101,9 @@ export default {
this.timeMachine && clearTimeout(this.timeMachine) this.timeMachine && clearTimeout(this.timeMachine)
this.timeMachine = null this.timeMachine = null
}, },
// 加载下一级子节点数据 loadTree(node, resolve) {
loadExpandDatas(row, treeNode, resolve) { if (!node || !node.data || !node.data.deptId) return
getDeptTree(row.deptId).then(res => { getDeptTree(node.data.deptId).then(res => {
let data = res.data let data = res.data
data = data.map(obj => { data = data.map(obj => {
if (obj.subCount > 0) { if (obj.subCount > 0) {
...@@ -91,17 +111,13 @@ export default { ...@@ -91,17 +111,13 @@ export default {
} }
return obj return obj
}) })
// this.maps.set(row.deptId, { row, treeNode, resolve }) this.setCheckExpandNodes(data)
resolve && resolve(data) resolve && resolve(data)
this.$nextTick(() => {
this.setCheckExpandNodes(data)
})
}) })
}, },
// 加载表格数据 // 加载表格数据
search(condition) { search(condition) {
// this.setTableAttr()
this.data = [] this.data = []
let param = {} let param = {}
if (condition && condition.value) { if (condition && condition.value) {
...@@ -110,31 +126,41 @@ export default { ...@@ -110,31 +126,41 @@ export default {
param = { conditions: [this.defaultCondition] } param = { conditions: [this.defaultCondition] }
} }
loadTable(param).then(res => { this.queryShareNodeIds(() => {
let data = res.data loadTable(param).then(res => {
data = data.map(obj => { let data = res.data
if (obj.subCount > 0) { data = data.map(obj => {
obj.hasChildren = true if (obj.subCount > 0) {
obj.hasChildren = true
}
return obj
})
this.setCheckExpandNodes(data)
this.expandNodeIds = []
if (condition && condition.value) {
// data = data.map(node => {
// delete (node.hasChildren)
// return node
// })
this.data = this.buildTree(data)
this.$nextTick(() => {
// this.expandNodeIds.push()
this.expandResult(this.data)
})
} else {
this.data = data
} }
return obj
}) })
})
},
if (condition && condition.value) { expandResult(list) {
data = data.map(node => { list.forEach(node => {
delete (node.hasChildren) if (node.children && node.children.length > 0) {
return node this.expandNodeIds.push(node.deptId)
}) this.expandResult(node.children)
this.data = this.buildTree(data)
this.$nextTick(() => {
data.forEach(node => {
this.$refs.table.toggleRowExpansion(node, true)
})
})
} else {
this.data = data
} }
this.queryShareNodeIds()
}) })
}, },
...@@ -159,22 +185,21 @@ export default { ...@@ -159,22 +185,21 @@ export default {
}, },
getSelected() { getSelected() {
// const ids = []
// this.searchChecked(ids)
// return {
// deptIds: ids
// }
// const ids = []
const nodesMap = this.$refs.tree.store.nodesMap
const ids = Object.values(nodesMap).filter(node => node.data.checked).map(item => item.data.deptId)
return { return {
deptIds: this.$refs.table.store.states.selection.map(item => item.deptId) deptIds: ids
} }
}, },
save(msg) {
const rows = this.$refs.table.store.states.selection
const request = this.buildRequest(rows)
saveShare(request).then(res => {
this.$success(msg)
return true
}).catch(err => {
this.$error(err.message)
return false
})
},
cancel() { cancel() {
}, },
...@@ -196,23 +221,23 @@ export default { ...@@ -196,23 +221,23 @@ export default {
const shares = res.data const shares = res.data
const nodeIds = shares.map(share => share.targetId) const nodeIds = shares.map(share => share.targetId)
this.shares = nodeIds this.shares = nodeIds
this.$nextTick(() => { // this.$nextTick(() => {
this.setCheckNodes() // this.setCheckNodes()
}) // })
callBack && callBack() callBack && callBack()
}) })
}, },
setCheckNodes() { // setCheckNodes() {
this.data.forEach(node => { // this.data.forEach(node => {
const nodeId = node.deptId // const nodeId = node.deptId
this.shares.includes(nodeId) && this.$refs.table.toggleRowSelection(node, true) // this.shares.includes(nodeId) && (node.checked = true)
}) // })
}, // },
setCheckExpandNodes(rows) { setCheckExpandNodes(rows) {
rows.forEach(node => { rows.forEach(node => {
const nodeId = node.deptId const nodeId = node.deptId
this.shares.includes(nodeId) && this.$refs.table.toggleRowSelection(node, true) this.shares.includes(nodeId) && (node.checked = true)
}) })
} }
...@@ -222,6 +247,37 @@ export default { ...@@ -222,6 +247,37 @@ export default {
<style scoped> <style scoped>
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-left: 8px;
}
.tree-main{
height: calc(100vh - 210px);
border: 1px solid #e6e6e6;
overflow-y: auto;
}
.tree-head{
height: 30px;
line-height: 30px;
border-bottom: 1px solid #e6e6e6;
background-color: #f7f8fa;
font-size: 12px;
color: #3d4d66 ;
}
.auth-span{
float: right;
width:50px;
margin-right: 30px
}
.highlights-text {
color: #faaa39 !important;
}
.my_table >>> .el-table__row>td{ .my_table >>> .el-table__row>td{
/* 去除表格线 */ /* 去除表格线 */
border: none; border: none;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</template> </template>
<script> <script>
import { roleGrid } from '@/api/system/role' import { roleGrid } from '@/api/system/user'
import { formatCondition } from '@/utils/index' import { formatCondition } from '@/utils/index'
import { saveShare, loadShares } from '@/api/panel/share' import { saveShare, loadShares } from '@/api/panel/share'
export default { export default {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论