RoleManage.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div>
  3. <!-- <div class="export-button pl-10">
  4. <el-button v-has="99102" type="primary" @click="onClick_add">
  5. 创建账号
  6. </el-button>
  7. </div> -->
  8. <el-table border :data="tableData" style="
  9. width: 80%;
  10. font-size: 20px;
  11. overflow: hidden;
  12. border-radius: 4px;
  13. margin: 20px 0 0 50px;
  14. ">
  15. <el-table-column prop="id" label="ID" width="180" align="center" />
  16. <el-table-column prop="name" label="角色名" width="280" align="center" />
  17. <el-table-column prop="description" label="描述" width="400" align="center" />
  18. <el-table-column fixed="right" label="操作" align="center">
  19. <template #default="scope">
  20. <el-button link type="primary" v-if="operationPermissions['c-1']"
  21. @click="handleChange(scope.row)">编辑</el-button>
  22. </template>
  23. </el-table-column>
  24. </el-table>
  25. <el-dialog v-model="dialogFormVisible" title="编辑角色" width="500" @close="handleClose">
  26. <div></div>
  27. <el-tree style="max-width: 600px" :data="permissionData" show-checkbox node-key="id"
  28. :default-checked-keys="currentCheckedKeys" :props="defaultProps" ref="tree" />
  29. <template #footer>
  30. <div class="dialog-footer">
  31. <el-button @click="handleClose">取消</el-button>
  32. <el-button type="primary" @click="submitChange"> 确认 </el-button>
  33. </div>
  34. </template>
  35. </el-dialog>
  36. </div>
  37. </template>
  38. <script setup>
  39. import { ref, reactive, getCurrentInstance, nextTick } from "vue";
  40. import { useMenuStore } from "@/stores/menu.js"
  41. const { operationPermissions } = useMenuStore();
  42. const { proxy } = getCurrentInstance();
  43. const defaultProps = {
  44. children: "children",
  45. label: "name",
  46. };
  47. let tableData = ref([]);
  48. let total = ref(0);
  49. let dialogFormVisible = ref(false);
  50. let permissionData = ref([]);
  51. let form = reactive({
  52. role_id: 0,
  53. name: "",
  54. description: "",
  55. permission_ids: 0,
  56. });
  57. let currentCheckedKeys = ref([]);
  58. // 使用 ref 函数创建一个引用对象
  59. const tree = ref(null);
  60. const init = () => {
  61. proxy.$http.get("/open-platform/user/roles").then((res) => {
  62. // console.log(res, "11");
  63. if (res.records && res.records.length > 0) {
  64. tableData.value = res.records
  65. } else {
  66. tableData.value = [];
  67. }
  68. total.value = res.total;
  69. });
  70. };
  71. init();
  72. const getPermission = () => {
  73. proxy.$http.get("/open-platform/user/permissions").then((res) => {
  74. if (res.records && res.records.length > 0) {
  75. permissionData.value = res.records;
  76. } else {
  77. permissionData.value = [];
  78. }
  79. });
  80. };
  81. getPermission();
  82. const handleChange = (row) => {
  83. dialogFormVisible.value = true;
  84. form.name = row.name;
  85. form.role_id = row.id;
  86. form.description = row.description;
  87. currentCheckedKeys.value = row.permission_ids ? [...row.permission_ids] : [];
  88. };
  89. const handleClose = () => {
  90. dialogFormVisible.value = false;
  91. nextTick(() => {
  92. tree.value.setCheckedKeys([]);
  93. });
  94. };
  95. const submitChange = () => {
  96. form.permission_ids = tree.value.getCheckedKeys();
  97. proxy.$http
  98. .post("/open-platform/user/roles", form)
  99. .then((res) => {
  100. proxy.$message.success("修改成功");
  101. dialogFormVisible.value = false;
  102. init();
  103. })
  104. .catch((err) => {
  105. proxy.$message.error("修改失败");
  106. });
  107. };
  108. </script>
  109. <style lang="less" scoped>
  110. :deep(.el-table th) {
  111. background-color: #eef6ff !important;
  112. /* 设置你想要的背景颜色 */
  113. color: #333;
  114. /* 设置表头文字颜色 */
  115. font-weight: bold;
  116. /* 设置表头文字加粗 */
  117. }
  118. :deep(.el-table .el-table__cell) {
  119. padding: 10px 0 !important;
  120. }
  121. </style>