admin.vue 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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
  7. type="primary"
  8. size="small"
  9. icon="el-icon-circle-plus-outline"
  10. style="float:right;"
  11. @click="openForm(0)"
  12. >新增</el-button
  13. >
  14. <!-- </router-link> -->
  15. </div>
  16. <div class="app-container">
  17. <el-table
  18. :row-style="{ color: '#303133' }"
  19. :header-cell-style="{
  20. backgroundColor: 'rgb(245, 247, 250)',
  21. color: '#606266'
  22. }"
  23. style="width:100%;"
  24. ref="table"
  25. border
  26. :data="admins"
  27. v-loading="is_loading_admins"
  28. >
  29. <el-table-column
  30. label="用户名"
  31. prop="user_name"
  32. min-width="160"
  33. align="center"
  34. ></el-table-column>
  35. <el-table-column
  36. label="最后登录IP"
  37. prop="ip"
  38. min-width="150"
  39. align="center"
  40. ></el-table-column>
  41. <el-table-column
  42. label="最后登录时间"
  43. prop="last_login_time"
  44. min-width="170"
  45. align="center"
  46. >
  47. <template slot-scope="scope">
  48. <span>{{
  49. scope.row.last_login_time == 0
  50. ? ""
  51. : _parseTime(scope.row.last_login_time, "{y}-{m}-{d} {h}:{i}")
  52. }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column
  56. label="角色"
  57. prop="role_name"
  58. min-width="160"
  59. align="center"
  60. ></el-table-column>
  61. <el-table-column
  62. label="职称"
  63. prop="title_name"
  64. min-width="160"
  65. align="center"
  66. ></el-table-column>
  67. <el-table-column label="状态" min-width="100" align="center">
  68. <template slot-scope="scope">
  69. <div
  70. v-if="scope.row.status == 1"
  71. style="color: #67C23A; font-size:20px;"
  72. >
  73. <li class="el-icon-success"></li>
  74. </div>
  75. <div v-else style="color: #F56C6C; font-size:20px;">
  76. <li class="el-icon-error"></li>
  77. </div>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="操作" width="120" align="center">
  81. <template slot-scope="scope">
  82. <!-- <router-link :to="{ path:'/role/admin/edit', query:{ id:scope.row.user_id }}"> -->
  83. <el-tooltip
  84. class="item"
  85. effect="dark"
  86. content="编辑"
  87. placement="top"
  88. >
  89. <el-button
  90. type="primary"
  91. icon="el-icon-edit-outline"
  92. size="small"
  93. @click="openForm(scope.row.user_id)"
  94. ></el-button>
  95. </el-tooltip>
  96. <!-- </router-link> -->
  97. <el-tooltip
  98. class="item"
  99. effect="dark"
  100. content="移除"
  101. placement="top"
  102. >
  103. <el-button
  104. type="danger"
  105. size="small"
  106. icon="el-icon-delete"
  107. v-if="scope.row.status == 1 && org.creator != scope.row.user_id && (scope.row.user_id != local_user_id )"
  108. @click="disableAdminAction(scope.row)"
  109. ></el-button>
  110. </el-tooltip>
  111. <el-tooltip
  112. class="item"
  113. effect="dark"
  114. content="恢复"
  115. placement="top"
  116. >
  117. <el-button
  118. size="small"
  119. type="info"
  120. icon="el-icon-refresh"
  121. v-if="scope.row.status == 0 && org.creator != scope.row.user_id && (scope.row.user_id != local_user_id )"
  122. @click="recoverAdminAction(scope.row)"
  123. ></el-button>
  124. </el-tooltip>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. <el-row style="margin-top: 15px;" v-if="admin_total_count > 10">
  129. <el-col :span="24">
  130. <el-pagination
  131. :total="admin_total_count"
  132. :current-page.sync="current_page"
  133. @current-change="pageChange"
  134. :page-size="10"
  135. layout="total, prev, pager, next, jumper"
  136. ></el-pagination>
  137. </el-col>
  138. </el-row>
  139. <admin-info-form ref="admininfoform"></admin-info-form>
  140. </div>
  141. </div>
  142. </template>
  143. <script>
  144. import { adminMainView, getAdmins, setAdminStatus } from "@/api/role/admin";
  145. import { getRoles } from "@/api/role/role";
  146. import { parseTime } from "@/utils";
  147. import BreadCrumb from "@/xt_pages/components/bread-crumb";
  148. import AdminInfoForm from "./components/AdminInfoForm";
  149. export default {
  150. name: "adminManage",
  151. data() {
  152. return {
  153. crumbs: [
  154. { path: false, name: "权限管理" },
  155. { path: false, name: "用户管理" }
  156. ],
  157. is_loading_admins: true,
  158. admins: [], // [{user_id, user_name, role_name, title_name, ip, last_login_time, status}]
  159. admin_total_count: 0,
  160. current_page: 1,
  161. roles:[],
  162. is_exist_role: false,
  163. org: null,
  164. isSubSuperAdmin:false,
  165. local_user_id: 0,
  166. };
  167. },
  168. components: {
  169. BreadCrumb,
  170. AdminInfoForm
  171. },
  172. created: function() {
  173. this.local_user_id = this.$store.getters.xt_user.user.id
  174. this.local_user_id = 597
  175. let page = 1
  176. this.getRoles(page)
  177. adminMainView()
  178. .then(rs => {
  179. this.is_loading_admins = false;
  180. var resp = rs.data;
  181. if (resp.state === 1) {
  182. this.admins.push(...resp.data.admins);
  183. this.admin_total_count = resp.data.total_count;
  184. this.is_exist_role = resp.data.is_exist_role;
  185. this.current_page = 1;
  186. this.org = resp.data.org
  187. this.isSubSuperAdmin = resp.data.isSubSuperAdmin
  188. //能进入当前页面的角色只有超级管理员和子管理员,如果当前角色是子管理员,需要把超级管理员和其他子管理员的信息去除,子管理员不能编辑超级管理员和其他子管理员信息,
  189. if(this.isSubSuperAdmin) {
  190. //去除管理员信息
  191. for (let i = 0; i < this.admins.length; i++){
  192. if (this.admins[i].user_id == this.org.creator) {
  193. this.admins.splice(i, 1)
  194. i--
  195. }
  196. }
  197. //去除其他子管理员信息
  198. for (let i = 0; i < this.admins.length; i++){
  199. if (this.admins[i].user_id != this.local_user_id && this.admins[i].is_sub_super_admin) { //将自己排除在外
  200. console.log(this.admins[i])
  201. this.admins.splice(i, 1)
  202. i--
  203. }
  204. }
  205. }
  206. } else {
  207. this.$message.error(resp.msg);
  208. }
  209. })
  210. .catch(err => {
  211. this.is_loading_admins = false;
  212. this.$message.error(err);
  213. });
  214. },
  215. computed: {
  216. should_update_admins() {
  217. return this.$store.getters.xt_role_temps.did_admins_changed;
  218. }
  219. },
  220. methods: {
  221. getRoles(page){
  222. getRoles(page)
  223. .then(rs => {
  224. this.loading_roles = false;
  225. const resp = rs.data;
  226. if (resp.state === 1) {
  227. this.roles.push(...resp.data.roles);
  228. } else {
  229. this.$message.error(resp.msg);
  230. }
  231. })
  232. .catch(err => {
  233. this.loading_roles = false;
  234. this.$message.error(err);
  235. });
  236. },
  237. openForm(adminId) {
  238. this.$refs["admininfoform"].open(adminId,this.roles);
  239. },
  240. _parseTime(time, format) {
  241. return parseTime(time, format);
  242. },
  243. requestAdminsWithPage: function(page) {
  244. this.admins.splice(0, this.admins.length);
  245. this.is_loading_admins = true;
  246. getAdmins(page)
  247. .then(rs => {
  248. this.is_loading_admins = false;
  249. const resp = rs.data;
  250. console.log(resp);
  251. if (resp.state === 1) {
  252. this.admins.push(...resp.data.admins);
  253. this.admin_total_count = resp.data.total_count;
  254. } else {
  255. this.$message.error(resp.msg);
  256. }
  257. })
  258. .catch(err => {
  259. this.is_loading_admins = false;
  260. this.$message.error(err);
  261. });
  262. },
  263. addAdminAction: function() {
  264. this.$router.push({ path: "/role/admin/create" });
  265. },
  266. disableAdminAction: function(row) {
  267. this.$msgbox({
  268. title: "提示",
  269. message: "是否确定要移除该用户",
  270. showCancelButton: true,
  271. confirmButtonText: "确定",
  272. cancelButtonText: "取消",
  273. type: "warning",
  274. beforeClose: (action, instance, done) => {
  275. if (action === "confirm") {
  276. instance.confirmButtonLoading = true;
  277. instance.confirmButtonText = "删除中...";
  278. setAdminStatus(row.user_id, false)
  279. .then(rs => {
  280. done();
  281. instance.confirmButtonLoading = false;
  282. const resp = rs.data;
  283. if (resp.state === 1) {
  284. row.status = 0;
  285. } else {
  286. this.$message.error(resp.msg);
  287. }
  288. })
  289. .catch(err => {
  290. done();
  291. instance.confirmButtonLoading = false;
  292. this.$message.error(err);
  293. });
  294. } else {
  295. done();
  296. }
  297. }
  298. });
  299. },
  300. recoverAdminAction: function(row) {
  301. const loading = this.$loading({
  302. lock: true,
  303. text: "正在恢复管理员...",
  304. spinner: "el-icon-loading",
  305. background: "rgba(0, 0, 0, 0.7)"
  306. });
  307. setAdminStatus(row.user_id, true)
  308. .then(rs => {
  309. loading.close();
  310. const resp = rs.data;
  311. if (resp.state === 1) {
  312. row.status = 1;
  313. } else {
  314. this.$message.error(resp.msg);
  315. }
  316. })
  317. .catch(err => {
  318. loading.close();
  319. this.$message.error(err);
  320. });
  321. },
  322. pageChange: function(nextPage) {
  323. this.requestAdminsWithPage(nextPage);
  324. }
  325. },
  326. watch: {
  327. should_update_admins(should_change) {
  328. if (should_change) {
  329. this.requestAdminsWithPage(this.current_page);
  330. }
  331. }
  332. }
  333. };
  334. </script>
  335. <style rel="stylesheet/scss" lang="scss" scoped>
  336. .el-button + .el-button {
  337. margin-left: 0 !important;
  338. }
  339. </style>
  340. <style>
  341. .el-table td,
  342. .el-table th.is-leaf,
  343. .el-table--border,
  344. .el-table--group {
  345. border-color: #d0d3da;
  346. }
  347. .el-table--border::after,
  348. .el-table--group::after,
  349. .el-table::before {
  350. background-color: #d0d3da;
  351. }
  352. </style>