roles.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div>
  3. <!--条件-->
  4. <el-form :model="listQuery" ref="queryForm" :inline="true">
  5. <el-form-item label="角色编码">
  6. <el-input
  7. v-model="listQuery.roleId"
  8. placeholder="请输入角色编码"
  9. ></el-input>
  10. </el-form-item>
  11. <el-form-item label="角色名称">
  12. <el-input
  13. v-model="listQuery.roleName"
  14. placeholder="请输入角色名称"
  15. ></el-input>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" @click="getData(true, 'search')"
  19. >查询</el-button
  20. >
  21. </el-form-item>
  22. </el-form>
  23. <!--列表-->
  24. <div>
  25. <el-table
  26. ref="multipleTable"
  27. row-key="id"
  28. @selection-change="handleSelectionChange"
  29. v-loading="listLoading"
  30. :data="list"
  31. element-loading-text="加载中"
  32. fit
  33. stripe
  34. >
  35. <template slot="empty">
  36. <img src="@/assets/nopage.png" alt />
  37. <p>暂无数据</p>
  38. </template>
  39. <el-table-column type="selection" width="55" reserve-selection>
  40. </el-table-column>
  41. <el-table-column type="index" label="序号" width="60"></el-table-column>
  42. <el-table-column label="角色编码" prop="id" />
  43. <el-table-column label="角色名称" prop="name" />
  44. </el-table>
  45. </div>
  46. <!--分页-->
  47. <yl-pagination
  48. v-show="total > 0"
  49. :total="total"
  50. :page.sync="listQuery.current"
  51. :limit.sync="listQuery.size"
  52. @pagination="getData(true)"
  53. />
  54. <div slot="footer" class="dialog-footer" style="text-align: right">
  55. <el-button @click="close">取消</el-button>
  56. <el-button type="primary" @click="submit">确定</el-button>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import { getRoleData } from "@/api/system/role";
  62. import ylPagination from "@/components/yl-pagination";
  63. export default {
  64. components: {
  65. ylPagination
  66. },
  67. props: {
  68. checkRole: {
  69. type: Array,
  70. default: []
  71. }
  72. },
  73. data() {
  74. return {
  75. multipleSelection: [],
  76. list: [], //列表
  77. total: 0, //分页
  78. listLoading: true,
  79. listQuery: {
  80. //条件查询
  81. roleName: "",
  82. current: 1,
  83. size: 10,
  84. roleId: ""
  85. }
  86. };
  87. },
  88. created() {
  89. this.getData();
  90. },
  91. methods: {
  92. // 选中数据
  93. handleSelectionChange(val) {
  94. this.multipleSelection = val;
  95. },
  96. // 回显数据
  97. toggleSelection(rows) {
  98. if (rows) {
  99. rows.forEach((row) => {
  100. this.$refs.multipleTable.toggleRowSelection(row, true);
  101. });
  102. } else {
  103. this.$refs.multipleTable.clearSelection();
  104. }
  105. },
  106. // 关闭
  107. close() {
  108. this.$emit("rolesClose", false);
  109. },
  110. // 提交
  111. submit() {
  112. this.$emit("rolesSubmit", this.multipleSelection);
  113. },
  114. //获取列表数据
  115. getData(query, type) {
  116. if (type == "search") {
  117. this.listQuery.current = 1;
  118. }
  119. this.listLoading = true;
  120. getRoleData(this.listQuery)
  121. .then((response) => {
  122. this.list = [];
  123. if (response.data.records.length > 0) {
  124. response.data.records.forEach((item) => {
  125. this.list.push({
  126. id: item.roleId,
  127. name: item.roleName
  128. });
  129. });
  130. }
  131. this.total = response.data.total;
  132. this.listLoading = false;
  133. if (!query) {
  134. this.toggleSelection(this.checkRole);
  135. }
  136. })
  137. .catch((err) => {
  138. this.listLoading = false;
  139. });
  140. }
  141. }
  142. };
  143. </script>
  144. <style scoped>
  145. </style>