index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div class="roleManagement-container">
  3. <el-divider content-position="left">
  4. 演示环境仅做基础功能展示,若想实现不同角色的真实菜单配置,需将settings.js路由加载模式改为all模式,由后端全面接管路由渲染与权限控制
  5. </el-divider>
  6. <vab-query-form>
  7. <vab-query-form-left-panel :span="12">
  8. <el-button icon="el-icon-plus" type="primary" @click="handleEdit">
  9. 添加
  10. </el-button>
  11. <el-button icon="el-icon-delete" type="danger" @click="handleDelete">
  12. 批量删除
  13. </el-button>
  14. </vab-query-form-left-panel>
  15. <vab-query-form-right-panel :span="12">
  16. <el-form :inline="true" :model="queryForm" @submit.native.prevent>
  17. <el-form-item>
  18. <el-input
  19. v-model.trim="queryForm.permission"
  20. placeholder="请输入查询条件"
  21. clearable
  22. />
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button icon="el-icon-search" type="primary" @click="queryData">
  26. 查询
  27. </el-button>
  28. </el-form-item>
  29. </el-form>
  30. </vab-query-form-right-panel>
  31. </vab-query-form>
  32. <el-table
  33. v-loading="listLoading"
  34. :data="list"
  35. :element-loading-text="elementLoadingText"
  36. @selection-change="setSelectRows"
  37. >
  38. <el-table-column show-overflow-tooltip type="selection"></el-table-column>
  39. <el-table-column
  40. show-overflow-tooltip
  41. prop="id"
  42. label="id"
  43. ></el-table-column>
  44. <el-table-column
  45. show-overflow-tooltip
  46. prop="permission"
  47. label="权限码"
  48. ></el-table-column>
  49. <el-table-column show-overflow-tooltip label="操作" width="200">
  50. <template #default="{ row }">
  51. <el-button type="text" @click="handleEdit(row)">编辑</el-button>
  52. <el-button type="text" @click="handleDelete(row)">删除</el-button>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <el-pagination
  57. background
  58. :current-page="queryForm.pageNo"
  59. :page-size="queryForm.pageSize"
  60. :layout="layout"
  61. :total="total"
  62. @size-change="handleSizeChange"
  63. @current-change="handleCurrentChange"
  64. ></el-pagination>
  65. <edit ref="edit" @fetch-data="fetchData"></edit>
  66. </div>
  67. </template>
  68. <script>
  69. import { getList, doDelete } from "@/api/roleManagement";
  70. import Edit from "./components/RoleManagementEdit";
  71. export default {
  72. name: "RoleManagement",
  73. components: { Edit },
  74. data() {
  75. return {
  76. list: null,
  77. listLoading: true,
  78. layout: "total, sizes, prev, pager, next, jumper",
  79. total: 0,
  80. selectRows: "",
  81. elementLoadingText: "正在加载...",
  82. queryForm: {
  83. pageNo: 1,
  84. pageSize: 10,
  85. permission: "",
  86. },
  87. };
  88. },
  89. created() {
  90. this.fetchData();
  91. },
  92. methods: {
  93. setSelectRows(val) {
  94. this.selectRows = val;
  95. },
  96. handleEdit(row) {
  97. if (row.id) {
  98. this.$refs["edit"].showEdit(row);
  99. } else {
  100. this.$refs["edit"].showEdit();
  101. }
  102. },
  103. handleDelete(row) {
  104. if (row.id) {
  105. this.$baseConfirm("你确定要删除当前项吗", null, async () => {
  106. const { msg } = await doDelete({ ids: row.id });
  107. this.$baseMessage(msg, "success");
  108. this.fetchData();
  109. });
  110. } else {
  111. if (this.selectRows.length > 0) {
  112. const ids = this.selectRows.map((item) => item.id).join();
  113. this.$baseConfirm("你确定要删除选中项吗", null, async () => {
  114. const { msg } = await doDelete({ ids });
  115. this.$baseMessage(msg, "success");
  116. this.fetchData();
  117. });
  118. } else {
  119. this.$baseMessage("未选中任何行", "error");
  120. return false;
  121. }
  122. }
  123. },
  124. handleSizeChange(val) {
  125. this.queryForm.pageSize = val;
  126. this.fetchData();
  127. },
  128. handleCurrentChange(val) {
  129. this.queryForm.pageNo = val;
  130. this.fetchData();
  131. },
  132. queryData() {
  133. this.queryForm.pageNo = 1;
  134. this.fetchData();
  135. },
  136. async fetchData() {
  137. this.listLoading = true;
  138. const { data, totalCount } = await getList(this.queryForm);
  139. this.list = data;
  140. this.total = totalCount;
  141. setTimeout(() => {
  142. this.listLoading = false;
  143. }, 300);
  144. },
  145. },
  146. };
  147. </script>