RoleManage.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. <el-form-item label="角色名称:">
  6. <el-input
  7. style="width: 200px;"
  8. v-model.trim="filter.roleName"
  9. placeholder="请输入内容"
  10. clearable
  11. ></el-input>
  12. </el-form-item>
  13. <el-form-item label="启用/禁用:" label-width="90px">
  14. <el-select
  15. v-model="filter.enable"
  16. style="width: 100px;"
  17. placeholder="请选择"
  18. clearable
  19. >
  20. <el-option
  21. v-for="(val, key) in ABLE_TYPE"
  22. :key="key"
  23. :value="key"
  24. :label="val"
  25. ></el-option>
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" icon="icon icon-search" @click="toPage(1)"
  30. >查询</el-button
  31. >
  32. </el-form-item>
  33. </el-form>
  34. <div class="part-box-action">
  35. <el-button type="warning" icon="icon icon-plus" @click="toAdd"
  36. >添加角色</el-button
  37. >
  38. </div>
  39. </div>
  40. <div class="part-box">
  41. <el-table ref="TableList" :data="roles" border stripe>
  42. <el-table-column
  43. type="index"
  44. label="序号"
  45. width="70"
  46. align="center"
  47. :index="indexMethod"
  48. ></el-table-column>
  49. <el-table-column prop="roleName" label="角色名称"></el-table-column>
  50. <el-table-column prop="enable" label="启用/禁用">
  51. <template slot-scope="scope">
  52. {{ scope.row.enable | enableFilter }}
  53. </template>
  54. </el-table-column>
  55. <el-table-column prop="createTime" label="创建时间"></el-table-column>
  56. <el-table-column
  57. class-name="action-column"
  58. label="操作"
  59. align="center"
  60. width="120px"
  61. >
  62. <template slot-scope="scope">
  63. <el-button
  64. class="btn-table-icon"
  65. type="text"
  66. icon="icon icon-edit"
  67. @click="toEdit(scope.row)"
  68. title="编辑"
  69. ></el-button>
  70. <el-button
  71. class="btn-table-icon"
  72. type="text"
  73. icon="icon icon-delete"
  74. @click="toDelete(scope.row)"
  75. title="删除"
  76. ></el-button>
  77. <el-button
  78. class="btn-table-icon"
  79. type="text"
  80. :icon="
  81. scope.row.enable
  82. ? 'icon icon-circle-stop'
  83. : 'icon icon-circle-caret-right'
  84. "
  85. @click="toEnable(scope.row)"
  86. :title="scope.row.enable ? '禁用' : '启用'"
  87. ></el-button>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <div class="part-page">
  92. <el-pagination
  93. background
  94. layout="total,prev, pager, next"
  95. :current-page="current"
  96. :total="total"
  97. :page-size="size"
  98. @current-change="toPage"
  99. >
  100. </el-pagination>
  101. </div>
  102. </div>
  103. <!-- ModifyRole -->
  104. <modify-role
  105. ref="ModifyRole"
  106. :instance="curRole"
  107. :menus="menus"
  108. @modified="getList"
  109. ></modify-role>
  110. </div>
  111. </template>
  112. <script>
  113. import { ABLE_TYPE, TEMPLATE_TYPE } from "@/constants/enumerate";
  114. import { menuList, roleListPage, ableRole, deleteRole } from "../api";
  115. import ModifyRole from "../components/ModifyRole";
  116. export default {
  117. name: "role-manage",
  118. components: {
  119. ModifyRole
  120. },
  121. props: {
  122. templateType: {
  123. type: String,
  124. default: "GENERIC",
  125. validator(val) {
  126. return Object.keys(TEMPLATE_TYPE).indexOf(val) !== -1;
  127. }
  128. }
  129. },
  130. data() {
  131. return {
  132. filter: {
  133. enable: null,
  134. roleName: ""
  135. },
  136. current: 1,
  137. size: this.GLOBAL.pageSize,
  138. total: 0,
  139. roles: [],
  140. curRole: {},
  141. ABLE_TYPE,
  142. // menus: [],
  143. menus: []
  144. };
  145. },
  146. created() {
  147. this.getList();
  148. this.getMenus();
  149. },
  150. methods: {
  151. async getMenus() {
  152. this.menus = await menuList();
  153. },
  154. async getList() {
  155. const datas = {
  156. ...this.filter,
  157. pageNumber: this.current,
  158. pageSize: this.size
  159. };
  160. const data = await roleListPage(datas);
  161. this.roles = data.records;
  162. this.total = data.total;
  163. },
  164. toPage(page) {
  165. this.current = page;
  166. this.getList();
  167. },
  168. toAdd() {
  169. this.curRole = {};
  170. this.$refs.ModifyRole.open();
  171. },
  172. toEdit(row) {
  173. this.curRole = row;
  174. this.$refs.ModifyRole.open();
  175. },
  176. toDelete(row) {
  177. this.$confirm("确定要删除当前角色吗?", "提示", {
  178. cancelButtonClass: "el-button--danger is-plain",
  179. confirmButtonClass: "el-button--primary",
  180. type: "warning"
  181. }).then(async () => {
  182. await deleteRole(row.id);
  183. this.$message.success("删除成功!");
  184. this.deletePageLastItem();
  185. });
  186. },
  187. async toEnable(row) {
  188. const enable = Number(!row.enable);
  189. await ableRole({
  190. id: row.id,
  191. enable
  192. });
  193. row.enable = enable;
  194. }
  195. }
  196. };
  197. </script>