auth-dialog.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <script>
  2. import { role, auth } from "@/api/system/table-template";
  3. import { listRole } from "@/api/system/role";
  4. export default {
  5. name: "AuthDialog",
  6. data() {
  7. return {
  8. loading: false,
  9. dialogFormVisible: false,
  10. form: { id: "" },
  11. roleList: [],
  12. authRoleList: [],
  13. };
  14. },
  15. methods: {
  16. //
  17. fetchItem(prop) {
  18. let { id } = prop;
  19. this.form.id = id;
  20. this.loading = true;
  21. this.dialogFormVisible = true;
  22. listRole({ id })
  23. .then((res) => {
  24. let { rows, total } = res;
  25. this.roleList = rows.map((item) => ({
  26. key: item.roleId,
  27. label: item.roleName,
  28. }));
  29. })
  30. .finally(() => {
  31. this.loading = false;
  32. });
  33. role(id)
  34. .then((res) => {
  35. let { data } = res;
  36. this.authRoleList = data.map((item) => item.roleId);
  37. })
  38. .finally(() => {
  39. this.loading = false;
  40. });
  41. },
  42. //
  43. onSubmit() {
  44. auth({ templateId: this.form.id, roleIdList: this.authRoleList })
  45. .then((res) => {
  46. let { code } = res;
  47. if (code == 200) {
  48. this.dialogFormVisible = false;
  49. this.$message.success("授权成功");
  50. this.$parent.$children
  51. .find((el) => el.$vnode.tag.indexOf("SearchTable") > -1)
  52. .fetchList();
  53. }
  54. })
  55. .finally(() => {
  56. this.loading = false;
  57. });
  58. },
  59. },
  60. created() {},
  61. };
  62. </script>
  63. <template>
  64. <el-dialog
  65. width="fit-content"
  66. destroy-on-close
  67. title="孙权"
  68. :visible.sync="dialogFormVisible"
  69. >
  70. <el-transfer
  71. v-loading="loading"
  72. v-model="authRoleList"
  73. :data="roleList"
  74. :titles="['未授权', '已授权']"
  75. >
  76. </el-transfer>
  77. <div slot="footer">
  78. <el-button :disabled="loading" @click="dialogFormVisible = false"
  79. >取 消</el-button
  80. >
  81. <el-button :disabled="loading" type="primary" @click="onSubmit"
  82. >确 定
  83. </el-button>
  84. </div>
  85. </el-dialog>
  86. </template>
  87. <style scoped>
  88. .el-transfer .el-transfer-panel__footer {
  89. display: flex;
  90. align-items: center;
  91. }
  92. </style>