RoleManage.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <div class="role-manage">
  3. <div class="part-box part-box-filter part-box-flex">
  4. <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
  5. <template v-if="checkPrivilege('condition', 'condition')">
  6. <el-form-item label="角色名称:">
  7. <el-input
  8. style="width: 200px;"
  9. v-model.trim="filter.name"
  10. placeholder="角色名称"
  11. clearable
  12. ></el-input>
  13. </el-form-item>
  14. <!-- <el-form-item label="启用/禁用:" label-width="90px">
  15. <el-select
  16. v-model="filter.enable"
  17. style="width: 120px;"
  18. placeholder="请选择"
  19. clearable
  20. >
  21. <el-option
  22. v-for="(val, key) in ABLE_TYPE"
  23. :key="key"
  24. :value="key * 1"
  25. :label="val"
  26. ></el-option>
  27. </el-select>
  28. </el-form-item> -->
  29. </template>
  30. <el-form-item>
  31. <el-button
  32. v-if="checkPrivilege('button', 'select')"
  33. type="primary"
  34. @click="toPage(1)"
  35. >查询</el-button
  36. >
  37. </el-form-item>
  38. </el-form>
  39. <div class="part-box-action">
  40. <el-button
  41. v-if="checkPrivilege('button', 'add')"
  42. type="primary"
  43. icon="el-icon-circle-plus-outline"
  44. @click="toAdd"
  45. >添加角色</el-button
  46. >
  47. </div>
  48. </div>
  49. <div class="part-box part-box-pad">
  50. <el-table ref="TableList" :data="roles">
  51. <el-table-column
  52. type="index"
  53. label="序号"
  54. width="70"
  55. :index="indexMethod"
  56. ></el-table-column>
  57. <el-table-column prop="name" label="角色名称"></el-table-column>
  58. <!-- <el-table-column prop="enable" label="启用/禁用">
  59. <template slot-scope="scope">
  60. {{ scope.row.enable | enableFilter }}
  61. </template>
  62. </el-table-column> -->
  63. <el-table-column prop="interpret" label="角色说明"></el-table-column>
  64. <el-table-column prop="createTime" label="创建时间" width="170">
  65. <span slot-scope="scope">{{
  66. scope.row.createTime | timestampFilter
  67. }}</span>
  68. </el-table-column>
  69. <el-table-column class-name="action-column" label="操作" width="180px">
  70. <template slot-scope="scope">
  71. <el-button
  72. v-if="checkPrivilege('link', 'edit') && !scope.row.defaultRole"
  73. class="btn-primary"
  74. type="text"
  75. @click="toEdit(scope.row)"
  76. >编辑</el-button
  77. >
  78. <el-button
  79. v-if="checkPrivilege('link', 'Manager')"
  80. class="btn-primary"
  81. type="text"
  82. @click="toEditUser(scope.row)"
  83. >人员管理</el-button
  84. >
  85. <el-button
  86. v-if="checkPrivilege('link', 'delete') && !scope.row.defaultRole"
  87. class="btn-danger"
  88. type="text"
  89. @click="toDelete(scope.row)"
  90. >删除</el-button
  91. >
  92. <!-- <el-button
  93. v-if="checkPrivilege('link', 'enable')"
  94. :class="scope.row.enable ? 'btn-danger' : 'btn-primary'"
  95. type="text"
  96. @click="toEnable(scope.row)"
  97. >{{ scope.row.enable ? "禁用" : "启用" }}</el-button
  98. > -->
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. <div class="part-page">
  103. <el-pagination
  104. background
  105. layout="total, sizes, prev, pager, next, jumper"
  106. :pager-count="5"
  107. :current-page="current"
  108. :total="total"
  109. :page-size="size"
  110. @current-change="toPage"
  111. @size-change="pageSizeChange"
  112. >
  113. </el-pagination>
  114. </div>
  115. </div>
  116. <!-- ModifyRole -->
  117. <modify-role
  118. v-if="checkPrivilege('button', 'add') || checkPrivilege('link', 'edit')"
  119. ref="ModifyRole"
  120. :instance="curRole"
  121. @modified="getList"
  122. ></modify-role>
  123. <!-- ModifyRoleUser -->
  124. <modify-role-user ref="ModifyRoleUser" :role="curRole"></modify-role-user>
  125. </div>
  126. </template>
  127. <script>
  128. import { ABLE_TYPE } from "@/constants/enumerate";
  129. import { roleListPage, ableRole, deleteRole } from "../api";
  130. import ModifyRole from "../components/ModifyRole";
  131. import ModifyRoleUser from "../components/ModifyRoleUser";
  132. export default {
  133. name: "role-manage",
  134. components: {
  135. ModifyRole,
  136. ModifyRoleUser
  137. },
  138. data() {
  139. return {
  140. filter: {
  141. enable: null,
  142. name: ""
  143. },
  144. current: 1,
  145. size: this.GLOBAL.pageSize,
  146. total: 0,
  147. roles: [],
  148. curRole: {},
  149. ABLE_TYPE,
  150. ROLE_TYPE: {}
  151. };
  152. },
  153. mounted() {
  154. this.toPage(1);
  155. },
  156. methods: {
  157. async getList() {
  158. if (!this.checkPrivilege("list", "list")) return;
  159. const datas = {
  160. ...this.filter,
  161. pageNumber: this.current,
  162. pageSize: this.size
  163. };
  164. if (datas.enable !== null && datas.enable !== "")
  165. datas.enable = !!datas.enable;
  166. const data = await roleListPage(datas);
  167. this.roles = data.records;
  168. this.total = data.total;
  169. },
  170. toPage(page) {
  171. this.current = page;
  172. this.getList();
  173. },
  174. toAdd() {
  175. this.curRole = {};
  176. this.$refs.ModifyRole.open();
  177. },
  178. toEdit(row) {
  179. this.curRole = row;
  180. this.$refs.ModifyRole.open();
  181. },
  182. toEditUser(row) {
  183. console.log(row);
  184. this.curRole = row;
  185. this.$refs.ModifyRoleUser.open();
  186. },
  187. toDelete(row) {
  188. this.$confirm(`确定要删除角色【${row.name}】吗?`, "提示", {
  189. type: "warning"
  190. })
  191. .then(async () => {
  192. await deleteRole(row.id);
  193. this.$message.success("删除成功!");
  194. this.deletePageLastItem();
  195. })
  196. .catch(() => {});
  197. },
  198. toEnable(row) {
  199. const action = row.enable ? "禁用" : "启用";
  200. this.$confirm(`确定要${action}角色【${row.name}】吗?`, "提示", {
  201. type: "warning"
  202. })
  203. .then(async () => {
  204. const enable = !row.enable;
  205. await ableRole({
  206. id: row.id,
  207. enable
  208. });
  209. row.enable = enable;
  210. this.$message.success("操作成功!");
  211. })
  212. .catch(() => {});
  213. }
  214. }
  215. };
  216. </script>