organization.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <HcCard actionSize="lg" scrollbar>
  3. <template #extra>
  4. <el-button type="primary" @click="editClick" size="large" v-if="!isShowIcon&&!isedit">
  5. <span>编辑组织机构</span>
  6. </el-button>
  7. <el-button type="primary" @click="goback" size="large" v-if="!isShowIcon&&isedit">
  8. <span>返回上一级</span>
  9. </el-button>
  10. </template>
  11. <div class="content-box" v-if="isShowIcon">
  12. <HcIcon name="add-box" class="add_icon" @click="addClick"/>
  13. </div>
  14. <div class="content-box1" v-if="!isShowIcon&&!isedit">
  15. <div style="height: 400px;text-align: center;">
  16. <vue3-tree-org
  17. :data="testdata"
  18. :horizontal="horizontal"
  19. :collapsable="collapsable"
  20. :label-style="style"
  21. :node-draggable="true"
  22. :scalable="false"
  23. :only-one-node="onlyOneNode"
  24. :default-expand-level="4"
  25. :clone-node-drag="cloneNodeDrag"
  26. @on-contextmenu="onMenus"
  27. @on-node-click="onNodeClick"
  28. >
  29. <!-- 自定义节点内容 -->
  30. <template v-slot="{node}">
  31. <div class="tree-org-node__text node-label">
  32. <!-- <div class="custom-content">自定义内容</div> -->
  33. <div>{{node.label}}</div>
  34. </div>
  35. </template>
  36. <!-- 自定义展开按钮 -->
  37. <template v-slot:expand="{node}">
  38. <div>{{node.children.length}}</div>
  39. </template>
  40. </vue3-tree-org>
  41. </div>
  42. </div>
  43. <div v-if="!isShowIcon&&isedit">
  44. <div class="tree-box blue">
  45. <el-scrollbar class="h-100p">
  46. <el-tree
  47. class="tree-line1"
  48. :data="dataSource"
  49. node-key="id"
  50. default-expand-all
  51. :expand-on-click-node="false"
  52. >
  53. <template #default="{ node, data }">
  54. <span class="custom-tree-node">
  55. <span :class="node.level === 1?'level-name':''" class="label">{{ node.label }}</span>
  56. <span>
  57. <HcIcon name="add-box" @click="addClick" style=" color: rgb(84, 188, 189);" v-if="data.children"/>
  58. <HcIcon name="edit" @click="addClick" style="margin-left: 8px;color: rgb(84, 188, 189);" />
  59. <HcIcon name="delete-bin" @click="delClick" style="margin-left: 8px;color: orange;" />
  60. <HcIcon name="vip-crown-2" @click="authorityClick" style="margin-left: 8px;color: purple;"/>
  61. </span>
  62. </span>
  63. </template>
  64. </el-tree>
  65. </el-scrollbar>
  66. </div>
  67. </div>
  68. <HcDialog :show="testModal" title="新增机构信息" @close="testModalClose" widths="80rem">
  69. <el-form ref="formRef" :model="formModel" :rules="formRules" label-position="left"
  70. size="large">
  71. <el-row :gutter="20">
  72. <el-col :span="12">
  73. <el-form-item label="上级组织节点名称">
  74. <el-select v-model="formModel.top" class="m-2" placeholder="请选择" size="large" style="width:100%">
  75. <el-option
  76. v-for="item in topMenuoptions"
  77. :key="item.value"
  78. :label="item.label"
  79. :value="item.value"
  80. />
  81. </el-select>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :span="12">
  85. <el-form-item label="组织节点类别">
  86. <el-select v-model="formModel.top" class="m-2" placeholder="请选择" size="large" style="width:100%">
  87. <el-option
  88. v-for="item in topMenuoptions"
  89. :key="item.value"
  90. :label="item.label"
  91. :value="item.value"
  92. />
  93. </el-select>
  94. </el-form-item>
  95. </el-col>
  96. <el-col :span="12">
  97. <el-form-item label="组织节点名称">
  98. <el-input v-model="formModel.deptId" placeholder=""/>
  99. </el-form-item>
  100. </el-col>
  101. </el-row>
  102. </el-form>
  103. </HcDialog>
  104. <HcDialog :show="authorityModal" title="权限配置" @close="authorityModalClose" widths="80rem">
  105. <el-tree
  106. :props="props"
  107. :load="loadNode"
  108. lazy
  109. show-checkbox
  110. @check-change="handleCheckChange"
  111. />
  112. </HcDialog>
  113. </HcCard>
  114. </template>
  115. <script setup>
  116. import {ref, watch} from "vue";
  117. import {useAppStore} from "~src/store";
  118. const isShowIcon=ref(false)
  119. const isedit=ref(false)
  120. const editClick=()=>{
  121. isedit.value=true
  122. }
  123. const addClick=()=>{
  124. testModal.value = true
  125. }
  126. const testModal = ref(false)
  127. //弹窗关闭
  128. const testModalClose = () => {
  129. console.log('弹窗关闭')
  130. testModal.value = false
  131. }
  132. const formModel=ref({})
  133. const formRules=ref({})
  134. const topMenuoptions=ref([])
  135. const dataSource = ref([
  136. {
  137. id: 1,
  138. label: '技术部',
  139. children: [
  140. {
  141. id: 4,
  142. label: '研发经理',
  143. children: [
  144. {
  145. id: 9,
  146. label: '产品经理',
  147. },
  148. {
  149. id: 10,
  150. label: 'java技术',
  151. },
  152. ],
  153. },
  154. ],
  155. },
  156. {
  157. id: 2,
  158. label: '人事部',
  159. children: [
  160. {
  161. id: 5,
  162. label: '人事管理',
  163. },
  164. {
  165. id: 6,
  166. label: 'Level two 2-2',
  167. },
  168. ],
  169. },
  170. {
  171. id: 3,
  172. label: 'Level one 3',
  173. children: [
  174. {
  175. id: 7,
  176. label: 'Level two 3-1',
  177. },
  178. {
  179. id: 8,
  180. label: 'Level two 3-2',
  181. },
  182. ],
  183. },
  184. ])
  185. const delClick = (node, data) => {
  186. console.log(node,'node');
  187. window?.$messageBox?.alert('您确定要注销[xxx] 的机构信息吗? 一旦注销数据将彻底清除,请谨慎操作?', '注销提醒', {
  188. showCancelButton: true,
  189. confirmButtonText: '确认注销',
  190. cancelButtonText: '取消',
  191. type: 'warning',
  192. callback: (action) => {
  193. if (action === 'confirm') {
  194. console.log(11111);
  195. }
  196. }
  197. })
  198. }
  199. const authorityModal=ref(false)
  200. const authorityClick=()=>{
  201. authorityModal.value=true
  202. }
  203. const authorityModalClose = () => {
  204. console.log('弹窗关闭')
  205. authorityModal.value = false
  206. }
  207. const props = {
  208. label: 'name',
  209. children: 'zones',
  210. }
  211. const goback=()=>{
  212. isedit.value=false
  213. }
  214. const handleCheckChange = (
  215. data,
  216. checked,
  217. indeterminate
  218. ) => {
  219. console.log(data, checked, indeterminate)
  220. }
  221. const loadNode = (node, resolve) => {
  222. if (node.level === 0) {
  223. return resolve([{ name: 'region' }])
  224. }
  225. if (node.level > 1) return resolve([])
  226. setTimeout(() => {
  227. const data = [
  228. {
  229. name: 'leaf',
  230. leaf: true,
  231. },
  232. {
  233. name: 'zone',
  234. },
  235. ]
  236. resolve(data)
  237. }, 500)
  238. }
  239. //组织架构显示信息
  240. const testdata=ref({
  241. "id":1,"label":"xxx科技有限公司",
  242. "children":[
  243. {
  244. "id":2,"pid":1,"label":"产品研发部",
  245. "style":{"color":"#fff","background":"#108ffe"},
  246. "children":[
  247. {"id":6,"pid":2,"label":"禁止编辑节点","disabled":true},
  248. {"id":8,"pid":2,"label":"禁止拖拽节点","noDragging":true},
  249. {"id":10,"pid":2,"label":"测试"}
  250. ]
  251. },
  252. {
  253. "id":3,"pid":1,"label":"客服部",
  254. "children":[
  255. {"id":11,"pid":3,"label":"客服一部"},
  256. {"id":12,"pid":3,"label":"客服二部"}
  257. ]
  258. },
  259. {"id":4,"pid":1,"label":"业务部"}
  260. ]
  261. })
  262. const horizontal=ref(false)
  263. const collapsable=ref(true)
  264. const onlyOneNode=ref(true)
  265. const cloneNodeDrag=ref(true)
  266. const expandAll=ref(true)
  267. const style=ref({background: "#fff",color: "#5e6d82",})
  268. const onMenus=({ node, command })=>{
  269. console.log(node, command);
  270. }
  271. const onNodeClick=(e, data)=>{
  272. }
  273. const expandChange=()=>{
  274. }
  275. </script>
  276. <style lang="scss" scoped>
  277. // 树的线样式
  278. .tree-line1 {
  279. :deep(.el-tree-node) {
  280. position: relative;
  281. padding-left: 12px; // 缩进量
  282. width: 100%;
  283. }
  284. :deep(.el-tree-node__children) {
  285. padding-left: 12px; // 缩进量
  286. }
  287. // 竖线
  288. :deep(.el-tree-node::before) {
  289. content:"";
  290. height: 100%;
  291. width: 1px;
  292. position: absolute;
  293. left: 1px;
  294. top: 0px;
  295. border-width: 1px;
  296. border-left: 2px dashed var(--el-color-primary);
  297. }
  298. // 当前层最后⼀个节点的竖线⾼度固定
  299. :deep(.el-tree-node:last-child::before){
  300. height: 15px; // 可以⾃⼰调节到合适数值
  301. }
  302. // 横线
  303. :deep(.el-tree-node::after) {
  304. content:"";
  305. width: 25px;
  306. height: 20px;
  307. position: absolute;
  308. left: 2px;
  309. top: 12px;
  310. border-width: 1px;
  311. border-top: 2px dashed var(--el-color-primary);
  312. }
  313. // 去掉最顶层的虚线,放最下⾯样式才不会被上⾯的覆盖了
  314. & > :deep(.el-tree-node::after) {
  315. border-top: none !important;
  316. border-top: 0 !important;
  317. }
  318. & > :deep(.el-tree-node::before) {
  319. border-left: none;
  320. }
  321. // 展开关闭的icon
  322. :deep(.el-tree-node__expand-icon) {
  323. font-size: 16px;
  324. &.is-leaf {
  325. color: transparent;
  326. font-size: 0;
  327. }
  328. }
  329. :deep(.el-tree__empty-block) {
  330. min-width: 300px;
  331. }
  332. }
  333. </style>
  334. <style lang="scss">
  335. .content-box{
  336. display: flex;
  337. justify-content: center;
  338. align-items: center;
  339. height: calc(100vh - 386px);
  340. text-align: center;
  341. width: 100%;
  342. color: rgb(84, 188, 189);
  343. }
  344. .content-box1{
  345. text-align: center;
  346. }
  347. .add_icon{
  348. font-size: 8rem;
  349. cursor: pointer;
  350. }
  351. .h-100p{height: 100%;}
  352. // 树样式
  353. .tree-box .el-tree-node{
  354. font-size: 18px;
  355. }
  356. .tree-box .el-tree-node .data-custom-tree-node .level-name{
  357. font-size: 24px;
  358. }
  359. </style>