userManagementList.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div class="app-container">
  3. <a-spin :spinning="loading">
  4. <div class="common-card basic-information-box">
  5. <div class="basic-information-title">新建账号</div>
  6. <div class="user-form-div">
  7. <a-form
  8. :form="addAdminForm"
  9. autocomplete="off"
  10. style="width: 400px;"
  11. @submit="handleSubmitForm"
  12. >
  13. <a-form-item
  14. label="账号"
  15. :label-col="labelCol"
  16. :wrapper-col="wrapperCol"
  17. >
  18. <a-input
  19. placeholder="输入账号"
  20. :maxLength="10"
  21. autocomplete="off"
  22. allow-clear
  23. v-decorator="[
  24. 'userName',
  25. {
  26. rules: [{ required: true, message: '请输入账号!' }],
  27. initialValue: '',
  28. },
  29. ]"
  30. />
  31. </a-form-item>
  32. <a-form-item
  33. label="密码"
  34. :label-col="labelCol"
  35. :wrapper-col="wrapperCol"
  36. >
  37. <a-input
  38. placeholder="输入密码"
  39. :maxLength="10"
  40. autocomplete="off"
  41. allow-clear
  42. v-decorator="[
  43. 'password',
  44. {
  45. rules: [{ required: true, message: '请输入密码!' }],
  46. initialValue: '',
  47. },
  48. ]"
  49. />
  50. </a-form-item>
  51. <a-form-item
  52. label="确认密码"
  53. :label-col="labelCol"
  54. :wrapper-col="wrapperCol"
  55. >
  56. <a-input
  57. placeholder="确认密码"
  58. :maxLength="10"
  59. autocomplete="off"
  60. allow-clear
  61. v-decorator="[
  62. 'passwordSecond',
  63. {
  64. rules: [{ required: true, message: '请输入相同的密码!' }],
  65. initialValue: '',
  66. },
  67. ]"
  68. />
  69. </a-form-item>
  70. <a-form-item
  71. label="用户名"
  72. :label-col="labelCol"
  73. :wrapper-col="wrapperCol"
  74. >
  75. <a-input
  76. placeholder="请输入用户名"
  77. :maxLength="10"
  78. autocomplete="off"
  79. allow-clear
  80. v-decorator="[
  81. 'nickName',
  82. {
  83. rules: [{ required: true, message: '请输入用户名' }],
  84. initialValue: '',
  85. },
  86. ]"
  87. />
  88. </a-form-item>
  89. <a-form-item
  90. :wrapper-col="{
  91. sm: { span: 12, offset: 12 },
  92. }"
  93. >
  94. <a-button type="primary" html-type="submit">提交</a-button>
  95. </a-form-item>
  96. </a-form>
  97. </div>
  98. </div>
  99. <div class="common-card a-card-margin-top">
  100. <!-- 表单 -->
  101. <a-table
  102. :columns="columns"
  103. :data-source="tableData"
  104. :row-key="(record) => record.registerTime"
  105. :pagination="false"
  106. >
  107. <template slot="action" slot-scope="text, record">
  108. <a @click="userDelete(record)">删除</a>
  109. </template>
  110. </a-table>
  111. <!-- 分页 -->
  112. <div class="a-pagination-display">
  113. <a-pagination
  114. v-model="pagination.current"
  115. :pageSize="pagination.pageSize"
  116. :total.sync="pagination.total"
  117. show-less-items
  118. show-quick-jumper
  119. @change="getAdminListFun"
  120. />
  121. </div>
  122. </div>
  123. </a-spin>
  124. </div>
  125. </template>
  126. <script>
  127. export default {
  128. name: 'userManagementList',
  129. props: {},
  130. components: {},
  131. data() {
  132. return {
  133. loading: false, // 是否显示加载动画
  134. // 基础信息的表单
  135. labelCol: { span: 6 }, // 表单行中label的占位
  136. wrapperCol: { span: 18 }, // 表单行中内容的占位
  137. addAdminForm: this.$form.createForm(this, { name: 'addAdminForm' }), // 表单
  138. // table
  139. columns: {}, // 表格列配置
  140. tableData: [], // 表格数据
  141. pagination: {
  142. pageSize: 10,
  143. current: 1,
  144. total: 0,
  145. }, // 分页参数
  146. };
  147. },
  148. created() {
  149. this.initDataFun(); //初始化数据
  150. },
  151. mounted() {},
  152. beforeDestroy() {},
  153. watch: {},
  154. computed: {},
  155. methods: {
  156. //初始化数据
  157. initDataFun() {
  158. // 表单的列的配置参数
  159. this.columns = [
  160. {
  161. title: '账号',
  162. dataIndex: 'userName',
  163. key: 'userName',
  164. },
  165. {
  166. title: '用户名',
  167. dataIndex: 'nickName',
  168. key: 'nickName',
  169. },
  170. {
  171. title: '密码',
  172. dataIndex: 'password',
  173. key: 'password',
  174. scopedSlots: { customRender: 'password' },
  175. },
  176. {
  177. title: '操作',
  178. dataIndex: 'action',
  179. key: 'action',
  180. scopedSlots: { customRender: 'action' },
  181. },
  182. ];
  183. this.getAdminListFun(); // 查询:已有账号列表
  184. },
  185. // 查询:已有账号列表
  186. getAdminListFun() {
  187. this.loading = true;
  188. // let params = {
  189. // page: this.pagination.current,
  190. // size: this.pagination.pageSize,
  191. // };
  192. this.$_http
  193. .get(this.$_API.INTERFACE_GET_USER_LIST)
  194. .then((res) => {
  195. this.tableData = res.data.content;
  196. this.pagination.total = res.data.totalElements; // 总条数
  197. this.loading = false;
  198. })
  199. .catch(() => {
  200. this.loading = false;
  201. });
  202. },
  203. // 操作:新建
  204. handleSubmitForm(e) {
  205. e.preventDefault();
  206. this.addAdminForm.validateFields((err, values) => {
  207. if (!err) {
  208. if (values.password !== values.passwordSecond) {
  209. this.addAdminForm.setFields({
  210. password: {
  211. value: values.password,
  212. errors: [new Error('密码输入不一致')],
  213. },
  214. passwordSecond: {
  215. value: values.passwordSecond,
  216. errors: [new Error('密码输入不一致')],
  217. },
  218. });
  219. return;
  220. } else {
  221. this.httpLoginFun(values); // 表单提交请求:新建管理员
  222. }
  223. }
  224. });
  225. },
  226. // 表单提交请求:新建管理员
  227. httpLoginFun(params) {
  228. this.loading = true;
  229. this.$_http
  230. .post(this.$_API.INTERFACE_POST_USER_ADMIN, params)
  231. .then(() => {
  232. this.$message.success('新建账号成功');
  233. // 清空表单值
  234. this.addAdminForm.setFieldsValue({
  235. userName: '',
  236. password: '',
  237. passwordSecond: '',
  238. nickName: '',
  239. });
  240. this.loading = false;
  241. this.getAdminListFun(); // 查询:已有账号列表
  242. })
  243. .catch(() => {
  244. this.loading = false;
  245. });
  246. },
  247. // 操作:删除用户
  248. userDelete(record) {
  249. let that = this;
  250. that.$confirm({
  251. title: '删除',
  252. content: `确认删除 ${record.userName} 吗?`,
  253. okText: '确认',
  254. cancelText: '取消',
  255. onOk() {
  256. that.loading = true;
  257. let params = {
  258. userName: record.userName,
  259. };
  260. that.$_http
  261. .delete(that.$_API.INTERFACE_DELETE_USER_ADMIN, { data: params })
  262. .then(() => {
  263. that.loading = false;
  264. that.$message.success('删除用户成功');
  265. this.getAdminListFun(); // 查询:已有账号列表
  266. })
  267. .catch(() => {
  268. that.loading = false;
  269. });
  270. },
  271. onCancel() {},
  272. });
  273. },
  274. },
  275. };
  276. </script>
  277. <style lang="less"></style>
  278. <style lang="less" scoped>
  279. @import '~@/styles/common/variable.less';
  280. .app-container {
  281. overflow-y: auto;
  282. .basic-information-title {
  283. font-size: 18px;
  284. font-weight: bold;
  285. color: @mainColorBlack85;
  286. margin-bottom: @paddingMarginVal;
  287. }
  288. .user-form-div {
  289. width: 100%;
  290. display: flex;
  291. justify-content: center;
  292. }
  293. }
  294. </style>