resetpass.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="修改密码"
  5. :placeholder="true"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar>
  10. <view class="page-wrap">
  11. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" >
  12. <u-form-item label="" prop="oldPassword" :borderBottom="false" ref="oldPassword" >
  13. <u--input
  14. v-model="form.oldPassword"
  15. border="none"
  16. placeholder="请输入旧密码"
  17. :customStyle="inputCustomStyle"
  18. ></u--input>
  19. </u-form-item>
  20. <u-form-item label="" prop="password" :borderBottom="false" ref="password" >
  21. <u--input
  22. v-model="form.password"
  23. border="none"
  24. :password="true"
  25. placeholder="请输入新密码"
  26. :customStyle="inputCustomStyle"
  27. ></u--input>
  28. </u-form-item>
  29. <u-form-item label="" prop="comfpassword" :borderBottom="false" ref="comfpassword" >
  30. <u--input
  31. v-model="form.comfpassword"
  32. border="none"
  33. :password="true"
  34. placeholder="确认密码"
  35. :customStyle="inputCustomStyle"
  36. ></u--input>
  37. </u-form-item>
  38. </u--form>
  39. <u-button
  40. @click="submit"
  41. text="确认"
  42. type="primary"
  43. shape="circle"
  44. :customStyle="{'margin-top':'60rpx',height:'98rpx','box-sizing':'border-box'}"
  45. >
  46. </u-button>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. export default {
  52. data() {
  53. return {
  54. form:{
  55. oldPassword:'',
  56. password:'',
  57. comfpassword:'',
  58. },
  59. rules: {
  60. oldPassword: {
  61. type: 'string',
  62. required: true,
  63. message: '请输入旧密码',
  64. trigger: ['blur', 'change']
  65. },
  66. password: [
  67. {
  68. type: 'string',
  69. required: true,
  70. message: '请输入新密码',
  71. trigger: ['blur', 'change']
  72. },
  73. {
  74. min: 6,
  75. max: 10,
  76. message: '长度在6-10个字符之间',
  77. trigger: 'blur',
  78. },
  79. ],
  80. comfpassword: [
  81. {
  82. type: 'string',
  83. required: true,
  84. message: '请确认密码',
  85. trigger: ['blur', 'change']
  86. },
  87. {
  88. validator: (rule, value, callback) => {
  89. if (value === '') {
  90. callback(new Error('请再次输入密码'));
  91. } else if (value !== this.form.password) {
  92. callback(new Error('两次输入密码不一致!'));
  93. } else {
  94. callback();
  95. }
  96. },
  97. trigger: 'blur',
  98. }
  99. ],
  100. },
  101. inputCustomStyle:{
  102. // height:'98rpx',
  103. 'border-color':'#eee',
  104. 'background-color': '#F5F9FC',
  105. 'padding-left':'30rpx',
  106. 'box-sizing':'border-box',
  107. }
  108. }
  109. },
  110. onShow() {
  111. },
  112. onReady() {
  113. this.$refs.uForm.setRules(this.rules)
  114. },
  115. onLoad() {
  116. },
  117. methods: {
  118. chekPass(){
  119. console.log('chekPass---',this.form);
  120. return new Promise((resolve, reject)=>{
  121. if(!password){
  122. reject('needAuth');
  123. }
  124. })
  125. },
  126. async submit(){
  127. // console.log('form',this.form);
  128. this.$refs.uForm.validate().then(res => {
  129. // let chekPassResult = await this.chekPass();
  130. // return
  131. // uni.$u.toast('校验通过')
  132. const param = {
  133. oldPassword:this.form.oldPassword,
  134. password:this.form.password
  135. }
  136. this.$u.api.updatePassword(param).then(res=>{
  137. // console.log('res',res.data);
  138. this.$u.vuex('vuex_user_info', res.data);
  139. uni.showToast({
  140. title:res.msg,
  141. icon:'success'
  142. })
  143. setTimeout(()=>{
  144. uni.$u.route('/pages/login/login');
  145. },2000)
  146. // uni.reLaunch({url: this.backUrl});
  147. }).catch(err=>{
  148. console.log('login',err);
  149. })
  150. }).catch(errors => {
  151. uni.$u.toast('请正确填写表单')
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .page-wrap{
  159. .u-form-item{
  160. margin-bottom: 40rpx;
  161. }
  162. /deep/ .u-form-item__body{
  163. background-color:#F5F9FC;
  164. border-radius: 16rpx;
  165. }
  166. }
  167. </style>