index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <!-- 搜索表单 -->
  5. <role-search @search="reload" />
  6. <!-- 数据表格 -->
  7. <ele-pro-table
  8. ref="table"
  9. :columns="columns"
  10. :datasource="datasource"
  11. :selection.sync="selection"
  12. cache-key="systemRoleTable"
  13. >
  14. <!-- 表头工具栏 -->
  15. <template v-slot:toolbar>
  16. <el-button
  17. size="small"
  18. type="primary"
  19. icon="el-icon-plus"
  20. class="ele-btn-icon"
  21. @click="openEdit()"
  22. >
  23. 添加
  24. </el-button>
  25. <el-button
  26. size="small"
  27. type="danger"
  28. icon="el-icon-delete"
  29. class="ele-btn-icon"
  30. @click="removeBatch"
  31. >
  32. 删除
  33. </el-button>
  34. </template>
  35. <template v-slot:enable="{ row }">
  36. <el-switch
  37. v-model="row.enable"
  38. active-color="#13ce66"
  39. inactive-color="#ff4949"
  40. :active-value="1"
  41. :inactive-value="0"
  42. @change="changeEnable(row)"
  43. >
  44. </el-switch>
  45. </template>
  46. <!-- 操作列 -->
  47. <template v-slot:action="{ row }">
  48. <el-link
  49. type="primary"
  50. :underline="false"
  51. icon="el-icon-edit"
  52. @click="openEdit(row)"
  53. >
  54. 修改
  55. </el-link>
  56. <el-link
  57. type="primary"
  58. :underline="false"
  59. icon="el-icon-finished"
  60. @click="openAuth(row)"
  61. >
  62. 分配权限
  63. </el-link>
  64. <el-popconfirm
  65. class="ele-action"
  66. title="确定要删除此角色吗?"
  67. @confirm="remove(row)"
  68. >
  69. <template v-slot:reference>
  70. <el-link type="danger" :underline="false" icon="el-icon-delete">
  71. 删除
  72. </el-link>
  73. </template>
  74. </el-popconfirm>
  75. </template>
  76. </ele-pro-table>
  77. </el-card>
  78. <!-- 编辑弹窗 -->
  79. <role-edit :data="current" :visible.sync="showEdit" @done="reload" />
  80. <!-- 权限分配弹窗 -->
  81. <role-auth :data="current" :visible.sync="showAuth" />
  82. </div>
  83. </template>
  84. <script>
  85. import RoleSearch from './components/role-search.vue';
  86. import RoleEdit from './components/role-edit.vue';
  87. import RoleAuth from './components/role-auth.vue';
  88. import {
  89. pageRoles,
  90. removeRole,
  91. removeRoles,
  92. putRoles
  93. } from '@/api/system/role';
  94. export default {
  95. name: 'SystemRole',
  96. components: {
  97. RoleSearch,
  98. RoleEdit,
  99. RoleAuth
  100. },
  101. data() {
  102. return {
  103. // 表格列配置
  104. columns: [
  105. {
  106. columnKey: 'selection',
  107. type: 'selection',
  108. width: 45,
  109. align: 'center',
  110. fixed: 'left'
  111. },
  112. {
  113. columnKey: 'index',
  114. label: '#',
  115. type: 'index',
  116. width: 45,
  117. align: 'center',
  118. showOverflowTooltip: true,
  119. fixed: 'left'
  120. },
  121. {
  122. prop: 'name',
  123. label: '角色名称',
  124. align: 'center',
  125. showOverflowTooltip: true,
  126. minWidth: 110
  127. },
  128. {
  129. prop: 'groupId',
  130. label: '组织ID',
  131. align: 'center',
  132. showOverflowTooltip: true,
  133. minWidth: 110
  134. },
  135. {
  136. prop: 'enable',
  137. label: '启用状态',
  138. align: 'center',
  139. showOverflowTooltip: true,
  140. slot: 'enable',
  141. minWidth: 110
  142. },
  143. {
  144. prop: 'createTime',
  145. label: '创建时间',
  146. align: 'center',
  147. showOverflowTooltip: true,
  148. minWidth: 110,
  149. formatter: (_row, _column, cellValue) => {
  150. return this.$util.toDateString(cellValue);
  151. }
  152. },
  153. {
  154. columnKey: 'action',
  155. label: '操作',
  156. width: 230,
  157. align: 'center',
  158. resizable: false,
  159. slot: 'action',
  160. showOverflowTooltip: true
  161. }
  162. ],
  163. // 表格选中数据
  164. selection: [],
  165. // 当前编辑数据
  166. current: null,
  167. // 是否显示编辑弹窗
  168. showEdit: false,
  169. // 是否显示导入弹窗
  170. showAuth: false
  171. };
  172. },
  173. created() {},
  174. methods: {
  175. /* 表格数据源 */
  176. datasource({ page, limit, where, order }) {
  177. console.log(where);
  178. return pageRoles({ pageNum: page, size: limit, ...where });
  179. },
  180. async changeEnable(row) {
  181. const res = await putRoles(row);
  182. if (res.code == 0) {
  183. this.$message({
  184. type: 'success',
  185. message: '修改成功',
  186. customClass: 'ele-message-border'
  187. });
  188. this.reload();
  189. }
  190. },
  191. /* 刷新表格 */
  192. reload(where) {
  193. this.$refs.table.reload({ page: 1, where });
  194. },
  195. /* 显示编辑 */
  196. openEdit(row) {
  197. this.current = row;
  198. this.showEdit = true;
  199. },
  200. /* 显示分配权限 */
  201. openAuth(row) {
  202. this.current = row;
  203. this.showAuth = true;
  204. },
  205. /* 删除 */
  206. remove(row) {
  207. const loading = this.$loading({ lock: true });
  208. removeRole(row.id)
  209. .then((msg) => {
  210. loading.close();
  211. this.$message.success(msg);
  212. this.reload();
  213. })
  214. .catch((e) => {
  215. loading.close();
  216. this.$message.error(e.message);
  217. });
  218. },
  219. /* 批量删除 */
  220. removeBatch() {
  221. if (!this.selection.length) {
  222. this.$message.error('请至少选择一条数据');
  223. return;
  224. }
  225. this.$confirm('确定要删除选中的角色吗?', '提示', {
  226. type: 'warning'
  227. })
  228. .then(() => {
  229. const loading = this.$loading({ lock: true });
  230. removeRole(
  231. this.selection.map((d) => d.id),
  232. true
  233. )
  234. .then((msg) => {
  235. loading.close();
  236. this.$message.success(msg);
  237. this.reload();
  238. })
  239. .catch((e) => {
  240. loading.close();
  241. this.$message.error(e.message);
  242. });
  243. })
  244. .catch(() => {});
  245. }
  246. }
  247. };
  248. </script>