auth-dialog.vue 2.4 KB

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