dataAuth.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!--
  2. * @Author: your name
  3. * @Date: 2024-06-11 09:36:36
  4. * @LastEditTime: 2024-07-09 15:38:47
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /dashengmag/performance-test/src/views/system/roleMag/components/dataAuth.vue
  8. -->
  9. <template>
  10. <div>
  11. <el-tree
  12. :data="menuList"
  13. show-checkbox
  14. default-expand-all
  15. node-key="codeNumber"
  16. ref="tree"
  17. highlight-current
  18. :props="defaultProps"
  19. >
  20. </el-tree>
  21. </div>
  22. </template>
  23. <script>
  24. import { getRoleOrganization } from "@/api/system.js";
  25. import {
  26. checkDataAuthTreeFn,
  27. getCheckDataAuthTreeFn,
  28. } from "@/utils/getMenu.js";
  29. export default {
  30. props: {
  31. treeObj: {
  32. type: Object,
  33. required: true,
  34. },
  35. },
  36. data() {
  37. return {
  38. menuList: [],
  39. defaultProps: {
  40. children: "children",
  41. label: "codeName",
  42. },
  43. };
  44. },
  45. watch: {
  46. treeObj: {
  47. handler() {
  48. this.getMenuList();
  49. },
  50. deep: true,
  51. immediate: true,
  52. },
  53. },
  54. created() {
  55. // this.getMenuList();
  56. },
  57. methods: {
  58. getMenuList() {
  59. getRoleOrganization({ roleId: this.treeObj.roleId }).then((res) => {
  60. this.menuList = res.data;
  61. this.updateTreeCheckState(this.menuList);
  62. });
  63. },
  64. getCheckTreeKey() {
  65. const result = getCheckDataAuthTreeFn(
  66. this.$refs.tree.getCheckedKeys(),
  67. this.menuList
  68. );
  69. const uniqueArray = Array.from(
  70. new Set(result.map((item) => item.codeNumber))
  71. ).map((id) => {
  72. return result.find((item) => item.codeNumber === id);
  73. });
  74. return {
  75. organizationCodes: uniqueArray,
  76. roleIdAuth: this.treeObj.roleId,
  77. };
  78. },
  79. updateTreeCheckState(checkList) {
  80. if (this.$refs.tree) {
  81. this.$refs.tree.setCheckedKeys(checkDataAuthTreeFn(checkList));
  82. }
  83. },
  84. },
  85. };
  86. </script>
  87. <style scoped lang="scss"></style>