role.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="app-container">
  3. <div>
  4. <el-row>
  5. <el-col :span="24">
  6. <el-button size="small" type="primary" @click="openCreateDialog">新增角色</el-button>
  7. </el-col>
  8. </el-row>
  9. <el-table :data="roles" style="width: 100%" v-loading="loading">
  10. <el-table-column type="index" width="40"></el-table-column>
  11. <el-table-column prop="rolename" label="角色名称" width="160"></el-table-column>
  12. <el-table-column prop="roleDescribe" label="角色描述"></el-table-column>
  13. <el-table-column label="操作" width="290">
  14. <template slot-scope="scope">
  15. <el-button size="small" @click="openEditDialog(scope.$index)">修改角色</el-button>
  16. <el-button
  17. size="small"
  18. @click="toAuthority(scope.row.id,scope.row.rolename)"
  19. >修改权限</el-button>
  20. <el-button
  21. size="small"
  22. type="danger"
  23. @click="deleteRole(scope.row.id,scope.row.rolename)"
  24. >删除角色</el-button>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. </div>
  29. <!-- 添加或修改的dialog -->
  30. <el-dialog :close-on-click-modal="false" :title="(roleForm.id==null?'新增':'修改')+'角色'" :visible.sync="dialogVisible" width="400px">
  31. <el-form ref="form" :model="roleForm" :rules="rules" label-width="60px">
  32. <el-form-item label="名称" prop="name">
  33. <el-input v-model="roleForm.name" ref="name" placeholder="请输入名称" clearable></el-input>
  34. </el-form-item>
  35. <el-form-item label="描述" prop="description">
  36. <el-input v-model="roleForm.description" placeholder="请输入描述" clearable></el-input>
  37. </el-form-item>
  38. </el-form>
  39. <span slot="footer" class="dialog-footer">
  40. <el-button @click="dialogVisible=false">取消</el-button>
  41. <el-button type="primary" @click="submitRole">提交</el-button>
  42. </span>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. import util from "../../common/js/util";
  48. export default {
  49. data() {
  50. return {
  51. roles: [],
  52. loading: false,
  53. dialogVisible: false,
  54. roleForm: {
  55. id: null,
  56. name: null,
  57. description: null
  58. },
  59. rules: {
  60. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  61. description: [
  62. { required: true, message: "请输入描述", trigger: "blur" }
  63. ]
  64. },
  65. //权限
  66. viewPermission:
  67. store.getters.authorization.indexOf("pc_view_permission") != -1,
  68. editPermission:
  69. store.getters.authorization.indexOf("pc_set_permission") != -1
  70. };
  71. },
  72. methods: {
  73. getRole() {
  74. this.loading = true;
  75. request({
  76. url: "/permission/getRoleList",
  77. method: "post"
  78. })
  79. .then(response => {
  80. this.roles = response.data;
  81. this.loading = false;
  82. })
  83. .catch(error => {
  84. this.loading = false;
  85. });
  86. },
  87. submitRole() {
  88. this.$refs.form.validate(valid => {
  89. if (valid) {
  90. this.loading = true;
  91. request({
  92. url: "/permission/editRole",
  93. method: "post",
  94. params: {
  95. id: this.roleForm.id,
  96. name: this.roleForm.name,
  97. description: this.roleForm.description
  98. }
  99. })
  100. .then(response => {
  101. this.loading = false;
  102. if (response.code == 'ok') {
  103. this.$message({
  104. message: "操作成功",
  105. type: "success"
  106. });
  107. this.dialogVisible = false;
  108. this.getRole();
  109. } else {
  110. this.$message({
  111. message: response.message,
  112. type: "error"
  113. });
  114. }
  115. })
  116. .catch(error => {
  117. this.loading = false;
  118. });
  119. }
  120. });
  121. },
  122. //删除
  123. deleteRole(id, name) {
  124. this.$confirm("是否删除" + name, "删除", {
  125. confirmButtonText: "确定",
  126. cancelButtonText: "取消",
  127. closeOnClickModal: false,
  128. type: "warning"
  129. }).then(() => {
  130. this.loading = true;
  131. request({
  132. url: "/permission/deleteRole",
  133. method: "post",
  134. params: {
  135. id: id
  136. }
  137. })
  138. .then(response => {
  139. this.loading = false;
  140. this.getRole();
  141. })
  142. .catch(error => {
  143. this.loading = false;
  144. });
  145. });
  146. },
  147. //打开新建dialog
  148. openCreateDialog() {
  149. this.roleForm.id = null;
  150. this.roleForm.name = "";
  151. this.roleForm.description = "";
  152. this.dialogVisible = true;
  153. this.$nextTick(() => {
  154. this.$refs.form.clearValidate();
  155. this.$refs.name.focus();
  156. },500)
  157. },
  158. //打开编辑dialog
  159. openEditDialog(index) {
  160. this.roleForm.id = this.roles[index].id;
  161. this.roleForm.name = this.roles[index].rolename;
  162. this.roleForm.description = this.roles[index].roleDescribe;
  163. this.dialogVisible = true;
  164. this.$refs.form.clearValidate();
  165. },
  166. toAuthority(id, name) {
  167. this.$router.push("/authority/" + id + "/" + name);
  168. }
  169. },
  170. mounted() {
  171. this.getRole();
  172. }
  173. };
  174. </script>
  175. <style scoped>
  176. </style>