index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <view class="pwd-retrieve-container">
  3. <uni-forms ref="form" :value="user" labelWidth="80px">
  4. <uni-forms-item name="oldPassword" label="旧密码">
  5. <uni-easyinput type="password" v-model="user.oldPassword" placeholder="请输入旧密码" />
  6. </uni-forms-item>
  7. <uni-forms-item name="newPassword" label="新密码">
  8. <uni-easyinput type="password" v-model="user.newPassword" placeholder="请输入新密码" />
  9. </uni-forms-item>
  10. <uni-forms-item name="confirmPassword" label="确认密码">
  11. <uni-easyinput type="password" v-model="user.confirmPassword" placeholder="请确认新密码" />
  12. </uni-forms-item>
  13. <button type="primary" @click="submit">提交</button>
  14. </uni-forms>
  15. </view>
  16. </template>
  17. <script>
  18. import { updateUserPwd } from "@/api/system/user"
  19. export default {
  20. data() {
  21. return {
  22. user: {
  23. oldPassword: undefined,
  24. newPassword: undefined,
  25. confirmPassword: undefined
  26. },
  27. rules: {
  28. oldPassword: {
  29. rules: [{
  30. required: true,
  31. errorMessage: '旧密码不能为空'
  32. }]
  33. },
  34. newPassword: {
  35. rules: [{
  36. required: true,
  37. errorMessage: '新密码不能为空',
  38. },
  39. {
  40. minLength: 6,
  41. maxLength: 20,
  42. errorMessage: '长度在 6 到 20 个字符'
  43. }
  44. ]
  45. },
  46. confirmPassword: {
  47. rules: [{
  48. required: true,
  49. errorMessage: '确认密码不能为空'
  50. }, {
  51. validateFunction: (rule, value, data) => data.newPassword === value,
  52. errorMessage: '两次输入的密码不一致'
  53. }
  54. ]
  55. }
  56. }
  57. }
  58. },
  59. onReady() {
  60. this.$refs.form.setRules(this.rules)
  61. },
  62. methods: {
  63. submit() {
  64. this.$refs.form.validate().then(res => {
  65. updateUserPwd(this.user.oldPassword, this.user.newPassword).then(response => {
  66. this.$modal.msgSuccess("修改成功")
  67. })
  68. })
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss">
  74. page {
  75. background-color: #ffffff;
  76. }
  77. .pwd-retrieve-container {
  78. padding-top: 36rpx;
  79. padding: 15px;
  80. }
  81. </style>