血透系统PC前端

admin.vue 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div class="main-contain">
  3. <div class="position">
  4. <bread-crumb></bread-crumb>
  5. <router-link to="/role/admin/create">
  6. <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" style="float:right;">新增</el-button>
  7. </router-link>
  8. </div>
  9. <div class="app-container">
  10. <el-table :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)'}" style="width:100%;" ref="table" :data="admins" v-loading="is_loading_admins">
  11. <el-table-column label="用户名" prop="user_name" width="160"></el-table-column>
  12. <el-table-column label="最后登录IP" prop="ip" width="150"></el-table-column>
  13. <el-table-column label="最后登录时间" prop="last_login_time" width="170">
  14. <template slot-scope="scope">
  15. <span>{{ scope.row.last_login_time == 0 ? '' : (_parseTime(scope.row.last_login_time, '{y}-{m}-{d} {h}:{i}'))}}</span>
  16. </template>
  17. </el-table-column>
  18. <el-table-column label="角色" prop="role_name" width="160"></el-table-column>
  19. <el-table-column label="职称" prop="title_name" width="160"></el-table-column>
  20. <el-table-column label="状态" width="100">
  21. <template slot-scope="scope">
  22. <div v-if="scope.row.status == 1" style="color: #67C23A; font-size:20px;">
  23. <li class="el-icon-success"></li>
  24. </div>
  25. <div v-else style="color: #F56C6C; font-size:20px;">
  26. <li class="el-icon-error"></li>
  27. </div>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="操作" >
  31. <template slot-scope="scope">
  32. <router-link :to="{ path:'/role/admin/edit', query:{ id:scope.row.user_id }}">
  33. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  34. <el-button type="primary" icon="el-icon-edit-outline" size="small"></el-button>
  35. </el-tooltip>
  36. </router-link>
  37. <el-tooltip class="item" effect="dark" content="移除" placement="top">
  38. <el-button type="danger" size="small" icon="el-icon-delete" v-if="scope.row.status == 1" @click="disableAdminAction(scope.row)"></el-button>
  39. </el-tooltip>
  40. <el-tooltip class="item" effect="dark" content="恢复" placement="top">
  41. <el-button size="small" type="info" icon="el-icon-refresh" v-if="scope.row.status == 0" @click="recoverAdminAction(scope.row)"></el-button>
  42. </el-tooltip>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. <el-row style="margin-top: 15px;" v-if="admin_total_count > 10">
  47. <el-col :span="24">
  48. <el-pagination :total="admin_total_count" :current-page.sync="current_page" @current-change="pageChange" :page-size="10" layout="total, prev, pager, next, jumper"></el-pagination>
  49. </el-col>
  50. </el-row>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import {adminMainView, getAdmins, setAdminStatus} from '@/api/role/admin'
  56. import { parseTime } from '@/utils'
  57. import BreadCrumb from "@/xt_pages/components/bread-crumb";
  58. export default {
  59. name: 'adminManage',
  60. data() {
  61. return {
  62. is_loading_admins: true,
  63. admins: [], // [{user_id, user_name, role_name, title_name, ip, last_login_time, status}]
  64. admin_total_count: 0,
  65. current_page: 1,
  66. is_exist_role: false
  67. }
  68. },
  69. components:{
  70. BreadCrumb
  71. },
  72. created: function() {
  73. adminMainView().then(rs => {
  74. this.is_loading_admins = false
  75. var resp = rs.data
  76. if (resp.state === 1) {
  77. this.admins.push(...resp.data.admins)
  78. this.admin_total_count = resp.data.total_count
  79. this.is_exist_role = resp.data.is_exist_role
  80. this.current_page = 1
  81. } else {
  82. this.$message.error(resp.msg)
  83. }
  84. }).catch(err => {
  85. this.is_loading_admins = false
  86. this.$message.error(err)
  87. })
  88. },
  89. computed: {
  90. should_update_admins() {
  91. return this.$store.getters.xt_role_temps.did_admins_changed
  92. }
  93. },
  94. methods: {
  95. _parseTime(time, format) {
  96. return parseTime(time, format)
  97. },
  98. requestAdminsWithPage: function(page) {
  99. this.admins.splice(0, this.admins.length)
  100. this.is_loading_admins = true
  101. getAdmins(page).then(rs => {
  102. this.is_loading_admins = false
  103. const resp = rs.data
  104. console.log(resp)
  105. if (resp.state === 1) {
  106. this.admins.push(...resp.data.admins)
  107. this.admin_total_count = resp.data.total_count
  108. } else {
  109. this.$message.error(resp.msg)
  110. }
  111. }).catch(err => {
  112. this.is_loading_admins = false
  113. this.$message.error(err)
  114. })
  115. },
  116. addAdminAction: function() {
  117. this.$router.push({path:'/role/admin/create'})
  118. },
  119. disableAdminAction: function(row) {
  120. this.$msgbox({
  121. title: '提示',
  122. message: '是否确定要移除该管理员',
  123. showCancelButton: true,
  124. confirmButtonText: '确定',
  125. cancelButtonText: '取消',
  126. type: 'warning',
  127. beforeClose: (action, instance, done) => {
  128. if (action === 'confirm') {
  129. instance.confirmButtonLoading = true
  130. instance.confirmButtonText = '删除中...'
  131. setAdminStatus(row.user_id, false).then(rs => {
  132. done()
  133. instance.confirmButtonLoading = false
  134. const resp = rs.data
  135. if (resp.state === 1) {
  136. row.status = 0
  137. } else {
  138. this.$message.error(resp.msg)
  139. }
  140. }).catch(err => {
  141. done()
  142. instance.confirmButtonLoading = false
  143. this.$message.error(err)
  144. })
  145. } else {
  146. done()
  147. }
  148. }
  149. })
  150. },
  151. recoverAdminAction: function(row) {
  152. const loading = this.$loading({
  153. lock: true,
  154. text: '正在恢复管理员...',
  155. spinner: 'el-icon-loading',
  156. background: 'rgba(0, 0, 0, 0.7)'
  157. })
  158. setAdminStatus(row.user_id, true).then(rs => {
  159. loading.close()
  160. const resp = rs.data
  161. if (resp.state === 1) {
  162. row.status = 1
  163. } else {
  164. this.$message.error(resp.msg)
  165. }
  166. }).catch(err => {
  167. loading.close()
  168. this.$message.error(err)
  169. })
  170. },
  171. pageChange: function(nextPage) {
  172. this.requestAdminsWithPage(nextPage)
  173. }
  174. },
  175. watch: {
  176. should_update_admins(should_change) {
  177. if (should_change) {
  178. this.requestAdminsWithPage(this.current_page)
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style rel="stylesheet/scss" lang="scss" scoped>
  185. .el-button+.el-button{
  186. margin-left:0!important;
  187. }
  188. </style>