InspectionAccountSet.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div class="client-account-set ">
  3. <div class="part-box-top">
  4. <Button type="success" icon="md-add" @click="toAdd">新增</Button>
  5. </div>
  6. <div class="part-box">
  7. <table class="table">
  8. <tr>
  9. <th>序号</th>
  10. <th>角色</th>
  11. <th>账号</th>
  12. <th>操作</th>
  13. </tr>
  14. <tr v-for="(user, index) in users" :key="index">
  15. <td style="width: 60px;">{{ index + 1 }}</td>
  16. <td>{{ user.roleName }}</td>
  17. <td style="width: 200px;">
  18. <Input v-model="user.loginName" clearable></Input>
  19. </td>
  20. <td>
  21. <Button
  22. size="small"
  23. type="primary"
  24. :disabled="!user.id"
  25. @click="toSave(user)"
  26. >重置</Button
  27. >
  28. <Button size="small" type="primary" @click="toSave(user)"
  29. >保存</Button
  30. >
  31. <Button size="small" type="error" @click="toDelete(index)"
  32. >删除</Button
  33. >
  34. </td>
  35. </tr>
  36. </table>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import {
  42. inspectionUserPageList,
  43. deleteInspectionUser,
  44. uploadInspectionUser
  45. } from "@/api";
  46. const initModalForm = {
  47. id: "",
  48. roleName: "纪检",
  49. loginName: "",
  50. password: ""
  51. };
  52. export default {
  53. name: "client-account-set",
  54. data() {
  55. return {
  56. workId: this.$route.params.workId,
  57. users: [],
  58. curUser: {}
  59. };
  60. },
  61. mounted() {
  62. this.getList();
  63. },
  64. methods: {
  65. async getList() {
  66. const datas = {
  67. workId: this.workId
  68. };
  69. const data = await inspectionUserPageList(datas);
  70. this.users = data.map(item => {
  71. return {
  72. id: item.id,
  73. loginName: item.loginName,
  74. password: item.password,
  75. roleName: "纪检"
  76. };
  77. });
  78. if (!this.users.length) this.toAdd();
  79. },
  80. toAdd() {
  81. this.users.push({ ...initModalForm });
  82. },
  83. async toSave(row) {
  84. if (!row.loginName.match(new RegExp(`^[a-zA-Z0-9_]{3,20}$`))) {
  85. this.$Message.error(
  86. "当前账号名只能由数字、字母和下划线组成,长度3-20个字符"
  87. );
  88. return;
  89. }
  90. await uploadInspectionUser({
  91. id: row.id,
  92. loginName: row.loginName,
  93. password: "123456"
  94. });
  95. this.$Message.success("保存成功!");
  96. this.getList();
  97. },
  98. toDelete(index) {
  99. const row = this.users[index];
  100. if (!row.id) {
  101. this.users.splice(index, 1);
  102. return;
  103. }
  104. this.$Modal.confirm({
  105. title: "删除警告",
  106. content: "确定要删除当前账号吗?",
  107. onOk: () => {
  108. this.toDel(row.id);
  109. }
  110. });
  111. },
  112. async toDel(id) {
  113. await deleteInspectionUser(id);
  114. this.$Message.success("删除成功!");
  115. this.getList();
  116. }
  117. }
  118. };
  119. </script>