modify-password.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view style="padding: 20rpx;">
  3. <view style="padding: 30rpx;background-color: white;border-radius:50rpx">
  4. <u--form labelPosition="left" :model="passwordInfo" ref="uForm" labelWidth='120'>
  5. <u-form-item label="原密码:" prop="oldPassword" borderBottom ref="uItem" :required="true" >
  6. <u--input v-model="passwordInfo.oldPassword" password clearable border="none" placeholder="请输入原密码"></u--input>
  7. </u-form-item>
  8. <u-form-item label="新密码:" prop="newPassword" borderBottom ref="uItem" :required="true">
  9. <u--input v-model="passwordInfo.newPassword" password clearable border="none" placeholder="请输入新密码"></u--input>
  10. </u-form-item>
  11. <u-form-item label="新密码确认:" prop="newPasswordConfirm" borderBottom ref="uItem" :required="true">
  12. <u--input v-model="passwordInfo.newPasswordConfirm" password clearable border="none" placeholder="请重复新密码"></u--input>
  13. </u-form-item>
  14. <u-button type="primary" text="提交" customStyle="margin-top: 50px" @click="submit"></u-button>
  15. </u--form>
  16. </view>
  17. <u-toast ref="uToast"></u-toast>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. modifyPassword
  23. } from '@/api/system/user.js'
  24. export default {
  25. data() {
  26. return {
  27. passwordInfo: {
  28. id: null,
  29. oldPassword: '',
  30. newPassword: '',
  31. newPasswordConfirm: ''
  32. },
  33. rules: {
  34. 'oldPassword': {
  35. type: 'string',
  36. required: true,
  37. message: '请填写原密码',
  38. trigger: ['blur', 'change']
  39. },
  40. 'newPassword': {
  41. type: 'string',
  42. required: true,
  43. message: '请填写新密码',
  44. trigger: ['blur', 'change']
  45. },
  46. 'newPasswordConfirm': {
  47. type: 'string',
  48. required: true,
  49. message: '请确认新密码',
  50. trigger: ['blur', 'change']
  51. }
  52. }
  53. }
  54. },
  55. methods: {
  56. submit() {
  57. this.$refs.uForm.validate().then(val => {
  58. modifyPassword(this.passwordInfo).then(res => {
  59. if (res.success) {
  60. this.$refs.uToast.show({
  61. type: 'success',
  62. message: "密码修改成功",
  63. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  64. })
  65. setTimeout(()=>{
  66. this.logout()
  67. }, 1000)
  68. } else {
  69. this.$refs.uToast.show({
  70. type: 'error',
  71. message: res.message,
  72. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  73. })
  74. }
  75. })
  76. })
  77. },
  78. logout() {
  79. this.$store.dispatch("LogOut").then(res => {
  80. uni.navigateTo({
  81. url: '/pages/login/index'
  82. })
  83. })
  84. }
  85. },
  86. onReady() {
  87. this.$refs.uForm.setRules(this.rules)
  88. },
  89. onLoad(option) {
  90. const userId = option.userId
  91. this.passwordInfo.id = userId
  92. },
  93. }
  94. </script>
  95. <style>
  96. </style>