index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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="systemRoleTable15"
  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: 55,
  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. isUpdate: false
  172. };
  173. },
  174. created () {},
  175. methods: {
  176. /* 表格数据源 */
  177. datasource ({ page, limit, where, order }) {
  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. if (row) {
  198. this.current = Object.assign({}, row);
  199. } else {
  200. this.current = null;
  201. }
  202. this.showEdit = true;
  203. },
  204. /* 显示分配权限 */
  205. openAuth (row) {
  206. if (row) {
  207. this.isUpdate = true;
  208. this.current = Object.assign({}, row);
  209. } else {
  210. this.isUpdate = false;
  211. }
  212. this.showAuth = true;
  213. },
  214. /* 删除 */
  215. remove (row) {
  216. const loading = this.$loading({ lock: true });
  217. removeRole(row.id)
  218. .then((msg) => {
  219. loading.close();
  220. this.$message.success(msg);
  221. this.reload();
  222. })
  223. .catch((e) => {
  224. loading.close();
  225. this.$message.error(e.message);
  226. });
  227. },
  228. /* 批量删除 */
  229. removeBatch () {
  230. if (!this.selection.length) {
  231. this.$message.error('请至少选择一条数据');
  232. return;
  233. }
  234. this.$confirm('确定要删除选中的角色吗?', '提示', {
  235. type: 'warning'
  236. })
  237. .then(() => {
  238. const loading = this.$loading({ lock: true });
  239. removeRole(
  240. this.selection.map((d) => d.id),
  241. true
  242. )
  243. .then((msg) => {
  244. loading.close();
  245. this.$message.success(msg);
  246. this.reload();
  247. })
  248. .catch((e) => {
  249. loading.close();
  250. this.$message.error(e.message);
  251. });
  252. })
  253. .catch(() => {});
  254. }
  255. }
  256. };
  257. </script>