You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
5.6 KiB

6 years ago
<template>
<el-card v-loading="loading" class="card-container max-view-height full">
6 years ago
<div class="department-outer">
<div class="view-box">
<org-tree-view
:data="data"
:horizontal="horizontal"
:zoom="realZoom"
collapsable
@node-contextmenu="openMenu"
@wheel.native.prevent="wheel"
6 years ago
/>
</div>
6 years ago
<div class="tooltip-box">
<el-radio-group v-model="horizontal" fill="#909399" size="small" style="margin-right: 20px">
<el-radio-button :label="true"> </el-radio-button>
<el-radio-button :label="false"> </el-radio-button>
</el-radio-group>
6 years ago
<el-button
circle
icon="el-icon-refresh"
size="small"
style="margin-right: 20px"
title="刷新"
type="info"
@click="search"
6 years ago
/>
6 years ago
<zoom-control v-model="zoom" :max="200" :min="20"/>
</div>
</div>
<context-menu
v-model="contextmenu.show"
:items="contextMenuItems"
:left="contextmenu.left"
:top="contextmenu.top"
/>
6 years ago
<edit-dialog v-model="editDialog" :data="currentNode" :type="type" @success="search"/>
</el-card>
</template>
<script>
/**
* 详情见iview-admin
* https://admin.iviewui.com/component/org_tree_page
*/
import ContextMenu from "el-admin-layout/src/component/TagsView/ContextMenu"
import EditDialog from "./component/EditDialog"
import OrgTreeView from "./component/OrgTreeView"
import ZoomControl from './component/ZoomControl'
import {add, update, del, get} from "@/api/system/department"
import {wic} from "@/util/auth"
import {elConfirm, elError, elSuccess} from "@/util/message"
import {createTreeByWorker} from "@/util/tree"
export default {
name: "departmentManagement",
components: {ContextMenu, EditDialog, OrgTreeView, ZoomControl},
data() {
return {
loading: false,
data: {},
zoom: 100,
horizontal: false,
currentNode: null,
type: 'add',
editDialog: false,
contextmenu: {
show: false,
left: 0,
top: 0
6 years ago
}
}
},
computed: {
...wic({add, update, del}),
contextMenuItems() {
6 years ago
return [
this.canAdd && {content: '添 加', click: this.add},
{content: '查 看', click: this.see},
this.canUpdate && {content: '编 辑', click: this.edit},
this.canDel && {content: '删 除', click: this.del}
]
},
realZoom() {
return this.zoom / 100
}
},
methods: {
//将部门树转换为页面需要的结构
completeDepartment(arr) {
arr.forEach(i => {
i.label = i.name
i.parentName = i.fullname
i.children && this.completeDepartment(i.children)
})
6 years ago
},
//右键菜单
openMenu(e, obj) {
e.preventDefault()
this.currentNode = obj
this.contextmenu.left = e.clientX + 15
this.contextmenu.top = e.clientY
this.contextmenu.show = true
},
//滚轮缩放
wheel(e) {
const eventDelta = e.wheelDelta || -(e.detail || 0)
const zoom = this.zoom + eventDelta / 12 * 2
if (zoom >= 20 && zoom <= 200) {
this.zoom = zoom
}
},
add() {
this.type = 'add'
this.editDialog = true
},
6 years ago
see() {
this.type = 'see'
this.editDialog = true
},
edit() {
this.type = 'edit'
this.editDialog = true
6 years ago
},
del() {
if (this.loading || !this.currentNode) return
if (this.currentNode.id === 1) return elError('根节点不能删除')
if (this.currentNode.children && this.currentNode.children.length > 0) {
return elError('请先删除子部门')
6 years ago
}
elConfirm(`确定删除部门【${this.currentNode.name}】?`)
.then(() => {
this.loading = true
return del.request(this.currentNode)
})
.then(({msg}) => {
elSuccess(msg)
this.search()
})
.finally(() => this.loading = false)
6 years ago
},
search() {
this.currentNode = null
this.loading = true
get
.request()
.then(({data}) => createTreeByWorker(data))
.then(data => {
this.completeDepartment(data)
this.data = data[0]
})
.finally(() => this.loading = false)
6 years ago
}
},
mounted() {
this.search()
}
}
6 years ago
</script>
<style lang="scss">
.department-outer {
width: 100%;
height: 100%;
overflow: hidden;
.tooltip-box {
position: absolute;
right: 30px;
bottom: 30px;
z-index: 2;
display: flex;
justify-content: flex-end;
align-items: center;
}
6 years ago
.view-box {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
6 years ago
}
}
6 years ago
</style>