index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <div class="filter-view">
  5. <div class="flex1" style="min-width: 200px; max-width: 350px;">
  6. <el-input
  7. v-model="params.pageVo.criteria"
  8. placeholder="Search by Name, Email, Contact"
  9. @keyup.enter.native="getTableData" />
  10. </div>
  11. <div>
  12. <el-button
  13. type="primary"
  14. icon="el-icon-search"
  15. @click="getTableData">
  16. Search
  17. </el-button>
  18. </div>
  19. <div class="filter-flex-button">
  20. <el-button
  21. type="primary"
  22. icon="el-icon-plus"
  23. @click="addUser">
  24. Add
  25. </el-button>
  26. </div>
  27. </div>
  28. </div>
  29. <el-table
  30. v-loading="table.loading"
  31. :data="table.list"
  32. class="no-border"
  33. fit>
  34. <el-table-column
  35. label="Name"
  36. align="center">
  37. <template slot-scope="{row}">
  38. <span>{{ row.userName }}</span>
  39. </template>
  40. </el-table-column>
  41. <el-table-column
  42. label="Email Address"
  43. align="center"
  44. prop="email"/>
  45. <el-table-column
  46. label="Role"
  47. align="center"
  48. prop="roleName"/>
  49. <el-table-column
  50. label="Description"
  51. align="center"
  52. prop="desc">
  53. <template slot-scope="{row}">
  54. <div
  55. v-for="item in row.desc"
  56. v-if="row.desc"
  57. :key="item">
  58. {{item}}
  59. </div>
  60. </template>
  61. </el-table-column>
  62. <el-table-column
  63. label="Last Login"
  64. align="center"
  65. prop="lastLogin"/>
  66. <el-table-column
  67. label="Action"
  68. align="center"
  69. min-width="140">
  70. <template slot-scope="{row}">
  71. <TableAction
  72. @edit="updateUser(row)"
  73. @delete="deleteUser(row)"/>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <div class="right">
  78. <pagination
  79. v-show="table.total > 0"
  80. :total="table.total"
  81. :page.sync="params.pageNo"
  82. :limit.sync="params.pageSize"
  83. @pagination="getTableData" />
  84. </div>
  85. <DialogDetail
  86. v-bind="dialogAction"
  87. @hide="hideDialog"/>
  88. </div>
  89. </template>
  90. <script>
  91. import api from '@/http/api/access'
  92. import Pagination from '@/components/Pagination'
  93. import TableAction from '@/components/TableAction'
  94. import DialogDetail from './DialogDetail'
  95. export default {
  96. data() {
  97. return {
  98. params: {
  99. pageNo: 1,
  100. pageSize: 10,
  101. pageVo: {
  102. criteria: ""
  103. }
  104. },
  105. table: {
  106. loading: false,
  107. list: [],
  108. total: 0
  109. },
  110. dialogAction: {
  111. isEdit: false,
  112. visible: false
  113. }
  114. }
  115. },
  116. components: { Pagination,TableAction,DialogDetail },
  117. created() {
  118. this.getTableData()
  119. },
  120. methods: {
  121. getTableData() {
  122. this.table.loading = true;
  123. api.getAccessPages(this.params).then(res => {
  124. if (res.data) {
  125. this.table.list = res.data
  126. this.table.total = res.total
  127. }
  128. }).catch(err => {
  129. this.$message({
  130. type: 'error',
  131. message: err
  132. })
  133. }).finally(() => {
  134. this.table.loading = false
  135. })
  136. },
  137. hideDialog(e) {
  138. this.dialogAction.id = "";
  139. this.dialogAction.visible = false;
  140. if (e)
  141. this.getTableData();
  142. },
  143. addUser() {
  144. this.dialogAction.id = "";
  145. this.dialogAction.isEdit = false;
  146. this.dialogAction.visible = true;
  147. },
  148. updateUser(row) {
  149. this.dialogAction.id = row.userPk;
  150. this.dialogAction.isEdit = true;
  151. this.dialogAction.visible = true;
  152. },
  153. deleteUser(row) {
  154. this.$confirm('Are you sure you want to delete this user?', 'Delete', {
  155. confirmButtonText: 'Confirm',
  156. cancelButtonText: 'Cancel',
  157. type: 'warning'
  158. }).then(res => {
  159. this.onDeleteUser(row.userPk);
  160. })
  161. },
  162. onDeleteUser(id) {
  163. this.table.loading = true;
  164. api.deleteAccessUser(id).then(res => {
  165. this.$message({
  166. type: 'success',
  167. message: "Successfully deleted!"
  168. })
  169. this.getTableData()
  170. }).catch(err => {
  171. this.$message({
  172. type: 'error',
  173. message: err
  174. })
  175. }).finally(() => {
  176. this.table.loading = false
  177. })
  178. }
  179. }
  180. }
  181. </script>
  182. <style>
  183. </style>