role.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <VerticalFlexLayout>
  3. <template #static>
  4. <Breadcrumb />
  5. </template>
  6. <div class="content">
  7. <div class="toolbar">
  8. <div>
  9. <el-input
  10. :style="{ width: '320px' }"
  11. v-model="requestParams.queryParam!.roleName"
  12. clearable
  13. placeholder="请输入角色名称"
  14. @keyup.enter="queryRolesPage"
  15. />
  16. <el-button type="primary" :icon="Search" @click="queryRolesPage" style="margin-left: 20px">查询</el-button>
  17. </div>
  18. <el-button type="primary" @click="openDrawer()" v-permission="PERM_USER.ROLE"> 添加角色 </el-button>
  19. </div>
  20. <el-table :data="roleList">
  21. <el-table-column label="角色ID" width="100" prop="id" />
  22. <el-table-column label="角色名称" prop="roleName" width="480" />
  23. <el-table-column label="备注" prop="remark" width="800" />
  24. <el-table-column label="创建时间" width="240" prop="createdAt" />
  25. <el-table-column label="操作" width="200" fixed="right">
  26. <template #default="{ row }">
  27. <section class="actions">
  28. <img src="@/assets/icons/edit.png" @click="openDrawer(row)" v-permission="PERM_USER.ROLE" />
  29. <img
  30. src="@/assets/icons/delete.png"
  31. @click="deleteRole(row.id)"
  32. v-permission="{ action: [PERM_USER.ROLE] }"
  33. />
  34. </section>
  35. </template>
  36. </el-table-column>
  37. </el-table>
  38. <section class="paginationPosition">
  39. <el-pagination
  40. background
  41. :layout="DEFAULT_LAYOUT"
  42. :page-sizes="[10, 30, 50]"
  43. :total="total"
  44. v-model:page-size="requestParams.pageSize"
  45. v-model:current-page="requestParams.pageNumber"
  46. @change="queryRolesPage"
  47. />
  48. </section>
  49. <RoleDrawer :title="drawerTitle" ref="drawerInstance" @submitted="onSubmitRole" />
  50. </div>
  51. </VerticalFlexLayout>
  52. </template>
  53. <script lang="ts" setup>
  54. import { ref, onMounted } from 'vue';
  55. import { Search } from '@element-plus/icons-vue';
  56. import { DEFAULT_LAYOUT } from '@/constant/pagination';
  57. import RoleDrawer from './components/RoleDrawer.vue';
  58. import useRolesQuery from './hooks/useRolesQuery';
  59. import { Role } from '@/types/role/type';
  60. import { deleteRole as _deleteRole } from '@/api/system/role';
  61. import { PERM_USER } from '@/types/permission/constants';
  62. import Breadcrumb from '@/components/Breadcrumb.vue';
  63. import VerticalFlexLayout from '@/components/VerticalFlexLayout.vue';
  64. import { msgConfirm } from '@/utils/element-plus/messageBox';
  65. const { roleList, total, queryRolesPage, requestParams } = useRolesQuery();
  66. // drawer 相关变量
  67. const drawerTitle = ref('');
  68. const drawerInstance = ref<InstanceType<typeof RoleDrawer>>();
  69. const openDrawer = (row?: Role) => {
  70. drawerTitle.value = row ? '编辑角色' : '添加角色';
  71. drawerInstance.value?.open(row);
  72. };
  73. /**
  74. * 创建或编辑角色后重新获取列表
  75. */
  76. const onSubmitRole = () => {
  77. queryRolesPage();
  78. };
  79. /**
  80. * 删除角色
  81. */
  82. const deleteRole = async (roleId: number) => {
  83. try {
  84. await msgConfirm('删除后无法回复,确认删除吗?', '确认删除', { type: 'warning' });
  85. await _deleteRole(roleId);
  86. queryRolesPage();
  87. } catch (e) {
  88. console.error(e);
  89. }
  90. };
  91. onMounted(() => {
  92. queryRolesPage();
  93. });
  94. </script>
  95. <style scoped>
  96. .actions {
  97. display: flex;
  98. }
  99. .actions > img {
  100. margin-right: 24px;
  101. cursor: pointer;
  102. }
  103. .content {
  104. padding: 20px;
  105. }
  106. .toolbar {
  107. margin-bottom: 20px;
  108. display: flex;
  109. justify-content: space-between;
  110. }
  111. </style>