passwd.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="page-box">
  3. <uni-forms :modelValue="postForm" ref="postForm" :rules="rules" :label-width="100">
  4. <uni-forms-item name="oldPassword" label="旧密码" required>
  5. <uni-easyinput type="text" v-model="postForm.oldPassword" placeholder="输入旧密码" />
  6. </uni-forms-item>
  7. <uni-forms-item name="password" label="新密码" required>
  8. <uni-easyinput type="text" v-model="postForm.password" placeholder="输入新密码" />
  9. </uni-forms-item>
  10. <uni-forms-item name="confirm" label="确认密码" required>
  11. <uni-easyinput type="text" v-model="postForm.confirm" placeholder="输入确认密码" />
  12. </uni-forms-item>
  13. </uni-forms>
  14. <view style="margin-top: 10px;">
  15. <button type="primary" @tap="handleUpdate">提交修改</button>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import { updatePass } from '@/api/user.js'
  21. export default {
  22. components: {
  23. },
  24. data() {
  25. return {
  26. rules: {
  27. oldPassword: {
  28. rules: [{
  29. required: true,
  30. errorMessage: '旧密码不能为空!'
  31. }]
  32. },
  33. password: {
  34. rules: [{
  35. required: true,
  36. errorMessage: '新密码不能为空!'
  37. }]
  38. },
  39. confirm: {
  40. rules: [{
  41. required: true,
  42. errorMessage: '确认密码不能为空!'
  43. },
  44. {
  45. validateFunction:function(rule,value,data,callback){
  46. if (value != data.password) {
  47. callback('两次密码输入不一致!')
  48. }
  49. return true
  50. }
  51. }
  52. ]
  53. }
  54. },
  55. postForm: {
  56. oldPassword: '',
  57. password: '',
  58. confirm: ''
  59. }
  60. }
  61. },
  62. methods: {
  63. handleUpdate() {
  64. this.$refs.postForm.validate().then((res) => {
  65. uni.showLoading({
  66. title: '加载中...'
  67. });
  68. this.loginLoading = true
  69. // 快速注册后开始考试
  70. updatePass(this.postForm).then(data => {
  71. // 关闭加载
  72. uni.hideLoading()
  73. // 移除token
  74. uni.removeStorageSync('token')
  75. //打印请求返回的数据
  76. uni.switchTab({
  77. url: '/pages/index/index'
  78. });
  79. });
  80. }).catch(()=>{
  81. })
  82. }
  83. }
  84. }
  85. </script>
  86. <style>
  87. .content {
  88. padding: 32rpx;
  89. font-size: 16px;
  90. line-height: 80rpx;
  91. }
  92. .uni-btn-v {
  93. margin-top: 50rpx;
  94. width: 100%;
  95. }
  96. </style>