password.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="password-page">
  3. <view class="form">
  4. <uni-forms ref="form" :rules="rules" :model="form" :label-width="80">
  5. <uni-forms-item label="原密码" name="original_password" required>
  6. <uni-easyinput v-model="form.original_password" type="password" placeholder="请输入原密码"></uni-easyinput>
  7. </uni-forms-item>
  8. <uni-forms-item label="新密码" name="new_password" required>
  9. <uni-easyinput v-model="form.new_password" type="password" placeholder="请输入新密码"></uni-easyinput>
  10. </uni-forms-item>
  11. <uni-forms-item label="再次确认" name="password" required>
  12. <uni-easyinput v-model="form.password" type="password" placeholder="请再次输入新密码"></uni-easyinput>
  13. </uni-forms-item>
  14. </uni-forms>
  15. <footer @click="onSubmit">提交</footer>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import {updatePassword,logout} from '@/api/user.js'
  21. export default {
  22. data() {
  23. return {
  24. rules:{
  25. original_password:{
  26. rules:[
  27. {
  28. required: true,
  29. errorMessage: '请输入原密码'
  30. }
  31. ],
  32. validateTrigger:'submit'
  33. },
  34. new_password:{
  35. rules:[
  36. {
  37. required: true,
  38. errorMessage: '请输入新密码'
  39. }
  40. ],
  41. validateTrigger:'submit'
  42. },
  43. password:{
  44. rules:[
  45. {
  46. required: true,
  47. errorMessage: '请再次输入新密码'
  48. }
  49. ],
  50. validateTrigger:'submit'
  51. },
  52. },
  53. form:{
  54. original_password:"",
  55. new_password:"",
  56. password:""
  57. }
  58. }
  59. },
  60. methods: {
  61. onSubmit(){
  62. this.$refs.form.validate().then(res=>{
  63. let accountId=uni.getStorageSync('accountInfo')?.userId
  64. updatePassword({
  65. accountId,
  66. password: this.form.new_password,
  67. rePassword: this.form.password
  68. }).then(()=>{
  69. uni.showModal({
  70. title:'提示!',
  71. content:"请退出重新登录",
  72. success(res) {
  73. if (res.confirm) {
  74. logout().then(()=>{
  75. uni.clearStorageSync()
  76. uni.navigateTo({
  77. url:'/pages/login/login'
  78. })
  79. })
  80. }
  81. }
  82. })
  83. })
  84. }).catch(err =>{
  85. console.log('表单错误信息:', err);
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .password-page{
  93. background: #F3F5FB;
  94. height: 100vh;
  95. .form{
  96. width: 686upx;
  97. background-color: #fff;
  98. margin: 0 auto;
  99. padding:40upx 36upx 2upx 36upx;
  100. box-sizing: border-box;
  101. border-radius: 20upx;
  102. }
  103. footer{
  104. width: 100%;
  105. height: 136upx;
  106. background: #FFFFFF;
  107. border-radius: 16upx 16upx 0px 0px;
  108. position: fixed;
  109. left: 0;
  110. bottom: 0;
  111. text-align: center;
  112. color: #168DEC;
  113. font-size: 32upx;
  114. padding-top: 20upx;
  115. letter-spacing: 2px;
  116. }
  117. }
  118. </style>