index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="app-container flex-column p4">
  3. <el-input
  4. class="w500"
  5. placeholder="查找部门"
  6. clearable
  7. @clear="keyword=undefined"
  8. v-model="keyword">
  9. </el-input>
  10. <div class="tree-container w500 mt10">
  11. <el-tree
  12. :data="dept"
  13. default-expand-all
  14. :props="{label:'name'}"
  15. :filter-node-method="filterDept"
  16. node-key="id"
  17. empty-text="无数据"
  18. ref="dept">
  19. <div class="custom-tree-node" slot-scope="{ node, dept }">
  20. <div>{{ node.label }}</div>
  21. <div>
  22. <router-link :to="{name:'SystemUser',params:{deptId:node.data.id}}">
  23. <el-link type="primary" icon="el-icon-view">查看用户</el-link>
  24. </router-link>
  25. <el-link @click.native.stop @click="onAdd(node)" class="ml20" type="success" >添加</el-link>
  26. <el-link @click.native.stop :disabled="!node.data.id" @click="onEdit(node)" class="ml20" type="warning" >修改</el-link>
  27. <el-link @click.native.stop :disabled="!node.data.id" @click="onRemove(node)" class="ml20" type="danger" >删除</el-link>
  28. </div>
  29. </div>
  30. </el-tree>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import {isNotEmpty} from "@/utils/validate";
  36. export default {
  37. name: "SystemDept",
  38. data() {
  39. return {
  40. keyword: undefined, // 过滤关键字
  41. deptForm: {
  42. id: undefined, // 部门id
  43. name: undefined, // 部门名称
  44. parentId: undefined, // 上级部门id
  45. },
  46. dept: undefined, // 所有部门
  47. }
  48. },
  49. watch: {
  50. keyword(val) {
  51. this.$refs["dept"].filter(val);
  52. }
  53. },
  54. // 页面创建
  55. created() {
  56. },
  57. // 页面挂载
  58. mounted() {
  59. },
  60. // keep-alive 显示界面时调用
  61. activated() {
  62. this.getDept();
  63. },
  64. // keep-alive 页面隐藏
  65. deactivated() {
  66. },
  67. methods: {
  68. // 获取部门
  69. getDept() {
  70. this.$axios.get("/v1/system/dept/list/tree").then((data) => {
  71. this.dept = [{
  72. "id": 0,
  73. "name": "数字巡检系统运维平台",
  74. "parentId": 0,
  75. "children": data
  76. }];
  77. });
  78. },
  79. // 添加
  80. onAdd(node) {
  81. this.$prompt(undefined, '添加部门', {
  82. confirmButtonText: '确定',
  83. cancelButtonText: '取消',
  84. inputValidator: isNotEmpty,
  85. inputPlaceholder: '请输入部门名称',
  86. inputErrorMessage: '部门名称不能为空',
  87. closeOnClickModal: false
  88. }).then(({value}) => {
  89. this.deptForm.parentId = node.data.id;
  90. this.deptForm.name = value;
  91. this.$axios.post("/v1/system/dept/add", this.deptForm).then(() => {
  92. this.deptForm.name = undefined;
  93. this.getDept();
  94. });
  95. }).catch(() => {
  96. this.deptForm.name = undefined;
  97. });
  98. },
  99. // 修改
  100. onEdit(node) {
  101. this.$prompt(undefined, '修改部门', {
  102. confirmButtonText: '确定',
  103. cancelButtonText: '取消',
  104. inputValidator: isNotEmpty,
  105. inputPlaceholder: '请输入部门名称',
  106. inputErrorMessage: '部门名称不能为空',
  107. closeOnClickModal: false,
  108. inputValue:node.data.name
  109. }).then(({value}) => {
  110. this.deptForm.id = node.data.id;
  111. this.deptForm.name = value;
  112. this.$axios.put("/v1/system/dept/update", this.deptForm).then(() => {
  113. this.deptForm.name = undefined;
  114. this.getDept();
  115. });
  116. }).catch(() => {
  117. this.deptForm.name = undefined;
  118. });
  119. },
  120. // 删除
  121. onRemove(node) {
  122. this.$confirm('此操作将删除部门, 是否继续?', '提示', {
  123. confirmButtonText: '确认',
  124. cancelButtonText: '取消',
  125. type: 'warning'
  126. }).then(async () => {
  127. this.$axios.delete(`/v1/system/dept/delete/${node.data.id}`).then(() => {
  128. this.$message.success("删除成功!");
  129. this.getDept();
  130. });
  131. }).catch(() => {
  132. this.$message.info("取消操作!")
  133. });
  134. },
  135. // 部门显示过滤
  136. filterDept(value, data) {
  137. if (!value) return true;
  138. return data.name.indexOf(value) !== -1;
  139. },
  140. // 关闭前确认
  141. onBeforeClose(done) {
  142. if (this.$store.state.app.closeConfirmEnable) {
  143. this.$confirm("确认关闭?").then(() => done());
  144. } else {
  145. done();
  146. }
  147. },
  148. }
  149. }
  150. </script>
  151. <style scoped lang="scss">
  152. .app-container {
  153. max-height: calc(100vh - 70px);
  154. .tree-container {
  155. flex: 1;
  156. overflow-y: auto;
  157. ::v-deep .el-form-item__content {
  158. max-height: 100%;
  159. overflow-y: auto;
  160. }
  161. .custom-tree-node {
  162. flex: 1;
  163. display: flex;
  164. align-items: center;
  165. justify-content: space-between;
  166. font-size: 14px;
  167. padding-right: 8px;
  168. }
  169. }
  170. }
  171. </style>