admin.vue 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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="
  108. scope.row.status == 1 &&
  109. org.creator != scope.row.user_id &&
  110. scope.row.user_id != local_user_id
  111. "
  112. @click="disableAdminAction(scope.row)"
  113. ></el-button>
  114. </el-tooltip>
  115. <el-tooltip
  116. class="item"
  117. effect="dark"
  118. content="恢复"
  119. placement="top"
  120. >
  121. <el-button
  122. size="small"
  123. type="info"
  124. icon="el-icon-refresh"
  125. v-if="
  126. scope.row.status == 0 &&
  127. org.creator != scope.row.user_id &&
  128. scope.row.user_id != local_user_id
  129. "
  130. @click="recoverAdminAction(scope.row)"
  131. ></el-button>
  132. </el-tooltip>
  133. </template>
  134. </el-table-column>
  135. </el-table>
  136. <el-row style="margin-top: 15px;" v-if="admin_total_count > 10">
  137. <el-col :span="24">
  138. <el-pagination
  139. :total="admin_total_count"
  140. :current-page.sync="current_page"
  141. @current-change="pageChange"
  142. :page-size="10"
  143. layout="total, prev, pager, next, jumper"
  144. ></el-pagination>
  145. </el-col>
  146. </el-row>
  147. <admin-info-form ref="admininfoform"></admin-info-form>
  148. </div>
  149. </div>
  150. </template>
  151. <script>
  152. import { adminMainView, getAdmins, setAdminStatus } from "@/api/role/admin";
  153. import { getRoles } from "@/api/role/role";
  154. import { parseTime } from "@/utils";
  155. import BreadCrumb from "@/xt_pages/components/bread-crumb";
  156. import AdminInfoForm from "./components/AdminInfoForm";
  157. export default {
  158. name: "adminManage",
  159. data() {
  160. return {
  161. crumbs: [
  162. { path: false, name: "管理中心" },
  163. { path: false, name: "员工管理" }
  164. ],
  165. is_loading_admins: true,
  166. admins: [], // [{user_id, user_name, role_name, title_name, ip, last_login_time, status}]
  167. admin_total_count: 0,
  168. current_page: 1,
  169. roles: [],
  170. is_exist_role: false,
  171. org: null,
  172. isSubSuperAdmin: false,
  173. local_user_id: 0
  174. };
  175. },
  176. components: {
  177. BreadCrumb,
  178. AdminInfoForm
  179. },
  180. created: function() {
  181. this.local_user_id = this.$store.getters.xt_user.user.id;
  182. let page = 1;
  183. this.getRoles(page);
  184. adminMainView()
  185. .then(rs => {
  186. this.is_loading_admins = false;
  187. var resp = rs.data;
  188. if (resp.state === 1) {
  189. this.admins.push(...resp.data.admins);
  190. this.admin_total_count = resp.data.total_count;
  191. this.is_exist_role = resp.data.is_exist_role;
  192. this.current_page = 1;
  193. this.org = resp.data.org;
  194. this.isSubSuperAdmin = resp.data.isSubSuperAdmin;
  195. //能进入当前页面的角色只有超级管理员和子管理员,如果当前角色是子管理员,需要把超级管理员和其他子管理员的信息去除,子管理员不能编辑超级管理员和其他子管理员信息,
  196. if (this.isSubSuperAdmin) {
  197. //去除管理员信息
  198. for (let i = 0; i < this.admins.length; i++) {
  199. if (this.admins[i].user_id == this.org.creator) {
  200. this.admins.splice(i, 1);
  201. i--;
  202. }
  203. }
  204. //去除其他子管理员信息
  205. for (let i = 0; i < this.admins.length; i++) {
  206. if (
  207. this.admins[i].user_id != this.local_user_id &&
  208. this.admins[i].is_sub_super_admin
  209. ) {
  210. //将自己排除在外
  211. console.log(this.admins[i]);
  212. this.admins.splice(i, 1);
  213. i--;
  214. }
  215. }
  216. }
  217. } else {
  218. this.$message.error(resp.msg);
  219. }
  220. })
  221. .catch(err => {
  222. this.is_loading_admins = false;
  223. this.$message.error(err);
  224. });
  225. },
  226. computed: {
  227. should_update_admins() {
  228. return this.$store.getters.xt_role_temps.did_admins_changed;
  229. }
  230. },
  231. methods: {
  232. getRoles(page) {
  233. getRoles(page)
  234. .then(rs => {
  235. this.loading_roles = false;
  236. const resp = rs.data;
  237. if (resp.state === 1) {
  238. this.roles.push(...resp.data.roles);
  239. } else {
  240. this.$message.error(resp.msg);
  241. }
  242. })
  243. .catch(err => {
  244. this.loading_roles = false;
  245. this.$message.error(err);
  246. });
  247. },
  248. openForm(adminId) {
  249. this.$refs["admininfoform"].open(adminId, this.roles);
  250. },
  251. _parseTime(time, format) {
  252. return parseTime(time, format);
  253. },
  254. requestAdminsWithPage: function(page) {
  255. this.admins.splice(0, this.admins.length);
  256. this.is_loading_admins = true;
  257. getAdmins(page)
  258. .then(rs => {
  259. this.is_loading_admins = false;
  260. const resp = rs.data;
  261. console.log(resp);
  262. if (resp.state === 1) {
  263. this.admins.push(...resp.data.admins);
  264. this.admin_total_count = resp.data.total_count;
  265. } else {
  266. this.$message.error(resp.msg);
  267. }
  268. })
  269. .catch(err => {
  270. this.is_loading_admins = false;
  271. this.$message.error(err);
  272. });
  273. },
  274. addAdminAction: function() {
  275. this.$router.push({ path: "/role/admin/create" });
  276. },
  277. disableAdminAction: function(row) {
  278. this.$msgbox({
  279. title: "提示",
  280. message: "是否确定要移除该用户",
  281. showCancelButton: true,
  282. confirmButtonText: "确定",
  283. cancelButtonText: "取消",
  284. type: "warning",
  285. beforeClose: (action, instance, done) => {
  286. if (action === "confirm") {
  287. instance.confirmButtonLoading = true;
  288. instance.confirmButtonText = "删除中...";
  289. setAdminStatus(row.user_id, false)
  290. .then(rs => {
  291. done();
  292. instance.confirmButtonLoading = false;
  293. const resp = rs.data;
  294. if (resp.state === 1) {
  295. row.status = 0;
  296. } else {
  297. this.$message.error(resp.msg);
  298. }
  299. })
  300. .catch(err => {
  301. done();
  302. instance.confirmButtonLoading = false;
  303. this.$message.error(err);
  304. });
  305. } else {
  306. done();
  307. }
  308. }
  309. });
  310. },
  311. recoverAdminAction: function(row) {
  312. const loading = this.$loading({
  313. lock: true,
  314. text: "正在恢复管理员...",
  315. spinner: "el-icon-loading",
  316. background: "rgba(0, 0, 0, 0.7)"
  317. });
  318. setAdminStatus(row.user_id, true)
  319. .then(rs => {
  320. loading.close();
  321. const resp = rs.data;
  322. if (resp.state === 1) {
  323. row.status = 1;
  324. } else {
  325. this.$message.error(resp.msg);
  326. }
  327. })
  328. .catch(err => {
  329. loading.close();
  330. this.$message.error(err);
  331. });
  332. },
  333. pageChange: function(nextPage) {
  334. this.requestAdminsWithPage(nextPage);
  335. }
  336. },
  337. watch: {
  338. should_update_admins(should_change) {
  339. if (should_change) {
  340. this.requestAdminsWithPage(this.current_page);
  341. }
  342. }
  343. }
  344. };
  345. </script>
  346. <style rel="stylesheet/scss" lang="scss" scoped>
  347. .el-button + .el-button {
  348. margin-left: 0 !important;
  349. }
  350. </style>
  351. <style>
  352. .el-table td,
  353. .el-table th.is-leaf,
  354. .el-table--border,
  355. .el-table--group {
  356. border-color: #d0d3da;
  357. }
  358. .el-table--border::after,
  359. .el-table--group::after,
  360. .el-table::before {
  361. background-color: #d0d3da;
  362. }
  363. </style>