resetpass.vue 4.0 KB

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