resetPass.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="wrap f-padding">
  3. <u-form :model="form" ref="uForm">
  4. <u-form-item label="原密码" prop="password" left-icon="lock-open" :label-width="labelWidth">
  5. <u-input v-model="form.oldPwd" placeholder="请输入原密码" />
  6. </u-form-item>
  7. <u-form-item label="新密码" prop="newPassword" left-icon="lock-open" :label-width="labelWidth">
  8. <u-input :password-icon="true" type="password" v-model="form.newPwd" placeholder="请输入新密码" />
  9. </u-form-item>
  10. <u-form-item label="确认新密码" prop="secPassword" left-icon="lock-open" :label-width="labelWidth">
  11. <u-input :password-icon="true" type="password" v-model="form.secPassword" placeholder="请确认新密码" />
  12. </u-form-item>
  13. <u-button class="u-m-t-80" type="primary" @click="submit">确认修改</u-button>
  14. </u-form>
  15. </view>
  16. </template>
  17. <script>
  18. import crypto from 'utils/crypto.js'
  19. export default{
  20. data(){
  21. let logPwd2 = (rule, value, callback) => {
  22. if (value === '') {
  23. callback(new Error('请再次输入密码'));
  24. } else if (value !== this.form.newPwd) {
  25. callback(new Error('两次输入密码不一致!'));
  26. } else {
  27. callback();
  28. }
  29. };
  30. return{
  31. labelWidth:'200',
  32. form:{},
  33. rules: {
  34. oldPwd: [
  35. {
  36. required: true,
  37. min: 6,
  38. message: '密码不能少于6个字符',
  39. // 可以单个或者同时写两个触发验证方式
  40. trigger: ['change','blur'],
  41. }
  42. ],
  43. newPwd: [
  44. {
  45. required: true,
  46. min: 6,
  47. message: '密码不能少于6个字符',
  48. trigger: 'change'
  49. }
  50. ],
  51. secPassword:[
  52. { required: true,validator: logPwd2, trigger: 'blur' }
  53. ]
  54. }
  55. }
  56. },
  57. onReady() {
  58. this.$refs.uForm.setRules(this.rules);
  59. },
  60. onLoad(){
  61. },
  62. onShow(){
  63. },
  64. methods:{
  65. submit() {
  66. // uni.switchTab({
  67. // url: '../index/index'
  68. // });
  69. this.$refs.uForm.validate(valid => {
  70. if (valid) {
  71. // this.form.password = crypto.Encrypt(this.form.password);
  72. // this.form.newPassword = crypto.Encrypt(this.form.newPassword);
  73. // this.form.secPassword = crypto.Encrypt(this.form.secPassword);
  74. this.$u.api.updatePwd(this.form).then(res=>{
  75. if(res.code==200){
  76. //#ifdef H5
  77. localStorage.setItem('backUrl', '');
  78. //#endif
  79. uni.navigateTo({
  80. url: '../../login/login'
  81. });
  82. }else{
  83. uni.showToast({
  84. icon:'none',
  85. title:res.msg
  86. })
  87. }
  88. console.log('res',res);
  89. }).catch(err=>{
  90. console.log('err',err);
  91. })
  92. // console.log('验证通过');
  93. } else {
  94. // console.log('验证失败');
  95. }
  96. });
  97. },
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. // @import './resetPass.scss'
  103. </style>