血透系统PC前端

admin.vue 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div class="main-contain">
  3. <div class="position">
  4. <bread-crumb :crumbs='crumbs'></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;" @click="openForm(0)">新增</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" border :data="admins" v-loading="is_loading_admins">
  11. <el-table-column label="用户名" prop="user_name" min-width="160" align="center"></el-table-column>
  12. <el-table-column label="最后登录IP" prop="ip" min-width="150" align="center"></el-table-column>
  13. <el-table-column label="最后登录时间" prop="last_login_time" min-width="170" align="center">
  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" min-width="160" align="center"></el-table-column>
  19. <el-table-column label="职称" prop="title_name" min-width="160" align="center"></el-table-column>
  20. <el-table-column label="状态" min-width="100" align="center">
  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="操作" width="120" align="center">
  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" @click="openForm(scope.row.user_id)"></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. <admin-info-form ref="admininfoform" ></admin-info-form>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import {adminMainView, getAdmins, setAdminStatus} from '@/api/role/admin'
  57. import { parseTime } from '@/utils'
  58. import BreadCrumb from "@/xt_pages/components/bread-crumb";
  59. import AdminInfoForm from "./components/AdminInfoForm";
  60. export default {
  61. name: 'adminManage',
  62. data() {
  63. return {
  64. crumbs:[
  65. {path:false, name:'权限管理'},
  66. {path:false, name:'用户管理'},
  67. ],
  68. is_loading_admins: true,
  69. admins: [], // [{user_id, user_name, role_name, title_name, ip, last_login_time, status}]
  70. admin_total_count: 0,
  71. current_page: 1,
  72. is_exist_role: false
  73. }
  74. },
  75. components:{
  76. BreadCrumb,
  77. AdminInfoForm
  78. },
  79. created: function() {
  80. adminMainView().then(rs => {
  81. this.is_loading_admins = false
  82. var resp = rs.data
  83. if (resp.state === 1) {
  84. this.admins.push(...resp.data.admins)
  85. this.admin_total_count = resp.data.total_count
  86. this.is_exist_role = resp.data.is_exist_role
  87. this.current_page = 1
  88. } else {
  89. this.$message.error(resp.msg)
  90. }
  91. }).catch(err => {
  92. this.is_loading_admins = false
  93. this.$message.error(err)
  94. })
  95. },
  96. computed: {
  97. should_update_admins() {
  98. return this.$store.getters.xt_role_temps.did_admins_changed
  99. }
  100. },
  101. methods: {
  102. openForm(adminId) {
  103. this.$refs['admininfoform'].open(adminId);
  104. },
  105. _parseTime(time, format) {
  106. return parseTime(time, format)
  107. },
  108. requestAdminsWithPage: function(page) {
  109. this.admins.splice(0, this.admins.length)
  110. this.is_loading_admins = true
  111. getAdmins(page).then(rs => {
  112. this.is_loading_admins = false
  113. const resp = rs.data
  114. console.log(resp)
  115. if (resp.state === 1) {
  116. this.admins.push(...resp.data.admins)
  117. this.admin_total_count = resp.data.total_count
  118. } else {
  119. this.$message.error(resp.msg)
  120. }
  121. }).catch(err => {
  122. this.is_loading_admins = false
  123. this.$message.error(err)
  124. })
  125. },
  126. addAdminAction: function() {
  127. this.$router.push({path:'/role/admin/create'})
  128. },
  129. disableAdminAction: function(row) {
  130. this.$msgbox({
  131. title: '提示',
  132. message: '是否确定要移除该管理员',
  133. showCancelButton: true,
  134. confirmButtonText: '确定',
  135. cancelButtonText: '取消',
  136. type: 'warning',
  137. beforeClose: (action, instance, done) => {
  138. if (action === 'confirm') {
  139. instance.confirmButtonLoading = true
  140. instance.confirmButtonText = '删除中...'
  141. setAdminStatus(row.user_id, false).then(rs => {
  142. done()
  143. instance.confirmButtonLoading = false
  144. const resp = rs.data
  145. if (resp.state === 1) {
  146. row.status = 0
  147. } else {
  148. this.$message.error(resp.msg)
  149. }
  150. }).catch(err => {
  151. done()
  152. instance.confirmButtonLoading = false
  153. this.$message.error(err)
  154. })
  155. } else {
  156. done()
  157. }
  158. }
  159. })
  160. },
  161. recoverAdminAction: function(row) {
  162. const loading = this.$loading({
  163. lock: true,
  164. text: '正在恢复管理员...',
  165. spinner: 'el-icon-loading',
  166. background: 'rgba(0, 0, 0, 0.7)'
  167. })
  168. setAdminStatus(row.user_id, true).then(rs => {
  169. loading.close()
  170. const resp = rs.data
  171. if (resp.state === 1) {
  172. row.status = 1
  173. } else {
  174. this.$message.error(resp.msg)
  175. }
  176. }).catch(err => {
  177. loading.close()
  178. this.$message.error(err)
  179. })
  180. },
  181. pageChange: function(nextPage) {
  182. this.requestAdminsWithPage(nextPage)
  183. }
  184. },
  185. watch: {
  186. should_update_admins(should_change) {
  187. if (should_change) {
  188. this.requestAdminsWithPage(this.current_page)
  189. }
  190. }
  191. }
  192. }
  193. </script>
  194. <style rel="stylesheet/scss" lang="scss" scoped>
  195. .el-button+.el-button{
  196. margin-left:0!important;
  197. }
  198. </style>