userManagementList.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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="basic-information-form">
  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-password
  38. placeholder="输入密码"
  39. :maxLength="50"
  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-password
  57. placeholder="确认密码"
  58. :maxLength="50"
  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 basic-information-box">
  100. <div class="basic-information-title">已有账号</div>
  101. <!-- 表单 -->
  102. <a-table
  103. :columns="columns"
  104. :data-source="tableData"
  105. :row-key="(record) => record.registerTime"
  106. :pagination="false"
  107. >
  108. <template slot="password" slot-scope="text, record">
  109. <span>{{ record.isShow ? record.password : '******' }}</span>
  110. <icon-font
  111. class="iconFont"
  112. :type="record.isShow ? 'ali-icon-kejian' : 'ali-icon-bukejian'"
  113. @click="record.isShow = !record.isShow"
  114. ></icon-font>
  115. </template>
  116. <template slot="action" slot-scope="text, record">
  117. <a @click="userDelete(record)">删除</a>
  118. </template>
  119. </a-table>
  120. <!-- 分页 -->
  121. <div class="a-pagination-display">
  122. <a-pagination
  123. v-model="pagination.current"
  124. :pageSize="pagination.pageSize"
  125. :total.sync="pagination.total"
  126. show-less-items
  127. show-quick-jumper
  128. @change="getAdminListFun"
  129. />
  130. </div>
  131. </div>
  132. </a-spin>
  133. <!-- <div class="company-info">
  134. <span>
  135. copyright © 浮游科技有限公司出品
  136. </span>
  137. </div> -->
  138. </div>
  139. </template>
  140. <script>
  141. export default {
  142. name: 'userManagementList',
  143. props: {},
  144. components: {},
  145. data() {
  146. return {
  147. loading: false, // 是否显示加载动画
  148. // 基础信息的表单
  149. labelCol: { span: 6 }, // 表单行中label的占位
  150. wrapperCol: { span: 18 }, // 表单行中内容的占位
  151. addAdminForm: this.$form.createForm(this, { name: 'addAdminForm' }), // 表单
  152. // table
  153. columns: {}, // 表格列配置
  154. tableData: [], // 表格数据
  155. pagination: {
  156. pageSize: 10,
  157. current: 1,
  158. total: 0,
  159. }, // 分页参数
  160. };
  161. },
  162. created() {
  163. this.initDataFun(); //初始化数据
  164. },
  165. mounted() {},
  166. beforeDestroy() {},
  167. watch: {},
  168. computed: {},
  169. methods: {
  170. //初始化数据
  171. initDataFun() {
  172. // 表单的列的配置参数
  173. this.columns = [
  174. {
  175. title: '账号',
  176. dataIndex: 'userName',
  177. key: 'userName',
  178. width: 300,
  179. },
  180. {
  181. title: '用户名',
  182. dataIndex: 'nickName',
  183. key: 'nickName',
  184. width: 300,
  185. },
  186. {
  187. title: '密码',
  188. dataIndex: 'password',
  189. key: 'password',
  190. scopedSlots: { customRender: 'password' },
  191. },
  192. {
  193. title: '操作',
  194. dataIndex: 'action',
  195. key: 'action',
  196. scopedSlots: { customRender: 'action' },
  197. width: 200,
  198. },
  199. ];
  200. this.getAdminListFun(); // 查询:已有账号列表
  201. },
  202. // 查询:已有账号列表
  203. getAdminListFun() {
  204. this.loading = true;
  205. let params = {
  206. page: this.pagination.current - 1,
  207. size: this.pagination.pageSize,
  208. };
  209. this.$_http
  210. .get(this.$_API.INTERFACE_GET_USER_LIST, { params })
  211. .then((res) => {
  212. let resdData = res.data.content;
  213. resdData.forEach((item) => {
  214. item.isShow = false;
  215. });
  216. this.tableData = [...resdData];
  217. this.pagination.total = res.data.totalElements; // 总条数
  218. this.loading = false;
  219. })
  220. .catch(() => {
  221. this.loading = false;
  222. });
  223. },
  224. // 操作:新建
  225. handleSubmitForm(e) {
  226. e.preventDefault();
  227. this.addAdminForm.validateFields((err, values) => {
  228. if (!err) {
  229. if (values.password !== values.passwordSecond) {
  230. this.addAdminForm.setFields({
  231. password: {
  232. value: values.password,
  233. errors: [new Error('密码输入不一致')],
  234. },
  235. passwordSecond: {
  236. value: values.passwordSecond,
  237. errors: [new Error('密码输入不一致')],
  238. },
  239. });
  240. return;
  241. } else {
  242. this.httpLoginFun(values); // 表单提交请求:新建管理员
  243. }
  244. }
  245. });
  246. },
  247. // 表单提交请求:新建管理员
  248. httpLoginFun(params) {
  249. this.loading = true;
  250. this.$_http
  251. .post(this.$_API.INTERFACE_POST_USER_ADMIN, params)
  252. .then(() => {
  253. this.$message.success('新建账号成功');
  254. // 清空表单值
  255. this.addAdminForm.setFieldsValue({
  256. userName: '',
  257. password: '',
  258. passwordSecond: '',
  259. nickName: '',
  260. });
  261. this.loading = false;
  262. this.getAdminListFun(); // 查询:已有账号列表
  263. })
  264. .catch(() => {
  265. this.loading = false;
  266. });
  267. },
  268. // 操作:删除用户
  269. userDelete(record) {
  270. let that = this;
  271. that.$confirm({
  272. title: '删除',
  273. content: `确认删除 ${record.userName} 吗?`,
  274. okText: '确认',
  275. cancelText: '取消',
  276. onOk() {
  277. that.loading = true;
  278. let params = {
  279. ...record,
  280. };
  281. that.$_http
  282. .delete(that.$_API.INTERFACE_DELETE_USER_ADMIN, { data: params })
  283. .then(() => {
  284. that.loading = false;
  285. that.$message.success('删除用户成功');
  286. that.getAdminListFun(); // 查询:已有账号列表
  287. })
  288. .catch(() => {
  289. that.loading = false;
  290. });
  291. },
  292. onCancel() {},
  293. });
  294. },
  295. },
  296. };
  297. </script>
  298. <style lang="less"></style>
  299. <style lang="less" scoped>
  300. @import '~@/styles/common/variable.less';
  301. .app-container {
  302. .basic-information-title {
  303. margin-bottom: @paddingMarginVal;
  304. }
  305. .iconFont {
  306. margin-left: @paddingMarginVal;
  307. &:hover {
  308. color: @mainColorBlueNormal;
  309. }
  310. }
  311. }
  312. </style>